@@ -1,997 +1,1015 | |||
|
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 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 "declarativelineseries.h" |
|
24 | 24 | #include "declarativeareaseries.h" |
|
25 | 25 | #include "declarativebarseries.h" |
|
26 | 26 | #include "declarativepieseries.h" |
|
27 | 27 | #include "declarativesplineseries.h" |
|
28 | 28 | #include "declarativeboxplotseries.h" |
|
29 | 29 | #include "declarativescatterseries.h" |
|
30 | 30 | #include "qbarcategoryaxis.h" |
|
31 | 31 | #include "qvalueaxis.h" |
|
32 | 32 | #include "qlogvalueaxis.h" |
|
33 | 33 | #include "qcategoryaxis.h" |
|
34 | 34 | #include "qabstractseries_p.h" |
|
35 | 35 | #include "declarativemargins.h" |
|
36 | 36 | #include "chartdataset_p.h" |
|
37 | 37 | #include "declarativeaxes.h" |
|
38 | 38 | #include "qchart_p.h" |
|
39 | 39 | #include "qpolarchart.h" |
|
40 | 40 | |
|
41 | 41 | #ifndef QT_ON_ARM |
|
42 | 42 | #include "qdatetimeaxis.h" |
|
43 | 43 | #endif |
|
44 | 44 | |
|
45 | 45 | #ifdef CHARTS_FOR_QUICK2 |
|
46 | 46 | #include <QGraphicsSceneMouseEvent> |
|
47 | 47 | #include <QGraphicsSceneHoverEvent> |
|
48 | 48 | #include <QApplication> |
|
49 | 49 | #include <QTimer> |
|
50 | 50 | #include <QThread> |
|
51 | 51 | #endif |
|
52 | 52 | |
|
53 | 53 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
54 | 54 | |
|
55 | 55 | /*! |
|
56 | 56 | \qmlclass ChartView DeclarativeChart |
|
57 | 57 | |
|
58 | 58 | ChartView element is the parent that is responsible for showing different chart series types. |
|
59 | 59 | |
|
60 | 60 | The following QML shows how to create a simple chart with one pie series: |
|
61 | 61 | \snippet ../examples/qmlpiechart/qml/qmlpiechart/main.qml 1 |
|
62 | 62 | \snippet ../examples/qmlpiechart/qml/qmlpiechart/main.qml 2 |
|
63 | 63 | \snippet ../examples/qmlpiechart/qml/qmlpiechart/main.qml 3 |
|
64 | 64 | |
|
65 | 65 | \beginfloatleft |
|
66 | 66 | \image examples_qmlpiechart.png |
|
67 | 67 | \endfloat |
|
68 | 68 | \clearfloat |
|
69 | 69 | */ |
|
70 | 70 | |
|
71 | 71 | /*! |
|
72 | 72 | \qmlproperty Theme ChartView::theme |
|
73 | 73 | Theme defines the visual appearance of the chart, including for example colors, fonts, line |
|
74 | 74 | widths and chart background. |
|
75 | 75 | */ |
|
76 | 76 | |
|
77 | 77 | /*! |
|
78 | 78 | \qmlproperty Animation ChartView::animationOptions |
|
79 | 79 | Animation configuration of the chart. One of ChartView.NoAnimation, ChartView.GridAxisAnimations, |
|
80 | 80 | ChartView.SeriesAnimations or ChartView.AllAnimations. |
|
81 | 81 | */ |
|
82 | 82 | |
|
83 | 83 | /*! |
|
84 | 84 | \qmlproperty Font ChartView::titleFont |
|
85 | 85 | The title font of the chart |
|
86 | 86 | |
|
87 | 87 | See the \l {Font} {QML Font Element} for detailed documentation. |
|
88 | 88 | */ |
|
89 | 89 | |
|
90 | 90 | /*! |
|
91 | 91 | \qmlproperty string ChartView::title |
|
92 | 92 | The title of the chart, shown on top of the chart. |
|
93 | 93 | \sa ChartView::titleColor |
|
94 | 94 | */ |
|
95 | 95 | |
|
96 | 96 | /*! |
|
97 | 97 | \qmlproperty color ChartView::titleColor |
|
98 | 98 | The color of the title text. |
|
99 | 99 | */ |
|
100 | 100 | |
|
101 | 101 | /*! |
|
102 | 102 | \qmlproperty Legend ChartView::legend |
|
103 | 103 | The legend of the chart. Legend lists all the series, pie slices and bar sets added on the chart. |
|
104 | 104 | */ |
|
105 | 105 | |
|
106 | 106 | /*! |
|
107 | 107 | \qmlproperty int ChartView::count |
|
108 | 108 | The count of series added to the chart. |
|
109 | 109 | */ |
|
110 | 110 | |
|
111 | 111 | /*! |
|
112 | 112 | \qmlproperty color ChartView::backgroundColor |
|
113 | 113 | The color of the chart's background. By default background color is defined by chart theme. |
|
114 | 114 | \sa ChartView::theme |
|
115 | 115 | */ |
|
116 | 116 | |
|
117 | 117 | /*! |
|
118 | \qmlproperty real ChartView::backgroundRoundness | |
|
119 | The diameter of the rounding cirle at the corners of the chart background. | |
|
120 | */ | |
|
121 | ||
|
122 | /*! | |
|
118 | 123 | \qmlproperty color ChartView::plotAreaColor |
|
119 | 124 | The color of the background of the chart's plot area. By default plot area background uses chart's |
|
120 | 125 | background color. |
|
121 | 126 | \sa ChartView::backgroundColor |
|
122 | 127 | */ |
|
123 | 128 | |
|
124 | 129 | /*! |
|
125 | 130 | \qmlproperty bool ChartView::dropShadowEnabled |
|
126 | 131 | The chart's border drop shadow. Set to true to enable drop shadow. |
|
127 | 132 | */ |
|
128 | 133 | |
|
129 | 134 | /*! |
|
130 | 135 | \qmlproperty real ChartView::topMargin |
|
131 | 136 | */ |
|
132 | 137 | |
|
133 | 138 | /*! |
|
134 | 139 | \qmlproperty real ChartView::bottomMargin |
|
135 | 140 | */ |
|
136 | 141 | |
|
137 | 142 | /*! |
|
138 | 143 | \qmlproperty real ChartView::leftMargin |
|
139 | 144 | */ |
|
140 | 145 | |
|
141 | 146 | /*! |
|
142 | 147 | \qmlproperty real ChartView::rightMargin |
|
143 | 148 | */ |
|
144 | 149 | |
|
145 | 150 | /*! |
|
146 | 151 | \qmlproperty Margins ChartView::minimumMargins |
|
147 | 152 | Deprecated; use margins instead. |
|
148 | 153 | The minimum margins allowed between the outer bounds and the plotArea of the ChartView. Margins |
|
149 | 154 | area of ChartView is used for drawing title, axes and legend. Please note that setting the |
|
150 | 155 | properties of minimumMargins may be bigger than the defined value, depending on other ChartView |
|
151 | 156 | properties that affect it's layout. If you need to know the actual plotting area used at any |
|
152 | 157 | given time, you can check ChartView::plotArea instead. |
|
153 | 158 | */ |
|
154 | 159 | |
|
155 | 160 | /*! |
|
156 | 161 | \qmlproperty rect ChartView::plotArea |
|
157 | 162 | The area on the ChartView that is used for drawing series. This is the ChartView rect without the |
|
158 | 163 | margins. |
|
159 | 164 | \sa ChartView::minimumMargins |
|
160 | 165 | */ |
|
161 | 166 | |
|
162 | 167 | /*! |
|
163 | 168 | \qmlproperty Margins ChartView::margins |
|
164 | 169 | The minimum margins allowed between the outer bounds and the plotArea of the ChartView. Margins |
|
165 | 170 | area of ChartView is used for drawing title, axes and legend. |
|
166 | 171 | */ |
|
167 | 172 | |
|
168 | 173 | /*! |
|
169 | 174 | \qmlmethod AbstractSeries ChartView::series(int index) |
|
170 | 175 | Returns the series with \a index on the chart. This allows you to loop through the series of a chart together with |
|
171 | 176 | the count property of the chart. |
|
172 | 177 | */ |
|
173 | 178 | |
|
174 | 179 | /*! |
|
175 | 180 | \qmlmethod AbstractSeries ChartView::series(string name) |
|
176 | 181 | Returns the first series on the chart with \a name. If there is no series with that name, returns null. |
|
177 | 182 | */ |
|
178 | 183 | |
|
179 | 184 | /*! |
|
180 | 185 | \qmlmethod AbstractSeries ChartView::createSeries(SeriesType type, string name, AbstractAxis axisX, AbstractAxis axisY) |
|
181 | 186 | Creates a series object of \a type to the chart with name \a name, optional axis \a axisX and |
|
182 | 187 | optional axis \a axisY. For example: |
|
183 | 188 | \code |
|
184 | 189 | // lineSeries is a LineSeries object that has already been added to the ChartView; re-use it's axes |
|
185 | 190 | var myAxisX = chartView.axisX(lineSeries); |
|
186 | 191 | var myAxisY = chartView.axisY(lineSeries); |
|
187 | 192 | var scatter = chartView.createSeries(ChartView.SeriesTypeScatter, "scatter series", myAxisX, myAxisY); |
|
188 | 193 | \endcode |
|
189 | 194 | */ |
|
190 | 195 | |
|
191 | 196 | /*! |
|
192 | 197 | \qmlmethod ChartView::removeSeries(AbstractSeries series) |
|
193 | 198 | Removes the \a series from the chart. The series object is also destroyed. |
|
194 | 199 | */ |
|
195 | 200 | |
|
196 | 201 | /*! |
|
197 | 202 | \qmlmethod ChartView::removeAllSeries() |
|
198 | 203 | Removes all series from the chart. All the series objects are also destroyed. |
|
199 | 204 | */ |
|
200 | 205 | |
|
201 | 206 | /*! |
|
202 | 207 | \qmlmethod Axis ChartView::axisX(AbstractSeries series) |
|
203 | 208 | The x-axis of the series. |
|
204 | 209 | */ |
|
205 | 210 | |
|
206 | 211 | /*! |
|
207 | 212 | \qmlmethod Axis ChartView::axisY(AbstractSeries series) |
|
208 | 213 | The y-axis of the series. |
|
209 | 214 | */ |
|
210 | 215 | |
|
211 | 216 | /*! |
|
212 | 217 | \qmlmethod ChartView::zoomY(real factor) |
|
213 | 218 | Zooms in by \a factor on the center of the chart. |
|
214 | 219 | */ |
|
215 | 220 | |
|
216 | 221 | /*! |
|
217 | 222 | \qmlmethod ChartView::scrollLeft(real pixels) |
|
218 | 223 | Scrolls to left by \a pixels. This is a convenience function that suits for example for key navigation. |
|
219 | 224 | */ |
|
220 | 225 | |
|
221 | 226 | /*! |
|
222 | 227 | \qmlmethod ChartView::scrollRight(real pixels) |
|
223 | 228 | Scrolls to right by \a pixels. This is a convenience function that suits for example for key navigation. |
|
224 | 229 | */ |
|
225 | 230 | |
|
226 | 231 | /*! |
|
227 | 232 | \qmlmethod ChartView::scrollUp(real pixels) |
|
228 | 233 | Scrolls up by \a pixels. This is a convenience function that suits for example for key navigation. |
|
229 | 234 | */ |
|
230 | 235 | |
|
231 | 236 | /*! |
|
232 | 237 | \qmlmethod ChartView::scrollDown(real pixels) |
|
233 | 238 | Scrolls down by \a pixels. This is a convenience function that suits for example for key navigation. |
|
234 | 239 | */ |
|
235 | 240 | |
|
236 | 241 | /*! |
|
237 | 242 | \qmlsignal ChartView::onPlotAreaChanged(rect plotArea) |
|
238 | 243 | The plot area of the chart has changed. This may happen for example, if you modify minimumMargins |
|
239 | 244 | or if you resize the chart, or if you modify font size related properties of the legend or chart |
|
240 | 245 | title. |
|
241 | 246 | */ |
|
242 | 247 | |
|
243 | 248 | /*! |
|
244 | 249 | \qmlsignal ChartView::seriesAdded(AbstractSeries series) |
|
245 | 250 | The \a series has been added to the chart. |
|
246 | 251 | */ |
|
247 | 252 | |
|
248 | 253 | /*! |
|
249 | 254 | \qmlsignal ChartView::seriesRemoved(AbstractSeries series) |
|
250 | 255 | The \a series has been removed from the chart. Please note that \a series is no longer a valid |
|
251 | 256 | object after the signal handler has completed. |
|
252 | 257 | */ |
|
253 | 258 | |
|
254 | 259 | DeclarativeChart::DeclarativeChart(QDECLARATIVE_ITEM *parent) |
|
255 | 260 | : QDECLARATIVE_PAINTED_ITEM(parent) |
|
256 | 261 | { |
|
257 | 262 | initChart(QChart::ChartTypeCartesian); |
|
258 | 263 | } |
|
259 | 264 | |
|
260 | 265 | DeclarativeChart::DeclarativeChart(QChart::ChartType type, QDECLARATIVE_ITEM *parent) |
|
261 | 266 | : QDECLARATIVE_PAINTED_ITEM(parent) |
|
262 | 267 | { |
|
263 | 268 | initChart(type); |
|
264 | 269 | } |
|
265 | 270 | |
|
266 | 271 | void DeclarativeChart::initChart(QChart::ChartType type) |
|
267 | 272 | { |
|
268 | 273 | #ifdef CHARTS_FOR_QUICK2 |
|
269 | 274 | m_currentSceneImage = 0; |
|
270 | 275 | m_guiThreadId = QThread::currentThreadId(); |
|
271 | 276 | m_paintThreadId = 0; |
|
272 | 277 | |
|
273 | 278 | if (type == QChart::ChartTypePolar) |
|
274 | 279 | m_chart = new QPolarChart(); |
|
275 | 280 | else |
|
276 | 281 | m_chart = new QChart(); |
|
277 | 282 | |
|
278 | 283 | m_scene = new QGraphicsScene(this); |
|
279 | 284 | m_scene->addItem(m_chart); |
|
280 | 285 | |
|
281 | 286 | setAntialiasing(QQuickItem::antialiasing()); |
|
282 | 287 | connect(m_scene, SIGNAL(changed(QList<QRectF>)), this, SLOT(sceneChanged(QList<QRectF>))); |
|
283 | 288 | connect(this, SIGNAL(antialiasingChanged(bool)), this, SLOT(handleAntialiasingChanged(bool))); |
|
284 | 289 | |
|
285 | 290 | setAcceptedMouseButtons(Qt::AllButtons); |
|
286 | 291 | setAcceptHoverEvents(true); |
|
287 | 292 | #else |
|
288 | 293 | if (type == QChart::ChartTypePolar) |
|
289 | 294 | m_chart = new QPolarChart(this); |
|
290 | 295 | else |
|
291 | 296 | m_chart = new QChart(this); |
|
292 | 297 | |
|
293 | 298 | setFlag(QGraphicsItem::ItemHasNoContents, false); |
|
294 | 299 | #endif |
|
295 | 300 | |
|
296 | 301 | m_margins = new DeclarativeMargins(this); |
|
297 | 302 | m_margins->setTop(m_chart->margins().top()); |
|
298 | 303 | m_margins->setLeft(m_chart->margins().left()); |
|
299 | 304 | m_margins->setRight(m_chart->margins().right()); |
|
300 | 305 | m_margins->setBottom(m_chart->margins().bottom()); |
|
301 | 306 | connect(m_margins, SIGNAL(topChanged(int,int,int,int)), this, SLOT(changeMinimumMargins(int,int,int,int))); |
|
302 | 307 | connect(m_margins, SIGNAL(bottomChanged(int,int,int,int)), this, SLOT(changeMinimumMargins(int,int,int,int))); |
|
303 | 308 | connect(m_margins, SIGNAL(leftChanged(int,int,int,int)), this, SLOT(changeMinimumMargins(int,int,int,int))); |
|
304 | 309 | connect(m_margins, SIGNAL(rightChanged(int,int,int,int)), this, SLOT(changeMinimumMargins(int,int,int,int))); |
|
305 | 310 | connect(m_chart->d_ptr->m_dataset, SIGNAL(seriesAdded(QAbstractSeries*)), this, SLOT(handleSeriesAdded(QAbstractSeries*))); |
|
306 | 311 | connect(m_chart->d_ptr->m_dataset, SIGNAL(seriesRemoved(QAbstractSeries*)), this, SIGNAL(seriesRemoved(QAbstractSeries*))); |
|
307 | 312 | } |
|
308 | 313 | |
|
309 | 314 | void DeclarativeChart::handleSeriesAdded(QAbstractSeries *series) |
|
310 | 315 | { |
|
311 | 316 | emit seriesAdded(series); |
|
312 | 317 | } |
|
313 | 318 | |
|
314 | 319 | void DeclarativeChart::changeMinimumMargins(int top, int bottom, int left, int right) |
|
315 | 320 | { |
|
316 | 321 | m_chart->setMargins(QMargins(left, top, right, bottom)); |
|
317 | 322 | emit minimumMarginsChanged(); |
|
318 | 323 | emit plotAreaChanged(m_chart->plotArea()); |
|
319 | 324 | } |
|
320 | 325 | |
|
321 | 326 | DeclarativeChart::~DeclarativeChart() |
|
322 | 327 | { |
|
323 | 328 | delete m_chart; |
|
324 | 329 | #ifdef CHARTS_FOR_QUICK2 |
|
325 | 330 | m_sceneImageLock.lock(); |
|
326 | 331 | delete m_currentSceneImage; |
|
327 | 332 | m_currentSceneImage = 0; |
|
328 | 333 | m_sceneImageLock.unlock(); |
|
329 | 334 | #endif |
|
330 | 335 | } |
|
331 | 336 | |
|
332 | 337 | void DeclarativeChart::childEvent(QChildEvent *event) |
|
333 | 338 | { |
|
334 | 339 | if (event->type() == QEvent::ChildAdded) { |
|
335 | 340 | if (qobject_cast<QAbstractSeries *>(event->child())) { |
|
336 | 341 | m_chart->addSeries(qobject_cast<QAbstractSeries *>(event->child())); |
|
337 | 342 | } |
|
338 | 343 | } |
|
339 | 344 | } |
|
340 | 345 | |
|
341 | 346 | void DeclarativeChart::componentComplete() |
|
342 | 347 | { |
|
343 | 348 | foreach (QObject *child, children()) { |
|
344 | 349 | if (qobject_cast<QAbstractSeries *>(child)) { |
|
345 | 350 | // Add series to the chart |
|
346 | 351 | QAbstractSeries *series = qobject_cast<QAbstractSeries *>(child); |
|
347 | 352 | m_chart->addSeries(series); |
|
348 | 353 | |
|
349 | 354 | // Connect to axis changed signals (unless this is a pie series) |
|
350 | 355 | if (!qobject_cast<DeclarativePieSeries *>(series)) { |
|
351 | 356 | connect(series, SIGNAL(axisXChanged(QAbstractAxis*)), this, SLOT(handleAxisXSet(QAbstractAxis*))); |
|
352 | 357 | connect(series, SIGNAL(axisXTopChanged(QAbstractAxis*)), this, SLOT(handleAxisXSet(QAbstractAxis*))); |
|
353 | 358 | connect(series, SIGNAL(axisYChanged(QAbstractAxis*)), this, SLOT(handleAxisYSet(QAbstractAxis*))); |
|
354 | 359 | connect(series, SIGNAL(axisYRightChanged(QAbstractAxis*)), this, SLOT(handleAxisYRightSet(QAbstractAxis*))); |
|
355 | 360 | } |
|
356 | 361 | |
|
357 | 362 | initializeAxes(series); |
|
358 | 363 | } |
|
359 | 364 | } |
|
360 | 365 | |
|
361 | 366 | QDECLARATIVE_ITEM::componentComplete(); |
|
362 | 367 | } |
|
363 | 368 | |
|
364 | 369 | void DeclarativeChart::handleAxisXSet(QAbstractAxis *axis) |
|
365 | 370 | { |
|
366 | 371 | QAbstractSeries *s = qobject_cast<QAbstractSeries *>(sender()); |
|
367 | 372 | if (axis && s) { |
|
368 | 373 | if (!m_chart->axes(Qt::Horizontal).contains(axis)) |
|
369 | 374 | m_chart->addAxis(axis, Qt::AlignBottom); |
|
370 | 375 | if (!s->attachedAxes().contains(axis)) |
|
371 | 376 | s->attachAxis(axis); |
|
372 | 377 | } else { |
|
373 | 378 | qWarning() << "Trying to set axisX to null."; |
|
374 | 379 | } |
|
375 | 380 | } |
|
376 | 381 | |
|
377 | 382 | void DeclarativeChart::handleAxisXTopSet(QAbstractAxis *axis) |
|
378 | 383 | { |
|
379 | 384 | QAbstractSeries *s = qobject_cast<QAbstractSeries *>(sender()); |
|
380 | 385 | if (axis && s) { |
|
381 | 386 | if (!m_chart->axes(Qt::Horizontal).contains(axis)) |
|
382 | 387 | m_chart->addAxis(axis, Qt::AlignTop); |
|
383 | 388 | if (!s->attachedAxes().contains(axis)) |
|
384 | 389 | s->attachAxis(axis); |
|
385 | 390 | } else { |
|
386 | 391 | qWarning() << "Trying to set axisXTop to null."; |
|
387 | 392 | } |
|
388 | 393 | } |
|
389 | 394 | |
|
390 | 395 | void DeclarativeChart::handleAxisYSet(QAbstractAxis *axis) |
|
391 | 396 | { |
|
392 | 397 | QAbstractSeries *s = qobject_cast<QAbstractSeries *>(sender()); |
|
393 | 398 | if (axis && s) { |
|
394 | 399 | if (!m_chart->axes(Qt::Vertical).contains(axis)) |
|
395 | 400 | m_chart->addAxis(axis, Qt::AlignLeft); |
|
396 | 401 | if (!s->attachedAxes().contains(axis)) |
|
397 | 402 | s->attachAxis(axis); |
|
398 | 403 | } else { |
|
399 | 404 | qWarning() << "Trying to set axisY to null."; |
|
400 | 405 | } |
|
401 | 406 | } |
|
402 | 407 | |
|
403 | 408 | void DeclarativeChart::handleAxisYRightSet(QAbstractAxis *axis) |
|
404 | 409 | { |
|
405 | 410 | QAbstractSeries *s = qobject_cast<QAbstractSeries *>(sender()); |
|
406 | 411 | if (axis && s) { |
|
407 | 412 | if (!m_chart->axes(Qt::Vertical).contains(axis)) |
|
408 | 413 | m_chart->addAxis(axis, Qt::AlignRight); |
|
409 | 414 | if (!s->attachedAxes().contains(axis)) |
|
410 | 415 | s->attachAxis(axis); |
|
411 | 416 | } else { |
|
412 | 417 | qWarning() << "Trying to set axisYRight to null."; |
|
413 | 418 | } |
|
414 | 419 | } |
|
415 | 420 | |
|
416 | 421 | void DeclarativeChart::geometryChanged(const QRectF &newGeometry, const QRectF &oldGeometry) |
|
417 | 422 | { |
|
418 | 423 | if (newGeometry.isValid()) { |
|
419 | 424 | if (newGeometry.width() > 0 && newGeometry.height() > 0) { |
|
420 | 425 | m_chart->resize(newGeometry.width(), newGeometry.height()); |
|
421 | 426 | } |
|
422 | 427 | } |
|
423 | 428 | QDECLARATIVE_ITEM::geometryChanged(newGeometry, oldGeometry); |
|
424 | 429 | |
|
425 | 430 | // It would be better to trigger the plotAreaChanged signal from QChart::plotAreaChanged or |
|
426 | 431 | // similar. Since that kind of a signal is not clearly needed in the C++ API the work-around is |
|
427 | 432 | // to implement it here for the QML API purposes. |
|
428 | 433 | emit plotAreaChanged(m_chart->plotArea()); |
|
429 | 434 | } |
|
430 | 435 | |
|
431 | 436 | #ifdef CHARTS_FOR_QUICK2 |
|
432 | 437 | void DeclarativeChart::sceneChanged(QList<QRectF> region) |
|
433 | 438 | { |
|
434 | 439 | Q_UNUSED(region); |
|
435 | 440 | |
|
436 | 441 | if (m_guiThreadId == m_paintThreadId) { |
|
437 | 442 | // Rendering in gui thread, no need for shenannigans, just update |
|
438 | 443 | update(); |
|
439 | 444 | } else { |
|
440 | 445 | // Multi-threaded rendering, need to ensure scene is actually rendered in gui thread |
|
441 | 446 | if (!m_updatePending) { |
|
442 | 447 | m_updatePending = true; |
|
443 | 448 | // Do async render to avoid some unnecessary renders. |
|
444 | 449 | QTimer::singleShot(0, this, SLOT(renderScene())); |
|
445 | 450 | } |
|
446 | 451 | } |
|
447 | 452 | } |
|
448 | 453 | |
|
449 | 454 | void DeclarativeChart::renderScene() |
|
450 | 455 | { |
|
451 | 456 | m_updatePending = false; |
|
452 | 457 | m_sceneImageLock.lock(); |
|
453 | 458 | delete m_currentSceneImage; |
|
454 | 459 | m_currentSceneImage = new QImage(m_chart->size().toSize(), QImage::Format_ARGB32); |
|
455 | 460 | m_currentSceneImage->fill(Qt::transparent); |
|
456 | 461 | QPainter painter(m_currentSceneImage); |
|
457 | 462 | if (antialiasing()) |
|
458 | 463 | painter.setRenderHints(QPainter::Antialiasing | QPainter::TextAntialiasing | QPainter::SmoothPixmapTransform); |
|
459 | 464 | QRect renderRect(QPoint(0, 0), m_chart->size().toSize()); |
|
460 | 465 | m_scene->render(&painter, renderRect, renderRect); |
|
461 | 466 | m_sceneImageLock.unlock(); |
|
462 | 467 | |
|
463 | 468 | update(); |
|
464 | 469 | } |
|
465 | 470 | |
|
466 | 471 | void DeclarativeChart::paint(QPainter *painter) |
|
467 | 472 | { |
|
468 | 473 | if (!m_paintThreadId) { |
|
469 | 474 | m_paintThreadId = QThread::currentThreadId(); |
|
470 | 475 | if (m_guiThreadId == m_paintThreadId) { |
|
471 | 476 | // No need for scene image in single threaded rendering, so delete |
|
472 | 477 | // the one that got made by default before the rendering type was |
|
473 | 478 | // detected. |
|
474 | 479 | delete m_currentSceneImage; |
|
475 | 480 | m_currentSceneImage = 0; |
|
476 | 481 | } |
|
477 | 482 | } |
|
478 | 483 | |
|
479 | 484 | if (m_guiThreadId == m_paintThreadId) { |
|
480 | 485 | QRectF renderRect(QPointF(0, 0), m_chart->size()); |
|
481 | 486 | m_scene->render(painter, renderRect, renderRect); |
|
482 | 487 | } else { |
|
483 | 488 | m_sceneImageLock.lock(); |
|
484 | 489 | if (m_currentSceneImage) { |
|
485 | 490 | QRect imageRect(QPoint(0, 0), m_currentSceneImage->size()); |
|
486 | 491 | QRect itemRect(QPoint(0, 0), QSize(width(), height())); |
|
487 | 492 | painter->drawImage(itemRect, *m_currentSceneImage, imageRect); |
|
488 | 493 | } |
|
489 | 494 | m_sceneImageLock.unlock(); |
|
490 | 495 | } |
|
491 | 496 | } |
|
492 | 497 | |
|
493 | 498 | void DeclarativeChart::mousePressEvent(QMouseEvent *event) |
|
494 | 499 | { |
|
495 | 500 | m_mousePressScenePoint = event->pos(); |
|
496 | 501 | m_mousePressScreenPoint = event->globalPos(); |
|
497 | 502 | m_lastMouseMoveScenePoint = m_mousePressScenePoint; |
|
498 | 503 | m_lastMouseMoveScreenPoint = m_mousePressScreenPoint; |
|
499 | 504 | m_mousePressButton = event->button(); |
|
500 | 505 | m_mousePressButtons = event->buttons(); |
|
501 | 506 | |
|
502 | 507 | QGraphicsSceneMouseEvent mouseEvent(QEvent::GraphicsSceneMousePress); |
|
503 | 508 | mouseEvent.setWidget(0); |
|
504 | 509 | mouseEvent.setButtonDownScenePos(m_mousePressButton, m_mousePressScenePoint); |
|
505 | 510 | mouseEvent.setButtonDownScreenPos(m_mousePressButton, m_mousePressScreenPoint); |
|
506 | 511 | mouseEvent.setScenePos(m_mousePressScenePoint); |
|
507 | 512 | mouseEvent.setScreenPos(m_mousePressScreenPoint); |
|
508 | 513 | mouseEvent.setLastScenePos(m_lastMouseMoveScenePoint); |
|
509 | 514 | mouseEvent.setLastScreenPos(m_lastMouseMoveScreenPoint); |
|
510 | 515 | mouseEvent.setButtons(m_mousePressButtons); |
|
511 | 516 | mouseEvent.setButton(m_mousePressButton); |
|
512 | 517 | mouseEvent.setModifiers(event->modifiers()); |
|
513 | 518 | mouseEvent.setAccepted(false); |
|
514 | 519 | |
|
515 | 520 | QApplication::sendEvent(m_scene, &mouseEvent); |
|
516 | 521 | } |
|
517 | 522 | |
|
518 | 523 | void DeclarativeChart::mouseReleaseEvent(QMouseEvent *event) |
|
519 | 524 | { |
|
520 | 525 | QGraphicsSceneMouseEvent mouseEvent(QEvent::GraphicsSceneMouseRelease); |
|
521 | 526 | mouseEvent.setWidget(0); |
|
522 | 527 | mouseEvent.setButtonDownScenePos(m_mousePressButton, m_mousePressScenePoint); |
|
523 | 528 | mouseEvent.setButtonDownScreenPos(m_mousePressButton, m_mousePressScreenPoint); |
|
524 | 529 | mouseEvent.setScenePos(event->pos()); |
|
525 | 530 | mouseEvent.setScreenPos(event->globalPos()); |
|
526 | 531 | mouseEvent.setLastScenePos(m_lastMouseMoveScenePoint); |
|
527 | 532 | mouseEvent.setLastScreenPos(m_lastMouseMoveScreenPoint); |
|
528 | 533 | mouseEvent.setButtons(event->buttons()); |
|
529 | 534 | mouseEvent.setButton(event->button()); |
|
530 | 535 | mouseEvent.setModifiers(event->modifiers()); |
|
531 | 536 | mouseEvent.setAccepted(false); |
|
532 | 537 | |
|
533 | 538 | QApplication::sendEvent(m_scene, &mouseEvent); |
|
534 | 539 | |
|
535 | 540 | m_mousePressButtons = event->buttons(); |
|
536 | 541 | m_mousePressButton = Qt::NoButton; |
|
537 | 542 | } |
|
538 | 543 | |
|
539 | 544 | void DeclarativeChart::hoverMoveEvent(QHoverEvent *event) |
|
540 | 545 | { |
|
541 | 546 | // Convert hover move to mouse move, since we don't seem to get actual mouse move events. |
|
542 | 547 | // QGraphicsScene generates hover events from mouse move events, so we don't need |
|
543 | 548 | // to pass hover events there. |
|
544 | 549 | QGraphicsSceneMouseEvent mouseEvent(QEvent::GraphicsSceneMouseMove); |
|
545 | 550 | mouseEvent.setWidget(0); |
|
546 | 551 | mouseEvent.setButtonDownScenePos(m_mousePressButton, m_mousePressScenePoint); |
|
547 | 552 | mouseEvent.setButtonDownScreenPos(m_mousePressButton, m_mousePressScreenPoint); |
|
548 | 553 | mouseEvent.setScenePos(event->pos()); |
|
549 | 554 | // Hover events do not have global pos in them, and the screen position doesn't seem to |
|
550 | 555 | // matter anyway in this use case, so just pass event pos instead of trying to |
|
551 | 556 | // calculate the real screen position. |
|
552 | 557 | mouseEvent.setScreenPos(event->pos()); |
|
553 | 558 | mouseEvent.setLastScenePos(m_lastMouseMoveScenePoint); |
|
554 | 559 | mouseEvent.setLastScreenPos(m_lastMouseMoveScreenPoint); |
|
555 | 560 | mouseEvent.setButtons(m_mousePressButtons); |
|
556 | 561 | mouseEvent.setButton(m_mousePressButton); |
|
557 | 562 | mouseEvent.setModifiers(event->modifiers()); |
|
558 | 563 | m_lastMouseMoveScenePoint = mouseEvent.scenePos(); |
|
559 | 564 | m_lastMouseMoveScreenPoint = mouseEvent.screenPos(); |
|
560 | 565 | mouseEvent.setAccepted(false); |
|
561 | 566 | |
|
562 | 567 | QApplication::sendEvent(m_scene, &mouseEvent); |
|
563 | 568 | } |
|
564 | 569 | |
|
565 | 570 | void DeclarativeChart::handleAntialiasingChanged(bool enable) |
|
566 | 571 | { |
|
567 | 572 | setAntialiasing(enable); |
|
568 | 573 | } |
|
569 | 574 | #endif |
|
570 | 575 | |
|
571 | 576 | void DeclarativeChart::setTheme(DeclarativeChart::Theme theme) |
|
572 | 577 | { |
|
573 | 578 | QChart::ChartTheme chartTheme = (QChart::ChartTheme) theme; |
|
574 | 579 | if (chartTheme != m_chart->theme()) |
|
575 | 580 | m_chart->setTheme(chartTheme); |
|
576 | 581 | } |
|
577 | 582 | |
|
578 | 583 | DeclarativeChart::Theme DeclarativeChart::theme() |
|
579 | 584 | { |
|
580 | 585 | return (DeclarativeChart::Theme) m_chart->theme(); |
|
581 | 586 | } |
|
582 | 587 | |
|
583 | 588 | void DeclarativeChart::setAnimationOptions(DeclarativeChart::Animation animations) |
|
584 | 589 | { |
|
585 | 590 | QChart::AnimationOption animationOptions = (QChart::AnimationOption) animations; |
|
586 | 591 | if (animationOptions != m_chart->animationOptions()) |
|
587 | 592 | m_chart->setAnimationOptions(animationOptions); |
|
588 | 593 | } |
|
589 | 594 | |
|
590 | 595 | DeclarativeChart::Animation DeclarativeChart::animationOptions() |
|
591 | 596 | { |
|
592 | 597 | if (m_chart->animationOptions().testFlag(QChart::AllAnimations)) |
|
593 | 598 | return DeclarativeChart::AllAnimations; |
|
594 | 599 | else if (m_chart->animationOptions().testFlag(QChart::GridAxisAnimations)) |
|
595 | 600 | return DeclarativeChart::GridAxisAnimations; |
|
596 | 601 | else if (m_chart->animationOptions().testFlag(QChart::SeriesAnimations)) |
|
597 | 602 | return DeclarativeChart::SeriesAnimations; |
|
598 | 603 | else |
|
599 | 604 | return DeclarativeChart::NoAnimation; |
|
600 | 605 | } |
|
601 | 606 | |
|
602 | 607 | void DeclarativeChart::setTitle(QString title) |
|
603 | 608 | { |
|
604 | 609 | if (title != m_chart->title()) |
|
605 | 610 | m_chart->setTitle(title); |
|
606 | 611 | } |
|
607 | 612 | QString DeclarativeChart::title() |
|
608 | 613 | { |
|
609 | 614 | return m_chart->title(); |
|
610 | 615 | } |
|
611 | 616 | |
|
612 | 617 | QAbstractAxis *DeclarativeChart::axisX(QAbstractSeries *series) |
|
613 | 618 | { |
|
614 | 619 | QList<QAbstractAxis *> axes = m_chart->axes(Qt::Horizontal, series); |
|
615 | 620 | if (axes.count()) |
|
616 | 621 | return axes[0]; |
|
617 | 622 | return 0; |
|
618 | 623 | } |
|
619 | 624 | |
|
620 | 625 | QAbstractAxis *DeclarativeChart::axisY(QAbstractSeries *series) |
|
621 | 626 | { |
|
622 | 627 | QList<QAbstractAxis *> axes = m_chart->axes(Qt::Vertical, series); |
|
623 | 628 | if (axes.count()) |
|
624 | 629 | return axes[0]; |
|
625 | 630 | return 0; |
|
626 | 631 | } |
|
627 | 632 | |
|
628 | 633 | QLegend *DeclarativeChart::legend() |
|
629 | 634 | { |
|
630 | 635 | return m_chart->legend(); |
|
631 | 636 | } |
|
632 | 637 | |
|
633 | 638 | void DeclarativeChart::setTitleColor(QColor color) |
|
634 | 639 | { |
|
635 | 640 | QBrush b = m_chart->titleBrush(); |
|
636 | 641 | if (color != b.color()) { |
|
637 | 642 | b.setColor(color); |
|
638 | 643 | m_chart->setTitleBrush(b); |
|
639 | 644 | emit titleColorChanged(color); |
|
640 | 645 | } |
|
641 | 646 | } |
|
642 | 647 | |
|
643 | 648 | QFont DeclarativeChart::titleFont() const |
|
644 | 649 | { |
|
645 | 650 | return m_chart->titleFont(); |
|
646 | 651 | } |
|
647 | 652 | |
|
648 | 653 | void DeclarativeChart::setTitleFont(const QFont &font) |
|
649 | 654 | { |
|
650 | 655 | m_chart->setTitleFont(font); |
|
651 | 656 | } |
|
652 | 657 | |
|
653 | 658 | QColor DeclarativeChart::titleColor() |
|
654 | 659 | { |
|
655 | 660 | return m_chart->titleBrush().color(); |
|
656 | 661 | } |
|
657 | 662 | |
|
658 | 663 | void DeclarativeChart::setBackgroundColor(QColor color) |
|
659 | 664 | { |
|
660 | 665 | QBrush b = m_chart->backgroundBrush(); |
|
661 | 666 | if (b.style() != Qt::SolidPattern || color != b.color()) { |
|
662 | 667 | b.setStyle(Qt::SolidPattern); |
|
663 | 668 | b.setColor(color); |
|
664 | 669 | m_chart->setBackgroundBrush(b); |
|
665 | 670 | emit backgroundColorChanged(); |
|
666 | 671 | } |
|
667 | 672 | } |
|
668 | 673 | |
|
669 | 674 | QColor DeclarativeChart::backgroundColor() |
|
670 | 675 | { |
|
671 | 676 | return m_chart->backgroundBrush().color(); |
|
672 | 677 | } |
|
673 | 678 | |
|
674 | 679 | void QtCommercialChart::DeclarativeChart::setPlotAreaColor(QColor color) |
|
675 | 680 | { |
|
676 | 681 | QBrush b = m_chart->plotAreaBackgroundBrush(); |
|
677 | 682 | if (b.style() != Qt::SolidPattern || color != b.color()) { |
|
678 | 683 | b.setStyle(Qt::SolidPattern); |
|
679 | 684 | b.setColor(color); |
|
680 | 685 | m_chart->setPlotAreaBackgroundBrush(b); |
|
681 | 686 | m_chart->setPlotAreaBackgroundVisible(true); |
|
682 | 687 | emit plotAreaColorChanged(); |
|
683 | 688 | } |
|
684 | 689 | } |
|
685 | 690 | |
|
686 | 691 | QColor QtCommercialChart::DeclarativeChart::plotAreaColor() |
|
687 | 692 | { |
|
688 | 693 | return m_chart->plotAreaBackgroundBrush().color(); |
|
689 | 694 | } |
|
690 | 695 | |
|
691 | 696 | int DeclarativeChart::count() |
|
692 | 697 | { |
|
693 | 698 | return m_chart->series().count(); |
|
694 | 699 | } |
|
695 | 700 | |
|
696 | 701 | void DeclarativeChart::setDropShadowEnabled(bool enabled) |
|
697 | 702 | { |
|
698 | 703 | if (enabled != m_chart->isDropShadowEnabled()) { |
|
699 | 704 | m_chart->setDropShadowEnabled(enabled); |
|
700 | 705 | dropShadowEnabledChanged(enabled); |
|
701 | 706 | } |
|
702 | 707 | } |
|
703 | 708 | |
|
704 | 709 | bool DeclarativeChart::dropShadowEnabled() |
|
705 | 710 | { |
|
706 | 711 | return m_chart->isDropShadowEnabled(); |
|
707 | 712 | } |
|
708 | 713 | |
|
714 | qreal DeclarativeChart::backgroundRoundness() const | |
|
715 | { | |
|
716 | return m_chart->backgroundRoundness(); | |
|
717 | } | |
|
718 | ||
|
719 | void DeclarativeChart::setBackgroundRoundness(qreal diameter) | |
|
720 | { | |
|
721 | if (m_chart->backgroundRoundness() != diameter) { | |
|
722 | m_chart->setBackgroundRoundness(diameter); | |
|
723 | emit backgroundRoundnessChanged(diameter); | |
|
724 | } | |
|
725 | } | |
|
726 | ||
|
709 | 727 | qreal DeclarativeChart::topMargin() |
|
710 | 728 | { |
|
711 | 729 | qWarning() << "ChartView.topMargin is deprecated. Use margins instead."; |
|
712 | 730 | return m_chart->margins().top(); |
|
713 | 731 | } |
|
714 | 732 | |
|
715 | 733 | qreal DeclarativeChart::bottomMargin() |
|
716 | 734 | { |
|
717 | 735 | qWarning() << "ChartView.bottomMargin is deprecated. Use margins instead."; |
|
718 | 736 | return m_chart->margins().bottom(); |
|
719 | 737 | } |
|
720 | 738 | |
|
721 | 739 | qreal DeclarativeChart::leftMargin() |
|
722 | 740 | { |
|
723 | 741 | qWarning() << "ChartView.leftMargin is deprecated. Use margins instead."; |
|
724 | 742 | return m_chart->margins().left(); |
|
725 | 743 | } |
|
726 | 744 | |
|
727 | 745 | qreal DeclarativeChart::rightMargin() |
|
728 | 746 | { |
|
729 | 747 | qWarning() << "ChartView.rightMargin is deprecated. Use margins instead."; |
|
730 | 748 | return m_chart->margins().right(); |
|
731 | 749 | } |
|
732 | 750 | |
|
733 | 751 | void DeclarativeChart::zoom(qreal factor) |
|
734 | 752 | { |
|
735 | 753 | m_chart->zoom(factor); |
|
736 | 754 | } |
|
737 | 755 | |
|
738 | 756 | void DeclarativeChart::scrollLeft(qreal pixels) |
|
739 | 757 | { |
|
740 | 758 | m_chart->scroll(-pixels, 0); |
|
741 | 759 | } |
|
742 | 760 | |
|
743 | 761 | void DeclarativeChart::scrollRight(qreal pixels) |
|
744 | 762 | { |
|
745 | 763 | m_chart->scroll(pixels, 0); |
|
746 | 764 | } |
|
747 | 765 | |
|
748 | 766 | void DeclarativeChart::scrollUp(qreal pixels) |
|
749 | 767 | { |
|
750 | 768 | m_chart->scroll(0, pixels); |
|
751 | 769 | } |
|
752 | 770 | |
|
753 | 771 | void DeclarativeChart::scrollDown(qreal pixels) |
|
754 | 772 | { |
|
755 | 773 | m_chart->scroll(0, -pixels); |
|
756 | 774 | } |
|
757 | 775 | |
|
758 | 776 | QDECLARATIVE_LIST_PROPERTY<QAbstractAxis> DeclarativeChart::axes() |
|
759 | 777 | { |
|
760 | 778 | return QDECLARATIVE_LIST_PROPERTY<QAbstractAxis>(this, 0, |
|
761 | 779 | &DeclarativeChart::axesAppendFunc, |
|
762 | 780 | &DeclarativeChart::axesCountFunc, |
|
763 | 781 | #ifdef CHARTS_FOR_QUICK2 |
|
764 | 782 | &DeclarativeChart::axesAtFunc, |
|
765 | 783 | &DeclarativeChart::axesClearFunc); |
|
766 | 784 | #else |
|
767 | 785 | &DeclarativeChart::axesAtFunc); |
|
768 | 786 | #endif |
|
769 | 787 | } |
|
770 | 788 | |
|
771 | 789 | void DeclarativeChart::axesAppendFunc(QDECLARATIVE_LIST_PROPERTY<QAbstractAxis> *list, QAbstractAxis *element) |
|
772 | 790 | { |
|
773 | 791 | // Empty implementation |
|
774 | 792 | Q_UNUSED(list); |
|
775 | 793 | Q_UNUSED(element); |
|
776 | 794 | } |
|
777 | 795 | |
|
778 | 796 | int DeclarativeChart::axesCountFunc(QDECLARATIVE_LIST_PROPERTY<QAbstractAxis> *list) |
|
779 | 797 | { |
|
780 | 798 | if (qobject_cast<DeclarativeChart *>(list->object)) { |
|
781 | 799 | DeclarativeChart *chart = qobject_cast<DeclarativeChart *>(list->object); |
|
782 | 800 | return chart->m_chart->axes(Qt::Horizontal | Qt::Vertical).count(); |
|
783 | 801 | } |
|
784 | 802 | return 0; |
|
785 | 803 | } |
|
786 | 804 | |
|
787 | 805 | QAbstractAxis *DeclarativeChart::axesAtFunc(QDECLARATIVE_LIST_PROPERTY<QAbstractAxis> *list, int index) |
|
788 | 806 | { |
|
789 | 807 | if (qobject_cast<DeclarativeChart *>(list->object)) { |
|
790 | 808 | DeclarativeChart *chart = qobject_cast<DeclarativeChart *>(list->object); |
|
791 | 809 | QList<QAbstractAxis *> axes = chart->m_chart->axes(Qt::Horizontal | Qt::Vertical, chart->m_chart->series()[0]); |
|
792 | 810 | return axes.at(index); |
|
793 | 811 | } |
|
794 | 812 | return 0; |
|
795 | 813 | } |
|
796 | 814 | |
|
797 | 815 | void DeclarativeChart::axesClearFunc(QDECLARATIVE_LIST_PROPERTY<QAbstractAxis> *list) |
|
798 | 816 | { |
|
799 | 817 | // Empty implementation |
|
800 | 818 | Q_UNUSED(list); |
|
801 | 819 | } |
|
802 | 820 | |
|
803 | 821 | |
|
804 | 822 | QAbstractSeries *DeclarativeChart::series(int index) |
|
805 | 823 | { |
|
806 | 824 | if (index < m_chart->series().count()) { |
|
807 | 825 | return m_chart->series().at(index); |
|
808 | 826 | } |
|
809 | 827 | return 0; |
|
810 | 828 | } |
|
811 | 829 | |
|
812 | 830 | QAbstractSeries *DeclarativeChart::series(QString seriesName) |
|
813 | 831 | { |
|
814 | 832 | foreach (QAbstractSeries *series, m_chart->series()) { |
|
815 | 833 | if (series->name() == seriesName) |
|
816 | 834 | return series; |
|
817 | 835 | } |
|
818 | 836 | return 0; |
|
819 | 837 | } |
|
820 | 838 | |
|
821 | 839 | QAbstractSeries *DeclarativeChart::createSeries(int type, QString name, QAbstractAxis *axisX, QAbstractAxis *axisY) |
|
822 | 840 | { |
|
823 | 841 | QAbstractSeries *series = 0; |
|
824 | 842 | |
|
825 | 843 | switch (type) { |
|
826 | 844 | case DeclarativeChart::SeriesTypeLine: |
|
827 | 845 | series = new DeclarativeLineSeries(); |
|
828 | 846 | break; |
|
829 | 847 | case DeclarativeChart::SeriesTypeArea: { |
|
830 | 848 | DeclarativeAreaSeries *area = new DeclarativeAreaSeries(); |
|
831 | 849 | area->setUpperSeries(new DeclarativeLineSeries()); |
|
832 | 850 | series = area; |
|
833 | 851 | break; |
|
834 | 852 | } |
|
835 | 853 | case DeclarativeChart::SeriesTypeStackedBar: |
|
836 | 854 | series = new DeclarativeStackedBarSeries(); |
|
837 | 855 | break; |
|
838 | 856 | case DeclarativeChart::SeriesTypePercentBar: |
|
839 | 857 | series = new DeclarativePercentBarSeries(); |
|
840 | 858 | break; |
|
841 | 859 | case DeclarativeChart::SeriesTypeBar: |
|
842 | 860 | series = new DeclarativeBarSeries(); |
|
843 | 861 | break; |
|
844 | 862 | case DeclarativeChart::SeriesTypeHorizontalBar: |
|
845 | 863 | series = new DeclarativeHorizontalBarSeries(); |
|
846 | 864 | break; |
|
847 | 865 | case DeclarativeChart::SeriesTypeHorizontalPercentBar: |
|
848 | 866 | series = new DeclarativeHorizontalPercentBarSeries(); |
|
849 | 867 | break; |
|
850 | 868 | case DeclarativeChart::SeriesTypeHorizontalStackedBar: |
|
851 | 869 | series = new DeclarativeHorizontalStackedBarSeries(); |
|
852 | 870 | break; |
|
853 | 871 | case DeclarativeChart::SeriesTypeBoxPlot: |
|
854 | 872 | series = new DeclarativeBoxPlotSeries(); |
|
855 | 873 | break; |
|
856 | 874 | case DeclarativeChart::SeriesTypePie: |
|
857 | 875 | series = new DeclarativePieSeries(); |
|
858 | 876 | break; |
|
859 | 877 | case DeclarativeChart::SeriesTypeScatter: |
|
860 | 878 | series = new DeclarativeScatterSeries(); |
|
861 | 879 | break; |
|
862 | 880 | case DeclarativeChart::SeriesTypeSpline: |
|
863 | 881 | series = new DeclarativeSplineSeries(); |
|
864 | 882 | break; |
|
865 | 883 | default: |
|
866 | 884 | qWarning() << "Illegal series type"; |
|
867 | 885 | } |
|
868 | 886 | |
|
869 | 887 | if (series) { |
|
870 | 888 | // Connect to axis changed signals (unless this is a pie series) |
|
871 | 889 | if (!qobject_cast<DeclarativePieSeries *>(series)) { |
|
872 | 890 | connect(series, SIGNAL(axisXChanged(QAbstractAxis*)), this, SLOT(handleAxisXSet(QAbstractAxis*))); |
|
873 | 891 | connect(series, SIGNAL(axisXTopChanged(QAbstractAxis*)), this, SLOT(handleAxisXSet(QAbstractAxis*))); |
|
874 | 892 | connect(series, SIGNAL(axisYChanged(QAbstractAxis*)), this, SLOT(handleAxisYSet(QAbstractAxis*))); |
|
875 | 893 | connect(series, SIGNAL(axisYRightChanged(QAbstractAxis*)), this, SLOT(handleAxisYRightSet(QAbstractAxis*))); |
|
876 | 894 | } |
|
877 | 895 | |
|
878 | 896 | series->setName(name); |
|
879 | 897 | m_chart->addSeries(series); |
|
880 | 898 | |
|
881 | 899 | if (axisX) |
|
882 | 900 | setAxisX(axisX, series); |
|
883 | 901 | if (axisY) |
|
884 | 902 | setAxisY(axisY, series); |
|
885 | 903 | |
|
886 | 904 | if (series->attachedAxes().count() < 2) |
|
887 | 905 | initializeAxes(series); |
|
888 | 906 | } |
|
889 | 907 | |
|
890 | 908 | return series; |
|
891 | 909 | } |
|
892 | 910 | |
|
893 | 911 | void DeclarativeChart::removeSeries(QAbstractSeries *series) |
|
894 | 912 | { |
|
895 | 913 | if (series) |
|
896 | 914 | m_chart->removeSeries(series); |
|
897 | 915 | else |
|
898 | 916 | qWarning("removeSeries: cannot remove null"); |
|
899 | 917 | } |
|
900 | 918 | |
|
901 | 919 | void DeclarativeChart::setAxisX(QAbstractAxis *axis, QAbstractSeries *series) |
|
902 | 920 | { |
|
903 | 921 | if (axis) |
|
904 | 922 | m_chart->setAxisX(axis, series); |
|
905 | 923 | } |
|
906 | 924 | |
|
907 | 925 | void DeclarativeChart::setAxisY(QAbstractAxis *axis, QAbstractSeries *series) |
|
908 | 926 | { |
|
909 | 927 | if (axis) |
|
910 | 928 | m_chart->setAxisY(axis, series); |
|
911 | 929 | } |
|
912 | 930 | |
|
913 | 931 | void DeclarativeChart::createDefaultAxes() |
|
914 | 932 | { |
|
915 | 933 | qWarning() << "ChartView.createDefaultAxes() is deprecated. Axes are created automatically."; |
|
916 | 934 | } |
|
917 | 935 | |
|
918 | 936 | QAbstractAxis *DeclarativeChart::defaultAxis(Qt::Orientation orientation, QAbstractSeries *series) |
|
919 | 937 | { |
|
920 | 938 | if (!series) { |
|
921 | 939 | qWarning() << "No axis type defined for null series"; |
|
922 | 940 | return 0; |
|
923 | 941 | } |
|
924 | 942 | |
|
925 | 943 | foreach (QAbstractAxis *existingAxis, m_chart->axes(orientation)) { |
|
926 | 944 | if (existingAxis->type() == series->d_ptr->defaultAxisType(orientation)) |
|
927 | 945 | return existingAxis; |
|
928 | 946 | } |
|
929 | 947 | |
|
930 | 948 | switch (series->d_ptr->defaultAxisType(orientation)) { |
|
931 | 949 | case QAbstractAxis::AxisTypeValue: |
|
932 | 950 | return new QValueAxis(this); |
|
933 | 951 | case QAbstractAxis::AxisTypeBarCategory: |
|
934 | 952 | return new QBarCategoryAxis(this); |
|
935 | 953 | case QAbstractAxis::AxisTypeCategory: |
|
936 | 954 | return new QCategoryAxis(this); |
|
937 | 955 | #ifndef QT_ON_ARM |
|
938 | 956 | case QAbstractAxis::AxisTypeDateTime: |
|
939 | 957 | return new QDateTimeAxis(this); |
|
940 | 958 | #endif |
|
941 | 959 | case QAbstractAxis::AxisTypeLogValue: |
|
942 | 960 | return new QLogValueAxis(this); |
|
943 | 961 | default: |
|
944 | 962 | // assume AxisTypeNoAxis |
|
945 | 963 | return 0; |
|
946 | 964 | } |
|
947 | 965 | } |
|
948 | 966 | |
|
949 | 967 | void DeclarativeChart::initializeAxes(QAbstractSeries *series) |
|
950 | 968 | { |
|
951 | 969 | if (qobject_cast<DeclarativeLineSeries *>(series)) |
|
952 | 970 | doInitializeAxes(series, qobject_cast<DeclarativeLineSeries *>(series)->m_axes); |
|
953 | 971 | else if (qobject_cast<DeclarativeScatterSeries *>(series)) |
|
954 | 972 | doInitializeAxes(series, qobject_cast<DeclarativeScatterSeries *>(series)->m_axes); |
|
955 | 973 | else if (qobject_cast<DeclarativeSplineSeries *>(series)) |
|
956 | 974 | doInitializeAxes(series, qobject_cast<DeclarativeSplineSeries *>(series)->m_axes); |
|
957 | 975 | else if (qobject_cast<DeclarativeAreaSeries *>(series)) |
|
958 | 976 | doInitializeAxes(series, qobject_cast<DeclarativeAreaSeries *>(series)->m_axes); |
|
959 | 977 | else if (qobject_cast<DeclarativeBarSeries *>(series)) |
|
960 | 978 | doInitializeAxes(series, qobject_cast<DeclarativeBarSeries *>(series)->m_axes); |
|
961 | 979 | else if (qobject_cast<DeclarativeStackedBarSeries *>(series)) |
|
962 | 980 | doInitializeAxes(series, qobject_cast<DeclarativeStackedBarSeries *>(series)->m_axes); |
|
963 | 981 | else if (qobject_cast<DeclarativePercentBarSeries *>(series)) |
|
964 | 982 | doInitializeAxes(series, qobject_cast<DeclarativePercentBarSeries *>(series)->m_axes); |
|
965 | 983 | else if (qobject_cast<DeclarativeHorizontalBarSeries *>(series)) |
|
966 | 984 | doInitializeAxes(series, qobject_cast<DeclarativeHorizontalBarSeries *>(series)->m_axes); |
|
967 | 985 | else if (qobject_cast<DeclarativeHorizontalStackedBarSeries *>(series)) |
|
968 | 986 | doInitializeAxes(series, qobject_cast<DeclarativeHorizontalStackedBarSeries *>(series)->m_axes); |
|
969 | 987 | else if (qobject_cast<DeclarativeHorizontalPercentBarSeries *>(series)) |
|
970 | 988 | doInitializeAxes(series, qobject_cast<DeclarativeHorizontalPercentBarSeries *>(series)->m_axes); |
|
971 | 989 | else if (qobject_cast<DeclarativeBoxPlotSeries *>(series)) |
|
972 | 990 | doInitializeAxes(series, qobject_cast<DeclarativeBoxPlotSeries *>(series)->m_axes); |
|
973 | 991 | // else: do nothing |
|
974 | 992 | } |
|
975 | 993 | |
|
976 | 994 | void DeclarativeChart::doInitializeAxes(QAbstractSeries *series, DeclarativeAxes *axes) |
|
977 | 995 | { |
|
978 | 996 | // Initialize axis X |
|
979 | 997 | if (axes->axisX()) |
|
980 | 998 | axes->emitAxisXChanged(); |
|
981 | 999 | else if (axes->axisXTop()) |
|
982 | 1000 | axes->emitAxisXTopChanged(); |
|
983 | 1001 | else |
|
984 | 1002 | axes->setAxisX(defaultAxis(Qt::Horizontal, series)); |
|
985 | 1003 | |
|
986 | 1004 | // Initialize axis Y |
|
987 | 1005 | if (axes->axisY()) |
|
988 | 1006 | axes->emitAxisYChanged(); |
|
989 | 1007 | else if (axes->axisYRight()) |
|
990 | 1008 | axes->emitAxisYRightChanged(); |
|
991 | 1009 | else |
|
992 | 1010 | axes->setAxisY(defaultAxis(Qt::Vertical, series)); |
|
993 | 1011 | } |
|
994 | 1012 | |
|
995 | 1013 | #include "moc_declarativechart.cpp" |
|
996 | 1014 | |
|
997 | 1015 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,230 +1,234 | |||
|
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 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 "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 | 52 | Q_PROPERTY(QLegend *legend READ legend) |
|
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 | Q_PROPERTY(qreal backgroundRoundness READ backgroundRoundness WRITE setBackgroundRoundness NOTIFY backgroundRoundnessChanged REVISION 3) | |
|
56 | 57 | Q_PROPERTY(qreal topMargin READ topMargin) |
|
57 | 58 | Q_PROPERTY(qreal bottomMargin READ bottomMargin) |
|
58 | 59 | Q_PROPERTY(qreal leftMargin READ leftMargin) |
|
59 | 60 | Q_PROPERTY(qreal rightMargin READ rightMargin) |
|
60 | 61 | Q_PROPERTY(DeclarativeMargins *minimumMargins READ minimumMargins NOTIFY minimumMarginsChanged REVISION 1) |
|
61 | 62 | Q_PROPERTY(DeclarativeMargins *margins READ margins NOTIFY marginsChanged REVISION 2) |
|
62 | 63 | Q_PROPERTY(QRectF plotArea READ plotArea NOTIFY plotAreaChanged REVISION 1) |
|
63 | 64 | Q_PROPERTY(QColor plotAreaColor READ plotAreaColor WRITE setPlotAreaColor NOTIFY plotAreaColorChanged REVISION 3) |
|
64 | 65 | #ifdef CHARTS_FOR_QUICK2 |
|
65 | 66 | Q_PROPERTY(QQmlListProperty<QAbstractAxis> axes READ axes REVISION 2) |
|
66 | 67 | #else |
|
67 | 68 | Q_PROPERTY(QDeclarativeListProperty<QAbstractAxis> axes READ axes REVISION 2) |
|
68 | 69 | #endif |
|
69 | 70 | Q_ENUMS(Animation) |
|
70 | 71 | Q_ENUMS(Theme) |
|
71 | 72 | Q_ENUMS(SeriesType) |
|
72 | 73 | |
|
73 | 74 | public: |
|
74 | 75 | // duplicating enums from QChart to make the QML api namings 1-to-1 with the C++ api |
|
75 | 76 | enum Theme { |
|
76 | 77 | ChartThemeLight = 0, |
|
77 | 78 | ChartThemeBlueCerulean, |
|
78 | 79 | ChartThemeDark, |
|
79 | 80 | ChartThemeBrownSand, |
|
80 | 81 | ChartThemeBlueNcs, |
|
81 | 82 | ChartThemeHighContrast, |
|
82 | 83 | ChartThemeBlueIcy |
|
83 | 84 | }; |
|
84 | 85 | |
|
85 | 86 | enum Animation { |
|
86 | 87 | NoAnimation = 0x0, |
|
87 | 88 | GridAxisAnimations = 0x1, |
|
88 | 89 | SeriesAnimations = 0x2, |
|
89 | 90 | AllAnimations = 0x3 |
|
90 | 91 | }; |
|
91 | 92 | |
|
92 | 93 | enum SeriesType { |
|
93 | 94 | SeriesTypeLine, |
|
94 | 95 | SeriesTypeArea, |
|
95 | 96 | SeriesTypeBar, |
|
96 | 97 | SeriesTypeStackedBar, |
|
97 | 98 | SeriesTypePercentBar, |
|
98 | 99 | SeriesTypeBoxPlot, |
|
99 | 100 | SeriesTypePie, |
|
100 | 101 | SeriesTypeScatter, |
|
101 | 102 | SeriesTypeSpline, |
|
102 | 103 | SeriesTypeHorizontalBar, |
|
103 | 104 | SeriesTypeHorizontalStackedBar, |
|
104 | 105 | SeriesTypeHorizontalPercentBar |
|
105 | 106 | }; |
|
106 | 107 | |
|
107 | 108 | public: |
|
108 | 109 | DeclarativeChart(QDECLARATIVE_ITEM *parent = 0); |
|
109 | 110 | ~DeclarativeChart(); |
|
110 | 111 | |
|
111 | 112 | public: // From parent classes |
|
112 | 113 | void childEvent(QChildEvent *event); |
|
113 | 114 | void componentComplete(); |
|
114 | 115 | void geometryChanged(const QRectF &newGeometry, const QRectF &oldGeometry); |
|
115 | 116 | #ifdef CHARTS_FOR_QUICK2 |
|
116 | 117 | void paint(QPainter *painter); |
|
117 | 118 | protected: |
|
118 | 119 | void mousePressEvent(QMouseEvent *event); |
|
119 | 120 | void mouseReleaseEvent(QMouseEvent *event); |
|
120 | 121 | void hoverMoveEvent(QHoverEvent *event); |
|
121 | 122 | private Q_SLOTS: |
|
122 | 123 | void handleAntialiasingChanged(bool enable); |
|
123 | 124 | void sceneChanged(QList<QRectF> region); |
|
124 | 125 | void renderScene(); |
|
125 | 126 | #endif |
|
126 | 127 | |
|
127 | 128 | public: |
|
128 | 129 | void setTheme(DeclarativeChart::Theme theme); |
|
129 | 130 | DeclarativeChart::Theme theme(); |
|
130 | 131 | void setAnimationOptions(DeclarativeChart::Animation animations); |
|
131 | 132 | DeclarativeChart::Animation animationOptions(); |
|
132 | 133 | void setTitle(QString title); |
|
133 | 134 | QString title(); |
|
134 | 135 | QLegend *legend(); |
|
135 | 136 | QFont titleFont() const; |
|
136 | 137 | void setTitleFont(const QFont &font); |
|
137 | 138 | void setTitleColor(QColor color); |
|
138 | 139 | QColor titleColor(); |
|
139 | 140 | void setBackgroundColor(QColor color); |
|
140 | 141 | QColor backgroundColor(); |
|
141 | 142 | Q_REVISION(3) void setPlotAreaColor(QColor color); |
|
142 | 143 | Q_REVISION(3) QColor plotAreaColor(); |
|
143 | 144 | int count(); |
|
144 | 145 | void setDropShadowEnabled(bool enabled); |
|
145 | 146 | bool dropShadowEnabled(); |
|
147 | Q_REVISION(3) qreal backgroundRoundness() const; | |
|
148 | Q_REVISION(3) void setBackgroundRoundness(qreal diameter); | |
|
146 | 149 | |
|
147 | 150 | // Margins & plotArea |
|
148 | 151 | qreal topMargin(); |
|
149 | 152 | qreal bottomMargin(); |
|
150 | 153 | qreal leftMargin(); |
|
151 | 154 | qreal rightMargin(); |
|
152 | 155 | DeclarativeMargins *minimumMargins() { return m_margins; } |
|
153 | 156 | Q_REVISION(2) DeclarativeMargins *margins() { return m_margins; } |
|
154 | 157 | QRectF plotArea() { return m_chart->plotArea(); } |
|
155 | 158 | |
|
156 | 159 | // Axis handling |
|
157 | 160 | QAbstractAxis *defaultAxis(Qt::Orientation orientation, QAbstractSeries *series); |
|
158 | 161 | void initializeAxes(QAbstractSeries *series); |
|
159 | 162 | void doInitializeAxes(QAbstractSeries *series, DeclarativeAxes *axes); |
|
160 | 163 | QDECLARATIVE_LIST_PROPERTY<QAbstractAxis> axes(); |
|
161 | 164 | static void axesAppendFunc(QDECLARATIVE_LIST_PROPERTY<QAbstractAxis> *list, QAbstractAxis *element); |
|
162 | 165 | static int axesCountFunc(QDECLARATIVE_LIST_PROPERTY<QAbstractAxis> *list); |
|
163 | 166 | static QAbstractAxis *axesAtFunc(QDECLARATIVE_LIST_PROPERTY<QAbstractAxis> *list, int index); |
|
164 | 167 | static void axesClearFunc(QDECLARATIVE_LIST_PROPERTY<QAbstractAxis> *list); |
|
165 | 168 | |
|
166 | 169 | public: |
|
167 | 170 | Q_INVOKABLE QAbstractSeries *series(int index); |
|
168 | 171 | Q_INVOKABLE QAbstractSeries *series(QString seriesName); |
|
169 | 172 | Q_INVOKABLE QAbstractSeries *createSeries(int type, QString name = "", QAbstractAxis *axisX = 0, QAbstractAxis *axisY = 0); |
|
170 | 173 | Q_INVOKABLE void removeSeries(QAbstractSeries *series); |
|
171 | 174 | Q_INVOKABLE void removeAllSeries() { m_chart->removeAllSeries(); } |
|
172 | 175 | Q_INVOKABLE void setAxisX(QAbstractAxis *axis, QAbstractSeries *series = 0); |
|
173 | 176 | Q_INVOKABLE void setAxisY(QAbstractAxis *axis, QAbstractSeries *series = 0); |
|
174 | 177 | Q_INVOKABLE void createDefaultAxes(); |
|
175 | 178 | Q_INVOKABLE QAbstractAxis *axisX(QAbstractSeries *series = 0); |
|
176 | 179 | Q_INVOKABLE QAbstractAxis *axisY(QAbstractSeries *series = 0); |
|
177 | 180 | Q_INVOKABLE void zoom(qreal factor); |
|
178 | 181 | Q_INVOKABLE void scrollLeft(qreal pixels); |
|
179 | 182 | Q_INVOKABLE void scrollRight(qreal pixels); |
|
180 | 183 | Q_INVOKABLE void scrollUp(qreal pixels); |
|
181 | 184 | Q_INVOKABLE void scrollDown(qreal pixels); |
|
182 | 185 | |
|
183 | 186 | Q_SIGNALS: |
|
184 | 187 | void axisLabelsChanged(); |
|
185 | 188 | void titleColorChanged(QColor color); |
|
186 | 189 | void backgroundColorChanged(); |
|
187 | 190 | void dropShadowEnabledChanged(bool enabled); |
|
188 | 191 | void minimumMarginsChanged(); |
|
189 | 192 | Q_REVISION(2) void marginsChanged(); |
|
190 | 193 | void plotAreaChanged(QRectF plotArea); |
|
191 | 194 | void seriesAdded(QAbstractSeries *series); |
|
192 | 195 | void seriesRemoved(QAbstractSeries *series); |
|
193 | 196 | Q_REVISION(3) void plotAreaColorChanged(); |
|
197 | Q_REVISION(3) void backgroundRoundnessChanged(qreal diameter); | |
|
194 | 198 | |
|
195 | 199 | private Q_SLOTS: |
|
196 | 200 | void changeMinimumMargins(int top, int bottom, int left, int right); |
|
197 | 201 | void handleAxisXSet(QAbstractAxis *axis); |
|
198 | 202 | void handleAxisYSet(QAbstractAxis *axis); |
|
199 | 203 | void handleAxisXTopSet(QAbstractAxis *axis); |
|
200 | 204 | void handleAxisYRightSet(QAbstractAxis *axis); |
|
201 | 205 | void handleSeriesAdded(QAbstractSeries *series); |
|
202 | 206 | |
|
203 | 207 | protected: |
|
204 | 208 | explicit DeclarativeChart(QChart::ChartType type, QDECLARATIVE_ITEM *parent); |
|
205 | 209 | |
|
206 | 210 | private: |
|
207 | 211 | void initChart(QChart::ChartType type); |
|
208 | 212 | // Extending QChart with DeclarativeChart is not possible because QObject does not support |
|
209 | 213 | // multi inheritance, so we now have a QChart as a member instead |
|
210 | 214 | QChart *m_chart; |
|
211 | 215 | #ifdef CHARTS_FOR_QUICK2 |
|
212 | 216 | QGraphicsScene *m_scene; |
|
213 | 217 | QPointF m_mousePressScenePoint; |
|
214 | 218 | QPoint m_mousePressScreenPoint; |
|
215 | 219 | QPointF m_lastMouseMoveScenePoint; |
|
216 | 220 | QPoint m_lastMouseMoveScreenPoint; |
|
217 | 221 | Qt::MouseButton m_mousePressButton; |
|
218 | 222 | Qt::MouseButtons m_mousePressButtons; |
|
219 | 223 | QMutex m_sceneImageLock; |
|
220 | 224 | QImage *m_currentSceneImage; |
|
221 | 225 | bool m_updatePending; |
|
222 | 226 | Qt::HANDLE m_paintThreadId; |
|
223 | 227 | Qt::HANDLE m_guiThreadId; |
|
224 | 228 | #endif |
|
225 | 229 | DeclarativeMargins *m_margins; |
|
226 | 230 | }; |
|
227 | 231 | |
|
228 | 232 | QTCOMMERCIALCHART_END_NAMESPACE |
|
229 | 233 | |
|
230 | 234 | #endif // DECLARATIVECHART_H |
@@ -1,101 +1,95 | |||
|
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 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 "chartbackground_p.h" |
|
22 | 22 | #include "chartconfig_p.h" |
|
23 | 23 | #include <QPen> |
|
24 | 24 | #include <QBrush> |
|
25 | 25 | #include <QPainter> |
|
26 | 26 | #include <QGraphicsDropShadowEffect> |
|
27 | 27 | |
|
28 | 28 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
29 | 29 | |
|
30 | 30 | ChartBackground::ChartBackground(QGraphicsItem *parent) |
|
31 | 31 | : QGraphicsRectItem(parent), |
|
32 |
m_diameter( |
|
|
32 | m_diameter(5), | |
|
33 | 33 | m_dropShadow(0) |
|
34 | 34 | { |
|
35 | 35 | } |
|
36 | 36 | |
|
37 | 37 | ChartBackground::~ChartBackground() |
|
38 | 38 | { |
|
39 | 39 | |
|
40 | 40 | } |
|
41 | 41 | |
|
42 | 42 | void ChartBackground::setDropShadowEnabled(bool enabled) |
|
43 | 43 | { |
|
44 | 44 | if (enabled) { |
|
45 | 45 | if (!m_dropShadow) { |
|
46 | 46 | m_dropShadow = new QGraphicsDropShadowEffect(); |
|
47 | 47 | #ifdef Q_OS_MAC |
|
48 | 48 | m_dropShadow->setBlurRadius(15); |
|
49 | 49 | m_dropShadow->setOffset(0, 0); |
|
50 | 50 | #elif defined(Q_OS_WIN) |
|
51 | 51 | m_dropShadow->setBlurRadius(10); |
|
52 | 52 | m_dropShadow->setOffset(0, 0); |
|
53 | 53 | #else |
|
54 | 54 | m_dropShadow->setBlurRadius(10); |
|
55 | 55 | m_dropShadow->setOffset(5, 5); |
|
56 | 56 | #endif |
|
57 | 57 | setGraphicsEffect(m_dropShadow); |
|
58 | 58 | } |
|
59 | 59 | } else { |
|
60 | 60 | delete m_dropShadow; |
|
61 | 61 | m_dropShadow = 0; |
|
62 | 62 | } |
|
63 | 63 | } |
|
64 | 64 | |
|
65 | 65 | void ChartBackground::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) |
|
66 | 66 | { |
|
67 | 67 | Q_UNUSED(option); |
|
68 | 68 | Q_UNUSED(widget); |
|
69 | 69 | painter->save(); |
|
70 | 70 | painter->setPen(pen()); |
|
71 | 71 | painter->setBrush(brush()); |
|
72 | painter->drawRoundRect(rect(), roundness(rect().width()), roundness(rect().height())); | |
|
72 | painter->drawRoundedRect(rect(), m_diameter, m_diameter); | |
|
73 | 73 | #ifndef QT_NO_DEBUG |
|
74 | 74 | painter->setPen(Qt::black); |
|
75 | 75 | QFont font; |
|
76 | 76 | QString build("build %1"); |
|
77 | 77 | font.setPointSize(6); |
|
78 | 78 | painter->setFont(font); |
|
79 | 79 | painter->drawText(rect().bottomLeft(), build.arg(ChartConfig::instance()->compilationTime())); |
|
80 | 80 | #endif |
|
81 | 81 | painter->restore(); |
|
82 | 82 | } |
|
83 | 83 | |
|
84 |
|
|
|
85 | { | |
|
86 | if (qFuzzyCompare(size, 0)) | |
|
87 | return 0; | |
|
88 | return 100 * m_diameter / int(size); | |
|
89 | } | |
|
90 | ||
|
91 | int ChartBackground::diameter() const | |
|
84 | qreal ChartBackground::diameter() const | |
|
92 | 85 | { |
|
93 | 86 | return m_diameter; |
|
94 | 87 | } |
|
95 | 88 | |
|
96 |
void ChartBackground::setDiameter( |
|
|
89 | void ChartBackground::setDiameter(qreal diameter) | |
|
97 | 90 | { |
|
98 | 91 | m_diameter = diameter; |
|
92 | update(); | |
|
99 | 93 | } |
|
100 | 94 | |
|
101 | 95 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,65 +1,62 | |||
|
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 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 | // W A R N I N G |
|
22 | 22 | // ------------- |
|
23 | 23 | // |
|
24 | 24 | // This file is not part of the QtCommercial Chart API. It exists purely as an |
|
25 | 25 | // implementation detail. This header file may change from version to |
|
26 | 26 | // version without notice, or even be removed. |
|
27 | 27 | // |
|
28 | 28 | // We mean it. |
|
29 | 29 | |
|
30 | 30 | #ifndef CHARTBACKGROUND_H |
|
31 | 31 | #define CHARTBACKGROUND_H |
|
32 | 32 | |
|
33 | 33 | #include "qchartglobal.h" |
|
34 | 34 | #include <QGraphicsRectItem> |
|
35 | 35 | |
|
36 | 36 | class QGraphicsDropShadowEffect; |
|
37 | 37 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
38 | 38 | |
|
39 | 39 | class ChartBackground: public QGraphicsRectItem |
|
40 | 40 | { |
|
41 | 41 | public: |
|
42 | 42 | ChartBackground(QGraphicsItem *parent = 0); |
|
43 | 43 | ~ChartBackground(); |
|
44 | 44 | |
|
45 |
void setDiameter( |
|
|
46 |
|
|
|
45 | void setDiameter(qreal diameter); | |
|
46 | qreal diameter() const; | |
|
47 | 47 | void setDropShadowEnabled(bool enabled); |
|
48 | 48 | bool isDropShadowEnabled() { return m_dropShadow != 0; } |
|
49 | 49 | |
|
50 | 50 | protected: |
|
51 | 51 | void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget); |
|
52 | 52 | |
|
53 | 53 | private: |
|
54 | int roundness(qreal size) const; | |
|
55 | ||
|
56 | private: | |
|
57 | int m_diameter; | |
|
54 | qreal m_diameter; | |
|
58 | 55 | QGraphicsDropShadowEffect *m_dropShadow; |
|
59 | 56 | }; |
|
60 | 57 | |
|
61 | 58 | QTCOMMERCIALCHART_END_NAMESPACE |
|
62 | 59 | |
|
63 | 60 | #endif /* CHARTBACKGROUND_H */ |
|
64 | 61 | |
|
65 | 62 |
@@ -1,472 +1,486 | |||
|
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 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 | #include "chartpresenter_p.h" |
|
21 | 21 | #include "qchart.h" |
|
22 | 22 | #include "chartitem_p.h" |
|
23 | 23 | #include "qchart_p.h" |
|
24 | 24 | #include "qabstractaxis.h" |
|
25 | 25 | #include "qabstractaxis_p.h" |
|
26 | 26 | #include "chartdataset_p.h" |
|
27 | 27 | #include "chartanimation_p.h" |
|
28 | 28 | #include "qabstractseries_p.h" |
|
29 | 29 | #include "qareaseries.h" |
|
30 | 30 | #include "chartaxiselement_p.h" |
|
31 | 31 | #include "chartbackground_p.h" |
|
32 | 32 | #include "cartesianchartlayout_p.h" |
|
33 | 33 | #include "polarchartlayout_p.h" |
|
34 | 34 | #include "charttitle_p.h" |
|
35 | 35 | #include <QTimer> |
|
36 | 36 | |
|
37 | 37 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
38 | 38 | |
|
39 | 39 | ChartPresenter::ChartPresenter(QChart *chart, QChart::ChartType type) |
|
40 | 40 | : QObject(chart), |
|
41 | 41 | m_chart(chart), |
|
42 | 42 | m_options(QChart::NoAnimation), |
|
43 | 43 | m_state(ShowState), |
|
44 | 44 | m_background(0), |
|
45 | 45 | m_plotAreaBackground(0), |
|
46 | 46 | m_title(0) |
|
47 | 47 | { |
|
48 | 48 | if (type == QChart::ChartTypeCartesian) |
|
49 | 49 | m_layout = new CartesianChartLayout(this); |
|
50 | 50 | else if (type == QChart::ChartTypePolar) |
|
51 | 51 | m_layout = new PolarChartLayout(this); |
|
52 | 52 | Q_ASSERT(m_layout); |
|
53 | 53 | } |
|
54 | 54 | |
|
55 | 55 | ChartPresenter::~ChartPresenter() |
|
56 | 56 | { |
|
57 | 57 | |
|
58 | 58 | } |
|
59 | 59 | |
|
60 | 60 | void ChartPresenter::setGeometry(const QRectF rect) |
|
61 | 61 | { |
|
62 | 62 | if (m_rect != rect) { |
|
63 | 63 | m_rect = rect; |
|
64 | 64 | foreach (ChartItem *chart, m_chartItems) { |
|
65 | 65 | chart->domain()->setSize(rect.size()); |
|
66 | 66 | chart->setPos(rect.topLeft()); |
|
67 | 67 | } |
|
68 | 68 | } |
|
69 | 69 | } |
|
70 | 70 | |
|
71 | 71 | QRectF ChartPresenter::geometry() const |
|
72 | 72 | { |
|
73 | 73 | return m_rect; |
|
74 | 74 | } |
|
75 | 75 | |
|
76 | 76 | void ChartPresenter::handleAxisAdded(QAbstractAxis *axis) |
|
77 | 77 | { |
|
78 | 78 | axis->d_ptr->initializeGraphics(rootItem()); |
|
79 | 79 | axis->d_ptr->initializeAnimations(m_options); |
|
80 | 80 | ChartAxisElement *item = axis->d_ptr->axisItem(); |
|
81 | 81 | item->setPresenter(this); |
|
82 | 82 | item->setThemeManager(m_chart->d_ptr->m_themeManager); |
|
83 | 83 | m_axisItems<<item; |
|
84 | 84 | m_axes<<axis; |
|
85 | 85 | m_layout->invalidate(); |
|
86 | 86 | } |
|
87 | 87 | |
|
88 | 88 | void ChartPresenter::handleAxisRemoved(QAbstractAxis *axis) |
|
89 | 89 | { |
|
90 | 90 | ChartAxisElement *item = axis->d_ptr->m_item.take(); |
|
91 | 91 | item->hide(); |
|
92 | 92 | item->disconnect(); |
|
93 | 93 | item->deleteLater(); |
|
94 | 94 | m_axisItems.removeAll(item); |
|
95 | 95 | m_axes.removeAll(axis); |
|
96 | 96 | m_layout->invalidate(); |
|
97 | 97 | } |
|
98 | 98 | |
|
99 | 99 | |
|
100 | 100 | void ChartPresenter::handleSeriesAdded(QAbstractSeries *series) |
|
101 | 101 | { |
|
102 | 102 | series->d_ptr->initializeGraphics(rootItem()); |
|
103 | 103 | series->d_ptr->initializeAnimations(m_options); |
|
104 | 104 | ChartItem *chart = series->d_ptr->chartItem(); |
|
105 | 105 | chart->setPresenter(this); |
|
106 | 106 | chart->setThemeManager(m_chart->d_ptr->m_themeManager); |
|
107 | 107 | chart->domain()->setSize(m_rect.size()); |
|
108 | 108 | chart->setPos(m_rect.topLeft()); |
|
109 | 109 | chart->handleDomainUpdated(); //this could be moved to intializeGraphics when animator is refactored |
|
110 | 110 | m_chartItems<<chart; |
|
111 | 111 | m_series<<series; |
|
112 | 112 | m_layout->invalidate(); |
|
113 | 113 | } |
|
114 | 114 | |
|
115 | 115 | void ChartPresenter::handleSeriesRemoved(QAbstractSeries *series) |
|
116 | 116 | { |
|
117 | 117 | ChartItem *chart = series->d_ptr->m_item.take(); |
|
118 | 118 | chart->hide(); |
|
119 | 119 | chart->disconnect(); |
|
120 | 120 | chart->deleteLater(); |
|
121 | 121 | m_chartItems.removeAll(chart); |
|
122 | 122 | m_series.removeAll(series); |
|
123 | 123 | m_layout->invalidate(); |
|
124 | 124 | } |
|
125 | 125 | |
|
126 | 126 | void ChartPresenter::setAnimationOptions(QChart::AnimationOptions options) |
|
127 | 127 | { |
|
128 | 128 | if (m_options != options) { |
|
129 | 129 | m_options = options; |
|
130 | 130 | |
|
131 | 131 | foreach(QAbstractSeries* series, m_series){ |
|
132 | 132 | series->d_ptr->initializeAnimations(m_options); |
|
133 | 133 | } |
|
134 | 134 | foreach(QAbstractAxis* axis, m_axes){ |
|
135 | 135 | axis->d_ptr->initializeAnimations(m_options); |
|
136 | 136 | } |
|
137 | 137 | } |
|
138 | 138 | } |
|
139 | 139 | |
|
140 | 140 | void ChartPresenter::setState(State state,QPointF point) |
|
141 | 141 | { |
|
142 | 142 | m_state=state; |
|
143 | 143 | m_statePoint=point; |
|
144 | 144 | } |
|
145 | 145 | |
|
146 | 146 | QChart::AnimationOptions ChartPresenter::animationOptions() const |
|
147 | 147 | { |
|
148 | 148 | return m_options; |
|
149 | 149 | } |
|
150 | 150 | |
|
151 | 151 | void ChartPresenter::createBackgroundItem() |
|
152 | 152 | { |
|
153 | 153 | if (!m_background) { |
|
154 | 154 | m_background = new ChartBackground(rootItem()); |
|
155 | 155 | m_background->setPen(Qt::NoPen); // Theme doesn't touch pen so don't use default |
|
156 | 156 | m_background->setBrush(QChartPrivate::defaultBrush()); |
|
157 | 157 | m_background->setZValue(ChartPresenter::BackgroundZValue); |
|
158 | 158 | } |
|
159 | 159 | } |
|
160 | 160 | |
|
161 | 161 | void ChartPresenter::createPlotAreaBackgroundItem() |
|
162 | 162 | { |
|
163 | 163 | if (!m_plotAreaBackground) { |
|
164 | 164 | if (m_chart->chartType() == QChart::ChartTypeCartesian) |
|
165 | 165 | m_plotAreaBackground = new QGraphicsRectItem(rootItem()); |
|
166 | 166 | else |
|
167 | 167 | m_plotAreaBackground = new QGraphicsEllipseItem(rootItem()); |
|
168 | 168 | // Use transparent pen instead of Qt::NoPen, as Qt::NoPen causes |
|
169 | 169 | // antialising artifacts with axis lines for some reason. |
|
170 | 170 | m_plotAreaBackground->setPen(QPen(Qt::transparent)); |
|
171 | 171 | m_plotAreaBackground->setBrush(Qt::NoBrush); |
|
172 | 172 | m_plotAreaBackground->setZValue(ChartPresenter::PlotAreaZValue); |
|
173 | 173 | m_plotAreaBackground->setVisible(false); |
|
174 | 174 | } |
|
175 | 175 | } |
|
176 | 176 | |
|
177 | 177 | void ChartPresenter::createTitleItem() |
|
178 | 178 | { |
|
179 | 179 | if (!m_title) { |
|
180 | 180 | m_title = new ChartTitle(rootItem()); |
|
181 | 181 | m_title->setZValue(ChartPresenter::BackgroundZValue); |
|
182 | 182 | } |
|
183 | 183 | } |
|
184 | 184 | |
|
185 | 185 | |
|
186 | 186 | void ChartPresenter::handleAnimationFinished() |
|
187 | 187 | { |
|
188 | 188 | m_animations.removeAll(qobject_cast<ChartAnimation *>(sender())); |
|
189 | 189 | if (m_animations.empty()) |
|
190 | 190 | emit animationsFinished(); |
|
191 | 191 | } |
|
192 | 192 | |
|
193 | 193 | void ChartPresenter::startAnimation(ChartAnimation *animation) |
|
194 | 194 | { |
|
195 | 195 | if (animation->state() != QAbstractAnimation::Stopped) animation->stop(); |
|
196 | 196 | QObject::connect(animation, SIGNAL(finished()), this, SLOT(handleAnimationFinished()), Qt::UniqueConnection); |
|
197 | 197 | if (!m_animations.isEmpty()) |
|
198 | 198 | m_animations.append(animation); |
|
199 | 199 | QTimer::singleShot(0, animation, SLOT(start())); |
|
200 | 200 | } |
|
201 | 201 | |
|
202 | 202 | void ChartPresenter::setBackgroundBrush(const QBrush &brush) |
|
203 | 203 | { |
|
204 | 204 | createBackgroundItem(); |
|
205 | 205 | m_background->setBrush(brush); |
|
206 | 206 | m_layout->invalidate(); |
|
207 | 207 | } |
|
208 | 208 | |
|
209 | 209 | QBrush ChartPresenter::backgroundBrush() const |
|
210 | 210 | { |
|
211 | 211 | if (!m_background) |
|
212 | 212 | return QBrush(); |
|
213 | 213 | return m_background->brush(); |
|
214 | 214 | } |
|
215 | 215 | |
|
216 | 216 | void ChartPresenter::setBackgroundPen(const QPen &pen) |
|
217 | 217 | { |
|
218 | 218 | createBackgroundItem(); |
|
219 | 219 | m_background->setPen(pen); |
|
220 | 220 | m_layout->invalidate(); |
|
221 | 221 | } |
|
222 | 222 | |
|
223 | 223 | QPen ChartPresenter::backgroundPen() const |
|
224 | 224 | { |
|
225 | 225 | if (!m_background) |
|
226 | 226 | return QPen(); |
|
227 | 227 | return m_background->pen(); |
|
228 | 228 | } |
|
229 | 229 | |
|
230 | void ChartPresenter::setBackgroundRoundness(qreal diameter) | |
|
231 | { | |
|
232 | createBackgroundItem(); | |
|
233 | m_background->setDiameter(diameter); | |
|
234 | m_layout->invalidate(); | |
|
235 | } | |
|
236 | ||
|
237 | qreal ChartPresenter::backgroundRoundness() const | |
|
238 | { | |
|
239 | if (!m_background) | |
|
240 | return 0; | |
|
241 | return m_background->diameter(); | |
|
242 | } | |
|
243 | ||
|
230 | 244 | void ChartPresenter::setPlotAreaBackgroundBrush(const QBrush &brush) |
|
231 | 245 | { |
|
232 | 246 | createPlotAreaBackgroundItem(); |
|
233 | 247 | m_plotAreaBackground->setBrush(brush); |
|
234 | 248 | m_layout->invalidate(); |
|
235 | 249 | } |
|
236 | 250 | |
|
237 | 251 | QBrush ChartPresenter::plotAreaBackgroundBrush() const |
|
238 | 252 | { |
|
239 | 253 | if (!m_plotAreaBackground) |
|
240 | 254 | return QBrush(); |
|
241 | 255 | return m_plotAreaBackground->brush(); |
|
242 | 256 | } |
|
243 | 257 | |
|
244 | 258 | void ChartPresenter::setPlotAreaBackgroundPen(const QPen &pen) |
|
245 | 259 | { |
|
246 | 260 | createPlotAreaBackgroundItem(); |
|
247 | 261 | m_plotAreaBackground->setPen(pen); |
|
248 | 262 | m_layout->invalidate(); |
|
249 | 263 | } |
|
250 | 264 | |
|
251 | 265 | QPen ChartPresenter::plotAreaBackgroundPen() const |
|
252 | 266 | { |
|
253 | 267 | if (!m_plotAreaBackground) |
|
254 | 268 | return QPen(); |
|
255 | 269 | return m_plotAreaBackground->pen(); |
|
256 | 270 | } |
|
257 | 271 | |
|
258 | 272 | void ChartPresenter::setTitle(const QString &title) |
|
259 | 273 | { |
|
260 | 274 | createTitleItem(); |
|
261 | 275 | m_title->setText(title); |
|
262 | 276 | m_layout->invalidate(); |
|
263 | 277 | } |
|
264 | 278 | |
|
265 | 279 | QString ChartPresenter::title() const |
|
266 | 280 | { |
|
267 | 281 | if (!m_title) |
|
268 | 282 | return QString(); |
|
269 | 283 | return m_title->text(); |
|
270 | 284 | } |
|
271 | 285 | |
|
272 | 286 | void ChartPresenter::setTitleFont(const QFont &font) |
|
273 | 287 | { |
|
274 | 288 | createTitleItem(); |
|
275 | 289 | m_title->setFont(font); |
|
276 | 290 | m_layout->invalidate(); |
|
277 | 291 | } |
|
278 | 292 | |
|
279 | 293 | QFont ChartPresenter::titleFont() const |
|
280 | 294 | { |
|
281 | 295 | if (!m_title) |
|
282 | 296 | return QFont(); |
|
283 | 297 | return m_title->font(); |
|
284 | 298 | } |
|
285 | 299 | |
|
286 | 300 | void ChartPresenter::setTitleBrush(const QBrush &brush) |
|
287 | 301 | { |
|
288 | 302 | createTitleItem(); |
|
289 | 303 | m_title->setDefaultTextColor(brush.color()); |
|
290 | 304 | m_layout->invalidate(); |
|
291 | 305 | } |
|
292 | 306 | |
|
293 | 307 | QBrush ChartPresenter::titleBrush() const |
|
294 | 308 | { |
|
295 | 309 | if (!m_title) |
|
296 | 310 | return QBrush(); |
|
297 | 311 | return QBrush(m_title->defaultTextColor()); |
|
298 | 312 | } |
|
299 | 313 | |
|
300 | 314 | void ChartPresenter::setBackgroundVisible(bool visible) |
|
301 | 315 | { |
|
302 | 316 | createBackgroundItem(); |
|
303 | 317 | m_background->setVisible(visible); |
|
304 | 318 | } |
|
305 | 319 | |
|
306 | 320 | |
|
307 | 321 | bool ChartPresenter::isBackgroundVisible() const |
|
308 | 322 | { |
|
309 | 323 | if (!m_background) |
|
310 | 324 | return false; |
|
311 | 325 | return m_background->isVisible(); |
|
312 | 326 | } |
|
313 | 327 | |
|
314 | 328 | void ChartPresenter::setPlotAreaBackgroundVisible(bool visible) |
|
315 | 329 | { |
|
316 | 330 | createPlotAreaBackgroundItem(); |
|
317 | 331 | m_plotAreaBackground->setVisible(visible); |
|
318 | 332 | } |
|
319 | 333 | |
|
320 | 334 | bool ChartPresenter::isPlotAreaBackgroundVisible() const |
|
321 | 335 | { |
|
322 | 336 | if (!m_plotAreaBackground) |
|
323 | 337 | return false; |
|
324 | 338 | return m_plotAreaBackground->isVisible(); |
|
325 | 339 | } |
|
326 | 340 | |
|
327 | 341 | void ChartPresenter::setBackgroundDropShadowEnabled(bool enabled) |
|
328 | 342 | { |
|
329 | 343 | createBackgroundItem(); |
|
330 | 344 | m_background->setDropShadowEnabled(enabled); |
|
331 | 345 | } |
|
332 | 346 | |
|
333 | 347 | bool ChartPresenter::isBackgroundDropShadowEnabled() const |
|
334 | 348 | { |
|
335 | 349 | if (!m_background) |
|
336 | 350 | return false; |
|
337 | 351 | return m_background->isDropShadowEnabled(); |
|
338 | 352 | } |
|
339 | 353 | |
|
340 | 354 | |
|
341 | 355 | AbstractChartLayout *ChartPresenter::layout() |
|
342 | 356 | { |
|
343 | 357 | return m_layout; |
|
344 | 358 | } |
|
345 | 359 | |
|
346 | 360 | QLegend *ChartPresenter::legend() |
|
347 | 361 | { |
|
348 | 362 | return m_chart->legend(); |
|
349 | 363 | } |
|
350 | 364 | |
|
351 | 365 | void ChartPresenter::setVisible(bool visible) |
|
352 | 366 | { |
|
353 | 367 | m_chart->setVisible(visible); |
|
354 | 368 | } |
|
355 | 369 | |
|
356 | 370 | ChartBackground *ChartPresenter::backgroundElement() |
|
357 | 371 | { |
|
358 | 372 | return m_background; |
|
359 | 373 | } |
|
360 | 374 | |
|
361 | 375 | QAbstractGraphicsShapeItem *ChartPresenter::plotAreaElement() |
|
362 | 376 | { |
|
363 | 377 | return m_plotAreaBackground; |
|
364 | 378 | } |
|
365 | 379 | |
|
366 | 380 | QList<ChartAxisElement *> ChartPresenter::axisItems() const |
|
367 | 381 | { |
|
368 | 382 | return m_axisItems; |
|
369 | 383 | } |
|
370 | 384 | |
|
371 | 385 | QList<ChartItem *> ChartPresenter::chartItems() const |
|
372 | 386 | { |
|
373 | 387 | return m_chartItems; |
|
374 | 388 | } |
|
375 | 389 | |
|
376 | 390 | ChartTitle *ChartPresenter::titleElement() |
|
377 | 391 | { |
|
378 | 392 | return m_title; |
|
379 | 393 | } |
|
380 | 394 | |
|
381 | 395 | QRectF ChartPresenter::textBoundingRect(const QFont &font, const QString &text, qreal angle) |
|
382 | 396 | { |
|
383 | 397 | static QGraphicsTextItem dummyTextItem; |
|
384 | 398 | |
|
385 | 399 | dummyTextItem.setFont(font); |
|
386 | 400 | dummyTextItem.setHtml(text); |
|
387 | 401 | QRectF boundingRect = dummyTextItem.boundingRect(); |
|
388 | 402 | |
|
389 | 403 | // Take rotation into account |
|
390 | 404 | if (angle) { |
|
391 | 405 | QTransform transform; |
|
392 | 406 | transform.rotate(angle); |
|
393 | 407 | boundingRect = transform.mapRect(boundingRect); |
|
394 | 408 | } |
|
395 | 409 | |
|
396 | 410 | return boundingRect; |
|
397 | 411 | } |
|
398 | 412 | |
|
399 | 413 | // boundingRect parameter returns the rotated bounding rect of the text |
|
400 | 414 | QString ChartPresenter::truncatedText(const QFont &font, const QString &text, qreal angle, |
|
401 | 415 | qreal maxSize, Qt::Orientation constraintOrientation, |
|
402 | 416 | QRectF &boundingRect) |
|
403 | 417 | { |
|
404 | 418 | QString truncatedString(text); |
|
405 | 419 | boundingRect = textBoundingRect(font, truncatedString, angle); |
|
406 | 420 | qreal checkDimension = ((constraintOrientation == Qt::Horizontal) |
|
407 | 421 | ? boundingRect.width() : boundingRect.height()); |
|
408 | 422 | if (checkDimension > maxSize) { |
|
409 | 423 | // It can be assumed that almost any amount of string manipulation is faster |
|
410 | 424 | // than calculating one bounding rectangle, so first prepare a list of truncated strings |
|
411 | 425 | // to try. |
|
412 | 426 | static const char *truncateMatchString = "&#?[0-9a-zA-Z]*;$"; |
|
413 | 427 | static QRegExp truncateMatcher(truncateMatchString); |
|
414 | 428 | |
|
415 | 429 | QVector<QString> testStrings(text.length()); |
|
416 | 430 | int count(0); |
|
417 | 431 | static QLatin1Char closeTag('>'); |
|
418 | 432 | static QLatin1Char openTag('<'); |
|
419 | 433 | static QLatin1Char semiColon(';'); |
|
420 | 434 | static QLatin1String ellipsis("..."); |
|
421 | 435 | while (truncatedString.length() > 1) { |
|
422 | 436 | int chopIndex(-1); |
|
423 | 437 | int chopCount(1); |
|
424 | 438 | QChar lastChar(truncatedString.at(truncatedString.length() - 1)); |
|
425 | 439 | |
|
426 | 440 | if (lastChar == closeTag) |
|
427 | 441 | chopIndex = truncatedString.lastIndexOf(openTag); |
|
428 | 442 | else if (lastChar == semiColon) |
|
429 | 443 | chopIndex = truncateMatcher.indexIn(truncatedString, 0); |
|
430 | 444 | |
|
431 | 445 | if (chopIndex != -1) |
|
432 | 446 | chopCount = truncatedString.length() - chopIndex; |
|
433 | 447 | truncatedString.chop(chopCount); |
|
434 | 448 | testStrings[count] = truncatedString + ellipsis; |
|
435 | 449 | count++; |
|
436 | 450 | } |
|
437 | 451 | |
|
438 | 452 | // Binary search for best fit |
|
439 | 453 | int minIndex(0); |
|
440 | 454 | int maxIndex(count - 1); |
|
441 | 455 | int bestIndex(count); |
|
442 | 456 | QRectF checkRect; |
|
443 | 457 | while (maxIndex >= minIndex) { |
|
444 | 458 | int mid = (maxIndex + minIndex) / 2; |
|
445 | 459 | checkRect = textBoundingRect(font, testStrings.at(mid), angle); |
|
446 | 460 | checkDimension = ((constraintOrientation == Qt::Horizontal) |
|
447 | 461 | ? checkRect.width() : checkRect.height()); |
|
448 | 462 | if (checkDimension > maxSize) { |
|
449 | 463 | // Checked index too large, all under this are also too large |
|
450 | 464 | minIndex = mid + 1; |
|
451 | 465 | } else { |
|
452 | 466 | // Checked index fits, all over this also fit |
|
453 | 467 | maxIndex = mid - 1; |
|
454 | 468 | bestIndex = mid; |
|
455 | 469 | boundingRect = checkRect; |
|
456 | 470 | } |
|
457 | 471 | } |
|
458 | 472 | // Default to "..." if nothing fits |
|
459 | 473 | if (bestIndex == count) { |
|
460 | 474 | boundingRect = textBoundingRect(font, ellipsis, angle); |
|
461 | 475 | truncatedString = ellipsis; |
|
462 | 476 | } else { |
|
463 | 477 | truncatedString = testStrings.at(bestIndex); |
|
464 | 478 | } |
|
465 | 479 | } |
|
466 | 480 | |
|
467 | 481 | return truncatedString; |
|
468 | 482 | } |
|
469 | 483 | |
|
470 | 484 | #include "moc_chartpresenter_p.cpp" |
|
471 | 485 | |
|
472 | 486 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,184 +1,187 | |||
|
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 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 | // W A R N I N G |
|
22 | 22 | // ------------- |
|
23 | 23 | // |
|
24 | 24 | // This file is not part of the QtCommercial Chart API. It exists purely as an |
|
25 | 25 | // implementation detail. This header file may change from version to |
|
26 | 26 | // version without notice, or even be removed. |
|
27 | 27 | // |
|
28 | 28 | // We mean it. |
|
29 | 29 | |
|
30 | 30 | #ifndef CHARTPRESENTER_H |
|
31 | 31 | #define CHARTPRESENTER_H |
|
32 | 32 | |
|
33 | 33 | #include "qchartglobal.h" |
|
34 | 34 | #include "qchart.h" //because of QChart::ChartThemeId |
|
35 | 35 | #include <QRectF> |
|
36 | 36 | #include <QMargins> |
|
37 | 37 | |
|
38 | 38 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
39 | 39 | |
|
40 | 40 | class ChartItem; |
|
41 | 41 | class AxisItem; |
|
42 | 42 | class QAbstractSeries; |
|
43 | 43 | class ChartDataSet; |
|
44 | 44 | class AbstractDomain; |
|
45 | 45 | class ChartAxisElement; |
|
46 | 46 | class ChartAnimator; |
|
47 | 47 | class ChartBackground; |
|
48 | 48 | class ChartTitle; |
|
49 | 49 | class ChartAnimation; |
|
50 | 50 | class AbstractChartLayout; |
|
51 | 51 | |
|
52 | 52 | class ChartPresenter: public QObject |
|
53 | 53 | { |
|
54 | 54 | Q_OBJECT |
|
55 | 55 | public: |
|
56 | 56 | enum ZValues { |
|
57 | 57 | BackgroundZValue = -1, |
|
58 | 58 | PlotAreaZValue, |
|
59 | 59 | ShadesZValue, |
|
60 | 60 | GridZValue, |
|
61 | 61 | AxisZValue, |
|
62 | 62 | SeriesZValue, |
|
63 | 63 | LineChartZValue = SeriesZValue, |
|
64 | 64 | SplineChartZValue = SeriesZValue, |
|
65 | 65 | BarSeriesZValue = SeriesZValue, |
|
66 | 66 | ScatterSeriesZValue = SeriesZValue, |
|
67 | 67 | PieSeriesZValue = SeriesZValue, |
|
68 | 68 | BoxPlotSeriesZValue = SeriesZValue, |
|
69 | 69 | LegendZValue, |
|
70 | 70 | TopMostZValue |
|
71 | 71 | }; |
|
72 | 72 | |
|
73 | 73 | enum State { |
|
74 | 74 | ShowState, |
|
75 | 75 | ScrollUpState, |
|
76 | 76 | ScrollDownState, |
|
77 | 77 | ScrollLeftState, |
|
78 | 78 | ScrollRightState, |
|
79 | 79 | ZoomInState, |
|
80 | 80 | ZoomOutState |
|
81 | 81 | }; |
|
82 | 82 | |
|
83 | 83 | ChartPresenter(QChart *chart, QChart::ChartType type); |
|
84 | 84 | virtual ~ChartPresenter(); |
|
85 | 85 | |
|
86 | 86 | |
|
87 | 87 | void setGeometry(QRectF rect); |
|
88 | 88 | QRectF geometry() const; |
|
89 | 89 | |
|
90 | 90 | QGraphicsItem *rootItem(){ return m_chart; } |
|
91 | 91 | ChartBackground *backgroundElement(); |
|
92 | 92 | QAbstractGraphicsShapeItem *plotAreaElement(); |
|
93 | 93 | ChartTitle *titleElement(); |
|
94 | 94 | QList<ChartAxisElement *> axisItems() const; |
|
95 | 95 | QList<ChartItem *> chartItems() const; |
|
96 | 96 | |
|
97 | 97 | QLegend *legend(); |
|
98 | 98 | |
|
99 | 99 | void setBackgroundBrush(const QBrush &brush); |
|
100 | 100 | QBrush backgroundBrush() const; |
|
101 | 101 | |
|
102 | 102 | void setBackgroundPen(const QPen &pen); |
|
103 | 103 | QPen backgroundPen() const; |
|
104 | 104 | |
|
105 | void setBackgroundRoundness(qreal diameter); | |
|
106 | qreal backgroundRoundness() const; | |
|
107 | ||
|
105 | 108 | void setPlotAreaBackgroundBrush(const QBrush &brush); |
|
106 | 109 | QBrush plotAreaBackgroundBrush() const; |
|
107 | 110 | |
|
108 | 111 | void setPlotAreaBackgroundPen(const QPen &pen); |
|
109 | 112 | QPen plotAreaBackgroundPen() const; |
|
110 | 113 | |
|
111 | 114 | void setTitle(const QString &title); |
|
112 | 115 | QString title() const; |
|
113 | 116 | |
|
114 | 117 | void setTitleFont(const QFont &font); |
|
115 | 118 | QFont titleFont() const; |
|
116 | 119 | |
|
117 | 120 | void setTitleBrush(const QBrush &brush); |
|
118 | 121 | QBrush titleBrush() const; |
|
119 | 122 | |
|
120 | 123 | void setBackgroundVisible(bool visible); |
|
121 | 124 | bool isBackgroundVisible() const; |
|
122 | 125 | |
|
123 | 126 | void setPlotAreaBackgroundVisible(bool visible); |
|
124 | 127 | bool isPlotAreaBackgroundVisible() const; |
|
125 | 128 | |
|
126 | 129 | void setBackgroundDropShadowEnabled(bool enabled); |
|
127 | 130 | bool isBackgroundDropShadowEnabled() const; |
|
128 | 131 | |
|
129 | 132 | void setVisible(bool visible); |
|
130 | 133 | |
|
131 | 134 | void setAnimationOptions(QChart::AnimationOptions options); |
|
132 | 135 | QChart::AnimationOptions animationOptions() const; |
|
133 | 136 | |
|
134 | 137 | void startAnimation(ChartAnimation *animation); |
|
135 | 138 | |
|
136 | 139 | //TODO refactor |
|
137 | 140 | void setState(State state,QPointF point); |
|
138 | 141 | State state() const { return m_state; } |
|
139 | 142 | QPointF statePoint() const { return m_statePoint; } |
|
140 | 143 | AbstractChartLayout *layout(); |
|
141 | 144 | |
|
142 | 145 | QChart::ChartType chartType() const { return m_chart->chartType(); } |
|
143 | 146 | QChart *chart() { return m_chart; } |
|
144 | 147 | |
|
145 | 148 | static QRectF textBoundingRect(const QFont &font, const QString &text, qreal angle = 0.0); |
|
146 | 149 | static QString truncatedText(const QFont &font, const QString &text, qreal angle, qreal maxSize, |
|
147 | 150 | Qt::Orientation constraintOrientation, QRectF &boundingRect); |
|
148 | 151 | private: |
|
149 | 152 | void createBackgroundItem(); |
|
150 | 153 | void createPlotAreaBackgroundItem(); |
|
151 | 154 | void createTitleItem(); |
|
152 | 155 | |
|
153 | 156 | public Q_SLOTS: |
|
154 | 157 | void handleSeriesAdded(QAbstractSeries *series); |
|
155 | 158 | void handleSeriesRemoved(QAbstractSeries *series); |
|
156 | 159 | void handleAxisAdded(QAbstractAxis *axis); |
|
157 | 160 | void handleAxisRemoved(QAbstractAxis *axis); |
|
158 | 161 | |
|
159 | 162 | private Q_SLOTS: |
|
160 | 163 | void handleAnimationFinished(); |
|
161 | 164 | |
|
162 | 165 | Q_SIGNALS: |
|
163 | 166 | void animationsFinished(); |
|
164 | 167 | |
|
165 | 168 | private: |
|
166 | 169 | QChart *m_chart; |
|
167 | 170 | QList<ChartItem *> m_chartItems; |
|
168 | 171 | QList<ChartAxisElement *> m_axisItems; |
|
169 | 172 | QList<QAbstractSeries *> m_series; |
|
170 | 173 | QList<QAbstractAxis *> m_axes; |
|
171 | 174 | QChart::AnimationOptions m_options; |
|
172 | 175 | State m_state; |
|
173 | 176 | QPointF m_statePoint; |
|
174 | 177 | QList<ChartAnimation *> m_animations; |
|
175 | 178 | AbstractChartLayout *m_layout; |
|
176 | 179 | ChartBackground *m_background; |
|
177 | 180 | QAbstractGraphicsShapeItem *m_plotAreaBackground; |
|
178 | 181 | ChartTitle *m_title; |
|
179 | 182 | QRectF m_rect; |
|
180 | 183 | }; |
|
181 | 184 | |
|
182 | 185 | QTCOMMERCIALCHART_END_NAMESPACE |
|
183 | 186 | |
|
184 | 187 | #endif /* CHARTPRESENTER_H */ |
@@ -1,811 +1,826 | |||
|
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 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 "qchart.h" |
|
22 | 22 | #include "qchart_p.h" |
|
23 | 23 | #include "legendscroller_p.h" |
|
24 | 24 | #include "qlegend_p.h" |
|
25 | 25 | #include "chartbackground_p.h" |
|
26 | 26 | #include "qabstractaxis.h" |
|
27 | 27 | #include "abstractchartlayout_p.h" |
|
28 | 28 | #include "charttheme_p.h" |
|
29 | 29 | #include "chartpresenter_p.h" |
|
30 | 30 | #include "chartdataset_p.h" |
|
31 | 31 | #include <QGraphicsScene> |
|
32 | 32 | #include <QGraphicsSceneResizeEvent> |
|
33 | 33 | |
|
34 | 34 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
35 | 35 | |
|
36 | 36 | /*! |
|
37 | 37 | \enum QChart::ChartTheme |
|
38 | 38 | |
|
39 | 39 | This enum describes the theme used by the chart. |
|
40 | 40 | |
|
41 | 41 | \value ChartThemeLight The default theme |
|
42 | 42 | \value ChartThemeBlueCerulean |
|
43 | 43 | \value ChartThemeDark |
|
44 | 44 | \value ChartThemeBrownSand |
|
45 | 45 | \value ChartThemeBlueNcs |
|
46 | 46 | \value ChartThemeHighContrast |
|
47 | 47 | \value ChartThemeBlueIcy |
|
48 | 48 | */ |
|
49 | 49 | |
|
50 | 50 | /*! |
|
51 | 51 | \enum QChart::AnimationOption |
|
52 | 52 | |
|
53 | 53 | For enabling/disabling animations. Defaults to NoAnimation. |
|
54 | 54 | |
|
55 | 55 | \value NoAnimation |
|
56 | 56 | \value GridAxisAnimations |
|
57 | 57 | \value SeriesAnimations |
|
58 | 58 | \value AllAnimations |
|
59 | 59 | */ |
|
60 | 60 | |
|
61 | 61 | /*! |
|
62 | 62 | \enum QChart::ChartType |
|
63 | 63 | |
|
64 | 64 | This enum describes the chart type. |
|
65 | 65 | |
|
66 | 66 | \value ChartTypeUndefined |
|
67 | 67 | \value ChartTypeCartesian |
|
68 | 68 | \value ChartTypePolar |
|
69 | 69 | */ |
|
70 | 70 | |
|
71 | 71 | /*! |
|
72 | 72 | \class QChart |
|
73 | 73 | \brief QtCommercial chart API. |
|
74 | 74 | |
|
75 | 75 | QChart is a QGraphicsWidget that you can show in a QGraphicsScene. It manages the graphical |
|
76 | 76 | representation of different types of series and other chart related objects like legend and |
|
77 | 77 | axes. If you simply want to show a chart in a layout, you can use the |
|
78 | 78 | convenience class QChartView instead of QChart. |
|
79 | 79 | \sa QChartView, QPolarChart |
|
80 | 80 | */ |
|
81 | 81 | |
|
82 | 82 | /*! |
|
83 | 83 | \property QChart::animationOptions |
|
84 | 84 | The animation \a options for the chart. Animations are enabled/disabled based on this setting. |
|
85 | 85 | */ |
|
86 | 86 | |
|
87 | 87 | /*! |
|
88 | 88 | \property QChart::backgroundVisible |
|
89 | 89 | Specifies whether the chart background is visible or not. |
|
90 | 90 | \sa setBackgroundBrush(), setBackgroundPen(), plotAreaBackgroundVisible |
|
91 | 91 | */ |
|
92 | 92 | |
|
93 | 93 | /*! |
|
94 | 94 | \property QChart::dropShadowEnabled |
|
95 | 95 | If set to true, the background drop shadow effect is enabled. If set to false, it is disabled. Note that the drop |
|
96 | 96 | shadow effect depends on theme, which means the setting may be changed if you switch to another theme. |
|
97 | 97 | */ |
|
98 | 98 | |
|
99 | 99 | /*! |
|
100 | \property QChart::backgroundRoundness | |
|
101 | The diameter of the rounding cirle at the corners of the chart background. | |
|
102 | */ | |
|
103 | ||
|
104 | /*! | |
|
100 | 105 | \property QChart::minimumMargins |
|
101 | 106 | Minimum margins between the plot area (axes) and the edge of the chart widget. |
|
102 | 107 | This property is deprecated; use margins property instead. |
|
103 | 108 | |
|
104 | 109 | \sa margins |
|
105 | 110 | */ |
|
106 | 111 | |
|
107 | 112 | /*! |
|
108 | 113 | \property QChart::margins |
|
109 | 114 | Margins between the plot area (axes) and the edge of the chart widget. |
|
110 | 115 | */ |
|
111 | 116 | |
|
112 | 117 | /*! |
|
113 | 118 | \property QChart::theme |
|
114 | 119 | Theme is a built-in collection of UI style related settings applied for all visual elements of a chart, like colors, |
|
115 | 120 | pens, brushes, and fonts of series, axes, title, and legend. \l {Chart themes demo} shows an example with a few |
|
116 | 121 | different themes. |
|
117 | 122 | \note Changing the theme will overwrite all customizations previously applied to the series. |
|
118 | 123 | */ |
|
119 | 124 | |
|
120 | 125 | /*! |
|
121 | 126 | \property QChart::title |
|
122 | 127 | Title is the name (label) of a chart. It is shown as a headline on top of the chart. Chart title supports html formatting. |
|
123 | 128 | */ |
|
124 | 129 | |
|
125 | 130 | /*! |
|
126 | 131 | \property QChart::chartType |
|
127 | 132 | Chart type indicates if the chart is a cartesian chart or a polar chart. |
|
128 | 133 | This property is set internally and it is read only. |
|
129 | 134 | \sa QPolarChart |
|
130 | 135 | */ |
|
131 | 136 | |
|
132 | 137 | /*! |
|
133 | 138 | \property QChart::plotAreaBackgroundVisible |
|
134 | 139 | Specifies whether the chart plot area background is visible or not. |
|
135 | 140 | \note By default the plot area background is not visible and the plot area uses |
|
136 | 141 | the general chart background. |
|
137 | 142 | \sa setPlotAreaBackgroundBrush(), setPlotAreaBackgroundPen(), backgroundVisible |
|
138 | 143 | */ |
|
139 | 144 | |
|
140 | 145 | /*! |
|
141 | 146 | \internal |
|
142 | 147 | Constructs a chart object of \a type which is a child of a \a parent. |
|
143 | 148 | Parameter \a wFlags is passed to the QGraphicsWidget constructor. |
|
144 | 149 | This constructor is called only by subclasses. |
|
145 | 150 | */ |
|
146 | 151 | QChart::QChart(QChart::ChartType type, QGraphicsItem *parent, Qt::WindowFlags wFlags) |
|
147 | 152 | : QGraphicsWidget(parent, wFlags), |
|
148 | 153 | d_ptr(new QChartPrivate(this, type)) |
|
149 | 154 | { |
|
150 | 155 | d_ptr->init(); |
|
151 | 156 | } |
|
152 | 157 | |
|
153 | 158 | /*! |
|
154 | 159 | Constructs a chart object which is a child of a \a parent. |
|
155 | 160 | Parameter \a wFlags is passed to the QGraphicsWidget constructor. |
|
156 | 161 | */ |
|
157 | 162 | QChart::QChart(QGraphicsItem *parent, Qt::WindowFlags wFlags) |
|
158 | 163 | : QGraphicsWidget(parent, wFlags), |
|
159 | 164 | d_ptr(new QChartPrivate(this, ChartTypeCartesian)) |
|
160 | 165 | { |
|
161 | 166 | d_ptr->init(); |
|
162 | 167 | } |
|
163 | 168 | |
|
164 | 169 | /*! |
|
165 | 170 | Destroys the chart object and its children, like series and axis objects added to it. |
|
166 | 171 | */ |
|
167 | 172 | QChart::~QChart() |
|
168 | 173 | { |
|
169 | 174 | //start by deleting dataset, it will remove all series and axes |
|
170 | 175 | delete d_ptr->m_dataset; |
|
171 | 176 | d_ptr->m_dataset = 0; |
|
172 | 177 | } |
|
173 | 178 | |
|
174 | 179 | /*! |
|
175 | 180 | Adds the \a series onto the chart and takes the ownership of it. |
|
176 | 181 | |
|
177 | 182 | \note A newly added series is attached to no axes by default, including any axes that were created for the chart |
|
178 | 183 | using createDefaultAxes() before the series was added to the chart. If no axes are attached to |
|
179 | 184 | the newly added series before the chart is shown, the series will get drawn as if it had axes with ranges |
|
180 | 185 | that exactly fit the series to the plot area of the chart. This can be confusing if the same chart also displays other |
|
181 | 186 | series that have properly attached axes, so always make sure you either call createDefaultAxes() after |
|
182 | 187 | a series has been added or explicitly attach axes for the series. |
|
183 | 188 | |
|
184 | 189 | \sa removeSeries(), removeAllSeries(), createDefaultAxes(), QAbstractSeries::attachAxis() |
|
185 | 190 | */ |
|
186 | 191 | void QChart::addSeries(QAbstractSeries *series) |
|
187 | 192 | { |
|
188 | 193 | Q_ASSERT(series); |
|
189 | 194 | d_ptr->m_dataset->addSeries(series); |
|
190 | 195 | } |
|
191 | 196 | |
|
192 | 197 | /*! |
|
193 | 198 | Removes the \a series from the chart. |
|
194 | 199 | The chart releases its ownership of the specified \a series object. |
|
195 | 200 | |
|
196 | 201 | \sa addSeries(), removeAllSeries() |
|
197 | 202 | */ |
|
198 | 203 | void QChart::removeSeries(QAbstractSeries *series) |
|
199 | 204 | { |
|
200 | 205 | Q_ASSERT(series); |
|
201 | 206 | d_ptr->m_dataset->removeSeries(series); |
|
202 | 207 | } |
|
203 | 208 | |
|
204 | 209 | /*! |
|
205 | 210 | Removes and deletes all series objects that have been added to the chart. |
|
206 | 211 | |
|
207 | 212 | \sa addSeries(), removeSeries() |
|
208 | 213 | */ |
|
209 | 214 | void QChart::removeAllSeries() |
|
210 | 215 | { |
|
211 | 216 | foreach (QAbstractSeries *s , d_ptr->m_dataset->series()){ |
|
212 | 217 | removeSeries(s); |
|
213 | 218 | delete s; |
|
214 | 219 | } |
|
215 | 220 | } |
|
216 | 221 | |
|
217 | 222 | /*! |
|
218 | 223 | Sets the \a brush that is used for painting the background of the chart area. |
|
219 | 224 | */ |
|
220 | 225 | void QChart::setBackgroundBrush(const QBrush &brush) |
|
221 | 226 | { |
|
222 | 227 | d_ptr->m_presenter->setBackgroundBrush(brush); |
|
223 | 228 | } |
|
224 | 229 | |
|
225 | 230 | /*! |
|
226 | 231 | Gets the brush that is used for painting the background of the chart area. |
|
227 | 232 | */ |
|
228 | 233 | QBrush QChart::backgroundBrush() const |
|
229 | 234 | { |
|
230 | 235 | return d_ptr->m_presenter->backgroundBrush(); |
|
231 | 236 | } |
|
232 | 237 | |
|
233 | 238 | /*! |
|
234 | 239 | Sets the \a pen that is used for painting the background of the chart area. |
|
235 | 240 | */ |
|
236 | 241 | void QChart::setBackgroundPen(const QPen &pen) |
|
237 | 242 | { |
|
238 | 243 | d_ptr->m_presenter->setBackgroundPen(pen); |
|
239 | 244 | } |
|
240 | 245 | |
|
241 | 246 | /*! |
|
242 | 247 | Gets the pen that is used for painting the background of the chart area. |
|
243 | 248 | */ |
|
244 | 249 | QPen QChart::backgroundPen() const |
|
245 | 250 | { |
|
246 | 251 | return d_ptr->m_presenter->backgroundPen(); |
|
247 | 252 | } |
|
248 | 253 | |
|
249 | 254 | void QChart::setTitle(const QString &title) |
|
250 | 255 | { |
|
251 | 256 | d_ptr->m_presenter->setTitle(title); |
|
252 | 257 | } |
|
253 | 258 | |
|
254 | 259 | QString QChart::title() const |
|
255 | 260 | { |
|
256 | 261 | return d_ptr->m_presenter->title(); |
|
257 | 262 | } |
|
258 | 263 | |
|
259 | 264 | /*! |
|
260 | 265 | Sets the \a font that is used for drawing the chart title. |
|
261 | 266 | */ |
|
262 | 267 | void QChart::setTitleFont(const QFont &font) |
|
263 | 268 | { |
|
264 | 269 | d_ptr->m_presenter->setTitleFont(font); |
|
265 | 270 | } |
|
266 | 271 | |
|
267 | 272 | /*! |
|
268 | 273 | Gets the font that is used for drawing the chart title. |
|
269 | 274 | */ |
|
270 | 275 | QFont QChart::titleFont() const |
|
271 | 276 | { |
|
272 | 277 | return d_ptr->m_presenter->titleFont(); |
|
273 | 278 | } |
|
274 | 279 | |
|
275 | 280 | /*! |
|
276 | 281 | Sets the \a brush used for drawing the title text. |
|
277 | 282 | */ |
|
278 | 283 | void QChart::setTitleBrush(const QBrush &brush) |
|
279 | 284 | { |
|
280 | 285 | d_ptr->m_presenter->setTitleBrush(brush); |
|
281 | 286 | } |
|
282 | 287 | |
|
283 | 288 | /*! |
|
284 | 289 | Returns the brush used for drawing the title text. |
|
285 | 290 | */ |
|
286 | 291 | QBrush QChart::titleBrush() const |
|
287 | 292 | { |
|
288 | 293 | return d_ptr->m_presenter->titleBrush(); |
|
289 | 294 | } |
|
290 | 295 | |
|
291 | 296 | void QChart::setTheme(QChart::ChartTheme theme) |
|
292 | 297 | { |
|
293 | 298 | d_ptr->m_themeManager->setTheme(theme); |
|
294 | 299 | } |
|
295 | 300 | |
|
296 | 301 | QChart::ChartTheme QChart::theme() const |
|
297 | 302 | { |
|
298 | 303 | return d_ptr->m_themeManager->theme()->id(); |
|
299 | 304 | } |
|
300 | 305 | |
|
301 | 306 | /*! |
|
302 | 307 | Zooms in the view by a factor of two. |
|
303 | 308 | */ |
|
304 | 309 | void QChart::zoomIn() |
|
305 | 310 | { |
|
306 | 311 | d_ptr->zoomIn(2.0); |
|
307 | 312 | } |
|
308 | 313 | |
|
309 | 314 | /*! |
|
310 | 315 | Zooms in the view to a maximum level at which \a rect is still fully visible. |
|
311 | 316 | \note This is not supported for polar charts. |
|
312 | 317 | */ |
|
313 | 318 | void QChart::zoomIn(const QRectF &rect) |
|
314 | 319 | { |
|
315 | 320 | if (d_ptr->m_type == QChart::ChartTypePolar) |
|
316 | 321 | return; |
|
317 | 322 | d_ptr->zoomIn(rect); |
|
318 | 323 | } |
|
319 | 324 | |
|
320 | 325 | /*! |
|
321 | 326 | Zooms out the view by a factor of two. |
|
322 | 327 | */ |
|
323 | 328 | void QChart::zoomOut() |
|
324 | 329 | { |
|
325 | 330 | d_ptr->zoomOut(2.0); |
|
326 | 331 | } |
|
327 | 332 | |
|
328 | 333 | /*! |
|
329 | 334 | Zooms in the view by a custom \a factor. |
|
330 | 335 | |
|
331 | 336 | A factor over 1.0 zooms the view in and factor between 0.0 and 1.0 zooms out. |
|
332 | 337 | */ |
|
333 | 338 | void QChart::zoom(qreal factor) |
|
334 | 339 | { |
|
335 | 340 | if (qFuzzyCompare(factor, 0)) |
|
336 | 341 | return; |
|
337 | 342 | |
|
338 | 343 | if (qFuzzyCompare(factor, (qreal)1.0)) |
|
339 | 344 | return; |
|
340 | 345 | |
|
341 | 346 | if (factor < 0) |
|
342 | 347 | return; |
|
343 | 348 | |
|
344 | 349 | if (factor > 1.0) |
|
345 | 350 | d_ptr->zoomIn(factor); |
|
346 | 351 | else |
|
347 | 352 | d_ptr->zoomOut(1.0 / factor); |
|
348 | 353 | } |
|
349 | 354 | |
|
350 | 355 | |
|
351 | 356 | /*! |
|
352 | 357 | Resets the series domains to what they were before any zoom method was called. |
|
353 | 358 | Note that this will also reset any scrolls and explicit axis range settings done between |
|
354 | 359 | the first zoom operation and calling this method. If no zoom operation has been |
|
355 | 360 | done, this method does nothing. |
|
356 | 361 | */ |
|
357 | 362 | void QChart::zoomReset() |
|
358 | 363 | { |
|
359 | 364 | d_ptr->zoomReset(); |
|
360 | 365 | } |
|
361 | 366 | |
|
362 | 367 | /*! |
|
363 | 368 | Returns true if any series has a zoomed domain. |
|
364 | 369 | */ |
|
365 | 370 | bool QChart::isZoomed() |
|
366 | 371 | { |
|
367 | 372 | return d_ptr->isZoomed(); |
|
368 | 373 | } |
|
369 | 374 | |
|
370 | 375 | /*! |
|
371 | 376 | Returns a pointer to the horizontal axis attached to the specified \a series. |
|
372 | 377 | If no \a series is specified, the first horizontal axis added to the chart is returned. |
|
373 | 378 | |
|
374 | 379 | \sa addAxis(), QAbstractSeries::attachAxis() |
|
375 | 380 | */ |
|
376 | 381 | QAbstractAxis *QChart::axisX(QAbstractSeries *series) const |
|
377 | 382 | { |
|
378 | 383 | QList<QAbstractAxis *> axisList = axes(Qt::Horizontal, series); |
|
379 | 384 | if (axisList.count()) |
|
380 | 385 | return axisList[0]; |
|
381 | 386 | return 0; |
|
382 | 387 | } |
|
383 | 388 | |
|
384 | 389 | /*! |
|
385 | 390 | Returns a pointer to the vertical axis attached to the specified \a series. |
|
386 | 391 | If no \a series is specified, the first vertical axis added to the chart is returned. |
|
387 | 392 | |
|
388 | 393 | \sa addAxis(), QAbstractSeries::attachAxis() |
|
389 | 394 | */ |
|
390 | 395 | QAbstractAxis *QChart::axisY(QAbstractSeries *series) const |
|
391 | 396 | { |
|
392 | 397 | QList<QAbstractAxis *> axisList = axes(Qt::Vertical, series); |
|
393 | 398 | if (axisList.count()) |
|
394 | 399 | return axisList[0]; |
|
395 | 400 | return 0; |
|
396 | 401 | } |
|
397 | 402 | |
|
398 | 403 | /*! |
|
399 | 404 | Returns the axes attached to the \a series with \a orientation. If no \a series is provided, |
|
400 | 405 | then all axes added to the chart with the specified orientation are returned. |
|
401 | 406 | \sa addAxis(), createDefaultAxes() |
|
402 | 407 | */ |
|
403 | 408 | QList<QAbstractAxis *> QChart::axes(Qt::Orientations orientation, QAbstractSeries *series) const |
|
404 | 409 | { |
|
405 | 410 | QList<QAbstractAxis *> result ; |
|
406 | 411 | |
|
407 | 412 | if (series) { |
|
408 | 413 | foreach (QAbstractAxis *axis, series->attachedAxes()){ |
|
409 | 414 | if (orientation.testFlag(axis->orientation())) |
|
410 | 415 | result << axis; |
|
411 | 416 | } |
|
412 | 417 | } else { |
|
413 | 418 | foreach (QAbstractAxis *axis, d_ptr->m_dataset->axes()){ |
|
414 | 419 | if (orientation.testFlag(axis->orientation()) && !result.contains(axis)) |
|
415 | 420 | result << axis; |
|
416 | 421 | } |
|
417 | 422 | } |
|
418 | 423 | |
|
419 | 424 | return result; |
|
420 | 425 | } |
|
421 | 426 | |
|
422 | 427 | /*! |
|
423 | 428 | Creates axes for the chart based on the series that have already been added to the chart. Any axes previously added to |
|
424 | 429 | the chart will be deleted. |
|
425 | 430 | |
|
426 | 431 | \note This function has to be called after all series have been added to the chart. The axes created by this function |
|
427 | 432 | will NOT get automatically attached to any series added to the chart after this function has been called. |
|
428 | 433 | A series with no axes attached will by default scale to utilize the entire plot area of the chart, which can be confusing |
|
429 | 434 | if there are other series with properly attached axes also present. |
|
430 | 435 | |
|
431 | 436 | \table |
|
432 | 437 | \header |
|
433 | 438 | \o Series type |
|
434 | 439 | \o X-axis |
|
435 | 440 | \o Y-axis |
|
436 | 441 | \row |
|
437 | 442 | \o QXYSeries |
|
438 | 443 | \o QValueAxis |
|
439 | 444 | \o QValueAxis |
|
440 | 445 | \row |
|
441 | 446 | \o QBarSeries |
|
442 | 447 | \o QBarCategoryAxis |
|
443 | 448 | \o QValueAxis |
|
444 | 449 | \row |
|
445 | 450 | \o QPieSeries |
|
446 | 451 | \o None |
|
447 | 452 | \o None |
|
448 | 453 | \endtable |
|
449 | 454 | |
|
450 | 455 | If there are several QXYSeries derived series added to the chart and no series of other types have been added, then only one pair of axes is created. |
|
451 | 456 | If there are several series of different types added to the chart, then each series gets its own axes pair. |
|
452 | 457 | |
|
453 | 458 | The axes specific to the series can be later obtained from the chart by providing the series as the parameter for axes() function call. |
|
454 | 459 | QPieSeries does not create any axes. |
|
455 | 460 | |
|
456 | 461 | \sa axisX(), axisY(), axes(), setAxisX(), setAxisY(), QAbstractSeries::attachAxis() |
|
457 | 462 | */ |
|
458 | 463 | void QChart::createDefaultAxes() |
|
459 | 464 | { |
|
460 | 465 | d_ptr->m_dataset->createDefaultAxes(); |
|
461 | 466 | } |
|
462 | 467 | |
|
463 | 468 | /*! |
|
464 | 469 | Returns the legend object of the chart. Ownership stays with the chart. |
|
465 | 470 | */ |
|
466 | 471 | QLegend *QChart::legend() const |
|
467 | 472 | { |
|
468 | 473 | return d_ptr->m_legend; |
|
469 | 474 | } |
|
470 | 475 | |
|
471 | 476 | void QChart::setMinimumMargins(const QMargins &margins) |
|
472 | 477 | { |
|
473 | 478 | qWarning() << "QChart::setMinimumMargins is deprecated. Use QChart::setMargins instead."; |
|
474 | 479 | d_ptr->m_presenter->layout()->setMargins(margins); |
|
475 | 480 | } |
|
476 | 481 | |
|
477 | 482 | QMargins QChart::minimumMargins() const |
|
478 | 483 | { |
|
479 | 484 | qWarning() << "QChart::minimumMargins is deprecated. Use QChart::margins instead."; |
|
480 | 485 | return d_ptr->m_presenter->layout()->margins(); |
|
481 | 486 | } |
|
482 | 487 | |
|
483 | 488 | void QChart::setMargins(const QMargins &margins) |
|
484 | 489 | { |
|
485 | 490 | d_ptr->m_presenter->layout()->setMargins(margins); |
|
486 | 491 | } |
|
487 | 492 | |
|
488 | 493 | QMargins QChart::margins() const |
|
489 | 494 | { |
|
490 | 495 | return d_ptr->m_presenter->layout()->margins(); |
|
491 | 496 | } |
|
492 | 497 | |
|
493 | 498 | QChart::ChartType QChart::chartType() const |
|
494 | 499 | { |
|
495 | 500 | return d_ptr->m_type; |
|
496 | 501 | } |
|
497 | 502 | |
|
498 | 503 | /*! |
|
499 | 504 | Returns the the rectangle within which the drawing of the chart is done. |
|
500 | 505 | It does not include the area defined by margins. |
|
501 | 506 | */ |
|
502 | 507 | QRectF QChart::plotArea() const |
|
503 | 508 | { |
|
504 | 509 | return d_ptr->m_presenter->geometry(); |
|
505 | 510 | } |
|
506 | 511 | |
|
507 | 512 | /*! |
|
508 | 513 | Sets the \a brush for the background of the plot area of the chart. |
|
509 | 514 | |
|
510 | 515 | \sa plotArea(), plotAreaBackgroundVisible, setPlotAreaBackgroundPen(), plotAreaBackgroundBrush() |
|
511 | 516 | */ |
|
512 | 517 | void QChart::setPlotAreaBackgroundBrush(const QBrush &brush) |
|
513 | 518 | { |
|
514 | 519 | d_ptr->m_presenter->setPlotAreaBackgroundBrush(brush); |
|
515 | 520 | } |
|
516 | 521 | |
|
517 | 522 | /*! |
|
518 | 523 | Returns the brush for the background of the plot area of the chart. |
|
519 | 524 | |
|
520 | 525 | \sa plotArea(), plotAreaBackgroundVisible, plotAreaBackgroundPen(), setPlotAreaBackgroundBrush() |
|
521 | 526 | */ |
|
522 | 527 | QBrush QChart::plotAreaBackgroundBrush() const |
|
523 | 528 | { |
|
524 | 529 | return d_ptr->m_presenter->plotAreaBackgroundBrush(); |
|
525 | 530 | } |
|
526 | 531 | |
|
527 | 532 | /*! |
|
528 | 533 | Sets the \a pen for the background of the plot area of the chart. |
|
529 | 534 | |
|
530 | 535 | \sa plotArea(), plotAreaBackgroundVisible, setPlotAreaBackgroundBrush(), plotAreaBackgroundPen() |
|
531 | 536 | */ |
|
532 | 537 | void QChart::setPlotAreaBackgroundPen(const QPen &pen) |
|
533 | 538 | { |
|
534 | 539 | d_ptr->m_presenter->setPlotAreaBackgroundPen(pen); |
|
535 | 540 | } |
|
536 | 541 | |
|
537 | 542 | /*! |
|
538 | 543 | Returns the pen for the background of the plot area of the chart. |
|
539 | 544 | |
|
540 | 545 | \sa plotArea(), plotAreaBackgroundVisible, plotAreaBackgroundBrush(), setPlotAreaBackgroundPen() |
|
541 | 546 | */ |
|
542 | 547 | QPen QChart::plotAreaBackgroundPen() const |
|
543 | 548 | { |
|
544 | 549 | return d_ptr->m_presenter->plotAreaBackgroundPen(); |
|
545 | 550 | } |
|
546 | 551 | |
|
547 | 552 | void QChart::setPlotAreaBackgroundVisible(bool visible) |
|
548 | 553 | { |
|
549 | 554 | d_ptr->m_presenter->setPlotAreaBackgroundVisible(visible); |
|
550 | 555 | } |
|
551 | 556 | |
|
552 | 557 | bool QChart::isPlotAreaBackgroundVisible() const |
|
553 | 558 | { |
|
554 | 559 | return d_ptr->m_presenter->isPlotAreaBackgroundVisible(); |
|
555 | 560 | } |
|
556 | 561 | |
|
557 | 562 | void QChart::setAnimationOptions(AnimationOptions options) |
|
558 | 563 | { |
|
559 | 564 | d_ptr->m_presenter->setAnimationOptions(options); |
|
560 | 565 | } |
|
561 | 566 | |
|
562 | 567 | QChart::AnimationOptions QChart::animationOptions() const |
|
563 | 568 | { |
|
564 | 569 | return d_ptr->m_presenter->animationOptions(); |
|
565 | 570 | } |
|
566 | 571 | |
|
567 | 572 | /*! |
|
568 | 573 | Scrolls the visible area of the chart by the distance defined in the \a dx and \a dy. |
|
569 | 574 | |
|
570 | 575 | For polar charts, \a dx indicates the angle along angular axis instead of distance. |
|
571 | 576 | */ |
|
572 | 577 | void QChart::scroll(qreal dx, qreal dy) |
|
573 | 578 | { |
|
574 | 579 | d_ptr->scroll(dx,dy); |
|
575 | 580 | } |
|
576 | 581 | |
|
577 | 582 | void QChart::setBackgroundVisible(bool visible) |
|
578 | 583 | { |
|
579 | 584 | d_ptr->m_presenter->setBackgroundVisible(visible); |
|
580 | 585 | } |
|
581 | 586 | |
|
582 | 587 | bool QChart::isBackgroundVisible() const |
|
583 | 588 | { |
|
584 | 589 | return d_ptr->m_presenter->isBackgroundVisible(); |
|
585 | 590 | } |
|
586 | 591 | |
|
587 | 592 | void QChart::setDropShadowEnabled(bool enabled) |
|
588 | 593 | { |
|
589 | 594 | d_ptr->m_presenter->setBackgroundDropShadowEnabled(enabled); |
|
590 | 595 | } |
|
591 | 596 | |
|
592 | 597 | bool QChart::isDropShadowEnabled() const |
|
593 | 598 | { |
|
594 | 599 | return d_ptr->m_presenter->isBackgroundDropShadowEnabled(); |
|
595 | 600 | } |
|
596 | 601 | |
|
602 | void QChart::setBackgroundRoundness(qreal diameter) | |
|
603 | { | |
|
604 | d_ptr->m_presenter->setBackgroundRoundness(diameter); | |
|
605 | } | |
|
606 | ||
|
607 | qreal QChart::backgroundRoundness() const | |
|
608 | { | |
|
609 | return d_ptr->m_presenter->backgroundRoundness(); | |
|
610 | } | |
|
611 | ||
|
597 | 612 | /*! |
|
598 | 613 | Returns all series that are added to the chart. |
|
599 | 614 | |
|
600 | 615 | \sa addSeries(), removeSeries(), removeAllSeries() |
|
601 | 616 | */ |
|
602 | 617 | QList<QAbstractSeries *> QChart::series() const |
|
603 | 618 | { |
|
604 | 619 | return d_ptr->m_dataset->series(); |
|
605 | 620 | } |
|
606 | 621 | |
|
607 | 622 | /*! |
|
608 | 623 | Adds the \a axis to the chart and attaches it to the \a series as a bottom-aligned horizontal axis. |
|
609 | 624 | The chart takes ownership of both the \a axis and the \a series. |
|
610 | 625 | Any horizontal axes previously attached to the \a series are deleted. |
|
611 | 626 | |
|
612 | 627 | \sa axisX(), axisY(), setAxisY(), createDefaultAxes(), QAbstractSeries::attachAxis() |
|
613 | 628 | */ |
|
614 | 629 | void QChart::setAxisX(QAbstractAxis *axis ,QAbstractSeries *series) |
|
615 | 630 | { |
|
616 | 631 | QList<QAbstractAxis*> list = axes(Qt::Horizontal, series); |
|
617 | 632 | |
|
618 | 633 | foreach (QAbstractAxis* a, list) { |
|
619 | 634 | d_ptr->m_dataset->removeAxis(a); |
|
620 | 635 | delete a; |
|
621 | 636 | } |
|
622 | 637 | |
|
623 | 638 | if (!d_ptr->m_dataset->axes().contains(axis)) |
|
624 | 639 | d_ptr->m_dataset->addAxis(axis, Qt::AlignBottom); |
|
625 | 640 | d_ptr->m_dataset->attachAxis(series, axis); |
|
626 | 641 | } |
|
627 | 642 | |
|
628 | 643 | /*! |
|
629 | 644 | Adds the \a axis to the chart and attaches it to the \a series as a left-aligned vertical axis. |
|
630 | 645 | The chart takes ownership of both the \a axis and the \a series. |
|
631 | 646 | Any vertical axes previously attached to the \a series are deleted. |
|
632 | 647 | |
|
633 | 648 | \sa axisX(), axisY(), setAxisX(), createDefaultAxes(), QAbstractSeries::attachAxis() |
|
634 | 649 | */ |
|
635 | 650 | void QChart::setAxisY(QAbstractAxis *axis ,QAbstractSeries *series) |
|
636 | 651 | { |
|
637 | 652 | QList<QAbstractAxis*> list = axes(Qt::Vertical, series); |
|
638 | 653 | |
|
639 | 654 | foreach (QAbstractAxis* a, list) { |
|
640 | 655 | d_ptr->m_dataset->removeAxis(a); |
|
641 | 656 | delete a; |
|
642 | 657 | } |
|
643 | 658 | |
|
644 | 659 | if (!d_ptr->m_dataset->axes().contains(axis)) |
|
645 | 660 | d_ptr->m_dataset->addAxis(axis, Qt::AlignLeft); |
|
646 | 661 | d_ptr->m_dataset->attachAxis(series, axis); |
|
647 | 662 | } |
|
648 | 663 | |
|
649 | 664 | /*! |
|
650 | 665 | Adds the \a axis to the chart with \a alignment. The chart takes the ownership of the axis. |
|
651 | 666 | |
|
652 | 667 | \sa removeAxis(), createDefaultAxes(), QAbstractSeries::attachAxis() |
|
653 | 668 | */ |
|
654 | 669 | void QChart::addAxis(QAbstractAxis *axis, Qt::Alignment alignment) |
|
655 | 670 | { |
|
656 | 671 | d_ptr->m_dataset->addAxis(axis, alignment); |
|
657 | 672 | } |
|
658 | 673 | |
|
659 | 674 | /*! |
|
660 | 675 | Removes the \a axis from the chart. |
|
661 | 676 | The chart releases its ownership of the specified \a axis object. |
|
662 | 677 | |
|
663 | 678 | \sa addAxis(), createDefaultAxes(), QAbstractSeries::detachAxis() |
|
664 | 679 | */ |
|
665 | 680 | void QChart::removeAxis(QAbstractAxis *axis) |
|
666 | 681 | { |
|
667 | 682 | d_ptr->m_dataset->removeAxis(axis); |
|
668 | 683 | } |
|
669 | 684 | |
|
670 | 685 | /*! |
|
671 | 686 | Returns the value in the \a series domain that corresponds to the \a position relative to chart widget. |
|
672 | 687 | */ |
|
673 | 688 | QPointF QChart::mapToValue(const QPointF &position, QAbstractSeries *series) |
|
674 | 689 | { |
|
675 | 690 | return d_ptr->m_dataset->mapToValue(position, series); |
|
676 | 691 | } |
|
677 | 692 | |
|
678 | 693 | /*! |
|
679 | 694 | Returns the position on the chart widget that corresponds to the \a value in the \a series domain. |
|
680 | 695 | */ |
|
681 | 696 | QPointF QChart::mapToPosition(const QPointF &value, QAbstractSeries *series) |
|
682 | 697 | { |
|
683 | 698 | return d_ptr->m_dataset->mapToPosition(value, series); |
|
684 | 699 | } |
|
685 | 700 | |
|
686 | 701 | ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
687 | 702 | |
|
688 | 703 | QChartPrivate::QChartPrivate(QChart *q, QChart::ChartType type): |
|
689 | 704 | q_ptr(q), |
|
690 | 705 | m_legend(0), |
|
691 | 706 | m_dataset(new ChartDataSet(q)), |
|
692 | 707 | m_presenter(new ChartPresenter(q, type)), |
|
693 | 708 | m_themeManager(new ChartThemeManager(q)), |
|
694 | 709 | m_type(type) |
|
695 | 710 | { |
|
696 | 711 | QObject::connect(m_dataset, SIGNAL(seriesAdded(QAbstractSeries*)), m_presenter, SLOT(handleSeriesAdded(QAbstractSeries*))); |
|
697 | 712 | QObject::connect(m_dataset, SIGNAL(seriesRemoved(QAbstractSeries*)), m_presenter, SLOT(handleSeriesRemoved(QAbstractSeries*))); |
|
698 | 713 | QObject::connect(m_dataset, SIGNAL(axisAdded(QAbstractAxis*)), m_presenter, SLOT(handleAxisAdded(QAbstractAxis*))); |
|
699 | 714 | QObject::connect(m_dataset, SIGNAL(axisRemoved(QAbstractAxis*)), m_presenter, SLOT(handleAxisRemoved(QAbstractAxis*))); |
|
700 | 715 | QObject::connect(m_dataset, SIGNAL(seriesAdded(QAbstractSeries*)), m_themeManager, SLOT(handleSeriesAdded(QAbstractSeries*))); |
|
701 | 716 | QObject::connect(m_dataset, SIGNAL(seriesRemoved(QAbstractSeries*)), m_themeManager, SLOT(handleSeriesRemoved(QAbstractSeries*))); |
|
702 | 717 | QObject::connect(m_dataset, SIGNAL(axisAdded(QAbstractAxis*)), m_themeManager, SLOT(handleAxisAdded(QAbstractAxis*))); |
|
703 | 718 | QObject::connect(m_dataset, SIGNAL(axisRemoved(QAbstractAxis*)), m_themeManager, SLOT(handleAxisRemoved(QAbstractAxis*))); |
|
704 | 719 | } |
|
705 | 720 | |
|
706 | 721 | QChartPrivate::~QChartPrivate() |
|
707 | 722 | { |
|
708 | 723 | } |
|
709 | 724 | |
|
710 | 725 | // Hackish solution to the problem of explicitly assigning the default pen/brush/font |
|
711 | 726 | // to a series or axis and having theme override it: |
|
712 | 727 | // Initialize pens, brushes, and fonts to something nobody is likely to ever use, |
|
713 | 728 | // so that default theme initialization will always set these properly. |
|
714 | 729 | QPen &QChartPrivate::defaultPen() |
|
715 | 730 | { |
|
716 | 731 | static QPen defaultPen(QColor(1, 2, 0), 0.93247536); |
|
717 | 732 | return defaultPen; |
|
718 | 733 | } |
|
719 | 734 | |
|
720 | 735 | QBrush &QChartPrivate::defaultBrush() |
|
721 | 736 | { |
|
722 | 737 | static QBrush defaultBrush(QColor(1, 2, 0), Qt::Dense7Pattern); |
|
723 | 738 | return defaultBrush; |
|
724 | 739 | } |
|
725 | 740 | |
|
726 | 741 | QFont &QChartPrivate::defaultFont() |
|
727 | 742 | { |
|
728 | 743 | static bool defaultFontInitialized(false); |
|
729 | 744 | static QFont defaultFont; |
|
730 | 745 | if (!defaultFontInitialized) { |
|
731 | 746 | defaultFont.setPointSizeF(8.34563465); |
|
732 | 747 | defaultFontInitialized = true; |
|
733 | 748 | } |
|
734 | 749 | return defaultFont; |
|
735 | 750 | } |
|
736 | 751 | |
|
737 | 752 | void QChartPrivate::init() |
|
738 | 753 | { |
|
739 | 754 | m_legend = new LegendScroller(q_ptr); |
|
740 | 755 | q_ptr->setTheme(QChart::ChartThemeLight); |
|
741 | 756 | q_ptr->setLayout(m_presenter->layout()); |
|
742 | 757 | } |
|
743 | 758 | |
|
744 | 759 | void QChartPrivate::zoomIn(qreal factor) |
|
745 | 760 | { |
|
746 | 761 | QRectF rect = m_presenter->geometry(); |
|
747 | 762 | rect.setWidth(rect.width() / factor); |
|
748 | 763 | rect.setHeight(rect.height() / factor); |
|
749 | 764 | rect.moveCenter(m_presenter->geometry().center()); |
|
750 | 765 | zoomIn(rect); |
|
751 | 766 | } |
|
752 | 767 | |
|
753 | 768 | void QChartPrivate::zoomIn(const QRectF &rect) |
|
754 | 769 | { |
|
755 | 770 | if (!rect.isValid()) |
|
756 | 771 | return; |
|
757 | 772 | |
|
758 | 773 | QRectF r = rect.normalized(); |
|
759 | 774 | const QRectF geometry = m_presenter->geometry(); |
|
760 | 775 | r.translate(-geometry.topLeft()); |
|
761 | 776 | |
|
762 | 777 | if (!r.isValid()) |
|
763 | 778 | return; |
|
764 | 779 | |
|
765 | 780 | QPointF zoomPoint(r.center().x() / geometry.width(), r.center().y() / geometry.height()); |
|
766 | 781 | m_presenter->setState(ChartPresenter::ZoomInState,zoomPoint); |
|
767 | 782 | m_dataset->zoomInDomain(r); |
|
768 | 783 | m_presenter->setState(ChartPresenter::ShowState,QPointF()); |
|
769 | 784 | |
|
770 | 785 | } |
|
771 | 786 | |
|
772 | 787 | void QChartPrivate::zoomReset() |
|
773 | 788 | { |
|
774 | 789 | m_dataset->zoomResetDomain(); |
|
775 | 790 | } |
|
776 | 791 | |
|
777 | 792 | bool QChartPrivate::isZoomed() |
|
778 | 793 | { |
|
779 | 794 | return m_dataset->isZoomedDomain(); |
|
780 | 795 | } |
|
781 | 796 | |
|
782 | 797 | void QChartPrivate::zoomOut(qreal factor) |
|
783 | 798 | { |
|
784 | 799 | const QRectF geometry = m_presenter->geometry(); |
|
785 | 800 | |
|
786 | 801 | QRectF r; |
|
787 | 802 | r.setSize(geometry.size() / factor); |
|
788 | 803 | r.moveCenter(QPointF(geometry.size().width()/2 ,geometry.size().height()/2)); |
|
789 | 804 | if (!r.isValid()) |
|
790 | 805 | return; |
|
791 | 806 | |
|
792 | 807 | QPointF zoomPoint(r.center().x() / geometry.width(), r.center().y() / geometry.height()); |
|
793 | 808 | m_presenter->setState(ChartPresenter::ZoomOutState,zoomPoint); |
|
794 | 809 | m_dataset->zoomOutDomain(r); |
|
795 | 810 | m_presenter->setState(ChartPresenter::ShowState,QPointF()); |
|
796 | 811 | } |
|
797 | 812 | |
|
798 | 813 | void QChartPrivate::scroll(qreal dx, qreal dy) |
|
799 | 814 | { |
|
800 | 815 | if (dx < 0) m_presenter->setState(ChartPresenter::ScrollLeftState,QPointF()); |
|
801 | 816 | if (dx > 0) m_presenter->setState(ChartPresenter::ScrollRightState,QPointF()); |
|
802 | 817 | if (dy < 0) m_presenter->setState(ChartPresenter::ScrollUpState,QPointF()); |
|
803 | 818 | if (dy > 0) m_presenter->setState(ChartPresenter::ScrollDownState,QPointF()); |
|
804 | 819 | |
|
805 | 820 | m_dataset->scrollDomain(dx, dy); |
|
806 | 821 | m_presenter->setState(ChartPresenter::ShowState,QPointF()); |
|
807 | 822 | } |
|
808 | 823 | |
|
809 | 824 | #include "moc_qchart.cpp" |
|
810 | 825 | |
|
811 | 826 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,173 +1,176 | |||
|
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 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 QCHART_H |
|
22 | 22 | #define QCHART_H |
|
23 | 23 | |
|
24 | 24 | #include <QAbstractSeries> |
|
25 | 25 | #include <QLegend> |
|
26 | 26 | #include <QGraphicsWidget> |
|
27 | 27 | #include <QMargins> |
|
28 | 28 | |
|
29 | 29 | class QGraphicsSceneResizeEvent; |
|
30 | 30 | |
|
31 | 31 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
32 | 32 | |
|
33 | 33 | class QAbstractSeries; |
|
34 | 34 | class QAbstractAxis; |
|
35 | 35 | class QLegend; |
|
36 | 36 | class QChartPrivate; |
|
37 | 37 | class QBoxPlotSeries; |
|
38 | 38 | |
|
39 | 39 | class QTCOMMERCIALCHART_EXPORT QChart : public QGraphicsWidget |
|
40 | 40 | { |
|
41 | 41 | Q_OBJECT |
|
42 | 42 | Q_PROPERTY(QChart::ChartTheme theme READ theme WRITE setTheme) |
|
43 | 43 | Q_PROPERTY(QString title READ title WRITE setTitle) |
|
44 | 44 | Q_PROPERTY(bool backgroundVisible READ isBackgroundVisible WRITE setBackgroundVisible) |
|
45 | 45 | Q_PROPERTY(bool dropShadowEnabled READ isDropShadowEnabled WRITE setDropShadowEnabled) |
|
46 | Q_PROPERTY(qreal backgroundRoundness READ backgroundRoundness WRITE setBackgroundRoundness) | |
|
46 | 47 | Q_PROPERTY(QChart::AnimationOptions animationOptions READ animationOptions WRITE setAnimationOptions) |
|
47 | 48 | Q_PROPERTY(QMargins minimumMargins READ minimumMargins WRITE setMinimumMargins) |
|
48 | 49 | Q_PROPERTY(QMargins margins READ margins WRITE setMargins) |
|
49 | 50 | Q_PROPERTY(QChart::ChartType chartType READ chartType) |
|
50 | 51 | Q_PROPERTY(bool plotAreaBackgroundVisible READ isPlotAreaBackgroundVisible WRITE setPlotAreaBackgroundVisible) |
|
51 | 52 | Q_ENUMS(ChartTheme) |
|
52 | 53 | Q_ENUMS(AnimationOption) |
|
53 | 54 | Q_ENUMS(ChartType) |
|
54 | 55 | |
|
55 | 56 | public: |
|
56 | 57 | enum ChartType { |
|
57 | 58 | ChartTypeUndefined = 0, |
|
58 | 59 | ChartTypeCartesian, |
|
59 | 60 | ChartTypePolar |
|
60 | 61 | }; |
|
61 | 62 | |
|
62 | 63 | enum ChartTheme { |
|
63 | 64 | ChartThemeLight = 0, |
|
64 | 65 | ChartThemeBlueCerulean, |
|
65 | 66 | ChartThemeDark, |
|
66 | 67 | ChartThemeBrownSand, |
|
67 | 68 | ChartThemeBlueNcs, |
|
68 | 69 | ChartThemeHighContrast, |
|
69 | 70 | ChartThemeBlueIcy |
|
70 | 71 | }; |
|
71 | 72 | |
|
72 | 73 | enum AnimationOption { |
|
73 | 74 | NoAnimation = 0x0, |
|
74 | 75 | GridAxisAnimations = 0x1, |
|
75 | 76 | SeriesAnimations = 0x2, |
|
76 | 77 | AllAnimations = 0x3 |
|
77 | 78 | }; |
|
78 | 79 | |
|
79 | 80 | Q_DECLARE_FLAGS(AnimationOptions, AnimationOption) |
|
80 | 81 | |
|
81 | 82 | public: |
|
82 | 83 | explicit QChart(QGraphicsItem *parent = 0, Qt::WindowFlags wFlags = 0); |
|
83 | 84 | ~QChart(); |
|
84 | 85 | |
|
85 | 86 | void addSeries(QAbstractSeries *series); |
|
86 | 87 | void removeSeries(QAbstractSeries *series); |
|
87 | 88 | void removeAllSeries(); |
|
88 | 89 | QList<QAbstractSeries *> series() const; |
|
89 | 90 | |
|
90 | 91 | // *** deprecated *** |
|
91 | 92 | void setAxisX(QAbstractAxis *axis, QAbstractSeries *series = 0); |
|
92 | 93 | void setAxisY(QAbstractAxis *axis, QAbstractSeries *series = 0); |
|
93 | 94 | QAbstractAxis *axisX(QAbstractSeries *series = 0) const; |
|
94 | 95 | QAbstractAxis *axisY(QAbstractSeries *series = 0) const; |
|
95 | 96 | // ****************** |
|
96 | 97 | |
|
97 | 98 | void addAxis(QAbstractAxis *axis, Qt::Alignment alignment); |
|
98 | 99 | void removeAxis(QAbstractAxis *axis); |
|
99 | 100 | QList<QAbstractAxis*> axes(Qt::Orientations orientation = Qt::Horizontal|Qt::Vertical, QAbstractSeries *series = 0) const; |
|
100 | 101 | |
|
101 | 102 | void createDefaultAxes(); |
|
102 | 103 | |
|
103 | 104 | void setTheme(QChart::ChartTheme theme); |
|
104 | 105 | QChart::ChartTheme theme() const; |
|
105 | 106 | |
|
106 | 107 | void setTitle(const QString &title); |
|
107 | 108 | QString title() const; |
|
108 | 109 | void setTitleFont(const QFont &font); |
|
109 | 110 | QFont titleFont() const; |
|
110 | 111 | void setTitleBrush(const QBrush &brush); |
|
111 | 112 | QBrush titleBrush() const; |
|
112 | 113 | |
|
113 | 114 | void setBackgroundBrush(const QBrush &brush); |
|
114 | 115 | QBrush backgroundBrush() const; |
|
115 | 116 | void setBackgroundPen(const QPen &pen); |
|
116 | 117 | QPen backgroundPen() const; |
|
117 | 118 | void setBackgroundVisible(bool visible = true); |
|
118 | 119 | bool isBackgroundVisible() const; |
|
119 | 120 | |
|
120 | 121 | void setDropShadowEnabled(bool enabled = true); |
|
121 | 122 | bool isDropShadowEnabled() const; |
|
123 | void setBackgroundRoundness(qreal diameter); | |
|
124 | qreal backgroundRoundness() const; | |
|
122 | 125 | void setAnimationOptions(AnimationOptions options); |
|
123 | 126 | AnimationOptions animationOptions() const; |
|
124 | 127 | |
|
125 | 128 | void zoomIn(); |
|
126 | 129 | void zoomOut(); |
|
127 | 130 | |
|
128 | 131 | void zoomIn(const QRectF &rect); |
|
129 | 132 | void zoom(qreal factor); |
|
130 | 133 | void zoomReset(); |
|
131 | 134 | bool isZoomed(); |
|
132 | 135 | |
|
133 | 136 | void scroll(qreal dx, qreal dy); |
|
134 | 137 | |
|
135 | 138 | QLegend *legend() const; |
|
136 | 139 | |
|
137 | 140 | void setMinimumMargins(const QMargins& margins); |
|
138 | 141 | QMargins minimumMargins() const; |
|
139 | 142 | |
|
140 | 143 | void setMargins(const QMargins &margins); |
|
141 | 144 | QMargins margins() const; |
|
142 | 145 | |
|
143 | 146 | QRectF plotArea() const; |
|
144 | 147 | void setPlotAreaBackgroundBrush(const QBrush &brush); |
|
145 | 148 | QBrush plotAreaBackgroundBrush() const; |
|
146 | 149 | void setPlotAreaBackgroundPen(const QPen &pen); |
|
147 | 150 | QPen plotAreaBackgroundPen() const; |
|
148 | 151 | void setPlotAreaBackgroundVisible(bool visible = true); |
|
149 | 152 | bool isPlotAreaBackgroundVisible() const; |
|
150 | 153 | |
|
151 | 154 | QPointF mapToValue(const QPointF &position, QAbstractSeries *series = 0); |
|
152 | 155 | QPointF mapToPosition(const QPointF &value, QAbstractSeries *series = 0); |
|
153 | 156 | |
|
154 | 157 | ChartType chartType() const; |
|
155 | 158 | |
|
156 | 159 | protected: |
|
157 | 160 | explicit QChart(QChart::ChartType type, QGraphicsItem *parent, Qt::WindowFlags wFlags); |
|
158 | 161 | QScopedPointer<QChartPrivate> d_ptr; |
|
159 | 162 | friend class QLegend; |
|
160 | 163 | friend class DeclarativeChart; |
|
161 | 164 | friend class ChartDataSet; |
|
162 | 165 | friend class ChartPresenter; |
|
163 | 166 | friend class ChartThemeManager; |
|
164 | 167 | friend class QAbstractSeries; |
|
165 | 168 | friend class QBoxPlotSeriesPrivate; |
|
166 | 169 | Q_DISABLE_COPY(QChart) |
|
167 | 170 | }; |
|
168 | 171 | |
|
169 | 172 | QTCOMMERCIALCHART_END_NAMESPACE |
|
170 | 173 | |
|
171 | 174 | Q_DECLARE_OPERATORS_FOR_FLAGS(QTCOMMERCIALCHART_NAMESPACE::QChart::AnimationOptions) |
|
172 | 175 | |
|
173 | 176 | #endif // QCHART_H |
@@ -1,1033 +1,1042 | |||
|
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 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 <QtTest/QtTest> |
|
22 | 22 | #include <qchartview.h> |
|
23 | 23 | #include <qlineseries.h> |
|
24 | 24 | #include <qareaseries.h> |
|
25 | 25 | #include <qscatterseries.h> |
|
26 | 26 | #include <qsplineseries.h> |
|
27 | 27 | #include <qpieseries.h> |
|
28 | 28 | #include <qabstractbarseries.h> |
|
29 | 29 | #include <qbarseries.h> |
|
30 | 30 | #include <qpercentbarseries.h> |
|
31 | 31 | #include <qstackedbarseries.h> |
|
32 | 32 | #include <qvalueaxis.h> |
|
33 | 33 | #include <qbarcategoryaxis.h> |
|
34 | 34 | #include "tst_definitions.h" |
|
35 | 35 | |
|
36 | 36 | QTCOMMERCIALCHART_USE_NAMESPACE |
|
37 | 37 | |
|
38 | 38 | Q_DECLARE_METATYPE(QAbstractAxis *) |
|
39 | 39 | Q_DECLARE_METATYPE(QValueAxis *) |
|
40 | 40 | Q_DECLARE_METATYPE(QBarCategoryAxis *) |
|
41 | 41 | Q_DECLARE_METATYPE(QAbstractSeries *) |
|
42 | 42 | Q_DECLARE_METATYPE(QChart::AnimationOption) |
|
43 | 43 | Q_DECLARE_METATYPE(QBrush) |
|
44 | 44 | Q_DECLARE_METATYPE(QPen) |
|
45 | 45 | Q_DECLARE_METATYPE(QChart::ChartTheme) |
|
46 | 46 | |
|
47 | 47 | class tst_QChart : public QObject |
|
48 | 48 | { |
|
49 | 49 | Q_OBJECT |
|
50 | 50 | |
|
51 | 51 | public slots: |
|
52 | 52 | void initTestCase(); |
|
53 | 53 | void cleanupTestCase(); |
|
54 | 54 | void init(); |
|
55 | 55 | void cleanup(); |
|
56 | 56 | |
|
57 | 57 | private slots: |
|
58 | 58 | void qchart_data(); |
|
59 | 59 | void qchart(); |
|
60 | 60 | void addSeries_data(); |
|
61 | 61 | void addSeries(); |
|
62 | 62 | void animationOptions_data(); |
|
63 | 63 | void animationOptions(); |
|
64 | 64 | void axisX_data(); |
|
65 | 65 | void axisX(); |
|
66 | 66 | void axisY_data(); |
|
67 | 67 | void axisY(); |
|
68 | 68 | void backgroundBrush_data(); |
|
69 | 69 | void backgroundBrush(); |
|
70 | 70 | void backgroundPen_data(); |
|
71 | 71 | void backgroundPen(); |
|
72 | 72 | void isBackgroundVisible_data(); |
|
73 | 73 | void isBackgroundVisible(); |
|
74 | 74 | void plotAreaBackgroundBrush_data(); |
|
75 | 75 | void plotAreaBackgroundBrush(); |
|
76 | 76 | void plotAreaBackgroundPen_data(); |
|
77 | 77 | void plotAreaBackgroundPen(); |
|
78 | 78 | void isPlotAreaBackgroundVisible_data(); |
|
79 | 79 | void isPlotAreaBackgroundVisible(); |
|
80 | 80 | void legend_data(); |
|
81 | 81 | void legend(); |
|
82 | 82 | void plotArea_data(); |
|
83 | 83 | void plotArea(); |
|
84 | 84 | void removeAllSeries_data(); |
|
85 | 85 | void removeAllSeries(); |
|
86 | 86 | void removeSeries_data(); |
|
87 | 87 | void removeSeries(); |
|
88 | 88 | void scroll_right_data(); |
|
89 | 89 | void scroll_right(); |
|
90 | 90 | void scroll_left_data(); |
|
91 | 91 | void scroll_left(); |
|
92 | 92 | void scroll_up_data(); |
|
93 | 93 | void scroll_up(); |
|
94 | 94 | void scroll_down_data(); |
|
95 | 95 | void scroll_down(); |
|
96 | 96 | void theme_data(); |
|
97 | 97 | void theme(); |
|
98 | 98 | void title_data(); |
|
99 | 99 | void title(); |
|
100 | 100 | void titleBrush_data(); |
|
101 | 101 | void titleBrush(); |
|
102 | 102 | void titleFont_data(); |
|
103 | 103 | void titleFont(); |
|
104 | 104 | void zoomIn_data(); |
|
105 | 105 | void zoomIn(); |
|
106 | 106 | void zoomOut_data(); |
|
107 | 107 | void zoomOut(); |
|
108 | 108 | void zoomReset(); |
|
109 | 109 | void createDefaultAxesForLineSeries_data(); |
|
110 | 110 | void createDefaultAxesForLineSeries(); |
|
111 | 111 | void axisPolarOrientation(); |
|
112 | void backgroundRoundness(); | |
|
112 | 113 | private: |
|
113 | 114 | void createTestData(); |
|
114 | 115 | |
|
115 | 116 | private: |
|
116 | 117 | QChartView* m_view; |
|
117 | 118 | QChart* m_chart; |
|
118 | 119 | }; |
|
119 | 120 | |
|
120 | 121 | void tst_QChart::initTestCase() |
|
121 | 122 | { |
|
122 | 123 | |
|
123 | 124 | } |
|
124 | 125 | |
|
125 | 126 | void tst_QChart::cleanupTestCase() |
|
126 | 127 | { |
|
127 | 128 | |
|
128 | 129 | } |
|
129 | 130 | |
|
130 | 131 | void tst_QChart::init() |
|
131 | 132 | { |
|
132 | 133 | m_view = new QChartView(newQChartOrQPolarChart()); |
|
133 | 134 | m_chart = m_view->chart(); |
|
134 | 135 | } |
|
135 | 136 | |
|
136 | 137 | void tst_QChart::cleanup() |
|
137 | 138 | { |
|
138 | 139 | delete m_view; |
|
139 | 140 | m_view = 0; |
|
140 | 141 | m_chart = 0; |
|
141 | 142 | } |
|
142 | 143 | |
|
143 | 144 | |
|
144 | 145 | void tst_QChart::createTestData() |
|
145 | 146 | { |
|
146 | 147 | QLineSeries* series0 = new QLineSeries(this); |
|
147 | 148 | *series0 << QPointF(0, 0) << QPointF(100, 100); |
|
148 | 149 | m_chart->addSeries(series0); |
|
149 | 150 | m_view->show(); |
|
150 | 151 | QTest::qWaitForWindowShown(m_view); |
|
151 | 152 | } |
|
152 | 153 | |
|
153 | 154 | void tst_QChart::qchart_data() |
|
154 | 155 | { |
|
155 | 156 | } |
|
156 | 157 | |
|
157 | 158 | void tst_QChart::qchart() |
|
158 | 159 | { |
|
159 | 160 | QVERIFY(m_chart); |
|
160 | 161 | QVERIFY(m_chart->legend()); |
|
161 | 162 | QVERIFY(m_chart->legend()->isVisible()); |
|
162 | 163 | |
|
163 | 164 | QCOMPARE(m_chart->animationOptions(), QChart::NoAnimation); |
|
164 | 165 | QVERIFY(!m_chart->axisX()); |
|
165 | 166 | QVERIFY(!m_chart->axisY()); |
|
166 | 167 | QVERIFY(m_chart->backgroundBrush()!=QBrush()); |
|
167 | 168 | QVERIFY(m_chart->backgroundPen()!=QPen()); |
|
168 | 169 | QCOMPARE(m_chart->isBackgroundVisible(), true); |
|
169 | 170 | QVERIFY(m_chart->plotArea().top()==0); |
|
170 | 171 | QVERIFY(m_chart->plotArea().left()==0); |
|
171 | 172 | QVERIFY(m_chart->plotArea().right()==0); |
|
172 | 173 | QVERIFY(m_chart->plotArea().bottom()==0); |
|
173 | 174 | QCOMPARE(m_chart->theme(), QChart::ChartThemeLight); |
|
174 | 175 | QCOMPARE(m_chart->title(), QString()); |
|
175 | 176 | |
|
176 | 177 | //QCOMPARE(m_chart->titleBrush(),QBrush()); |
|
177 | 178 | //QCOMPARE(m_chart->titleFont(),QFont()); |
|
178 | 179 | |
|
179 | 180 | m_chart->removeAllSeries(); |
|
180 | 181 | m_chart->scroll(0,0); |
|
181 | 182 | |
|
182 | 183 | m_chart->zoomIn(); |
|
183 | 184 | m_chart->zoomIn(QRectF()); |
|
184 | 185 | m_chart->zoomOut(); |
|
185 | 186 | |
|
186 | 187 | m_view->show(); |
|
187 | 188 | |
|
188 | 189 | QVERIFY(m_chart->plotArea().top()>0); |
|
189 | 190 | QVERIFY(m_chart->plotArea().left()>0); |
|
190 | 191 | QVERIFY(m_chart->plotArea().right()>0); |
|
191 | 192 | QVERIFY(m_chart->plotArea().bottom()>0); |
|
192 | 193 | } |
|
193 | 194 | |
|
194 | 195 | void tst_QChart::addSeries_data() |
|
195 | 196 | { |
|
196 | 197 | QTest::addColumn<QAbstractSeries *>("series"); |
|
197 | 198 | |
|
198 | 199 | QAbstractSeries* line = new QLineSeries(this); |
|
199 | 200 | QAbstractSeries* area = new QAreaSeries(static_cast<QLineSeries*>(line)); |
|
200 | 201 | QAbstractSeries* scatter = new QScatterSeries(this); |
|
201 | 202 | QAbstractSeries* spline = new QSplineSeries(this); |
|
202 | 203 | |
|
203 | 204 | QTest::newRow("lineSeries") << line; |
|
204 | 205 | QTest::newRow("areaSeries") << area; |
|
205 | 206 | QTest::newRow("scatterSeries") << scatter; |
|
206 | 207 | QTest::newRow("splineSeries") << spline; |
|
207 | 208 | |
|
208 | 209 | if (!isPolarTest()) { |
|
209 | 210 | QAbstractSeries* pie = new QPieSeries(this); |
|
210 | 211 | QAbstractSeries* bar = new QBarSeries(this); |
|
211 | 212 | QAbstractSeries* percent = new QPercentBarSeries(this); |
|
212 | 213 | QAbstractSeries* stacked = new QStackedBarSeries(this); |
|
213 | 214 | QTest::newRow("pieSeries") << pie; |
|
214 | 215 | QTest::newRow("barSeries") << bar; |
|
215 | 216 | QTest::newRow("percentBarSeries") << percent; |
|
216 | 217 | QTest::newRow("stackedBarSeries") << stacked; |
|
217 | 218 | } |
|
218 | 219 | } |
|
219 | 220 | |
|
220 | 221 | void tst_QChart::addSeries() |
|
221 | 222 | { |
|
222 | 223 | QFETCH(QAbstractSeries *, series); |
|
223 | 224 | m_view->show(); |
|
224 | 225 | QTest::qWaitForWindowShown(m_view); |
|
225 | 226 | QVERIFY(!series->chart()); |
|
226 | 227 | QCOMPARE(m_chart->series().count(), 0); |
|
227 | 228 | m_chart->addSeries(series); |
|
228 | 229 | QCOMPARE(m_chart->series().count(), 1); |
|
229 | 230 | QCOMPARE(m_chart->series().first(), series); |
|
230 | 231 | QVERIFY(series->chart() == m_chart); |
|
231 | 232 | m_chart->createDefaultAxes(); |
|
232 | 233 | if(series->type()!=QAbstractSeries::SeriesTypePie){ |
|
233 | 234 | QVERIFY(m_chart->axisY(series)); |
|
234 | 235 | QVERIFY(m_chart->axisX(series)); |
|
235 | 236 | }else{ |
|
236 | 237 | QVERIFY(!m_chart->axisY(series)); |
|
237 | 238 | QVERIFY(!m_chart->axisX(series)); |
|
238 | 239 | } |
|
239 | 240 | m_chart->removeSeries(series); |
|
240 | 241 | QVERIFY(!series->chart()); |
|
241 | 242 | QCOMPARE(m_chart->series().count(), 0); |
|
242 | 243 | } |
|
243 | 244 | |
|
244 | 245 | void tst_QChart::animationOptions_data() |
|
245 | 246 | { |
|
246 | 247 | QTest::addColumn<QChart::AnimationOption>("animationOptions"); |
|
247 | 248 | QTest::newRow("AllAnimations") << QChart::AllAnimations; |
|
248 | 249 | QTest::newRow("NoAnimation") << QChart::NoAnimation; |
|
249 | 250 | QTest::newRow("GridAxisAnimations") << QChart::GridAxisAnimations; |
|
250 | 251 | QTest::newRow("SeriesAnimations") << QChart::SeriesAnimations; |
|
251 | 252 | } |
|
252 | 253 | |
|
253 | 254 | void tst_QChart::animationOptions() |
|
254 | 255 | { |
|
255 | 256 | createTestData(); |
|
256 | 257 | QFETCH(QChart::AnimationOption, animationOptions); |
|
257 | 258 | m_chart->setAnimationOptions(animationOptions); |
|
258 | 259 | QCOMPARE(m_chart->animationOptions(), animationOptions); |
|
259 | 260 | } |
|
260 | 261 | |
|
261 | 262 | void tst_QChart::axisX_data() |
|
262 | 263 | { |
|
263 | 264 | |
|
264 | 265 | QTest::addColumn<QAbstractAxis*>("axis"); |
|
265 | 266 | QTest::addColumn<QAbstractSeries *>("series"); |
|
266 | 267 | |
|
267 | 268 | QTest::newRow("categories,lineSeries") << (QAbstractAxis*) new QBarCategoryAxis() << (QAbstractSeries*) new QLineSeries(this); |
|
268 | 269 | QTest::newRow("categories,areaSeries") << (QAbstractAxis*) new QBarCategoryAxis() << (QAbstractSeries*) new QAreaSeries(new QLineSeries(this)); |
|
269 | 270 | QTest::newRow("categories,scatterSeries") << (QAbstractAxis*) new QBarCategoryAxis() << (QAbstractSeries*) new QScatterSeries(this); |
|
270 | 271 | QTest::newRow("categories,splineSeries") << (QAbstractAxis*) new QBarCategoryAxis() << (QAbstractSeries*) new QSplineSeries(this); |
|
271 | 272 | if (!isPolarTest()) { |
|
272 | 273 | QTest::newRow("categories,pieSeries") << (QAbstractAxis*) new QBarCategoryAxis() << (QAbstractSeries*) new QPieSeries(this); |
|
273 | 274 | QTest::newRow("categories,barSeries") << (QAbstractAxis*) new QBarCategoryAxis() << (QAbstractSeries*) new QBarSeries(this); |
|
274 | 275 | QTest::newRow("categories,percentBarSeries") << (QAbstractAxis*) new QBarCategoryAxis() << (QAbstractSeries*) new QPercentBarSeries(this); |
|
275 | 276 | QTest::newRow("categories,stackedBarSeries") << (QAbstractAxis*) new QBarCategoryAxis() << (QAbstractSeries*) new QStackedBarSeries(this); |
|
276 | 277 | } |
|
277 | 278 | |
|
278 | 279 | QTest::newRow("value,lineSeries") << (QAbstractAxis*) new QValueAxis() << (QAbstractSeries*) new QLineSeries(this); |
|
279 | 280 | QTest::newRow("value,areaSeries") << (QAbstractAxis*) new QValueAxis() << (QAbstractSeries*) new QAreaSeries(new QLineSeries(this)); |
|
280 | 281 | QTest::newRow("value,scatterSeries") << (QAbstractAxis*) new QValueAxis() << (QAbstractSeries*) new QScatterSeries(this); |
|
281 | 282 | QTest::newRow("value,splineSeries") << (QAbstractAxis*) new QValueAxis() << (QAbstractSeries*) new QSplineSeries(this); |
|
282 | 283 | if (!isPolarTest()) { |
|
283 | 284 | QTest::newRow("value,pieSeries") << (QAbstractAxis*) new QValueAxis() << (QAbstractSeries*) new QPieSeries(this); |
|
284 | 285 | QTest::newRow("value,barSeries") << (QAbstractAxis*) new QValueAxis() << (QAbstractSeries*) new QBarSeries(this); |
|
285 | 286 | QTest::newRow("value,percentBarSeries") << (QAbstractAxis*) new QValueAxis() << (QAbstractSeries*) new QPercentBarSeries(this); |
|
286 | 287 | QTest::newRow("value,stackedBarSeries") << (QAbstractAxis*) new QValueAxis() << (QAbstractSeries*) new QStackedBarSeries(this); |
|
287 | 288 | } |
|
288 | 289 | } |
|
289 | 290 | |
|
290 | 291 | void tst_QChart::axisX() |
|
291 | 292 | { |
|
292 | 293 | QFETCH(QAbstractAxis*, axis); |
|
293 | 294 | QFETCH(QAbstractSeries*, series); |
|
294 | 295 | QVERIFY(!m_chart->axisX()); |
|
295 | 296 | m_view->show(); |
|
296 | 297 | QTest::qWaitForWindowShown(m_view); |
|
297 | 298 | m_chart->addSeries(series); |
|
298 | 299 | m_chart->setAxisX(axis,series); |
|
299 | 300 | QVERIFY(m_chart->axisX(series)==axis); |
|
300 | 301 | } |
|
301 | 302 | |
|
302 | 303 | void tst_QChart::axisY_data() |
|
303 | 304 | { |
|
304 | 305 | axisX_data(); |
|
305 | 306 | } |
|
306 | 307 | |
|
307 | 308 | |
|
308 | 309 | void tst_QChart::axisY() |
|
309 | 310 | { |
|
310 | 311 | QFETCH(QAbstractAxis*, axis); |
|
311 | 312 | QFETCH(QAbstractSeries*, series); |
|
312 | 313 | QVERIFY(!m_chart->axisY()); |
|
313 | 314 | m_view->show(); |
|
314 | 315 | QTest::qWaitForWindowShown(m_view); |
|
315 | 316 | m_chart->addSeries(series); |
|
316 | 317 | m_chart->setAxisY(axis,series); |
|
317 | 318 | QVERIFY(m_chart->axisY(series)==axis); |
|
318 | 319 | } |
|
319 | 320 | |
|
320 | 321 | void tst_QChart::backgroundBrush_data() |
|
321 | 322 | { |
|
322 | 323 | QTest::addColumn<QBrush>("backgroundBrush"); |
|
323 | 324 | QTest::newRow("null") << QBrush(); |
|
324 | 325 | QTest::newRow("blue") << QBrush(Qt::blue); |
|
325 | 326 | QTest::newRow("white") << QBrush(Qt::white); |
|
326 | 327 | QTest::newRow("black") << QBrush(Qt::black); |
|
327 | 328 | } |
|
328 | 329 | |
|
329 | 330 | void tst_QChart::backgroundBrush() |
|
330 | 331 | { |
|
331 | 332 | QFETCH(QBrush, backgroundBrush); |
|
332 | 333 | m_chart->setBackgroundBrush(backgroundBrush); |
|
333 | 334 | QCOMPARE(m_chart->backgroundBrush(), backgroundBrush); |
|
334 | 335 | } |
|
335 | 336 | |
|
336 | 337 | void tst_QChart::backgroundPen_data() |
|
337 | 338 | { |
|
338 | 339 | QTest::addColumn<QPen>("backgroundPen"); |
|
339 | 340 | QTest::newRow("null") << QPen(); |
|
340 | 341 | QTest::newRow("blue") << QPen(Qt::blue); |
|
341 | 342 | QTest::newRow("white") << QPen(Qt::white); |
|
342 | 343 | QTest::newRow("black") << QPen(Qt::black); |
|
343 | 344 | } |
|
344 | 345 | |
|
345 | 346 | |
|
346 | 347 | void tst_QChart::backgroundPen() |
|
347 | 348 | { |
|
348 | 349 | QFETCH(QPen, backgroundPen); |
|
349 | 350 | m_chart->setBackgroundPen(backgroundPen); |
|
350 | 351 | QCOMPARE(m_chart->backgroundPen(), backgroundPen); |
|
351 | 352 | } |
|
352 | 353 | |
|
353 | 354 | void tst_QChart::isBackgroundVisible_data() |
|
354 | 355 | { |
|
355 | 356 | QTest::addColumn<bool>("isBackgroundVisible"); |
|
356 | 357 | QTest::newRow("true") << true; |
|
357 | 358 | QTest::newRow("false") << false; |
|
358 | 359 | } |
|
359 | 360 | |
|
360 | 361 | void tst_QChart::isBackgroundVisible() |
|
361 | 362 | { |
|
362 | 363 | QFETCH(bool, isBackgroundVisible); |
|
363 | 364 | m_chart->setBackgroundVisible(isBackgroundVisible); |
|
364 | 365 | QCOMPARE(m_chart->isBackgroundVisible(), isBackgroundVisible); |
|
365 | 366 | } |
|
366 | 367 | |
|
367 | 368 | void tst_QChart::plotAreaBackgroundBrush_data() |
|
368 | 369 | { |
|
369 | 370 | QTest::addColumn<QBrush>("plotAreaBackgroundBrush"); |
|
370 | 371 | QTest::newRow("null") << QBrush(); |
|
371 | 372 | QTest::newRow("blue") << QBrush(Qt::blue); |
|
372 | 373 | QTest::newRow("white") << QBrush(Qt::white); |
|
373 | 374 | QTest::newRow("black") << QBrush(Qt::black); |
|
374 | 375 | } |
|
375 | 376 | |
|
376 | 377 | void tst_QChart::plotAreaBackgroundBrush() |
|
377 | 378 | { |
|
378 | 379 | QFETCH(QBrush, plotAreaBackgroundBrush); |
|
379 | 380 | m_chart->setPlotAreaBackgroundBrush(plotAreaBackgroundBrush); |
|
380 | 381 | QCOMPARE(m_chart->plotAreaBackgroundBrush(), plotAreaBackgroundBrush); |
|
381 | 382 | } |
|
382 | 383 | |
|
383 | 384 | void tst_QChart::plotAreaBackgroundPen_data() |
|
384 | 385 | { |
|
385 | 386 | QTest::addColumn<QPen>("plotAreaBackgroundPen"); |
|
386 | 387 | QTest::newRow("null") << QPen(); |
|
387 | 388 | QTest::newRow("blue") << QPen(Qt::blue); |
|
388 | 389 | QTest::newRow("white") << QPen(Qt::white); |
|
389 | 390 | QTest::newRow("black") << QPen(Qt::black); |
|
390 | 391 | } |
|
391 | 392 | |
|
392 | 393 | |
|
393 | 394 | void tst_QChart::plotAreaBackgroundPen() |
|
394 | 395 | { |
|
395 | 396 | QFETCH(QPen, plotAreaBackgroundPen); |
|
396 | 397 | m_chart->setPlotAreaBackgroundPen(plotAreaBackgroundPen); |
|
397 | 398 | QCOMPARE(m_chart->plotAreaBackgroundPen(), plotAreaBackgroundPen); |
|
398 | 399 | } |
|
399 | 400 | |
|
400 | 401 | void tst_QChart::isPlotAreaBackgroundVisible_data() |
|
401 | 402 | { |
|
402 | 403 | QTest::addColumn<bool>("isPlotAreaBackgroundVisible"); |
|
403 | 404 | QTest::newRow("true") << true; |
|
404 | 405 | QTest::newRow("false") << false; |
|
405 | 406 | } |
|
406 | 407 | |
|
407 | 408 | void tst_QChart::isPlotAreaBackgroundVisible() |
|
408 | 409 | { |
|
409 | 410 | QFETCH(bool, isPlotAreaBackgroundVisible); |
|
410 | 411 | m_chart->setPlotAreaBackgroundVisible(isPlotAreaBackgroundVisible); |
|
411 | 412 | QCOMPARE(m_chart->isPlotAreaBackgroundVisible(), isPlotAreaBackgroundVisible); |
|
412 | 413 | } |
|
413 | 414 | void tst_QChart::legend_data() |
|
414 | 415 | { |
|
415 | 416 | |
|
416 | 417 | } |
|
417 | 418 | |
|
418 | 419 | void tst_QChart::legend() |
|
419 | 420 | { |
|
420 | 421 | QLegend *legend = m_chart->legend(); |
|
421 | 422 | QVERIFY(legend); |
|
422 | 423 | |
|
423 | 424 | // Colors related signals |
|
424 | 425 | QSignalSpy colorSpy(legend, SIGNAL(colorChanged(QColor))); |
|
425 | 426 | QSignalSpy borderColorSpy(legend, SIGNAL(borderColorChanged(QColor))); |
|
426 | 427 | QSignalSpy labelColorSpy(legend, SIGNAL(labelColorChanged(QColor))); |
|
427 | 428 | |
|
428 | 429 | // colorChanged |
|
429 | 430 | legend->setColor(QColor("aliceblue")); |
|
430 | 431 | QCOMPARE(colorSpy.count(), 1); |
|
431 | 432 | QBrush b = legend->brush(); |
|
432 | 433 | b.setColor(QColor("aqua")); |
|
433 | 434 | legend->setBrush(b); |
|
434 | 435 | QCOMPARE(colorSpy.count(), 2); |
|
435 | 436 | |
|
436 | 437 | // borderColorChanged |
|
437 | 438 | legend->setBorderColor(QColor("aliceblue")); |
|
438 | 439 | QCOMPARE(borderColorSpy.count(), 1); |
|
439 | 440 | QPen p = legend->pen(); |
|
440 | 441 | p.setColor(QColor("aqua")); |
|
441 | 442 | legend->setPen(p); |
|
442 | 443 | QCOMPARE(borderColorSpy.count(), 2); |
|
443 | 444 | |
|
444 | 445 | // labelColorChanged |
|
445 | 446 | legend->setLabelColor(QColor("lightsalmon")); |
|
446 | 447 | QCOMPARE(labelColorSpy.count(), 1); |
|
447 | 448 | b = legend->labelBrush(); |
|
448 | 449 | b.setColor(QColor("lightseagreen")); |
|
449 | 450 | legend->setLabelBrush(b); |
|
450 | 451 | QCOMPARE(labelColorSpy.count(), 2); |
|
451 | 452 | |
|
452 | 453 | // fontChanged |
|
453 | 454 | QSignalSpy fontSpy(legend, SIGNAL(fontChanged(QFont))); |
|
454 | 455 | QFont f = legend->font(); |
|
455 | 456 | f.setBold(!f.bold()); |
|
456 | 457 | legend->setFont(f); |
|
457 | 458 | QCOMPARE(fontSpy.count(), 1); |
|
458 | 459 | } |
|
459 | 460 | |
|
460 | 461 | void tst_QChart::plotArea_data() |
|
461 | 462 | { |
|
462 | 463 | |
|
463 | 464 | } |
|
464 | 465 | |
|
465 | 466 | void tst_QChart::plotArea() |
|
466 | 467 | { |
|
467 | 468 | createTestData(); |
|
468 | 469 | QRectF rect = m_chart->geometry(); |
|
469 | 470 | QVERIFY(m_chart->plotArea().isValid()); |
|
470 | 471 | QVERIFY(m_chart->plotArea().height() < rect.height()); |
|
471 | 472 | QVERIFY(m_chart->plotArea().width() < rect.width()); |
|
472 | 473 | } |
|
473 | 474 | |
|
474 | 475 | void tst_QChart::removeAllSeries_data() |
|
475 | 476 | { |
|
476 | 477 | |
|
477 | 478 | } |
|
478 | 479 | |
|
479 | 480 | void tst_QChart::removeAllSeries() |
|
480 | 481 | { |
|
481 | 482 | QLineSeries* series0 = new QLineSeries(this); |
|
482 | 483 | QLineSeries* series1 = new QLineSeries(this); |
|
483 | 484 | QLineSeries* series2 = new QLineSeries(this); |
|
484 | 485 | QSignalSpy deleteSpy1(series0, SIGNAL(destroyed())); |
|
485 | 486 | QSignalSpy deleteSpy2(series1, SIGNAL(destroyed())); |
|
486 | 487 | QSignalSpy deleteSpy3(series2, SIGNAL(destroyed())); |
|
487 | 488 | |
|
488 | 489 | m_chart->addSeries(series0); |
|
489 | 490 | m_chart->addSeries(series1); |
|
490 | 491 | m_chart->addSeries(series2); |
|
491 | 492 | m_view->show(); |
|
492 | 493 | QTest::qWaitForWindowShown(m_view); |
|
493 | 494 | m_chart->createDefaultAxes(); |
|
494 | 495 | QCOMPARE(m_chart->axes().count(), 2); |
|
495 | 496 | QVERIFY(m_chart->axisY(series0)!=0); |
|
496 | 497 | QVERIFY(m_chart->axisY(series1)!=0); |
|
497 | 498 | QVERIFY(m_chart->axisY(series2)!=0); |
|
498 | 499 | |
|
499 | 500 | m_chart->removeAllSeries(); |
|
500 | 501 | QCOMPARE(m_chart->axes().count(), 2); |
|
501 | 502 | QVERIFY(m_chart->axisX() != 0); |
|
502 | 503 | QVERIFY(m_chart->axisY() != 0); |
|
503 | 504 | QCOMPARE(deleteSpy1.count(), 1); |
|
504 | 505 | QCOMPARE(deleteSpy2.count(), 1); |
|
505 | 506 | QCOMPARE(deleteSpy3.count(), 1); |
|
506 | 507 | } |
|
507 | 508 | |
|
508 | 509 | void tst_QChart::removeSeries_data() |
|
509 | 510 | { |
|
510 | 511 | axisX_data(); |
|
511 | 512 | } |
|
512 | 513 | |
|
513 | 514 | void tst_QChart::removeSeries() |
|
514 | 515 | { |
|
515 | 516 | QFETCH(QAbstractAxis *, axis); |
|
516 | 517 | QFETCH(QAbstractSeries *, series); |
|
517 | 518 | QSignalSpy deleteSpy(series, SIGNAL(destroyed())); |
|
518 | 519 | m_view->show(); |
|
519 | 520 | QTest::qWaitForWindowShown(m_view); |
|
520 | 521 | if(!axis) axis = m_chart->axisY(); |
|
521 | 522 | m_chart->addSeries(series); |
|
522 | 523 | m_chart->setAxisY(axis,series); |
|
523 | 524 | QCOMPARE(m_chart->axisY(series),axis); |
|
524 | 525 | m_chart->removeSeries(series); |
|
525 | 526 | QCOMPARE(m_chart->axes().count(), 1); |
|
526 | 527 | QVERIFY(m_chart->axisY() != 0); |
|
527 | 528 | QVERIFY(m_chart->axisY(series)==0); |
|
528 | 529 | QCOMPARE(deleteSpy.count(), 0); |
|
529 | 530 | } |
|
530 | 531 | |
|
531 | 532 | void tst_QChart::scroll_right_data() |
|
532 | 533 | { |
|
533 | 534 | QTest::addColumn<QAbstractSeries *>("series"); |
|
534 | 535 | |
|
535 | 536 | QLineSeries* series0 = new QLineSeries(this); |
|
536 | 537 | *series0 << QPointF(0, 0) << QPointF(100, 100); |
|
537 | 538 | |
|
538 | 539 | QTest::newRow("lineSeries") << (QAbstractSeries*) series0; |
|
539 | 540 | |
|
540 | 541 | |
|
541 | 542 | } |
|
542 | 543 | |
|
543 | 544 | void tst_QChart::scroll_right() |
|
544 | 545 | { |
|
545 | 546 | QFETCH(QAbstractSeries *, series); |
|
546 | 547 | m_chart->addSeries(series); |
|
547 | 548 | m_chart->createDefaultAxes(); |
|
548 | 549 | m_view->show(); |
|
549 | 550 | QTest::qWaitForWindowShown(m_view); |
|
550 | 551 | QAbstractAxis * axis = m_chart->axisX(); |
|
551 | 552 | QVERIFY(axis!=0); |
|
552 | 553 | |
|
553 | 554 | switch(axis->type()) |
|
554 | 555 | { |
|
555 | 556 | case QAbstractAxis::AxisTypeValue:{ |
|
556 | 557 | QValueAxis* vaxis = qobject_cast<QValueAxis*>(axis); |
|
557 | 558 | QVERIFY(vaxis!=0); |
|
558 | 559 | qreal min = vaxis->min(); |
|
559 | 560 | qreal max = vaxis->max(); |
|
560 | 561 | QVERIFY(max>min); |
|
561 | 562 | m_chart->scroll(50, 0); |
|
562 | 563 | QVERIFY(min<vaxis->min()); |
|
563 | 564 | QVERIFY(max<vaxis->max()); |
|
564 | 565 | break; |
|
565 | 566 | } |
|
566 | 567 | case QAbstractAxis::AxisTypeBarCategory:{ |
|
567 | 568 | QBarCategoryAxis* caxis = qobject_cast<QBarCategoryAxis*>(axis); |
|
568 | 569 | QVERIFY(caxis!=0); |
|
569 | 570 | qreal min = caxis->min().toDouble(); |
|
570 | 571 | qreal max = caxis->max().toDouble(); |
|
571 | 572 | m_chart->scroll(50, 0); |
|
572 | 573 | QVERIFY(min<caxis->min().toDouble()); |
|
573 | 574 | QVERIFY(max<caxis->max().toDouble()); |
|
574 | 575 | break; |
|
575 | 576 | } |
|
576 | 577 | default: |
|
577 | 578 | qFatal("Unsupported type"); |
|
578 | 579 | break; |
|
579 | 580 | } |
|
580 | 581 | } |
|
581 | 582 | |
|
582 | 583 | void tst_QChart::scroll_left_data() |
|
583 | 584 | { |
|
584 | 585 | scroll_right_data(); |
|
585 | 586 | } |
|
586 | 587 | |
|
587 | 588 | void tst_QChart::scroll_left() |
|
588 | 589 | { |
|
589 | 590 | QFETCH(QAbstractSeries *, series); |
|
590 | 591 | m_chart->addSeries(series); |
|
591 | 592 | m_chart->createDefaultAxes(); |
|
592 | 593 | m_view->show(); |
|
593 | 594 | QTest::qWaitForWindowShown(m_view); |
|
594 | 595 | QAbstractAxis * axis = m_chart->axisX(); |
|
595 | 596 | QVERIFY(axis!=0); |
|
596 | 597 | |
|
597 | 598 | switch(axis->type()) |
|
598 | 599 | { |
|
599 | 600 | case QAbstractAxis::AxisTypeValue:{ |
|
600 | 601 | QValueAxis* vaxis = qobject_cast<QValueAxis*>(axis); |
|
601 | 602 | QVERIFY(vaxis!=0); |
|
602 | 603 | qreal min = vaxis->min(); |
|
603 | 604 | qreal max = vaxis->max(); |
|
604 | 605 | m_chart->scroll(-50, 0); |
|
605 | 606 | QVERIFY(min>vaxis->min()); |
|
606 | 607 | QVERIFY(max>vaxis->max()); |
|
607 | 608 | break; |
|
608 | 609 | } |
|
609 | 610 | case QAbstractAxis::AxisTypeBarCategory:{ |
|
610 | 611 | QBarCategoryAxis* caxis = qobject_cast<QBarCategoryAxis*>(axis); |
|
611 | 612 | QVERIFY(caxis!=0); |
|
612 | 613 | qreal min = caxis->min().toDouble(); |
|
613 | 614 | qreal max = caxis->max().toDouble(); |
|
614 | 615 | m_chart->scroll(-50, 0); |
|
615 | 616 | QVERIFY(min>caxis->min().toDouble()); |
|
616 | 617 | QVERIFY(max>caxis->max().toDouble()); |
|
617 | 618 | break; |
|
618 | 619 | } |
|
619 | 620 | default: |
|
620 | 621 | qFatal("Unsupported type"); |
|
621 | 622 | break; |
|
622 | 623 | } |
|
623 | 624 | } |
|
624 | 625 | |
|
625 | 626 | void tst_QChart::scroll_up_data() |
|
626 | 627 | { |
|
627 | 628 | scroll_right_data(); |
|
628 | 629 | } |
|
629 | 630 | |
|
630 | 631 | void tst_QChart::scroll_up() |
|
631 | 632 | { |
|
632 | 633 | QFETCH(QAbstractSeries *, series); |
|
633 | 634 | m_chart->addSeries(series); |
|
634 | 635 | m_chart->createDefaultAxes(); |
|
635 | 636 | m_view->show(); |
|
636 | 637 | QTest::qWaitForWindowShown(m_view); |
|
637 | 638 | QAbstractAxis * axis = m_chart->axisY(); |
|
638 | 639 | QVERIFY(axis!=0); |
|
639 | 640 | |
|
640 | 641 | switch(axis->type()) |
|
641 | 642 | { |
|
642 | 643 | case QAbstractAxis::AxisTypeValue:{ |
|
643 | 644 | QValueAxis* vaxis = qobject_cast<QValueAxis*>(axis); |
|
644 | 645 | QVERIFY(vaxis!=0); |
|
645 | 646 | qreal min = vaxis->min(); |
|
646 | 647 | qreal max = vaxis->max(); |
|
647 | 648 | m_chart->scroll(0, 50); |
|
648 | 649 | QVERIFY(min<vaxis->min()); |
|
649 | 650 | QVERIFY(max<vaxis->max()); |
|
650 | 651 | break; |
|
651 | 652 | } |
|
652 | 653 | case QAbstractAxis::AxisTypeBarCategory:{ |
|
653 | 654 | QBarCategoryAxis* caxis = qobject_cast<QBarCategoryAxis*>(axis); |
|
654 | 655 | QVERIFY(caxis!=0); |
|
655 | 656 | qreal min = caxis->min().toDouble(); |
|
656 | 657 | qreal max = caxis->max().toDouble(); |
|
657 | 658 | m_chart->scroll(0, 50); |
|
658 | 659 | QVERIFY(min<caxis->min().toDouble()); |
|
659 | 660 | QVERIFY(max<caxis->max().toDouble()); |
|
660 | 661 | break; |
|
661 | 662 | } |
|
662 | 663 | default: |
|
663 | 664 | qFatal("Unsupported type"); |
|
664 | 665 | break; |
|
665 | 666 | } |
|
666 | 667 | } |
|
667 | 668 | |
|
668 | 669 | void tst_QChart::scroll_down_data() |
|
669 | 670 | { |
|
670 | 671 | scroll_right_data(); |
|
671 | 672 | } |
|
672 | 673 | |
|
673 | 674 | void tst_QChart::scroll_down() |
|
674 | 675 | { |
|
675 | 676 | QFETCH(QAbstractSeries *, series); |
|
676 | 677 | m_chart->addSeries(series); |
|
677 | 678 | m_chart->createDefaultAxes(); |
|
678 | 679 | m_view->show(); |
|
679 | 680 | QTest::qWaitForWindowShown(m_view); |
|
680 | 681 | QAbstractAxis * axis = m_chart->axisY(); |
|
681 | 682 | QVERIFY(axis!=0); |
|
682 | 683 | |
|
683 | 684 | switch(axis->type()) |
|
684 | 685 | { |
|
685 | 686 | case QAbstractAxis::AxisTypeValue:{ |
|
686 | 687 | QValueAxis* vaxis = qobject_cast<QValueAxis*>(axis); |
|
687 | 688 | QVERIFY(vaxis!=0); |
|
688 | 689 | qreal min = vaxis->min(); |
|
689 | 690 | qreal max = vaxis->max(); |
|
690 | 691 | m_chart->scroll(0, -50); |
|
691 | 692 | QVERIFY(min>vaxis->min()); |
|
692 | 693 | QVERIFY(max>vaxis->max()); |
|
693 | 694 | break; |
|
694 | 695 | } |
|
695 | 696 | case QAbstractAxis::AxisTypeBarCategory:{ |
|
696 | 697 | QBarCategoryAxis* caxis = qobject_cast<QBarCategoryAxis*>(axis); |
|
697 | 698 | QVERIFY(caxis!=0); |
|
698 | 699 | qreal min = caxis->min().toDouble(); |
|
699 | 700 | qreal max = caxis->max().toDouble(); |
|
700 | 701 | m_chart->scroll(0, -50); |
|
701 | 702 | QVERIFY(min>caxis->min().toDouble()); |
|
702 | 703 | QVERIFY(max>caxis->max().toDouble()); |
|
703 | 704 | break; |
|
704 | 705 | } |
|
705 | 706 | default: |
|
706 | 707 | qFatal("Unsupported type"); |
|
707 | 708 | break; |
|
708 | 709 | } |
|
709 | 710 | } |
|
710 | 711 | |
|
711 | 712 | void tst_QChart::theme_data() |
|
712 | 713 | { |
|
713 | 714 | QTest::addColumn<QChart::ChartTheme>("theme"); |
|
714 | 715 | QTest::newRow("ChartThemeBlueCerulean") << QChart::ChartThemeBlueCerulean; |
|
715 | 716 | QTest::newRow("ChartThemeBlueIcy") << QChart::ChartThemeBlueIcy; |
|
716 | 717 | QTest::newRow("ChartThemeBlueNcs") << QChart::ChartThemeBlueNcs; |
|
717 | 718 | QTest::newRow("ChartThemeBrownSand") << QChart::ChartThemeBrownSand; |
|
718 | 719 | QTest::newRow("ChartThemeDark") << QChart::ChartThemeDark; |
|
719 | 720 | QTest::newRow("hartThemeHighContrast") << QChart::ChartThemeHighContrast; |
|
720 | 721 | QTest::newRow("ChartThemeLight") << QChart::ChartThemeLight; |
|
721 | 722 | } |
|
722 | 723 | |
|
723 | 724 | void tst_QChart::theme() |
|
724 | 725 | { |
|
725 | 726 | QFETCH(QChart::ChartTheme, theme); |
|
726 | 727 | createTestData(); |
|
727 | 728 | m_chart->setTheme(theme); |
|
728 | 729 | QVERIFY(m_chart->theme()==theme); |
|
729 | 730 | } |
|
730 | 731 | |
|
731 | 732 | void tst_QChart::title_data() |
|
732 | 733 | { |
|
733 | 734 | QTest::addColumn<QString>("title"); |
|
734 | 735 | QTest::newRow("null") << QString(); |
|
735 | 736 | QTest::newRow("foo") << QString("foo"); |
|
736 | 737 | } |
|
737 | 738 | |
|
738 | 739 | void tst_QChart::title() |
|
739 | 740 | { |
|
740 | 741 | QFETCH(QString, title); |
|
741 | 742 | m_chart->setTitle(title); |
|
742 | 743 | QCOMPARE(m_chart->title(), title); |
|
743 | 744 | } |
|
744 | 745 | |
|
745 | 746 | void tst_QChart::titleBrush_data() |
|
746 | 747 | { |
|
747 | 748 | QTest::addColumn<QBrush>("titleBrush"); |
|
748 | 749 | QTest::newRow("null") << QBrush(); |
|
749 | 750 | QTest::newRow("blue") << QBrush(Qt::blue); |
|
750 | 751 | QTest::newRow("white") << QBrush(Qt::white); |
|
751 | 752 | QTest::newRow("black") << QBrush(Qt::black); |
|
752 | 753 | } |
|
753 | 754 | |
|
754 | 755 | void tst_QChart::titleBrush() |
|
755 | 756 | { |
|
756 | 757 | QFETCH(QBrush, titleBrush); |
|
757 | 758 | m_chart->setTitleBrush(titleBrush); |
|
758 | 759 | QCOMPARE(m_chart->titleBrush().color(), titleBrush.color()); |
|
759 | 760 | } |
|
760 | 761 | |
|
761 | 762 | void tst_QChart::titleFont_data() |
|
762 | 763 | { |
|
763 | 764 | QTest::addColumn<QFont>("titleFont"); |
|
764 | 765 | QTest::newRow("null") << QFont(); |
|
765 | 766 | QTest::newRow("courier") << QFont("Courier", 8, QFont::Bold, true); |
|
766 | 767 | } |
|
767 | 768 | |
|
768 | 769 | void tst_QChart::titleFont() |
|
769 | 770 | { |
|
770 | 771 | QFETCH(QFont, titleFont); |
|
771 | 772 | m_chart->setTitleFont(titleFont); |
|
772 | 773 | QCOMPARE(m_chart->titleFont(), titleFont); |
|
773 | 774 | } |
|
774 | 775 | |
|
775 | 776 | void tst_QChart::zoomIn_data() |
|
776 | 777 | { |
|
777 | 778 | QTest::addColumn<QRectF>("rect"); |
|
778 | 779 | QTest::newRow("null") << QRectF(); |
|
779 | 780 | QTest::newRow("100x100") << QRectF(10,10,100,100); |
|
780 | 781 | QTest::newRow("200x200") << QRectF(10,10,200,200); |
|
781 | 782 | } |
|
782 | 783 | |
|
783 | 784 | |
|
784 | 785 | void tst_QChart::zoomIn() |
|
785 | 786 | { |
|
786 | 787 | |
|
787 | 788 | QFETCH(QRectF, rect); |
|
788 | 789 | createTestData(); |
|
789 | 790 | m_chart->createDefaultAxes(); |
|
790 | 791 | QRectF marigns = m_chart->plotArea(); |
|
791 | 792 | rect.adjust(marigns.left(),marigns.top(),-marigns.right(),-marigns.bottom()); |
|
792 | 793 | QValueAxis* axisX = qobject_cast<QValueAxis*>(m_chart->axisX()); |
|
793 | 794 | QVERIFY(axisX!=0); |
|
794 | 795 | QValueAxis* axisY = qobject_cast<QValueAxis*>(m_chart->axisY()); |
|
795 | 796 | QVERIFY(axisY!=0); |
|
796 | 797 | qreal minX = axisX->min(); |
|
797 | 798 | qreal minY = axisY->min(); |
|
798 | 799 | qreal maxX = axisX->max(); |
|
799 | 800 | qreal maxY = axisY->max(); |
|
800 | 801 | m_chart->zoomIn(rect); |
|
801 | 802 | if(rect.isValid()){ |
|
802 | 803 | QVERIFY(minX<axisX->min()); |
|
803 | 804 | QVERIFY(maxX>axisX->max()); |
|
804 | 805 | QVERIFY(minY<axisY->min()); |
|
805 | 806 | QVERIFY(maxY>axisY->max()); |
|
806 | 807 | } |
|
807 | 808 | |
|
808 | 809 | } |
|
809 | 810 | |
|
810 | 811 | void tst_QChart::zoomOut_data() |
|
811 | 812 | { |
|
812 | 813 | |
|
813 | 814 | } |
|
814 | 815 | |
|
815 | 816 | void tst_QChart::zoomOut() |
|
816 | 817 | { |
|
817 | 818 | createTestData(); |
|
818 | 819 | m_chart->createDefaultAxes(); |
|
819 | 820 | |
|
820 | 821 | QValueAxis* axisX = qobject_cast<QValueAxis*>(m_chart->axisX()); |
|
821 | 822 | QVERIFY(axisX!=0); |
|
822 | 823 | QValueAxis* axisY = qobject_cast<QValueAxis*>(m_chart->axisY()); |
|
823 | 824 | QVERIFY(axisY!=0); |
|
824 | 825 | |
|
825 | 826 | qreal minX = axisX->min(); |
|
826 | 827 | qreal minY = axisY->min(); |
|
827 | 828 | qreal maxX = axisX->max(); |
|
828 | 829 | qreal maxY = axisY->max(); |
|
829 | 830 | |
|
830 | 831 | m_chart->zoomIn(); |
|
831 | 832 | |
|
832 | 833 | QVERIFY(minX < axisX->min()); |
|
833 | 834 | QVERIFY(maxX > axisX->max()); |
|
834 | 835 | QVERIFY(minY < axisY->min()); |
|
835 | 836 | QVERIFY(maxY > axisY->max()); |
|
836 | 837 | |
|
837 | 838 | m_chart->zoomOut(); |
|
838 | 839 | |
|
839 | 840 | // min x may be a zero value |
|
840 | 841 | if (qFuzzyIsNull(minX)) |
|
841 | 842 | QVERIFY(qFuzzyIsNull(axisX->min())); |
|
842 | 843 | else |
|
843 | 844 | QCOMPARE(minX, axisX->min()); |
|
844 | 845 | |
|
845 | 846 | // min y may be a zero value |
|
846 | 847 | if (qFuzzyIsNull(minY)) |
|
847 | 848 | QVERIFY(qFuzzyIsNull(axisY->min())); |
|
848 | 849 | else |
|
849 | 850 | QCOMPARE(minY, axisY->min()); |
|
850 | 851 | |
|
851 | 852 | QVERIFY(maxX == axisX->max()); |
|
852 | 853 | QVERIFY(maxY == axisY->max()); |
|
853 | 854 | |
|
854 | 855 | } |
|
855 | 856 | |
|
856 | 857 | void tst_QChart::zoomReset() |
|
857 | 858 | { |
|
858 | 859 | createTestData(); |
|
859 | 860 | m_chart->createDefaultAxes(); |
|
860 | 861 | QValueAxis *axisX = qobject_cast<QValueAxis *>(m_chart->axisX()); |
|
861 | 862 | QVERIFY(axisX != 0); |
|
862 | 863 | QValueAxis *axisY = qobject_cast<QValueAxis *>(m_chart->axisY()); |
|
863 | 864 | QVERIFY(axisY != 0); |
|
864 | 865 | |
|
865 | 866 | qreal minX = axisX->min(); |
|
866 | 867 | qreal minY = axisY->min(); |
|
867 | 868 | qreal maxX = axisX->max(); |
|
868 | 869 | qreal maxY = axisY->max(); |
|
869 | 870 | |
|
870 | 871 | QVERIFY(!m_chart->isZoomed()); |
|
871 | 872 | |
|
872 | 873 | m_chart->zoomIn(); |
|
873 | 874 | |
|
874 | 875 | QVERIFY(m_chart->isZoomed()); |
|
875 | 876 | QVERIFY(minX < axisX->min()); |
|
876 | 877 | QVERIFY(maxX > axisX->max()); |
|
877 | 878 | QVERIFY(minY < axisY->min()); |
|
878 | 879 | QVERIFY(maxY > axisY->max()); |
|
879 | 880 | |
|
880 | 881 | m_chart->zoomReset(); |
|
881 | 882 | |
|
882 | 883 | // Reset after zoomIn should restore originals |
|
883 | 884 | QVERIFY(!m_chart->isZoomed()); |
|
884 | 885 | QVERIFY(minX == axisX->min()); |
|
885 | 886 | QVERIFY(maxX == axisX->max()); |
|
886 | 887 | QVERIFY(minY == axisY->min()); |
|
887 | 888 | QVERIFY(maxY == axisY->max()); |
|
888 | 889 | |
|
889 | 890 | m_chart->zoomOut(); |
|
890 | 891 | |
|
891 | 892 | QVERIFY(m_chart->isZoomed()); |
|
892 | 893 | QVERIFY(minX > axisX->min()); |
|
893 | 894 | QVERIFY(maxX < axisX->max()); |
|
894 | 895 | QVERIFY(minY > axisY->min()); |
|
895 | 896 | QVERIFY(maxY < axisY->max()); |
|
896 | 897 | |
|
897 | 898 | m_chart->zoomReset(); |
|
898 | 899 | |
|
899 | 900 | // Reset after zoomOut should restore originals |
|
900 | 901 | QVERIFY(!m_chart->isZoomed()); |
|
901 | 902 | QVERIFY(minX == axisX->min()); |
|
902 | 903 | QVERIFY(maxX == axisX->max()); |
|
903 | 904 | QVERIFY(minY == axisY->min()); |
|
904 | 905 | QVERIFY(maxY == axisY->max()); |
|
905 | 906 | |
|
906 | 907 | axisX->setRange(234, 345); |
|
907 | 908 | axisY->setRange(345, 456); |
|
908 | 909 | |
|
909 | 910 | minX = axisX->min(); |
|
910 | 911 | minY = axisY->min(); |
|
911 | 912 | maxX = axisX->max(); |
|
912 | 913 | maxY = axisY->max(); |
|
913 | 914 | |
|
914 | 915 | QVERIFY(!m_chart->isZoomed()); |
|
915 | 916 | |
|
916 | 917 | m_chart->zoomReset(); |
|
917 | 918 | |
|
918 | 919 | // Reset without zoom should not change anything |
|
919 | 920 | QVERIFY(!m_chart->isZoomed()); |
|
920 | 921 | QVERIFY(minX == axisX->min()); |
|
921 | 922 | QVERIFY(maxX == axisX->max()); |
|
922 | 923 | QVERIFY(minY == axisY->min()); |
|
923 | 924 | QVERIFY(maxY == axisY->max()); |
|
924 | 925 | |
|
925 | 926 | } |
|
926 | 927 | |
|
927 | 928 | void tst_QChart::createDefaultAxesForLineSeries_data() |
|
928 | 929 | { |
|
929 | 930 | QTest::addColumn<qreal>("series1minX"); |
|
930 | 931 | QTest::addColumn<qreal>("series1midX"); |
|
931 | 932 | QTest::addColumn<qreal>("series1maxX"); |
|
932 | 933 | QTest::addColumn<qreal>("series2minX"); |
|
933 | 934 | QTest::addColumn<qreal>("series2midX"); |
|
934 | 935 | QTest::addColumn<qreal>("series2maxX"); |
|
935 | 936 | QTest::addColumn<qreal>("overallminX"); |
|
936 | 937 | QTest::addColumn<qreal>("overallmaxX"); |
|
937 | 938 | QTest::addColumn<qreal>("series1minY"); |
|
938 | 939 | QTest::addColumn<qreal>("series1midY"); |
|
939 | 940 | QTest::addColumn<qreal>("series1maxY"); |
|
940 | 941 | QTest::addColumn<qreal>("series2minY"); |
|
941 | 942 | QTest::addColumn<qreal>("series2midY"); |
|
942 | 943 | QTest::addColumn<qreal>("series2maxY"); |
|
943 | 944 | QTest::addColumn<qreal>("overallminY"); |
|
944 | 945 | QTest::addColumn<qreal>("overallmaxY"); |
|
945 | 946 | QTest::newRow("series1hasMinAndMax") << (qreal)1.0 << (qreal)2.0 << (qreal)3.0 << (qreal)1.1 << (qreal)1.7 << (qreal)2.9 << (qreal)1.0 << (qreal)3.0 |
|
946 | 947 | << (qreal)1.0 << (qreal)2.0 << (qreal)3.0 << (qreal)1.1 << (qreal)1.7 << (qreal)2.9 << (qreal)1.0 << (qreal)3.0; |
|
947 | 948 | QTest::newRow("series2hasMinAndMax") << (qreal)1.1 << (qreal)2.0 << (qreal)2.9 << (qreal)1.0 << (qreal)1.7 << (qreal)3.0 << (qreal)1.0 << (qreal)3.0 |
|
948 | 949 | << (qreal)1.1 << (qreal)2.0 << (qreal)2.9 << (qreal)1.0 << (qreal)1.7 << (qreal)3.0 << (qreal)1.0 << (qreal)3.0; |
|
949 | 950 | QTest::newRow("series1hasMinAndMaxX_series2hasMinAndMaxY") << (qreal)1.0 << (qreal)2.0 << (qreal)3.0 << (qreal)1.1 << (qreal)1.7 << (qreal)2.9 << (qreal)1.0 << (qreal)3.0 |
|
950 | 951 | << (qreal)1.1 << (qreal)2.0 << (qreal)2.9 << (qreal)1.0 << (qreal)2.0 << (qreal)3.0 << (qreal)1.0 << (qreal)3.0; |
|
951 | 952 | QTest::newRow("series1hasMin_series2hasMax") << (qreal)1.0 << (qreal)2.0 << (qreal)2.9 << (qreal)1.1 << (qreal)1.7 << (qreal)3.0 << (qreal)1.0 << (qreal)3.0 |
|
952 | 953 | << (qreal)1.0 << (qreal)2.0 << (qreal)2.9 << (qreal)1.1 << (qreal)1.7 << (qreal)3.0 << (qreal)1.0 << (qreal)3.0; |
|
953 | 954 | QTest::newRow("bothSeriesHaveSameMinAndMax") << (qreal)1.0 << (qreal)2.0 << (qreal)2.9 << (qreal)1.1 << (qreal)1.7 << (qreal)3.0 << (qreal)1.0 << (qreal)3.0 |
|
954 | 955 | << (qreal)1.1 << (qreal)1.1 << (qreal)1.1 << (qreal)1.1 << (qreal)1.1 << (qreal)1.1 << (qreal)0.6 << (qreal)1.6; |
|
955 | 956 | } |
|
956 | 957 | |
|
957 | 958 | void tst_QChart::createDefaultAxesForLineSeries() |
|
958 | 959 | { |
|
959 | 960 | QFETCH(qreal, series1minX); |
|
960 | 961 | QFETCH(qreal, series1midX); |
|
961 | 962 | QFETCH(qreal, series1maxX); |
|
962 | 963 | QFETCH(qreal, series2minX); |
|
963 | 964 | QFETCH(qreal, series2midX); |
|
964 | 965 | QFETCH(qreal, series2maxX); |
|
965 | 966 | QFETCH(qreal, series1minY); |
|
966 | 967 | QFETCH(qreal, series1midY); |
|
967 | 968 | QFETCH(qreal, series1maxY); |
|
968 | 969 | QFETCH(qreal, series2minY); |
|
969 | 970 | QFETCH(qreal, series2midY); |
|
970 | 971 | QFETCH(qreal, series2maxY); |
|
971 | 972 | QFETCH(qreal, overallminX); |
|
972 | 973 | QFETCH(qreal, overallmaxX); |
|
973 | 974 | QFETCH(qreal, overallminY); |
|
974 | 975 | QFETCH(qreal, overallmaxY); |
|
975 | 976 | QLineSeries* series1 = new QLineSeries(this); |
|
976 | 977 | series1->append(series1minX, series1minY); |
|
977 | 978 | series1->append(series1midX, series1midY); |
|
978 | 979 | series1->append(series1maxX, series1maxY); |
|
979 | 980 | QLineSeries* series2 = new QLineSeries(this); |
|
980 | 981 | series2->append(series2minX, series2minY); |
|
981 | 982 | series2->append(series2midX, series2midY); |
|
982 | 983 | series2->append(series2maxX, series2maxY); |
|
983 | 984 | QChart *chart = newQChartOrQPolarChart(); |
|
984 | 985 | chart->addSeries(series1); |
|
985 | 986 | chart->addSeries(series2); |
|
986 | 987 | chart->createDefaultAxes(); |
|
987 | 988 | QValueAxis *xAxis = (QValueAxis *)chart->axisX(); |
|
988 | 989 | QCOMPARE(xAxis->min(), overallminX); |
|
989 | 990 | QCOMPARE(xAxis->max(), overallmaxX); |
|
990 | 991 | QValueAxis *yAxis = (QValueAxis *)chart->axisY(); |
|
991 | 992 | QCOMPARE(yAxis->min(), overallminY); |
|
992 | 993 | QCOMPARE(yAxis->max(), overallmaxY); |
|
993 | 994 | QLineSeries *series3 = new QLineSeries(this); |
|
994 | 995 | // Numbers clearly out of existing range |
|
995 | 996 | series3->append(0, 0); |
|
996 | 997 | series3->append(100, 100); |
|
997 | 998 | // Adding a new series should not change the axes as they have not been told to update |
|
998 | 999 | chart->addSeries(series3); |
|
999 | 1000 | QCOMPARE(xAxis->min(), overallminX); |
|
1000 | 1001 | QCOMPARE(xAxis->max(), overallmaxX); |
|
1001 | 1002 | QCOMPARE(yAxis->min(), overallminY); |
|
1002 | 1003 | QCOMPARE(yAxis->max(), overallmaxY); |
|
1003 | 1004 | } |
|
1004 | 1005 | |
|
1005 | 1006 | void tst_QChart::axisPolarOrientation() |
|
1006 | 1007 | { |
|
1007 | 1008 | QLineSeries* series1 = new QLineSeries(this); |
|
1008 | 1009 | series1->append(1, 2); |
|
1009 | 1010 | series1->append(2, 4); |
|
1010 | 1011 | series1->append(3, 8); |
|
1011 | 1012 | QPolarChart chart; |
|
1012 | 1013 | chart.addSeries(series1); |
|
1013 | 1014 | |
|
1014 | 1015 | QValueAxis *xAxis = new QValueAxis(); |
|
1015 | 1016 | QValueAxis *yAxis = new QValueAxis(); |
|
1016 | 1017 | chart.addAxis(xAxis, QPolarChart::PolarOrientationAngular); |
|
1017 | 1018 | chart.addAxis(yAxis, QPolarChart::PolarOrientationRadial); |
|
1018 | 1019 | |
|
1019 | 1020 | QList<QAbstractAxis *> xAxes = chart.axes(QPolarChart::PolarOrientationAngular); |
|
1020 | 1021 | QList<QAbstractAxis *> yAxes = chart.axes(QPolarChart::PolarOrientationRadial); |
|
1021 | 1022 | |
|
1022 | 1023 | QCOMPARE(xAxes.size(), 1); |
|
1023 | 1024 | QCOMPARE(yAxes.size(), 1); |
|
1024 | 1025 | QCOMPARE(xAxes[0], xAxis); |
|
1025 | 1026 | QCOMPARE(yAxes[0], yAxis); |
|
1026 | 1027 | |
|
1027 | 1028 | QCOMPARE(chart.axisPolarOrientation(xAxes[0]), QPolarChart::PolarOrientationAngular); |
|
1028 | 1029 | QCOMPARE(chart.axisPolarOrientation(yAxes[0]), QPolarChart::PolarOrientationRadial); |
|
1029 | 1030 | } |
|
1030 | 1031 | |
|
1032 | void tst_QChart::backgroundRoundness() | |
|
1033 | { | |
|
1034 | createTestData(); | |
|
1035 | m_chart->createDefaultAxes(); | |
|
1036 | m_chart->setBackgroundRoundness(100.0); | |
|
1037 | QVERIFY(m_chart->backgroundRoundness() == 100.0); | |
|
1038 | } | |
|
1039 | ||
|
1031 | 1040 | QTEST_MAIN(tst_QChart) |
|
1032 | 1041 | #include "tst_qchart.moc" |
|
1033 | 1042 |
@@ -1,107 +1,108 | |||
|
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 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 QtCommercial.Chart 1.3 |
|
23 | 23 | |
|
24 | 24 | ChartView { |
|
25 | 25 | id: chartView |
|
26 | 26 | title: "Chart Title" |
|
27 | 27 | anchors.fill: parent |
|
28 | 28 | property variant chart: chartView |
|
29 | 29 | |
|
30 | 30 | LineSeries { |
|
31 | 31 | name: "line" |
|
32 | 32 | XYPoint { x: 0; y: 0 } |
|
33 | 33 | XYPoint { x: 1.1; y: 2.1 } |
|
34 | 34 | XYPoint { x: 1.9; y: 3.3 } |
|
35 | 35 | XYPoint { x: 2.1; y: 2.1 } |
|
36 | 36 | XYPoint { x: 2.9; y: 4.9 } |
|
37 | 37 | XYPoint { x: 3.4; y: 3.0 } |
|
38 | 38 | XYPoint { x: 4.1; y: 3.3 } |
|
39 | 39 | } |
|
40 | 40 | |
|
41 | 41 | onVisibleChanged: console.log("chart.onVisibleChanged: " + visible); |
|
42 | 42 | onTitleColorChanged: console.log("chart.onTitleColorChanged: " + color); |
|
43 | 43 | onBackgroundColorChanged: console.log("chart.onBackgroundColorChanged: " + chart.backgroundColor); |
|
44 | 44 | onDropShadowEnabledChanged: console.log("chart.onDropShadowEnabledChanged: " + enabled); |
|
45 | onBackgroundRoundnessChanged: console.log("chart.onBackgroundRoundnessChanged: " + diameter); | |
|
45 | 46 | onSeriesAdded: console.log("chart.onSeriesAdded: " + series.name); |
|
46 | 47 | onSeriesRemoved: console.log("chart.onSeriesRemoved: " + series.name); |
|
47 | 48 | onPlotAreaColorChanged: console.log("chart.plotAreaColorChanged: " + chart.plotAreaColor); |
|
48 | 49 | |
|
49 | 50 | legend.onVisibleChanged: console.log("legend.onVisibleChanged: " + chart.legend.visible); |
|
50 | 51 | legend.onBackgroundVisibleChanged: console.log("legend.onBackgroundVisibleChanged: " + visible); |
|
51 | 52 | legend.onColorChanged: console.log("legend.onColorChanged: " + color); |
|
52 | 53 | legend.onBorderColorChanged: console.log("legend.onBorderColorChanged: " + color); |
|
53 | 54 | legend.onLabelColorChanged: console.log("legend.onLabelColorChanged: " + color); |
|
54 | 55 | margins.onTopChanged: console.log("chart.margins.onTopChanged: " + top ); |
|
55 | 56 | margins.onBottomChanged: console.log("chart.margins.onBottomChanged: " + bottom); |
|
56 | 57 | margins.onLeftChanged: console.log("chart.margins.onLeftChanged: " + left); |
|
57 | 58 | margins.onRightChanged: console.log("chart.margins.onRightChanged: " + right); |
|
58 | 59 | onPlotAreaChanged: { |
|
59 | 60 | console.log("chart.onPlotAreaChanged, width: " + chartView.plotArea.width |
|
60 | 61 | + " height: " + chartView.plotArea.height |
|
61 | 62 | + " y: " + chartView.plotArea.y |
|
62 | 63 | + " x: " + chartView.plotArea.x); |
|
63 | 64 | marginVisualizer.opacity = 1.0; |
|
64 | 65 | } |
|
65 | 66 | |
|
66 | 67 | ValueAxis{ |
|
67 | 68 | onColorChanged: console.log("axisX.onColorChanged: " + color); |
|
68 | 69 | onLabelsVisibleChanged: console.log("axisX.onLabelsVisibleChanged: " + visible); |
|
69 | 70 | onLabelsColorChanged: console.log("axisX.onLabelsColorChanged: " + color); |
|
70 | 71 | onVisibleChanged: console.log("axisX.onVisibleChanged: " + visible); |
|
71 | 72 | onGridVisibleChanged: console.log("axisX.onGridVisibleChanged: " + visible); |
|
72 | 73 | onShadesVisibleChanged: console.log("axisX.onShadesVisibleChanged: " + visible); |
|
73 | 74 | onShadesColorChanged: console.log("axisX.onShadesColorChanged: " + color); |
|
74 | 75 | onShadesBorderColorChanged: console.log("axisX.onShadesBorderColorChanged: " + color); |
|
75 | 76 | onMinChanged: console.log("axisX.onMinChanged: " + min); |
|
76 | 77 | onMaxChanged: console.log("axisX.onMaxChanged: " + max); |
|
77 | 78 | } |
|
78 | 79 | |
|
79 | 80 | ValueAxis{ |
|
80 | 81 | onColorChanged: console.log("axisY.onColorChanged: " + color); |
|
81 | 82 | onLabelsVisibleChanged: console.log("axisY.onLabelsVisibleChanged: " + visible); |
|
82 | 83 | onLabelsColorChanged: console.log("axisY.onLabelsColorChanged: " + color); |
|
83 | 84 | onVisibleChanged: console.log("axisY.onVisibleChanged: " + visible); |
|
84 | 85 | onGridVisibleChanged: console.log("axisY.onGridVisibleChanged: " + visible); |
|
85 | 86 | onShadesVisibleChanged: console.log("axisY.onShadesVisibleChanged: " + visible); |
|
86 | 87 | onShadesColorChanged: console.log("axisY.onShadesColorChanged: " + color); |
|
87 | 88 | onShadesBorderColorChanged: console.log("axisY.onShadesBorderColorChanged: " + color); |
|
88 | 89 | onMinChanged: console.log("axisY.onMinChanged: " + min); |
|
89 | 90 | onMaxChanged: console.log("axisY.onMaxChanged: " + max); |
|
90 | 91 | } |
|
91 | 92 | |
|
92 | 93 | Rectangle { |
|
93 | 94 | id: marginVisualizer |
|
94 | 95 | color: "transparent" |
|
95 | 96 | border.color: "red" |
|
96 | 97 | anchors.fill: parent |
|
97 | 98 | anchors.topMargin: chartView.minimumMargins.top |
|
98 | 99 | anchors.bottomMargin: chartView.minimumMargins.bottom |
|
99 | 100 | anchors.leftMargin: chartView.minimumMargins.left |
|
100 | 101 | anchors.rightMargin: chartView.minimumMargins.right |
|
101 | 102 | opacity: 0.0 |
|
102 | 103 | onOpacityChanged: if (opacity > 0.9) opacity = 0.0; |
|
103 | 104 | Behavior on opacity { |
|
104 | 105 | NumberAnimation { duration: 800 } |
|
105 | 106 | } |
|
106 | 107 | } |
|
107 | 108 | } |
@@ -1,120 +1,124 | |||
|
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 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 | |
|
23 | 23 | Flow { |
|
24 | 24 | anchors.fill: parent |
|
25 | 25 | property variant chart |
|
26 | 26 | flow: Flow.TopToBottom |
|
27 | 27 | spacing: 5 |
|
28 | 28 | Button { |
|
29 | 29 | text: "visible" |
|
30 | 30 | onClicked: chart.visible = !chart.visible; |
|
31 | 31 | } |
|
32 | 32 | Button { |
|
33 | 33 | text: "theme +" |
|
34 | 34 | onClicked: chart.theme++; |
|
35 | 35 | } |
|
36 | 36 | Button { |
|
37 | 37 | text: "theme -" |
|
38 | 38 | onClicked: chart.theme--; |
|
39 | 39 | } |
|
40 | 40 | Button { |
|
41 | 41 | text: "animation opt +" |
|
42 | 42 | onClicked: chart.animationOptions++; |
|
43 | 43 | } |
|
44 | 44 | Button { |
|
45 | 45 | text: "animation opt -" |
|
46 | 46 | onClicked: chart.animationOptions--; |
|
47 | 47 | } |
|
48 | 48 | Button { |
|
49 | 49 | text: "background color" |
|
50 | 50 | onClicked: chart.backgroundColor = main.nextColor(); |
|
51 | 51 | } |
|
52 | 52 | Button { |
|
53 | 53 | text: "plot area color" |
|
54 | 54 | onClicked: chart.plotAreaColor = main.nextColor(); |
|
55 | 55 | } |
|
56 | 56 | Button { |
|
57 | 57 | text: "drop shadow enabled" |
|
58 | 58 | onClicked: chart.dropShadowEnabled = !chart.dropShadowEnabled; |
|
59 | 59 | } |
|
60 | 60 | Button { |
|
61 | text: "roundness" | |
|
62 | onClicked: chart.backgroundRoundness++; | |
|
63 | } | |
|
64 | Button { | |
|
61 | 65 | text: "zoom +" |
|
62 | 66 | onClicked: chart.zoom(2); |
|
63 | 67 | } |
|
64 | 68 | Button { |
|
65 | 69 | text: "zoom -" |
|
66 | 70 | onClicked: chart.zoom(0.5); |
|
67 | 71 | } |
|
68 | 72 | Button { |
|
69 | 73 | text: "scroll left" |
|
70 | 74 | onClicked: chart.scrollLeft(10); |
|
71 | 75 | } |
|
72 | 76 | Button { |
|
73 | 77 | text: "scroll right" |
|
74 | 78 | onClicked: chart.scrollRight(10); |
|
75 | 79 | } |
|
76 | 80 | Button { |
|
77 | 81 | text: "scroll up" |
|
78 | 82 | onClicked: chart.scrollUp(10); |
|
79 | 83 | } |
|
80 | 84 | Button { |
|
81 | 85 | text: "scroll down" |
|
82 | 86 | onClicked: chart.scrollDown(10); |
|
83 | 87 | } |
|
84 | 88 | Button { |
|
85 | 89 | text: "title color" |
|
86 | 90 | onClicked: chart.titleColor = main.nextColor(); |
|
87 | 91 | } |
|
88 | 92 | Button { |
|
89 | 93 | text: "top margin +" |
|
90 | 94 | onClicked: chart.margins.top += 5; |
|
91 | 95 | } |
|
92 | 96 | Button { |
|
93 | 97 | text: "top margin -" |
|
94 | 98 | onClicked: chart.margins.top -= 5; |
|
95 | 99 | } |
|
96 | 100 | Button { |
|
97 | 101 | text: "bottom margin +" |
|
98 | 102 | onClicked: chart.margins.bottom += 5; |
|
99 | 103 | } |
|
100 | 104 | Button { |
|
101 | 105 | text: "bottom margin -" |
|
102 | 106 | onClicked: chart.margins.bottom -= 5; |
|
103 | 107 | } |
|
104 | 108 | Button { |
|
105 | 109 | text: "left margin +" |
|
106 | 110 | onClicked: chart.margins.left += 5; |
|
107 | 111 | } |
|
108 | 112 | Button { |
|
109 | 113 | text: "left margin -" |
|
110 | 114 | onClicked: chart.margins.left -= 5; |
|
111 | 115 | } |
|
112 | 116 | Button { |
|
113 | 117 | text: "right margin +" |
|
114 | 118 | onClicked: chart.margins.right += 5; |
|
115 | 119 | } |
|
116 | 120 | Button { |
|
117 | 121 | text: "right margin -" |
|
118 | 122 | onClicked: chart.margins.right -= 5; |
|
119 | 123 | } |
|
120 | 124 | } |
@@ -1,107 +1,108 | |||
|
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 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 2.0 |
|
22 | 22 | import QtCommercial.Chart 1.3 |
|
23 | 23 | |
|
24 | 24 | ChartView { |
|
25 | 25 | id: chartView |
|
26 | 26 | title: "Chart Title" |
|
27 | 27 | anchors.fill: parent |
|
28 | 28 | property variant chart: chartView |
|
29 | 29 | |
|
30 | 30 | LineSeries { |
|
31 | 31 | name: "line" |
|
32 | 32 | XYPoint { x: 0; y: 0 } |
|
33 | 33 | XYPoint { x: 1.1; y: 2.1 } |
|
34 | 34 | XYPoint { x: 1.9; y: 3.3 } |
|
35 | 35 | XYPoint { x: 2.1; y: 2.1 } |
|
36 | 36 | XYPoint { x: 2.9; y: 4.9 } |
|
37 | 37 | XYPoint { x: 3.4; y: 3.0 } |
|
38 | 38 | XYPoint { x: 4.1; y: 3.3 } |
|
39 | 39 | } |
|
40 | 40 | |
|
41 | 41 | onVisibleChanged: console.log("chart.onVisibleChanged: " + visible); |
|
42 | 42 | onTitleColorChanged: console.log("chart.onTitleColorChanged: " + color); |
|
43 | 43 | onBackgroundColorChanged: console.log("chart.onBackgroundColorChanged: " + chart.backgroundColor); |
|
44 | 44 | onDropShadowEnabledChanged: console.log("chart.onDropShadowEnabledChanged: " + enabled); |
|
45 | onBackgroundRoundnessChanged: console.log("chart.onBackgroundRoundnessChanged: " + diameter); | |
|
45 | 46 | onSeriesAdded: console.log("chart.onSeriesAdded: " + series.name); |
|
46 | 47 | onSeriesRemoved: console.log("chart.onSeriesRemoved: " + series.name); |
|
47 | 48 | onPlotAreaColorChanged: console.log("chart.plotAreaColorChanged: " + chart.plotAreaColor); |
|
48 | 49 | |
|
49 | 50 | legend.onVisibleChanged: console.log("legend.onVisibleChanged: " + chart.legend.visible); |
|
50 | 51 | legend.onBackgroundVisibleChanged: console.log("legend.onBackgroundVisibleChanged: " + visible); |
|
51 | 52 | legend.onColorChanged: console.log("legend.onColorChanged: " + color); |
|
52 | 53 | legend.onBorderColorChanged: console.log("legend.onBorderColorChanged: " + color); |
|
53 | 54 | legend.onLabelColorChanged: console.log("legend.onLabelColorChanged: " + color); |
|
54 | 55 | margins.onTopChanged: console.log("chart.margins.onTopChanged: " + top ); |
|
55 | 56 | margins.onBottomChanged: console.log("chart.margins.onBottomChanged: " + bottom); |
|
56 | 57 | margins.onLeftChanged: console.log("chart.margins.onLeftChanged: " + left); |
|
57 | 58 | margins.onRightChanged: console.log("chart.margins.onRightChanged: " + right); |
|
58 | 59 | onPlotAreaChanged: { |
|
59 | 60 | console.log("chart.onPlotAreaChanged, width: " + chartView.plotArea.width |
|
60 | 61 | + " height: " + chartView.plotArea.height |
|
61 | 62 | + " y: " + chartView.plotArea.y |
|
62 | 63 | + " x: " + chartView.plotArea.x); |
|
63 | 64 | marginVisualizer.opacity = 1.0; |
|
64 | 65 | } |
|
65 | 66 | |
|
66 | 67 | ValueAxis{ |
|
67 | 68 | onColorChanged: console.log("axisX.onColorChanged: " + color); |
|
68 | 69 | onLabelsVisibleChanged: console.log("axisX.onLabelsVisibleChanged: " + visible); |
|
69 | 70 | onLabelsColorChanged: console.log("axisX.onLabelsColorChanged: " + color); |
|
70 | 71 | onVisibleChanged: console.log("axisX.onVisibleChanged: " + visible); |
|
71 | 72 | onGridVisibleChanged: console.log("axisX.onGridVisibleChanged: " + visible); |
|
72 | 73 | onShadesVisibleChanged: console.log("axisX.onShadesVisibleChanged: " + visible); |
|
73 | 74 | onShadesColorChanged: console.log("axisX.onShadesColorChanged: " + color); |
|
74 | 75 | onShadesBorderColorChanged: console.log("axisX.onShadesBorderColorChanged: " + color); |
|
75 | 76 | onMinChanged: console.log("axisX.onMinChanged: " + min); |
|
76 | 77 | onMaxChanged: console.log("axisX.onMaxChanged: " + max); |
|
77 | 78 | } |
|
78 | 79 | |
|
79 | 80 | ValueAxis{ |
|
80 | 81 | onColorChanged: console.log("axisY.onColorChanged: " + color); |
|
81 | 82 | onLabelsVisibleChanged: console.log("axisY.onLabelsVisibleChanged: " + visible); |
|
82 | 83 | onLabelsColorChanged: console.log("axisY.onLabelsColorChanged: " + color); |
|
83 | 84 | onVisibleChanged: console.log("axisY.onVisibleChanged: " + visible); |
|
84 | 85 | onGridVisibleChanged: console.log("axisY.onGridVisibleChanged: " + visible); |
|
85 | 86 | onShadesVisibleChanged: console.log("axisY.onShadesVisibleChanged: " + visible); |
|
86 | 87 | onShadesColorChanged: console.log("axisY.onShadesColorChanged: " + color); |
|
87 | 88 | onShadesBorderColorChanged: console.log("axisY.onShadesBorderColorChanged: " + color); |
|
88 | 89 | onMinChanged: console.log("axisY.onMinChanged: " + min); |
|
89 | 90 | onMaxChanged: console.log("axisY.onMaxChanged: " + max); |
|
90 | 91 | } |
|
91 | 92 | |
|
92 | 93 | Rectangle { |
|
93 | 94 | id: marginVisualizer |
|
94 | 95 | color: "transparent" |
|
95 | 96 | border.color: "red" |
|
96 | 97 | anchors.fill: parent |
|
97 | 98 | anchors.topMargin: chartView.minimumMargins.top |
|
98 | 99 | anchors.bottomMargin: chartView.minimumMargins.bottom |
|
99 | 100 | anchors.leftMargin: chartView.minimumMargins.left |
|
100 | 101 | anchors.rightMargin: chartView.minimumMargins.right |
|
101 | 102 | opacity: 0.0 |
|
102 | 103 | onOpacityChanged: if (opacity > 0.9) opacity = 0.0; |
|
103 | 104 | Behavior on opacity { |
|
104 | 105 | NumberAnimation { duration: 800 } |
|
105 | 106 | } |
|
106 | 107 | } |
|
107 | 108 | } |
@@ -1,120 +1,124 | |||
|
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 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 2.0 |
|
22 | 22 | |
|
23 | 23 | Flow { |
|
24 | 24 | anchors.fill: parent |
|
25 | 25 | property variant chart |
|
26 | 26 | flow: Flow.TopToBottom |
|
27 | 27 | spacing: 5 |
|
28 | 28 | Button { |
|
29 | 29 | text: "visible" |
|
30 | 30 | onClicked: chart.visible = !chart.visible; |
|
31 | 31 | } |
|
32 | 32 | Button { |
|
33 | 33 | text: "theme +" |
|
34 | 34 | onClicked: chart.theme++; |
|
35 | 35 | } |
|
36 | 36 | Button { |
|
37 | 37 | text: "theme -" |
|
38 | 38 | onClicked: chart.theme--; |
|
39 | 39 | } |
|
40 | 40 | Button { |
|
41 | 41 | text: "animation opt +" |
|
42 | 42 | onClicked: chart.animationOptions++; |
|
43 | 43 | } |
|
44 | 44 | Button { |
|
45 | 45 | text: "animation opt -" |
|
46 | 46 | onClicked: chart.animationOptions--; |
|
47 | 47 | } |
|
48 | 48 | Button { |
|
49 | 49 | text: "background color" |
|
50 | 50 | onClicked: chart.backgroundColor = main.nextColor(); |
|
51 | 51 | } |
|
52 | 52 | Button { |
|
53 | 53 | text: "plot area color" |
|
54 | 54 | onClicked: chart.plotAreaColor = main.nextColor(); |
|
55 | 55 | } |
|
56 | 56 | Button { |
|
57 | 57 | text: "drop shadow enabled" |
|
58 | 58 | onClicked: chart.dropShadowEnabled = !chart.dropShadowEnabled; |
|
59 | 59 | } |
|
60 | 60 | Button { |
|
61 | text: "roundness" | |
|
62 | onClicked: chart.backgroundRoundness++; | |
|
63 | } | |
|
64 | Button { | |
|
61 | 65 | text: "zoom +" |
|
62 | 66 | onClicked: chart.zoom(2); |
|
63 | 67 | } |
|
64 | 68 | Button { |
|
65 | 69 | text: "zoom -" |
|
66 | 70 | onClicked: chart.zoom(0.5); |
|
67 | 71 | } |
|
68 | 72 | Button { |
|
69 | 73 | text: "scroll left" |
|
70 | 74 | onClicked: chart.scrollLeft(10); |
|
71 | 75 | } |
|
72 | 76 | Button { |
|
73 | 77 | text: "scroll right" |
|
74 | 78 | onClicked: chart.scrollRight(10); |
|
75 | 79 | } |
|
76 | 80 | Button { |
|
77 | 81 | text: "scroll up" |
|
78 | 82 | onClicked: chart.scrollUp(10); |
|
79 | 83 | } |
|
80 | 84 | Button { |
|
81 | 85 | text: "scroll down" |
|
82 | 86 | onClicked: chart.scrollDown(10); |
|
83 | 87 | } |
|
84 | 88 | Button { |
|
85 | 89 | text: "title color" |
|
86 | 90 | onClicked: chart.titleColor = main.nextColor(); |
|
87 | 91 | } |
|
88 | 92 | Button { |
|
89 | 93 | text: "top margin +" |
|
90 | 94 | onClicked: chart.margins.top += 5; |
|
91 | 95 | } |
|
92 | 96 | Button { |
|
93 | 97 | text: "top margin -" |
|
94 | 98 | onClicked: chart.margins.top -= 5; |
|
95 | 99 | } |
|
96 | 100 | Button { |
|
97 | 101 | text: "bottom margin +" |
|
98 | 102 | onClicked: chart.margins.bottom += 5; |
|
99 | 103 | } |
|
100 | 104 | Button { |
|
101 | 105 | text: "bottom margin -" |
|
102 | 106 | onClicked: chart.margins.bottom -= 5; |
|
103 | 107 | } |
|
104 | 108 | Button { |
|
105 | 109 | text: "left margin +" |
|
106 | 110 | onClicked: chart.margins.left += 5; |
|
107 | 111 | } |
|
108 | 112 | Button { |
|
109 | 113 | text: "left margin -" |
|
110 | 114 | onClicked: chart.margins.left -= 5; |
|
111 | 115 | } |
|
112 | 116 | Button { |
|
113 | 117 | text: "right margin +" |
|
114 | 118 | onClicked: chart.margins.right += 5; |
|
115 | 119 | } |
|
116 | 120 | Button { |
|
117 | 121 | text: "right margin -" |
|
118 | 122 | onClicked: chart.margins.right -= 5; |
|
119 | 123 | } |
|
120 | 124 | } |
General Comments 0
You need to be logged in to leave comments.
Login now