1 | // Copyright (C) 2023 The Qt Company Ltd. |
2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only |
3 | |
4 | #ifndef QITEMMODELBARDATAPROXY_H |
5 | #define QITEMMODELBARDATAPROXY_H |
6 | |
7 | #include <QtGraphs/qbardataproxy.h> |
8 | #include <QtCore/QAbstractItemModel> |
9 | #include <QtCore/QRegularExpression> |
10 | |
11 | QT_BEGIN_NAMESPACE |
12 | |
13 | class QItemModelBarDataProxyPrivate; |
14 | |
15 | class Q_GRAPHS_EXPORT QItemModelBarDataProxy : public QBarDataProxy |
16 | { |
17 | Q_OBJECT |
18 | Q_DECLARE_PRIVATE(QItemModelBarDataProxy) |
19 | Q_PROPERTY(QAbstractItemModel* itemModel READ itemModel WRITE setItemModel NOTIFY itemModelChanged) |
20 | Q_PROPERTY(QString rowRole READ rowRole WRITE setRowRole NOTIFY rowRoleChanged) |
21 | Q_PROPERTY(QString columnRole READ columnRole WRITE setColumnRole NOTIFY columnRoleChanged) |
22 | Q_PROPERTY(QString valueRole READ valueRole WRITE setValueRole NOTIFY valueRoleChanged) |
23 | Q_PROPERTY(QString rotationRole READ rotationRole WRITE setRotationRole NOTIFY rotationRoleChanged) |
24 | Q_PROPERTY(QStringList rowCategories READ rowCategories WRITE setRowCategories NOTIFY rowCategoriesChanged) |
25 | Q_PROPERTY(QStringList columnCategories READ columnCategories WRITE setColumnCategories NOTIFY columnCategoriesChanged) |
26 | Q_PROPERTY(bool useModelCategories READ useModelCategories WRITE setUseModelCategories NOTIFY useModelCategoriesChanged) |
27 | Q_PROPERTY(bool autoRowCategories READ autoRowCategories WRITE setAutoRowCategories NOTIFY autoRowCategoriesChanged) |
28 | Q_PROPERTY(bool autoColumnCategories READ autoColumnCategories WRITE setAutoColumnCategories NOTIFY autoColumnCategoriesChanged) |
29 | Q_PROPERTY(QRegularExpression rowRolePattern READ rowRolePattern WRITE setRowRolePattern NOTIFY rowRolePatternChanged) |
30 | Q_PROPERTY(QRegularExpression columnRolePattern READ columnRolePattern WRITE setColumnRolePattern NOTIFY columnRolePatternChanged) |
31 | Q_PROPERTY(QRegularExpression valueRolePattern READ valueRolePattern WRITE setValueRolePattern NOTIFY valueRolePatternChanged) |
32 | Q_PROPERTY(QRegularExpression rotationRolePattern READ rotationRolePattern WRITE setRotationRolePattern NOTIFY rotationRolePatternChanged) |
33 | Q_PROPERTY(QString rowRoleReplace READ rowRoleReplace WRITE setRowRoleReplace NOTIFY rowRoleReplaceChanged) |
34 | Q_PROPERTY(QString columnRoleReplace READ columnRoleReplace WRITE setColumnRoleReplace NOTIFY columnRoleReplaceChanged) |
35 | Q_PROPERTY(QString valueRoleReplace READ valueRoleReplace WRITE setValueRoleReplace NOTIFY valueRoleReplaceChanged) |
36 | Q_PROPERTY(QString rotationRoleReplace READ rotationRoleReplace WRITE setRotationRoleReplace NOTIFY rotationRoleReplaceChanged) |
37 | Q_PROPERTY(QItemModelBarDataProxy::MultiMatchBehavior multiMatchBehavior READ multiMatchBehavior WRITE setMultiMatchBehavior NOTIFY multiMatchBehaviorChanged) |
38 | |
39 | public: |
40 | enum MultiMatchBehavior { |
41 | MMBFirst = 0, |
42 | MMBLast = 1, |
43 | MMBAverage = 2, |
44 | MMBCumulative = 3 |
45 | }; |
46 | Q_ENUM(MultiMatchBehavior) |
47 | |
48 | explicit QItemModelBarDataProxy(QObject *parent = nullptr); |
49 | explicit QItemModelBarDataProxy(QAbstractItemModel *itemModel, QObject *parent = nullptr); |
50 | explicit QItemModelBarDataProxy(QAbstractItemModel *itemModel, const QString &valueRole, |
51 | QObject *parent = nullptr); |
52 | explicit QItemModelBarDataProxy(QAbstractItemModel *itemModel, const QString &rowRole, |
53 | const QString &columnRole, const QString &valueRole, |
54 | QObject *parent = nullptr); |
55 | explicit QItemModelBarDataProxy(QAbstractItemModel *itemModel, const QString &rowRole, |
56 | const QString &columnRole, const QString &valueRole, |
57 | const QString &rotationRole, QObject *parent = nullptr); |
58 | explicit QItemModelBarDataProxy(QAbstractItemModel *itemModel, const QString &rowRole, |
59 | const QString &columnRole, const QString &valueRole, |
60 | const QStringList &rowCategories, const QStringList &columnCategories, |
61 | QObject *parent = nullptr); |
62 | explicit QItemModelBarDataProxy(QAbstractItemModel *itemModel, const QString &rowRole, |
63 | const QString &columnRole, const QString &valueRole, |
64 | const QString &rotationRole, const QStringList &rowCategories, |
65 | const QStringList &columnCategories, QObject *parent = nullptr); |
66 | virtual ~QItemModelBarDataProxy(); |
67 | |
68 | void setItemModel(QAbstractItemModel *itemModel); |
69 | QAbstractItemModel *itemModel() const; |
70 | |
71 | void setRowRole(const QString &role); |
72 | QString rowRole() const; |
73 | void setColumnRole(const QString &role); |
74 | QString columnRole() const; |
75 | void setValueRole(const QString &role); |
76 | QString valueRole() const; |
77 | void setRotationRole(const QString &role); |
78 | QString rotationRole() const; |
79 | |
80 | void setRowCategories(const QStringList &categories); |
81 | QStringList rowCategories() const; |
82 | void setColumnCategories(const QStringList &categories); |
83 | QStringList columnCategories() const; |
84 | |
85 | void setUseModelCategories(bool enable); |
86 | bool useModelCategories() const; |
87 | void setAutoRowCategories(bool enable); |
88 | bool autoRowCategories() const; |
89 | void setAutoColumnCategories(bool enable); |
90 | bool autoColumnCategories() const; |
91 | |
92 | void remap(const QString &rowRole, const QString &columnRole, |
93 | const QString &valueRole, const QString &rotationRole, |
94 | const QStringList &rowCategories, |
95 | const QStringList &columnCategories); |
96 | |
97 | Q_INVOKABLE int rowCategoryIndex(const QString& category); |
98 | Q_INVOKABLE int columnCategoryIndex(const QString& category); |
99 | |
100 | void setRowRolePattern(const QRegularExpression &pattern); |
101 | QRegularExpression rowRolePattern() const; |
102 | void setColumnRolePattern(const QRegularExpression &pattern); |
103 | QRegularExpression columnRolePattern() const; |
104 | void setValueRolePattern(const QRegularExpression &pattern); |
105 | QRegularExpression valueRolePattern() const; |
106 | void setRotationRolePattern(const QRegularExpression &pattern); |
107 | QRegularExpression rotationRolePattern() const; |
108 | |
109 | void setRowRoleReplace(const QString &replace); |
110 | QString rowRoleReplace() const; |
111 | void setColumnRoleReplace(const QString &replace); |
112 | QString columnRoleReplace() const; |
113 | void setValueRoleReplace(const QString &replace); |
114 | QString valueRoleReplace() const; |
115 | void setRotationRoleReplace(const QString &replace); |
116 | QString rotationRoleReplace() const; |
117 | |
118 | void setMultiMatchBehavior(QItemModelBarDataProxy::MultiMatchBehavior behavior); |
119 | QItemModelBarDataProxy::MultiMatchBehavior multiMatchBehavior() const; |
120 | |
121 | Q_SIGNALS: |
122 | void itemModelChanged(const QAbstractItemModel* itemModel); |
123 | void rowRoleChanged(const QString &role); |
124 | void columnRoleChanged(const QString &role); |
125 | void valueRoleChanged(const QString &role); |
126 | void rotationRoleChanged(const QString &role); |
127 | void rowCategoriesChanged(); |
128 | void columnCategoriesChanged(); |
129 | void useModelCategoriesChanged(bool enable); |
130 | void autoRowCategoriesChanged(bool enable); |
131 | void autoColumnCategoriesChanged(bool enable); |
132 | void rowRolePatternChanged(const QRegularExpression &pattern); |
133 | void columnRolePatternChanged(const QRegularExpression &pattern); |
134 | void valueRolePatternChanged(const QRegularExpression &pattern); |
135 | void rotationRolePatternChanged(const QRegularExpression &pattern); |
136 | void rowRoleReplaceChanged(const QString &replace); |
137 | void columnRoleReplaceChanged(const QString &replace); |
138 | void valueRoleReplaceChanged(const QString &replace); |
139 | void rotationRoleReplaceChanged(const QString &replace); |
140 | void multiMatchBehaviorChanged(QItemModelBarDataProxy::MultiMatchBehavior behavior); |
141 | |
142 | private: |
143 | Q_DISABLE_COPY(QItemModelBarDataProxy) |
144 | |
145 | friend class BarItemModelHandler; |
146 | }; |
147 | |
148 | QT_END_NAMESPACE |
149 | |
150 | #endif |
151 | |