summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Berthold Stoeger <bstoeger@mail.tuwien.ac.at>2019-03-16 11:35:44 +0100
committerGravatar Dirk Hohndel <dirk@hohndel.org>2019-04-12 18:19:07 +0300
commitcd3a8ba354c67b322c07b3c29899bc1ad7d5887c (patch)
tree5ad0e51822c043d76db78d0c3415750ee287d229
parentd4282e2689ec8647e9deb842ac434f274218a63a (diff)
downloadsubsurface-cd3a8ba354c67b322c07b3c29899bc1ad7d5887c.tar.gz
Dive site: add edit field to dive site table
Add an edit column that calls the new editDiveSite() function of MainWindow. The calling code is in DiveSiteSortedModel. Quite illogical, but that's how TableView works, for now. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
-rw-r--r--desktop-widgets/mainwindow.cpp11
-rw-r--r--desktop-widgets/mainwindow.h1
-rw-r--r--qt-models/divelocationmodel.cpp27
-rw-r--r--qt-models/divelocationmodel.h2
4 files changed, 28 insertions, 13 deletions
diff --git a/desktop-widgets/mainwindow.cpp b/desktop-widgets/mainwindow.cpp
index 7c9cf9ba2..8c7124c7c 100644
--- a/desktop-widgets/mainwindow.cpp
+++ b/desktop-widgets/mainwindow.cpp
@@ -378,12 +378,19 @@ void MainWindow::setStateProperties(const QByteArray& state, const PropertyList&
stateProperties[state] = PropertiesForQuadrant(tl, tr, bl, br);
}
-void MainWindow::on_actionDiveSiteEdit_triggered()
+void MainWindow::editDiveSite(dive_site *ds)
{
- diveSiteEdit->initFields(get_dive_site_for_dive(&displayed_dive));
+ if (!ds)
+ return;
+ diveSiteEdit->initFields(ds);
setApplicationState("EditDiveSite");
}
+void MainWindow::on_actionDiveSiteEdit_triggered()
+{
+ editDiveSite(get_dive_site_for_dive(&displayed_dive));
+}
+
void MainWindow::enableDisableCloudActions()
{
ui.actionCloudstorageopen->setEnabled(prefs.cloud_verification_status == qPrefCloudStorage::CS_VERIFIED);
diff --git a/desktop-widgets/mainwindow.h b/desktop-widgets/mainwindow.h
index 859cafed1..4282938a6 100644
--- a/desktop-widgets/mainwindow.h
+++ b/desktop-widgets/mainwindow.h
@@ -82,6 +82,7 @@ public:
void enableDisableOtherDCsActions();
void enterEditState();
void exitEditState();
+ void editDiveSite(dive_site *ds);
MainTab *mainTab;
PlannerDetails *plannerDetails;
diff --git a/qt-models/divelocationmodel.cpp b/qt-models/divelocationmodel.cpp
index c18f85932..b01ae03b6 100644
--- a/qt-models/divelocationmodel.cpp
+++ b/qt-models/divelocationmodel.cpp
@@ -6,7 +6,7 @@
#include "core/divesite.h"
#include "core/metrics.h"
#ifndef SUBSURFACE_MOBILE
-#include "cleanertablemodel.h" // for trashIcon();
+#include "cleanertablemodel.h" // for trashIcon() and editIcon()
#include "desktop-widgets/mainwindow.h" // to place message box
#include "desktop-widgets/command.h"
#include <QMessageBox>
@@ -100,12 +100,14 @@ QVariant LocationInformationModel::getDiveSiteData(const struct dive_site *ds, i
break;
case Qt::ToolTipRole:
switch(column) {
+ case EDIT: return tr("Click here to edit the divesite.");
case REMOVE: return tr("Clicking here will remove this divesite.");
}
break;
case Qt::DecorationRole:
switch(column) {
#ifndef SUBSURFACE_MOBILE
+ case EDIT: return editIcon();
case REMOVE: return trashIcon();
#endif
case NAME: return dive_site_has_gps_location(ds) ? QIcon(":geotag-icon") : QVariant();
@@ -238,21 +240,26 @@ bool DiveSiteSortedModel::setData(const QModelIndex &index, const QVariant &valu
}
}
-// TODO: Remove from model. It doesn't make sense to call the model here, which calls the undo command,
+// TODO: Remove or edit. 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 = getDiveSite(index);
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});
+ 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;
+ }
}
#endif // SUBSURFACE_MOBILE
diff --git a/qt-models/divelocationmodel.h b/qt-models/divelocationmodel.h
index 60c5c993a..bca833a06 100644
--- a/qt-models/divelocationmodel.h
+++ b/qt-models/divelocationmodel.h
@@ -17,7 +17,7 @@ class LocationInformationModel : public QAbstractTableModel {
public:
// Common columns, roles and accessor function for all dive-site models.
// Thus, different views can connect to different models.
- enum Columns { REMOVE, NAME, DESCRIPTION, NUM_DIVES, LOCATION, NOTES, DIVESITE, TAXONOMY, COLUMNS};
+ enum Columns { EDIT, REMOVE, NAME, DESCRIPTION, NUM_DIVES, LOCATION, NOTES, DIVESITE, TAXONOMY, COLUMNS };
enum Roles { DIVESITE_ROLE = Qt::UserRole + 1 };
static QVariant getDiveSiteData(const struct dive_site *ds, int column, int role);