From 59e602447b951cfdfabd8f0a067dfb8c804ee506 Mon Sep 17 00:00:00 2001 From: Berthold Stoeger Date: Tue, 12 Mar 2019 00:25:31 +0100 Subject: Dive site: inform model of dive site addition / deletion Introduce two DiveListNotifier signals which are sent by the undo commands if dives are added to / removed from the core. The signal has the dive site and the index in the global dive site table as payload. Thus, the model has only to remove the appropriate rows. Signed-off-by: Berthold Stoeger --- qt-models/divelocationmodel.cpp | 20 ++++++++++++++++++++ qt-models/divelocationmodel.h | 2 ++ 2 files changed, 22 insertions(+) (limited to 'qt-models') diff --git a/qt-models/divelocationmodel.cpp b/qt-models/divelocationmodel.cpp index 03c07a5e0..0a0eacaaf 100644 --- a/qt-models/divelocationmodel.cpp +++ b/qt-models/divelocationmodel.cpp @@ -25,6 +25,8 @@ LocationInformationModel *LocationInformationModel::instance() LocationInformationModel::LocationInformationModel(QObject *obj) : QAbstractTableModel(obj) { connect(&diveListNotifier, &DiveListNotifier::diveSiteDiveCountChanged, this, &LocationInformationModel::diveSiteDiveCountChanged); + connect(&diveListNotifier, &DiveListNotifier::diveSiteAdded, this, &LocationInformationModel::diveSiteAdded); + connect(&diveListNotifier, &DiveListNotifier::diveSiteDeleted, this, &LocationInformationModel::diveSiteDeleted); } int LocationInformationModel::columnCount(const QModelIndex &) const @@ -163,6 +165,24 @@ void LocationInformationModel::diveSiteDiveCountChanged(dive_site *ds) dataChanged(createIndex(idx, NUM_DIVES), createIndex(idx, NUM_DIVES)); } +void LocationInformationModel::diveSiteAdded(struct dive_site *, int idx) +{ + if (idx < 0) + return; + beginInsertRows(QModelIndex(), idx, idx); + // Row has already been added by Undo-Command. + endInsertRows(); +} + +void LocationInformationModel::diveSiteDeleted(struct dive_site *, int idx) +{ + if (idx < 0) + return; + beginRemoveRows(QModelIndex(), idx, idx); + // Row has already been added by Undo-Command. + endRemoveRows(); +} + GeoReferencingOptionsModel *GeoReferencingOptionsModel::instance() { static GeoReferencingOptionsModel *self = new GeoReferencingOptionsModel(); diff --git a/qt-models/divelocationmodel.h b/qt-models/divelocationmodel.h index 794056324..8f2e25190 100644 --- a/qt-models/divelocationmodel.h +++ b/qt-models/divelocationmodel.h @@ -34,6 +34,8 @@ public slots: void update(); QStringList allSiteNames() const; void diveSiteDiveCountChanged(struct dive_site *ds); + void diveSiteAdded(struct dive_site *ds, int idx); + void diveSiteDeleted(struct dive_site *ds, int idx); private: QStringList locationNames; }; -- cgit v1.2.3-70-g09d2