Cockatrice 2026-09-01-Development-3.1.0-beta.10
A virtual tabletop for multiplayer card games
Loading...
Searching...
No Matches
settings_search_model.h
Go to the documentation of this file.
1
6#ifndef COCKATRICE_SETTINGS_SEARCH_MODEL_H
7#define COCKATRICE_SETTINGS_SEARCH_MODEL_H
8
9#include <QAbstractListModel>
10#include <QList>
11#include <QRegularExpression>
12#include <QWidget>
13
21{
23 QString groupTitle;
24 QString widgetLabel;
26 QWidget *widget;
27};
28
36class SettingsSearchModel : public QAbstractListModel
37{
38 Q_OBJECT
39public:
43 enum Roles
44 {
45 EntryRole = Qt::UserRole + 1,
46 };
47
48 explicit SettingsSearchModel(QObject *parent = nullptr);
49
51 void setSourceEntries(const QList<SettingsSearchEntry> &entries);
53 void setFilterString(const QString &text);
55 bool isFilterActive() const;
56
57 int rowCount(const QModelIndex &parent = QModelIndex()) const override;
58 QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
59
61 SettingsSearchEntry entryForIndex(const QModelIndex &index) const;
62
63private:
64 QList<SettingsSearchEntry> sourceEntries;
65 QList<int> filteredIndices;
66 QRegularExpression filterRegex;
67 QString filterQuery;
68 bool filterActive = false;
69
71 void rebuildFilter();
72};
73
74Q_DECLARE_METATYPE(SettingsSearchEntry)
75
76#endif // COCKATRICE_SETTINGS_SEARCH_MODEL_H
bool isFilterActive() const
Whether a non-empty filter is currently active.
Definition settings_search_model.cpp:34
QList< SettingsSearchEntry > sourceEntries
Complete unfiltered entry list.
Definition settings_search_model.h:64
Roles
Custom data role for accessing the full entry.
Definition settings_search_model.h:44
@ EntryRole
Full SettingsSearchEntry object.
Definition settings_search_model.h:45
void setSourceEntries(const QList< SettingsSearchEntry > &entries)
Replaces the source entries and rebuilds the filter.
Definition settings_search_model.cpp:15
QVariant data(const QModelIndex &index, int role=Qt::DisplayRole) const override
Definition settings_search_model.cpp:118
QString filterQuery
Current filter query string.
Definition settings_search_model.h:67
SettingsSearchEntry entryForIndex(const QModelIndex &index) const
Returns the full entry for a given model index.
Definition settings_search_model.cpp:139
SettingsSearchModel(QObject *parent=nullptr)
Definition settings_search_model.cpp:11
void setFilterString(const QString &text)
Sets the filter string and recalculates the results.
Definition settings_search_model.cpp:23
int rowCount(const QModelIndex &parent=QModelIndex()) const override
Definition settings_search_model.cpp:110
QRegularExpression filterRegex
Compiled regex for the current filter.
Definition settings_search_model.h:66
void rebuildFilter()
Recalculates the filtered index list and ranking.
Definition settings_search_model.cpp:80
QList< int > filteredIndices
Indices into sourceEntries matching the filter.
Definition settings_search_model.h:65
bool filterActive
Whether filtering is active.
Definition settings_search_model.h:68
Represents a single searchable setting entry.
Definition settings_search_model.h:21
QWidget * widget
Pointer to the setting widget for focus/scrolling.
Definition settings_search_model.h:26
QString groupTitle
Title of the group/section within the page.
Definition settings_search_model.h:23
int pageIndex
Index of the settings page this entry belongs to.
Definition settings_search_model.h:22
QString widgetLabel
Display label for the setting widget.
Definition settings_search_model.h:24
QString fullSearchText
Extended search text (label, control text, tooltip) for full-text matching.
Definition settings_search_model.h:25