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
94
95 //
96 // Getter Methods
97 //
98
103 [[nodiscard]] QString filter() const { return m_filter; }
104
109 [[nodiscard]] QString filterRoleName() const { return m_filterRoleName; }
110
111
112 //
113 // Setter Methods
114 //
115
120 void setFilter(const QString& newFilter);
121
126 void setFilterRoleName(const QString& newFilterRoleName);
127
128
129 //
130 // Methods
131 //
132
137 void setSourceModel(QAbstractItemModel* newSourceModel) override;
138
139signals:
142
145
146protected:
155 [[nodiscard]] bool filterAcceptsRow(int sourceRow, const QModelIndex& sourceParent) const override;
156
164 [[nodiscard]] int roleForName(const QString& roleName) const;
165
166private:
167 Q_DISABLE_COPY_MOVE(NameFilterProxyModel)
168
169 QString m_filter;
170 QString m_filterRoleName {QStringLiteral("name")};
171
172 // Role matching m_filterRoleName in the current source model, or -1
173 int m_filterRole {-1};
174};
175
176} // 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.
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.
NameFilterProxyModel(QObject *parent=nullptr)
Standard constructor.
Makes QSortFilterProxyModel known to the QML type system.