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

source code of qtdatavis3d/src/datavisualization/data/qitemmodelbardataproxy.h