@@ -1,551 +1,548 | |||
|
1 | 1 | /**************************************************************************** |
|
2 | 2 | ** |
|
3 | 3 | ** Copyright (C) 2012 Digia Plc |
|
4 | 4 | ** All rights reserved. |
|
5 | 5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
6 | 6 | ** |
|
7 | 7 | ** This file is part of the Qt Commercial Charts Add-on. |
|
8 | 8 | ** |
|
9 | 9 | ** $QT_BEGIN_LICENSE$ |
|
10 | 10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
11 | 11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
12 | 12 | ** Software or, alternatively, in accordance with the terms contained in |
|
13 | 13 | ** a written agreement between you and Digia. |
|
14 | 14 | ** |
|
15 | 15 | ** If you have questions regarding the use of this file, please use |
|
16 | 16 | ** contact form at http://qt.digia.com |
|
17 | 17 | ** $QT_END_LICENSE$ |
|
18 | 18 | ** |
|
19 | 19 | ****************************************************************************/ |
|
20 | 20 | |
|
21 | 21 | #include "qlegend.h" |
|
22 | 22 | #include "qlegend_p.h" |
|
23 | 23 | #include "qabstractseries.h" |
|
24 | 24 | #include "qabstractseries_p.h" |
|
25 | 25 | #include "qchart_p.h" |
|
26 | 26 | #include "legendlayout_p.h" |
|
27 | 27 | #include "legendmarker_p.h" |
|
28 | 28 | #include "qxyseries.h" |
|
29 | 29 | #include "qlineseries.h" |
|
30 | 30 | #include "qareaseries.h" |
|
31 | 31 | #include "qscatterseries.h" |
|
32 | 32 | #include "qsplineseries.h" |
|
33 | 33 | #include "qbarseries.h" |
|
34 | 34 | #include "qstackedbarseries.h" |
|
35 | 35 | #include "qpercentbarseries.h" |
|
36 | 36 | #include "qbarset.h" |
|
37 | 37 | #include "qpieseries.h" |
|
38 | 38 | #include "qpieseries_p.h" |
|
39 | 39 | #include "qpieslice.h" |
|
40 | 40 | #include "chartpresenter_p.h" |
|
41 | 41 | #include <QPainter> |
|
42 | 42 | #include <QPen> |
|
43 | 43 | #include <QTimer> |
|
44 | 44 | #include <QGraphicsLayout> |
|
45 | 45 | #include <QGraphicsSceneEvent> |
|
46 | 46 | |
|
47 | 47 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
48 | 48 | |
|
49 | 49 | /*! |
|
50 | 50 | \class QLegend |
|
51 | 51 | \brief Legend object |
|
52 | 52 | \mainclass |
|
53 | 53 | |
|
54 | 54 | QLegend is a graphical object, whics displays legend of the chart. Legend state is updated by QChart, when |
|
55 | 55 | series have been changed. By default, legend is drawn by QChart, but user can set a new parent to legend and |
|
56 | 56 | handle the drawing manually. |
|
57 | 57 | User isn't supposed to create or delete legend objects, but can reference it via QChart class. |
|
58 | 58 | |
|
59 | 59 | \image examples_percentbarchart_legend.png |
|
60 | 60 | |
|
61 | 61 | \sa QChart |
|
62 | 62 | */ |
|
63 | 63 | /*! |
|
64 | 64 | \qmlclass Legend QLegend |
|
65 | 65 | \brief Legend is part of QtCommercial Chart QML API. |
|
66 | 66 | |
|
67 | 67 | Legend is a graphical object, whics displays legend of the chart. Legend state is updated by ChartView, when |
|
68 | 68 | series have been changed. Legend is used via ChartView class. For example: |
|
69 | 69 | \code |
|
70 | 70 | ChartView { |
|
71 | 71 | legend.visible: true |
|
72 | 72 | legend.alignment: Qt.AlignBottom |
|
73 | 73 | // Add a few series... |
|
74 | 74 | } |
|
75 | 75 | \endcode |
|
76 | 76 | |
|
77 | 77 | \image examples_percentbarchart_legend.png |
|
78 | 78 | */ |
|
79 | 79 | |
|
80 | 80 | /*! |
|
81 | 81 | \property QLegend::alignment |
|
82 | 82 | \brief The alignment of the legend. |
|
83 | 83 | |
|
84 | 84 | Legend paints on the defined position in the chart. The following alignments are supported: |
|
85 | 85 | Qt::AlignTop, Qt::AlignBottom, Qt::AlignLeft, Qt::AlignRight. If you set more than one flag the result is undefined. |
|
86 | 86 | */ |
|
87 | 87 | /*! |
|
88 | 88 | \qmlproperty Qt.Alignment Legend::alignment |
|
89 | 89 | \brief The alignment of the legend. |
|
90 | 90 | |
|
91 | 91 | Legend paints on the defined position in the chart. The following alignments are supported: |
|
92 | 92 | Qt.AlignTop, Qt.AlignBottom, Qt.AlignLeft, Qt.AlignRight. If you set more than one flag the result is undefined. |
|
93 | 93 | */ |
|
94 | 94 | |
|
95 | 95 | /*! |
|
96 | 96 | \property QLegend::backgroundVisible |
|
97 | 97 | Whether the legend background is visible or not. |
|
98 | 98 | */ |
|
99 | 99 | /*! |
|
100 | 100 | \qmlproperty bool Legend::backgroundVisible |
|
101 | 101 | Whether the legend background is visible or not. |
|
102 | 102 | */ |
|
103 | 103 | |
|
104 | 104 | /*! |
|
105 | 105 | \property QLegend::color |
|
106 | 106 | The color of the legend, i.e. the background (brush) color. Note that if you change the color |
|
107 | 107 | of the legend, the style of the legend brush is set to Qt::SolidPattern. |
|
108 | 108 | */ |
|
109 | 109 | /*! |
|
110 | 110 | \qmlproperty color Legend::color |
|
111 | 111 | The color of the legend, i.e. the background (brush) color. |
|
112 | 112 | */ |
|
113 | 113 | |
|
114 | 114 | /*! |
|
115 | 115 | \property QLegend::borderColor |
|
116 | 116 | The border color of the legend, i.e. the line color. |
|
117 | 117 | */ |
|
118 | 118 | /*! |
|
119 | 119 | \qmlproperty color Legend::borderColor |
|
120 | 120 | The border color of the legend, i.e. the line color. |
|
121 | 121 | */ |
|
122 | 122 | |
|
123 | 123 | /*! |
|
124 | 124 | \property QLegend::font |
|
125 | 125 | The font of markers used by legend |
|
126 | 126 | */ |
|
127 | 127 | /*! |
|
128 | 128 | \qmlproperty color Legend::font |
|
129 | 129 | The font of markers used by legend |
|
130 | 130 | */ |
|
131 | 131 | |
|
132 | 132 | /*! |
|
133 | 133 | \property QLegend::labelColor |
|
134 | 134 | The color of brush used to draw labels. |
|
135 | 135 | */ |
|
136 | 136 | /*! |
|
137 | 137 | \qmlproperty color QLegend::labelColor |
|
138 | 138 | The color of brush used to draw labels. |
|
139 | 139 | */ |
|
140 | 140 | |
|
141 | 141 | /*! |
|
142 | 142 | \fn void QLegend::backgroundVisibleChanged(bool) |
|
143 | 143 | The visibility of the legend background changed to \a visible. |
|
144 | 144 | */ |
|
145 | 145 | |
|
146 | 146 | /*! |
|
147 | 147 | \fn void QLegend::colorChanged(QColor) |
|
148 | 148 | The color of the legend background changed to \a color. |
|
149 | 149 | */ |
|
150 | 150 | |
|
151 | 151 | /*! |
|
152 | 152 | \fn void QLegend::borderColorChanged(QColor) |
|
153 | 153 | The border color of the legend background changed to \a color. |
|
154 | 154 | */ |
|
155 | 155 | |
|
156 | 156 | /*! |
|
157 | 157 | \fn void QLegend::fontChanged(QFont) |
|
158 | 158 | The font of markers of the legend changed to \a font. |
|
159 | 159 | */ |
|
160 | 160 | |
|
161 | 161 | /*! |
|
162 | 162 | \fn void QLegend::labelBrushChanged(QBrush brush) |
|
163 | 163 | This signal is emitted when the brush used to draw labels has changed to \a brush. |
|
164 | 164 | */ |
|
165 | 165 | |
|
166 | 166 | /*! |
|
167 | 167 | \fn void QLegend::labelColorChanged(QColor color) |
|
168 | 168 | This signal is emitted when the color of brush used to draw labels has changed to \a color. |
|
169 | 169 | */ |
|
170 | 170 | |
|
171 | 171 | /*! |
|
172 | 172 | \fn qreal QLegend::minWidth() const |
|
173 | 173 | Returns minimum width of the legend |
|
174 | 174 | */ |
|
175 | 175 | |
|
176 | 176 | /*! |
|
177 | 177 | \fn qreal QLegend::minHeight() const |
|
178 | 178 | Returns minimum height of the legend |
|
179 | 179 | */ |
|
180 | 180 | |
|
181 | 181 | /*! |
|
182 | 182 | Constructs the legend object and sets the parent to \a parent |
|
183 | 183 | */ |
|
184 | 184 | |
|
185 | 185 | QLegend::QLegend(QChart *chart):QGraphicsWidget(chart), |
|
186 | 186 | d_ptr(new QLegendPrivate(chart->d_ptr->m_presenter,chart,this)) |
|
187 | 187 | { |
|
188 | 188 | setZValue(ChartPresenter::LegendZValue); |
|
189 | 189 | setFlags(QGraphicsItem::ItemClipsChildrenToShape); |
|
190 | 190 | QObject::connect(chart->d_ptr->m_dataset,SIGNAL(seriesAdded(QAbstractSeries*,Domain*)),d_ptr.data(),SLOT(handleSeriesAdded(QAbstractSeries*,Domain*))); |
|
191 | 191 | QObject::connect(chart->d_ptr->m_dataset,SIGNAL(seriesRemoved(QAbstractSeries*)),d_ptr.data(),SLOT(handleSeriesRemoved(QAbstractSeries*))); |
|
192 | 192 | QObject::connect(chart->d_ptr->m_dataset,SIGNAL(seriesUpdated(QAbstractSeries*)),d_ptr.data(),SLOT(handleSeriesUpdated(QAbstractSeries*))); |
|
193 | 193 | setLayout(d_ptr->m_layout); |
|
194 | 194 | } |
|
195 | 195 | |
|
196 | 196 | /*! |
|
197 | 197 | Destroys the legend object. Legend is always owned by a QChart, so an application should never call this. |
|
198 | 198 | */ |
|
199 | 199 | QLegend::~QLegend() |
|
200 | 200 | { |
|
201 | 201 | } |
|
202 | 202 | |
|
203 | 203 | /*! |
|
204 | 204 | \internal |
|
205 | 205 | */ |
|
206 | 206 | void QLegend::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) |
|
207 | 207 | { |
|
208 | 208 | Q_UNUSED(option) |
|
209 | 209 | Q_UNUSED(widget) |
|
210 | 210 | if(!d_ptr->m_backgroundVisible) return; |
|
211 | 211 | |
|
212 | 212 | painter->setOpacity(opacity()); |
|
213 | 213 | painter->setPen(d_ptr->m_pen); |
|
214 | 214 | painter->setBrush(d_ptr->m_brush); |
|
215 | 215 | painter->drawRoundRect(rect(),d_ptr->roundness(rect().width()),d_ptr->roundness(rect().height())); |
|
216 | 216 | |
|
217 | 217 | } |
|
218 | 218 | |
|
219 | 219 | |
|
220 | 220 | /*! |
|
221 | 221 | Sets the \a brush of legend. Brush affects the background of legend. |
|
222 | 222 | */ |
|
223 | 223 | void QLegend::setBrush(const QBrush &brush) |
|
224 | 224 | { |
|
225 | 225 | if (d_ptr->m_brush != brush) { |
|
226 | 226 | d_ptr->m_brush = brush; |
|
227 | 227 | update(); |
|
228 | emit colorChanged(brush.color()); | |
|
228 | 229 | } |
|
229 | 230 | } |
|
230 | 231 | |
|
231 | 232 | /*! |
|
232 | 233 | Returns the brush used by legend. |
|
233 | 234 | */ |
|
234 | 235 | QBrush QLegend::brush() const |
|
235 | 236 | { |
|
236 | 237 | return d_ptr->m_brush; |
|
237 | 238 | } |
|
238 | 239 | |
|
239 | 240 | void QLegend::setColor(QColor color) |
|
240 | 241 | { |
|
241 | 242 | QBrush b = d_ptr->m_brush; |
|
242 | 243 | if (b.style() != Qt::SolidPattern || b.color() != color) { |
|
243 | 244 | b.setStyle(Qt::SolidPattern); |
|
244 | 245 | b.setColor(color); |
|
245 | 246 | setBrush(b); |
|
246 | emit colorChanged(color); | |
|
247 | 247 | } |
|
248 | 248 | } |
|
249 | 249 | |
|
250 | 250 | QColor QLegend::color() |
|
251 | 251 | { |
|
252 | 252 | return d_ptr->m_brush.color(); |
|
253 | 253 | } |
|
254 | 254 | |
|
255 | 255 | /*! |
|
256 | 256 | Sets the \a pen of legend. Pen affects the legend borders. |
|
257 | 257 | */ |
|
258 | 258 | void QLegend::setPen(const QPen &pen) |
|
259 | 259 | { |
|
260 | 260 | if (d_ptr->m_pen != pen) { |
|
261 | 261 | d_ptr->m_pen = pen; |
|
262 | 262 | update(); |
|
263 | emit borderColorChanged(pen.color()); | |
|
263 | 264 | } |
|
264 | 265 | } |
|
265 | 266 | |
|
266 | 267 | /*! |
|
267 | 268 | Returns the pen used by legend |
|
268 | 269 | */ |
|
269 | 270 | |
|
270 | 271 | QPen QLegend::pen() const |
|
271 | 272 | { |
|
272 | 273 | return d_ptr->m_pen; |
|
273 | 274 | } |
|
274 | 275 | |
|
275 | 276 | void QLegend::setFont(const QFont &font) |
|
276 | 277 | { |
|
277 | 278 | if (d_ptr->m_font != font) { |
|
278 | 279 | d_ptr->m_font = font; |
|
279 | 280 | |
|
280 | 281 | foreach (LegendMarker *marker, d_ptr->markers()) { |
|
281 | 282 | marker->setFont(d_ptr->m_font); |
|
282 | 283 | } |
|
283 | 284 | layout()->invalidate(); |
|
284 | 285 | emit fontChanged(font); |
|
285 | 286 | } |
|
286 | 287 | } |
|
287 | 288 | |
|
288 | 289 | QFont QLegend::font() const |
|
289 | 290 | { |
|
290 | 291 | return d_ptr->m_font; |
|
291 | 292 | } |
|
292 | 293 | |
|
293 | 294 | void QLegend::setBorderColor(QColor color) |
|
294 | 295 | { |
|
295 | 296 | QPen p = d_ptr->m_pen; |
|
296 | 297 | if (p.color() != color) { |
|
297 | 298 | p.setColor(color); |
|
298 | 299 | setPen(p); |
|
299 | emit borderColorChanged(color); | |
|
300 | 300 | } |
|
301 | 301 | } |
|
302 | 302 | |
|
303 | 303 | QColor QLegend::borderColor() |
|
304 | 304 | { |
|
305 | 305 | return d_ptr->m_pen.color(); |
|
306 | 306 | } |
|
307 | 307 | |
|
308 | 308 | /*! |
|
309 | 309 | Set brush used to draw labels to \a brush. |
|
310 | 310 | */ |
|
311 | 311 | void QLegend::setLabelBrush(const QBrush &brush) |
|
312 | 312 | { |
|
313 | 313 | if (d_ptr->m_labelBrush != brush) { |
|
314 | ||
|
315 | 314 | d_ptr->m_labelBrush = brush; |
|
316 | ||
|
317 | 315 | foreach (LegendMarker *marker, d_ptr->markers()) { |
|
318 | 316 | marker->setLabelBrush(d_ptr->m_labelBrush); |
|
319 | 317 | } |
|
320 |
emit label |
|
|
318 | emit labelColorChanged(brush.color()); | |
|
321 | 319 | } |
|
322 | 320 | } |
|
323 | 321 | |
|
324 | 322 | /*! |
|
325 | 323 | Brush used to draw labels. |
|
326 | 324 | */ |
|
327 | 325 | QBrush QLegend::labelBrush() const |
|
328 | 326 | { |
|
329 | 327 | return d_ptr->m_labelBrush; |
|
330 | 328 | } |
|
331 | 329 | |
|
332 | 330 | void QLegend::setLabelColor(QColor color) |
|
333 | 331 | { |
|
334 | 332 | QBrush b = d_ptr->m_labelBrush; |
|
335 | 333 | if (b.style() != Qt::SolidPattern || b.color() != color) { |
|
336 | 334 | b.setStyle(Qt::SolidPattern); |
|
337 | 335 | b.setColor(color); |
|
338 | 336 | setLabelBrush(b); |
|
339 | emit labelColorChanged(color); | |
|
340 | 337 | } |
|
341 | 338 | } |
|
342 | 339 | |
|
343 | 340 | QColor QLegend::labelColor() const |
|
344 | 341 | { |
|
345 | 342 | return d_ptr->m_labelBrush.color(); |
|
346 | 343 | } |
|
347 | 344 | |
|
348 | 345 | |
|
349 | 346 | void QLegend::setAlignment(Qt::Alignment alignment) |
|
350 | 347 | { |
|
351 | 348 | if(d_ptr->m_alignment!=alignment) { |
|
352 | 349 | d_ptr->m_alignment = alignment; |
|
353 | 350 | updateGeometry(); |
|
354 | 351 | if(isAttachedToChart()){ |
|
355 | 352 | d_ptr->m_presenter->layout()->invalidate(); |
|
356 | 353 | }else{ |
|
357 | 354 | layout()->invalidate(); |
|
358 | 355 | } |
|
359 | 356 | } |
|
360 | 357 | } |
|
361 | 358 | |
|
362 | 359 | Qt::Alignment QLegend::alignment() const |
|
363 | 360 | { |
|
364 | 361 | return d_ptr->m_alignment; |
|
365 | 362 | } |
|
366 | 363 | |
|
367 | 364 | /*! |
|
368 | 365 | Detaches the legend from chart. Chart won't change layout of the legend. |
|
369 | 366 | */ |
|
370 | 367 | void QLegend::detachFromChart() |
|
371 | 368 | { |
|
372 | 369 | d_ptr->m_attachedToChart = false; |
|
373 | 370 | d_ptr->m_layout->invalidate(); |
|
374 | 371 | setParent(0); |
|
375 | 372 | |
|
376 | 373 | } |
|
377 | 374 | |
|
378 | 375 | /*! |
|
379 | 376 | Attaches the legend to chart. Chart may change layout of the legend. |
|
380 | 377 | */ |
|
381 | 378 | void QLegend::attachToChart() |
|
382 | 379 | { |
|
383 | 380 | d_ptr->m_attachedToChart = true; |
|
384 | 381 | d_ptr->m_layout->invalidate(); |
|
385 | 382 | setParent(d_ptr->m_chart); |
|
386 | 383 | } |
|
387 | 384 | |
|
388 | 385 | /*! |
|
389 | 386 | Returns true, if legend is attached to chart. |
|
390 | 387 | */ |
|
391 | 388 | bool QLegend::isAttachedToChart() |
|
392 | 389 | { |
|
393 | 390 | return d_ptr->m_attachedToChart; |
|
394 | 391 | } |
|
395 | 392 | |
|
396 | 393 | /*! |
|
397 | 394 | Sets the visibility of legend background to \a visible |
|
398 | 395 | */ |
|
399 | 396 | void QLegend::setBackgroundVisible(bool visible) |
|
400 | 397 | { |
|
401 | 398 | if(d_ptr->m_backgroundVisible != visible) { |
|
402 | 399 | d_ptr->m_backgroundVisible = visible; |
|
403 | 400 | update(); |
|
404 | 401 | emit backgroundVisibleChanged(visible); |
|
405 | 402 | } |
|
406 | 403 | } |
|
407 | 404 | |
|
408 | 405 | /*! |
|
409 | 406 | Returns the visibility of legend background |
|
410 | 407 | */ |
|
411 | 408 | bool QLegend::isBackgroundVisible() const |
|
412 | 409 | { |
|
413 | 410 | return d_ptr->m_backgroundVisible; |
|
414 | 411 | } |
|
415 | 412 | |
|
416 | 413 | /*! |
|
417 | 414 | \internal \a event see QGraphicsWidget for details |
|
418 | 415 | */ |
|
419 | 416 | void QLegend::hideEvent(QHideEvent *event) |
|
420 | 417 | { |
|
421 | 418 | QGraphicsWidget::hideEvent(event); |
|
422 | 419 | d_ptr->m_presenter->layout()->invalidate(); |
|
423 | 420 | } |
|
424 | 421 | |
|
425 | 422 | /*! |
|
426 | 423 | \internal \a event see QGraphicsWidget for details |
|
427 | 424 | */ |
|
428 | 425 | void QLegend::showEvent(QShowEvent *event) |
|
429 | 426 | { |
|
430 | 427 | QGraphicsWidget::showEvent(event); |
|
431 | 428 | d_ptr->m_presenter->layout()->invalidate(); |
|
432 | 429 | } |
|
433 | 430 | |
|
434 | 431 | //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
435 | 432 | |
|
436 | 433 | QLegendPrivate::QLegendPrivate(ChartPresenter* presenter, QChart *chart, QLegend *q): |
|
437 | 434 | q_ptr(q), |
|
438 | 435 | m_presenter(presenter), |
|
439 | 436 | m_layout(new LegendLayout(q)), |
|
440 | 437 | m_chart(chart), |
|
441 | 438 | m_items(new QGraphicsItemGroup(q)), |
|
442 | 439 | m_alignment(Qt::AlignTop), |
|
443 | 440 | m_brush(QBrush()), |
|
444 | 441 | m_pen(QPen()), |
|
445 | 442 | m_labelBrush(QBrush()), |
|
446 | 443 | m_diameter(5), |
|
447 | 444 | m_attachedToChart(true), |
|
448 | 445 | m_backgroundVisible(false) |
|
449 | 446 | { |
|
450 | 447 | |
|
451 | 448 | } |
|
452 | 449 | |
|
453 | 450 | QLegendPrivate::~QLegendPrivate() |
|
454 | 451 | { |
|
455 | 452 | |
|
456 | 453 | } |
|
457 | 454 | |
|
458 | 455 | void QLegendPrivate::setOffset(qreal x, qreal y) |
|
459 | 456 | { |
|
460 | 457 | m_layout->setOffset(x,y); |
|
461 | 458 | } |
|
462 | 459 | |
|
463 | 460 | QPointF QLegendPrivate::offset() const |
|
464 | 461 | { |
|
465 | 462 | return m_layout->offset(); |
|
466 | 463 | } |
|
467 | 464 | |
|
468 | 465 | int QLegendPrivate::roundness(qreal size) |
|
469 | 466 | { |
|
470 | 467 | return 100*m_diameter/int(size); |
|
471 | 468 | } |
|
472 | 469 | |
|
473 | 470 | void QLegendPrivate::handleSeriesAdded(QAbstractSeries *series, Domain *domain) |
|
474 | 471 | { |
|
475 | 472 | Q_UNUSED(domain) |
|
476 | 473 | |
|
477 | 474 | QList<LegendMarker*> markers = series->d_ptr->createLegendMarker(q_ptr); |
|
478 | 475 | |
|
479 | 476 | foreach(LegendMarker* marker, markers) { |
|
480 | 477 | marker->setFont(m_font); |
|
481 | 478 | marker->setLabelBrush(m_labelBrush); |
|
482 | 479 | m_items->addToGroup(marker); |
|
483 | 480 | m_markers<<marker; |
|
484 | 481 | } |
|
485 | 482 | |
|
486 | 483 | QObject::connect(series, SIGNAL(visibleChanged()), this, SLOT(handleSeriesVisibleChanged())); |
|
487 | 484 | |
|
488 | 485 | if(series->type() == QAbstractSeries::SeriesTypePie) { |
|
489 | 486 | QPieSeries *pieSeries = static_cast<QPieSeries *>(series); |
|
490 | 487 | QObject::connect(pieSeries, SIGNAL(added(QList<QPieSlice*>)), this, SLOT(handleUpdatePieSeries())); |
|
491 | 488 | QObject::connect(pieSeries, SIGNAL(removed(QList<QPieSlice*>)), this, SLOT(handleUpdatePieSeries())); |
|
492 | 489 | } |
|
493 | 490 | |
|
494 | 491 | q_ptr->layout()->invalidate(); |
|
495 | 492 | q_ptr->layout()->activate(); |
|
496 | 493 | } |
|
497 | 494 | |
|
498 | 495 | void QLegendPrivate::handleSeriesRemoved(QAbstractSeries *series) |
|
499 | 496 | { |
|
500 | 497 | foreach (LegendMarker *marker, m_markers) { |
|
501 | 498 | if (marker->series() == series) { |
|
502 | 499 | delete marker; |
|
503 | 500 | m_markers.removeAll(marker); |
|
504 | 501 | } |
|
505 | 502 | } |
|
506 | 503 | |
|
507 | 504 | if(series->type() == QAbstractSeries::SeriesTypePie) |
|
508 | 505 | { |
|
509 | 506 | QPieSeries *pieSeries = static_cast<QPieSeries *>(series); |
|
510 | 507 | QObject::disconnect(pieSeries, SIGNAL(added(QList<QPieSlice*>)), this, SLOT(handleUpdatePieSeries())); |
|
511 | 508 | QObject::disconnect(pieSeries, SIGNAL(removed(QList<QPieSlice*>)), this, SLOT(handleUpdatePieSeries())); |
|
512 | 509 | } |
|
513 | 510 | |
|
514 | 511 | q_ptr->layout()->invalidate(); |
|
515 | 512 | } |
|
516 | 513 | |
|
517 | 514 | void QLegendPrivate::handleSeriesUpdated(QAbstractSeries *series) |
|
518 | 515 | { |
|
519 | 516 | // TODO: find out which markers are are added or removed. Update them |
|
520 | 517 | // TODO: better implementation |
|
521 | 518 | handleSeriesRemoved(series); |
|
522 | 519 | Domain domain; |
|
523 | 520 | handleSeriesAdded(series, &domain); |
|
524 | 521 | } |
|
525 | 522 | |
|
526 | 523 | void QLegendPrivate::handleUpdatePieSeries() |
|
527 | 524 | { |
|
528 | 525 | //TODO: reimplement to be optimal |
|
529 | 526 | QPieSeries* series = qobject_cast<QPieSeries *> (sender()); |
|
530 | 527 | Q_ASSERT(series); |
|
531 | 528 | handleSeriesRemoved(series); |
|
532 | 529 | handleSeriesAdded(series, 0); |
|
533 | 530 | } |
|
534 | 531 | |
|
535 | 532 | void QLegendPrivate::handleSeriesVisibleChanged() |
|
536 | 533 | { |
|
537 | 534 | QAbstractSeries* series = qobject_cast<QAbstractSeries *> (sender()); |
|
538 | 535 | |
|
539 | 536 | foreach (LegendMarker* marker, m_markers) { |
|
540 | 537 | if (marker->series() == series) { |
|
541 | 538 | marker->setVisible(!marker->isVisible()); |
|
542 | 539 | } |
|
543 | 540 | } |
|
544 | 541 | |
|
545 | 542 | q_ptr->layout()->invalidate(); |
|
546 | 543 | } |
|
547 | 544 | |
|
548 | 545 | #include "moc_qlegend.cpp" |
|
549 | 546 | #include "moc_qlegend_p.cpp" |
|
550 | 547 | |
|
551 | 548 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,112 +1,111 | |||
|
1 | 1 | /**************************************************************************** |
|
2 | 2 | ** |
|
3 | 3 | ** Copyright (C) 2012 Digia Plc |
|
4 | 4 | ** All rights reserved. |
|
5 | 5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
6 | 6 | ** |
|
7 | 7 | ** This file is part of the Qt Commercial Charts Add-on. |
|
8 | 8 | ** |
|
9 | 9 | ** $QT_BEGIN_LICENSE$ |
|
10 | 10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
11 | 11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
12 | 12 | ** Software or, alternatively, in accordance with the terms contained in |
|
13 | 13 | ** a written agreement between you and Digia. |
|
14 | 14 | ** |
|
15 | 15 | ** If you have questions regarding the use of this file, please use |
|
16 | 16 | ** contact form at http://qt.digia.com |
|
17 | 17 | ** $QT_END_LICENSE$ |
|
18 | 18 | ** |
|
19 | 19 | ****************************************************************************/ |
|
20 | 20 | |
|
21 | 21 | #ifndef QLEGEND_H |
|
22 | 22 | #define QLEGEND_H |
|
23 | 23 | |
|
24 | 24 | #include <QChartGlobal> |
|
25 | 25 | #include <QGraphicsWidget> |
|
26 | 26 | #include <QPen> |
|
27 | 27 | #include <QBrush> |
|
28 | 28 | |
|
29 | 29 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
30 | 30 | |
|
31 | 31 | class Domain; |
|
32 | 32 | class LegendMarker; |
|
33 | 33 | class QPieSlice; |
|
34 | 34 | class QXYSeries; |
|
35 | 35 | class QBarSet; |
|
36 | 36 | class QBarSeries; |
|
37 | 37 | class QPieSeries; |
|
38 | 38 | class QAreaSeries; |
|
39 | 39 | class LegendScrollButton; |
|
40 | 40 | class QChart; |
|
41 | 41 | class QLegendPrivate; |
|
42 | 42 | |
|
43 | 43 | class QTCOMMERCIALCHART_EXPORT QLegend : public QGraphicsWidget |
|
44 | 44 | { |
|
45 | 45 | Q_OBJECT |
|
46 | 46 | Q_PROPERTY(Qt::Alignment alignment READ alignment WRITE setAlignment) |
|
47 | 47 | Q_PROPERTY(bool backgroundVisible READ isBackgroundVisible WRITE setBackgroundVisible NOTIFY backgroundVisibleChanged) |
|
48 | 48 | Q_PROPERTY(QColor color READ color WRITE setColor NOTIFY colorChanged) |
|
49 | 49 | Q_PROPERTY(QColor borderColor READ borderColor WRITE setBorderColor NOTIFY borderColorChanged) |
|
50 | 50 | Q_PROPERTY(QFont font READ font WRITE setFont NOTIFY fontChanged) |
|
51 | 51 | Q_PROPERTY(QColor labelColor READ labelColor WRITE setLabelColor NOTIFY labelColorChanged) |
|
52 | 52 | |
|
53 | 53 | private: |
|
54 | 54 | explicit QLegend(QChart *chart); |
|
55 | 55 | |
|
56 | 56 | public: |
|
57 | 57 | ~QLegend(); |
|
58 | 58 | |
|
59 | 59 | void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0); |
|
60 | 60 | |
|
61 | 61 | void setBrush(const QBrush &brush); |
|
62 | 62 | QBrush brush() const; |
|
63 | 63 | void setColor(QColor color); |
|
64 | 64 | QColor color(); |
|
65 | 65 | |
|
66 | 66 | void setPen(const QPen &pen); |
|
67 | 67 | QPen pen() const; |
|
68 | 68 | void setBorderColor(QColor color); |
|
69 | 69 | QColor borderColor(); |
|
70 | 70 | |
|
71 | 71 | void setFont(const QFont &font); |
|
72 | 72 | QFont font() const; |
|
73 | 73 | void setLabelBrush(const QBrush &brush); |
|
74 | 74 | QBrush labelBrush() const; |
|
75 | 75 | |
|
76 | 76 | void setLabelColor(QColor color); |
|
77 | 77 | QColor labelColor() const; |
|
78 | 78 | |
|
79 | 79 | void setAlignment(Qt::Alignment alignment); |
|
80 | 80 | Qt::Alignment alignment() const; |
|
81 | 81 | |
|
82 | 82 | void detachFromChart(); |
|
83 | 83 | void attachToChart(); |
|
84 | 84 | bool isAttachedToChart(); |
|
85 | 85 | |
|
86 | 86 | void setBackgroundVisible(bool visible = true); |
|
87 | 87 | bool isBackgroundVisible() const; |
|
88 | 88 | |
|
89 | 89 | |
|
90 | 90 | protected: |
|
91 | 91 | void hideEvent(QHideEvent *event); |
|
92 | 92 | void showEvent(QShowEvent *event); |
|
93 | 93 | |
|
94 | 94 | Q_SIGNALS: |
|
95 | 95 | void backgroundVisibleChanged(bool visible); |
|
96 | 96 | void colorChanged(QColor color); |
|
97 | 97 | void borderColorChanged(QColor color); |
|
98 | 98 | void fontChanged(QFont font); |
|
99 | void labelBrushChanged(QBrush brush); | |
|
100 | 99 | void labelColorChanged(QColor color); |
|
101 | 100 | |
|
102 | 101 | private: |
|
103 | 102 | QScopedPointer<QLegendPrivate> d_ptr; |
|
104 | 103 | Q_DISABLE_COPY(QLegend) |
|
105 | 104 | friend class LegendScroller; |
|
106 | 105 | friend class LegendLayout; |
|
107 | 106 | friend class ChartLayout; |
|
108 | 107 | }; |
|
109 | 108 | |
|
110 | 109 | QTCOMMERCIALCHART_END_NAMESPACE |
|
111 | 110 | |
|
112 | 111 | #endif // QLEGEND_H |
@@ -1,628 +1,665 | |||
|
1 | 1 | /**************************************************************************** |
|
2 | 2 | ** |
|
3 | 3 | ** Copyright (C) 2012 Digia Plc |
|
4 | 4 | ** All rights reserved. |
|
5 | 5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
6 | 6 | ** |
|
7 | 7 | ** This file is part of the Qt Commercial Charts Add-on. |
|
8 | 8 | ** |
|
9 | 9 | ** $QT_BEGIN_LICENSE$ |
|
10 | 10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
11 | 11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
12 | 12 | ** Software or, alternatively, in accordance with the terms contained in |
|
13 | 13 | ** a written agreement between you and Digia. |
|
14 | 14 | ** |
|
15 | 15 | ** If you have questions regarding the use of this file, please use |
|
16 | 16 | ** contact form at http://qt.digia.com |
|
17 | 17 | ** $QT_END_LICENSE$ |
|
18 | 18 | ** |
|
19 | 19 | ****************************************************************************/ |
|
20 | 20 | |
|
21 | 21 | #include <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 <qbarseries.h> |
|
29 | 29 | #include <qpercentbarseries.h> |
|
30 | 30 | #include <qstackedbarseries.h> |
|
31 | 31 | #include <qvaluesaxis.h> |
|
32 | 32 | |
|
33 | 33 | QTCOMMERCIALCHART_USE_NAMESPACE |
|
34 | 34 | |
|
35 | 35 | Q_DECLARE_METATYPE(QAbstractAxis *) |
|
36 | 36 | Q_DECLARE_METATYPE(QValuesAxis *) |
|
37 | 37 | Q_DECLARE_METATYPE(QAbstractSeries *) |
|
38 | 38 | Q_DECLARE_METATYPE(QChart::AnimationOption) |
|
39 | 39 | Q_DECLARE_METATYPE(QBrush) |
|
40 | 40 | Q_DECLARE_METATYPE(QPen) |
|
41 | 41 | Q_DECLARE_METATYPE(QChart::ChartTheme) |
|
42 | 42 | |
|
43 | 43 | class tst_QChart : public QObject |
|
44 | 44 | { |
|
45 | 45 | Q_OBJECT |
|
46 | 46 | |
|
47 | 47 | public slots: |
|
48 | 48 | void initTestCase(); |
|
49 | 49 | void cleanupTestCase(); |
|
50 | 50 | void init(); |
|
51 | 51 | void cleanup(); |
|
52 | 52 | |
|
53 | 53 | private slots: |
|
54 | 54 | void qchart_data(); |
|
55 | 55 | void qchart(); |
|
56 | 56 | |
|
57 | 57 | void addSeries_data(); |
|
58 | 58 | void addSeries(); |
|
59 | 59 | void animationOptions_data(); |
|
60 | 60 | void animationOptions(); |
|
61 | 61 | void axisX_data(); |
|
62 | 62 | void axisX(); |
|
63 | 63 | void axisY_data(); |
|
64 | 64 | void axisY(); |
|
65 | 65 | void backgroundBrush_data(); |
|
66 | 66 | void backgroundBrush(); |
|
67 | 67 | void backgroundPen_data(); |
|
68 | 68 | void backgroundPen(); |
|
69 | 69 | void isBackgroundVisible_data(); |
|
70 | 70 | void isBackgroundVisible(); |
|
71 | 71 | void legend_data(); |
|
72 | 72 | void legend(); |
|
73 | 73 | void margins_data(); |
|
74 | 74 | void margins(); |
|
75 | 75 | void removeAllSeries_data(); |
|
76 | 76 | void removeAllSeries(); |
|
77 | 77 | void removeSeries_data(); |
|
78 | 78 | void removeSeries(); |
|
79 | 79 | void scrollDown_data(); |
|
80 | 80 | void scrollDown(); |
|
81 | 81 | void scrollLeft_data(); |
|
82 | 82 | void scrollLeft(); |
|
83 | 83 | void scrollRight_data(); |
|
84 | 84 | void scrollRight(); |
|
85 | 85 | void scrollUp_data(); |
|
86 | 86 | void scrollUp(); |
|
87 | 87 | void theme_data(); |
|
88 | 88 | void theme(); |
|
89 | 89 | void title_data(); |
|
90 | 90 | void title(); |
|
91 | 91 | void titleBrush_data(); |
|
92 | 92 | void titleBrush(); |
|
93 | 93 | void titleFont_data(); |
|
94 | 94 | void titleFont(); |
|
95 | 95 | void zoomIn_data(); |
|
96 | 96 | void zoomIn(); |
|
97 | 97 | void zoomOut_data(); |
|
98 | 98 | void zoomOut(); |
|
99 | 99 | |
|
100 | 100 | private: |
|
101 | 101 | void createTestData(); |
|
102 | 102 | |
|
103 | 103 | private: |
|
104 | 104 | QChartView* m_view; |
|
105 | 105 | QChart* m_chart; |
|
106 | 106 | }; |
|
107 | 107 | |
|
108 | 108 | void tst_QChart::initTestCase() |
|
109 | 109 | { |
|
110 | 110 | |
|
111 | 111 | } |
|
112 | 112 | |
|
113 | 113 | void tst_QChart::cleanupTestCase() |
|
114 | 114 | { |
|
115 | 115 | |
|
116 | 116 | } |
|
117 | 117 | |
|
118 | 118 | void tst_QChart::init() |
|
119 | 119 | { |
|
120 | 120 | m_view = new QChartView(new QChart()); |
|
121 | 121 | m_chart = m_view->chart(); |
|
122 | 122 | } |
|
123 | 123 | |
|
124 | 124 | void tst_QChart::createTestData() |
|
125 | 125 | { |
|
126 | 126 | QLineSeries* series0 = new QLineSeries(this); |
|
127 | 127 | *series0 << QPointF(0, 0) << QPointF(100, 100); |
|
128 | 128 | m_chart->addSeries(series0); |
|
129 | 129 | m_view->show(); |
|
130 | 130 | QTest::qWaitForWindowShown(m_view); |
|
131 | 131 | } |
|
132 | 132 | |
|
133 | 133 | void tst_QChart::cleanup() |
|
134 | 134 | { |
|
135 | 135 | delete m_view; |
|
136 | 136 | m_view = 0; |
|
137 | 137 | m_chart = 0; |
|
138 | 138 | } |
|
139 | 139 | |
|
140 | 140 | void tst_QChart::qchart_data() |
|
141 | 141 | { |
|
142 | 142 | } |
|
143 | 143 | |
|
144 | 144 | void tst_QChart::qchart() |
|
145 | 145 | { |
|
146 | 146 | QVERIFY(m_chart); |
|
147 | 147 | QVERIFY(m_chart->legend()); |
|
148 | 148 | QVERIFY(m_chart->legend()->isVisible()); |
|
149 | 149 | |
|
150 | 150 | QCOMPARE(m_chart->animationOptions(), QChart::NoAnimation); |
|
151 | 151 | QVERIFY(m_chart->axisX()); |
|
152 | 152 | QVERIFY(m_chart->axisY()); |
|
153 | 153 | QVERIFY(m_chart->backgroundBrush()!=QBrush()); |
|
154 | 154 | QVERIFY(m_chart->backgroundPen()!=QPen()); |
|
155 | 155 | QCOMPARE(m_chart->isBackgroundVisible(), true); |
|
156 | 156 | |
|
157 | 157 | QVERIFY(m_chart->margins().top()>0); |
|
158 | 158 | QVERIFY(m_chart->margins().left()>0); |
|
159 | 159 | QVERIFY(m_chart->margins().right()>0); |
|
160 | 160 | QVERIFY(m_chart->margins().bottom()>0); |
|
161 | 161 | |
|
162 | 162 | QCOMPARE(m_chart->theme(), QChart::ChartThemeLight); |
|
163 | 163 | QCOMPARE(m_chart->title(), QString()); |
|
164 | 164 | |
|
165 | 165 | //QCOMPARE(m_chart->titleBrush(),QBrush()); |
|
166 | 166 | //QCOMPARE(m_chart->titleFont(),QFont()); |
|
167 | 167 | |
|
168 | 168 | m_chart->removeAllSeries(); |
|
169 | 169 | m_chart->scrollDown(); |
|
170 | 170 | m_chart->scrollLeft(); |
|
171 | 171 | m_chart->scrollRight(); |
|
172 | 172 | m_chart->scrollUp(); |
|
173 | 173 | |
|
174 | 174 | m_chart->zoomIn(); |
|
175 | 175 | m_chart->zoomIn(QRectF()); |
|
176 | 176 | m_chart->zoomOut(); |
|
177 | 177 | } |
|
178 | 178 | |
|
179 | 179 | void tst_QChart::addSeries_data() |
|
180 | 180 | { |
|
181 | 181 | QTest::addColumn<QAbstractSeries *>("series"); |
|
182 | 182 | QTest::addColumn<QAbstractAxis *>("axis"); |
|
183 | 183 | |
|
184 | 184 | QAbstractSeries* series0 = new QLineSeries(this); |
|
185 | 185 | QAbstractSeries* series1 = new QAreaSeries(static_cast<QLineSeries*>(series0)); |
|
186 | 186 | QAbstractSeries* series2 = new QScatterSeries(this); |
|
187 | 187 | QAbstractSeries* series3 = new QSplineSeries(this); |
|
188 | 188 | QAbstractSeries* series4 = new QPieSeries(this); |
|
189 | 189 | QAbstractSeries* series5 = new QBarSeries(this); |
|
190 | 190 | QAbstractSeries* series6 = new QPercentBarSeries(this); |
|
191 | 191 | QAbstractSeries* series7 = new QStackedBarSeries(this); |
|
192 | 192 | |
|
193 | 193 | QValuesAxis* axis = new QValuesAxis(this); |
|
194 | 194 | |
|
195 | 195 | QTest::newRow("default axis: lineSeries") << series0 << (QAbstractAxis*) 0; |
|
196 | 196 | QTest::newRow("axis0: lineSeries") << series0 << axis; |
|
197 | 197 | QTest::newRow("default axis: areaSeries") << series1 << (QAbstractAxis*) 0; |
|
198 | 198 | QTest::newRow("axis: areaSeries") << series1 << axis; |
|
199 | 199 | QTest::newRow("default axis: scatterSeries") << series2 << (QAbstractAxis*) 0; |
|
200 | 200 | QTest::newRow("axis1: scatterSeries") << series2 << axis; |
|
201 | 201 | QTest::newRow("default axis: splineSeries") << series3 << (QAbstractAxis*) 0; |
|
202 | 202 | QTest::newRow("axis: splineSeries") << series3 << axis; |
|
203 | 203 | QTest::newRow("default axis: pieSeries") << series4 << (QAbstractAxis*) 0; |
|
204 | 204 | QTest::newRow("axis: pieSeries") << series4 << axis; |
|
205 | 205 | QTest::newRow("default axis: barSeries") << series5 << (QAbstractAxis*) 0; |
|
206 | 206 | QTest::newRow("axis: barSeries") << series5 << axis; |
|
207 | 207 | QTest::newRow("default axis: percentBarSeries") << series6 << (QAbstractAxis*) 0; |
|
208 | 208 | QTest::newRow("axis: barSeries") << series6 << axis; |
|
209 | 209 | QTest::newRow("default axis: stackedBarSeries") << series7 << (QAbstractAxis*) 0; |
|
210 | 210 | QTest::newRow("axis: barSeries") << series7 << axis; |
|
211 | 211 | |
|
212 | 212 | } |
|
213 | 213 | |
|
214 | 214 | void tst_QChart::addSeries() |
|
215 | 215 | { |
|
216 | 216 | QFETCH(QAbstractSeries *, series); |
|
217 | 217 | QFETCH(QAbstractAxis *, axis); |
|
218 | 218 | m_view->show(); |
|
219 | 219 | QTest::qWaitForWindowShown(m_view); |
|
220 | 220 | if(!axis) axis = m_chart->axisY(); |
|
221 | 221 | QVERIFY(!series->chart()); |
|
222 | 222 | QCOMPARE(m_chart->series().count(), 0); |
|
223 | 223 | m_chart->addSeries(series); |
|
224 | 224 | m_chart->setAxisY(series,axis); |
|
225 | 225 | QCOMPARE(m_chart->series().count(), 1); |
|
226 | 226 | QCOMPARE(m_chart->series().first(), series); |
|
227 | 227 | QVERIFY(series->chart() == m_chart); |
|
228 | 228 | QCOMPARE(m_chart->axisY(series),axis); |
|
229 | 229 | m_chart->removeSeries(series); |
|
230 | 230 | QVERIFY(!series->chart()); |
|
231 | 231 | QCOMPARE(m_chart->series().count(), 0); |
|
232 | 232 | } |
|
233 | 233 | |
|
234 | 234 | void tst_QChart::animationOptions_data() |
|
235 | 235 | { |
|
236 | 236 | QTest::addColumn<QChart::AnimationOption>("animationOptions"); |
|
237 | 237 | QTest::newRow("AllAnimations") << QChart::AllAnimations; |
|
238 | 238 | QTest::newRow("NoAnimation") << QChart::NoAnimation; |
|
239 | 239 | QTest::newRow("GridAxisAnimations") << QChart::GridAxisAnimations; |
|
240 | 240 | QTest::newRow("SeriesAnimations") << QChart::SeriesAnimations; |
|
241 | 241 | } |
|
242 | 242 | |
|
243 | 243 | void tst_QChart::animationOptions() |
|
244 | 244 | { |
|
245 | 245 | createTestData(); |
|
246 | 246 | QFETCH(QChart::AnimationOption, animationOptions); |
|
247 | 247 | m_chart->setAnimationOptions(animationOptions); |
|
248 | 248 | QCOMPARE(m_chart->animationOptions(), animationOptions); |
|
249 | 249 | } |
|
250 | 250 | |
|
251 | 251 | void tst_QChart::axisX_data() |
|
252 | 252 | { |
|
253 | 253 | |
|
254 | 254 | } |
|
255 | 255 | |
|
256 | 256 | void tst_QChart::axisX() |
|
257 | 257 | { |
|
258 | 258 | QVERIFY(m_chart->axisX()); |
|
259 | 259 | QAbstractAxis* axis = m_chart->axisX(); |
|
260 | 260 | createTestData(); |
|
261 | 261 | //it should be the same axis |
|
262 | 262 | QCOMPARE(axis,m_chart->axisX()); |
|
263 | 263 | } |
|
264 | 264 | |
|
265 | 265 | void tst_QChart::axisY_data() |
|
266 | 266 | { |
|
267 | 267 | QTest::addColumn<QAbstractAxis*>("axis0"); |
|
268 | 268 | QTest::addColumn<QAbstractAxis*>("axis1"); |
|
269 | 269 | QTest::addColumn<QAbstractAxis*>("axis2"); |
|
270 | 270 | QTest::newRow("1 defualt, 2 optional") << (QAbstractAxis*)0 << new QValuesAxis() << new QValuesAxis(); |
|
271 | 271 | QTest::newRow("3 optional") << new QValuesAxis() << new QValuesAxis() << new QValuesAxis(); |
|
272 | 272 | } |
|
273 | 273 | |
|
274 | 274 | |
|
275 | 275 | void tst_QChart::axisY() |
|
276 | 276 | { |
|
277 | 277 | QFETCH(QAbstractAxis*, axis0); |
|
278 | 278 | QFETCH(QAbstractAxis*, axis1); |
|
279 | 279 | QFETCH(QAbstractAxis*, axis2); |
|
280 | 280 | |
|
281 | 281 | QAbstractAxis* defaultAxisY = m_chart->axisY(); |
|
282 | 282 | |
|
283 | 283 | QVERIFY2(defaultAxisY, "Missing axisY."); |
|
284 | 284 | |
|
285 | 285 | QLineSeries* series0 = new QLineSeries(); |
|
286 | 286 | m_chart->addSeries(series0); |
|
287 | 287 | m_chart->setAxisY(series0,axis0); |
|
288 | 288 | |
|
289 | 289 | QLineSeries* series1 = new QLineSeries(); |
|
290 | 290 | m_chart->addSeries(series1); |
|
291 | 291 | m_chart->setAxisY(series1,axis1); |
|
292 | 292 | |
|
293 | 293 | QLineSeries* series2 = new QLineSeries(); |
|
294 | 294 | m_chart->addSeries(series2); |
|
295 | 295 | m_chart->setAxisY(series2,axis2); |
|
296 | 296 | |
|
297 | 297 | if (!axis0) |
|
298 | 298 | axis0 = defaultAxisY; |
|
299 | 299 | if (!axis1) |
|
300 | 300 | axis1 = defaultAxisY; |
|
301 | 301 | if (!axis2) |
|
302 | 302 | axis2 = defaultAxisY; |
|
303 | 303 | |
|
304 | 304 | QVERIFY(m_chart->axisY(series0) == axis0); |
|
305 | 305 | QVERIFY(m_chart->axisY(series1) == axis1); |
|
306 | 306 | QVERIFY(m_chart->axisY(series2) == axis2); |
|
307 | 307 | } |
|
308 | 308 | |
|
309 | 309 | void tst_QChart::backgroundBrush_data() |
|
310 | 310 | { |
|
311 | 311 | QTest::addColumn<QBrush>("backgroundBrush"); |
|
312 | 312 | QTest::newRow("null") << QBrush(); |
|
313 | 313 | QTest::newRow("blue") << QBrush(Qt::blue); |
|
314 | 314 | QTest::newRow("white") << QBrush(Qt::white); |
|
315 | 315 | QTest::newRow("black") << QBrush(Qt::black); |
|
316 | 316 | } |
|
317 | 317 | |
|
318 | 318 | void tst_QChart::backgroundBrush() |
|
319 | 319 | { |
|
320 | 320 | QFETCH(QBrush, backgroundBrush); |
|
321 | 321 | m_chart->setBackgroundBrush(backgroundBrush); |
|
322 | 322 | QCOMPARE(m_chart->backgroundBrush(), backgroundBrush); |
|
323 | 323 | } |
|
324 | 324 | |
|
325 | 325 | void tst_QChart::backgroundPen_data() |
|
326 | 326 | { |
|
327 | 327 | QTest::addColumn<QPen>("backgroundPen"); |
|
328 | 328 | QTest::newRow("null") << QPen(); |
|
329 | 329 | QTest::newRow("blue") << QPen(Qt::blue); |
|
330 | 330 | QTest::newRow("white") << QPen(Qt::white); |
|
331 | 331 | QTest::newRow("black") << QPen(Qt::black); |
|
332 | 332 | } |
|
333 | 333 | |
|
334 | 334 | |
|
335 | 335 | void tst_QChart::backgroundPen() |
|
336 | 336 | { |
|
337 | 337 | QFETCH(QPen, backgroundPen); |
|
338 | 338 | m_chart->setBackgroundPen(backgroundPen); |
|
339 | 339 | QCOMPARE(m_chart->backgroundPen(), backgroundPen); |
|
340 | 340 | } |
|
341 | 341 | |
|
342 | 342 | void tst_QChart::isBackgroundVisible_data() |
|
343 | 343 | { |
|
344 | 344 | QTest::addColumn<bool>("isBackgroundVisible"); |
|
345 | 345 | QTest::newRow("true") << true; |
|
346 | 346 | QTest::newRow("false") << false; |
|
347 | 347 | } |
|
348 | 348 | |
|
349 | 349 | void tst_QChart::isBackgroundVisible() |
|
350 | 350 | { |
|
351 | 351 | QFETCH(bool, isBackgroundVisible); |
|
352 | 352 | m_chart->setBackgroundVisible(isBackgroundVisible); |
|
353 | 353 | QCOMPARE(m_chart->isBackgroundVisible(), isBackgroundVisible); |
|
354 | 354 | } |
|
355 | 355 | |
|
356 | 356 | void tst_QChart::legend_data() |
|
357 | 357 | { |
|
358 | 358 | |
|
359 | 359 | } |
|
360 | 360 | |
|
361 | 361 | void tst_QChart::legend() |
|
362 | 362 | { |
|
363 |
Q |
|
|
363 | QLegend *legend = m_chart->legend(); | |
|
364 | QVERIFY(legend); | |
|
365 | ||
|
366 | // Colors related signals | |
|
367 | QSignalSpy colorSpy(legend, SIGNAL(colorChanged(QColor))); | |
|
368 | QSignalSpy borderColorSpy(legend, SIGNAL(borderColorChanged(QColor))); | |
|
369 | QSignalSpy labelColorSpy(legend, SIGNAL(labelColorChanged(QColor))); | |
|
370 | ||
|
371 | // colorChanged | |
|
372 | legend->setColor(QColor("aliceblue")); | |
|
373 | QCOMPARE(colorSpy.count(), 1); | |
|
374 | QBrush b = legend->brush(); | |
|
375 | b.setColor(QColor("aqua")); | |
|
376 | legend->setBrush(b); | |
|
377 | QCOMPARE(colorSpy.count(), 2); | |
|
378 | ||
|
379 | // borderColorChanged | |
|
380 | legend->setBorderColor(QColor("aliceblue")); | |
|
381 | QCOMPARE(borderColorSpy.count(), 1); | |
|
382 | QPen p = legend->pen(); | |
|
383 | p.setColor(QColor("aqua")); | |
|
384 | legend->setPen(p); | |
|
385 | QCOMPARE(borderColorSpy.count(), 2); | |
|
386 | ||
|
387 | // labelColorChanged | |
|
388 | legend->setLabelColor(QColor("lightsalmon")); | |
|
389 | QCOMPARE(labelColorSpy.count(), 1); | |
|
390 | b = legend->labelBrush(); | |
|
391 | b.setColor(QColor("lightseagreen")); | |
|
392 | legend->setLabelBrush(b); | |
|
393 | QCOMPARE(labelColorSpy.count(), 2); | |
|
394 | ||
|
395 | // fontChanged | |
|
396 | QSignalSpy fontSpy(legend, SIGNAL(fontChanged(QFont))); | |
|
397 | QFont f = legend->font(); | |
|
398 | f.setBold(!f.bold()); | |
|
399 | legend->setFont(f); | |
|
400 | QCOMPARE(fontSpy.count(), 1); | |
|
364 | 401 | } |
|
365 | 402 | |
|
366 | 403 | void tst_QChart::margins_data() |
|
367 | 404 | { |
|
368 | 405 | |
|
369 | 406 | } |
|
370 | 407 | |
|
371 | 408 | void tst_QChart::margins() |
|
372 | 409 | { |
|
373 | 410 | createTestData(); |
|
374 | 411 | QRectF rect = m_chart->geometry(); |
|
375 | 412 | |
|
376 | 413 | QVERIFY(m_chart->margins().top()+m_chart->margins().bottom() < rect.height()); |
|
377 | 414 | QVERIFY(m_chart->margins().left()+m_chart->margins().right() < rect.width()); |
|
378 | 415 | } |
|
379 | 416 | |
|
380 | 417 | void tst_QChart::removeAllSeries_data() |
|
381 | 418 | { |
|
382 | 419 | |
|
383 | 420 | } |
|
384 | 421 | |
|
385 | 422 | void tst_QChart::removeAllSeries() |
|
386 | 423 | { |
|
387 | 424 | QLineSeries* series0 = new QLineSeries(this); |
|
388 | 425 | QLineSeries* series1 = new QLineSeries(this); |
|
389 | 426 | QLineSeries* series2 = new QLineSeries(this); |
|
390 | 427 | QSignalSpy deleteSpy1(series0, SIGNAL(destroyed())); |
|
391 | 428 | QSignalSpy deleteSpy2(series1, SIGNAL(destroyed())); |
|
392 | 429 | QSignalSpy deleteSpy3(series2, SIGNAL(destroyed())); |
|
393 | 430 | |
|
394 | 431 | m_chart->addSeries(series0); |
|
395 | 432 | m_chart->addSeries(series1); |
|
396 | 433 | m_chart->addSeries(series2); |
|
397 | 434 | m_view->show(); |
|
398 | 435 | QTest::qWaitForWindowShown(m_view); |
|
399 | 436 | |
|
400 | 437 | QVERIFY(m_chart->axisY(series0)!=0); |
|
401 | 438 | QVERIFY(m_chart->axisY(series1)!=0); |
|
402 | 439 | QVERIFY(m_chart->axisY(series2)!=0); |
|
403 | 440 | |
|
404 | 441 | m_chart->removeAllSeries(); |
|
405 | 442 | QVERIFY(m_chart->axisY(series0)==0); |
|
406 | 443 | QVERIFY(m_chart->axisY(series1)==0); |
|
407 | 444 | QVERIFY(m_chart->axisY(series2)==0); |
|
408 | 445 | QCOMPARE(deleteSpy1.count(), 1); |
|
409 | 446 | QCOMPARE(deleteSpy2.count(), 1); |
|
410 | 447 | QCOMPARE(deleteSpy3.count(), 1); |
|
411 | 448 | } |
|
412 | 449 | |
|
413 | 450 | void tst_QChart::removeSeries_data() |
|
414 | 451 | { |
|
415 | 452 | addSeries_data(); |
|
416 | 453 | } |
|
417 | 454 | |
|
418 | 455 | void tst_QChart::removeSeries() |
|
419 | 456 | { |
|
420 | 457 | QFETCH(QAbstractSeries *, series); |
|
421 | 458 | QFETCH(QAbstractAxis *, axis); |
|
422 | 459 | QSignalSpy deleteSpy(series, SIGNAL(destroyed())); |
|
423 | 460 | m_view->show(); |
|
424 | 461 | QTest::qWaitForWindowShown(m_view); |
|
425 | 462 | if(!axis) axis = m_chart->axisY(); |
|
426 | 463 | m_chart->addSeries(series); |
|
427 | 464 | m_chart->setAxisY(series,axis); |
|
428 | 465 | QCOMPARE(m_chart->axisY(series),axis); |
|
429 | 466 | m_chart->removeSeries(series); |
|
430 | 467 | QVERIFY(m_chart->axisY(series)==0); |
|
431 | 468 | QCOMPARE(deleteSpy.count(), 0); |
|
432 | 469 | } |
|
433 | 470 | |
|
434 | 471 | void tst_QChart::scrollDown_data() |
|
435 | 472 | { |
|
436 | 473 | |
|
437 | 474 | } |
|
438 | 475 | |
|
439 | 476 | void tst_QChart::scrollDown() |
|
440 | 477 | { |
|
441 | 478 | qFatal("implement me"); |
|
442 | 479 | createTestData(); |
|
443 | 480 | //TODO qreal min = m_chart->axisY()->min(); |
|
444 | 481 | m_chart->scrollDown(); |
|
445 | 482 | //TODO QVERIFY(m_chart->axisY()->min()<min); |
|
446 | 483 | } |
|
447 | 484 | |
|
448 | 485 | void tst_QChart::scrollLeft_data() |
|
449 | 486 | { |
|
450 | 487 | |
|
451 | 488 | } |
|
452 | 489 | |
|
453 | 490 | void tst_QChart::scrollLeft() |
|
454 | 491 | { |
|
455 | 492 | qFatal("implement me"); |
|
456 | 493 | createTestData(); |
|
457 | 494 | //TODO qreal min = m_chart->axisX()->min(); |
|
458 | 495 | m_chart->scrollLeft(); |
|
459 | 496 | //TODO QVERIFY(m_chart->axisX()->min()<min); |
|
460 | 497 | } |
|
461 | 498 | |
|
462 | 499 | void tst_QChart::scrollRight_data() |
|
463 | 500 | { |
|
464 | 501 | |
|
465 | 502 | } |
|
466 | 503 | |
|
467 | 504 | void tst_QChart::scrollRight() |
|
468 | 505 | { |
|
469 | 506 | qFatal("implement me"); |
|
470 | 507 | createTestData(); |
|
471 | 508 | //TODO qreal min = m_chart->axisX()->min(); |
|
472 | 509 | m_chart->scrollRight(); |
|
473 | 510 | //TODO QVERIFY(m_chart->axisX()->min()>min); |
|
474 | 511 | } |
|
475 | 512 | |
|
476 | 513 | void tst_QChart::scrollUp_data() |
|
477 | 514 | { |
|
478 | 515 | |
|
479 | 516 | } |
|
480 | 517 | |
|
481 | 518 | void tst_QChart::scrollUp() |
|
482 | 519 | { |
|
483 | 520 | qFatal("implement me"); |
|
484 | 521 | createTestData(); |
|
485 | 522 | //TODO qreal min = m_chart->axisY()->min(); |
|
486 | 523 | m_chart->scrollUp(); |
|
487 | 524 | //TODO QVERIFY(m_chart->axisY()->min()>min); |
|
488 | 525 | } |
|
489 | 526 | |
|
490 | 527 | void tst_QChart::theme_data() |
|
491 | 528 | { |
|
492 | 529 | QTest::addColumn<QChart::ChartTheme>("theme"); |
|
493 | 530 | QTest::newRow("ChartThemeBlueCerulean") << QChart::ChartThemeBlueCerulean; |
|
494 | 531 | QTest::newRow("ChartThemeBlueIcy") << QChart::ChartThemeBlueIcy; |
|
495 | 532 | QTest::newRow("ChartThemeBlueNcs") << QChart::ChartThemeBlueNcs; |
|
496 | 533 | QTest::newRow("ChartThemeBrownSand") << QChart::ChartThemeBrownSand; |
|
497 | 534 | QTest::newRow("ChartThemeDark") << QChart::ChartThemeDark; |
|
498 | 535 | QTest::newRow("hartThemeHighContrast") << QChart::ChartThemeHighContrast; |
|
499 | 536 | QTest::newRow("ChartThemeLight") << QChart::ChartThemeLight; |
|
500 | 537 | } |
|
501 | 538 | |
|
502 | 539 | void tst_QChart::theme() |
|
503 | 540 | { |
|
504 | 541 | QFETCH(QChart::ChartTheme, theme); |
|
505 | 542 | createTestData(); |
|
506 | 543 | m_chart->setTheme(theme); |
|
507 | 544 | QVERIFY(m_chart->theme()==theme); |
|
508 | 545 | } |
|
509 | 546 | |
|
510 | 547 | void tst_QChart::title_data() |
|
511 | 548 | { |
|
512 | 549 | QTest::addColumn<QString>("title"); |
|
513 | 550 | QTest::newRow("null") << QString(); |
|
514 | 551 | QTest::newRow("foo") << QString("foo"); |
|
515 | 552 | } |
|
516 | 553 | |
|
517 | 554 | void tst_QChart::title() |
|
518 | 555 | { |
|
519 | 556 | QFETCH(QString, title); |
|
520 | 557 | m_chart->setTitle(title); |
|
521 | 558 | QCOMPARE(m_chart->title(), title); |
|
522 | 559 | } |
|
523 | 560 | |
|
524 | 561 | void tst_QChart::titleBrush_data() |
|
525 | 562 | { |
|
526 | 563 | QTest::addColumn<QBrush>("titleBrush"); |
|
527 | 564 | QTest::newRow("null") << QBrush(); |
|
528 | 565 | QTest::newRow("blue") << QBrush(Qt::blue); |
|
529 | 566 | QTest::newRow("white") << QBrush(Qt::white); |
|
530 | 567 | QTest::newRow("black") << QBrush(Qt::black); |
|
531 | 568 | } |
|
532 | 569 | |
|
533 | 570 | void tst_QChart::titleBrush() |
|
534 | 571 | { |
|
535 | 572 | QFETCH(QBrush, titleBrush); |
|
536 | 573 | m_chart->setTitleBrush(titleBrush); |
|
537 | 574 | QCOMPARE(m_chart->titleBrush(), titleBrush); |
|
538 | 575 | } |
|
539 | 576 | |
|
540 | 577 | void tst_QChart::titleFont_data() |
|
541 | 578 | { |
|
542 | 579 | QTest::addColumn<QFont>("titleFont"); |
|
543 | 580 | QTest::newRow("null") << QFont(); |
|
544 | 581 | QTest::newRow("courier") << QFont("Courier", 8, QFont::Bold, true); |
|
545 | 582 | } |
|
546 | 583 | |
|
547 | 584 | void tst_QChart::titleFont() |
|
548 | 585 | { |
|
549 | 586 | QFETCH(QFont, titleFont); |
|
550 | 587 | m_chart->setTitleFont(titleFont); |
|
551 | 588 | QCOMPARE(m_chart->titleFont(), titleFont); |
|
552 | 589 | } |
|
553 | 590 | |
|
554 | 591 | void tst_QChart::zoomIn_data() |
|
555 | 592 | { |
|
556 | 593 | QTest::addColumn<QRectF>("rect"); |
|
557 | 594 | QTest::newRow("null") << QRectF(); |
|
558 | 595 | QTest::newRow("100x100") << QRectF(10,10,100,100); |
|
559 | 596 | QTest::newRow("200x200") << QRectF(10,10,200,200); |
|
560 | 597 | } |
|
561 | 598 | |
|
562 | 599 | |
|
563 | 600 | void tst_QChart::zoomIn() |
|
564 | 601 | { |
|
565 | 602 | qFatal("implement me"); |
|
566 | 603 | /* |
|
567 | 604 | QFETCH(QRectF, rect); |
|
568 | 605 | createTestData(); |
|
569 | 606 | QRectF marigns = m_chart->margins(); |
|
570 | 607 | rect.adjust(marigns.left(),marigns.top(),-marigns.right(),-marigns.bottom()); |
|
571 | 608 | qreal minX = m_chart->axisX()->min(); |
|
572 | 609 | qreal minY = m_chart->axisY()->min(); |
|
573 | 610 | qreal maxX = m_chart->axisX()->max(); |
|
574 | 611 | qreal maxY = m_chart->axisY()->max(); |
|
575 | 612 | m_chart->zoomIn(rect); |
|
576 | 613 | if(rect.isValid()){ |
|
577 | 614 | QVERIFY(minX<m_chart->axisX()->min()); |
|
578 | 615 | QVERIFY(maxX>m_chart->axisX()->max()); |
|
579 | 616 | QVERIFY(minY<m_chart->axisY()->min()); |
|
580 | 617 | QVERIFY(maxY>m_chart->axisY()->max()); |
|
581 | 618 | } |
|
582 | 619 | */ |
|
583 | 620 | } |
|
584 | 621 | |
|
585 | 622 | void tst_QChart::zoomOut_data() |
|
586 | 623 | { |
|
587 | 624 | |
|
588 | 625 | } |
|
589 | 626 | |
|
590 | 627 | void tst_QChart::zoomOut() |
|
591 | 628 | { |
|
592 | 629 | qFatal("implement me"); |
|
593 | 630 | createTestData(); |
|
594 | 631 | /* |
|
595 | 632 | qreal minX = m_chart->axisX()->min(); |
|
596 | 633 | qreal minY = m_chart->axisY()->min(); |
|
597 | 634 | qreal maxX = m_chart->axisX()->max(); |
|
598 | 635 | qreal maxY = m_chart->axisY()->max(); |
|
599 | 636 | |
|
600 | 637 | m_chart->zoomIn(); |
|
601 | 638 | |
|
602 | 639 | QVERIFY(minX < m_chart->axisX()->min()); |
|
603 | 640 | QVERIFY(maxX > m_chart->axisX()->max()); |
|
604 | 641 | QVERIFY(minY < m_chart->axisY()->min()); |
|
605 | 642 | QVERIFY(maxY > m_chart->axisY()->max()); |
|
606 | 643 | |
|
607 | 644 | m_chart->zoomOut(); |
|
608 | 645 | |
|
609 | 646 | // min x may be a zero value |
|
610 | 647 | if (qFuzzyIsNull(minX)) |
|
611 | 648 | QVERIFY(qFuzzyIsNull(m_chart->axisX()->min())); |
|
612 | 649 | else |
|
613 | 650 | QCOMPARE(minX, m_chart->axisX()->min()); |
|
614 | 651 | |
|
615 | 652 | // min y may be a zero value |
|
616 | 653 | if (qFuzzyIsNull(minY)) |
|
617 | 654 | QVERIFY(qFuzzyIsNull(m_chart->axisY()->min())); |
|
618 | 655 | else |
|
619 | 656 | QCOMPARE(minY, m_chart->axisY()->min()); |
|
620 | 657 | |
|
621 | 658 | QVERIFY(maxX == m_chart->axisX()->max()); |
|
622 | 659 | QVERIFY(maxY == m_chart->axisY()->max()); |
|
623 | 660 | */ |
|
624 | 661 | } |
|
625 | 662 | |
|
626 | 663 | QTEST_MAIN(tst_QChart) |
|
627 | 664 | #include "tst_qchart.moc" |
|
628 | 665 |
@@ -1,107 +1,106 | |||
|
1 | 1 | /**************************************************************************** |
|
2 | 2 | ** |
|
3 | 3 | ** Copyright (C) 2012 Digia Plc |
|
4 | 4 | ** All rights reserved. |
|
5 | 5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
6 | 6 | ** |
|
7 | 7 | ** This file is part of the Qt Commercial Charts Add-on. |
|
8 | 8 | ** |
|
9 | 9 | ** $QT_BEGIN_LICENSE$ |
|
10 | 10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
11 | 11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
12 | 12 | ** Software or, alternatively, in accordance with the terms contained in |
|
13 | 13 | ** a written agreement between you and Digia. |
|
14 | 14 | ** |
|
15 | 15 | ** If you have questions regarding the use of this file, please use |
|
16 | 16 | ** contact form at http://qt.digia.com |
|
17 | 17 | ** $QT_END_LICENSE$ |
|
18 | 18 | ** |
|
19 | 19 | ****************************************************************************/ |
|
20 | 20 | |
|
21 | 21 | import QtQuick 1.0 |
|
22 | 22 | import QtCommercial.Chart 1.0 |
|
23 | 23 | |
|
24 | 24 | ChartView { |
|
25 | 25 | id: chartView |
|
26 | 26 | title: "Chart Title" |
|
27 | 27 | anchors.fill: parent |
|
28 | 28 | property variant series: 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: " + series.backgroundColor); |
|
44 | 44 | onDropShadowEnabledChanged: console.log("chart.onDropShadowEnabledChanged: " + enabled); |
|
45 | 45 | onTopMarginChanged: { |
|
46 | 46 | console.log("chart.onTopMarginChanged: " + margin); |
|
47 | 47 | marginVisualizer.opacity = 1.0; |
|
48 | 48 | } |
|
49 | 49 | onBottomMarginChanged: { |
|
50 | 50 | console.log("chart.onBottomMarginChanged: " + margin); |
|
51 | 51 | marginVisualizer.opacity = 1.0; |
|
52 | 52 | } |
|
53 | 53 | onLeftMarginChanged: { |
|
54 | 54 | console.log("chart.onLeftMarginChanged: " + margin); |
|
55 | 55 | marginVisualizer.opacity = 1.0; |
|
56 | 56 | } |
|
57 | 57 | onRightMarginChanged: { |
|
58 | 58 | console.log("chart.onRightMarginChanged: " + margin); |
|
59 | 59 | marginVisualizer.opacity = 1.0; |
|
60 | 60 | } |
|
61 | 61 | |
|
62 | 62 | legend.onVisibleChanged: console.log("legend.onVisibleChanged: " + series.legend.visible); |
|
63 | 63 | legend.onBackgroundVisibleChanged: console.log("legend.onBackgroundVisibleChanged: " + visible); |
|
64 | 64 | legend.onColorChanged: console.log("legend.onColorChanged: " + color); |
|
65 | 65 | legend.onBorderColorChanged: console.log("legend.onBorderColorChanged: " + color); |
|
66 | 66 | legend.onLabelColorChanged: console.log("legend.onLabelColorChanged: " + color); |
|
67 | legend.onLabelBrushChanged: console.log("legend.onLabelBrushChanged: " + brush); | |
|
68 | 67 | |
|
69 | 68 | axisX.onColorChanged: console.log("axisX.onColorChanged: " + color); |
|
70 | 69 | axisX.onLabelsVisibleChanged: console.log("axisX.onLabelsVisibleChanged: " + visible); |
|
71 | 70 | axisX.onLabelsColorChanged: console.log("axisX.onLabelsColorChanged: " + color); |
|
72 | 71 | axisX.onVisibleChanged: console.log("axisX.onVisibleChanged: " + visible); |
|
73 | 72 | axisX.onGridVisibleChanged: console.log("axisX.onGridVisibleChanged: " + visible); |
|
74 | 73 | axisX.onShadesVisibleChanged: console.log("axisX.onShadesVisibleChanged: " + visible); |
|
75 | 74 | axisX.onShadesColorChanged: console.log("axisX.onShadesColorChanged: " + color); |
|
76 | 75 | axisX.onShadesBorderColorChanged: console.log("axisX.onShadesBorderColorChanged: " + color); |
|
77 | 76 | axisX.onMinChanged: console.log("axisX.onMinChanged: " + min); |
|
78 | 77 | axisX.onMaxChanged: console.log("axisX.onMaxChanged: " + max); |
|
79 | 78 | |
|
80 | 79 | axisY.onColorChanged: console.log("axisY.onColorChanged: " + color); |
|
81 | 80 | axisY.onLabelsVisibleChanged: console.log("axisY.onLabelsVisibleChanged: " + visible); |
|
82 | 81 | axisY.onLabelsColorChanged: console.log("axisY.onLabelsColorChanged: " + color); |
|
83 | 82 | axisY.onVisibleChanged: console.log("axisY.onVisibleChanged: " + visible); |
|
84 | 83 | axisY.onGridVisibleChanged: console.log("axisY.onGridVisibleChanged: " + visible); |
|
85 | 84 | axisY.onShadesVisibleChanged: console.log("axisY.onShadesVisibleChanged: " + visible); |
|
86 | 85 | axisY.onShadesColorChanged: console.log("axisY.onShadesColorChanged: " + color); |
|
87 | 86 | axisY.onShadesBorderColorChanged: console.log("axisY.onShadesBorderColorChanged: " + color); |
|
88 | 87 | axisY.onMinChanged: console.log("axisY.onMinChanged: " + min); |
|
89 | 88 | axisY.onMaxChanged: console.log("axisY.onMaxChanged: " + max); |
|
90 | 89 | |
|
91 | 90 | |
|
92 | 91 | Rectangle { |
|
93 | 92 | id: marginVisualizer |
|
94 | 93 | color: "transparent" |
|
95 | 94 | border.color: "red" |
|
96 | 95 | anchors.fill: parent |
|
97 | 96 | anchors.topMargin: parent.topMargin |
|
98 | 97 | anchors.bottomMargin: parent.bottomMargin |
|
99 | 98 | anchors.leftMargin: parent.leftMargin |
|
100 | 99 | anchors.rightMargin: parent.rightMargin |
|
101 | 100 | opacity: 0.0 |
|
102 | 101 | onOpacityChanged: if (opacity > 0.9) opacity = 0.0; |
|
103 | 102 | Behavior on opacity { |
|
104 | 103 | NumberAnimation { duration: 800 } |
|
105 | 104 | } |
|
106 | 105 | } |
|
107 | 106 | } |
General Comments 0
You need to be logged in to leave comments.
Login now