Enroute Flight Navigation
A navigation app for VFR pilots
NameFilterProxyModel.h
1/***************************************************************************
2 * Copyright (C) 2026 by Stefan Kebekus *
3 * stefan.kebekus@gmail.com *
4 * *
5 * This program is free software; you can redistribute it and/or modify *
6 * it under the terms of the GNU General Public License as published by *
7 * the Free Software Foundation; either version 3 of the License, or *
8 * (at your option) any later version. *
9 * *
10 * This program is distributed in the hope that it will be useful, *
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13 * GNU General Public License for more details. *
14 * *
15 * You should have received a copy of the GNU General Public License *
16 * along with this program; if not, write to the *
17 * Free Software Foundation, Inc., *
18 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
19 ***************************************************************************/
20
21#pragma once
22
23#include <QQmlEngine>
24#include <QSortFilterProxyModel>
25
26namespace Ui {
27
36{
37 Q_GADGET
38 QML_FOREIGN(QSortFilterProxyModel)
39 QML_ANONYMOUS
40};
41
42
59
60class NameFilterProxyModel : public QSortFilterProxyModel
61{
62 Q_OBJECT
63 QML_ELEMENT
64
65public:
70 explicit NameFilterProxyModel(QObject* parent = nullptr);
71
72 // Default destructor
73 ~NameFilterProxyModel() override = default;
74
75
76 //
77 // Properties
78 //
79
85 Q_PROPERTY(QString filter READ filter WRITE setFilter NOTIFY filterChanged)
86
87
93
101
102
103 //
104 // Getter Methods
105 //
106
111 [[nodiscard]] QString filter() const { return m_filter; }
112
117 [[nodiscard]] QString filterRoleName() const { return m_filterRoleName; }
118
123 [[nodiscard]] bool filterRoleIsSimplified() const { return m_filterRoleIsSimplified; }
124
125
126 //
127 // Setter Methods
128 //
129
134 void setFilter(const QString& newFilter);
135
140 void setFilterRoleName(const QString& newFilterRoleName);
141
146 void setFilterRoleIsSimplified(bool newValue);
147
148
149 //
150 // Methods
151 //
152
157 void setSourceModel(QAbstractItemModel* newSourceModel) override;
158
159signals:
162
165
168
169protected:
178 [[nodiscard]] bool filterAcceptsRow(int sourceRow, const QModelIndex& sourceParent) const override;
179
187 [[nodiscard]] int roleForName(const QString& roleName) const;
188
189private:
190 Q_DISABLE_COPY_MOVE(NameFilterProxyModel)
191
192 QString m_filter;
193 QString m_filterRoleName {QStringLiteral("name")};
194
195 // Role matching m_filterRoleName in the current source model, or -1
196 int m_filterRole {-1};
197
198 bool m_filterRoleIsSimplified {false};
199
200 // Librarian::filterWords(m_filter), recomputed in setFilter()
201 QStringList m_filterWords;
202};
203
204} // namespace Ui
QString filterRoleName() const
Getter function for the property with the same name.
void setFilter(const QString &newFilter)
Setter function for the property with the same name.
QString filter
Filter string.
void filterChanged()
Notification signal for property with the same name.
QString filterRoleName
Name of the source model role that the filter is matched against.
void setFilterRoleName(const QString &newFilterRoleName)
Setter function for the property with the same name.
void setSourceModel(QAbstractItemModel *newSourceModel) override
Re-implemented from QAbstractProxyModel.
void filterRoleNameChanged()
Notification signal for property with the same name.
bool filterRoleIsSimplified
Whether the filter role holds text already simplified with Librarian::simplify().
bool filterRoleIsSimplified() const
Getter function for the property with the same name.
void filterRoleIsSimplifiedChanged()
Notifier signal.
int roleForName(const QString &roleName) const
Looks up a role by name in the source model.
bool filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const override
Re-implemented from QSortFilterProxyModel.
void setFilterRoleIsSimplified(bool newValue)
Setter function for the property with the same name.
NameFilterProxyModel(QObject *parent=nullptr)
Standard constructor.
Makes QSortFilterProxyModel known to the QML type system.