diff options
Diffstat (limited to 'qt-models')
-rw-r--r-- | qt-models/divelocationmodel.cpp | 25 | ||||
-rw-r--r-- | qt-models/divelocationmodel.h | 2 |
2 files changed, 26 insertions, 1 deletions
diff --git a/qt-models/divelocationmodel.cpp b/qt-models/divelocationmodel.cpp index 383de43ca..ebdffc185 100644 --- a/qt-models/divelocationmodel.cpp +++ b/qt-models/divelocationmodel.cpp @@ -5,8 +5,12 @@ #include "core/qthelper.h" #include "core/divesite.h" #include "core/metrics.h" +#ifndef SUBSURFACE_MOBILE #include "cleanertablemodel.h" // for trashIcon(); -#include <QDebug> +#include "desktop-widgets/mainwindow.h" // to place message box +#include "desktop-widgets/command.h" +#include <QMessageBox> +#endif #include <QLineEdit> #include <QIcon> #include <core/gettextfromc.h> @@ -219,6 +223,25 @@ QStringList DiveSiteSortedModel::allSiteNames() const return locationNames; } +#ifndef SUBSURFACE_MOBILE +// TODO: Remove from model. It doesn't make sense to call the model here, which calls the undo command, +// which in turn calls the model. +void DiveSiteSortedModel::remove(const QModelIndex &index) +{ + if (index.column() != LocationInformationModel::REMOVE) + return; + struct dive_site *ds = get_dive_site(mapToSource(index).row(), &dive_site_table); + if (!ds) + return; + 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}); +} +#endif + GeoReferencingOptionsModel *GeoReferencingOptionsModel::instance() { static GeoReferencingOptionsModel *self = new GeoReferencingOptionsModel(); diff --git a/qt-models/divelocationmodel.h b/qt-models/divelocationmodel.h index f2bcc7cf7..34ac34c04 100644 --- a/qt-models/divelocationmodel.h +++ b/qt-models/divelocationmodel.h @@ -42,6 +42,8 @@ class DiveSiteSortedModel : public QSortFilterProxyModel { private: bool filterAcceptsRow(int sourceRow, const QModelIndex &source_parent) const override; bool lessThan(const QModelIndex &i1, const QModelIndex &i2) const override; +public slots: + void remove(const QModelIndex &index); public: DiveSiteSortedModel(); QStringList allSiteNames() const; |