From 6f574c53a38ad848bfd364acb0ae16680c3f6c8a Mon Sep 17 00:00:00 2001 From: Berthold Stoeger Date: Wed, 20 Mar 2019 21:46:58 +0100 Subject: Undo: implement undo of dive site editing This one is a bit more tricky. There are two modes: set dive site and set newly created dive site. This is realized using an OO model with derived classed. Quite convoluted - but it seems to work. Moreover, editing a dive site is not simply setting a value, but the list of dives in a dive site has to be kept up to date. Finally, we have to inform the dive site list of the changed number of dives. Therefore add a new signal diveSiteDivesChanged. To send only one signal per dive site, hook into the undo() and redo() functions and call the functions of the base class there. Signed-off-by: Berthold Stoeger --- qt-models/divelocationmodel.cpp | 9 +++++++++ qt-models/divelocationmodel.h | 1 + 2 files changed, 10 insertions(+) (limited to 'qt-models') diff --git a/qt-models/divelocationmodel.cpp b/qt-models/divelocationmodel.cpp index b01ae03b6..fbeab7be8 100644 --- a/qt-models/divelocationmodel.cpp +++ b/qt-models/divelocationmodel.cpp @@ -27,6 +27,7 @@ LocationInformationModel::LocationInformationModel(QObject *obj) : QAbstractTabl connect(&diveListNotifier, &DiveListNotifier::diveSiteAdded, this, &LocationInformationModel::diveSiteAdded); connect(&diveListNotifier, &DiveListNotifier::diveSiteDeleted, this, &LocationInformationModel::diveSiteDeleted); connect(&diveListNotifier, &DiveListNotifier::diveSiteChanged, this, &LocationInformationModel::diveSiteChanged); + connect(&diveListNotifier, &DiveListNotifier::diveSiteDivesChanged, this, &LocationInformationModel::diveSiteDivesChanged); } int LocationInformationModel::columnCount(const QModelIndex &) const @@ -167,6 +168,14 @@ void LocationInformationModel::diveSiteChanged(struct dive_site *ds, int field) dataChanged(createIndex(idx, field), createIndex(idx, field)); } +void LocationInformationModel::diveSiteDivesChanged(struct dive_site *ds) +{ + int idx = get_divesite_idx(ds, &dive_site_table); + if (idx < 0) + return; + dataChanged(createIndex(idx, NUM_DIVES), createIndex(idx, NUM_DIVES)); +} + bool DiveSiteSortedModel::filterAcceptsRow(int sourceRow, const QModelIndex &source_parent) const { // TODO: filtering diff --git a/qt-models/divelocationmodel.h b/qt-models/divelocationmodel.h index bca833a06..9f1c4468b 100644 --- a/qt-models/divelocationmodel.h +++ b/qt-models/divelocationmodel.h @@ -35,6 +35,7 @@ public slots: void diveSiteAdded(struct dive_site *ds, int idx); void diveSiteDeleted(struct dive_site *ds, int idx); void diveSiteChanged(struct dive_site *ds, int field); + void diveSiteDivesChanged(struct dive_site *ds); }; class DiveSiteSortedModel : public QSortFilterProxyModel { -- cgit v1.2.3-70-g09d2