summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Berthold Stoeger <bstoeger@mail.tuwien.ac.at>2019-11-17 17:41:23 +0100
committerGravatar Dirk Hohndel <dirk@hohndel.org>2019-11-19 21:13:40 -0800
commit6d6d10f03a92a9bac5394fc226c398af61f29d66 (patch)
tree55cc04e1ddfc0174973f6ad7e496aa80e07523f9
parent2d09819ddfc6bbb4eb9bd7127485f42c839fd85b (diff)
downloadsubsurface-6d6d10f03a92a9bac5394fc226c398af61f29d66.tar.gz
Filter: move calculation of shown dives to undo command
The filter-model was catching dives-added / dives-deleted signals from the models to keep track of the number of shown dives. To simplify the data flow, do this directly in the undo-command. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
-rw-r--r--commands/command_divelist.cpp19
-rw-r--r--core/subsurface-qt/DiveListNotifier.h3
-rw-r--r--desktop-widgets/mainwindow.cpp1
-rw-r--r--qt-models/filtermodels.cpp21
-rw-r--r--qt-models/filtermodels.h2
5 files changed, 23 insertions, 23 deletions
diff --git a/commands/command_divelist.cpp b/commands/command_divelist.cpp
index 4b4ef4ab8..9943651eb 100644
--- a/commands/command_divelist.cpp
+++ b/commands/command_divelist.cpp
@@ -40,6 +40,9 @@ DiveToAdd DiveListBase::removeDive(struct dive *d, std::vector<OwningTripPtr> &t
if (idx < 0)
qWarning("Deletion of unknown dive!");
+ if (!d->hidden_by_filter)
+ --shown_dives;
+
res.dive.reset(unregister_dive(idx)); // Remove dive from backend
return res;
@@ -67,6 +70,8 @@ dive *DiveListBase::addDive(DiveToAdd &d)
// Set the filter flag according to current filter settings
bool show = MultiFilterSortModel::instance()->showDive(res);
res->hidden_by_filter = !show;
+ if (show)
+ ++shown_dives;
int idx = dive_table_get_insertion_index(&dive_table, res);
add_to_dive_table(&dive_table, idx, res); // Return ownership to backend
@@ -118,6 +123,9 @@ DivesAndTripsToAdd DiveListBase::removeDives(DivesAndSitesToRemove &divesAndSite
divesToAdd.reserve(divesAndSitesToDelete.dives.size());
sitesToAdd.reserve(divesAndSitesToDelete.sites.size());
+ // Remember old number of shown dives
+ int oldShown = shown_dives;
+
// Make sure that the dive list is sorted. The added dives will be sent in a signal
// and the recipients assume that the dives are sorted the same way as they are
// in the core list.
@@ -149,6 +157,10 @@ DivesAndTripsToAdd DiveListBase::removeDives(DivesAndSitesToRemove &divesAndSite
{ return ptr.get() == trip; }) != tripsToAdd.end();
emit diveListNotifier.divesDeleted(trip, deleteTrip, divesInTrip);
});
+
+ if (oldShown != shown_dives)
+ emit diveListNotifier.numShownChanged();
+
return { std::move(divesToAdd), std::move(tripsToAdd), std::move(sitesToAdd) };
}
@@ -172,6 +184,9 @@ DivesAndSitesToRemove DiveListBase::addDives(DivesAndTripsToAdd &toAdd)
[](const DiveToAdd &d, const DiveToAdd &d2)
{ return dive_less_than(d.dive.get(), d2.dive.get()); });
+ // Remember old number of shown dives
+ int oldShown = shown_dives;
+
// Now, add the dives
// Note: the idiomatic STL-way would be std::transform, but let's use a loop since
// that is closer to classical C-style.
@@ -207,6 +222,10 @@ DivesAndSitesToRemove DiveListBase::addDives(DivesAndTripsToAdd &toAdd)
// Finally, emit the signal
emit diveListNotifier.divesAdded(trip, createTrip, divesInTrip);
});
+
+ if (oldShown != shown_dives)
+ emit diveListNotifier.numShownChanged();
+
return { res, sites };
}
diff --git a/core/subsurface-qt/DiveListNotifier.h b/core/subsurface-qt/DiveListNotifier.h
index cda7ea335..475f2ddbe 100644
--- a/core/subsurface-qt/DiveListNotifier.h
+++ b/core/subsurface-qt/DiveListNotifier.h
@@ -92,6 +92,9 @@ signals:
void diveSiteChanged(dive_site *ds, int field); // field according to LocationInformationModel
void diveSiteDivesChanged(dive_site *ds); // The dives associated with that site changed
+ // Filter-related signals
+ void numShownChanged();
+
// This signal is emited every time a command is executed.
// This is used to hide an old multi-dives-edited warning message.
// This is necessary, so that the user can't click on the "undo" button and undo
diff --git a/desktop-widgets/mainwindow.cpp b/desktop-widgets/mainwindow.cpp
index 7b3120ca4..41369f8ec 100644
--- a/desktop-widgets/mainwindow.cpp
+++ b/desktop-widgets/mainwindow.cpp
@@ -214,6 +214,7 @@ MainWindow::MainWindow() : QMainWindow(),
connect(this, &MainWindow::showError, ui.mainErrorMessage, &NotificationWidget::showError, Qt::AutoConnection);
connect(&windowTitleUpdate, &WindowTitleUpdate::updateTitle, this, &MainWindow::setAutomaticTitle);
+ connect(&diveListNotifier, &DiveListNotifier::numShownChanged, this, &MainWindow::setAutomaticTitle);
#ifdef NO_PRINTING
plannerDetails->printPlan()->hide();
ui.menuFile->removeAction(ui.actionPrint);
diff --git a/qt-models/filtermodels.cpp b/qt-models/filtermodels.cpp
index 7a1a8af7d..9736d3335 100644
--- a/qt-models/filtermodels.cpp
+++ b/qt-models/filtermodels.cpp
@@ -111,9 +111,6 @@ MultiFilterSortModel::MultiFilterSortModel(QObject *parent) : QSortFilterProxyMo
{
setFilterKeyColumn(-1); // filter all columns
setFilterCaseSensitivity(Qt::CaseInsensitive);
-
- connect(&diveListNotifier, &DiveListNotifier::divesAdded, this, &MultiFilterSortModel::divesAdded);
- connect(&diveListNotifier, &DiveListNotifier::divesDeleted, this, &MultiFilterSortModel::divesDeleted);
}
void MultiFilterSortModel::resetModel(DiveTripModelBase::Layout layout)
@@ -343,24 +340,6 @@ void MultiFilterSortModel::filterDataChanged(const FilterData &data)
myInvalidate();
}
-void MultiFilterSortModel::divesAdded(dive_trip *, bool, const QVector<dive *> &dives)
-{
- for (dive *d: dives) {
- if (!d->hidden_by_filter)
- ++shown_dives;
- }
- countsChanged();
-}
-
-void MultiFilterSortModel::divesDeleted(dive_trip *, bool, const QVector<dive *> &dives)
-{
- for (dive *d: dives) {
- if (!d->hidden_by_filter)
- --shown_dives;
- }
- countsChanged();
-}
-
void MultiFilterSortModel::countsChanged()
{
updateWindowTitle();
diff --git a/qt-models/filtermodels.h b/qt-models/filtermodels.h
index a3397dde6..d4a03d134 100644
--- a/qt-models/filtermodels.h
+++ b/qt-models/filtermodels.h
@@ -72,8 +72,6 @@ slots:
void stopFilterDiveSites();
void resetModel(DiveTripModelBase::Layout layout);
void filterDataChanged(const FilterData &data);
- void divesAdded(struct dive_trip *, bool, const QVector<dive *> &dives);
- void divesDeleted(struct dive_trip *, bool, const QVector<dive *> &dives);
signals:
void filterFinished();