// SPDX-License-Identifier: GPL-2.0 // A class that filters dives. #ifndef DIVE_FILTER_H #define DIVE_FILTER_H #include "fulltext.h" #include "filterconstraint.h" #include #include #include struct dive; struct dive_trip; struct dive_site; // Structure describing changes of shown status upon applying the filter struct ShownChange { QVector newShown; QVector newHidden; bool currentChanged; }; struct FilterData { // The mode ids are chosen such that they can be directly converted from / to combobox indices. enum class Mode { ALL_OF = 0, ANY_OF = 1, NONE_OF = 2 }; FullTextQuery fullText; StringFilterMode fulltextStringMode = StringFilterMode::STARTSWITH; std::vector constraints; bool validFilter() const; bool operator==(const FilterData &) const; }; class DiveFilter { public: static DiveFilter *instance(); void reset(); QString shownText() const; int shownDives() const; bool diveSiteMode() const; // returns true if we're filtering on dive site (on mobile always returns false) std::vector visibleDives() const; #ifndef SUBSURFACE_MOBILE const QVector &filteredDiveSites() const; void startFilterDiveSites(QVector ds); void setFilterDiveSite(QVector ds); void stopFilterDiveSites(); #endif void setFilter(const FilterData &data); ShownChange update(const QVector &dives) const; // Update filter status of given dives and return dives whose status changed ShownChange updateAll() const; // Update filter status of all dives and return dives whose status changed void diveRemoved(const dive *dive) const; // Dive was removed; update count accordingly private: DiveFilter(); bool showDive(const struct dive *d) const; // Should that dive be shown? bool setFilterStatus(struct dive *d, bool shown) const; void updateDiveStatus(dive *d, bool newStatus, ShownChange &change) const; QVector dive_sites; FilterData filterData; mutable int shown_dives; // We use ref-counting for the dive site mode. The reason is that when switching // between two tabs that both need dive site mode, the following course of // events may happen: // 1) The new tab appears -> enter dive site mode. // 2) The old tab gets its hide() signal -> exit dive site mode. // The filter is now not in dive site mode, even if it should int diveSiteRefCount; }; #endif