| 1 | // Copyright (C) 2023 The Qt Company Ltd. | 
| 2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only | 
| 3 |  | 
| 4 | #ifndef QTGRAPHS_QBARSERIES_H | 
| 5 | #define QTGRAPHS_QBARSERIES_H | 
| 6 |  | 
| 7 | #include <QtGraphs/qabstractseries.h> | 
| 8 | #include <QtGraphs/qgraphsglobal.h> | 
| 9 |  | 
| 10 | QT_BEGIN_NAMESPACE | 
| 11 |  | 
| 12 | class QBarSet; | 
| 13 | class QBarSeriesPrivate; | 
| 14 |  | 
| 15 | class Q_GRAPHS_EXPORT QBarSeries : public QAbstractSeries | 
| 16 | { | 
| 17 |     Q_OBJECT | 
| 18 |     Q_CLASSINFO("RegisterEnumClassesUnscoped" , "false" ) | 
| 19 |     Q_PROPERTY(QList<QColor> seriesColors READ seriesColors WRITE setSeriesColors NOTIFY seriesColorsChanged FINAL) | 
| 20 |     Q_PROPERTY(QList<QColor> borderColors READ borderColors WRITE setBorderColors NOTIFY borderColorsChanged FINAL) | 
| 21 |     Q_PROPERTY(BarsType barsType READ barsType WRITE setBarsType NOTIFY barsTypeChanged FINAL) | 
| 22 |     Q_PROPERTY(qreal barWidth READ barWidth WRITE setBarWidth NOTIFY barWidthChanged FINAL) | 
| 23 |     Q_PROPERTY(qsizetype count READ count NOTIFY countChanged FINAL) | 
| 24 |     Q_PROPERTY(bool labelsVisible READ labelsVisible WRITE setLabelsVisible NOTIFY | 
| 25 |                    labelsVisibleChanged FINAL) | 
| 26 |     Q_PROPERTY(QString labelsFormat READ labelsFormat WRITE setLabelsFormat NOTIFY | 
| 27 |                    labelsFormatChanged FINAL) | 
| 28 |     Q_PROPERTY(LabelsPosition labelsPosition READ labelsPosition WRITE setLabelsPosition NOTIFY | 
| 29 |                    labelsPositionChanged FINAL) | 
| 30 |     Q_PROPERTY( | 
| 31 |         qreal labelsMargin READ labelsMargin WRITE setLabelsMargin NOTIFY labelsMarginChanged FINAL) | 
| 32 |     Q_PROPERTY( | 
| 33 |         qreal labelsAngle READ labelsAngle WRITE setLabelsAngle NOTIFY labelsAngleChanged FINAL) | 
| 34 |     Q_PROPERTY(int labelsPrecision READ labelsPrecision WRITE setLabelsPrecision NOTIFY | 
| 35 |                    labelsPrecisionChanged FINAL) | 
| 36 |     Q_PROPERTY(QQmlComponent *barDelegate READ barDelegate WRITE setBarDelegate NOTIFY barDelegateChanged FINAL) | 
| 37 |     Q_PROPERTY(QList<QBarSet *> barSets READ barSets NOTIFY barSetsChanged FINAL) | 
| 38 |     QML_NAMED_ELEMENT(BarSeries) | 
| 39 |  | 
| 40 | public: | 
| 41 |     enum class LabelsPosition { | 
| 42 |         Center, | 
| 43 |         InsideEnd, | 
| 44 |         InsideBase, | 
| 45 |         OutsideEnd, | 
| 46 |     }; | 
| 47 |     Q_ENUM(LabelsPosition) | 
| 48 |  | 
| 49 |     enum class BarsType { | 
| 50 |         Groups, | 
| 51 |         Stacked, | 
| 52 |         StackedPercent, | 
| 53 |     }; | 
| 54 |     Q_ENUM(BarsType) | 
| 55 |  | 
| 56 |     explicit QBarSeries(QObject *parent = nullptr); | 
| 57 |     ~QBarSeries() override; | 
| 58 |     QAbstractSeries::SeriesType type() const override; | 
| 59 |  | 
| 60 |     QList<QColor> seriesColors() const; | 
| 61 |     void setSeriesColors(const QList<QColor> &newSeriesColors); | 
| 62 |  | 
| 63 |     QList<QColor> borderColors() const; | 
| 64 |     void setBorderColors(const QList<QColor> &newBorderColors); | 
| 65 |  | 
| 66 |     void setBarsType(QBarSeries::BarsType type); | 
| 67 |     QBarSeries::BarsType barsType() const; | 
| 68 |  | 
| 69 |     void setBarWidth(qreal width); | 
| 70 |     qreal barWidth() const; | 
| 71 |  | 
| 72 |     Q_INVOKABLE bool append(QBarSet *set); | 
| 73 |     Q_INVOKABLE bool take(QBarSet *set); | 
| 74 |     Q_INVOKABLE qsizetype count() const; | 
| 75 |     Q_INVOKABLE bool append(const QList<QBarSet *> &sets); | 
| 76 |     Q_INVOKABLE bool remove(QBarSet *set); | 
| 77 |     Q_INVOKABLE bool insert(qsizetype index, QBarSet *set); | 
| 78 |     Q_INVOKABLE void clear(); | 
| 79 |     Q_INVOKABLE void replace(qsizetype index, QBarSet *set); | 
| 80 |     Q_INVOKABLE QBarSet *at(qsizetype index); | 
| 81 |     Q_INVOKABLE qsizetype find(QBarSet *set) const; | 
| 82 |     Q_INVOKABLE void removeMultiple(qsizetype index, qsizetype count); | 
| 83 |     Q_INVOKABLE bool remove(qsizetype index); | 
| 84 |     Q_INVOKABLE bool replace(QBarSet *oldValue, QBarSet *newValue); | 
| 85 |     Q_INVOKABLE bool replace(const QList<QBarSet *> &sets); | 
| 86 |  | 
| 87 |     QList<QBarSet *> barSets() const; | 
| 88 |  | 
| 89 |     void setLabelsVisible(bool visible = true); | 
| 90 |     bool labelsVisible() const; | 
| 91 |  | 
| 92 |     void setLabelsFormat(const QString &format); | 
| 93 |     QString labelsFormat() const; | 
| 94 |  | 
| 95 |     void setLabelsMargin(qreal margin); | 
| 96 |     qreal labelsMargin() const; | 
| 97 |  | 
| 98 |     void setLabelsAngle(qreal angle); | 
| 99 |     qreal labelsAngle() const; | 
| 100 |  | 
| 101 |     void setLabelsPosition(QBarSeries::LabelsPosition position); | 
| 102 |     QBarSeries::LabelsPosition labelsPosition() const; | 
| 103 |  | 
| 104 |     void setLabelsPrecision(int precision); | 
| 105 |     int labelsPrecision() const; | 
| 106 |  | 
| 107 |     QQmlComponent *barDelegate() const; | 
| 108 |     void setBarDelegate(QQmlComponent *newBarDelegate); | 
| 109 |  | 
| 110 | public Q_SLOTS: | 
| 111 |     void selectAll(); | 
| 112 |     void deselectAll(); | 
| 113 |  | 
| 114 | protected: | 
| 115 |     QBarSeries(QBarSeriesPrivate &dd, QObject *parent = nullptr); | 
| 116 |     void componentComplete() override; | 
| 117 |  | 
| 118 | Q_SIGNALS: | 
| 119 |     void updatedBars(); | 
| 120 |     void seriesColorsChanged(); | 
| 121 |     void borderColorsChanged(); | 
| 122 |     void countChanged(); | 
| 123 |     void barWidthChanged(); | 
| 124 |     void labelsVisibleChanged(bool visible); | 
| 125 |     void labelsFormatChanged(const QString &format); | 
| 126 |     void labelsPositionChanged(QBarSeries::LabelsPosition position); | 
| 127 |     void barsTypeChanged(QBarSeries::BarsType type); | 
| 128 |     void labelsMarginChanged(qreal margin); | 
| 129 |     void labelsAngleChanged(qreal angle); | 
| 130 |     void labelsPrecisionChanged(int precision); | 
| 131 |     void barDelegateChanged(); | 
| 132 |  | 
| 133 |     void barsetsAdded(const QList<QBarSet *> &sets); | 
| 134 |     void barsetsReplaced(const QList<QBarSet *> &sets); | 
| 135 |     void barsetsRemoved(const QList<QBarSet *> &sets); | 
| 136 |     void setValueChanged(qsizetype index, QBarSet *barset); | 
| 137 |     void setValueAdded(qsizetype index, qsizetype count, QBarSet *barset); | 
| 138 |     void setValueRemoved(qsizetype index, qsizetype count, QBarSet *barset); | 
| 139 |     void barSetsChanged(); | 
| 140 |  | 
| 141 | private Q_SLOTS: | 
| 142 |     void handleSetValueChange(qsizetype index); | 
| 143 |     void handleSetValueAdd(qsizetype index, qsizetype count); | 
| 144 |     void handleSetValueRemove(qsizetype index, qsizetype count); | 
| 145 |  | 
| 146 | private: | 
| 147 |     Q_DECLARE_PRIVATE(QBarSeries) | 
| 148 |     Q_DISABLE_COPY(QBarSeries) | 
| 149 |     friend class BarSet; | 
| 150 |     friend class BarsRenderer; | 
| 151 |     bool barDelegateDirty() const; | 
| 152 |     void setBarDelegateDirty(bool dirty); | 
| 153 | }; | 
| 154 |  | 
| 155 | QT_END_NAMESPACE | 
| 156 |  | 
| 157 | #endif // QTGRAPHS_QBARSERIES_H | 
| 158 |  |