##// END OF EJS Templates
Fix DeclarativeChart::legend property...
Titta Heikkala -
r2685:ccb5e8a7f100
parent child
Show More
@@ -1,235 +1,235
1 /****************************************************************************
1 /****************************************************************************
2 **
2 **
3 ** Copyright (C) 2013 Digia Plc
3 ** Copyright (C) 2013 Digia Plc
4 ** All rights reserved.
4 ** All rights reserved.
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 **
6 **
7 ** This file is part of the Qt Enterprise Charts Add-on.
7 ** This file is part of the Qt Enterprise Charts Add-on.
8 **
8 **
9 ** $QT_BEGIN_LICENSE$
9 ** $QT_BEGIN_LICENSE$
10 ** Licensees holding valid Qt Enterprise licenses may use this file in
10 ** Licensees holding valid Qt Enterprise licenses may use this file in
11 ** accordance with the Qt Enterprise License Agreement provided with the
11 ** accordance with the Qt Enterprise License Agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia.
13 ** a written agreement between you and Digia.
14 **
14 **
15 ** If you have questions regarding the use of this file, please use
15 ** If you have questions regarding the use of this file, please use
16 ** contact form at http://qt.digia.com
16 ** contact form at http://qt.digia.com
17 ** $QT_END_LICENSE$
17 ** $QT_END_LICENSE$
18 **
18 **
19 ****************************************************************************/
19 ****************************************************************************/
20
20
21 #ifndef DECLARATIVECHART_H
21 #ifndef DECLARATIVECHART_H
22 #define DECLARATIVECHART_H
22 #define DECLARATIVECHART_H
23
23
24 #include <QtCore/QtGlobal>
24 #include <QtCore/QtGlobal>
25 #include "shared_defines.h"
25 #include "shared_defines.h"
26
26
27 #ifdef CHARTS_FOR_QUICK2
27 #ifdef CHARTS_FOR_QUICK2
28 #include <QtQuick/QQuickItem>
28 #include <QtQuick/QQuickItem>
29 #include <QtQuick/QQuickPaintedItem>
29 #include <QtQuick/QQuickPaintedItem>
30 #include <QtWidgets/QGraphicsScene>
30 #include <QtWidgets/QGraphicsScene>
31 #include <QtCore/QMutex>
31 #include <QtCore/QMutex>
32 #else
32 #else
33 #include <QtDeclarative/QDeclarativeItem>
33 #include <QtDeclarative/QDeclarativeItem>
34 #endif
34 #endif
35
35
36 #include "qchart.h"
36 #include "qchart.h"
37
37
38 QTCOMMERCIALCHART_BEGIN_NAMESPACE
38 QTCOMMERCIALCHART_BEGIN_NAMESPACE
39
39
40 class DeclarativeMargins;
40 class DeclarativeMargins;
41 class Domain;
41 class Domain;
42 class DeclarativeAxes;
42 class DeclarativeAxes;
43
43
44 class DeclarativeChart : public QDECLARATIVE_PAINTED_ITEM
44 class DeclarativeChart : public QDECLARATIVE_PAINTED_ITEM
45 {
45 {
46 Q_OBJECT
46 Q_OBJECT
47 Q_PROPERTY(Theme theme READ theme WRITE setTheme)
47 Q_PROPERTY(Theme theme READ theme WRITE setTheme)
48 Q_PROPERTY(Animation animationOptions READ animationOptions WRITE setAnimationOptions)
48 Q_PROPERTY(Animation animationOptions READ animationOptions WRITE setAnimationOptions)
49 Q_PROPERTY(QString title READ title WRITE setTitle)
49 Q_PROPERTY(QString title READ title WRITE setTitle)
50 Q_PROPERTY(QFont titleFont READ titleFont WRITE setTitleFont)
50 Q_PROPERTY(QFont titleFont READ titleFont WRITE setTitleFont)
51 Q_PROPERTY(QColor titleColor READ titleColor WRITE setTitleColor NOTIFY titleColorChanged)
51 Q_PROPERTY(QColor titleColor READ titleColor WRITE setTitleColor NOTIFY titleColorChanged)
52 Q_PROPERTY(QLegend *legend READ legend)
52 Q_PROPERTY(QLegend *legend READ legend CONSTANT)
53 Q_PROPERTY(int count READ count)
53 Q_PROPERTY(int count READ count)
54 Q_PROPERTY(QColor backgroundColor READ backgroundColor WRITE setBackgroundColor NOTIFY backgroundColorChanged)
54 Q_PROPERTY(QColor backgroundColor READ backgroundColor WRITE setBackgroundColor NOTIFY backgroundColorChanged)
55 Q_PROPERTY(bool dropShadowEnabled READ dropShadowEnabled WRITE setDropShadowEnabled NOTIFY dropShadowEnabledChanged)
55 Q_PROPERTY(bool dropShadowEnabled READ dropShadowEnabled WRITE setDropShadowEnabled NOTIFY dropShadowEnabledChanged)
56 Q_PROPERTY(qreal backgroundRoundness READ backgroundRoundness WRITE setBackgroundRoundness NOTIFY backgroundRoundnessChanged REVISION 3)
56 Q_PROPERTY(qreal backgroundRoundness READ backgroundRoundness WRITE setBackgroundRoundness NOTIFY backgroundRoundnessChanged REVISION 3)
57 Q_PROPERTY(qreal topMargin READ topMargin)
57 Q_PROPERTY(qreal topMargin READ topMargin)
58 Q_PROPERTY(qreal bottomMargin READ bottomMargin)
58 Q_PROPERTY(qreal bottomMargin READ bottomMargin)
59 Q_PROPERTY(qreal leftMargin READ leftMargin)
59 Q_PROPERTY(qreal leftMargin READ leftMargin)
60 Q_PROPERTY(qreal rightMargin READ rightMargin)
60 Q_PROPERTY(qreal rightMargin READ rightMargin)
61 Q_PROPERTY(DeclarativeMargins *minimumMargins READ minimumMargins NOTIFY minimumMarginsChanged REVISION 1)
61 Q_PROPERTY(DeclarativeMargins *minimumMargins READ minimumMargins NOTIFY minimumMarginsChanged REVISION 1)
62 Q_PROPERTY(DeclarativeMargins *margins READ margins NOTIFY marginsChanged REVISION 2)
62 Q_PROPERTY(DeclarativeMargins *margins READ margins NOTIFY marginsChanged REVISION 2)
63 Q_PROPERTY(QRectF plotArea READ plotArea NOTIFY plotAreaChanged REVISION 1)
63 Q_PROPERTY(QRectF plotArea READ plotArea NOTIFY plotAreaChanged REVISION 1)
64 Q_PROPERTY(QColor plotAreaColor READ plotAreaColor WRITE setPlotAreaColor NOTIFY plotAreaColorChanged REVISION 3)
64 Q_PROPERTY(QColor plotAreaColor READ plotAreaColor WRITE setPlotAreaColor NOTIFY plotAreaColorChanged REVISION 3)
65 #ifdef CHARTS_FOR_QUICK2
65 #ifdef CHARTS_FOR_QUICK2
66 Q_PROPERTY(QQmlListProperty<QAbstractAxis> axes READ axes REVISION 2)
66 Q_PROPERTY(QQmlListProperty<QAbstractAxis> axes READ axes REVISION 2)
67 #else
67 #else
68 Q_PROPERTY(QDeclarativeListProperty<QAbstractAxis> axes READ axes REVISION 2)
68 Q_PROPERTY(QDeclarativeListProperty<QAbstractAxis> axes READ axes REVISION 2)
69 #endif
69 #endif
70 Q_ENUMS(Animation)
70 Q_ENUMS(Animation)
71 Q_ENUMS(Theme)
71 Q_ENUMS(Theme)
72 Q_ENUMS(SeriesType)
72 Q_ENUMS(SeriesType)
73
73
74 public:
74 public:
75 // duplicating enums from QChart to make the QML api namings 1-to-1 with the C++ api
75 // duplicating enums from QChart to make the QML api namings 1-to-1 with the C++ api
76 enum Theme {
76 enum Theme {
77 ChartThemeLight = 0,
77 ChartThemeLight = 0,
78 ChartThemeBlueCerulean,
78 ChartThemeBlueCerulean,
79 ChartThemeDark,
79 ChartThemeDark,
80 ChartThemeBrownSand,
80 ChartThemeBrownSand,
81 ChartThemeBlueNcs,
81 ChartThemeBlueNcs,
82 ChartThemeHighContrast,
82 ChartThemeHighContrast,
83 ChartThemeBlueIcy,
83 ChartThemeBlueIcy,
84 ChartThemeQt
84 ChartThemeQt
85 };
85 };
86
86
87 enum Animation {
87 enum Animation {
88 NoAnimation = 0x0,
88 NoAnimation = 0x0,
89 GridAxisAnimations = 0x1,
89 GridAxisAnimations = 0x1,
90 SeriesAnimations = 0x2,
90 SeriesAnimations = 0x2,
91 AllAnimations = 0x3
91 AllAnimations = 0x3
92 };
92 };
93
93
94 enum SeriesType {
94 enum SeriesType {
95 SeriesTypeLine,
95 SeriesTypeLine,
96 SeriesTypeArea,
96 SeriesTypeArea,
97 SeriesTypeBar,
97 SeriesTypeBar,
98 SeriesTypeStackedBar,
98 SeriesTypeStackedBar,
99 SeriesTypePercentBar,
99 SeriesTypePercentBar,
100 SeriesTypeBoxPlot,
100 SeriesTypeBoxPlot,
101 SeriesTypePie,
101 SeriesTypePie,
102 SeriesTypeScatter,
102 SeriesTypeScatter,
103 SeriesTypeSpline,
103 SeriesTypeSpline,
104 SeriesTypeHorizontalBar,
104 SeriesTypeHorizontalBar,
105 SeriesTypeHorizontalStackedBar,
105 SeriesTypeHorizontalStackedBar,
106 SeriesTypeHorizontalPercentBar
106 SeriesTypeHorizontalPercentBar
107 };
107 };
108
108
109 public:
109 public:
110 DeclarativeChart(QDECLARATIVE_ITEM *parent = 0);
110 DeclarativeChart(QDECLARATIVE_ITEM *parent = 0);
111 ~DeclarativeChart();
111 ~DeclarativeChart();
112
112
113 public: // From parent classes
113 public: // From parent classes
114 void childEvent(QChildEvent *event);
114 void childEvent(QChildEvent *event);
115 void componentComplete();
115 void componentComplete();
116 void geometryChanged(const QRectF &newGeometry, const QRectF &oldGeometry);
116 void geometryChanged(const QRectF &newGeometry, const QRectF &oldGeometry);
117 #ifdef CHARTS_FOR_QUICK2
117 #ifdef CHARTS_FOR_QUICK2
118 void paint(QPainter *painter);
118 void paint(QPainter *painter);
119 protected:
119 protected:
120 void mousePressEvent(QMouseEvent *event);
120 void mousePressEvent(QMouseEvent *event);
121 void mouseReleaseEvent(QMouseEvent *event);
121 void mouseReleaseEvent(QMouseEvent *event);
122 void hoverMoveEvent(QHoverEvent *event);
122 void hoverMoveEvent(QHoverEvent *event);
123 private Q_SLOTS:
123 private Q_SLOTS:
124 void handleAntialiasingChanged(bool enable);
124 void handleAntialiasingChanged(bool enable);
125 void sceneChanged(QList<QRectF> region);
125 void sceneChanged(QList<QRectF> region);
126 void renderScene();
126 void renderScene();
127 #endif
127 #endif
128
128
129 public:
129 public:
130 void setTheme(DeclarativeChart::Theme theme);
130 void setTheme(DeclarativeChart::Theme theme);
131 DeclarativeChart::Theme theme();
131 DeclarativeChart::Theme theme();
132 void setAnimationOptions(DeclarativeChart::Animation animations);
132 void setAnimationOptions(DeclarativeChart::Animation animations);
133 DeclarativeChart::Animation animationOptions();
133 DeclarativeChart::Animation animationOptions();
134 void setTitle(QString title);
134 void setTitle(QString title);
135 QString title();
135 QString title();
136 QLegend *legend();
136 QLegend *legend();
137 QFont titleFont() const;
137 QFont titleFont() const;
138 void setTitleFont(const QFont &font);
138 void setTitleFont(const QFont &font);
139 void setTitleColor(QColor color);
139 void setTitleColor(QColor color);
140 QColor titleColor();
140 QColor titleColor();
141 void setBackgroundColor(QColor color);
141 void setBackgroundColor(QColor color);
142 QColor backgroundColor();
142 QColor backgroundColor();
143 Q_REVISION(3) void setPlotAreaColor(QColor color);
143 Q_REVISION(3) void setPlotAreaColor(QColor color);
144 Q_REVISION(3) QColor plotAreaColor();
144 Q_REVISION(3) QColor plotAreaColor();
145 int count();
145 int count();
146 void setDropShadowEnabled(bool enabled);
146 void setDropShadowEnabled(bool enabled);
147 bool dropShadowEnabled();
147 bool dropShadowEnabled();
148 Q_REVISION(3) qreal backgroundRoundness() const;
148 Q_REVISION(3) qreal backgroundRoundness() const;
149 Q_REVISION(3) void setBackgroundRoundness(qreal diameter);
149 Q_REVISION(3) void setBackgroundRoundness(qreal diameter);
150
150
151 // Margins & plotArea
151 // Margins & plotArea
152 qreal topMargin();
152 qreal topMargin();
153 qreal bottomMargin();
153 qreal bottomMargin();
154 qreal leftMargin();
154 qreal leftMargin();
155 qreal rightMargin();
155 qreal rightMargin();
156 DeclarativeMargins *minimumMargins() { return m_margins; }
156 DeclarativeMargins *minimumMargins() { return m_margins; }
157 Q_REVISION(2) DeclarativeMargins *margins() { return m_margins; }
157 Q_REVISION(2) DeclarativeMargins *margins() { return m_margins; }
158 QRectF plotArea() { return m_chart->plotArea(); }
158 QRectF plotArea() { return m_chart->plotArea(); }
159
159
160 // Axis handling
160 // Axis handling
161 QAbstractAxis *defaultAxis(Qt::Orientation orientation, QAbstractSeries *series);
161 QAbstractAxis *defaultAxis(Qt::Orientation orientation, QAbstractSeries *series);
162 void initializeAxes(QAbstractSeries *series);
162 void initializeAxes(QAbstractSeries *series);
163 void doInitializeAxes(QAbstractSeries *series, DeclarativeAxes *axes);
163 void doInitializeAxes(QAbstractSeries *series, DeclarativeAxes *axes);
164 QDECLARATIVE_LIST_PROPERTY<QAbstractAxis> axes();
164 QDECLARATIVE_LIST_PROPERTY<QAbstractAxis> axes();
165 static void axesAppendFunc(QDECLARATIVE_LIST_PROPERTY<QAbstractAxis> *list, QAbstractAxis *element);
165 static void axesAppendFunc(QDECLARATIVE_LIST_PROPERTY<QAbstractAxis> *list, QAbstractAxis *element);
166 static int axesCountFunc(QDECLARATIVE_LIST_PROPERTY<QAbstractAxis> *list);
166 static int axesCountFunc(QDECLARATIVE_LIST_PROPERTY<QAbstractAxis> *list);
167 static QAbstractAxis *axesAtFunc(QDECLARATIVE_LIST_PROPERTY<QAbstractAxis> *list, int index);
167 static QAbstractAxis *axesAtFunc(QDECLARATIVE_LIST_PROPERTY<QAbstractAxis> *list, int index);
168 static void axesClearFunc(QDECLARATIVE_LIST_PROPERTY<QAbstractAxis> *list);
168 static void axesClearFunc(QDECLARATIVE_LIST_PROPERTY<QAbstractAxis> *list);
169
169
170 public:
170 public:
171 Q_INVOKABLE QAbstractSeries *series(int index);
171 Q_INVOKABLE QAbstractSeries *series(int index);
172 Q_INVOKABLE QAbstractSeries *series(QString seriesName);
172 Q_INVOKABLE QAbstractSeries *series(QString seriesName);
173 Q_INVOKABLE QAbstractSeries *createSeries(int type, QString name = "", QAbstractAxis *axisX = 0, QAbstractAxis *axisY = 0);
173 Q_INVOKABLE QAbstractSeries *createSeries(int type, QString name = "", QAbstractAxis *axisX = 0, QAbstractAxis *axisY = 0);
174 Q_INVOKABLE void removeSeries(QAbstractSeries *series);
174 Q_INVOKABLE void removeSeries(QAbstractSeries *series);
175 Q_INVOKABLE void removeAllSeries() { m_chart->removeAllSeries(); }
175 Q_INVOKABLE void removeAllSeries() { m_chart->removeAllSeries(); }
176 Q_INVOKABLE void setAxisX(QAbstractAxis *axis, QAbstractSeries *series = 0);
176 Q_INVOKABLE void setAxisX(QAbstractAxis *axis, QAbstractSeries *series = 0);
177 Q_INVOKABLE void setAxisY(QAbstractAxis *axis, QAbstractSeries *series = 0);
177 Q_INVOKABLE void setAxisY(QAbstractAxis *axis, QAbstractSeries *series = 0);
178 Q_INVOKABLE void createDefaultAxes();
178 Q_INVOKABLE void createDefaultAxes();
179 Q_INVOKABLE QAbstractAxis *axisX(QAbstractSeries *series = 0);
179 Q_INVOKABLE QAbstractAxis *axisX(QAbstractSeries *series = 0);
180 Q_INVOKABLE QAbstractAxis *axisY(QAbstractSeries *series = 0);
180 Q_INVOKABLE QAbstractAxis *axisY(QAbstractSeries *series = 0);
181 Q_INVOKABLE void zoom(qreal factor);
181 Q_INVOKABLE void zoom(qreal factor);
182 Q_INVOKABLE void scrollLeft(qreal pixels);
182 Q_INVOKABLE void scrollLeft(qreal pixels);
183 Q_INVOKABLE void scrollRight(qreal pixels);
183 Q_INVOKABLE void scrollRight(qreal pixels);
184 Q_INVOKABLE void scrollUp(qreal pixels);
184 Q_INVOKABLE void scrollUp(qreal pixels);
185 Q_INVOKABLE void scrollDown(qreal pixels);
185 Q_INVOKABLE void scrollDown(qreal pixels);
186
186
187 Q_SIGNALS:
187 Q_SIGNALS:
188 void axisLabelsChanged();
188 void axisLabelsChanged();
189 void titleColorChanged(QColor color);
189 void titleColorChanged(QColor color);
190 void backgroundColorChanged();
190 void backgroundColorChanged();
191 void dropShadowEnabledChanged(bool enabled);
191 void dropShadowEnabledChanged(bool enabled);
192 void minimumMarginsChanged();
192 void minimumMarginsChanged();
193 Q_REVISION(2) void marginsChanged();
193 Q_REVISION(2) void marginsChanged();
194 void plotAreaChanged(QRectF plotArea);
194 void plotAreaChanged(QRectF plotArea);
195 void seriesAdded(QAbstractSeries *series);
195 void seriesAdded(QAbstractSeries *series);
196 void seriesRemoved(QAbstractSeries *series);
196 void seriesRemoved(QAbstractSeries *series);
197 Q_REVISION(3) void plotAreaColorChanged();
197 Q_REVISION(3) void plotAreaColorChanged();
198 Q_REVISION(3) void backgroundRoundnessChanged(qreal diameter);
198 Q_REVISION(3) void backgroundRoundnessChanged(qreal diameter);
199
199
200 private Q_SLOTS:
200 private Q_SLOTS:
201 void changeMinimumMargins(int top, int bottom, int left, int right);
201 void changeMinimumMargins(int top, int bottom, int left, int right);
202 void handleAxisXSet(QAbstractAxis *axis);
202 void handleAxisXSet(QAbstractAxis *axis);
203 void handleAxisYSet(QAbstractAxis *axis);
203 void handleAxisYSet(QAbstractAxis *axis);
204 void handleAxisXTopSet(QAbstractAxis *axis);
204 void handleAxisXTopSet(QAbstractAxis *axis);
205 void handleAxisYRightSet(QAbstractAxis *axis);
205 void handleAxisYRightSet(QAbstractAxis *axis);
206 void handleSeriesAdded(QAbstractSeries *series);
206 void handleSeriesAdded(QAbstractSeries *series);
207
207
208 protected:
208 protected:
209 explicit DeclarativeChart(QChart::ChartType type, QDECLARATIVE_ITEM *parent);
209 explicit DeclarativeChart(QChart::ChartType type, QDECLARATIVE_ITEM *parent);
210
210
211 private:
211 private:
212 void initChart(QChart::ChartType type);
212 void initChart(QChart::ChartType type);
213 // Extending QChart with DeclarativeChart is not possible because QObject does not support
213 // Extending QChart with DeclarativeChart is not possible because QObject does not support
214 // multi inheritance, so we now have a QChart as a member instead
214 // multi inheritance, so we now have a QChart as a member instead
215 QChart *m_chart;
215 QChart *m_chart;
216 #ifdef CHARTS_FOR_QUICK2
216 #ifdef CHARTS_FOR_QUICK2
217 QGraphicsScene *m_scene;
217 QGraphicsScene *m_scene;
218 QPointF m_mousePressScenePoint;
218 QPointF m_mousePressScenePoint;
219 QPoint m_mousePressScreenPoint;
219 QPoint m_mousePressScreenPoint;
220 QPointF m_lastMouseMoveScenePoint;
220 QPointF m_lastMouseMoveScenePoint;
221 QPoint m_lastMouseMoveScreenPoint;
221 QPoint m_lastMouseMoveScreenPoint;
222 Qt::MouseButton m_mousePressButton;
222 Qt::MouseButton m_mousePressButton;
223 Qt::MouseButtons m_mousePressButtons;
223 Qt::MouseButtons m_mousePressButtons;
224 QMutex m_sceneImageLock;
224 QMutex m_sceneImageLock;
225 QImage *m_currentSceneImage;
225 QImage *m_currentSceneImage;
226 bool m_updatePending;
226 bool m_updatePending;
227 Qt::HANDLE m_paintThreadId;
227 Qt::HANDLE m_paintThreadId;
228 Qt::HANDLE m_guiThreadId;
228 Qt::HANDLE m_guiThreadId;
229 #endif
229 #endif
230 DeclarativeMargins *m_margins;
230 DeclarativeMargins *m_margins;
231 };
231 };
232
232
233 QTCOMMERCIALCHART_END_NAMESPACE
233 QTCOMMERCIALCHART_END_NAMESPACE
234
234
235 #endif // DECLARATIVECHART_H
235 #endif // DECLARATIVECHART_H
General Comments 0
You need to be logged in to leave comments. Login now