diff options
author | Berthold Stoeger <bstoeger@mail.tuwien.ac.at> | 2019-11-02 22:52:27 +0100 |
---|---|---|
committer | Dirk Hohndel <dirk@hohndel.org> | 2019-12-05 10:14:25 -0800 |
commit | b3253304a59b85c76f8a70f20ada4139e715a5b3 (patch) | |
tree | 8e21ae9d46d9d6ed1f651b7b6008512ae1fd622d /desktop-widgets/tab-widgets/TabDiveSite.cpp | |
parent | 147a36647ce6148ef2eccbe393faa658d0fe6834 (diff) | |
download | subsurface-b3253304a59b85c76f8a70f20ada4139e715a5b3.tar.gz |
Desktop: don't connect to remove() slot of model from TableModel
When connecting a model to the TableModel class, it would connect
clicking on an item to the remove() slot of the model.
This breaks the program flow implied by the undo code:
Ui --> Undo-Command --> Model --> UI
Moreover, the naming of the remove() slot is illogical, because
clicks can also have different effects, as for example in the
cylinder-table.
Therefore, move the connect() call from TableModel to the
callers. In the case of TabDiveSite, move the remove() function
from the model to the TabWidget, where it makes more sense.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Diffstat (limited to 'desktop-widgets/tab-widgets/TabDiveSite.cpp')
-rw-r--r-- | desktop-widgets/tab-widgets/TabDiveSite.cpp | 24 |
1 files changed, 23 insertions, 1 deletions
diff --git a/desktop-widgets/tab-widgets/TabDiveSite.cpp b/desktop-widgets/tab-widgets/TabDiveSite.cpp index 3ff693e59..9e269ee26 100644 --- a/desktop-widgets/tab-widgets/TabDiveSite.cpp +++ b/desktop-widgets/tab-widgets/TabDiveSite.cpp @@ -4,9 +4,10 @@ #include "core/divesite.h" #include "core/divefilter.h" #include "qt-models/divelocationmodel.h" +#include "desktop-widgets/mainwindow.h" // to place message box #include "commands/command.h" -#include <qt-models/divecomputerextradatamodel.h> +#include <QMessageBox> TabDiveSite::TabDiveSite(QWidget *parent) : TabBase(parent) { @@ -25,6 +26,7 @@ TabDiveSite::TabDiveSite(QWidget *parent) : TabBase(parent) ui.diveSites->view()->setColumnHidden(i, true); connect(ui.diveSites, &TableView::addButtonClicked, this, &TabDiveSite::add); + connect(ui.diveSites, &TableView::itemClicked, this, &TabDiveSite::diveSiteClicked); connect(ui.diveSites->view()->selectionModel(), &QItemSelectionModel::selectionChanged, this, &TabDiveSite::selectionChanged); // Subtle: We depend on this slot being executed after the slot in the model. @@ -40,6 +42,26 @@ void TabDiveSite::clear() { } +void TabDiveSite::diveSiteClicked(const QModelIndex &index) +{ + struct dive_site *ds = model.getDiveSite(index); + if (!ds) + return; + switch (index.column()) { + case LocationInformationModel::EDIT: + MainWindow::instance()->editDiveSite(ds); + break; + case LocationInformationModel::REMOVE: + if (ds->dives.nr > 0 && + QMessageBox::warning(MainWindow::instance(), tr("Delete dive site?"), + tr("This dive site has %n dive(s). Do you really want to delete it?\n", "", ds->dives.nr), + QMessageBox::Yes|QMessageBox::No) == QMessageBox::No) + return; + Command::deleteDiveSites(QVector<dive_site *>{ds}); + break; + } +} + void TabDiveSite::add() { // This is mighty dirty: We hook into the "dive site added" signal and |