Fix deleted events persisting after all events deleted

This commit is contained in:
GriffinR 2020-07-13 10:42:47 -04:00 committed by huderlem
parent e518e2c554
commit c68e352bb1

View file

@ -2072,9 +2072,12 @@ void MainWindow::on_toolButton_deleteObject_clicked()
DraggablePixmapItem *next_selected_event = nullptr;
for (DraggablePixmapItem *item : *editor->selected_events) {
QString event_group = item->event->get("event_group_type");
int index = editor->map->events.value(event_group).indexOf(item->event);
if (event_group != "heal_event_group") {
// Get the index for the event that should be selected after this event has been deleted.
// If it's at the end of the list, select the previous event, otherwise select the next one.
// Don't bother getting the event to select if there are still more events to delete
if (editor->selected_events->length() == 1) {
int index = editor->map->events.value(event_group).indexOf(item->event);
if (index != editor->map->events.value(event_group).size() - 1)
index++;
else
@ -2082,7 +2085,6 @@ void MainWindow::on_toolButton_deleteObject_clicked()
Event *event = nullptr;
if (index >= 0)
event = editor->map->events.value(event_group).at(index);
if (event_group != "heal_event_group") {
for (QGraphicsItem *child : editor->events_group->childItems()) {
DraggablePixmapItem *event_item = static_cast<DraggablePixmapItem *>(child);
if (event_item->event == event) {
@ -2090,6 +2092,7 @@ void MainWindow::on_toolButton_deleteObject_clicked()
break;
}
}
}
editor->deleteEvent(item->event);
if (editor->scene->items().contains(item)) {
editor->scene->removeItem(item);