| 1 | // Copyright (C) 2023 The Qt Company Ltd. |
| 2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only |
| 3 | |
| 4 | #ifndef QTGRAPHS_QITEMMODELBARDATAPROXY_H |
| 5 | #define QTGRAPHS_QITEMMODELBARDATAPROXY_H |
| 6 | |
| 7 | #include <QtCore/qabstractitemmodel.h> |
| 8 | #include <QtCore/qregularexpression.h> |
| 9 | #include <QtGraphs/qbardataproxy.h> |
| 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_CLASSINFO("RegisterEnumClassesUnscoped" , "false" ) |
| 20 | Q_PROPERTY(QAbstractItemModel *itemModel READ itemModel WRITE setItemModel NOTIFY |
| 21 | itemModelChanged FINAL) |
| 22 | Q_PROPERTY(QString rowRole READ rowRole WRITE setRowRole NOTIFY rowRoleChanged FINAL) |
| 23 | Q_PROPERTY(QString columnRole READ columnRole WRITE setColumnRole NOTIFY columnRoleChanged FINAL) |
| 24 | Q_PROPERTY(QString valueRole READ valueRole WRITE setValueRole NOTIFY valueRoleChanged FINAL) |
| 25 | Q_PROPERTY(QString rotationRole READ rotationRole WRITE setRotationRole NOTIFY |
| 26 | rotationRoleChanged FINAL) |
| 27 | Q_PROPERTY(QStringList rowCategories READ rowCategories WRITE setRowCategories NOTIFY |
| 28 | rowCategoriesChanged FINAL) |
| 29 | Q_PROPERTY(QStringList columnCategories READ columnCategories WRITE setColumnCategories NOTIFY |
| 30 | columnCategoriesChanged FINAL) |
| 31 | Q_PROPERTY(bool useModelCategories READ useModelCategories WRITE setUseModelCategories NOTIFY |
| 32 | useModelCategoriesChanged FINAL) |
| 33 | Q_PROPERTY(bool autoRowCategories READ autoRowCategories WRITE setAutoRowCategories NOTIFY |
| 34 | autoRowCategoriesChanged FINAL) |
| 35 | Q_PROPERTY(bool autoColumnCategories READ autoColumnCategories WRITE setAutoColumnCategories |
| 36 | NOTIFY autoColumnCategoriesChanged FINAL) |
| 37 | Q_PROPERTY(QRegularExpression rowRolePattern READ rowRolePattern WRITE setRowRolePattern NOTIFY |
| 38 | rowRolePatternChanged FINAL) |
| 39 | Q_PROPERTY(QRegularExpression columnRolePattern READ columnRolePattern WRITE |
| 40 | setColumnRolePattern NOTIFY columnRolePatternChanged FINAL) |
| 41 | Q_PROPERTY(QRegularExpression valueRolePattern READ valueRolePattern WRITE setValueRolePattern |
| 42 | NOTIFY valueRolePatternChanged FINAL) |
| 43 | Q_PROPERTY(QRegularExpression rotationRolePattern READ rotationRolePattern WRITE |
| 44 | setRotationRolePattern NOTIFY rotationRolePatternChanged FINAL) |
| 45 | Q_PROPERTY(QString rowRoleReplace READ rowRoleReplace WRITE setRowRoleReplace NOTIFY |
| 46 | rowRoleReplaceChanged FINAL) |
| 47 | Q_PROPERTY(QString columnRoleReplace READ columnRoleReplace WRITE setColumnRoleReplace NOTIFY |
| 48 | columnRoleReplaceChanged FINAL) |
| 49 | Q_PROPERTY(QString valueRoleReplace READ valueRoleReplace WRITE setValueRoleReplace NOTIFY |
| 50 | valueRoleReplaceChanged FINAL) |
| 51 | Q_PROPERTY(QString rotationRoleReplace READ rotationRoleReplace WRITE setRotationRoleReplace |
| 52 | NOTIFY rotationRoleReplaceChanged FINAL) |
| 53 | Q_PROPERTY(QItemModelBarDataProxy::MultiMatchBehavior multiMatchBehavior READ multiMatchBehavior |
| 54 | WRITE setMultiMatchBehavior NOTIFY multiMatchBehaviorChanged FINAL) |
| 55 | |
| 56 | public: |
| 57 | enum class MultiMatchBehavior { |
| 58 | First, |
| 59 | Last, |
| 60 | Average, |
| 61 | Cumulative, |
| 62 | }; |
| 63 | Q_ENUM(MultiMatchBehavior) |
| 64 | |
| 65 | explicit QItemModelBarDataProxy(QObject *parent = nullptr); |
| 66 | explicit QItemModelBarDataProxy(QAbstractItemModel *itemModel, QObject *parent = nullptr); |
| 67 | explicit QItemModelBarDataProxy(QAbstractItemModel *itemModel, |
| 68 | const QString &valueRole, |
| 69 | QObject *parent = nullptr); |
| 70 | explicit QItemModelBarDataProxy(QAbstractItemModel *itemModel, |
| 71 | const QString &rowRole, |
| 72 | const QString &columnRole, |
| 73 | const QString &valueRole, |
| 74 | QObject *parent = nullptr); |
| 75 | explicit QItemModelBarDataProxy(QAbstractItemModel *itemModel, |
| 76 | const QString &rowRole, |
| 77 | const QString &columnRole, |
| 78 | const QString &valueRole, |
| 79 | const QString &rotationRole, |
| 80 | QObject *parent = nullptr); |
| 81 | explicit QItemModelBarDataProxy(QAbstractItemModel *itemModel, |
| 82 | const QString &rowRole, |
| 83 | const QString &columnRole, |
| 84 | const QString &valueRole, |
| 85 | const QStringList &rowCategories, |
| 86 | const QStringList &columnCategories, |
| 87 | QObject *parent = nullptr); |
| 88 | explicit QItemModelBarDataProxy(QAbstractItemModel *itemModel, |
| 89 | const QString &rowRole, |
| 90 | const QString &columnRole, |
| 91 | const QString &valueRole, |
| 92 | const QString &rotationRole, |
| 93 | const QStringList &rowCategories, |
| 94 | const QStringList &columnCategories, |
| 95 | QObject *parent = nullptr); |
| 96 | ~QItemModelBarDataProxy() override; |
| 97 | |
| 98 | void setItemModel(QAbstractItemModel *itemModel); |
| 99 | QAbstractItemModel *itemModel() const; |
| 100 | |
| 101 | void setRowRole(const QString &role); |
| 102 | QString rowRole() const; |
| 103 | void setColumnRole(const QString &role); |
| 104 | QString columnRole() const; |
| 105 | void setValueRole(const QString &role); |
| 106 | QString valueRole() const; |
| 107 | void setRotationRole(const QString &role); |
| 108 | QString rotationRole() const; |
| 109 | |
| 110 | void setRowCategories(const QStringList &categories); |
| 111 | QStringList rowCategories() const; |
| 112 | void setColumnCategories(const QStringList &categories); |
| 113 | QStringList columnCategories() const; |
| 114 | |
| 115 | void setUseModelCategories(bool enable); |
| 116 | bool useModelCategories() const; |
| 117 | void setAutoRowCategories(bool enable); |
| 118 | bool autoRowCategories() const; |
| 119 | void setAutoColumnCategories(bool enable); |
| 120 | bool autoColumnCategories() const; |
| 121 | |
| 122 | void remap(const QString &rowRole, |
| 123 | const QString &columnRole, |
| 124 | const QString &valueRole, |
| 125 | const QString &rotationRole, |
| 126 | const QStringList &rowCategories, |
| 127 | const QStringList &columnCategories); |
| 128 | |
| 129 | Q_INVOKABLE qsizetype rowCategoryIndex(const QString &category); |
| 130 | Q_INVOKABLE qsizetype columnCategoryIndex(const QString &category); |
| 131 | |
| 132 | void setRowRolePattern(const QRegularExpression &pattern); |
| 133 | QRegularExpression rowRolePattern() const; |
| 134 | void setColumnRolePattern(const QRegularExpression &pattern); |
| 135 | QRegularExpression columnRolePattern() const; |
| 136 | void setValueRolePattern(const QRegularExpression &pattern); |
| 137 | QRegularExpression valueRolePattern() const; |
| 138 | void setRotationRolePattern(const QRegularExpression &pattern); |
| 139 | QRegularExpression rotationRolePattern() const; |
| 140 | |
| 141 | void setRowRoleReplace(const QString &replace); |
| 142 | QString rowRoleReplace() const; |
| 143 | void setColumnRoleReplace(const QString &replace); |
| 144 | QString columnRoleReplace() const; |
| 145 | void setValueRoleReplace(const QString &replace); |
| 146 | QString valueRoleReplace() const; |
| 147 | void setRotationRoleReplace(const QString &replace); |
| 148 | QString rotationRoleReplace() const; |
| 149 | |
| 150 | void setMultiMatchBehavior(QItemModelBarDataProxy::MultiMatchBehavior behavior); |
| 151 | QItemModelBarDataProxy::MultiMatchBehavior multiMatchBehavior() const; |
| 152 | |
| 153 | Q_SIGNALS: |
| 154 | void itemModelChanged(const QAbstractItemModel *itemModel); |
| 155 | void rowRoleChanged(const QString &role); |
| 156 | void columnRoleChanged(const QString &role); |
| 157 | void valueRoleChanged(const QString &role); |
| 158 | void rotationRoleChanged(const QString &role); |
| 159 | void rowCategoriesChanged(); |
| 160 | void columnCategoriesChanged(); |
| 161 | void useModelCategoriesChanged(bool enable); |
| 162 | void autoRowCategoriesChanged(bool enable); |
| 163 | void autoColumnCategoriesChanged(bool enable); |
| 164 | void rowRolePatternChanged(const QRegularExpression &pattern); |
| 165 | void columnRolePatternChanged(const QRegularExpression &pattern); |
| 166 | void valueRolePatternChanged(const QRegularExpression &pattern); |
| 167 | void rotationRolePatternChanged(const QRegularExpression &pattern); |
| 168 | void rowRoleReplaceChanged(const QString &replace); |
| 169 | void columnRoleReplaceChanged(const QString &replace); |
| 170 | void valueRoleReplaceChanged(const QString &replace); |
| 171 | void rotationRoleReplaceChanged(const QString &replace); |
| 172 | void multiMatchBehaviorChanged(QItemModelBarDataProxy::MultiMatchBehavior behavior); |
| 173 | |
| 174 | private: |
| 175 | Q_DISABLE_COPY(QItemModelBarDataProxy) |
| 176 | |
| 177 | friend class BarItemModelHandler; |
| 178 | }; |
| 179 | |
| 180 | QT_END_NAMESPACE |
| 181 | |
| 182 | #endif |
| 183 | |