cleanup: move shown-text calculation from filter widget to core

The filter widget was caching whether the filter was active and
used that flag to calculate the "# dives shown" string. Move this
directly to the DiveFilter class to remove interdependencies and
to unify with mobile.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
This commit is contained in:
Berthold Stoeger 2020-06-22 14:05:46 +02:00 committed by Dirk Hohndel
parent 68fffc2672
commit 38b686687f
5 changed files with 12 additions and 14 deletions

View file

@ -2,6 +2,7 @@
#include "divefilter.h" #include "divefilter.h"
#include "divelist.h" // for filter_dive #include "divelist.h" // for filter_dive
#include "gettextfromc.h"
#include "qthelper.h" #include "qthelper.h"
#include "subsurface-qt/divelistnotifier.h" #include "subsurface-qt/divelistnotifier.h"
#ifndef SUBSURFACE_MOBILE #ifndef SUBSURFACE_MOBILE
@ -151,6 +152,14 @@ bool DiveFilter::diveSiteMode() const
} }
#endif #endif
QString DiveFilter::shownText() const
{
if (diveSiteMode() || filterData.validFilter())
return gettextFromC::tr("%L1/%L2 shown").arg(shown_dives).arg(dive_table.nr);
else
return gettextFromC::tr("%L1 dives").arg(dive_table.nr);
}
void DiveFilter::setFilter(const FilterData &data) void DiveFilter::setFilter(const FilterData &data)
{ {
filterData = data; filterData = data;

View file

@ -38,6 +38,7 @@ class DiveFilter {
public: public:
static DiveFilter *instance(); static DiveFilter *instance();
QString shownText() const;
bool diveSiteMode() const; // returns true if we're filtering on dive site (on mobile always returns false) bool diveSiteMode() const; // returns true if we're filtering on dive site (on mobile always returns false)
#ifndef SUBSURFACE_MOBILE #ifndef SUBSURFACE_MOBILE
const QVector<dive_site *> &filteredDiveSites() const; const QVector<dive_site *> &filteredDiveSites() const;

View file

@ -10,8 +10,7 @@
FilterWidget2::FilterWidget2(QWidget* parent) : FilterWidget2::FilterWidget2(QWidget* parent) :
QWidget(parent), QWidget(parent),
ignoreSignal(false), ignoreSignal(false)
validFilter(false)
{ {
ui.setupUi(this); ui.setupUi(this);
@ -194,7 +193,6 @@ void FilterWidget2::updateFilter()
return; return;
FilterData filterData = createFilterData(); FilterData filterData = createFilterData();
validFilter = filterData.validFilter();
DiveFilter::instance()->setFilter(filterData); DiveFilter::instance()->setFilter(filterData);
} }
@ -227,11 +225,3 @@ void FilterWidget2::addConstraint(filter_constraint_type type)
{ {
constraintModel.addConstraint(type); constraintModel.addConstraint(type);
} }
QString FilterWidget2::shownText()
{
if (validFilter)
return tr("%L1/%L2 shown").arg(shown_dives).arg(dive_table.nr);
else
return tr("%L1 dives").arg(dive_table.nr);
}

View file

@ -20,7 +20,6 @@ class FilterWidget2 : public QWidget {
public: public:
explicit FilterWidget2(QWidget *parent = 0); explicit FilterWidget2(QWidget *parent = 0);
~FilterWidget2(); ~FilterWidget2();
QString shownText();
protected: protected:
void hideEvent(QHideEvent *event) override; void hideEvent(QHideEvent *event) override;
@ -43,7 +42,6 @@ private:
bool ignoreSignal; bool ignoreSignal;
Ui::FilterWidget2 ui; Ui::FilterWidget2 ui;
FilterConstraintModel constraintModel; FilterConstraintModel constraintModel;
bool validFilter;
void addConstraint(filter_constraint_type type); void addConstraint(filter_constraint_type type);
std::vector<std::unique_ptr<FilterConstraintWidget>> constraintWidgets; std::vector<std::unique_ptr<FilterConstraintWidget>> constraintWidgets;
FilterData createFilterData() const; FilterData createFilterData() const;

View file

@ -1536,7 +1536,7 @@ void MainWindow::setTitle()
} }
QString unsaved = (unsavedChanges() ? " *" : ""); QString unsaved = (unsavedChanges() ? " *" : "");
QString shown = QString(" (%1)").arg(filterWidget2.shownText()); QString shown = QString(" (%1)").arg(DiveFilter::instance()->shownText());
setWindowTitle("Subsurface: " + displayedFilename(existing_filename) + unsaved + shown); setWindowTitle("Subsurface: " + displayedFilename(existing_filename) + unsaved + shown);
} }