| 1 | // Copyright (C) 2023 The Qt Company Ltd. |
| 2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only |
| 3 | |
| 4 | #ifndef QTGRAPHS_QABSTRACTSERIES_H |
| 5 | #define QTGRAPHS_QABSTRACTSERIES_H |
| 6 | |
| 7 | #include <QtCore/qobject.h> |
| 8 | #include <QtGraphs/qabstractaxis.h> |
| 9 | #include <QtGraphs/qgraphsglobal.h> |
| 10 | #include <QtGui/qpen.h> |
| 11 | #include <QtQml/qqmllist.h> |
| 12 | #include <QtQml/qqmlparserstatus.h> |
| 13 | |
| 14 | QT_BEGIN_NAMESPACE |
| 15 | |
| 16 | class QAbstractSeriesPrivate; |
| 17 | class QGraphsView; |
| 18 | |
| 19 | struct Q_GRAPHS_EXPORT QLegendData |
| 20 | { |
| 21 | Q_GADGET |
| 22 | Q_PROPERTY(QColor color MEMBER color FINAL) |
| 23 | Q_PROPERTY(QColor borderColor MEMBER borderColor FINAL) |
| 24 | Q_PROPERTY(QString label MEMBER label FINAL) |
| 25 | |
| 26 | public: |
| 27 | QColor color; |
| 28 | QColor borderColor; |
| 29 | QString label; |
| 30 | }; |
| 31 | |
| 32 | class Q_GRAPHS_EXPORT QAbstractSeries : public QObject, public QQmlParserStatus |
| 33 | { |
| 34 | Q_OBJECT |
| 35 | Q_DECLARE_PRIVATE(QAbstractSeries) |
| 36 | Q_CLASSINFO("RegisterEnumClassesUnscoped" , "false" ) |
| 37 | Q_INTERFACES(QQmlParserStatus) |
| 38 | Q_PROPERTY(QString name READ name WRITE setName NOTIFY nameChanged FINAL) |
| 39 | Q_PROPERTY(bool visible READ isVisible WRITE setVisible NOTIFY visibleChanged FINAL) |
| 40 | Q_PROPERTY(bool selectable READ isSelectable WRITE setSelectable NOTIFY selectableChanged FINAL) |
| 41 | Q_PROPERTY(bool hoverable READ isHoverable WRITE setHoverable NOTIFY hoverableChanged FINAL) |
| 42 | Q_PROPERTY(qreal opacity READ opacity WRITE setOpacity NOTIFY opacityChanged FINAL) |
| 43 | Q_PROPERTY(qreal valuesMultiplier READ valuesMultiplier WRITE setValuesMultiplier NOTIFY |
| 44 | valuesMultiplierChanged FINAL) |
| 45 | Q_PROPERTY(SeriesType type READ type CONSTANT FINAL) |
| 46 | Q_PROPERTY(QQmlListProperty<QObject> seriesChildren READ seriesChildren CONSTANT FINAL) |
| 47 | Q_PROPERTY(QList<QLegendData> legendData READ legendData NOTIFY legendDataChanged FINAL) |
| 48 | Q_CLASSINFO("DefaultProperty" , "seriesChildren" ) |
| 49 | |
| 50 | public: |
| 51 | enum class SeriesType { |
| 52 | Line, |
| 53 | Area, |
| 54 | Bar, |
| 55 | Pie, |
| 56 | Scatter, |
| 57 | Spline, |
| 58 | }; |
| 59 | Q_ENUM(SeriesType) |
| 60 | |
| 61 | protected: |
| 62 | explicit QAbstractSeries(QAbstractSeriesPrivate &dd, QObject *parent = nullptr); |
| 63 | |
| 64 | // from QDeclarativeParserStatus |
| 65 | void classBegin() override; |
| 66 | void componentComplete() override; |
| 67 | |
| 68 | public: |
| 69 | ~QAbstractSeries() override; |
| 70 | virtual SeriesType type() const = 0; |
| 71 | |
| 72 | QString name() const; |
| 73 | void setName(const QString &name); |
| 74 | |
| 75 | bool isVisible() const; |
| 76 | void setVisible(bool visible = true); |
| 77 | |
| 78 | bool isSelectable() const; |
| 79 | void setSelectable(bool selectable); |
| 80 | |
| 81 | qreal opacity() const; |
| 82 | void setOpacity(qreal opacity); |
| 83 | |
| 84 | qreal valuesMultiplier() const; |
| 85 | void setValuesMultiplier(qreal valuesMultiplier); |
| 86 | |
| 87 | QGraphsView *graph() const; |
| 88 | void setGraph(QGraphsView *graph); |
| 89 | |
| 90 | const QList<QLegendData> legendData() const; |
| 91 | |
| 92 | void show(); |
| 93 | void hide(); |
| 94 | |
| 95 | QQmlListProperty<QObject> seriesChildren(); |
| 96 | |
| 97 | bool isHoverable() const; |
| 98 | void setHoverable(bool newHoverable); |
| 99 | |
| 100 | bool hasLoaded() const; |
| 101 | |
| 102 | Q_SIGNALS: |
| 103 | void update(); |
| 104 | void nameChanged(); |
| 105 | void visibleChanged(); |
| 106 | void selectableChanged(); |
| 107 | void hoverableChanged(); |
| 108 | void opacityChanged(); |
| 109 | void valuesMultiplierChanged(); |
| 110 | void legendDataChanged(); |
| 111 | void hoverEnter(const QString &seriesName, QPointF position, QPointF value); |
| 112 | void hoverExit(const QString &seriesName, QPointF position); |
| 113 | void hover(const QString &seriesName, QPointF position, QPointF value); |
| 114 | |
| 115 | protected: |
| 116 | friend class BarsRenderer; |
| 117 | friend class PointRenderer; |
| 118 | friend class PieRenderer; |
| 119 | friend class AreaRenderer; |
| 120 | }; |
| 121 | |
| 122 | QT_END_NAMESPACE |
| 123 | |
| 124 | Q_DECLARE_METATYPE(QLegendData) |
| 125 | |
| 126 | #endif // QTGRAPHS_QABSTRACTSERIES_H |
| 127 | |