1 | // Copyright (C) 2022 The Qt Company Ltd. |
2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only |
3 | |
4 | #ifndef QXYSERIES_H |
5 | #define QXYSERIES_H |
6 | |
7 | #include <QtCharts/QChartGlobal> |
8 | #include <QtCharts/QAbstractSeries> |
9 | #include <QtGui/QPen> |
10 | #include <QtGui/QBrush> |
11 | #include <QtGui/QImage> |
12 | |
13 | QT_BEGIN_NAMESPACE |
14 | class QModelIndex; |
15 | QT_END_NAMESPACE |
16 | |
17 | QT_BEGIN_NAMESPACE |
18 | |
19 | class QXYSeriesPrivate; |
20 | class QXYModelMapper; |
21 | |
22 | class Q_CHARTS_EXPORT QXYSeries : public QAbstractSeries |
23 | { |
24 | Q_OBJECT |
25 | Q_PROPERTY(bool pointsVisible READ pointsVisible WRITE setPointsVisible) |
26 | Q_PROPERTY(QColor color READ color WRITE setColor NOTIFY colorChanged) |
27 | Q_PROPERTY(QColor selectedColor READ color WRITE setSelectedColor NOTIFY selectedColorChanged REVISION(6, 2)) |
28 | Q_PROPERTY(QString pointLabelsFormat READ pointLabelsFormat WRITE setPointLabelsFormat NOTIFY pointLabelsFormatChanged) |
29 | Q_PROPERTY(bool pointLabelsVisible READ pointLabelsVisible WRITE setPointLabelsVisible NOTIFY pointLabelsVisibilityChanged) |
30 | Q_PROPERTY(QFont pointLabelsFont READ pointLabelsFont WRITE setPointLabelsFont NOTIFY pointLabelsFontChanged) |
31 | Q_PROPERTY(QColor pointLabelsColor READ pointLabelsColor WRITE setPointLabelsColor NOTIFY pointLabelsColorChanged) |
32 | Q_PROPERTY(bool pointLabelsClipping READ pointLabelsClipping WRITE setPointLabelsClipping NOTIFY pointLabelsClippingChanged) |
33 | Q_PROPERTY(bool bestFitLineVisible READ bestFitLineVisible WRITE setBestFitLineVisible NOTIFY bestFitLineVisibilityChanged REVISION(6, 2)) |
34 | Q_PROPERTY(QColor bestFitLineColor READ bestFitLineColor WRITE setBestFitLineColor NOTIFY bestFitLineColorChanged REVISION(6, 2)) |
35 | |
36 | protected: |
37 | explicit QXYSeries(QXYSeriesPrivate &d, QObject *parent = nullptr); |
38 | |
39 | public: |
40 | enum class PointConfiguration { |
41 | Color = 0, |
42 | Size, |
43 | Visibility, |
44 | LabelVisibility, |
45 | LabelFormat |
46 | }; |
47 | Q_ENUM(PointConfiguration) |
48 | |
49 | public: |
50 | ~QXYSeries(); |
51 | void append(qreal x, qreal y); |
52 | void append(const QPointF &point); |
53 | void append(const QList<QPointF> &points); |
54 | void replace(qreal oldX, qreal oldY, qreal newX, qreal newY); |
55 | void replace(const QPointF &oldPoint, const QPointF &newPoint); |
56 | void replace(int index, qreal newX, qreal newY); |
57 | void replace(int index, const QPointF &newPoint); |
58 | void remove(qreal x, qreal y); |
59 | void remove(const QPointF &point); |
60 | void remove(int index); |
61 | void removePoints(int index, int count); |
62 | void insert(int index, const QPointF &point); |
63 | void clear(); |
64 | |
65 | int count() const; |
66 | QList<QPointF> points() const; |
67 | #if QT_DEPRECATED_SINCE(6, 0) |
68 | QT_DEPRECATED_X("Use points() instead" ) |
69 | QList<QPointF> pointsVector() const; |
70 | #endif |
71 | const QPointF &at(int index) const; |
72 | |
73 | QXYSeries &operator << (const QPointF &point); |
74 | QXYSeries &operator << (const QList<QPointF> &points); |
75 | |
76 | virtual void setPen(const QPen &pen); |
77 | QPen pen() const; |
78 | |
79 | virtual void setBrush(const QBrush &brush); |
80 | QBrush brush() const; |
81 | |
82 | virtual void setColor(const QColor &color); |
83 | virtual QColor color() const; |
84 | |
85 | void setSelectedColor(const QColor &color); |
86 | QColor selectedColor() const; |
87 | |
88 | void setPointsVisible(bool visible = true); |
89 | bool pointsVisible() const; |
90 | |
91 | void setPointLabelsFormat(const QString &format); |
92 | QString pointLabelsFormat() const; |
93 | |
94 | void setPointLabelsVisible(bool visible = true); |
95 | bool pointLabelsVisible() const; |
96 | |
97 | void setPointLabelsFont(const QFont &font); |
98 | QFont pointLabelsFont() const; |
99 | |
100 | void setPointLabelsColor(const QColor &color); |
101 | QColor pointLabelsColor() const; |
102 | |
103 | void setPointLabelsClipping(bool enabled = true); |
104 | bool pointLabelsClipping() const; |
105 | |
106 | void replace(const QList<QPointF> &points); |
107 | |
108 | bool isPointSelected(int index); |
109 | void selectPoint(int index); |
110 | void deselectPoint(int index); |
111 | void setPointSelected(int index, bool selected); |
112 | void selectAllPoints(); |
113 | void deselectAllPoints(); |
114 | void selectPoints(const QList<int> &indexes); |
115 | void deselectPoints(const QList<int> &indexes); |
116 | void toggleSelection(const QList<int> &indexes); |
117 | QList<int> selectedPoints() const; |
118 | |
119 | void setLightMarker(const QImage &lightMarker); |
120 | const QImage &lightMarker() const; |
121 | |
122 | void setSelectedLightMarker(const QImage &selectedLightMarker); |
123 | const QImage &selectedLightMarker() const; |
124 | |
125 | void setMarkerSize(qreal size); |
126 | qreal markerSize() const; |
127 | |
128 | void setBestFitLineVisible(bool visible = true); |
129 | bool bestFitLineVisible() const; |
130 | QPair<qreal, qreal> bestFitLineEquation(bool &ok) const; |
131 | |
132 | void setBestFitLinePen(const QPen &pen); |
133 | QPen bestFitLinePen() const; |
134 | void setBestFitLineColor(const QColor &color); |
135 | QColor bestFitLineColor() const; |
136 | |
137 | void clearPointConfiguration(const int index); |
138 | void clearPointConfiguration(const int index, const PointConfiguration key); |
139 | void clearPointsConfiguration(); |
140 | void clearPointsConfiguration(const PointConfiguration key); |
141 | void setPointConfiguration(const int index, |
142 | const QHash<PointConfiguration, QVariant> &configuration); |
143 | void setPointConfiguration(const int index, const PointConfiguration key, |
144 | const QVariant &value); |
145 | void setPointsConfiguration( |
146 | const QHash<int, QHash<QXYSeries::PointConfiguration, QVariant>> &pointsConfiguration); |
147 | QHash<PointConfiguration, QVariant> pointConfiguration(const int index) const; |
148 | QHash<int, QHash<PointConfiguration, QVariant>> pointsConfiguration() const; |
149 | |
150 | void sizeBy(const QList<qreal> &sourceData, const qreal minSize, const qreal maxSize); |
151 | void colorBy(const QList<qreal> &sourceData, const QLinearGradient &gradient = QLinearGradient()); |
152 | |
153 | Q_SIGNALS: |
154 | void clicked(const QPointF &point); |
155 | void hovered(const QPointF &point, bool state); |
156 | void pressed(const QPointF &point); |
157 | void released(const QPointF &point); |
158 | void doubleClicked(const QPointF &point); |
159 | void pointReplaced(int index); |
160 | void pointRemoved(int index); |
161 | void pointAdded(int index); |
162 | void colorChanged(QColor color); |
163 | Q_REVISION(6, 2) void selectedColorChanged(const QColor &color); |
164 | void pointsReplaced(); |
165 | void pointLabelsFormatChanged(const QString &format); |
166 | void pointLabelsVisibilityChanged(bool visible); |
167 | void pointLabelsFontChanged(const QFont &font); |
168 | void pointLabelsColorChanged(const QColor &color); |
169 | void pointLabelsClippingChanged(bool clipping); |
170 | void pointsRemoved(int index, int count); |
171 | void penChanged(const QPen &pen); |
172 | void selectedPointsChanged(); |
173 | Q_REVISION(6, 2) void lightMarkerChanged(const QImage &lightMarker); |
174 | Q_REVISION(6, 2) void selectedLightMarkerChanged(const QImage &selectedLightMarker); |
175 | Q_REVISION(6, 2) void bestFitLineVisibilityChanged(bool visible); |
176 | Q_REVISION(6, 2) void bestFitLinePenChanged(const QPen &pen); |
177 | Q_REVISION(6, 2) void bestFitLineColorChanged(const QColor &color); |
178 | Q_REVISION(6, 2) void pointsConfigurationChanged( |
179 | const QHash<int, QHash<PointConfiguration, QVariant>> &configuration); |
180 | void markerSizeChanged(qreal size); |
181 | |
182 | private: |
183 | Q_DECLARE_PRIVATE(QXYSeries) |
184 | Q_DISABLE_COPY(QXYSeries) |
185 | friend class QXYLegendMarkerPrivate; |
186 | friend class XYLegendMarker; |
187 | friend class XYChart; |
188 | friend class QColorAxisPrivate; |
189 | }; |
190 | |
191 | QT_END_NAMESPACE |
192 | |
193 | #endif // QXYSERIES_H |
194 | |