mirror of
https://github.com/subsurface/subsurface.git
synced 2024-12-03 15:43:09 +00:00
Filter: move number of shown dives to core
We mark hidden/shown dives in the core but store the number of shown dives in the MultiFilterSortModel. Move this datum to the core for improved locality. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
This commit is contained in:
parent
cbd98edb73
commit
2d09819ddf
5 changed files with 10 additions and 10 deletions
|
@ -899,6 +899,7 @@ void deselect_dive(struct dive *dive)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int shown_dives = 0;
|
||||||
void filter_dive(struct dive *d, bool shown)
|
void filter_dive(struct dive *d, bool shown)
|
||||||
{
|
{
|
||||||
if (!d)
|
if (!d)
|
||||||
|
|
|
@ -9,6 +9,7 @@ extern "C" {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
struct deco_state;
|
struct deco_state;
|
||||||
|
extern int shown_dives;
|
||||||
|
|
||||||
/* this is used for both git and xml format */
|
/* this is used for both git and xml format */
|
||||||
#define DATAFORMAT_VERSION 3
|
#define DATAFORMAT_VERSION 3
|
||||||
|
|
|
@ -2,6 +2,7 @@
|
||||||
#include "desktop-widgets/simplewidgets.h"
|
#include "desktop-widgets/simplewidgets.h"
|
||||||
#include "desktop-widgets/mainwindow.h"
|
#include "desktop-widgets/mainwindow.h"
|
||||||
#include "core/qthelper.h"
|
#include "core/qthelper.h"
|
||||||
|
#include "core/divelist.h"
|
||||||
#include "core/settings/qPrefUnit.h"
|
#include "core/settings/qPrefUnit.h"
|
||||||
|
|
||||||
#include <QDoubleSpinBox>
|
#include <QDoubleSpinBox>
|
||||||
|
@ -242,8 +243,7 @@ void FilterWidget2::filterDataChanged(const FilterData &data)
|
||||||
QString FilterWidget2::shownText()
|
QString FilterWidget2::shownText()
|
||||||
{
|
{
|
||||||
if (isActive())
|
if (isActive())
|
||||||
return tr("%L1/%L2 shown").arg(MultiFilterSortModel::instance()->divesDisplayed)
|
return tr("%L1/%L2 shown").arg(shown_dives).arg(dive_table.nr);
|
||||||
.arg(dive_table.nr);
|
|
||||||
else
|
else
|
||||||
return tr("%L1 dives").arg(dive_table.nr);
|
return tr("%L1 dives").arg(dive_table.nr);
|
||||||
}
|
}
|
||||||
|
|
|
@ -107,7 +107,6 @@ MultiFilterSortModel *MultiFilterSortModel::instance()
|
||||||
}
|
}
|
||||||
|
|
||||||
MultiFilterSortModel::MultiFilterSortModel(QObject *parent) : QSortFilterProxyModel(parent),
|
MultiFilterSortModel::MultiFilterSortModel(QObject *parent) : QSortFilterProxyModel(parent),
|
||||||
divesDisplayed(0),
|
|
||||||
diveSiteRefCount(0)
|
diveSiteRefCount(0)
|
||||||
{
|
{
|
||||||
setFilterKeyColumn(-1); // filter all columns
|
setFilterKeyColumn(-1); // filter all columns
|
||||||
|
@ -215,7 +214,7 @@ void MultiFilterSortModel::myInvalidate()
|
||||||
// as a consequence of the filterFinished signal right after the local scope.
|
// as a consequence of the filterFinished signal right after the local scope.
|
||||||
auto marker = diveListNotifier.enterCommand();
|
auto marker = diveListNotifier.enterCommand();
|
||||||
|
|
||||||
divesDisplayed = 0;
|
shown_dives = 0;
|
||||||
|
|
||||||
for (int i = 0; i < m->rowCount(QModelIndex()); ++i) {
|
for (int i = 0; i < m->rowCount(QModelIndex()); ++i) {
|
||||||
QModelIndex idx = m->index(i, 0, QModelIndex());
|
QModelIndex idx = m->index(i, 0, QModelIndex());
|
||||||
|
@ -233,7 +232,7 @@ void MultiFilterSortModel::myInvalidate()
|
||||||
}
|
}
|
||||||
bool show = showDive(d);
|
bool show = showDive(d);
|
||||||
if (show) {
|
if (show) {
|
||||||
divesDisplayed++;
|
shown_dives++;
|
||||||
showTrip = true;
|
showTrip = true;
|
||||||
}
|
}
|
||||||
m->setData(idx2, show, DiveTripModelBase::SHOWN_ROLE);
|
m->setData(idx2, show, DiveTripModelBase::SHOWN_ROLE);
|
||||||
|
@ -243,7 +242,7 @@ void MultiFilterSortModel::myInvalidate()
|
||||||
dive *d = m->data(idx, DiveTripModelBase::DIVE_ROLE).value<dive *>();
|
dive *d = m->data(idx, DiveTripModelBase::DIVE_ROLE).value<dive *>();
|
||||||
bool show = (d != NULL) && showDive(d);
|
bool show = (d != NULL) && showDive(d);
|
||||||
if (show)
|
if (show)
|
||||||
divesDisplayed++;
|
shown_dives++;
|
||||||
m->setData(idx, show, DiveTripModelBase::SHOWN_ROLE);
|
m->setData(idx, show, DiveTripModelBase::SHOWN_ROLE);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -278,7 +277,7 @@ bool MultiFilterSortModel::updateDive(struct dive *d)
|
||||||
bool changed = oldStatus != newStatus;
|
bool changed = oldStatus != newStatus;
|
||||||
if (changed) {
|
if (changed) {
|
||||||
filter_dive(d, newStatus);
|
filter_dive(d, newStatus);
|
||||||
divesDisplayed += newStatus - oldStatus;
|
shown_dives += newStatus - oldStatus;
|
||||||
}
|
}
|
||||||
return changed;
|
return changed;
|
||||||
}
|
}
|
||||||
|
@ -348,7 +347,7 @@ void MultiFilterSortModel::divesAdded(dive_trip *, bool, const QVector<dive *> &
|
||||||
{
|
{
|
||||||
for (dive *d: dives) {
|
for (dive *d: dives) {
|
||||||
if (!d->hidden_by_filter)
|
if (!d->hidden_by_filter)
|
||||||
++divesDisplayed;
|
++shown_dives;
|
||||||
}
|
}
|
||||||
countsChanged();
|
countsChanged();
|
||||||
}
|
}
|
||||||
|
@ -357,7 +356,7 @@ void MultiFilterSortModel::divesDeleted(dive_trip *, bool, const QVector<dive *>
|
||||||
{
|
{
|
||||||
for (dive *d: dives) {
|
for (dive *d: dives) {
|
||||||
if (!d->hidden_by_filter)
|
if (!d->hidden_by_filter)
|
||||||
--divesDisplayed;
|
--shown_dives;
|
||||||
}
|
}
|
||||||
countsChanged();
|
countsChanged();
|
||||||
}
|
}
|
||||||
|
|
|
@ -61,7 +61,6 @@ public:
|
||||||
bool filterAcceptsRow(int source_row, const QModelIndex &source_parent) const override;
|
bool filterAcceptsRow(int source_row, const QModelIndex &source_parent) const override;
|
||||||
bool showDive(const struct dive *d) const;
|
bool showDive(const struct dive *d) const;
|
||||||
bool updateDive(struct dive *d); // returns true if visibility status changed
|
bool updateDive(struct dive *d); // returns true if visibility status changed
|
||||||
int divesDisplayed;
|
|
||||||
bool lessThan(const QModelIndex &, const QModelIndex &) const override;
|
bool lessThan(const QModelIndex &, const QModelIndex &) const override;
|
||||||
bool diveSiteMode() const; // returns true if we're filtering on dive site
|
bool diveSiteMode() const; // returns true if we're filtering on dive site
|
||||||
const QVector<dive_site *> &filteredDiveSites() const;
|
const QVector<dive_site *> &filteredDiveSites() const;
|
||||||
|
|
Loading…
Reference in a new issue