mirror of
https://github.com/subsurface/subsurface.git
synced 2025-02-19 22:16:15 +00:00
Filter: update counts if dives added / removed
Update the filter counts if dives were added removed by the undo commands. The undo commands call into the filter model at the right time so that hidden_by_filter is already set. The filter model keeps track of the counts and emits a signal, which is caught by the widget. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
This commit is contained in:
parent
3915e8a0d5
commit
c210bfc0e0
5 changed files with 33 additions and 8 deletions
|
@ -141,14 +141,6 @@ std::vector<dive *> DiveListBase::addDives(DivesAndTripsToAdd &toAdd)
|
||||||
std::vector<dive *> res;
|
std::vector<dive *> res;
|
||||||
res.resize(toAdd.dives.size());
|
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
|
// Now, add the dives
|
||||||
// Note: the idiomatic STL-way would be std::transform, but let's use a loop since
|
// Note: the idiomatic STL-way would be std::transform, but let's use a loop since
|
||||||
// that is closer to classical C-style.
|
// that is closer to classical C-style.
|
||||||
|
|
|
@ -96,6 +96,10 @@ FilterWidget2::FilterWidget2(QWidget* parent) : QWidget(parent)
|
||||||
// Update temperature fields if user changes temperature-units in preferences.
|
// Update temperature fields if user changes temperature-units in preferences.
|
||||||
connect(qPrefUnits::instance(), &qPrefUnits::temperatureChanged, this, &FilterWidget2::temperatureChanged);
|
connect(qPrefUnits::instance(), &qPrefUnits::temperatureChanged, this, &FilterWidget2::temperatureChanged);
|
||||||
connect(qPrefUnits::instance(), &qPrefUnits::unit_systemChanged, 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()
|
void FilterWidget2::temperatureChanged()
|
||||||
|
@ -161,7 +165,11 @@ void FilterWidget2::hideEvent(QHideEvent *event)
|
||||||
void FilterWidget2::filterDataChanged(const FilterData &data)
|
void FilterWidget2::filterDataChanged(const FilterData &data)
|
||||||
{
|
{
|
||||||
MultiFilterSortModel::instance()->filterDataChanged(data);
|
MultiFilterSortModel::instance()->filterDataChanged(data);
|
||||||
|
countsChanged();
|
||||||
|
}
|
||||||
|
|
||||||
|
void FilterWidget2::countsChanged()
|
||||||
|
{
|
||||||
ui.filterText->setText(tr("%L1/%L2 shown").arg(MultiFilterSortModel::instance()->divesDisplayed)
|
ui.filterText->setText(tr("%L1/%L2 shown").arg(MultiFilterSortModel::instance()->divesDisplayed)
|
||||||
.arg(dive_table.nr));
|
.arg(dive_table.nr));
|
||||||
}
|
}
|
||||||
|
|
|
@ -29,6 +29,7 @@ public slots:
|
||||||
void updateLogged(int value);
|
void updateLogged(int value);
|
||||||
private slots:
|
private slots:
|
||||||
void temperatureChanged();
|
void temperatureChanged();
|
||||||
|
void countsChanged();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Ui::FilterWidget2 ui;
|
Ui::FilterWidget2 ui;
|
||||||
|
|
|
@ -79,6 +79,9 @@ MultiFilterSortModel::MultiFilterSortModel(QObject *parent) : QSortFilterProxyMo
|
||||||
{
|
{
|
||||||
setFilterKeyColumn(-1); // filter all columns
|
setFilterKeyColumn(-1); // filter all columns
|
||||||
setFilterCaseSensitivity(Qt::CaseInsensitive);
|
setFilterCaseSensitivity(Qt::CaseInsensitive);
|
||||||
|
|
||||||
|
connect(&diveListNotifier, &DiveListNotifier::divesAdded, this, &MultiFilterSortModel::divesAdded);
|
||||||
|
connect(&diveListNotifier, &DiveListNotifier::divesDeleted, this, &MultiFilterSortModel::divesDeleted);
|
||||||
}
|
}
|
||||||
|
|
||||||
void MultiFilterSortModel::resetModel(DiveTripModelBase::Layout layout)
|
void MultiFilterSortModel::resetModel(DiveTripModelBase::Layout layout)
|
||||||
|
@ -235,3 +238,21 @@ void MultiFilterSortModel::filterDataChanged(const FilterData &data)
|
||||||
filterData = data;
|
filterData = data;
|
||||||
myInvalidate();
|
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();
|
||||||
|
}
|
||||||
|
|
|
@ -57,9 +57,12 @@ slots:
|
||||||
void filterChanged(const QModelIndex &from, const QModelIndex &to, const QVector<int> &roles);
|
void filterChanged(const QModelIndex &from, const QModelIndex &to, const QVector<int> &roles);
|
||||||
void resetModel(DiveTripModelBase::Layout layout);
|
void resetModel(DiveTripModelBase::Layout layout);
|
||||||
void filterDataChanged(const FilterData &data);
|
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:
|
signals:
|
||||||
void filterFinished();
|
void filterFinished();
|
||||||
|
void countsChanged();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
MultiFilterSortModel(QObject *parent = 0);
|
MultiFilterSortModel(QObject *parent = 0);
|
||||||
|
|
Loading…
Add table
Reference in a new issue