1// Copyright (C) 2023 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
3
4//
5// W A R N I N G
6// -------------
7//
8// This file is not part of the QtGraphs API. It exists purely as an
9// implementation detail. This header file may change from version to
10// version without notice, or even be removed.
11//
12// We mean it.
13
14#ifndef DECLARATIVESERIES_P_H
15#define DECLARATIVESERIES_P_H
16
17#include "qbar3dseries.h"
18#include "qscatter3dseries.h"
19#include "qsurface3dseries.h"
20#include "colorgradient_p.h"
21#include "declarativecolor_p.h"
22
23#include <private/graphsglobal_p.h>
24#include <QtQml/qqml.h>
25
26QT_BEGIN_NAMESPACE
27
28enum GradientType {
29 GradientTypeBase,
30 GradientTypeSingle,
31 GradientTypeMulti
32};
33
34class DeclarativeBar3DSeries : public QBar3DSeries
35{
36 Q_OBJECT
37 Q_PROPERTY(QQmlListProperty<QObject> seriesChildren READ seriesChildren CONSTANT)
38 // This property is overloaded to use QPointF instead of QPoint to work around qml bug
39 // where Qt.point(0, 0) can't be assigned due to error "Cannot assign QPointF to QPoint".
40 Q_PROPERTY(QPointF selectedBar READ selectedBar WRITE setSelectedBar NOTIFY selectedBarChanged)
41 // This is static method in parent class, overload as constant property for qml.
42 Q_PROPERTY(QPointF invalidSelectionPosition READ invalidSelectionPosition CONSTANT)
43 Q_PROPERTY(ColorGradient *baseGradient READ baseGradient WRITE setBaseGradient NOTIFY baseGradientChanged)
44 Q_PROPERTY(ColorGradient *singleHighlightGradient READ singleHighlightGradient WRITE setSingleHighlightGradient NOTIFY singleHighlightGradientChanged)
45 Q_PROPERTY(ColorGradient *multiHighlightGradient READ multiHighlightGradient WRITE setMultiHighlightGradient NOTIFY multiHighlightGradientChanged)
46 Q_PROPERTY(QQmlListProperty<DeclarativeColor> rowColors READ rowColors CONSTANT)
47 Q_CLASSINFO("DefaultProperty", "seriesChildren")
48
49 QML_NAMED_ELEMENT(Bar3DSeries)
50
51public:
52 DeclarativeBar3DSeries(QObject *parent = 0);
53 virtual ~DeclarativeBar3DSeries();
54
55 QQmlListProperty<QObject> seriesChildren();
56 static void appendSeriesChildren(QQmlListProperty<QObject> *list, QObject *element);
57
58 void setSelectedBar(const QPointF &position);
59 QPointF selectedBar() const;
60 QPointF invalidSelectionPosition() const;
61
62 void setBaseGradient(ColorGradient *gradient);
63 ColorGradient *baseGradient() const;
64 void setSingleHighlightGradient(ColorGradient *gradient);
65 ColorGradient *singleHighlightGradient() const;
66 void setMultiHighlightGradient(ColorGradient *gradient);
67 ColorGradient *multiHighlightGradient() const;
68
69 QQmlListProperty<DeclarativeColor> rowColors();
70 static void appendRowColorsFunc(QQmlListProperty<DeclarativeColor> *list,
71 DeclarativeColor *color);
72 static qsizetype countRowColorsFunc(QQmlListProperty<DeclarativeColor> *list);
73 static DeclarativeColor *atRowColorsFunc(QQmlListProperty<DeclarativeColor> *list,
74 qsizetype index);
75 static void clearRowColorsFunc(QQmlListProperty<DeclarativeColor> *list);
76
77public Q_SLOTS:
78 void handleBaseGradientUpdate();
79 void handleSingleHighlightGradientUpdate();
80 void handleMultiHighlightGradientUpdate();
81 void handleRowColorUpdate();
82
83Q_SIGNALS:
84 void selectedBarChanged(const QPointF &position);
85 void baseGradientChanged(ColorGradient *gradient);
86 void singleHighlightGradientChanged(ColorGradient *gradient);
87 void multiHighlightGradientChanged(ColorGradient *gradient);
88
89private:
90 ColorGradient *m_baseGradient; // Not owned
91 ColorGradient *m_singleHighlightGradient; // Not owned
92 ColorGradient *m_multiHighlightGradient; // Not owned
93
94 QList<DeclarativeColor *> m_rowColors;
95 bool m_dummyColors;
96
97 void addColor(DeclarativeColor *color);
98 QList<DeclarativeColor *> colorList();
99 void clearColors();
100 void clearDummyColors();
101};
102
103class DeclarativeScatter3DSeries : public QScatter3DSeries
104{
105 Q_OBJECT
106 Q_PROPERTY(QQmlListProperty<QObject> seriesChildren READ seriesChildren CONSTANT)
107 Q_PROPERTY(ColorGradient *baseGradient READ baseGradient WRITE setBaseGradient NOTIFY baseGradientChanged)
108 Q_PROPERTY(ColorGradient *singleHighlightGradient READ singleHighlightGradient WRITE setSingleHighlightGradient NOTIFY singleHighlightGradientChanged)
109 Q_PROPERTY(ColorGradient *multiHighlightGradient READ multiHighlightGradient WRITE setMultiHighlightGradient NOTIFY multiHighlightGradientChanged)
110 // This is static method in parent class, overload as constant property for qml.
111 Q_PROPERTY(int invalidSelectionIndex READ invalidSelectionIndex CONSTANT)
112 Q_CLASSINFO("DefaultProperty", "seriesChildren")
113
114 QML_NAMED_ELEMENT(Scatter3DSeries)
115
116public:
117 DeclarativeScatter3DSeries(QObject *parent = 0);
118 virtual ~DeclarativeScatter3DSeries();
119
120 QQmlListProperty<QObject> seriesChildren();
121 static void appendSeriesChildren(QQmlListProperty<QObject> *list, QObject *element);
122
123 void setBaseGradient(ColorGradient *gradient);
124 ColorGradient *baseGradient() const;
125 void setSingleHighlightGradient(ColorGradient *gradient);
126 ColorGradient *singleHighlightGradient() const;
127 void setMultiHighlightGradient(ColorGradient *gradient);
128 ColorGradient *multiHighlightGradient() const;
129
130 int invalidSelectionIndex() const;
131
132public Q_SLOTS:
133 void handleBaseGradientUpdate();
134 void handleSingleHighlightGradientUpdate();
135 void handleMultiHighlightGradientUpdate();
136
137Q_SIGNALS:
138 void baseGradientChanged(ColorGradient *gradient);
139 void singleHighlightGradientChanged(ColorGradient *gradient);
140 void multiHighlightGradientChanged(ColorGradient *gradient);
141
142private:
143 ColorGradient *m_baseGradient; // Not owned
144 ColorGradient *m_singleHighlightGradient; // Not owned
145 ColorGradient *m_multiHighlightGradient; // Not owned
146};
147
148class DeclarativeSurface3DSeries : public QSurface3DSeries
149{
150 Q_OBJECT
151 Q_PROPERTY(QQmlListProperty<QObject> seriesChildren READ seriesChildren CONSTANT)
152 // This property is overloaded to use QPointF instead of QPoint to work around qml bug
153 // where Qt.point(0, 0) can't be assigned due to error "Cannot assign QPointF to QPoint".
154 Q_PROPERTY(QPointF selectedPoint READ selectedPoint WRITE setSelectedPoint NOTIFY selectedPointChanged)
155 // This is static method in parent class, overload as constant property for qml.
156 Q_PROPERTY(QPointF invalidSelectionPosition READ invalidSelectionPosition CONSTANT)
157 Q_PROPERTY(ColorGradient *baseGradient READ baseGradient WRITE setBaseGradient NOTIFY baseGradientChanged)
158 Q_PROPERTY(ColorGradient *singleHighlightGradient READ singleHighlightGradient WRITE setSingleHighlightGradient NOTIFY singleHighlightGradientChanged)
159 Q_PROPERTY(ColorGradient *multiHighlightGradient READ multiHighlightGradient WRITE setMultiHighlightGradient NOTIFY multiHighlightGradientChanged)
160 Q_CLASSINFO("DefaultProperty", "seriesChildren")
161
162 QML_NAMED_ELEMENT(Surface3DSeries)
163
164public:
165 DeclarativeSurface3DSeries(QObject *parent = 0);
166 virtual ~DeclarativeSurface3DSeries();
167
168 void setSelectedPoint(const QPointF &position);
169 QPointF selectedPoint() const;
170 QPointF invalidSelectionPosition() const;
171
172 QQmlListProperty<QObject> seriesChildren();
173 static void appendSeriesChildren(QQmlListProperty<QObject> *list, QObject *element);
174
175 void setBaseGradient(ColorGradient *gradient);
176 ColorGradient *baseGradient() const;
177 void setSingleHighlightGradient(ColorGradient *gradient);
178 ColorGradient *singleHighlightGradient() const;
179 void setMultiHighlightGradient(ColorGradient *gradient);
180 ColorGradient *multiHighlightGradient() const;
181
182public Q_SLOTS:
183 void handleBaseGradientUpdate();
184 void handleSingleHighlightGradientUpdate();
185 void handleMultiHighlightGradientUpdate();
186
187Q_SIGNALS:
188 void selectedPointChanged(const QPointF &position);
189 void baseGradientChanged(ColorGradient *gradient);
190 void singleHighlightGradientChanged(ColorGradient *gradient);
191 void multiHighlightGradientChanged(ColorGradient *gradient);
192
193private:
194 ColorGradient *m_baseGradient; // Not owned
195 ColorGradient *m_singleHighlightGradient; // Not owned
196 ColorGradient *m_multiHighlightGradient; // Not owned
197};
198
199QT_END_NAMESPACE
200
201#endif
202

source code of qtgraphs/src/graphs/qml/declarativeseries_p.h