Guard against index out of bounds when deleting last event in group
This commit is contained in:
parent
631896a708
commit
654b788937
1 changed files with 5 additions and 1 deletions
|
@ -1785,11 +1785,15 @@ void MainWindow::on_toolButton_deleteObject_clicked()
|
|||
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);
|
||||
// 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.
|
||||
if (index != editor->map->events.value(event_group).size() - 1)
|
||||
index++;
|
||||
else
|
||||
index--;
|
||||
Event *event = editor->map->events.value(event_group).at(index);
|
||||
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);
|
||||
|
|
Loading…
Reference in a new issue