@@ -1,769 +1,769 | |||
|
1 | 1 | /**************************************************************************** |
|
2 | 2 | ** |
|
3 | 3 | ** Copyright (C) 2012 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 Commercial Charts Add-on. |
|
8 | 8 | ** |
|
9 | 9 | ** $QT_BEGIN_LICENSE$ |
|
10 | 10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
11 | 11 | ** accordance with the Qt Commercial 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 | #include "declarativechart.h" |
|
22 | 22 | #include <QPainter> |
|
23 | 23 | #include <QDeclarativeEngine> |
|
24 | 24 | #include "declarativelineseries.h" |
|
25 | 25 | #include "declarativeareaseries.h" |
|
26 | 26 | #include "declarativebarseries.h" |
|
27 | 27 | #include "declarativepieseries.h" |
|
28 | 28 | #include "declarativesplineseries.h" |
|
29 | 29 | #include "declarativescatterseries.h" |
|
30 | 30 | #include "qbarcategoryaxis.h" |
|
31 | 31 | #include "qvalueaxis.h" |
|
32 | 32 | #include "qcategoryaxis.h" |
|
33 | 33 | #include "qabstractseries_p.h" |
|
34 | 34 | #include "declarativemargins.h" |
|
35 | 35 | #include "chartdataset_p.h" |
|
36 | 36 | #include "declarativeaxes.h" |
|
37 | 37 | #include "qchart_p.h" |
|
38 | 38 | |
|
39 | 39 | #ifndef QT_ON_ARM |
|
40 | 40 | #include "qdatetimeaxis.h" |
|
41 | 41 | #endif |
|
42 | 42 | |
|
43 | 43 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
44 | 44 | |
|
45 | 45 | /*! |
|
46 | 46 | \qmlclass ChartView DeclarativeChart |
|
47 | 47 | |
|
48 | 48 | ChartView element is the parent that is responsible for showing different chart series types. |
|
49 | 49 | |
|
50 | 50 | The following QML shows how to create a simple chart with one pie series: |
|
51 | 51 | \snippet ../examples/qmlpiechart/qml/qmlpiechart/main.qml 1 |
|
52 | 52 | \snippet ../examples/qmlpiechart/qml/qmlpiechart/main.qml 2 |
|
53 | 53 | \snippet ../examples/qmlpiechart/qml/qmlpiechart/main.qml 3 |
|
54 | 54 | |
|
55 | 55 | \beginfloatleft |
|
56 | 56 | \image examples_qmlpiechart.png |
|
57 | 57 | \endfloat |
|
58 | 58 | \clearfloat |
|
59 | 59 | */ |
|
60 | 60 | |
|
61 | 61 | /*! |
|
62 | 62 | \qmlproperty Theme ChartView::theme |
|
63 | 63 | Theme defines the visual appearance of the chart, including for example colors, fonts, line |
|
64 | 64 | widths and chart background. |
|
65 | 65 | */ |
|
66 | 66 | |
|
67 | 67 | /*! |
|
68 | 68 | \qmlproperty Animation ChartView::animationOptions |
|
69 | 69 | Animation configuration of the chart. One of ChartView.NoAnimation, ChartView.GridAxisAnimations, |
|
70 | 70 | ChartView.SeriesAnimations or ChartView.AllAnimations. |
|
71 | 71 | */ |
|
72 | 72 | |
|
73 | 73 | /*! |
|
74 | 74 | \qmlproperty Font ChartView::titleFont |
|
75 | 75 | The title font of the chart |
|
76 | 76 | |
|
77 | 77 | See the \l {Font} {QML Font Element} for detailed documentation. |
|
78 | 78 | */ |
|
79 | 79 | |
|
80 | 80 | /*! |
|
81 | 81 | \qmlproperty string ChartView::title |
|
82 | 82 | The title of the chart, shown on top of the chart. |
|
83 | 83 | \sa ChartView::titleColor |
|
84 | 84 | */ |
|
85 | 85 | |
|
86 | 86 | /*! |
|
87 | 87 | \qmlproperty color ChartView::titleColor |
|
88 | 88 | The color of the title text. |
|
89 | 89 | */ |
|
90 | 90 | |
|
91 | 91 | /*! |
|
92 | 92 | \qmlproperty Legend ChartView::legend |
|
93 | 93 | The legend of the chart. Legend lists all the series, pie slices and bar sets added on the chart. |
|
94 | 94 | */ |
|
95 | 95 | |
|
96 | 96 | /*! |
|
97 | 97 | \qmlproperty int ChartView::count |
|
98 | 98 | The count of series added to the chart. |
|
99 | 99 | */ |
|
100 | 100 | |
|
101 | 101 | /*! |
|
102 | 102 | \qmlproperty color ChartView::backgroundColor |
|
103 | 103 | The color of the chart's background. By default background color is defined by chart theme. |
|
104 | 104 | \sa ChartView::theme |
|
105 | 105 | */ |
|
106 | 106 | |
|
107 | 107 | /*! |
|
108 | 108 | \qmlproperty bool ChartView::dropShadowEnabled |
|
109 | 109 | The chart's border drop shadow. Set to true to enable drop shadow. |
|
110 | 110 | */ |
|
111 | 111 | |
|
112 | 112 | /*! |
|
113 | 113 | \qmlproperty real ChartView::topMargin |
|
114 | 114 | Deprecated. Use minimumMargins and plotArea instead. |
|
115 | 115 | */ |
|
116 | 116 | |
|
117 | 117 | /*! |
|
118 | 118 | \qmlproperty real ChartView::bottomMargin |
|
119 | 119 | Deprecated. Use minimumMargins and plotArea instead. |
|
120 | 120 | */ |
|
121 | 121 | |
|
122 | 122 | /*! |
|
123 | 123 | \qmlproperty real ChartView::leftMargin |
|
124 | 124 | Deprecated. Use minimumMargins and plotArea instead. |
|
125 | 125 | */ |
|
126 | 126 | |
|
127 | 127 | /*! |
|
128 | 128 | \qmlproperty real ChartView::rightMargin |
|
129 | 129 | Deprecated. Use minimumMargins and plotArea instead. |
|
130 | 130 | */ |
|
131 | 131 | |
|
132 | 132 | /*! |
|
133 | 133 | \qmlproperty Margins ChartView::minimumMargins |
|
134 | 134 | The minimum margins allowed between the outer bounds and the plotArea of the ChartView. Margins |
|
135 | 135 | area of ChartView is used for drawing title, axes and legend. Please note that setting the |
|
136 | 136 | properties of minimumMargins may be bigger than the defined value, depending on other ChartView |
|
137 | 137 | properties that affect it's layout. If you need to know the actual plotting area used at any |
|
138 | 138 | given time, you can check ChartView::plotArea instead. |
|
139 | 139 | */ |
|
140 | 140 | |
|
141 | 141 | /*! |
|
142 | 142 | \qmlproperty rect ChartView::plotArea |
|
143 | 143 | The area on the ChartView that is used for drawing series. This is the ChartView rect without the |
|
144 | 144 | margins. |
|
145 | 145 | \sa ChartView::minimumMargins |
|
146 | 146 | */ |
|
147 | 147 | |
|
148 | 148 | /*! |
|
149 | 149 | \qmlmethod AbstractSeries ChartView::series(int index) |
|
150 | 150 | Returns the series with \a index on the chart. This allows you to loop through the series of a chart together with |
|
151 | 151 | the count property of the chart. |
|
152 | 152 | */ |
|
153 | 153 | |
|
154 | 154 | /*! |
|
155 | 155 | \qmlmethod AbstractSeries ChartView::series(string name) |
|
156 | 156 | Returns the first series on the chart with \a name. If there is no series with that name, returns null. |
|
157 | 157 | */ |
|
158 | 158 | |
|
159 | 159 | /*! |
|
160 | 160 | \qmlmethod AbstractSeries ChartView::createSeries(SeriesType type, string name, AbstractAxis axisX, AbstractAxis axisY) |
|
161 | 161 | Creates a series object of \a type to the chart with name \a name, optional axis \a axisX and |
|
162 | 162 | optional axis \a axisY. For example: |
|
163 | 163 | \code |
|
164 | 164 | // lineSeries is a LineSeries object that has already been added to the ChartView; re-use it's axes |
|
165 | 165 | var myAxisX = chartView.axisX(lineSeries); |
|
166 | 166 | var myAxisY = chartView.axisY(lineSeries); |
|
167 | 167 | var scatter = chartView.createSeries(ChartView.SeriesTypeScatter, "scatter series", myAxisX, myAxisY); |
|
168 | 168 | \endcode |
|
169 | 169 | */ |
|
170 | 170 | |
|
171 | 171 | /*! |
|
172 | 172 | \qmlmethod ChartView::removeSeries(AbstractSeries series) |
|
173 | 173 | Removes the \a series from the chart. The series object is also destroyed. |
|
174 | 174 | */ |
|
175 | 175 | |
|
176 | 176 | /*! |
|
177 | 177 | \qmlmethod ChartView::removeAllSeries() |
|
178 | 178 | Removes all series from the chart. All the series objects are also destroyed. |
|
179 | 179 | */ |
|
180 | 180 | |
|
181 | 181 | /*! |
|
182 | 182 | \qmlmethod Axis ChartView::axisX(AbstractSeries series) |
|
183 | 183 | The x-axis of the series. |
|
184 | 184 | */ |
|
185 | 185 | |
|
186 | 186 | /*! |
|
187 | 187 | \qmlmethod Axis ChartView::axisY(AbstractSeries series) |
|
188 | 188 | The y-axis of the series. |
|
189 | 189 | */ |
|
190 | 190 | |
|
191 | 191 | /*! |
|
192 | 192 | \qmlmethod ChartView::zoomY(real factor) |
|
193 | 193 | Zooms in by \a factor on the center of the chart. |
|
194 | 194 | */ |
|
195 | 195 | |
|
196 | 196 | /*! |
|
197 | 197 | \qmlmethod ChartView::scrollLeft(real pixels) |
|
198 | 198 | Scrolls to left by \a pixels. This is a convenience function that suits for example for key navigation. |
|
199 | 199 | \sa ValueAxis::min, ValueAxis::max, BarCategoryAxis::min, BarCategoryAxis::max |
|
200 | 200 | */ |
|
201 | 201 | |
|
202 | 202 | /*! |
|
203 | 203 | \qmlmethod ChartView::scrollRight(real pixels) |
|
204 | 204 | Scrolls to right by \a pixels. This is a convenience function that suits for example for key navigation. |
|
205 | 205 | \sa ValueAxis::min, ValueAxis::max, BarCategoryAxis::min, BarCategoryAxis::max |
|
206 | 206 | */ |
|
207 | 207 | |
|
208 | 208 | /*! |
|
209 | 209 | \qmlmethod ChartView::scrollUp(real pixels) |
|
210 | 210 | Scrolls up by \a pixels. This is a convenience function that suits for example for key navigation. |
|
211 | 211 | \sa ValueAxis::min, ValueAxis::max, BarCategoryAxis::min, BarCategoryAxis::max |
|
212 | 212 | */ |
|
213 | 213 | |
|
214 | 214 | /*! |
|
215 | 215 | \qmlmethod ChartView::scrollDown(real pixels) |
|
216 | 216 | Scrolls down by \a pixels. This is a convenience function that suits for example for key navigation. |
|
217 | 217 | \sa ValueAxis::min, ValueAxis::max, BarCategoryAxis::min, BarCategoryAxis::max |
|
218 | 218 | */ |
|
219 | 219 | |
|
220 | 220 | /*! |
|
221 | 221 | \qmlsignal ChartView::onPlotAreaChanged(rect plotArea) |
|
222 | 222 | The plot area of the chart has changed. This may happen for example, if you modify minimumMargins |
|
223 | 223 | or if you resize the chart, or if you modify font size related properties of the legend or chart |
|
224 | 224 | title. |
|
225 | 225 | */ |
|
226 | 226 | |
|
227 | 227 | /*! |
|
228 | 228 | \qmlsignal ChartView::seriesAdded(AbstractSeries series) |
|
229 | 229 | The \a series has been added to the chart. |
|
230 | 230 | */ |
|
231 | 231 | |
|
232 | 232 | /*! |
|
233 | 233 | \qmlsignal ChartView::seriesRemoved(AbstractSeries series) |
|
234 | 234 | The \a series has been removed from the chart. Please note that \a series is no longer a valid |
|
235 | 235 | object after the signal handler has completed. |
|
236 | 236 | */ |
|
237 | 237 | |
|
238 | 238 | DeclarativeChart::DeclarativeChart(QDeclarativeItem *parent) |
|
239 | 239 | : QDeclarativeItem(parent), |
|
240 | 240 | m_chart(new QChart(this)) |
|
241 | 241 | { |
|
242 | 242 | setFlag(QGraphicsItem::ItemHasNoContents, false); |
|
243 | 243 | m_margins = new DeclarativeMargins(this); |
|
244 | 244 | m_margins->setTop(m_chart->margins().top()); |
|
245 | 245 | m_margins->setLeft(m_chart->margins().left()); |
|
246 | 246 | m_margins->setRight(m_chart->margins().right()); |
|
247 | 247 | m_margins->setBottom(m_chart->margins().bottom()); |
|
248 | 248 | connect(m_margins, SIGNAL(topChanged(int,int,int,int)), this, SLOT(changeMinimumMargins(int,int,int,int))); |
|
249 | 249 | connect(m_margins, SIGNAL(bottomChanged(int,int,int,int)), this, SLOT(changeMinimumMargins(int,int,int,int))); |
|
250 | 250 | connect(m_margins, SIGNAL(leftChanged(int,int,int,int)), this, SLOT(changeMinimumMargins(int,int,int,int))); |
|
251 | 251 | connect(m_margins, SIGNAL(rightChanged(int,int,int,int)), this, SLOT(changeMinimumMargins(int,int,int,int))); |
|
252 | 252 | connect(m_chart->d_ptr->m_dataset, SIGNAL(seriesAdded(QAbstractSeries*)), this, SLOT(handleSeriesAdded(QAbstractSeries*))); |
|
253 | 253 | connect(m_chart->d_ptr->m_dataset, SIGNAL(seriesRemoved(QAbstractSeries*)), this, SIGNAL(seriesRemoved(QAbstractSeries*))); |
|
254 | 254 | } |
|
255 | 255 | |
|
256 | 256 | void DeclarativeChart::handleSeriesAdded(QAbstractSeries *series) |
|
257 | 257 | { |
|
258 | 258 | emit seriesAdded(series); |
|
259 | 259 | } |
|
260 | 260 | |
|
261 | 261 | void DeclarativeChart::changeMinimumMargins(int top, int bottom, int left, int right) |
|
262 | 262 | { |
|
263 | 263 | m_chart->setMargins(QMargins(left, top, right, bottom)); |
|
264 | 264 | emit minimumMarginsChanged(); |
|
265 | 265 | emit plotAreaChanged(m_chart->plotArea()); |
|
266 | 266 | } |
|
267 | 267 | |
|
268 | 268 | DeclarativeChart::~DeclarativeChart() |
|
269 | 269 | { |
|
270 | 270 | delete m_chart; |
|
271 | 271 | } |
|
272 | 272 | |
|
273 | 273 | void DeclarativeChart::childEvent(QChildEvent *event) |
|
274 | 274 | { |
|
275 | 275 | if (event->type() == QEvent::ChildAdded) { |
|
276 | 276 | if (qobject_cast<QAbstractSeries *>(event->child())) { |
|
277 | 277 | m_chart->addSeries(qobject_cast<QAbstractSeries *>(event->child())); |
|
278 | 278 | } |
|
279 | 279 | } |
|
280 | 280 | } |
|
281 | 281 | |
|
282 | 282 | void DeclarativeChart::componentComplete() |
|
283 | 283 | { |
|
284 | 284 | foreach (QObject *child, children()) { |
|
285 | 285 | if (qobject_cast<QAbstractSeries *>(child)) { |
|
286 | 286 | // Add series to the chart |
|
287 | 287 | QAbstractSeries *series = qobject_cast<QAbstractSeries *>(child); |
|
288 | 288 | m_chart->addSeries(series); |
|
289 | 289 | |
|
290 | 290 | // Connect to axis changed signals (unless this is a pie series) |
|
291 | 291 | if (!qobject_cast<DeclarativePieSeries *>(series)) { |
|
292 | 292 | connect(series, SIGNAL(axisXChanged(QAbstractAxis*)), this, SLOT(handleAxisXSet(QAbstractAxis*))); |
|
293 | 293 | connect(series, SIGNAL(axisXTopChanged(QAbstractAxis*)), this, SLOT(handleAxisXSet(QAbstractAxis*))); |
|
294 | 294 | connect(series, SIGNAL(axisYChanged(QAbstractAxis*)), this, SLOT(handleAxisYSet(QAbstractAxis*))); |
|
295 | 295 | connect(series, SIGNAL(axisYRightChanged(QAbstractAxis*)), this, SLOT(handleAxisYRightSet(QAbstractAxis*))); |
|
296 | 296 | } |
|
297 | 297 | |
|
298 | 298 | initializeAxes(series); |
|
299 | 299 | } |
|
300 | 300 | } |
|
301 | 301 | |
|
302 | 302 | QDeclarativeItem::componentComplete(); |
|
303 | 303 | } |
|
304 | 304 | |
|
305 | 305 | void DeclarativeChart::handleAxisXSet(QAbstractAxis *axis) |
|
306 | 306 | { |
|
307 | 307 | QAbstractSeries *s = qobject_cast<QAbstractSeries *>(sender()); |
|
308 | 308 | if (axis && s) { |
|
309 | 309 | if (!m_chart->axes(Qt::Horizontal).contains(axis)) |
|
310 | 310 | m_chart->addAxis(axis, Qt::AlignBottom); |
|
311 | 311 | if (!s->attachedAxes().contains(axis)) |
|
312 | 312 | s->attachAxis(axis); |
|
313 | 313 | } else { |
|
314 | 314 | qWarning() << "Trying to set axisX to null."; |
|
315 | 315 | } |
|
316 | 316 | } |
|
317 | 317 | |
|
318 | 318 | void DeclarativeChart::handleAxisXTopSet(QAbstractAxis *axis) |
|
319 | 319 | { |
|
320 | 320 | QAbstractSeries *s = qobject_cast<QAbstractSeries *>(sender()); |
|
321 | 321 | if (axis && s) { |
|
322 | 322 | if (!m_chart->axes(Qt::Horizontal).contains(axis)) |
|
323 | 323 | m_chart->addAxis(axis, Qt::AlignTop); |
|
324 | 324 | if (!s->attachedAxes().contains(axis)) |
|
325 | 325 | s->attachAxis(axis); |
|
326 | 326 | } else { |
|
327 | 327 | qWarning() << "Trying to set axisXTop to null."; |
|
328 | 328 | } |
|
329 | 329 | } |
|
330 | 330 | |
|
331 | 331 | void DeclarativeChart::handleAxisYSet(QAbstractAxis *axis) |
|
332 | 332 | { |
|
333 | 333 | QAbstractSeries *s = qobject_cast<QAbstractSeries *>(sender()); |
|
334 | 334 | if (axis && s) { |
|
335 | 335 | if (!m_chart->axes(Qt::Vertical).contains(axis)) |
|
336 | 336 | m_chart->addAxis(axis, Qt::AlignLeft); |
|
337 | 337 | if (!s->attachedAxes().contains(axis)) |
|
338 | 338 | s->attachAxis(axis); |
|
339 | 339 | } else { |
|
340 | 340 | qWarning() << "Trying to set axisY to null."; |
|
341 | 341 | } |
|
342 | 342 | } |
|
343 | 343 | |
|
344 | 344 | void DeclarativeChart::handleAxisYRightSet(QAbstractAxis *axis) |
|
345 | 345 | { |
|
346 | 346 | QAbstractSeries *s = qobject_cast<QAbstractSeries *>(sender()); |
|
347 | 347 | if (axis && s) { |
|
348 | 348 | if (!m_chart->axes(Qt::Vertical).contains(axis)) |
|
349 | 349 | m_chart->addAxis(axis, Qt::AlignRight); |
|
350 | 350 | if (!s->attachedAxes().contains(axis)) |
|
351 | 351 | s->attachAxis(axis); |
|
352 | 352 | } else { |
|
353 | 353 | qWarning() << "Trying to set axisYRight to null."; |
|
354 | 354 | } |
|
355 | 355 | } |
|
356 | 356 | |
|
357 | 357 | void DeclarativeChart::geometryChanged(const QRectF &newGeometry, const QRectF &oldGeometry) |
|
358 | 358 | { |
|
359 | 359 | // qDebug() << "DeclarativeChart::geometryChanged" << newGeometry.width() << newGeometry.height(); |
|
360 | 360 | if (newGeometry.isValid()) { |
|
361 | 361 | if (newGeometry.width() > 0 && newGeometry.height() > 0) { |
|
362 | 362 | m_chart->resize(newGeometry.width(), newGeometry.height()); |
|
363 | 363 | } |
|
364 | 364 | } |
|
365 | 365 | QDeclarativeItem::geometryChanged(newGeometry, oldGeometry); |
|
366 | 366 | |
|
367 | 367 | // It would be better to trigger the plotAreaChanged signal from QChart::plotAreaChanged or |
|
368 | 368 | // similar. Since that kind of a signal is not clearly needed in the C++ API the work-around is |
|
369 | 369 | // to implement it here for the QML API purposes. |
|
370 | 370 | emit plotAreaChanged(m_chart->plotArea()); |
|
371 | 371 | } |
|
372 | 372 | |
|
373 | 373 | void DeclarativeChart::setTheme(DeclarativeChart::Theme theme) |
|
374 | 374 | { |
|
375 | 375 | QChart::ChartTheme chartTheme = (QChart::ChartTheme) theme; |
|
376 | 376 | if (chartTheme != m_chart->theme()) |
|
377 | 377 | m_chart->setTheme(chartTheme); |
|
378 | 378 | } |
|
379 | 379 | |
|
380 | 380 | DeclarativeChart::Theme DeclarativeChart::theme() |
|
381 | 381 | { |
|
382 | 382 | return (DeclarativeChart::Theme) m_chart->theme(); |
|
383 | 383 | } |
|
384 | 384 | |
|
385 | 385 | void DeclarativeChart::setAnimationOptions(DeclarativeChart::Animation animations) |
|
386 | 386 | { |
|
387 | 387 | QChart::AnimationOption animationOptions = (QChart::AnimationOption) animations; |
|
388 | 388 | if (animationOptions != m_chart->animationOptions()) |
|
389 | 389 | m_chart->setAnimationOptions(animationOptions); |
|
390 | 390 | } |
|
391 | 391 | |
|
392 | 392 | DeclarativeChart::Animation DeclarativeChart::animationOptions() |
|
393 | 393 | { |
|
394 | 394 | if (m_chart->animationOptions().testFlag(QChart::AllAnimations)) |
|
395 | 395 | return DeclarativeChart::AllAnimations; |
|
396 | 396 | else if (m_chart->animationOptions().testFlag(QChart::GridAxisAnimations)) |
|
397 | 397 | return DeclarativeChart::GridAxisAnimations; |
|
398 | 398 | else if (m_chart->animationOptions().testFlag(QChart::SeriesAnimations)) |
|
399 | 399 | return DeclarativeChart::SeriesAnimations; |
|
400 | 400 | else |
|
401 | 401 | return DeclarativeChart::NoAnimation; |
|
402 | 402 | } |
|
403 | 403 | |
|
404 | 404 | void DeclarativeChart::setTitle(QString title) |
|
405 | 405 | { |
|
406 | 406 | if (title != m_chart->title()) |
|
407 | 407 | m_chart->setTitle(title); |
|
408 | 408 | } |
|
409 | 409 | QString DeclarativeChart::title() |
|
410 | 410 | { |
|
411 | 411 | return m_chart->title(); |
|
412 | 412 | } |
|
413 | 413 | |
|
414 | 414 | QAbstractAxis *DeclarativeChart::axisX(QAbstractSeries *series) |
|
415 | 415 | { |
|
416 | 416 | QList<QAbstractAxis *> axes = m_chart->axes(Qt::Horizontal, series); |
|
417 | 417 | if (axes.count()) |
|
418 | 418 | return axes[0]; |
|
419 | 419 | return 0; |
|
420 | 420 | } |
|
421 | 421 | |
|
422 | 422 | QAbstractAxis *DeclarativeChart::axisY(QAbstractSeries *series) |
|
423 | 423 | { |
|
424 | 424 | QList<QAbstractAxis *> axes = m_chart->axes(Qt::Vertical, series); |
|
425 | 425 | if (axes.count()) |
|
426 | 426 | return axes[0]; |
|
427 | 427 | return 0; |
|
428 | 428 | } |
|
429 | 429 | |
|
430 | 430 | QLegend *DeclarativeChart::legend() |
|
431 | 431 | { |
|
432 | 432 | return m_chart->legend(); |
|
433 | 433 | } |
|
434 | 434 | |
|
435 | 435 | void DeclarativeChart::setTitleColor(QColor color) |
|
436 | 436 | { |
|
437 | 437 | QBrush b = m_chart->titleBrush(); |
|
438 | 438 | if (color != b.color()) { |
|
439 | 439 | b.setColor(color); |
|
440 | 440 | m_chart->setTitleBrush(b); |
|
441 | 441 | emit titleColorChanged(color); |
|
442 | 442 | } |
|
443 | 443 | } |
|
444 | 444 | |
|
445 | 445 | QFont DeclarativeChart::titleFont() const |
|
446 | 446 | { |
|
447 | 447 | return m_chart->titleFont(); |
|
448 | 448 | } |
|
449 | 449 | |
|
450 | 450 | void DeclarativeChart::setTitleFont(const QFont &font) |
|
451 | 451 | { |
|
452 | 452 | m_chart->setTitleFont(font); |
|
453 | 453 | } |
|
454 | 454 | |
|
455 | 455 | QColor DeclarativeChart::titleColor() |
|
456 | 456 | { |
|
457 | 457 | return m_chart->titleBrush().color(); |
|
458 | 458 | } |
|
459 | 459 | |
|
460 | 460 | void DeclarativeChart::setBackgroundColor(QColor color) |
|
461 | 461 | { |
|
462 | 462 | QBrush b = m_chart->backgroundBrush(); |
|
463 | 463 | if (b.style() != Qt::SolidPattern || color != b.color()) { |
|
464 | 464 | b.setStyle(Qt::SolidPattern); |
|
465 | 465 | b.setColor(color); |
|
466 | 466 | m_chart->setBackgroundBrush(b); |
|
467 | 467 | emit backgroundColorChanged(); |
|
468 | 468 | } |
|
469 | 469 | } |
|
470 | 470 | |
|
471 | 471 | QColor DeclarativeChart::backgroundColor() |
|
472 | 472 | { |
|
473 | 473 | return m_chart->backgroundBrush().color(); |
|
474 | 474 | } |
|
475 | 475 | |
|
476 | 476 | int DeclarativeChart::count() |
|
477 | 477 | { |
|
478 | 478 | return m_chart->series().count(); |
|
479 | 479 | } |
|
480 | 480 | |
|
481 | 481 | void DeclarativeChart::setDropShadowEnabled(bool enabled) |
|
482 | 482 | { |
|
483 | 483 | if (enabled != m_chart->isDropShadowEnabled()) { |
|
484 | 484 | m_chart->setDropShadowEnabled(enabled); |
|
485 | 485 | dropShadowEnabledChanged(enabled); |
|
486 | 486 | } |
|
487 | 487 | } |
|
488 | 488 | |
|
489 | 489 | bool DeclarativeChart::dropShadowEnabled() |
|
490 | 490 | { |
|
491 | 491 | return m_chart->isDropShadowEnabled(); |
|
492 | 492 | } |
|
493 | 493 | |
|
494 | 494 | qreal DeclarativeChart::topMargin() |
|
495 | 495 | { |
|
496 | 496 | qWarning() << "ChartView.topMargin is deprecated. Use minimumMargins and plotArea instead."; |
|
497 | 497 | return m_chart->plotArea().top(); |
|
498 | 498 | } |
|
499 | 499 | |
|
500 | 500 | qreal DeclarativeChart::bottomMargin() |
|
501 | 501 | { |
|
502 | 502 | |
|
503 | 503 | qWarning() << "ChartView.bottomMargin is deprecated. Use minimumMargins and plotArea instead."; |
|
504 | 504 | return m_chart->plotArea().bottom(); |
|
505 | 505 | } |
|
506 | 506 | |
|
507 | 507 | qreal DeclarativeChart::leftMargin() |
|
508 | 508 | { |
|
509 | 509 | qWarning() << "ChartView.leftMargin is deprecated. Use minimumMargins and plotArea instead."; |
|
510 | 510 | return m_chart->plotArea().left(); |
|
511 | 511 | } |
|
512 | 512 | |
|
513 | 513 | qreal DeclarativeChart::rightMargin() |
|
514 | 514 | { |
|
515 | 515 | qWarning() << "ChartView.rightMargin is deprecated. Use minimumMargins and plotArea instead."; |
|
516 | 516 | return m_chart->plotArea().right(); |
|
517 | 517 | } |
|
518 | 518 | |
|
519 | 519 | void DeclarativeChart::zoom(qreal factor) |
|
520 | 520 | { |
|
521 | 521 | m_chart->zoom(factor); |
|
522 | 522 | } |
|
523 | 523 | |
|
524 | 524 | void DeclarativeChart::scrollLeft(qreal pixels) |
|
525 | 525 | { |
|
526 | 526 | m_chart->scroll(-pixels, 0); |
|
527 | 527 | } |
|
528 | 528 | |
|
529 | 529 | void DeclarativeChart::scrollRight(qreal pixels) |
|
530 | 530 | { |
|
531 | 531 | m_chart->scroll(pixels, 0); |
|
532 | 532 | } |
|
533 | 533 | |
|
534 | 534 | void DeclarativeChart::scrollUp(qreal pixels) |
|
535 | 535 | { |
|
536 | 536 | m_chart->scroll(0, pixels); |
|
537 | 537 | } |
|
538 | 538 | |
|
539 | 539 | void DeclarativeChart::scrollDown(qreal pixels) |
|
540 | 540 | { |
|
541 | 541 | m_chart->scroll(0, -pixels); |
|
542 | 542 | } |
|
543 | 543 | |
|
544 | 544 | QDeclarativeListProperty<QAbstractAxis> DeclarativeChart::axes() |
|
545 | 545 | { |
|
546 | 546 | return QDeclarativeListProperty<QAbstractAxis>(this, 0, |
|
547 | 547 | &DeclarativeChart::axesAppendFunc, |
|
548 | 548 | &DeclarativeChart::axesCountFunc, |
|
549 | 549 | &DeclarativeChart::axesAtFunc); |
|
550 | 550 | } |
|
551 | 551 | |
|
552 | 552 | void DeclarativeChart::axesAppendFunc(QDeclarativeListProperty<QAbstractAxis> *list, QAbstractAxis *element) |
|
553 | 553 | { |
|
554 | 554 | // Empty implementation |
|
555 | 555 | Q_UNUSED(list); |
|
556 | 556 | Q_UNUSED(element); |
|
557 | 557 | } |
|
558 | 558 | |
|
559 | 559 | int DeclarativeChart::axesCountFunc(QDeclarativeListProperty<QAbstractAxis> *list) |
|
560 | 560 | { |
|
561 | 561 | if (qobject_cast<DeclarativeChart *>(list->object)) { |
|
562 | 562 | DeclarativeChart *chart = qobject_cast<DeclarativeChart *>(list->object); |
|
563 |
return chart->m_chart->axes(Qt::Horizontal | Qt::Vertical |
|
|
563 | return chart->m_chart->axes(Qt::Horizontal | Qt::Vertical).count(); | |
|
564 | 564 | } |
|
565 | 565 | return 0; |
|
566 | 566 | } |
|
567 | 567 | |
|
568 | 568 | QAbstractAxis *DeclarativeChart::axesAtFunc(QDeclarativeListProperty<QAbstractAxis> *list, int index) |
|
569 | 569 | { |
|
570 | 570 | if (qobject_cast<DeclarativeChart *>(list->object)) { |
|
571 | 571 | DeclarativeChart *chart = qobject_cast<DeclarativeChart *>(list->object); |
|
572 | 572 | QList<QAbstractAxis *> axes = chart->m_chart->axes(Qt::Horizontal | Qt::Vertical, chart->m_chart->series()[0]); |
|
573 | 573 | return axes.at(index); |
|
574 | 574 | } |
|
575 | 575 | return 0; |
|
576 | 576 | } |
|
577 | 577 | |
|
578 | 578 | QAbstractSeries *DeclarativeChart::series(int index) |
|
579 | 579 | { |
|
580 | 580 | if (index < m_chart->series().count()) { |
|
581 | 581 | return m_chart->series().at(index); |
|
582 | 582 | } |
|
583 | 583 | return 0; |
|
584 | 584 | } |
|
585 | 585 | |
|
586 | 586 | QAbstractSeries *DeclarativeChart::series(QString seriesName) |
|
587 | 587 | { |
|
588 | 588 | foreach (QAbstractSeries *series, m_chart->series()) { |
|
589 | 589 | if (series->name() == seriesName) |
|
590 | 590 | return series; |
|
591 | 591 | } |
|
592 | 592 | return 0; |
|
593 | 593 | } |
|
594 | 594 | |
|
595 | 595 | QAbstractSeries *DeclarativeChart::createSeries(DeclarativeChart::SeriesType type, QString name) |
|
596 | 596 | { |
|
597 | 597 | return createSeries(type, name, 0, 0); |
|
598 | 598 | } |
|
599 | 599 | |
|
600 | 600 | QAbstractSeries *DeclarativeChart::createSeries(DeclarativeChart::SeriesType type, QString name, QAbstractAxis *axisX, QAbstractAxis *axisY) |
|
601 | 601 | { |
|
602 | 602 | QAbstractSeries *series = 0; |
|
603 | 603 | |
|
604 | 604 | switch (type) { |
|
605 | 605 | case DeclarativeChart::SeriesTypeLine: |
|
606 | 606 | series = new DeclarativeLineSeries(); |
|
607 | 607 | break; |
|
608 | 608 | case DeclarativeChart::SeriesTypeArea: { |
|
609 | 609 | DeclarativeAreaSeries *area = new DeclarativeAreaSeries(); |
|
610 | 610 | area->setUpperSeries(new DeclarativeLineSeries()); |
|
611 | 611 | series = area; |
|
612 | 612 | break; |
|
613 | 613 | } |
|
614 | 614 | case DeclarativeChart::SeriesTypeStackedBar: |
|
615 | 615 | series = new DeclarativeStackedBarSeries(); |
|
616 | 616 | break; |
|
617 | 617 | case DeclarativeChart::SeriesTypePercentBar: |
|
618 | 618 | series = new DeclarativePercentBarSeries(); |
|
619 | 619 | break; |
|
620 | 620 | case DeclarativeChart::SeriesTypeBar: |
|
621 | 621 | series = new DeclarativeBarSeries(); |
|
622 | 622 | break; |
|
623 | 623 | case DeclarativeChart::SeriesTypeHorizontalBar: |
|
624 | 624 | series = new DeclarativeHorizontalBarSeries(); |
|
625 | 625 | break; |
|
626 | 626 | case DeclarativeChart::SeriesTypeHorizontalPercentBar: |
|
627 | 627 | series = new DeclarativeHorizontalPercentBarSeries(); |
|
628 | 628 | break; |
|
629 | 629 | case DeclarativeChart::SeriesTypeHorizontalStackedBar: |
|
630 | 630 | series = new DeclarativeHorizontalStackedBarSeries(); |
|
631 | 631 | break; |
|
632 | 632 | case DeclarativeChart::SeriesTypePie: |
|
633 | 633 | series = new DeclarativePieSeries(); |
|
634 | 634 | break; |
|
635 | 635 | case DeclarativeChart::SeriesTypeScatter: |
|
636 | 636 | series = new DeclarativeScatterSeries(); |
|
637 | 637 | break; |
|
638 | 638 | case DeclarativeChart::SeriesTypeSpline: |
|
639 | 639 | series = new DeclarativeSplineSeries(); |
|
640 | 640 | break; |
|
641 | 641 | default: |
|
642 | 642 | qWarning() << "Illegal series type"; |
|
643 | 643 | } |
|
644 | 644 | |
|
645 | 645 | if (series) { |
|
646 | 646 | // Connect to axis changed signals (unless this is a pie series) |
|
647 | 647 | if (!qobject_cast<DeclarativePieSeries *>(series)) { |
|
648 | 648 | connect(series, SIGNAL(axisXChanged(QAbstractAxis*)), this, SLOT(handleAxisXSet(QAbstractAxis*))); |
|
649 | 649 | connect(series, SIGNAL(axisXTopChanged(QAbstractAxis*)), this, SLOT(handleAxisXSet(QAbstractAxis*))); |
|
650 | 650 | connect(series, SIGNAL(axisYChanged(QAbstractAxis*)), this, SLOT(handleAxisYSet(QAbstractAxis*))); |
|
651 | 651 | connect(series, SIGNAL(axisYRightChanged(QAbstractAxis*)), this, SLOT(handleAxisYRightSet(QAbstractAxis*))); |
|
652 | 652 | } |
|
653 | 653 | |
|
654 | 654 | series->setName(name); |
|
655 | 655 | m_chart->addSeries(series); |
|
656 | 656 | |
|
657 | 657 | if (axisX) |
|
658 | 658 | setAxisX(axisX, series); |
|
659 | 659 | if (axisY) |
|
660 | 660 | setAxisY(axisY, series); |
|
661 | 661 | |
|
662 | 662 | if (series->attachedAxes().count() < 2) |
|
663 | 663 | initializeAxes(series); |
|
664 | 664 | } |
|
665 | 665 | |
|
666 | 666 | return series; |
|
667 | 667 | } |
|
668 | 668 | |
|
669 | 669 | void DeclarativeChart::removeSeries(QAbstractSeries *series) |
|
670 | 670 | { |
|
671 | 671 | if (series) |
|
672 | 672 | m_chart->removeSeries(series); |
|
673 | 673 | else |
|
674 | 674 | qWarning("removeSeries: cannot remove null"); |
|
675 | 675 | } |
|
676 | 676 | |
|
677 | 677 | void DeclarativeChart::setAxisX(QAbstractAxis *axis, QAbstractSeries *series) |
|
678 | 678 | { |
|
679 | 679 | if (axis) |
|
680 | 680 | m_chart->setAxisX(axis, series); |
|
681 | 681 | } |
|
682 | 682 | |
|
683 | 683 | void DeclarativeChart::setAxisY(QAbstractAxis *axis, QAbstractSeries *series) |
|
684 | 684 | { |
|
685 | 685 | if (axis) |
|
686 | 686 | m_chart->setAxisY(axis, series); |
|
687 | 687 | } |
|
688 | 688 | |
|
689 | 689 | void DeclarativeChart::createDefaultAxes() |
|
690 | 690 | { |
|
691 | 691 | qWarning() << "ChartView.createDefaultAxes() is deprecated. Axes are created automatically."; |
|
692 | 692 | } |
|
693 | 693 | |
|
694 | 694 | QAbstractAxis *DeclarativeChart::defaultAxis(Qt::Orientation orientation, QAbstractSeries *series) |
|
695 | 695 | { |
|
696 | 696 | if (!series) { |
|
697 | 697 | qWarning() << "No axis type defined for null series"; |
|
698 | 698 | return 0; |
|
699 | 699 | } |
|
700 | 700 | |
|
701 | 701 | foreach (QAbstractAxis *existingAxis, m_chart->axes(orientation)) { |
|
702 | 702 | if (existingAxis->type() == series->d_ptr->defaultAxisType(orientation)) |
|
703 | 703 | return existingAxis; |
|
704 | 704 | } |
|
705 | 705 | |
|
706 | 706 | switch (series->d_ptr->defaultAxisType(orientation)) { |
|
707 | 707 | case QAbstractAxis::AxisTypeValue: |
|
708 | 708 | return new QValueAxis(this); |
|
709 | 709 | case QAbstractAxis::AxisTypeBarCategory: |
|
710 | 710 | return new QBarCategoryAxis(this); |
|
711 | 711 | case QAbstractAxis::AxisTypeCategory: |
|
712 | 712 | return new QCategoryAxis(this); |
|
713 | 713 | #ifndef QT_ON_ARM |
|
714 | 714 | case QAbstractAxis::AxisTypeDateTime: |
|
715 | 715 | return new QDateTimeAxis(this); |
|
716 | 716 | #endif |
|
717 | 717 | default: |
|
718 | 718 | // assume AxisTypeNoAxis |
|
719 | 719 | return 0; |
|
720 | 720 | } |
|
721 | 721 | } |
|
722 | 722 | |
|
723 | 723 | void DeclarativeChart::initializeAxes(QAbstractSeries *series) |
|
724 | 724 | { |
|
725 | 725 | if (qobject_cast<DeclarativeLineSeries *>(series)) |
|
726 | 726 | doInitializeAxes(series, qobject_cast<DeclarativeLineSeries *>(series)->m_axes); |
|
727 | 727 | else if (qobject_cast<DeclarativeScatterSeries *>(series)) |
|
728 | 728 | doInitializeAxes(series, qobject_cast<DeclarativeScatterSeries *>(series)->m_axes); |
|
729 | 729 | else if (qobject_cast<DeclarativeSplineSeries *>(series)) |
|
730 | 730 | doInitializeAxes(series, qobject_cast<DeclarativeSplineSeries *>(series)->m_axes); |
|
731 | 731 | else if (qobject_cast<DeclarativeAreaSeries *>(series)) |
|
732 | 732 | doInitializeAxes(series, qobject_cast<DeclarativeAreaSeries *>(series)->m_axes); |
|
733 | 733 | else if (qobject_cast<DeclarativeBarSeries *>(series)) |
|
734 | 734 | doInitializeAxes(series, qobject_cast<DeclarativeBarSeries *>(series)->m_axes); |
|
735 | 735 | else if (qobject_cast<DeclarativeStackedBarSeries *>(series)) |
|
736 | 736 | doInitializeAxes(series, qobject_cast<DeclarativeStackedBarSeries *>(series)->m_axes); |
|
737 | 737 | else if (qobject_cast<DeclarativePercentBarSeries *>(series)) |
|
738 | 738 | doInitializeAxes(series, qobject_cast<DeclarativePercentBarSeries *>(series)->m_axes); |
|
739 | 739 | else if (qobject_cast<DeclarativeHorizontalBarSeries *>(series)) |
|
740 | 740 | doInitializeAxes(series, qobject_cast<DeclarativeHorizontalBarSeries *>(series)->m_axes); |
|
741 | 741 | else if (qobject_cast<DeclarativeHorizontalStackedBarSeries *>(series)) |
|
742 | 742 | doInitializeAxes(series, qobject_cast<DeclarativeHorizontalStackedBarSeries *>(series)->m_axes); |
|
743 | 743 | else if (qobject_cast<DeclarativeHorizontalPercentBarSeries *>(series)) |
|
744 | 744 | doInitializeAxes(series, qobject_cast<DeclarativeHorizontalPercentBarSeries *>(series)->m_axes); |
|
745 | 745 | // else: do nothing |
|
746 | 746 | } |
|
747 | 747 | |
|
748 | 748 | void DeclarativeChart::doInitializeAxes(QAbstractSeries *series, DeclarativeAxes *axes) |
|
749 | 749 | { |
|
750 | 750 | // Initialize axis X |
|
751 | 751 | if (axes->axisX()) |
|
752 | 752 | axes->emitAxisXChanged(); |
|
753 | 753 | else if (axes->axisXTop()) |
|
754 | 754 | axes->emitAxisXTopChanged(); |
|
755 | 755 | else |
|
756 | 756 | axes->setAxisX(defaultAxis(Qt::Horizontal, series)); |
|
757 | 757 | |
|
758 | 758 | // Initialize axis Y |
|
759 | 759 | if (axes->axisY()) |
|
760 | 760 | axes->emitAxisYChanged(); |
|
761 | 761 | else if (axes->axisYRight()) |
|
762 | 762 | axes->emitAxisYRightChanged(); |
|
763 | 763 | else |
|
764 | 764 | axes->setAxisY(defaultAxis(Qt::Vertical, series)); |
|
765 | 765 | } |
|
766 | 766 | |
|
767 | 767 | #include "moc_declarativechart.cpp" |
|
768 | 768 | |
|
769 | 769 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,184 +1,184 | |||
|
1 | 1 | /**************************************************************************** |
|
2 | 2 | ** |
|
3 | 3 | ** Copyright (C) 2012 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 Commercial Charts Add-on. |
|
8 | 8 | ** |
|
9 | 9 | ** $QT_BEGIN_LICENSE$ |
|
10 | 10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
11 | 11 | ** accordance with the Qt Commercial 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 <QtDeclarative/QDeclarativeItem> |
|
26 | 26 | |
|
27 | 27 | #include "qchart.h" |
|
28 | 28 | |
|
29 | 29 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
30 | 30 | |
|
31 | 31 | class DeclarativeMargins; |
|
32 | 32 | class Domain; |
|
33 | 33 | class DeclarativeAxes; |
|
34 | 34 | |
|
35 | 35 | class DeclarativeChart : public QDeclarativeItem |
|
36 | 36 | { |
|
37 | 37 | Q_OBJECT |
|
38 | 38 | Q_PROPERTY(Theme theme READ theme WRITE setTheme) |
|
39 | 39 | Q_PROPERTY(Animation animationOptions READ animationOptions WRITE setAnimationOptions) |
|
40 | 40 | Q_PROPERTY(QString title READ title WRITE setTitle) |
|
41 | 41 | Q_PROPERTY(QFont titleFont READ titleFont WRITE setTitleFont) |
|
42 | 42 | Q_PROPERTY(QColor titleColor READ titleColor WRITE setTitleColor NOTIFY titleColorChanged) |
|
43 | 43 | Q_PROPERTY(QLegend *legend READ legend) |
|
44 | 44 | Q_PROPERTY(int count READ count) |
|
45 | 45 | Q_PROPERTY(QColor backgroundColor READ backgroundColor WRITE setBackgroundColor NOTIFY backgroundColorChanged) |
|
46 | 46 | Q_PROPERTY(bool dropShadowEnabled READ dropShadowEnabled WRITE setDropShadowEnabled NOTIFY dropShadowEnabledChanged) |
|
47 | 47 | Q_PROPERTY(qreal topMargin READ topMargin) |
|
48 | 48 | Q_PROPERTY(qreal bottomMargin READ bottomMargin) |
|
49 | 49 | Q_PROPERTY(qreal leftMargin READ leftMargin) |
|
50 | 50 | Q_PROPERTY(qreal rightMargin READ rightMargin) |
|
51 | 51 | Q_PROPERTY(DeclarativeMargins *minimumMargins READ minimumMargins NOTIFY minimumMarginsChanged REVISION 1) |
|
52 | 52 | Q_PROPERTY(DeclarativeMargins *margins READ margins NOTIFY marginsChanged REVISION 2) |
|
53 | 53 | Q_PROPERTY(QRectF plotArea READ plotArea NOTIFY plotAreaChanged REVISION 1) |
|
54 | 54 | Q_PROPERTY(QDeclarativeListProperty<QAbstractAxis> axes READ axes REVISION 2) |
|
55 | 55 | Q_ENUMS(Animation) |
|
56 | 56 | Q_ENUMS(Theme) |
|
57 | 57 | Q_ENUMS(SeriesType) |
|
58 | 58 | |
|
59 | 59 | public: |
|
60 | 60 | // duplicating enums from QChart to make the QML api namings 1-to-1 with the C++ api |
|
61 | 61 | enum Theme { |
|
62 | 62 | ChartThemeLight = 0, |
|
63 | 63 | ChartThemeBlueCerulean, |
|
64 | 64 | ChartThemeDark, |
|
65 | 65 | ChartThemeBrownSand, |
|
66 | 66 | ChartThemeBlueNcs, |
|
67 | 67 | ChartThemeHighContrast, |
|
68 | 68 | ChartThemeBlueIcy |
|
69 | 69 | }; |
|
70 | 70 | |
|
71 | 71 | enum Animation { |
|
72 | 72 | NoAnimation = 0x0, |
|
73 | 73 | GridAxisAnimations = 0x1, |
|
74 | 74 | SeriesAnimations = 0x2, |
|
75 | 75 | AllAnimations = 0x3 |
|
76 | 76 | }; |
|
77 | 77 | |
|
78 | 78 | enum SeriesType { |
|
79 | 79 | SeriesTypeLine, |
|
80 | 80 | SeriesTypeArea, |
|
81 | 81 | SeriesTypeBar, |
|
82 | 82 | SeriesTypeStackedBar, |
|
83 | 83 | SeriesTypePercentBar, |
|
84 | 84 | SeriesTypePie, |
|
85 | 85 | SeriesTypeScatter, |
|
86 | 86 | SeriesTypeSpline, |
|
87 | 87 | SeriesTypeHorizontalBar, |
|
88 | 88 | SeriesTypeHorizontalStackedBar, |
|
89 | 89 | SeriesTypeHorizontalPercentBar |
|
90 | 90 | }; |
|
91 | 91 | |
|
92 | 92 | public: |
|
93 | 93 | DeclarativeChart(QDeclarativeItem *parent = 0); |
|
94 | 94 | ~DeclarativeChart(); |
|
95 | 95 | |
|
96 | 96 | public: // From QDeclarativeItem/QGraphicsItem |
|
97 | 97 | void childEvent(QChildEvent *event); |
|
98 | 98 | void componentComplete(); |
|
99 | 99 | void geometryChanged(const QRectF &newGeometry, const QRectF &oldGeometry); |
|
100 | 100 | |
|
101 | 101 | public: |
|
102 | 102 | void setTheme(DeclarativeChart::Theme theme); |
|
103 | 103 | DeclarativeChart::Theme theme(); |
|
104 | 104 | void setAnimationOptions(DeclarativeChart::Animation animations); |
|
105 | 105 | DeclarativeChart::Animation animationOptions(); |
|
106 | 106 | void setTitle(QString title); |
|
107 | 107 | QString title(); |
|
108 | 108 | QLegend *legend(); |
|
109 | 109 | QFont titleFont() const; |
|
110 | 110 | void setTitleFont(const QFont &font); |
|
111 | 111 | void setTitleColor(QColor color); |
|
112 | 112 | QColor titleColor(); |
|
113 | 113 | void setBackgroundColor(QColor color); |
|
114 | 114 | QColor backgroundColor(); |
|
115 | 115 | int count(); |
|
116 | 116 | void setDropShadowEnabled(bool enabled); |
|
117 | 117 | bool dropShadowEnabled(); |
|
118 | ||
|
119 | // Margins & plotArea | |
|
118 | 120 | qreal topMargin(); |
|
119 | 121 | qreal bottomMargin(); |
|
120 | 122 | qreal leftMargin(); |
|
121 | 123 | qreal rightMargin(); |
|
122 | QAbstractAxis *defaultAxis(Qt::Orientation orientation, QAbstractSeries *series); | |
|
123 | void initializeAxes(QAbstractSeries *series); | |
|
124 | void doInitializeAxes(QAbstractSeries *series, DeclarativeAxes *axes); | |
|
125 | //TODO this is deprecated: | |
|
126 | 124 | DeclarativeMargins *minimumMargins() { return m_margins; } |
|
127 | ||
|
128 | 125 | Q_REVISION(2) DeclarativeMargins *margins() { return m_margins; } |
|
129 | 126 | QRectF plotArea() { return m_chart->plotArea(); } |
|
130 | 127 | |
|
131 | // Axis list property methods | |
|
128 | // Axis handling | |
|
129 | QAbstractAxis *defaultAxis(Qt::Orientation orientation, QAbstractSeries *series); | |
|
130 | void initializeAxes(QAbstractSeries *series); | |
|
131 | void doInitializeAxes(QAbstractSeries *series, DeclarativeAxes *axes); | |
|
132 | 132 | QDeclarativeListProperty<QAbstractAxis> axes(); |
|
133 | 133 | static void axesAppendFunc(QDeclarativeListProperty<QAbstractAxis> *list, QAbstractAxis *element); |
|
134 | 134 | static int axesCountFunc(QDeclarativeListProperty<QAbstractAxis> *list); |
|
135 | 135 | static QAbstractAxis *axesAtFunc(QDeclarativeListProperty<QAbstractAxis> *list, int index); |
|
136 | 136 | |
|
137 | 137 | public: |
|
138 | 138 | Q_INVOKABLE QAbstractSeries *series(int index); |
|
139 | 139 | Q_INVOKABLE QAbstractSeries *series(QString seriesName); |
|
140 | 140 | Q_INVOKABLE QAbstractSeries *createSeries(DeclarativeChart::SeriesType type, QString name = ""); |
|
141 | 141 | Q_INVOKABLE QAbstractSeries *createSeries(DeclarativeChart::SeriesType type, QString name, QAbstractAxis *axisX, QAbstractAxis *axisY); |
|
142 | 142 | Q_INVOKABLE void removeSeries(QAbstractSeries *series); |
|
143 | 143 | Q_INVOKABLE void removeAllSeries() { m_chart->removeAllSeries(); } |
|
144 | 144 | Q_INVOKABLE void setAxisX(QAbstractAxis *axis, QAbstractSeries *series = 0); |
|
145 | 145 | Q_INVOKABLE void setAxisY(QAbstractAxis *axis, QAbstractSeries *series = 0); |
|
146 | 146 | Q_INVOKABLE void createDefaultAxes(); |
|
147 | 147 | Q_INVOKABLE QAbstractAxis *axisX(QAbstractSeries *series = 0); |
|
148 | 148 | Q_INVOKABLE QAbstractAxis *axisY(QAbstractSeries *series = 0); |
|
149 | 149 | Q_INVOKABLE void zoom(qreal factor); |
|
150 | 150 | Q_INVOKABLE void scrollLeft(qreal pixels); |
|
151 | 151 | Q_INVOKABLE void scrollRight(qreal pixels); |
|
152 | 152 | Q_INVOKABLE void scrollUp(qreal pixels); |
|
153 | 153 | Q_INVOKABLE void scrollDown(qreal pixels); |
|
154 | 154 | |
|
155 | 155 | Q_SIGNALS: |
|
156 | 156 | void axisLabelsChanged(); |
|
157 | 157 | void titleColorChanged(QColor color); |
|
158 | 158 | void backgroundColorChanged(); |
|
159 | 159 | void dropShadowEnabledChanged(bool enabled); |
|
160 | 160 | void minimumMarginsChanged(); |
|
161 | 161 | Q_REVISION(2) void marginsChanged(); |
|
162 | 162 | void plotAreaChanged(QRectF plotArea); |
|
163 | 163 | void seriesAdded(QAbstractSeries *series); |
|
164 | 164 | void seriesRemoved(QAbstractSeries *series); |
|
165 | 165 | |
|
166 | 166 | private Q_SLOTS: |
|
167 | 167 | void changeMinimumMargins(int top, int bottom, int left, int right); |
|
168 | 168 | void handleAxisXSet(QAbstractAxis *axis); |
|
169 | 169 | void handleAxisYSet(QAbstractAxis *axis); |
|
170 | 170 | void handleAxisXTopSet(QAbstractAxis *axis); |
|
171 | 171 | void handleAxisYRightSet(QAbstractAxis *axis); |
|
172 | 172 | void handleSeriesAdded(QAbstractSeries *series); |
|
173 | 173 | |
|
174 | 174 | private: |
|
175 | 175 | // Extending QChart with DeclarativeChart is not possible because QObject does not support |
|
176 | 176 | // multi inheritance, so we now have a QChart as a member instead |
|
177 | 177 | QChart *m_chart; |
|
178 | 178 | //QMargins m_chartMargins; |
|
179 | 179 | DeclarativeMargins *m_margins; |
|
180 | 180 | }; |
|
181 | 181 | |
|
182 | 182 | QTCOMMERCIALCHART_END_NAMESPACE |
|
183 | 183 | |
|
184 | 184 | #endif // DECLARATIVECHART_H |
@@ -1,83 +1,84 | |||
|
1 | 1 | /**************************************************************************** |
|
2 | 2 | ** |
|
3 | 3 | ** Copyright (C) 2012 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 Commercial Charts Add-on. |
|
8 | 8 | ** |
|
9 | 9 | ** $QT_BEGIN_LICENSE$ |
|
10 | 10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
11 | 11 | ** accordance with the Qt Commercial 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 | import QtQuick 1.0 |
|
22 | 22 | import QtQuickTest 1.0 |
|
23 | 23 | import QtCommercial.Chart 1.2 |
|
24 | 24 | |
|
25 | 25 | Rectangle { |
|
26 | 26 | width: 400 |
|
27 | 27 | height: 300 |
|
28 | 28 | |
|
29 | 29 | TestCase { |
|
30 | 30 | id: tc1 |
|
31 | 31 | name: "tst_qml-qtquicktest ChartView Properties" |
|
32 | 32 | when: windowShown |
|
33 | 33 | |
|
34 | 34 | function test_chartViewProperties() { |
|
35 | 35 | compare(chartView.animationOptions, ChartView.NoAnimation, "ChartView.animationOptions"); |
|
36 | 36 | verify(chartView.backgroundColor != undefined); |
|
37 | 37 | verify(chartView.bottomMargin > 0, "ChartView.bottomMargin"); |
|
38 | 38 | verify(chartView.topMargin > 0, "ChartView.topMargin"); |
|
39 | 39 | verify(chartView.leftMargin > 0, "ChartView.leftMargin"); |
|
40 | 40 | verify(chartView.rightMargin > 0, "ChartView.rightMargin"); |
|
41 | 41 | verify(chartView.margins.bottom > 0, "ChartView.margins.bottom"); |
|
42 | 42 | verify(chartView.margins.top > 0, "ChartView.margins.top"); |
|
43 | 43 | verify(chartView.margins.left > 0, "ChartView.margins.left"); |
|
44 | 44 | verify(chartView.margins.right > 0, "ChartView.margins.right"); |
|
45 | 45 | compare(chartView.count, 0, "ChartView.count"); |
|
46 | 46 | compare(chartView.dropShadowEnabled, false, "ChartView.dropShadowEnabled"); |
|
47 | 47 | verify(chartView.plotArea.height > 0, "ChartView.plotArea.height"); |
|
48 | 48 | verify(chartView.plotArea.width > 0, "ChartView.plotArea.width"); |
|
49 | 49 | verify(chartView.plotArea.x > 0, "ChartView.plotArea.x"); |
|
50 | 50 | verify(chartView.plotArea.y > 0, "ChartView.plotArea.y"); |
|
51 | 51 | compare(chartView.theme, ChartView.ChartThemeLight, "ChartView.theme"); |
|
52 | 52 | compare(chartView.title, "", "ChartView.title"); |
|
53 | 53 | compare(chartView.title, "", "ChartView.title"); |
|
54 | 54 | verify(chartView.titleColor != undefined, "ChartView.titleColor"); |
|
55 | 55 | compare(chartView.titleFont.bold, false, "ChartView.titleFont.bold"); |
|
56 | 56 | // Legend |
|
57 | 57 | compare(chartView.legend.visible, true, "ChartView.legend.visible"); |
|
58 | 58 | compare(chartView.legend.alignment, Qt.AlignTop, "ChartView.legend.alignment"); |
|
59 | 59 | compare(chartView.legend.backgroundVisible, false, "ChartView.legend.backgroundVisible"); |
|
60 | 60 | verify(chartView.legend.borderColor != undefined, "ChartView.legend.borderColor"); |
|
61 | 61 | verify(chartView.legend.color != undefined, "ChartView.legend.color"); |
|
62 | 62 | // Legend font |
|
63 | 63 | compare(chartView.legend.font.bold, false, "ChartView.legend.font.bold"); |
|
64 | 64 | compare(chartView.legend.font.capitalization, Font.MixedCase, "ChartView.legend.font.capitalization"); |
|
65 |
|
|
|
65 | verify(chartView.legend.font.family != "", "ChartView.legend.font.family"); | |
|
66 | 66 | compare(chartView.legend.font.italic, false, "ChartView.legend.font.italic"); |
|
67 | 67 | compare(chartView.legend.font.letterSpacing, 0.0, "ChartView.legend.font.letterSpacing"); |
|
68 | 68 | verify(chartView.legend.font.pixelSize > 0 |
|
69 | 69 | && chartView.legend.font.pixelSize < 50, "ChartView.legend.font.pixelSize"); |
|
70 | 70 | verify(chartView.legend.font.pointSize > 0 |
|
71 | 71 | && chartView.legend.font.pointSize < 50, "ChartView.legend.font.pointSize"); |
|
72 | 72 | compare(chartView.legend.font.strikeout, false, "ChartView.legend.font.strikeout"); |
|
73 | 73 | compare(chartView.legend.font.underline, false, "ChartView.legend.font.underline"); |
|
74 | 74 | compare(chartView.legend.font.weight, Font.Normal, "ChartView.legend.font.weight"); |
|
75 | 75 | compare(chartView.legend.font.wordSpacing, 0.0, "ChartView.legend.font.wordSpacing"); |
|
76 | compare(chartView.axes.length, 0, "ChartView.axes.length"); | |
|
76 | 77 | } |
|
77 | 78 | } |
|
78 | 79 | |
|
79 | 80 | ChartView { |
|
80 | 81 | id: chartView |
|
81 | 82 | anchors.fill: parent |
|
82 | 83 | } |
|
83 | 84 | } |
@@ -1,79 +1,79 | |||
|
1 | 1 | /**************************************************************************** |
|
2 | 2 | ** |
|
3 | 3 | ** Copyright (C) 2012 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 Commercial Charts Add-on. |
|
8 | 8 | ** |
|
9 | 9 | ** $QT_BEGIN_LICENSE$ |
|
10 | 10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
11 | 11 | ** accordance with the Qt Commercial 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 | import QtQuick 1.0 |
|
22 | 22 | import QtQuickTest 1.0 |
|
23 | 23 | import QtCommercial.Chart 1.1 |
|
24 | 24 | |
|
25 | 25 | Rectangle { |
|
26 | 26 | width: 400 |
|
27 | 27 | height: 300 |
|
28 | 28 | |
|
29 | 29 | TestCase { |
|
30 | 30 | id: tc1 |
|
31 | 31 | name: "tst_qml-qtquicktest ChartView Properties 1.1" |
|
32 | 32 | when: windowShown |
|
33 | 33 | |
|
34 | 34 | function test_chartViewProperties() { |
|
35 | 35 | compare(chartView.animationOptions, ChartView.NoAnimation, "ChartView.animationOptions"); |
|
36 | 36 | verify(chartView.backgroundColor != undefined); |
|
37 | 37 | verify(chartView.bottomMargin > 0, "ChartView.bottomMargin"); |
|
38 | 38 | verify(chartView.topMargin > 0, "ChartView.topMargin"); |
|
39 | 39 | verify(chartView.leftMargin > 0, "ChartView.leftMargin"); |
|
40 | 40 | verify(chartView.rightMargin > 0, "ChartView.rightMargin"); |
|
41 | 41 | compare(chartView.count, 0, "ChartView.count"); |
|
42 | 42 | compare(chartView.dropShadowEnabled, false, "ChartView.dropShadowEnabled"); |
|
43 | 43 | verify(chartView.plotArea.height > 0, "ChartView.plotArea.height"); |
|
44 | 44 | verify(chartView.plotArea.width > 0, "ChartView.plotArea.width"); |
|
45 | 45 | verify(chartView.plotArea.x > 0, "ChartView.plotArea.x"); |
|
46 | 46 | verify(chartView.plotArea.y > 0, "ChartView.plotArea.y"); |
|
47 | 47 | compare(chartView.theme, ChartView.ChartThemeLight, "ChartView.theme"); |
|
48 | 48 | compare(chartView.title, "", "ChartView.title"); |
|
49 | 49 | compare(chartView.title, "", "ChartView.title"); |
|
50 | 50 | verify(chartView.titleColor != undefined, "ChartView.titleColor"); |
|
51 | 51 | compare(chartView.titleFont.bold, false, "ChartView.titleFont.bold"); |
|
52 | 52 | // Legend |
|
53 | 53 | compare(chartView.legend.visible, true, "ChartView.legend.visible"); |
|
54 | 54 | compare(chartView.legend.alignment, Qt.AlignTop, "ChartView.legend.alignment"); |
|
55 | 55 | compare(chartView.legend.backgroundVisible, false, "ChartView.legend.backgroundVisible"); |
|
56 | 56 | verify(chartView.legend.borderColor != undefined, "ChartView.legend.borderColor"); |
|
57 | 57 | verify(chartView.legend.color != undefined, "ChartView.legend.color"); |
|
58 | 58 | // Legend font |
|
59 | 59 | compare(chartView.legend.font.bold, false, "ChartView.legend.font.bold"); |
|
60 | 60 | compare(chartView.legend.font.capitalization, Font.MixedCase, "ChartView.legend.font.capitalization"); |
|
61 |
|
|
|
61 | verify(chartView.legend.font.family != "", "ChartView.legend.font.family"); | |
|
62 | 62 | compare(chartView.legend.font.italic, false, "ChartView.legend.font.italic"); |
|
63 | 63 | compare(chartView.legend.font.letterSpacing, 0.0, "ChartView.legend.font.letterSpacing"); |
|
64 | 64 | verify(chartView.legend.font.pixelSize > 0 |
|
65 | 65 | && chartView.legend.font.pixelSize < 50, "ChartView.legend.font.pixelSize"); |
|
66 | 66 | verify(chartView.legend.font.pointSize > 0 |
|
67 | 67 | && chartView.legend.font.pointSize < 50, "ChartView.legend.font.pointSize"); |
|
68 | 68 | compare(chartView.legend.font.strikeout, false, "ChartView.legend.font.strikeout"); |
|
69 | 69 | compare(chartView.legend.font.underline, false, "ChartView.legend.font.underline"); |
|
70 | 70 | compare(chartView.legend.font.weight, Font.Normal, "ChartView.legend.font.weight"); |
|
71 | 71 | compare(chartView.legend.font.wordSpacing, 0.0, "ChartView.legend.font.wordSpacing"); |
|
72 | 72 | } |
|
73 | 73 | } |
|
74 | 74 | |
|
75 | 75 | ChartView { |
|
76 | 76 | id: chartView |
|
77 | 77 | anchors.fill: parent |
|
78 | 78 | } |
|
79 | 79 | } |
@@ -1,102 +1,100 | |||
|
1 | 1 | /**************************************************************************** |
|
2 | 2 | ** |
|
3 | 3 | ** Copyright (C) 2012 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 Commercial Charts Add-on. |
|
8 | 8 | ** |
|
9 | 9 | ** $QT_BEGIN_LICENSE$ |
|
10 | 10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
11 | 11 | ** accordance with the Qt Commercial 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 | import QtQuick 1.0 |
|
22 | 22 | import QtQuickTest 1.0 |
|
23 | 23 | import QtCommercial.Chart 1.2 |
|
24 | 24 | |
|
25 | 25 | Rectangle { |
|
26 | 26 | width: 400 |
|
27 | 27 | height: 300 |
|
28 | 28 | |
|
29 | 29 | TestCase { |
|
30 | 30 | id: tc1 |
|
31 | 31 | name: "tst_qml-qtquicktest ValueAxis" |
|
32 | 32 | when: windowShown |
|
33 | 33 | |
|
34 | 34 | function test_defaultPropertyValues() { |
|
35 |
|
|
|
36 |
|
|
|
37 |
|
|
|
38 |
|
|
|
35 | verify(axisX.min < 0, "AxisX min"); | |
|
36 | verify(axisX.max > 0, "AxisX max"); | |
|
37 | verify(axisY.min < 0, "AxisY min"); | |
|
38 | verify(axisY.max > 0, "AxisY max"); | |
|
39 | 39 | verify(axisX.tickCount > 0, "AxisX tick count"); |
|
40 | 40 | verify(axisY.tickCount > 0, "AxisX tick count"); |
|
41 | 41 | compare(axisX.niceNumbersEnabled, false, "nice numbers"); |
|
42 | 42 | compare(axisX.labelFormat, "", "label format"); |
|
43 | 43 | } |
|
44 | 44 | |
|
45 | 45 | function test_modifyProperties() { |
|
46 |
|
|
|
47 |
compare( |
|
|
46 | axisX.tickCount = 3; | |
|
47 | compare(axisX.tickCount, 3, "set tick count"); | |
|
48 | 48 | |
|
49 |
|
|
|
49 | axisX.niceNumbersEnabled = true; | |
|
50 | 50 | compare(axisX.niceNumbersEnabled, true, "nice numbers"); |
|
51 | 51 | } |
|
52 | 52 | |
|
53 | 53 | function test_signals() { |
|
54 | minChangedSpy.clear(); | |
|
55 | maxChangedSpy.clear(); | |
|
54 | 56 | axisX.min = 2; |
|
55 | 57 | compare(minChangedSpy.count, 1, "onMinChanged"); |
|
56 | 58 | compare(maxChangedSpy.count, 0, "onMaxChanged"); |
|
57 | 59 | |
|
58 | 60 | axisX.max = 8; |
|
59 | 61 | compare(minChangedSpy.count, 1, "onMinChanged"); |
|
60 | 62 | compare(maxChangedSpy.count, 1, "onMaxChanged"); |
|
61 | 63 | |
|
62 | 64 | // restore original values |
|
63 | 65 | axisX.min = 0; |
|
64 | 66 | axisX.max = 10; |
|
65 | 67 | compare(minChangedSpy.count, 2, "onMinChanged"); |
|
66 | 68 | compare(maxChangedSpy.count, 2, "onMaxChanged"); |
|
67 | 69 | } |
|
68 | 70 | } |
|
69 | 71 | |
|
70 | 72 | ChartView { |
|
71 | 73 | id: chartView |
|
72 | 74 | anchors.fill: parent |
|
73 | 75 | |
|
74 | 76 | LineSeries { |
|
75 | 77 | id: lineSeries1 |
|
76 | 78 | axisX: ValueAxis { |
|
77 | 79 | id: axisX |
|
78 | min: 0 | |
|
79 | max: 10 | |
|
80 | 80 | } |
|
81 | 81 | axisY: ValueAxis { |
|
82 | 82 | id: axisY |
|
83 | min: 0 | |
|
84 | max: 10 | |
|
85 | 83 | } |
|
86 | 84 | XYPoint { x: -1; y: -1 } |
|
87 | 85 | XYPoint { x: 0; y: 0 } |
|
88 | 86 | XYPoint { x: 5; y: 5 } |
|
89 | 87 | } |
|
90 | 88 | |
|
91 | 89 | SignalSpy { |
|
92 | 90 | id: minChangedSpy |
|
93 | 91 | target: axisX |
|
94 | 92 | signalName: "minChanged" |
|
95 | 93 | } |
|
96 | 94 | SignalSpy { |
|
97 | 95 | id: maxChangedSpy |
|
98 | 96 | target: axisX |
|
99 | 97 | signalName: "maxChanged" |
|
100 | 98 | } |
|
101 | 99 | } |
|
102 | 100 | } |
@@ -1,264 +1,260 | |||
|
1 | 1 | /**************************************************************************** |
|
2 | 2 | ** |
|
3 | 3 | ** Copyright (C) 2012 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 Commercial Charts Add-on. |
|
8 | 8 | ** |
|
9 | 9 | ** $QT_BEGIN_LICENSE$ |
|
10 | 10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
11 | 11 | ** accordance with the Qt Commercial 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 | import QtQuick 1.0 |
|
22 | 22 | import QtQuickTest 1.0 |
|
23 | 23 | import QtCommercial.Chart 1.2 |
|
24 | 24 | |
|
25 | 25 | Rectangle { |
|
26 | 26 | width: 400 |
|
27 | 27 | height: 300 |
|
28 | 28 | |
|
29 | 29 | TestCase { |
|
30 | 30 | id: tc1 |
|
31 | 31 | name: "tst_qml-qtquicktest XY Series" |
|
32 | 32 | when: windowShown |
|
33 | 33 | |
|
34 | 34 | function test_properties() { |
|
35 | 35 | verify(lineSeries.color != undefined); |
|
36 | 36 | compare(lineSeries.pointsVisible, false); |
|
37 | 37 | compare(lineSeries.capStyle, Qt.SquareCap); |
|
38 | 38 | compare(lineSeries.style, Qt.SolidLine); |
|
39 | 39 | compare(lineSeries.width, 2.0); |
|
40 | 40 | |
|
41 | 41 | verify(splineSeries.color != undefined); |
|
42 | 42 | compare(splineSeries.pointsVisible, false); |
|
43 | 43 | compare(splineSeries.capStyle, Qt.SquareCap); |
|
44 | 44 | compare(splineSeries.style, Qt.SolidLine); |
|
45 | 45 | compare(splineSeries.width, 2.0); |
|
46 | 46 | |
|
47 | 47 | verify(scatterSeries.color != undefined); |
|
48 | 48 | verify(scatterSeries.borderColor != undefined); |
|
49 | 49 | compare(scatterSeries.borderWidth, 2.0); |
|
50 | 50 | compare(scatterSeries.markerShape, ScatterSeries.MarkerShapeCircle); |
|
51 | 51 | compare(scatterSeries.markerSize, 15.0); |
|
52 | 52 | |
|
53 | 53 | verify(areaSeries.color != undefined); |
|
54 | 54 | verify(areaSeries.borderColor != undefined); |
|
55 | 55 | compare(areaSeries.borderWidth, 2.0); |
|
56 | 56 | } |
|
57 | 57 | |
|
58 | 58 | function test_axes() { |
|
59 | 59 | compare(chartView.axes.length, 2); |
|
60 | console.log("chart.axes[0] " + chartView.axes[0]); | |
|
61 | console.log("chart.axes[1] " + chartView.axes[1]); | |
|
62 | console.log("lineSeries.axisX " + lineSeries.axisX); | |
|
63 | console.log("lineSeries.axisY " + lineSeries.axisY); | |
|
64 | 60 | verify(chartView.axes[0] == lineSeries.axisX || chartView.axes[1] == lineSeries.axisX); |
|
65 | 61 | verify(chartView.axes[0] == lineSeries.axisY || chartView.axes[1] == lineSeries.axisY); |
|
66 | 62 | verify(lineSeries.axisX == splineSeries.axisX); |
|
67 | 63 | verify(lineSeries.axisY == splineSeries.axisY); |
|
68 | 64 | verify(lineSeries.axisX == areaSeries.axisX); |
|
69 | 65 | verify(lineSeries.axisY == areaSeries.axisY); |
|
70 | 66 | } |
|
71 | 67 | |
|
72 | 68 | function test_append() { |
|
73 | 69 | lineSeriesPointAddedSpy.clear(); |
|
74 | 70 | splineSeriesPointAddedSpy.clear(); |
|
75 | 71 | scatterSeriesPointAddedSpy.clear(); |
|
76 | 72 | var count = append(); |
|
77 | 73 | compare(lineSeries.count, count); |
|
78 | 74 | compare(splineSeries.count, count); |
|
79 | 75 | compare(scatterSeries.count, count); |
|
80 | 76 | tryCompare(lineSeriesPointAddedSpy.count, count); |
|
81 | 77 | tryCompare(splineSeriesPointAddedSpy.count, count); |
|
82 | 78 | tryCompare(scatterSeriesPointAddedSpy.count, count); |
|
83 | 79 | clear(); |
|
84 | 80 | compare(lineSeries.count, 0); |
|
85 | 81 | compare(splineSeries.count, 0); |
|
86 | 82 | compare(scatterSeries.count, 0); |
|
87 | 83 | } |
|
88 | 84 | |
|
89 | 85 | function test_replace() { |
|
90 | 86 | var count = append(); |
|
91 | 87 | for (var i = 0; i < count; i++) { |
|
92 | 88 | lineSeries.replace(lineSeries.at(i).x, lineSeries.at(i).y, i, Math.random()); |
|
93 | 89 | splineSeries.replace(splineSeries.at(i).x, splineSeries.at(i).y, i, Math.random()); |
|
94 | 90 | scatterSeries.replace(scatterSeries.at(i).x, scatterSeries.at(i).y, i, Math.random()); |
|
95 | 91 | } |
|
96 | 92 | compare(lineSeries.count, count); |
|
97 | 93 | compare(splineSeries.count, count); |
|
98 | 94 | compare(scatterSeries.count, count); |
|
99 | 95 | tryCompare(lineSeriesPointReplacedSpy.count, count); |
|
100 | 96 | tryCompare(splineSeriesPointReplacedSpy.count, count); |
|
101 | 97 | tryCompare(scatterSeriesPointReplacedSpy.count, count); |
|
102 | 98 | clear(); |
|
103 | 99 | } |
|
104 | 100 | |
|
105 | 101 | function test_insert() { |
|
106 | 102 | var count = append(); |
|
107 | 103 | lineSeriesPointAddedSpy.clear(); |
|
108 | 104 | splineSeriesPointAddedSpy.clear(); |
|
109 | 105 | scatterSeriesPointAddedSpy.clear(); |
|
110 | 106 | for (var i = 0; i < count; i++) { |
|
111 | 107 | lineSeries.insert(i * 2, i, Math.random()); |
|
112 | 108 | splineSeries.insert(i * 2, i, Math.random()); |
|
113 | 109 | scatterSeries.insert(i * 2, i, Math.random()); |
|
114 | 110 | } |
|
115 | 111 | compare(lineSeries.count, count * 2); |
|
116 | 112 | compare(splineSeries.count, count * 2); |
|
117 | 113 | compare(scatterSeries.count, count * 2); |
|
118 | 114 | tryCompare(lineSeriesPointAddedSpy.count, count); |
|
119 | 115 | tryCompare(splineSeriesPointAddedSpy.count, count); |
|
120 | 116 | tryCompare(scatterSeriesPointAddedSpy.count, count); |
|
121 | 117 | clear(); |
|
122 | 118 | } |
|
123 | 119 | |
|
124 | 120 | function test_remove() { |
|
125 | 121 | lineSeriesPointRemovedSpy.clear(); |
|
126 | 122 | splineSeriesPointRemovedSpy.clear(); |
|
127 | 123 | scatterSeriesPointRemovedSpy.clear(); |
|
128 | 124 | var count = append(); |
|
129 | 125 | for (var i = 0; i < count; i++) { |
|
130 | 126 | lineSeries.remove(lineSeries.at(0).x, lineSeries.at(0).y); |
|
131 | 127 | splineSeries.remove(splineSeries.at(0).x, splineSeries.at(0).y); |
|
132 | 128 | scatterSeries.remove(scatterSeries.at(0).x, scatterSeries.at(0).y); |
|
133 | 129 | } |
|
134 | 130 | compare(lineSeries.count, 0); |
|
135 | 131 | compare(splineSeries.count, 0); |
|
136 | 132 | compare(scatterSeries.count, 0); |
|
137 | 133 | tryCompare(lineSeriesPointRemovedSpy.count, count); |
|
138 | 134 | tryCompare(splineSeriesPointRemovedSpy.count, count); |
|
139 | 135 | tryCompare(scatterSeriesPointRemovedSpy.count, count); |
|
140 | 136 | } |
|
141 | 137 | |
|
142 | 138 | // Not a test function, called from test functions |
|
143 | 139 | function append() { |
|
144 | 140 | var count = 100; |
|
145 | 141 | chartView.axisX().min = 0; |
|
146 | 142 | chartView.axisX().max = 100; |
|
147 | 143 | chartView.axisY().min = 0; |
|
148 | 144 | chartView.axisY().max = 1; |
|
149 | 145 | |
|
150 | 146 | for (var i = 0; i < count; i++) { |
|
151 | 147 | lineSeries.append(i, Math.random()); |
|
152 | 148 | splineSeries.append(i, Math.random()); |
|
153 | 149 | scatterSeries.append(i, Math.random()); |
|
154 | 150 | } |
|
155 | 151 | |
|
156 | 152 | return count; |
|
157 | 153 | } |
|
158 | 154 | |
|
159 | 155 | // Not a test function, called from test functions |
|
160 | 156 | function clear() { |
|
161 | 157 | lineSeries.clear(); |
|
162 | 158 | splineSeries.clear(); |
|
163 | 159 | scatterSeries.clear(); |
|
164 | 160 | } |
|
165 | 161 | } |
|
166 | 162 | |
|
167 | 163 | ChartView { |
|
168 | 164 | id: chartView |
|
169 | 165 | anchors.fill: parent |
|
170 | 166 | |
|
171 | 167 | LineSeries { |
|
172 | 168 | id: lineSeries |
|
173 | 169 | name: "line" |
|
174 | 170 | |
|
175 | 171 | SignalSpy { |
|
176 | 172 | id: lineSeriesPointAddedSpy |
|
177 | 173 | target: lineSeries |
|
178 | 174 | signalName: "pointAdded" |
|
179 | 175 | } |
|
180 | 176 | |
|
181 | 177 | SignalSpy { |
|
182 | 178 | id: lineSeriesPointReplacedSpy |
|
183 | 179 | target: lineSeries |
|
184 | 180 | signalName: "pointReplaced" |
|
185 | 181 | } |
|
186 | 182 | |
|
187 | 183 | SignalSpy { |
|
188 | 184 | id: lineSeriesPointsReplacedSpy |
|
189 | 185 | target: lineSeries |
|
190 | 186 | signalName: "pointsReplaced" |
|
191 | 187 | } |
|
192 | 188 | |
|
193 | 189 | SignalSpy { |
|
194 | 190 | id: lineSeriesPointRemovedSpy |
|
195 | 191 | target: lineSeries |
|
196 | 192 | signalName: "pointRemoved" |
|
197 | 193 | } |
|
198 | 194 | } |
|
199 | 195 | |
|
200 | 196 | AreaSeries { |
|
201 | 197 | id: areaSeries |
|
202 | 198 | name: "area" |
|
203 | 199 | upperSeries: lineSeries |
|
204 | 200 | } |
|
205 | 201 | |
|
206 | 202 | SplineSeries { |
|
207 | 203 | id: splineSeries |
|
208 | 204 | name: "spline" |
|
209 | 205 | |
|
210 | 206 | SignalSpy { |
|
211 | 207 | id: splineSeriesPointAddedSpy |
|
212 | 208 | target: splineSeries |
|
213 | 209 | signalName: "pointAdded" |
|
214 | 210 | } |
|
215 | 211 | |
|
216 | 212 | SignalSpy { |
|
217 | 213 | id: splineSeriesPointReplacedSpy |
|
218 | 214 | target: splineSeries |
|
219 | 215 | signalName: "pointReplaced" |
|
220 | 216 | } |
|
221 | 217 | |
|
222 | 218 | SignalSpy { |
|
223 | 219 | id: splineSeriesPointsReplacedSpy |
|
224 | 220 | target: splineSeries |
|
225 | 221 | signalName: "pointsReplaced" |
|
226 | 222 | } |
|
227 | 223 | |
|
228 | 224 | SignalSpy { |
|
229 | 225 | id: splineSeriesPointRemovedSpy |
|
230 | 226 | target: splineSeries |
|
231 | 227 | signalName: "pointRemoved" |
|
232 | 228 | } |
|
233 | 229 | } |
|
234 | 230 | |
|
235 | 231 | ScatterSeries { |
|
236 | 232 | id: scatterSeries |
|
237 | 233 | name: "scatter" |
|
238 | 234 | |
|
239 | 235 | SignalSpy { |
|
240 | 236 | id: scatterSeriesPointAddedSpy |
|
241 | 237 | target: scatterSeries |
|
242 | 238 | signalName: "pointAdded" |
|
243 | 239 | } |
|
244 | 240 | |
|
245 | 241 | SignalSpy { |
|
246 | 242 | id: scatterSeriesPointReplacedSpy |
|
247 | 243 | target: scatterSeries |
|
248 | 244 | signalName: "pointReplaced" |
|
249 | 245 | } |
|
250 | 246 | |
|
251 | 247 | SignalSpy { |
|
252 | 248 | id: scatterSeriesPointsReplacedSpy |
|
253 | 249 | target: scatterSeries |
|
254 | 250 | signalName: "pointsReplaced" |
|
255 | 251 | } |
|
256 | 252 | |
|
257 | 253 | SignalSpy { |
|
258 | 254 | id: scatterSeriesPointRemovedSpy |
|
259 | 255 | target: scatterSeries |
|
260 | 256 | signalName: "pointRemoved" |
|
261 | 257 | } |
|
262 | 258 | } |
|
263 | 259 | } |
|
264 | 260 | } |
General Comments 0
You need to be logged in to leave comments.
Login now