Cockatrice 2026-10-19-Development-3.1.2-beta.2
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 <QByteArray>
11#include <QList>
12#include <QMetaType>
13#include <QModelIndex>
14#include <QRegularExpression>
15#include <QString>
16#include <qnamespace.h>
17#include <qtmetamacros.h>
18
19class QObject;
20class QWidget;
21
29{
31 QString groupTitle;
32 QString widgetLabel;
34 QWidget *widget;
35};
36
44class SettingsSearchModel : public QAbstractListModel
45{
46 Q_OBJECT
47public:
51 enum Roles
52 {
53 EntryRole = Qt::UserRole + 1,
54 };
55
56 explicit SettingsSearchModel(QObject *parent = nullptr);
57
61 void setFilterString(const QString &text);
63 bool isFilterActive() const;
64
65 int rowCount(const QModelIndex &parent = QModelIndex()) const override;
66 QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
67
69 SettingsSearchEntry entryForIndex(const QModelIndex &index) const;
70
71private:
74 QRegularExpression filterRegex;
75 QString filterQuery;
76 bool filterActive = false;
77
79 void rebuildFilter();
80};
81
82Q_DECLARE_METATYPE(SettingsSearchEntry)
83
84#endif // COCKATRICE_SETTINGS_SEARCH_MODEL_H
Definition remote_connection_controller.h:20
bool isFilterActive() const
Whether a non-empty filter is currently active.
Definition settings_search_model.cpp:41
QList< SettingsSearchEntry > sourceEntries
Complete unfiltered entry list.
Definition settings_search_model.h:72
Roles
Custom data role for accessing the full entry.
Definition settings_search_model.h:52
@ EntryRole
Full SettingsSearchEntry object.
Definition settings_search_model.h:53
void setSourceEntries(const QList< SettingsSearchEntry > &entries)
Replaces the source entries and rebuilds the filter.
Definition settings_search_model.cpp:22
QVariant data(const QModelIndex &index, int role=Qt::DisplayRole) const override
Definition settings_search_model.cpp:125
QString filterQuery
Current filter query string.
Definition settings_search_model.h:75
SettingsSearchEntry entryForIndex(const QModelIndex &index) const
Returns the full entry for a given model index.
Definition settings_search_model.cpp:146
SettingsSearchModel(QObject *parent=nullptr)
Definition settings_search_model.cpp:18
void setFilterString(const QString &text)
Sets the filter string and recalculates the results.
Definition settings_search_model.cpp:30
int rowCount(const QModelIndex &parent=QModelIndex()) const override
Definition settings_search_model.cpp:117
QRegularExpression filterRegex
Compiled regex for the current filter.
Definition settings_search_model.h:74
void rebuildFilter()
Recalculates the filtered index list and ranking.
Definition settings_search_model.cpp:87
QList< int > filteredIndices
Indices into sourceEntries matching the filter.
Definition settings_search_model.h:73
bool filterActive
Whether filtering is active.
Definition settings_search_model.h:76
Represents a single searchable setting entry.
Definition settings_search_model.h:29
QWidget * widget
Pointer to the setting widget for focus/scrolling.
Definition settings_search_model.h:34
QString groupTitle
Title of the group/section within the page.
Definition settings_search_model.h:31
int pageIndex
Index of the settings page this entry belongs to.
Definition settings_search_model.h:30
QString widgetLabel
Display label for the setting widget.
Definition settings_search_model.h:32
QString fullSearchText
Extended search text (label, control text, tooltip) for full-text matching.
Definition settings_search_model.h:33