diff options
-rw-r--r-- | desktop-widgets/command_divelist.cpp | 8 | ||||
-rw-r--r-- | desktop-widgets/filterwidget2.cpp | 8 | ||||
-rw-r--r-- | desktop-widgets/filterwidget2.h | 1 | ||||
-rw-r--r-- | qt-models/filtermodels.cpp | 21 | ||||
-rw-r--r-- | qt-models/filtermodels.h | 3 |
5 files changed, 33 insertions, 8 deletions
diff --git a/desktop-widgets/command_divelist.cpp b/desktop-widgets/command_divelist.cpp index cf8feed0b..f45202aa9 100644 --- a/desktop-widgets/command_divelist.cpp +++ b/desktop-widgets/command_divelist.cpp @@ -141,14 +141,6 @@ std::vector<dive *> DiveListBase::addDives(DivesAndTripsToAdd &toAdd) std::vector<dive *> res; res.resize(toAdd.dives.size()); - // First, tell the filters that new dives are added. We do this here - // instead of later by signals, so that the filter can set the - // checkboxes of the new rows to its liking. The added dives will - // then appear in the correct shown/hidden state. - QVector<dive *> divesForFilter; - for (const DiveToAdd &entry: toAdd.dives) - divesForFilter.push_back(entry.dive.get()); - // 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. diff --git a/desktop-widgets/filterwidget2.cpp b/desktop-widgets/filterwidget2.cpp index 9eb4f733b..028f774f1 100644 --- a/desktop-widgets/filterwidget2.cpp +++ b/desktop-widgets/filterwidget2.cpp @@ -96,6 +96,10 @@ FilterWidget2::FilterWidget2(QWidget* parent) : QWidget(parent) // Update temperature fields if user changes temperature-units in preferences. connect(qPrefUnits::instance(), &qPrefUnits::temperatureChanged, this, &FilterWidget2::temperatureChanged); connect(qPrefUnits::instance(), &qPrefUnits::unit_systemChanged, this, &FilterWidget2::temperatureChanged); + + // Update counts if dives were added / removed + connect(MultiFilterSortModel::instance(), &MultiFilterSortModel::countsChanged, + this, &FilterWidget2::countsChanged); } void FilterWidget2::temperatureChanged() @@ -161,7 +165,11 @@ void FilterWidget2::hideEvent(QHideEvent *event) void FilterWidget2::filterDataChanged(const FilterData &data) { MultiFilterSortModel::instance()->filterDataChanged(data); + countsChanged(); +} +void FilterWidget2::countsChanged() +{ ui.filterText->setText(tr("%L1/%L2 shown").arg(MultiFilterSortModel::instance()->divesDisplayed) .arg(dive_table.nr)); } diff --git a/desktop-widgets/filterwidget2.h b/desktop-widgets/filterwidget2.h index ab388ba6a..23d08dd2a 100644 --- a/desktop-widgets/filterwidget2.h +++ b/desktop-widgets/filterwidget2.h @@ -29,6 +29,7 @@ public slots: void updateLogged(int value); private slots: void temperatureChanged(); + void countsChanged(); private: Ui::FilterWidget2 ui; diff --git a/qt-models/filtermodels.cpp b/qt-models/filtermodels.cpp index 53149eba2..5168e32d8 100644 --- a/qt-models/filtermodels.cpp +++ b/qt-models/filtermodels.cpp @@ -79,6 +79,9 @@ 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) @@ -235,3 +238,21 @@ void MultiFilterSortModel::filterDataChanged(const FilterData &data) filterData = data; myInvalidate(); } + +void MultiFilterSortModel::divesAdded(dive_trip *, bool, const QVector<dive *> &dives) +{ + for (dive *d: dives) { + if (!d->hidden_by_filter) + ++divesDisplayed; + } + emit countsChanged(); +} + +void MultiFilterSortModel::divesDeleted(dive_trip *, bool, const QVector<dive *> &dives) +{ + for (dive *d: dives) { + if (!d->hidden_by_filter) + --divesDisplayed; + } + emit countsChanged(); +} diff --git a/qt-models/filtermodels.h b/qt-models/filtermodels.h index 1925bc422..faaae8c2f 100644 --- a/qt-models/filtermodels.h +++ b/qt-models/filtermodels.h @@ -57,9 +57,12 @@ slots: void filterChanged(const QModelIndex &from, const QModelIndex &to, const QVector<int> &roles); 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(); + void countsChanged(); private: MultiFilterSortModel(QObject *parent = 0); |