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