diff --git a/CHANGELOG.md b/CHANGELOG.md index 51520783..dfee0051 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -22,6 +22,7 @@ The **"Breaking Changes"** listed below are changes that have been made in the d - Fix config files being written before the project is opened successfully. - Fix the map and other project info still displaying if a new project fails to open. - Fix unsaved changes being ignored when quitting (such as with Cmd+Q on macOS). +- Fix selections with multiple Events not always clearing when making a new selection. - Fix `About porymap` opening a new window each time it's activated. - Fix the `Edit History` window not raising to the front when reactivated. diff --git a/include/mainwindow.h b/include/mainwindow.h index 83eea1f5..d58d11c0 100644 --- a/include/mainwindow.h +++ b/include/mainwindow.h @@ -222,7 +222,7 @@ private slots: void on_toolButton_deleteObject_clicked(); void addNewEvent(Event::Type type); - void tryAddEventTab(QWidget * tab, Event::Group group); + void tryAddEventTab(QWidget * tab); void displayEventTabs(); void updateSelectedObjects(); void updateObjects(); @@ -328,12 +328,6 @@ private slots: QAction *copyAction = nullptr; QAction *pasteAction = nullptr; - QWidget *eventTabObjectWidget; - QWidget *eventTabWarpWidget; - QWidget *eventTabTriggerWidget; - QWidget *eventTabBGWidget; - QWidget *eventTabHealspotWidget; - QWidget *eventTabMultipleWidget; QMap lastSelectedEvent; bool isProgrammaticEventTabChange; diff --git a/src/editor.cpp b/src/editor.cpp index 54194a96..46aa0458 100644 --- a/src/editor.cpp +++ b/src/editor.cpp @@ -2116,19 +2116,25 @@ void Editor::selectMapEvent(DraggablePixmapItem *object) { } void Editor::selectMapEvent(DraggablePixmapItem *object, bool toggle) { - if (selected_events && object) { - if (selected_events->contains(object)) { - if (toggle) { - selected_events->removeOne(object); - } - } else { - if (!toggle) { - selected_events->clear(); - } - selected_events->append(object); - } - updateSelectedEvents(); + if (!selected_events || !object) + return; + + if (!toggle) { + // Selecting just this event + selected_events->clear(); + selected_events->append(object); + } else if (!selected_events->contains(object)) { + // Adding event to selection + selected_events->append(object); + } else if (selected_events->length() > 1) { + // Removing from group selection + selected_events->removeOne(object); + } else { + // Attempting to toggle the only currently-selected event. + // Unselecting an event this way would be unexpected, so we ignore it. + return; } + updateSelectedEvents(); } void Editor::selectedEventIndexChanged(int index, Event::Group eventGroup) { diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index 8595fbcc..39167597 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -366,12 +366,6 @@ void MainWindow::initMiscHeapObjects() { mapListProxyModel->setSourceModel(mapListModel); ui->mapList->setModel(mapListProxyModel); - eventTabObjectWidget = ui->tab_Objects; - eventTabWarpWidget = ui->tab_Warps; - eventTabTriggerWidget = ui->tab_Triggers; - eventTabBGWidget = ui->tab_BGs; - eventTabHealspotWidget = ui->tab_Healspots; - eventTabMultipleWidget = ui->tab_Multiple; ui->tabWidget_EventType->clear(); } @@ -1977,7 +1971,8 @@ void MainWindow::addNewEvent(Event::Type type) { } } -void MainWindow::tryAddEventTab(QWidget * tab, Event::Group group) { +void MainWindow::tryAddEventTab(QWidget * tab) { + auto group = getEventGroupFromTabWidget(tab); if (editor->map->events.value(group).length()) ui->tabWidget_EventType->addTab(tab, QString("%1s").arg(Event::eventGroupToString(group))); } @@ -1986,11 +1981,11 @@ void MainWindow::displayEventTabs() { const QSignalBlocker blocker(ui->tabWidget_EventType); ui->tabWidget_EventType->clear(); - tryAddEventTab(eventTabObjectWidget, Event::Group::Object); - tryAddEventTab(eventTabWarpWidget, Event::Group::Warp); - tryAddEventTab(eventTabTriggerWidget, Event::Group::Coord); - tryAddEventTab(eventTabBGWidget, Event::Group::Bg); - tryAddEventTab(eventTabHealspotWidget, Event::Group::Heal); + tryAddEventTab(ui->tab_Objects); + tryAddEventTab(ui->tab_Warps); + tryAddEventTab(ui->tab_Triggers); + tryAddEventTab(ui->tab_BGs); + tryAddEventTab(ui->tab_Healspots); } void MainWindow::updateObjects() { @@ -2150,30 +2145,15 @@ void MainWindow::updateSelectedObjects() { } } -Event::Group MainWindow::getEventGroupFromTabWidget(QWidget *tab) -{ - Event::Group ret = Event::Group::None; - if (tab == eventTabObjectWidget) - { - ret = Event::Group::Object; - } - else if (tab == eventTabWarpWidget) - { - ret = Event::Group::Warp; - } - else if (tab == eventTabTriggerWidget) - { - ret = Event::Group::Coord; - } - else if (tab == eventTabBGWidget) - { - ret = Event::Group::Bg; - } - else if (tab == eventTabHealspotWidget) - { - ret = Event::Group::Heal; - } - return ret; +Event::Group MainWindow::getEventGroupFromTabWidget(QWidget *tab) { + static const QMap tabToGroup = { + {ui->tab_Objects, Event::Group::Object}, + {ui->tab_Warps, Event::Group::Warp}, + {ui->tab_Triggers, Event::Group::Coord}, + {ui->tab_BGs, Event::Group::Bg}, + {ui->tab_Healspots, Event::Group::Heal}, + }; + return tabToGroup.value(tab, Event::Group::None); } void MainWindow::eventTabChanged(int index) {