game_launcher 1.1.0
Modern Linux game launcher with Steam / Proton / Wine integration
Loading...
Searching...
No Matches
game_list_proxy_model.h
Go to the documentation of this file.
1// SPDX-License-Identifier: MIT
2// ==============================================================================
3// ui/qt/game_list_proxy_model.h
4// ==============================================================================
5// QSortFilterProxyModel layered on top of GameListModel. Filters by category,
6// source, runner version, search text, and collection. Sorts by name or
7// various statistics.
8// ==============================================================================
9// Design: filters are *additive* (AND'd together). Empty filter = pass-through.
10// Source model row order is preserved within a filter.
11// Updates: when a filter setter runs we call beginFilterChange / endFilterChange
12// (Qt 6.9+ API) to replace the older invalidateFilter(), which is slated for
13// deprecation in Qt 6.13. Build-gated so 6.8 LTS users still compile.
14// ==============================================================================
15
16#pragma once
17
18#include <QSortFilterProxyModel>
19#include <QString>
20#include <QStringList>
21
22class GameListProxyModel : public QSortFilterProxyModel
23{
24 Q_OBJECT
25
26 public:
27 enum class SortKey
28 {
29 Name, // A-Z by game name (case-insensitive)
30 RecentlyPlayed, // newest lastPlayed first
31 MostPlayed, // highest totalPlayTimeSeconds first
32 Recent, // highest dateAdded first
33 };
34
35 explicit GameListProxyModel(QObject* parent = nullptr);
36
37 // ==========================================================================
38 // Filter setters. Each triggers a re-evaluation.
39 // ==========================================================================
40
41 /// Free-text search (matches against name, developer, publisher).
42 /// Empty string clears the filter.
43 void setSearchText(const QString& text);
44
45 /// Restrict to a specific source name ("Steam", "GOG", etc.) or empty for all.
46 void setSourceFilter(const QString& source);
47
48 /// Restrict to a specific runner version ("proton-ge-9", "Wine 9.0", etc.).
49 void setRunnerFilter(const QString& runner);
50
51 /// Restrict to a collection name, or empty for all.
52 void setCollectionFilter(const QString& collection);
53
54 /// Additional booleans applied on top of the main filters.
55 void setShowRunningOnly(bool running);
56 void setShowUpdatesOnlyGame(bool updatesOnly);
57 void setShowFavoritesOnly(bool favoritesOnly);
58
59 /// Reset all filters in one shot.
60 void clearAllFilters();
61
62 // ==========================================================================
63 // Sort configuration
64 // ==========================================================================
65
66 void setSortKey(SortKey key);
68 {
69 return sortKey_;
70 }
71
72 protected:
73 bool filterAcceptsRow(int sourceRow, const QModelIndex& sourceParent) const override;
74 bool lessThan(const QModelIndex& left, const QModelIndex& right) const override;
75
76 private:
77 void reapplyFilter();
78
79 QString searchText_;
80 QString sourceFilter_;
81 QString runnerFilter_;
82 QString collectionFilter_;
83 bool showRunningOnly_ = false;
84 bool showUpdatesOnly_ = false;
85 bool showFavoritesOnly_ = false;
86 SortKey sortKey_ = SortKey::Name;
87};
void setRunnerFilter(const QString &runner)
Restrict to a specific runner version ("proton-ge-9", "Wine 9.0", etc.).
void setShowRunningOnly(bool running)
Additional booleans applied on top of the main filters.
GameListProxyModel(QObject *parent=nullptr)
bool lessThan(const QModelIndex &left, const QModelIndex &right) const override
void setSourceFilter(const QString &source)
Restrict to a specific source name ("Steam", "GOG", etc.) or empty for all.
void setCollectionFilter(const QString &collection)
Restrict to a collection name, or empty for all.
void setShowFavoritesOnly(bool favoritesOnly)
void setSearchText(const QString &text)
Free-text search (matches against name, developer, publisher).
bool filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const override
void setShowUpdatesOnlyGame(bool updatesOnly)
void clearAllFilters()
Reset all filters in one shot.