1 | // Copyright (C) 2016 The Qt Company Ltd. |
2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only |
3 | |
4 | #ifndef QSORTFILTERPROXYMODEL_H |
5 | #define QSORTFILTERPROXYMODEL_H |
6 | |
7 | #include <QtCore/qabstractproxymodel.h> |
8 | |
9 | #include <QtCore/qregularexpression.h> |
10 | |
11 | QT_REQUIRE_CONFIG(sortfilterproxymodel); |
12 | |
13 | QT_BEGIN_NAMESPACE |
14 | |
15 | |
16 | class QSortFilterProxyModelPrivate; |
17 | class QSortFilterProxyModelLessThan; |
18 | class QSortFilterProxyModelGreaterThan; |
19 | |
20 | class Q_CORE_EXPORT QSortFilterProxyModel : public QAbstractProxyModel |
21 | { |
22 | friend class QSortFilterProxyModelLessThan; |
23 | friend class QSortFilterProxyModelGreaterThan; |
24 | |
25 | Q_OBJECT |
26 | Q_PROPERTY(QRegularExpression filterRegularExpression READ filterRegularExpression |
27 | WRITE setFilterRegularExpression BINDABLE bindableFilterRegularExpression) |
28 | Q_PROPERTY(int filterKeyColumn READ filterKeyColumn WRITE setFilterKeyColumn |
29 | BINDABLE bindableFilterKeyColumn) |
30 | Q_PROPERTY(bool dynamicSortFilter READ dynamicSortFilter WRITE setDynamicSortFilter |
31 | BINDABLE bindableDynamicSortFilter) |
32 | Q_PROPERTY(Qt::CaseSensitivity filterCaseSensitivity READ filterCaseSensitivity |
33 | WRITE setFilterCaseSensitivity NOTIFY filterCaseSensitivityChanged |
34 | BINDABLE bindableFilterCaseSensitivity) |
35 | Q_PROPERTY(Qt::CaseSensitivity sortCaseSensitivity READ sortCaseSensitivity |
36 | WRITE setSortCaseSensitivity NOTIFY sortCaseSensitivityChanged |
37 | BINDABLE bindableSortCaseSensitivity) |
38 | Q_PROPERTY(bool isSortLocaleAware READ isSortLocaleAware WRITE setSortLocaleAware |
39 | NOTIFY sortLocaleAwareChanged BINDABLE bindableIsSortLocaleAware) |
40 | Q_PROPERTY(int sortRole READ sortRole WRITE setSortRole NOTIFY sortRoleChanged |
41 | BINDABLE bindableSortRole) |
42 | Q_PROPERTY(int filterRole READ filterRole WRITE setFilterRole NOTIFY filterRoleChanged |
43 | BINDABLE bindableFilterRole) |
44 | Q_PROPERTY(bool recursiveFilteringEnabled READ isRecursiveFilteringEnabled |
45 | WRITE setRecursiveFilteringEnabled NOTIFY recursiveFilteringEnabledChanged |
46 | BINDABLE bindableRecursiveFilteringEnabled) |
47 | Q_PROPERTY(bool autoAcceptChildRows READ autoAcceptChildRows WRITE setAutoAcceptChildRows |
48 | NOTIFY autoAcceptChildRowsChanged BINDABLE bindableAutoAcceptChildRows) |
49 | |
50 | public: |
51 | explicit QSortFilterProxyModel(QObject *parent = nullptr); |
52 | ~QSortFilterProxyModel(); |
53 | |
54 | void setSourceModel(QAbstractItemModel *sourceModel) override; |
55 | |
56 | QModelIndex mapToSource(const QModelIndex &proxyIndex) const override; |
57 | QModelIndex mapFromSource(const QModelIndex &sourceIndex) const override; |
58 | |
59 | QItemSelection mapSelectionToSource(const QItemSelection &proxySelection) const override; |
60 | QItemSelection mapSelectionFromSource(const QItemSelection &sourceSelection) const override; |
61 | |
62 | QRegularExpression filterRegularExpression() const; |
63 | QBindable<QRegularExpression> bindableFilterRegularExpression(); |
64 | |
65 | int filterKeyColumn() const; |
66 | void setFilterKeyColumn(int column); |
67 | QBindable<int> bindableFilterKeyColumn(); |
68 | |
69 | Qt::CaseSensitivity filterCaseSensitivity() const; |
70 | void setFilterCaseSensitivity(Qt::CaseSensitivity cs); |
71 | QBindable<Qt::CaseSensitivity> bindableFilterCaseSensitivity(); |
72 | |
73 | Qt::CaseSensitivity sortCaseSensitivity() const; |
74 | void setSortCaseSensitivity(Qt::CaseSensitivity cs); |
75 | QBindable<Qt::CaseSensitivity> bindableSortCaseSensitivity(); |
76 | |
77 | bool isSortLocaleAware() const; |
78 | void setSortLocaleAware(bool on); |
79 | QBindable<bool> bindableIsSortLocaleAware(); |
80 | |
81 | int sortColumn() const; |
82 | Qt::SortOrder sortOrder() const; |
83 | |
84 | bool dynamicSortFilter() const; |
85 | void setDynamicSortFilter(bool enable); |
86 | QBindable<bool> bindableDynamicSortFilter(); |
87 | |
88 | int sortRole() const; |
89 | void setSortRole(int role); |
90 | QBindable<int> bindableSortRole(); |
91 | |
92 | int filterRole() const; |
93 | void setFilterRole(int role); |
94 | QBindable<int> bindableFilterRole(); |
95 | |
96 | bool isRecursiveFilteringEnabled() const; |
97 | void setRecursiveFilteringEnabled(bool recursive); |
98 | QBindable<bool> bindableRecursiveFilteringEnabled(); |
99 | |
100 | bool autoAcceptChildRows() const; |
101 | void setAutoAcceptChildRows(bool accept); |
102 | QBindable<bool> bindableAutoAcceptChildRows(); |
103 | |
104 | public Q_SLOTS: |
105 | void setFilterRegularExpression(const QString &pattern); |
106 | void setFilterRegularExpression(const QRegularExpression ®ularExpression); |
107 | void setFilterWildcard(const QString &pattern); |
108 | void setFilterFixedString(const QString &pattern); |
109 | void invalidate(); |
110 | |
111 | protected: |
112 | virtual bool filterAcceptsRow(int source_row, const QModelIndex &source_parent) const; |
113 | virtual bool filterAcceptsColumn(int source_column, const QModelIndex &source_parent) const; |
114 | virtual bool lessThan(const QModelIndex &source_left, const QModelIndex &source_right) const; |
115 | |
116 | void invalidateFilter(); |
117 | void invalidateRowsFilter(); |
118 | void invalidateColumnsFilter(); |
119 | |
120 | public: |
121 | using QObject::parent; |
122 | |
123 | QModelIndex index(int row, int column, const QModelIndex &parent = QModelIndex()) const override; |
124 | QModelIndex parent(const QModelIndex &child) const override; |
125 | QModelIndex sibling(int row, int column, const QModelIndex &idx) const override; |
126 | |
127 | int rowCount(const QModelIndex &parent = QModelIndex()) const override; |
128 | int columnCount(const QModelIndex &parent = QModelIndex()) const override; |
129 | bool hasChildren(const QModelIndex &parent = QModelIndex()) const override; |
130 | |
131 | QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override; |
132 | bool setData(const QModelIndex &index, const QVariant &value, int role = Qt::EditRole) override; |
133 | |
134 | QVariant (int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const override; |
135 | bool (int section, Qt::Orientation orientation, |
136 | const QVariant &value, int role = Qt::EditRole) override; |
137 | |
138 | QMimeData *mimeData(const QModelIndexList &indexes) const override; |
139 | bool dropMimeData(const QMimeData *data, Qt::DropAction action, |
140 | int row, int column, const QModelIndex &parent) override; |
141 | |
142 | bool insertRows(int row, int count, const QModelIndex &parent = QModelIndex()) override; |
143 | bool insertColumns(int column, int count, const QModelIndex &parent = QModelIndex()) override; |
144 | bool removeRows(int row, int count, const QModelIndex &parent = QModelIndex()) override; |
145 | bool removeColumns(int column, int count, const QModelIndex &parent = QModelIndex()) override; |
146 | |
147 | void fetchMore(const QModelIndex &parent) override; |
148 | bool canFetchMore(const QModelIndex &parent) const override; |
149 | Qt::ItemFlags flags(const QModelIndex &index) const override; |
150 | |
151 | QModelIndex buddy(const QModelIndex &index) const override; |
152 | QModelIndexList match(const QModelIndex &start, int role, |
153 | const QVariant &value, int hits = 1, |
154 | Qt::MatchFlags flags = |
155 | Qt::MatchFlags(Qt::MatchStartsWith|Qt::MatchWrap)) const override; |
156 | QSize span(const QModelIndex &index) const override; |
157 | void sort(int column, Qt::SortOrder order = Qt::AscendingOrder) override; |
158 | |
159 | QStringList mimeTypes() const override; |
160 | Qt::DropActions supportedDropActions() const override; |
161 | |
162 | Q_SIGNALS: |
163 | void dynamicSortFilterChanged(bool dynamicSortFilter); |
164 | void filterCaseSensitivityChanged(Qt::CaseSensitivity filterCaseSensitivity); |
165 | void sortCaseSensitivityChanged(Qt::CaseSensitivity sortCaseSensitivity); |
166 | void sortLocaleAwareChanged(bool sortLocaleAware); |
167 | void sortRoleChanged(int sortRole); |
168 | void filterRoleChanged(int filterRole); |
169 | void recursiveFilteringEnabledChanged(bool recursiveFilteringEnabled); |
170 | void autoAcceptChildRowsChanged(bool autoAcceptChildRows); |
171 | |
172 | private: |
173 | Q_DECLARE_PRIVATE(QSortFilterProxyModel) |
174 | Q_DISABLE_COPY(QSortFilterProxyModel) |
175 | }; |
176 | |
177 | QT_END_NAMESPACE |
178 | |
179 | #endif // QSORTFILTERPROXYMODEL_H |
180 | |