Qt Model Utilities  2.0.3
A set of utilities for the model/view framework of Qt
rolemaskproxymodel.h
1 /****************************************************************************\
2  Copyright 2018 Luca Beldi
3  Licensed under the Apache License, Version 2.0 (the "License");
4  you may not use this file except in compliance with the License.
5  You may obtain a copy of the License at
6  http://www.apache.org/licenses/LICENSE-2.0
7  Unless required by applicable law or agreed to in writing, software
8  distributed under the License is distributed on an "AS IS" BASIS,
9  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10  See the License for the specific language governing permissions and
11  limitations under the License.
12 \****************************************************************************/
13 #ifndef ROLEMASKPROXYMODEL_H
14 #define ROLEMASKPROXYMODEL_H
15 #include <modelutilities_global.h>
16 #include <QIdentityProxyModel>
17 #include <QList>
18 #include <QSet>
19 class RoleMaskProxyModelPrivate;
20 class MODELUTILITIES_EXPORT RoleMaskProxyModel : public QIdentityProxyModel
21 {
22  Q_OBJECT
23  Q_PROPERTY(bool transparentIfEmpty READ transparentIfEmpty WRITE setTransparentIfEmpty NOTIFY transparentIfEmptyChanged)
24  Q_PROPERTY(bool mergeDisplayEdit READ mergeDisplayEdit WRITE setMergeDisplayEdit NOTIFY mergeDisplayEditChanged)
25  Q_PROPERTY(bool maskHeaderData READ maskHeaderData WRITE setMaskHeaderData NOTIFY maskHeaderDataChanged)
26  Q_PROPERTY(QList<int> maskedRoles READ maskedRoles WRITE setMaskedRoles NOTIFY maskedRolesChanged RESET clearMaskedRoles)
27  Q_DISABLE_COPY(RoleMaskProxyModel)
28  Q_DECLARE_PRIVATE(RoleMaskProxyModel)
29 public:
30  explicit RoleMaskProxyModel(QObject *parent = Q_NULLPTR);
32  QList<int> maskedRoles() const;
33  void setMaskedRoles(const QList<int> &roles);
34  void clearMaskedRoles();
35  void addMaskedRole(int role);
36  void removeMaskedRole(int role);
37  QVariant maskedRoleDefaultValue(int role) const;
38  bool setMaskedRoleDefaultValue(int role, const QVariant &value);
39  void setSourceModel(QAbstractItemModel *sourceModel) override;
40  QVariant data(const QModelIndex &proxyIndex, int role = Qt::DisplayRole) const override;
41  Qt::ItemFlags flags(const QModelIndex &index) const override;
42  bool setData(const QModelIndex &index, const QVariant &value, int role = Qt::EditRole) override;
43  bool setMaskedFlags(const QModelIndex &index, Qt::ItemFlags flags);
44  bool setItemData(const QModelIndex &index, const QMap<int, QVariant> &roles) override;
45  QMap<int, QVariant> itemData(const QModelIndex &index) const override;
46  QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const override;
47  bool setHeaderData(int section, Qt::Orientation orientation, const QVariant &value, int role = Qt::EditRole) override;
48  void sort(int column, Qt::SortOrder order = Qt::AscendingOrder) override;
49 #if (QT_VERSION >= QT_VERSION_CHECK(6, 0, 0))
50  void multiData(const QModelIndex &index, QModelRoleDataSpan roleDataSpan) const override;
51  bool clearItemData(const QModelIndex &index) override;
52 #endif
53  QMap<int, QVariant> maskedItemData(const QModelIndex &index) const;
54  const Qt::ItemFlags *maskedFlags(const QModelIndex &index) const;
55  void clearMaskedData(const QModelIndex &index);
56  void clearMaskedFlags(const QModelIndex &index);
57  bool transparentIfEmpty() const;
58  void setTransparentIfEmpty(bool val);
59  bool mergeDisplayEdit() const;
60  void setMergeDisplayEdit(bool val);
61  bool maskHeaderData() const;
62  void setMaskHeaderData(bool val);
63 Q_SIGNALS:
64  void mergeDisplayEditChanged(bool val);
65  void transparentIfEmptyChanged(bool val);
66  void maskHeaderDataChanged(bool val);
68  void maskedDataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight, const QVector<int> &roles);
69 
70 protected:
71  const QSet<int> &maskedRolesSets() const;
72  RoleMaskProxyModel(RoleMaskProxyModelPrivate &dptr, QObject *parent);
73 
74 private:
75  RoleMaskProxyModelPrivate *d_ptr;
76 };
77 #endif // ROLEMASKPROXYMODEL_H
This proxy will act as a mask on top of the source model to intercept data.
Definition: rolemaskproxymodel.h:21
void maskedDataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight, const QVector< int > &roles)