##// END OF EJS Templates
Changes to qchart qabstractseries API
Michal Klocek -
r1553:aa0203a138dd
parent child
Show More
@@ -1,64 +1,64
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 "chart.h"
22 22 #include <QAbstractAxis>
23 23 #include <QSplineSeries>
24 24 #include <QTime>
25 25
26 26 Chart::Chart(QGraphicsItem *parent, Qt::WindowFlags wFlags)
27 27 :QChart(parent, wFlags),
28 28 m_step(1),
29 29 m_x(0),
30 30 m_y(1)
31 31 {
32 32 qsrand((uint) QTime::currentTime().msec());
33 33
34 34 QObject::connect(&m_timer, SIGNAL(timeout()), this, SLOT(handleTimeout()));
35 35 m_timer.setInterval(1000);
36 36
37 37 m_series = new QSplineSeries(this);
38 38 QPen green(Qt::red);
39 39 green.setWidth(3);
40 40 m_series->setPen(green);
41 41 m_series->append(m_x, m_y);
42 42
43 43 addSeries(m_series);
44 44
45 45 axisY()->setRange(-5, 5);
46 46 axisX()->setRange(-9, 1);
47 47 //TODO:axisX()->setTicksCount(11);
48 48
49 49 m_timer.start();
50 50 }
51 51
52 52 Chart::~Chart()
53 53 {
54 54
55 55 }
56 56
57 57 void Chart::handleTimeout()
58 58 {
59 59 m_x += m_step;
60 60 m_y = qrand() % 5 - 2.5;
61 61 m_series->append(m_x, m_y);
62 scrollRight();
62 scroll(10,0);
63 63 if(m_x==100) m_timer.stop();
64 64 }
@@ -1,63 +1,63
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 "chart.h"
22 22 #include <QGesture>
23 23 #include <QGraphicsScene>
24 24 #include <QGraphicsView>
25 25
26 26 Chart::Chart(QGraphicsItem *parent, Qt::WindowFlags wFlags)
27 27 :QChart(parent, wFlags)
28 28 {
29 29 // Seems that QGraphicsView (QChartView) does not grab gestures.
30 30 // They can only be grabbed here in the QGraphicsWidget (QChart).
31 31 grabGesture(Qt::PanGesture);
32 32 grabGesture(Qt::PinchGesture);
33 33 }
34 34
35 35 Chart::~Chart()
36 36 {
37 37
38 38 }
39 39
40 40 //![1]
41 41 bool Chart::sceneEvent(QEvent *event)
42 42 {
43 43 if (event->type() == QEvent::Gesture)
44 44 return gestureEvent(static_cast<QGestureEvent*>(event));
45 45 return QChart::event(event);
46 46 }
47 47
48 48 bool Chart::gestureEvent(QGestureEvent* event)
49 49 {
50 50 if (QGesture *gesture = event->gesture(Qt::PanGesture)) {
51 51 QPanGesture *pan = static_cast<QPanGesture *>(gesture);
52 QChart::scroll(pan->delta());
52 QChart::scroll(pan->delta().x(),pan->delta().y());
53 53 }
54 54
55 55 if (QGesture *gesture = event->gesture(Qt::PinchGesture)) {
56 56 QPinchGesture *pinch = static_cast<QPinchGesture *>(gesture);
57 57 if (pinch->changeFlags() & QPinchGesture::ScaleFactorChanged)
58 58 QChart::zoom(pinch->scaleFactor());
59 59 }
60 60
61 61 return true;
62 62 }
63 63 //![1]
@@ -1,100 +1,100
1 1 /****************************************************************************
2 2 **
3 3 ** Copyright (C) 2012 Digia Plc
4 4 ** All rights reserved.
5 5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 6 **
7 7 ** This file is part of the Qt Commercial Charts Add-on.
8 8 **
9 9 ** $QT_BEGIN_LICENSE$
10 10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 11 ** accordance with the Qt Commercial License Agreement provided with the
12 12 ** Software or, alternatively, in accordance with the terms contained in
13 13 ** a written agreement between you and Digia.
14 14 **
15 15 ** If you have questions regarding the use of this file, please use
16 16 ** contact form at http://qt.digia.com
17 17 ** $QT_END_LICENSE$
18 18 **
19 19 ****************************************************************************/
20 20
21 21 #include "chartview.h"
22 22 #include <QMouseEvent>
23 23
24 24 ChartView::ChartView(QChart *chart, QWidget *parent) :
25 25 QChartView(chart, parent),
26 26 m_isTouching(false)
27 27 {
28 28 setRubberBand(QChartView::RectangleRubberBand);
29 29 }
30 30
31 31 bool ChartView::viewportEvent(QEvent *event)
32 32 {
33 33 if (event->type() == QEvent::TouchBegin) {
34 34 // By default touch events are converted to mouse events. So
35 35 // after this event we will get a mouse event also but we want
36 36 // to handle touch events as gestures only. So we need this safeguard
37 37 // to block mouse events that are actually generated from touch.
38 38 m_isTouching = true;
39 39
40 40 // Turn off animations when handling gestures they
41 41 // will only slow us down.
42 42 chart()->setAnimationOptions(QChart::NoAnimation);
43 43 }
44 44 return QChartView::viewportEvent(event);
45 45 }
46 46
47 47 void ChartView::mousePressEvent(QMouseEvent *event)
48 48 {
49 49 if (m_isTouching)
50 50 return;
51 51 QChartView::mousePressEvent(event);
52 52 }
53 53
54 54 void ChartView::mouseMoveEvent(QMouseEvent *event)
55 55 {
56 56 if (m_isTouching)
57 57 return;
58 58 QChartView::mouseMoveEvent(event);
59 59 }
60 60
61 61 void ChartView::mouseReleaseEvent(QMouseEvent *event)
62 62 {
63 63 if (m_isTouching)
64 64 m_isTouching = false;
65 65
66 66 // Because we disabled animations when touch event was detected
67 67 // we must put them back on.
68 68 chart()->setAnimationOptions(QChart::SeriesAnimations);
69 69
70 70 QChartView::mouseReleaseEvent(event);
71 71 }
72 72
73 73 //![1]
74 74 void ChartView::keyPressEvent(QKeyEvent *event)
75 75 {
76 76 switch (event->key()) {
77 77 case Qt::Key_Plus:
78 78 chart()->zoomIn();
79 79 break;
80 80 case Qt::Key_Minus:
81 81 chart()->zoomOut();
82 82 break;
83 83 //![1]
84 84 case Qt::Key_Left:
85 chart()->scrollLeft();
85 chart()->scroll(-10,0);
86 86 break;
87 87 case Qt::Key_Right:
88 chart()->scrollRight();
88 chart()->scroll(10,0);
89 89 break;
90 90 case Qt::Key_Up:
91 chart()->scrollUp();
91 chart()->scroll(0,10);
92 92 break;
93 93 case Qt::Key_Down:
94 chart()->scrollDown();
94 chart()->scroll(0,-10);
95 95 break;
96 96 default:
97 97 QGraphicsView::keyPressEvent(event);
98 98 break;
99 99 }
100 100 }
@@ -1,501 +1,501
1 1 /****************************************************************************
2 2 **
3 3 ** Copyright (C) 2012 Digia Plc
4 4 ** All rights reserved.
5 5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 6 **
7 7 ** This file is part of the Qt Commercial Charts Add-on.
8 8 **
9 9 ** $QT_BEGIN_LICENSE$
10 10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 11 ** accordance with the Qt Commercial License Agreement provided with the
12 12 ** Software or, alternatively, in accordance with the terms contained in
13 13 ** a written agreement between you and Digia.
14 14 **
15 15 ** If you have questions regarding the use of this file, please use
16 16 ** contact form at http://qt.digia.com
17 17 ** $QT_END_LICENSE$
18 18 **
19 19 ****************************************************************************/
20 20
21 21 #include "declarativechart.h"
22 22 #include <QPainter>
23 23 #include "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 "declarativescatterseries.h"
29 29 #include "qcategoriesaxis.h"
30 30
31 31 QTCOMMERCIALCHART_BEGIN_NAMESPACE
32 32
33 33 /*!
34 34 \qmlclass ChartView DeclarativeChart
35 35
36 36 ChartView element is the parent that is responsible for showing different chart series types.
37 37
38 38 The following QML shows how to create a simple chart with one pie series:
39 39 \snippet ../examples/qmlpiechart/qml/qmlpiechart/main.qml 1
40 40 \snippet ../examples/qmlpiechart/qml/qmlpiechart/main.qml 2
41 41 \snippet ../examples/qmlpiechart/qml/qmlpiechart/main.qml 3
42 42
43 43 \beginfloatleft
44 44 \image examples_qmlpiechart.png
45 45 \endfloat
46 46 \clearfloat
47 47 */
48 48
49 49 /*!
50 50 \qmlproperty Theme ChartView::theme
51 51 Theme defines the visual appearance of the chart, including for example colors, fonts, line
52 52 widths and chart background.
53 53 */
54 54
55 55 /*!
56 56 \qmlproperty Animation ChartView::animation
57 57 Animation configuration of the chart. One of ChartView.NoAnimation, ChartView.GridAxisAnimations,
58 58 ChartView.SeriesAnimations or ChartView.AllAnimations.
59 59 */
60 60
61 61 /*!
62 62 \qmlproperty Font ChartView::titleFont
63 63 The title font of the chart
64 64
65 65 See the \l {Font} {QML Font Element} for detailed documentation.
66 66 */
67 67
68 68 /*!
69 69 \qmlproperty string ChartView::title
70 70 The title of the chart, shown on top of the chart.
71 71 \sa ChartView::titleColor
72 72 */
73 73
74 74 /*!
75 75 \qmlproperty string ChartView::titleColor
76 76 The color of the title text.
77 77 */
78 78
79 79 /*!
80 80 \qmlproperty Axis ChartView::axisX
81 81 The x-axis of the chart.
82 82 */
83 83
84 84 /*!
85 85 \qmlproperty Axis ChartView::axisY
86 86 The default y-axis of the chart.
87 87 */
88 88
89 89 /*!
90 90 \qmlproperty Legend ChartView::legend
91 91 The legend of the chart. Legend lists all the series, pie slices and bar sets added on the chart.
92 92 */
93 93
94 94 /*!
95 95 \qmlproperty int ChartView::count
96 96 The count of series added to the chart.
97 97 */
98 98
99 99 /*!
100 100 \qmlproperty color ChartView::backgroundColor
101 101 The color of the chart's background. By default background color is defined by chart theme.
102 102 \sa ChartView::theme
103 103 */
104 104
105 105 /*!
106 106 \qmlproperty bool ChartView::dropShadowEnabled
107 107 The chart's border drop shadow. Set to true to enable drop shadow.
108 108 */
109 109
110 110 /*!
111 111 \qmlproperty real ChartView::topMargin
112 112 The space between the top of chart view and the top of the plot area. The title (if non-empty) is drawn on top margin
113 113 area of the chart view. Top margin area is also used by legend, if aligned to top.
114 114 */
115 115
116 116 /*!
117 117 \qmlproperty real ChartView::bottomMargin
118 118 The space between the bottom of chart view and the bottom of the plot area. The bottom margin area may be used by
119 119 legend (if aligned to bottom), x-axis, x-axis labels and x-axis tick marks.
120 120 */
121 121
122 122 /*!
123 123 \qmlproperty real ChartView::leftMargin
124 124 The space between the left side of chart view and the left side of the plot area. The left margin area may be used by
125 125 legend (if aligned to left), y-axis, y-axis labels and y-axis tick marks.
126 126 */
127 127
128 128 /*!
129 129 \qmlproperty real ChartView::rightMargin
130 130 The space between the right side of chart view and the right side of the plot area. The right margin area may be used
131 131 by legend (if aligned to right).
132 132 */
133 133
134 134 /*!
135 135 \qmlmethod AbstractSeries ChartView::series(int index)
136 136 Returns the series with \a index on the chart. This allows you to loop through the series of a chart together with
137 137 the count property of the chart.
138 138 */
139 139
140 140 /*!
141 141 \qmlmethod AbstractSeries ChartView::series(string name)
142 142 Returns the first series on the chart with \a name. If there is no series with that name, returns null.
143 143 */
144 144
145 145 /*!
146 146 \qmlmethod AbstractSeries ChartView::createSeries(SeriesType type, string name)
147 147 Creates a series object of \a type to the chart. For example:
148 148 \code
149 149 var scatter = chartView.createSeries(ChartView.SeriesTypeScatter, "scatter series");
150 150 scatter.markerSize = 22;
151 151 scatter.append(1.1, 2.0);
152 152 \endcode
153 153 */
154 154
155 155 /*!
156 156 \qmlmethod Axis ChartView::axisY(QAbstractSeries *series)
157 157 The y-axis of the series. This is the same as the default y-axis of the chart as multiple y-axes are not yet supported.
158 158 */
159 159
160 160 /*!
161 161 \qmlmethod ChartView::zoomY(real factor)
162 162 Zooms in by \a factor on the center of the chart.
163 163 */
164 164
165 165 /*!
166 166 \qmlmethod ChartView::scrollLeft(real pixels)
167 167 Scrolls to left by \a pixels. This is a convenience function that suits for example for key navigation.
168 168 \sa Axis::min, Axis::max
169 169 */
170 170
171 171 /*!
172 172 \qmlmethod ChartView::scrollRight(real pixels)
173 173 Scrolls to right by \a pixels. This is a convenience function that suits for example for key navigation.
174 174 \sa Axis::min, Axis::max
175 175 */
176 176
177 177 /*!
178 178 \qmlmethod ChartView::scrollUp(real pixels)
179 179 Scrolls up by \a pixels. This is a convenience function that suits for example for key navigation.
180 180 \sa Axis::min, Axis::max
181 181 */
182 182
183 183 /*!
184 184 \qmlmethod ChartView::scrollDown(real pixels)
185 185 Scrolls down by \a pixels. This is a convenience function that suits for example for key navigation.
186 186 \sa Axis::min, Axis::max
187 187 */
188 188
189 189 /*!
190 190 \qmlsignal ChartView::onTopMarginChanged(real margin)
191 191 The top margin of the chart view has changed to \a margin. This may happen for example if you modify font size
192 192 related properties of the legend or chart title.
193 193 */
194 194
195 195 /*!
196 196 \qmlsignal ChartView::onBottomMarginChanged(real margin)
197 197 The bottom margin of the chart view has changed to \a margin. This may happen for example if you modify font size
198 198 related properties of the legend or chart title.
199 199 */
200 200
201 201 /*!
202 202 \qmlsignal ChartView::onLeftMarginChanged(real margin)
203 203 The left margin of the chart view has changed to \a margin. This may happen for example if you modify font size
204 204 related properties of the legend or chart title.
205 205 */
206 206
207 207 /*!
208 208 \qmlsignal ChartView::onRightMarginChanged(real margin)
209 209 The right margin of the chart view has changed to \a margin. This may happen for example if you modify font size
210 210 related properties of the legend or chart title.
211 211 */
212 212
213 213 DeclarativeChart::DeclarativeChart(QDeclarativeItem *parent)
214 214 : QDeclarativeItem(parent),
215 215 m_chart(new QChart(this))
216 216 {
217 217 setFlag(QGraphicsItem::ItemHasNoContents, false);
218 218 // m_chart->axisX()->setNiceNumbersEnabled(false);
219 219 m_chartMargins = m_chart->margins();
220 220 connect(m_chart, SIGNAL(marginsChanged(QRectF)), this, SLOT(handleMarginsChanged(QRectF)));
221 221 }
222 222
223 223 void DeclarativeChart::handleMarginsChanged(QRectF newMargins)
224 224 {
225 225 if (m_chartMargins.top() != newMargins.top())
226 226 topMarginChanged(m_chart->margins().top());
227 227 if (m_chartMargins.bottom() != newMargins.bottom())
228 228 bottomMarginChanged(m_chart->margins().bottom());
229 229 if (m_chartMargins.left() != newMargins.left())
230 230 leftMarginChanged(m_chart->margins().left());
231 231 if (m_chartMargins.right() != newMargins.right())
232 232 rightMarginChanged(m_chart->margins().right());
233 233
234 234 m_chartMargins = m_chart->margins();
235 235 }
236 236
237 237 DeclarativeChart::~DeclarativeChart()
238 238 {
239 239 delete m_chart;
240 240 }
241 241
242 242 void DeclarativeChart::childEvent(QChildEvent *event)
243 243 {
244 244 if (event->type() == QEvent::ChildAdded) {
245 245 if (qobject_cast<QAbstractSeries *>(event->child())) {
246 246 m_chart->addSeries(qobject_cast<QAbstractSeries *>(event->child()));
247 247 }
248 248 }
249 249 }
250 250
251 251 void DeclarativeChart::componentComplete()
252 252 {
253 253 foreach(QObject *child, children()) {
254 254 if (qobject_cast<QAbstractSeries *>(child)) {
255 255 // qDebug() << "DeclarativeChart::componentComplete(), add: " << child;
256 256 // TODO: how about optional y-axis?
257 257 m_chart->addSeries(qobject_cast<QAbstractSeries *>(child));
258 258 }
259 259 }
260 260 QDeclarativeItem::componentComplete();
261 261 }
262 262
263 263 void DeclarativeChart::geometryChanged(const QRectF &newGeometry, const QRectF &oldGeometry)
264 264 {
265 265 // qDebug() << "DeclarativeChart::geometryChanged" << newGeometry.width() << newGeometry.height();
266 266 if (newGeometry.isValid()) {
267 267 if (newGeometry.width() > 0 && newGeometry.height() > 0) {
268 268 m_chart->resize(newGeometry.width(), newGeometry.height());
269 269 }
270 270 }
271 271 QDeclarativeItem::geometryChanged(newGeometry, oldGeometry);
272 272 }
273 273
274 274 void DeclarativeChart::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
275 275 {
276 276 Q_UNUSED(option)
277 277 Q_UNUSED(widget)
278 278
279 279 // TODO: optimized?
280 280 painter->setRenderHint(QPainter::Antialiasing, true);
281 281 }
282 282
283 283 void DeclarativeChart::setTheme(DeclarativeChart::Theme theme)
284 284 {
285 285 QChart::ChartTheme chartTheme = (QChart::ChartTheme) theme;
286 286 if (chartTheme != m_chart->theme())
287 287 m_chart->setTheme(chartTheme);
288 288 }
289 289
290 290 DeclarativeChart::Theme DeclarativeChart::theme()
291 291 {
292 292 return (DeclarativeChart::Theme) m_chart->theme();
293 293 }
294 294
295 295 void DeclarativeChart::setAnimationOptions(DeclarativeChart::Animation animations)
296 296 {
297 297 QChart::AnimationOption animationOptions = (QChart::AnimationOption) animations;
298 298 if (animationOptions != m_chart->animationOptions())
299 299 m_chart->setAnimationOptions(animationOptions);
300 300 }
301 301
302 302 DeclarativeChart::Animation DeclarativeChart::animationOptions()
303 303 {
304 304 if (m_chart->animationOptions().testFlag(QChart::AllAnimations))
305 305 return DeclarativeChart::AllAnimations;
306 306 else if (m_chart->animationOptions().testFlag(QChart::GridAxisAnimations))
307 307 return DeclarativeChart::GridAxisAnimations;
308 308 else if (m_chart->animationOptions().testFlag(QChart::SeriesAnimations))
309 309 return DeclarativeChart::SeriesAnimations;
310 310 else
311 311 return DeclarativeChart::NoAnimation;
312 312 }
313 313
314 314 void DeclarativeChart::setTitle(QString title)
315 315 {
316 316 if (title != m_chart->title())
317 317 m_chart->setTitle(title);
318 318 }
319 319 QString DeclarativeChart::title()
320 320 {
321 321 return m_chart->title();
322 322 }
323 323
324 324 QAbstractAxis *DeclarativeChart::axisX(QAbstractSeries *series)
325 325 {
326 326 return m_chart->axisX(series);
327 327 }
328 328
329 329 QAbstractAxis *DeclarativeChart::axisY(QAbstractSeries *series)
330 330 {
331 331 return m_chart->axisY(series);
332 332 }
333 333
334 334 QLegend *DeclarativeChart::legend()
335 335 {
336 336 return m_chart->legend();
337 337 }
338 338
339 339 void DeclarativeChart::setTitleColor(QColor color)
340 340 {
341 341 QBrush b = m_chart->titleBrush();
342 342 if (color != b.color()) {
343 343 b.setColor(color);
344 344 m_chart->setTitleBrush(b);
345 345 emit titleColorChanged(color);
346 346 }
347 347 }
348 348
349 349 QFont DeclarativeChart::titleFont() const
350 350 {
351 351 return m_chart->titleFont();
352 352 }
353 353
354 354 void DeclarativeChart::setTitleFont(const QFont& font)
355 355 {
356 356 m_chart->setTitleFont(font);
357 357 }
358 358
359 359 QColor DeclarativeChart::titleColor()
360 360 {
361 361 return m_chart->titleBrush().color();
362 362 }
363 363
364 364 void DeclarativeChart::setBackgroundColor(QColor color)
365 365 {
366 366 QBrush b = m_chart->backgroundBrush();
367 367 if (b.style() != Qt::SolidPattern || color != b.color()) {
368 368 b.setStyle(Qt::SolidPattern);
369 369 b.setColor(color);
370 370 m_chart->setBackgroundBrush(b);
371 371 emit backgroundColorChanged();
372 372 }
373 373 }
374 374
375 375 QColor DeclarativeChart::backgroundColor()
376 376 {
377 377 return m_chart->backgroundBrush().color();
378 378 }
379 379
380 380 int DeclarativeChart::count()
381 381 {
382 382 return m_chart->series().count();
383 383 }
384 384
385 385 void DeclarativeChart::setDropShadowEnabled(bool enabled)
386 386 {
387 387 if (enabled != m_chart->isDropShadowEnabled()) {
388 388 m_chart->setDropShadowEnabled(enabled);
389 389 dropShadowEnabledChanged(enabled);
390 390 }
391 391 }
392 392
393 393 bool DeclarativeChart::dropShadowEnabled()
394 394 {
395 395 return m_chart->isDropShadowEnabled();
396 396 }
397 397
398 398 qreal DeclarativeChart::topMargin()
399 399 {
400 400 return m_chart->margins().top();
401 401 }
402 402
403 403 qreal DeclarativeChart::bottomMargin()
404 404 {
405 405 return m_chart->margins().bottom();
406 406 }
407 407
408 408 qreal DeclarativeChart::leftMargin()
409 409 {
410 410 return m_chart->margins().left();
411 411 }
412 412
413 413 qreal DeclarativeChart::rightMargin()
414 414 {
415 415 return m_chart->margins().right();
416 416 }
417 417
418 418 void DeclarativeChart::zoom(qreal factor)
419 419 {
420 420 m_chart->zoom(factor);
421 421 }
422 422
423 423 void DeclarativeChart::scrollLeft(qreal pixels)
424 424 {
425 m_chart->scroll(QPointF(pixels, 0));
425 m_chart->scroll(pixels, 0);
426 426 }
427 427
428 428 void DeclarativeChart::scrollRight(qreal pixels)
429 429 {
430 m_chart->scroll(QPointF(-pixels, 0));
430 m_chart->scroll(-pixels, 0);
431 431 }
432 432
433 433 void DeclarativeChart::scrollUp(qreal pixels)
434 434 {
435 m_chart->scroll(QPointF(0, pixels));
435 m_chart->scroll(0, pixels);
436 436 }
437 437
438 438 void DeclarativeChart::scrollDown(qreal pixels)
439 439 {
440 m_chart->scroll(QPointF(0, -pixels));
440 m_chart->scroll(0, -pixels);
441 441 }
442 442
443 443 QAbstractSeries *DeclarativeChart::series(int index)
444 444 {
445 445 if (index < m_chart->series().count()) {
446 446 return m_chart->series().at(index);
447 447 }
448 448 return 0;
449 449 }
450 450
451 451 QAbstractSeries *DeclarativeChart::series(QString seriesName)
452 452 {
453 453 foreach(QAbstractSeries *series, m_chart->series()) {
454 454 if (series->name() == seriesName)
455 455 return series;
456 456 }
457 457 return 0;
458 458 }
459 459
460 460 QAbstractSeries *DeclarativeChart::createSeries(DeclarativeChart::SeriesType type, QString name)
461 461 {
462 462 QAbstractSeries *series = 0;
463 463 switch (type) {
464 464 case DeclarativeChart::SeriesTypeLine:
465 465 series = new DeclarativeLineSeries();
466 466 break;
467 467 case DeclarativeChart::SeriesTypeArea:
468 468 series = new DeclarativeAreaSeries();
469 469 break;
470 470 case DeclarativeChart::SeriesTypeBar:
471 471 series = new DeclarativeBarSeries();
472 472 break;
473 473 case DeclarativeChart::SeriesTypeStackedBar:
474 474 // TODO
475 475 break;
476 476 case DeclarativeChart::SeriesTypePercentBar:
477 477 // TODO
478 478 break;
479 479 case DeclarativeChart::SeriesTypeGroupedBar:
480 480 series = new DeclarativeGroupedBarSeries();
481 481 break;
482 482 case DeclarativeChart::SeriesTypePie:
483 483 series = new DeclarativePieSeries();
484 484 break;
485 485 case DeclarativeChart::SeriesTypeScatter:
486 486 series = new DeclarativeScatterSeries();
487 487 break;
488 488 case DeclarativeChart::SeriesTypeSpline:
489 489 series = new DeclarativeSplineSeries();
490 490 break;
491 491 default:
492 492 qWarning() << "Illegal series type";
493 493 }
494 494 series->setName(name);
495 495 m_chart->addSeries(series);
496 496 return series;
497 497 }
498 498
499 499 #include "moc_declarativechart.cpp"
500 500
501 501 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,175 +1,190
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 "qabstractseries.h"
22 22 #include "qabstractseries_p.h"
23 23 #include "chartdataset_p.h"
24 24
25 25 QTCOMMERCIALCHART_BEGIN_NAMESPACE
26 26
27 27 /*!
28 28 \class QAbstractSeries
29 29 \brief Base class for all QtCommercial Chart series.
30 30 \mainclass
31 31
32 32 Usually you use the series type specific inherited classes instead of the base class.
33 33 \sa QXYSeries, QLineSeries, QSplineSeries, QScatterSeries, QAreaSeries, QBarSeries, QStackedBarSeries,
34 34 QPercentBarSeries, QPieSeries
35 35 */
36 36 /*!
37 37 \qmlclass AbstractSeries
38 38 AbstractSeries is the base class for all series.
39 39 The class cannot be instantiated by the user.
40 40 */
41 41
42 42 /*!
43 43 \enum QAbstractSeries::SeriesType
44 44
45 45 The type of the series object.
46 46
47 47 \value SeriesTypeLine
48 48 \value SeriesTypeArea
49 49 \value SeriesTypeBar
50 50 \value SeriesTypeStackedBar
51 51 \value SeriesTypePercentBar
52 52 \value SeriesTypeGroupedBar
53 53 \value SeriesTypePie
54 54 \value SeriesTypeScatter
55 55 \value SeriesTypeSpline
56 56 */
57 57
58 58 /*!
59 59 \property QAbstractSeries::type
60 60 The type of the series.
61 61 */
62 62 /*!
63 63 \qmlproperty ChartView.SeriesType AbstractSeries::type
64 64 The type of the series.
65 65 */
66 66
67 67 /*!
68 68 \property QAbstractSeries::name
69 69 \brief name of the series property. The name is shown in legend for QXYSeries.
70 70 */
71 71 /*!
72 72 \qmlproperty string AbstractSeries::name
73 73 Name of the series. The name is shown in legend for QXYSeries.
74 74 */
75 75
76 76 /*!
77 77 \fn void QAbstractSeries::nameChanged()
78 78 This signal is emitted when the series name changes.
79 79 */
80 80 /*!
81 81 \qmlsignal AbstractSeries::nameChanged()
82 82 This signal is emitted when the series name changes.
83 83 */
84 84
85 85 /*!
86 86 \property QAbstractSeries::visible
87 87 \brief whether the series is visible or not; true by default.
88 88 */
89 89
90 90 /*!
91 91 \fn void QAbstractSeries::visibleChanged()
92 92 Emitted when the series visibility changes.
93 93 */
94 94
95 95 /*!
96 96 \internal
97 97 \brief Constructs ChartSeries object with \a parent.
98 98 */
99 99 QAbstractSeries::QAbstractSeries(QAbstractSeriesPrivate &d, QObject *parent) :
100 100 QObject(parent),
101 101 d_ptr(&d)
102 102 {
103 103 }
104 104
105 105 /*!
106 106 \brief Virtual destructor for the chart series.
107 107 */
108 108 QAbstractSeries::~QAbstractSeries()
109 109 {
110 110 if(d_ptr->m_dataset) qFatal("Still binded series detected !");
111 111 }
112 112
113 113 void QAbstractSeries::setName(const QString& name)
114 114 {
115 115 if (name != d_ptr->m_name) {
116 116 d_ptr->m_name = name;
117 117 emit nameChanged();
118 118 }
119 119 }
120 120
121 121 QString QAbstractSeries::name() const
122 122 {
123 123 return d_ptr->m_name;
124 124 }
125 125
126 126 /*!
127 127 Sets the visibility of series to \a visible
128 128 */
129 129 void QAbstractSeries::setVisible(bool visible)
130 130 {
131 131 if (visible != d_ptr->m_visible) {
132 132 d_ptr->m_visible = visible;
133 133 emit visibleChanged();
134 134 }
135 135 }
136 136
137 137 /*!
138 138 Returns the visibility of series
139 139 */
140 140 bool QAbstractSeries::isVisible() const
141 141 {
142 142 return d_ptr->m_visible;
143 143 }
144 144
145 145 /*!
146 146 \brief Returns the chart where series belongs to.
147 147
148 148 Set automatically when the series is added to the chart
149 149 and unset when the series is removed from the chart.
150 150 */
151 151 QChart* QAbstractSeries::chart() const
152 152 {
153 153 return d_ptr->m_chart;
154 154 }
155 155
156 void QAbstractSeries::adjustView()
157 {
158 //TODO:
159 }
160
161 void QAbstractSeries::show()
162 {
163 setVisible(true);
164 }
165
166 void QAbstractSeries::hide()
167 {
168 setVisible(false);
169 }
170
156 171 ///////////////////////////////////////////////////////////////////////////////////////////////////
157 172
158 173 QAbstractSeriesPrivate::QAbstractSeriesPrivate(QAbstractSeries* q):
159 174 q_ptr(q),
160 175 m_chart(0),
161 176 m_dataset(0),
162 177 m_visible(true)
163 178 {
164 179 }
165 180
166 181 QAbstractSeriesPrivate::~QAbstractSeriesPrivate()
167 182 {
168 183 }
169 184
170 185 #include "moc_qabstractseries.cpp"
171 186 #include "moc_qabstractseries_p.cpp"
172 187
173 188 QTCOMMERCIALCHART_END_NAMESPACE
174 189
175 190
@@ -1,492 +1,437
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 "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 <QGraphicsScene>
28 28 #include <QGraphicsSceneResizeEvent>
29 29 #include <QGraphicsLayout>
30 30
31 31 QTCOMMERCIALCHART_BEGIN_NAMESPACE
32 32
33 33 /*!
34 34 \enum QChart::ChartTheme
35 35
36 36 This enum describes the theme used by the chart.
37 37
38 38 \value ChartThemeLight The default theme
39 39 \value ChartThemeBlueCerulean
40 40 \value ChartThemeDark
41 41 \value ChartThemeBrownSand
42 42 \value ChartThemeBlueNcs
43 43 \value ChartThemeHighContrast
44 44 \value ChartThemeBlueIcy
45 45 */
46 46
47 47 /*!
48 48 \enum QChart::AnimationOption
49 49
50 50 For enabling/disabling animations. Defaults to NoAnimation.
51 51
52 52 \value NoAnimation
53 53 \value GridAxisAnimations
54 54 \value SeriesAnimations
55 55 \value AllAnimations
56 56 */
57 57
58 58 /*!
59 59 \class QChart
60 60 \brief QtCommercial chart API.
61 61
62 62 QChart is a QGraphicsWidget that you can show in a QGraphicsScene. It manages the graphical
63 63 representation of different types of series and other chart related objects like
64 64 QAxis and QLegend. If you simply want to show a chart in a layout, you can use the
65 65 convenience class QChartView instead of QChart.
66 66 \sa QChartView
67 67 */
68 68
69 69 /*!
70 70 \property QChart::animationOptions
71 71 The animation \a options for the chart. Animations are enabled/disabled based on this setting.
72 72 */
73 73
74 74 /*!
75 75 \property QChart::backgroundVisible
76 76 Whether the chart background is visible or not.
77 77 \sa setBackgroundBrush(), setBackgroundPen()
78 78 */
79 79
80 80 /*!
81 81 \property QChart::dropShadowEnabled
82 82 If set to true, the background drop shadow effect is enabled. If set to false, it is disabled. Note that the drop
83 83 shadow effect depends on theme, which means the setting may be changed if you switch to another theme.
84 84 */
85 85
86 86 /*!
87 87 \property QChart::margins
88 88 Margins around the plot area. Note that the margin area is used for drawing chart title, legend and axes.
89 89 */
90 90
91 91 /*!
92 92 \property QChart::theme
93 93 Theme is a built-in collection of UI style related settings applied for all visual elements of a chart, like colors,
94 94 pens, brushes and fonts of series, axes, title and legend. \l {Chart themes demo} shows an example with a few
95 95 different themes.
96 96 Note: changing the theme will overwrite all customizations previously applied to the series.
97 97 */
98 98
99 99 /*!
100 100 \property QChart::title
101 101 Title is the name (label) of a chart. It is shown as a headline on top of the chart.
102 102 */
103 103
104 104 /*!
105 105 \fn void QChart::marginsChanged(QRectF newMargins)
106 106 The margins around plot area have changed to \a newMargins. This may happen for example if you change title font size,
107 107 modify axes or hide/show legend.
108 108 */
109 109
110 110 /*!
111 111 Constructs a chart object which is a child of a\a parent. Parameter \a wFlags is passed to the QGraphicsWidget constructor.
112 112 */
113 113 QChart::QChart(QGraphicsItem *parent, Qt::WindowFlags wFlags) : QGraphicsWidget(parent,wFlags),
114 114 d_ptr(new QChartPrivate())
115 115 {
116 116 d_ptr->m_dataset = new ChartDataSet(this);
117 117 d_ptr->m_presenter = new ChartPresenter(this,d_ptr->m_dataset);
118 118 d_ptr->createConnections();
119 119 d_ptr->m_legend = new LegendScroller(this);
120 120 d_ptr->m_presenter->setTheme(QChart::ChartThemeLight, false);
121 121 //connect(d_ptr->m_presenter, SIGNAL(marginsChanged(QRectF)), this, SIGNAL(marginsChanged(QRectF)));
122 122 setLayout(d_ptr->m_presenter->layout());
123 123 }
124 124
125 125 /*!
126 126 Destroys the object and it's children, like series and axis objects added to it.
127 127 */
128 128 QChart::~QChart()
129 129 {
130 130 //delete first presenter , since this is a root of all the graphical items
131 131 setLayout(0);
132 132 delete d_ptr->m_presenter;
133 133 d_ptr->m_presenter=0;
134 134 }
135 135
136 136 /*!
137 137 Adds the \a series and optional \a axisY onto the chart and takes the ownership of the objects.
138 138 If auto scaling is enabled, re-scales the axes the series is bound to (both the x axis and
139 139 the y axis).
140 140
141 141 \sa removeSeries(), removeAllSeries()
142 142 */
143 143 void QChart::addSeries(QAbstractSeries *series)
144 144 {
145 145 Q_ASSERT(series);
146 146 d_ptr->m_dataset->addSeries(series);
147 147 }
148 148
149 149 /*!
150 150 Removes the \a series specified in a perameter from the QChartView.
151 151 It releses its ownership of the specified QChartSeries object.
152 152 It does not delete the pointed QChartSeries data object
153 153 \sa addSeries(), removeAllSeries()
154 154 */
155 155 void QChart::removeSeries(QAbstractSeries *series)
156 156 {
157 157 Q_ASSERT(series);
158 158 d_ptr->m_dataset->removeSeries(series);
159 159 }
160 160
161 161 /*!
162 162 Removes all the QChartSeries that have been added to the QChartView
163 163 It also deletes the pointed QChartSeries data objects
164 164 \sa addSeries(), removeSeries()
165 165 */
166 166 void QChart::removeAllSeries()
167 167 {
168 168 d_ptr->m_dataset->removeAllSeries();
169 169 }
170 170
171 171 /*!
172 172 Sets the \a brush that is used for painting the background of the chart area.
173 173 */
174 174 void QChart::setBackgroundBrush(const QBrush& brush)
175 175 {
176 176 d_ptr->m_presenter->setBackgroundBrush(brush);
177 177 }
178 178
179 179 /*!
180 180 Gets the brush that is used for painting the background of the chart area.
181 181 */
182 182 QBrush QChart::backgroundBrush() const
183 183 {
184 184 return d_ptr->m_presenter->backgroundBrush();
185 185 }
186 186
187 187 /*!
188 188 Sets the \a pen that is used for painting the background of the chart area.
189 189 */
190 190 void QChart::setBackgroundPen(const QPen& pen)
191 191 {
192 192 d_ptr->m_presenter->setBackgroundPen(pen);
193 193 }
194 194
195 195 /*!
196 196 Gets the pen that is used for painting the background of the chart area.
197 197 */
198 198 QPen QChart::backgroundPen() const
199 199 {
200 200 return d_ptr->m_presenter->backgroundPen();
201 201 }
202 202
203 203 /*!
204 204 Sets the chart \a title. The description text that is drawn above the chart.
205 205 */
206 206 void QChart::setTitle(const QString& title)
207 207 {
208 208 d_ptr->m_presenter->setTitle(title);
209 209 }
210 210
211 211 /*!
212 212 Returns the chart title. The description text that is drawn above the chart.
213 213 */
214 214 QString QChart::title() const
215 215 {
216 216 return d_ptr->m_presenter->title();
217 217 }
218 218
219 219 /*!
220 220 Sets the \a font that is used for drawing the chart description text that is rendered above the chart.
221 221 */
222 222 void QChart::setTitleFont(const QFont& font)
223 223 {
224 224 d_ptr->m_presenter->setTitleFont(font);
225 225 }
226 226
227 227 /*!
228 228 Gets the font that is used for drawing the chart description text that is rendered above the chart.
229 229 */
230 230 QFont QChart::titleFont() const
231 231 {
232 232 return d_ptr->m_presenter->titleFont();
233 233 }
234 234
235 235 /*!
236 236 Sets the \a brush used for rendering the title text.
237 237 */
238 238 void QChart::setTitleBrush(const QBrush &brush)
239 239 {
240 240 d_ptr->m_presenter->setTitleBrush(brush);
241 241 }
242 242
243 243 /*!
244 244 Returns the brush used for rendering the title text.
245 245 */
246 246 QBrush QChart::titleBrush() const
247 247 {
248 248 return d_ptr->m_presenter->titleBrush();
249 249 }
250 250
251 251 void QChart::setTheme(QChart::ChartTheme theme)
252 252 {
253 253 d_ptr->m_presenter->setTheme(theme);
254 254 }
255 255
256 256 QChart::ChartTheme QChart::theme() const
257 257 {
258 258 return d_ptr->m_presenter->theme();
259 259 }
260 260
261 261 /*!
262 262 Zooms in the view by a factor of 2
263 263 */
264 264 void QChart::zoomIn()
265 265 {
266 266 d_ptr->m_presenter->zoomIn(2.0);
267 267 }
268 268
269 269 /*!
270 270 Zooms in the view to a maximum level at which \a rect is still fully visible.
271 271 */
272 272 void QChart::zoomIn(const QRectF& rect)
273 273 {
274 274 if (!rect.isValid()) return;
275 275 d_ptr->m_presenter->zoomIn(rect);
276 276 }
277 277
278 278 /*!
279 279 Restores the view zoom level to the previous one.
280 280 */
281 281 void QChart::zoomOut()
282 282 {
283 283 d_ptr->m_presenter->zoomOut(2.0);
284 284 }
285 285
286 286 /*!
287 287 Zooms in the view by a \a factor.
288 288
289 289 A factor over 1.0 zooms the view in and factor between 0.0 and 1.0 zooms out.
290 290 */
291 291 void QChart::zoom(qreal factor)
292 292 {
293 293 if (qFuzzyIsNull(factor))
294 294 return;
295 295
296 296 if (qFuzzyCompare(factor, 1.0))
297 297 return;
298 298
299 299 if (factor < 0)
300 300 return;
301 301
302 302 if (factor > 1.0)
303 303 d_ptr->m_presenter->zoomIn(factor);
304 304 else
305 305 d_ptr->m_presenter->zoomOut(1.0 / factor);
306 306 }
307 307
308 308 /*!
309 309 Returns the pointer to the x axis object of the chart
310 310 */
311 311 QAbstractAxis* QChart::axisX(QAbstractSeries* series) const
312 312 {
313 313 return d_ptr->m_dataset->axisX(series);
314 314 }
315 315
316 316 /*!
317 317 Returns the pointer to the y axis object of the \a series
318 318 If no \a series is provided then default Y axis of the chart is returned.
319 319 */
320 320 QAbstractAxis* QChart::axisY(QAbstractSeries *series) const
321 321 {
322 322 return d_ptr->m_dataset->axisY(series);
323 323 }
324 324
325 325 /*!
326 326 Returns the legend object of the chart. Ownership stays in chart.
327 327 */
328 328 QLegend* QChart::legend() const
329 329 {
330 330 return d_ptr->m_legend;
331 331 }
332 332
333 333 /*!
334 334 Returns the rect that contains information about margins (distance between chart widget edge and axes).
335 335 Individual margins can be obtained by calling left, top, right, bottom on the returned rect.
336 336 */
337 337 QRectF QChart::margins() const
338 338 {
339 339 return d_ptr->m_presenter->margins();
340 340 }
341 341
342 342 /*!
343 343 Sets animation \a options for the chart
344 344 */
345 345
346 346 void QChart::setAnimationOptions(AnimationOptions options)
347 347 {
348 348 d_ptr->m_presenter->setAnimationOptions(options);
349 349 }
350 350
351 351 QChart::AnimationOptions QChart::animationOptions() const
352 352 {
353 353 return d_ptr->m_presenter->animationOptions();
354 354 }
355 355
356 356 /*!
357 Scrolls the visible area of the chart to the left by the distance between two x axis ticks
358 */
359 void QChart::scrollLeft(qreal dx)
360 {
361 <<<<<<< Updated upstream
362 // d_ptr->m_presenter->scroll(-d_ptr->m_presenter->geometry().width()/(axisX()->ticksCount()-1),0);
363 =======
364 //TODO:
365 Q_UNUSED(dx);
366 // d_ptr->m_presenter->scroll(-d_ptr->m_presenter->geometry().width()/(axisX()->d_ptr->ticksCount()-1),0);
367 >>>>>>> Stashed changes
368 }
369
370 /*!
371 Scrolls the visible area of the chart to the right by the distance between two x axis ticks
372 */
373 void QChart::scrollRight(qreal dx)
374 {
375 <<<<<<< Updated upstream
376 // d_ptr->m_presenter->scroll(d_ptr->m_presenter->geometry().width()/(axisX()->ticksCount()-1),0);
377 =======
378 //TODO:
379 Q_UNUSED(dx);
380 // d_ptr->m_presenter->scroll(d_ptr->m_presenter->geometry().width()/(axisX()->ticksCount()-1),0);
381 >>>>>>> Stashed changes
382 }
383
384 /*!
385 Scrolls the visible area of the chart up by the distance between two y axis ticks
386 */
387 void QChart::scrollUp(qreal dy)
388 {
389 <<<<<<< Updated upstream
390 =======
391 //TODO:
392 Q_UNUSED(dy);
393 >>>>>>> Stashed changes
394 // d_ptr->m_presenter->scroll(0,d_ptr->m_presenter->geometry().width()/(axisY()->ticksCount()-1));
395 }
396
397 /*!
398 Scrolls the visible area of the chart down by the distance between two y axis ticks
399 */
400 void QChart::scrollDown(qreal dy)
401 {
402 <<<<<<< Updated upstream
403 // d_ptr->m_presenter->scroll(0,-d_ptr->m_presenter->geometry().width()/(axisY()->ticksCount()-1));
404 =======
405 //TODO:
406 Q_UNUSED(dy);
407 // d_ptr->m_presenter->scroll(0,-d_ptr->m_presenter->geometry().width()/(axisY()->ticksCount()-1));
408 >>>>>>> Stashed changes
409 }
410
411 /*!
412 357 Scrolls the visible area of the chart by the distance defined in the \a delta.
413 358 */
414 void QChart::scroll(const QPointF &delta)
359 void QChart::scroll(qreal dx, qreal dy)
415 360 {
416 d_ptr->m_presenter->scroll(-delta.x(), delta.y());
361 d_ptr->m_presenter->scroll(dx, dy);
417 362 }
418 363
419 364 void QChart::setBackgroundVisible(bool visible)
420 365 {
421 366 d_ptr->m_presenter->setBackgroundVisible(visible);
422 367 }
423 368
424 369 bool QChart::isBackgroundVisible() const
425 370 {
426 371 return d_ptr->m_presenter->isBackgroundVisible();
427 372 }
428 373
429 374 void QChart::setDropShadowEnabled(bool enabled)
430 375 {
431 376 d_ptr->m_presenter->setBackgroundDropShadowEnabled(enabled);
432 377 }
433 378
434 379 bool QChart::isDropShadowEnabled() const
435 380 {
436 381 return d_ptr->m_presenter->isBackgroundDropShadowEnabled();
437 382 }
438 383
439 384 /*!
440 385 Returns all the series that are added to the chart.
441 386
442 387 \sa addSeries(), removeSeries(), removeAllSeries()
443 388 */
444 389 QList<QAbstractSeries*> QChart::series() const
445 390 {
446 391 return d_ptr->m_dataset->series();
447 392 }
448 393
449 394 void QChart::setMarginsMinimum(const QRectF& margins)
450 395 {
451 396 d_ptr->m_presenter->setMarginsMinimum(margins);
452 397 }
453 398
454 399 void QChart::setAxisX(QAbstractSeries *series, QAbstractAxis* axis)
455 400 {
456 401 Q_UNUSED(series);
457 402 Q_UNUSED(axis);
458 403 }
459 404
460 405 void QChart::setAxisY(QAbstractSeries *series, QAbstractAxis* axis)
461 406 {
462 407 Q_UNUSED(series);
463 408 Q_UNUSED(axis);
464 409 }
465 410
466 411 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
467 412
468 413 QChartPrivate::QChartPrivate():
469 414 m_legend(0),
470 415 m_dataset(0),
471 416 m_presenter(0)
472 417 {
473 418
474 419 }
475 420
476 421 QChartPrivate::~QChartPrivate()
477 422 {
478 423
479 424 }
480 425
481 426 void QChartPrivate::createConnections()
482 427 {
483 428 QObject::connect(m_dataset,SIGNAL(seriesAdded(QAbstractSeries*,Domain*)),m_presenter,SLOT(handleSeriesAdded(QAbstractSeries*,Domain*)));
484 429 QObject::connect(m_dataset,SIGNAL(seriesRemoved(QAbstractSeries*)),m_presenter,SLOT(handleSeriesRemoved(QAbstractSeries*)));
485 430 QObject::connect(m_dataset,SIGNAL(axisAdded(QAbstractAxis*,Domain*)),m_presenter,SLOT(handleAxisAdded(QAbstractAxis*,Domain*)));
486 431 QObject::connect(m_dataset,SIGNAL(axisRemoved(QAbstractAxis*)),m_presenter,SLOT(handleAxisRemoved(QAbstractAxis*)));
487 432 //QObject::connect(m_presenter, SIGNAL(marginsChanged(QRectF)), q_ptr, SIGNAL(marginsChanged(QRectF)));
488 433 }
489 434
490 435 #include "moc_qchart.cpp"
491 436
492 437 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,137 +1,133
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 QCHART_H
22 22 #define QCHART_H
23 23
24 24 #include <QAbstractSeries>
25 25 #include <QLegend>
26 26 #include <QGraphicsWidget>
27 27
28 28 class QGraphicsSceneResizeEvent;
29 29
30 30 QTCOMMERCIALCHART_BEGIN_NAMESPACE
31 31
32 32 class QAbstractSeries;
33 33 class QAbstractAxis;
34 34 class QLegend;
35 35 struct QChartPrivate;
36 36
37 37 class QTCOMMERCIALCHART_EXPORT QChart : public QGraphicsWidget
38 38 {
39 39 Q_OBJECT
40 40 Q_PROPERTY(QChart::ChartTheme theme READ theme WRITE setTheme)
41 41 Q_PROPERTY(QString title READ title WRITE setTitle)
42 42 Q_PROPERTY(bool backgroundVisible READ isBackgroundVisible WRITE setBackgroundVisible)
43 43 Q_PROPERTY(bool dropShadowEnabled READ isDropShadowEnabled WRITE setDropShadowEnabled)
44 44 Q_PROPERTY(QChart::AnimationOptions animationOptions READ animationOptions WRITE setAnimationOptions)
45 45 Q_PROPERTY(QRectF margins READ margins NOTIFY marginsChanged)
46 46 Q_ENUMS(ChartTheme)
47 47 Q_ENUMS(AnimationOption)
48 48
49 49 public:
50 50 enum ChartTheme {
51 51 ChartThemeLight = 0,
52 52 ChartThemeBlueCerulean,
53 53 ChartThemeDark,
54 54 ChartThemeBrownSand,
55 55 ChartThemeBlueNcs,
56 56 ChartThemeHighContrast,
57 57 ChartThemeBlueIcy
58 58 };
59 59
60 60 enum AnimationOption {
61 61 NoAnimation = 0x0,
62 62 GridAxisAnimations = 0x1,
63 63 SeriesAnimations =0x2,
64 64 AllAnimations = 0x3
65 65 };
66 66
67 67 Q_DECLARE_FLAGS(AnimationOptions, AnimationOption)
68 68
69 69 public:
70 70 explicit QChart(QGraphicsItem *parent = 0, Qt::WindowFlags wFlags = 0);
71 71 ~QChart();
72 72
73 73 void addSeries(QAbstractSeries *series);
74 74 void removeSeries(QAbstractSeries *series);
75 75 void removeAllSeries();
76 76 QList<QAbstractSeries*> series() const;
77 77
78 78 void setAxisX(QAbstractSeries *series, QAbstractAxis* axis);
79 79 void setAxisY(QAbstractSeries *series, QAbstractAxis* axis);
80 80
81 81 QAbstractAxis* axisX(QAbstractSeries* series = 0) const;
82 82 QAbstractAxis* axisY(QAbstractSeries* series = 0) const;
83 83
84 84 void setTheme(QChart::ChartTheme theme);
85 85 QChart::ChartTheme theme() const;
86 86
87 87 void setTitle(const QString& title);
88 88 QString title() const;
89 89 void setTitleFont(const QFont& font);
90 90 QFont titleFont() const;
91 91 void setTitleBrush(const QBrush &brush);
92 92 QBrush titleBrush() const;
93 93
94 94 void setBackgroundBrush(const QBrush &brush);
95 95 QBrush backgroundBrush() const;
96 96 void setBackgroundPen(const QPen &pen);
97 97 QPen backgroundPen() const;
98 98 void setBackgroundVisible(bool visible = true);
99 99 bool isBackgroundVisible() const;
100 100
101 101 void setDropShadowEnabled(bool enabled = true);
102 102 bool isDropShadowEnabled() const;
103 103 void setAnimationOptions(AnimationOptions options);
104 104 AnimationOptions animationOptions() const;
105 105
106 106 void zoomIn();
107 107 void zoomIn(const QRectF &rect);
108 108 void zoomOut();
109 109 void zoom(qreal factor);
110 void scrollLeft(qreal dx);
111 void scrollRight(qreal dx);
112 void scrollUp(qreal dy);
113 void scrollDown(qreal dy);
114 void scroll(const QPointF &delta);
110 void scroll(qreal dx, qreal dy);
115 111
116 112 void adjustViewToSeries(QAbstractSeries* series= 0);
117 113
118 114 QLegend* legend() const;
119 115
120 116 void setMarginsMinimum(const QRectF& margins);
121 117 QRectF margins() const;
122 118
123 119 Q_SIGNALS:
124 120 void marginsChanged(QRectF newMargins);
125 121
126 122 protected:
127 123 QScopedPointer<QChartPrivate> d_ptr;
128 124 friend class QLegend;
129 125 friend class ChartPresenter;
130 126 Q_DISABLE_COPY(QChart)
131 127 };
132 128
133 129 QTCOMMERCIALCHART_END_NAMESPACE
134 130
135 131 Q_DECLARE_OPERATORS_FOR_FLAGS(QTCOMMERCIALCHART_NAMESPACE::QChart::AnimationOptions)
136 132
137 133 #endif
@@ -1,665 +1,614
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 void scrollDown_data();
80 void scrollDown();
81 void scrollLeft_data();
82 void scrollLeft();
83 void scrollRight_data();
84 void scrollRight();
85 void scrollUp_data();
86 void scrollUp();
79 void scroll_data();
80 void scroll();
87 81 void theme_data();
88 82 void theme();
89 83 void title_data();
90 84 void title();
91 85 void titleBrush_data();
92 86 void titleBrush();
93 87 void titleFont_data();
94 88 void titleFont();
95 89 void zoomIn_data();
96 90 void zoomIn();
97 91 void zoomOut_data();
98 92 void zoomOut();
99 93
100 94 private:
101 95 void createTestData();
102 96
103 97 private:
104 98 QChartView* m_view;
105 99 QChart* m_chart;
106 100 };
107 101
108 102 void tst_QChart::initTestCase()
109 103 {
110 104
111 105 }
112 106
113 107 void tst_QChart::cleanupTestCase()
114 108 {
115 109
116 110 }
117 111
118 112 void tst_QChart::init()
119 113 {
120 114 m_view = new QChartView(new QChart());
121 115 m_chart = m_view->chart();
122 116 }
123 117
124 118 void tst_QChart::createTestData()
125 119 {
126 120 QLineSeries* series0 = new QLineSeries(this);
127 121 *series0 << QPointF(0, 0) << QPointF(100, 100);
128 122 m_chart->addSeries(series0);
129 123 m_view->show();
130 124 QTest::qWaitForWindowShown(m_view);
131 125 }
132 126
133 127 void tst_QChart::cleanup()
134 128 {
135 129 delete m_view;
136 130 m_view = 0;
137 131 m_chart = 0;
138 132 }
139 133
140 134 void tst_QChart::qchart_data()
141 135 {
142 136 }
143 137
144 138 void tst_QChart::qchart()
145 139 {
146 140 QVERIFY(m_chart);
147 141 QVERIFY(m_chart->legend());
148 142 QVERIFY(m_chart->legend()->isVisible());
149 143
150 144 QCOMPARE(m_chart->animationOptions(), QChart::NoAnimation);
151 145 QVERIFY(m_chart->axisX());
152 146 QVERIFY(m_chart->axisY());
153 147 QVERIFY(m_chart->backgroundBrush()!=QBrush());
154 148 QVERIFY(m_chart->backgroundPen()!=QPen());
155 149 QCOMPARE(m_chart->isBackgroundVisible(), true);
156 150
157 151 QVERIFY(m_chart->margins().top()>0);
158 152 QVERIFY(m_chart->margins().left()>0);
159 153 QVERIFY(m_chart->margins().right()>0);
160 154 QVERIFY(m_chart->margins().bottom()>0);
161 155
162 156 QCOMPARE(m_chart->theme(), QChart::ChartThemeLight);
163 157 QCOMPARE(m_chart->title(), QString());
164 158
165 159 //QCOMPARE(m_chart->titleBrush(),QBrush());
166 160 //QCOMPARE(m_chart->titleFont(),QFont());
167 161
168 162 m_chart->removeAllSeries();
169 m_chart->scrollDown();
170 m_chart->scrollLeft();
171 m_chart->scrollRight();
172 m_chart->scrollUp();
163 m_chart->scroll(0,0);
173 164
174 165 m_chart->zoomIn();
175 166 m_chart->zoomIn(QRectF());
176 167 m_chart->zoomOut();
177 168 }
178 169
179 170 void tst_QChart::addSeries_data()
180 171 {
181 172 QTest::addColumn<QAbstractSeries *>("series");
182 173 QTest::addColumn<QAbstractAxis *>("axis");
183 174
184 175 QAbstractSeries* series0 = new QLineSeries(this);
185 176 QAbstractSeries* series1 = new QAreaSeries(static_cast<QLineSeries*>(series0));
186 177 QAbstractSeries* series2 = new QScatterSeries(this);
187 178 QAbstractSeries* series3 = new QSplineSeries(this);
188 179 QAbstractSeries* series4 = new QPieSeries(this);
189 180 QAbstractSeries* series5 = new QBarSeries(this);
190 181 QAbstractSeries* series6 = new QPercentBarSeries(this);
191 182 QAbstractSeries* series7 = new QStackedBarSeries(this);
192 183
193 184 QValuesAxis* axis = new QValuesAxis(this);
194 185
195 186 QTest::newRow("default axis: lineSeries") << series0 << (QAbstractAxis*) 0;
196 187 QTest::newRow("axis0: lineSeries") << series0 << axis;
197 188 QTest::newRow("default axis: areaSeries") << series1 << (QAbstractAxis*) 0;
198 189 QTest::newRow("axis: areaSeries") << series1 << axis;
199 190 QTest::newRow("default axis: scatterSeries") << series2 << (QAbstractAxis*) 0;
200 191 QTest::newRow("axis1: scatterSeries") << series2 << axis;
201 192 QTest::newRow("default axis: splineSeries") << series3 << (QAbstractAxis*) 0;
202 193 QTest::newRow("axis: splineSeries") << series3 << axis;
203 194 QTest::newRow("default axis: pieSeries") << series4 << (QAbstractAxis*) 0;
204 195 QTest::newRow("axis: pieSeries") << series4 << axis;
205 196 QTest::newRow("default axis: barSeries") << series5 << (QAbstractAxis*) 0;
206 197 QTest::newRow("axis: barSeries") << series5 << axis;
207 198 QTest::newRow("default axis: percentBarSeries") << series6 << (QAbstractAxis*) 0;
208 199 QTest::newRow("axis: barSeries") << series6 << axis;
209 200 QTest::newRow("default axis: stackedBarSeries") << series7 << (QAbstractAxis*) 0;
210 201 QTest::newRow("axis: barSeries") << series7 << axis;
211 202
212 203 }
213 204
214 205 void tst_QChart::addSeries()
215 206 {
216 207 QFETCH(QAbstractSeries *, series);
217 208 QFETCH(QAbstractAxis *, axis);
218 209 m_view->show();
219 210 QTest::qWaitForWindowShown(m_view);
220 211 if(!axis) axis = m_chart->axisY();
221 212 QVERIFY(!series->chart());
222 213 QCOMPARE(m_chart->series().count(), 0);
223 214 m_chart->addSeries(series);
224 215 m_chart->setAxisY(series,axis);
225 216 QCOMPARE(m_chart->series().count(), 1);
226 217 QCOMPARE(m_chart->series().first(), series);
227 218 QVERIFY(series->chart() == m_chart);
228 219 QCOMPARE(m_chart->axisY(series),axis);
229 220 m_chart->removeSeries(series);
230 221 QVERIFY(!series->chart());
231 222 QCOMPARE(m_chart->series().count(), 0);
232 223 }
233 224
234 225 void tst_QChart::animationOptions_data()
235 226 {
236 227 QTest::addColumn<QChart::AnimationOption>("animationOptions");
237 228 QTest::newRow("AllAnimations") << QChart::AllAnimations;
238 229 QTest::newRow("NoAnimation") << QChart::NoAnimation;
239 230 QTest::newRow("GridAxisAnimations") << QChart::GridAxisAnimations;
240 231 QTest::newRow("SeriesAnimations") << QChart::SeriesAnimations;
241 232 }
242 233
243 234 void tst_QChart::animationOptions()
244 235 {
245 236 createTestData();
246 237 QFETCH(QChart::AnimationOption, animationOptions);
247 238 m_chart->setAnimationOptions(animationOptions);
248 239 QCOMPARE(m_chart->animationOptions(), animationOptions);
249 240 }
250 241
251 242 void tst_QChart::axisX_data()
252 243 {
253 244
254 245 }
255 246
256 247 void tst_QChart::axisX()
257 248 {
258 249 QVERIFY(m_chart->axisX());
259 250 QAbstractAxis* axis = m_chart->axisX();
260 251 createTestData();
261 252 //it should be the same axis
262 253 QCOMPARE(axis,m_chart->axisX());
263 254 }
264 255
265 256 void tst_QChart::axisY_data()
266 257 {
267 258 QTest::addColumn<QAbstractAxis*>("axis0");
268 259 QTest::addColumn<QAbstractAxis*>("axis1");
269 260 QTest::addColumn<QAbstractAxis*>("axis2");
270 261 QTest::newRow("1 defualt, 2 optional") << (QAbstractAxis*)0 << new QValuesAxis() << new QValuesAxis();
271 262 QTest::newRow("3 optional") << new QValuesAxis() << new QValuesAxis() << new QValuesAxis();
272 263 }
273 264
274 265
275 266 void tst_QChart::axisY()
276 267 {
277 268 QFETCH(QAbstractAxis*, axis0);
278 269 QFETCH(QAbstractAxis*, axis1);
279 270 QFETCH(QAbstractAxis*, axis2);
280 271
281 272 QAbstractAxis* defaultAxisY = m_chart->axisY();
282 273
283 274 QVERIFY2(defaultAxisY, "Missing axisY.");
284 275
285 276 QLineSeries* series0 = new QLineSeries();
286 277 m_chart->addSeries(series0);
287 278 m_chart->setAxisY(series0,axis0);
288 279
289 280 QLineSeries* series1 = new QLineSeries();
290 281 m_chart->addSeries(series1);
291 282 m_chart->setAxisY(series1,axis1);
292 283
293 284 QLineSeries* series2 = new QLineSeries();
294 285 m_chart->addSeries(series2);
295 286 m_chart->setAxisY(series2,axis2);
296 287
297 288 if (!axis0)
298 289 axis0 = defaultAxisY;
299 290 if (!axis1)
300 291 axis1 = defaultAxisY;
301 292 if (!axis2)
302 293 axis2 = defaultAxisY;
303 294
304 295 QVERIFY(m_chart->axisY(series0) == axis0);
305 296 QVERIFY(m_chart->axisY(series1) == axis1);
306 297 QVERIFY(m_chart->axisY(series2) == axis2);
307 298 }
308 299
309 300 void tst_QChart::backgroundBrush_data()
310 301 {
311 302 QTest::addColumn<QBrush>("backgroundBrush");
312 303 QTest::newRow("null") << QBrush();
313 304 QTest::newRow("blue") << QBrush(Qt::blue);
314 305 QTest::newRow("white") << QBrush(Qt::white);
315 306 QTest::newRow("black") << QBrush(Qt::black);
316 307 }
317 308
318 309 void tst_QChart::backgroundBrush()
319 310 {
320 311 QFETCH(QBrush, backgroundBrush);
321 312 m_chart->setBackgroundBrush(backgroundBrush);
322 313 QCOMPARE(m_chart->backgroundBrush(), backgroundBrush);
323 314 }
324 315
325 316 void tst_QChart::backgroundPen_data()
326 317 {
327 318 QTest::addColumn<QPen>("backgroundPen");
328 319 QTest::newRow("null") << QPen();
329 320 QTest::newRow("blue") << QPen(Qt::blue);
330 321 QTest::newRow("white") << QPen(Qt::white);
331 322 QTest::newRow("black") << QPen(Qt::black);
332 323 }
333 324
334 325
335 326 void tst_QChart::backgroundPen()
336 327 {
337 328 QFETCH(QPen, backgroundPen);
338 329 m_chart->setBackgroundPen(backgroundPen);
339 330 QCOMPARE(m_chart->backgroundPen(), backgroundPen);
340 331 }
341 332
342 333 void tst_QChart::isBackgroundVisible_data()
343 334 {
344 335 QTest::addColumn<bool>("isBackgroundVisible");
345 336 QTest::newRow("true") << true;
346 337 QTest::newRow("false") << false;
347 338 }
348 339
349 340 void tst_QChart::isBackgroundVisible()
350 341 {
351 342 QFETCH(bool, isBackgroundVisible);
352 343 m_chart->setBackgroundVisible(isBackgroundVisible);
353 344 QCOMPARE(m_chart->isBackgroundVisible(), isBackgroundVisible);
354 345 }
355 346
356 347 void tst_QChart::legend_data()
357 348 {
358 349
359 350 }
360 351
361 352 void tst_QChart::legend()
362 353 {
363 354 QLegend *legend = m_chart->legend();
364 355 QVERIFY(legend);
365 356
366 357 // Colors related signals
367 358 QSignalSpy colorSpy(legend, SIGNAL(colorChanged(QColor)));
368 359 QSignalSpy borderColorSpy(legend, SIGNAL(borderColorChanged(QColor)));
369 360 QSignalSpy labelColorSpy(legend, SIGNAL(labelColorChanged(QColor)));
370 361
371 362 // colorChanged
372 363 legend->setColor(QColor("aliceblue"));
373 364 QCOMPARE(colorSpy.count(), 1);
374 365 QBrush b = legend->brush();
375 366 b.setColor(QColor("aqua"));
376 367 legend->setBrush(b);
377 368 QCOMPARE(colorSpy.count(), 2);
378 369
379 370 // borderColorChanged
380 371 legend->setBorderColor(QColor("aliceblue"));
381 372 QCOMPARE(borderColorSpy.count(), 1);
382 373 QPen p = legend->pen();
383 374 p.setColor(QColor("aqua"));
384 375 legend->setPen(p);
385 376 QCOMPARE(borderColorSpy.count(), 2);
386 377
387 378 // labelColorChanged
388 379 legend->setLabelColor(QColor("lightsalmon"));
389 380 QCOMPARE(labelColorSpy.count(), 1);
390 381 b = legend->labelBrush();
391 382 b.setColor(QColor("lightseagreen"));
392 383 legend->setLabelBrush(b);
393 384 QCOMPARE(labelColorSpy.count(), 2);
394 385
395 386 // fontChanged
396 387 QSignalSpy fontSpy(legend, SIGNAL(fontChanged(QFont)));
397 388 QFont f = legend->font();
398 389 f.setBold(!f.bold());
399 390 legend->setFont(f);
400 391 QCOMPARE(fontSpy.count(), 1);
401 392 }
402 393
403 394 void tst_QChart::margins_data()
404 395 {
405 396
406 397 }
407 398
408 399 void tst_QChart::margins()
409 400 {
410 401 createTestData();
411 402 QRectF rect = m_chart->geometry();
412 403
413 404 QVERIFY(m_chart->margins().top()+m_chart->margins().bottom() < rect.height());
414 405 QVERIFY(m_chart->margins().left()+m_chart->margins().right() < rect.width());
415 406 }
416 407
417 408 void tst_QChart::removeAllSeries_data()
418 409 {
419 410
420 411 }
421 412
422 413 void tst_QChart::removeAllSeries()
423 414 {
424 415 QLineSeries* series0 = new QLineSeries(this);
425 416 QLineSeries* series1 = new QLineSeries(this);
426 417 QLineSeries* series2 = new QLineSeries(this);
427 418 QSignalSpy deleteSpy1(series0, SIGNAL(destroyed()));
428 419 QSignalSpy deleteSpy2(series1, SIGNAL(destroyed()));
429 420 QSignalSpy deleteSpy3(series2, SIGNAL(destroyed()));
430 421
431 422 m_chart->addSeries(series0);
432 423 m_chart->addSeries(series1);
433 424 m_chart->addSeries(series2);
434 425 m_view->show();
435 426 QTest::qWaitForWindowShown(m_view);
436 427
437 428 QVERIFY(m_chart->axisY(series0)!=0);
438 429 QVERIFY(m_chart->axisY(series1)!=0);
439 430 QVERIFY(m_chart->axisY(series2)!=0);
440 431
441 432 m_chart->removeAllSeries();
442 433 QVERIFY(m_chart->axisY(series0)==0);
443 434 QVERIFY(m_chart->axisY(series1)==0);
444 435 QVERIFY(m_chart->axisY(series2)==0);
445 436 QCOMPARE(deleteSpy1.count(), 1);
446 437 QCOMPARE(deleteSpy2.count(), 1);
447 438 QCOMPARE(deleteSpy3.count(), 1);
448 439 }
449 440
450 441 void tst_QChart::removeSeries_data()
451 442 {
452 443 addSeries_data();
453 444 }
454 445
455 446 void tst_QChart::removeSeries()
456 447 {
457 448 QFETCH(QAbstractSeries *, series);
458 449 QFETCH(QAbstractAxis *, axis);
459 450 QSignalSpy deleteSpy(series, SIGNAL(destroyed()));
460 451 m_view->show();
461 452 QTest::qWaitForWindowShown(m_view);
462 453 if(!axis) axis = m_chart->axisY();
463 454 m_chart->addSeries(series);
464 455 m_chart->setAxisY(series,axis);
465 456 QCOMPARE(m_chart->axisY(series),axis);
466 457 m_chart->removeSeries(series);
467 458 QVERIFY(m_chart->axisY(series)==0);
468 459 QCOMPARE(deleteSpy.count(), 0);
469 460 }
470 461
471 void tst_QChart::scrollDown_data()
462 void tst_QChart::scroll_data()
472 463 {
473 464
474 465 }
475 466
476 void tst_QChart::scrollDown()
467 void tst_QChart::scroll()
477 468 {
478 469 qFatal("implement me");
479 470 createTestData();
480 471 //TODO qreal min = m_chart->axisY()->min();
481 m_chart->scrollDown();
472 m_chart->scroll(0,0);
482 473 //TODO QVERIFY(m_chart->axisY()->min()<min);
483 474 }
484 475
485 void tst_QChart::scrollLeft_data()
486 {
487
488 }
489
490 void tst_QChart::scrollLeft()
491 {
492 qFatal("implement me");
493 createTestData();
494 //TODO qreal min = m_chart->axisX()->min();
495 m_chart->scrollLeft();
496 //TODO QVERIFY(m_chart->axisX()->min()<min);
497 }
498
499 void tst_QChart::scrollRight_data()
500 {
501
502 }
503
504 void tst_QChart::scrollRight()
505 {
506 qFatal("implement me");
507 createTestData();
508 //TODO qreal min = m_chart->axisX()->min();
509 m_chart->scrollRight();
510 //TODO QVERIFY(m_chart->axisX()->min()>min);
511 }
512
513 void tst_QChart::scrollUp_data()
514 {
515
516 }
517
518 void tst_QChart::scrollUp()
519 {
520 qFatal("implement me");
521 createTestData();
522 //TODO qreal min = m_chart->axisY()->min();
523 m_chart->scrollUp();
524 //TODO QVERIFY(m_chart->axisY()->min()>min);
525 }
526
527 476 void tst_QChart::theme_data()
528 477 {
529 478 QTest::addColumn<QChart::ChartTheme>("theme");
530 479 QTest::newRow("ChartThemeBlueCerulean") << QChart::ChartThemeBlueCerulean;
531 480 QTest::newRow("ChartThemeBlueIcy") << QChart::ChartThemeBlueIcy;
532 481 QTest::newRow("ChartThemeBlueNcs") << QChart::ChartThemeBlueNcs;
533 482 QTest::newRow("ChartThemeBrownSand") << QChart::ChartThemeBrownSand;
534 483 QTest::newRow("ChartThemeDark") << QChart::ChartThemeDark;
535 484 QTest::newRow("hartThemeHighContrast") << QChart::ChartThemeHighContrast;
536 485 QTest::newRow("ChartThemeLight") << QChart::ChartThemeLight;
537 486 }
538 487
539 488 void tst_QChart::theme()
540 489 {
541 490 QFETCH(QChart::ChartTheme, theme);
542 491 createTestData();
543 492 m_chart->setTheme(theme);
544 493 QVERIFY(m_chart->theme()==theme);
545 494 }
546 495
547 496 void tst_QChart::title_data()
548 497 {
549 498 QTest::addColumn<QString>("title");
550 499 QTest::newRow("null") << QString();
551 500 QTest::newRow("foo") << QString("foo");
552 501 }
553 502
554 503 void tst_QChart::title()
555 504 {
556 505 QFETCH(QString, title);
557 506 m_chart->setTitle(title);
558 507 QCOMPARE(m_chart->title(), title);
559 508 }
560 509
561 510 void tst_QChart::titleBrush_data()
562 511 {
563 512 QTest::addColumn<QBrush>("titleBrush");
564 513 QTest::newRow("null") << QBrush();
565 514 QTest::newRow("blue") << QBrush(Qt::blue);
566 515 QTest::newRow("white") << QBrush(Qt::white);
567 516 QTest::newRow("black") << QBrush(Qt::black);
568 517 }
569 518
570 519 void tst_QChart::titleBrush()
571 520 {
572 521 QFETCH(QBrush, titleBrush);
573 522 m_chart->setTitleBrush(titleBrush);
574 523 QCOMPARE(m_chart->titleBrush(), titleBrush);
575 524 }
576 525
577 526 void tst_QChart::titleFont_data()
578 527 {
579 528 QTest::addColumn<QFont>("titleFont");
580 529 QTest::newRow("null") << QFont();
581 530 QTest::newRow("courier") << QFont("Courier", 8, QFont::Bold, true);
582 531 }
583 532
584 533 void tst_QChart::titleFont()
585 534 {
586 535 QFETCH(QFont, titleFont);
587 536 m_chart->setTitleFont(titleFont);
588 537 QCOMPARE(m_chart->titleFont(), titleFont);
589 538 }
590 539
591 540 void tst_QChart::zoomIn_data()
592 541 {
593 542 QTest::addColumn<QRectF>("rect");
594 543 QTest::newRow("null") << QRectF();
595 544 QTest::newRow("100x100") << QRectF(10,10,100,100);
596 545 QTest::newRow("200x200") << QRectF(10,10,200,200);
597 546 }
598 547
599 548
600 549 void tst_QChart::zoomIn()
601 550 {
602 551 qFatal("implement me");
603 552 /*
604 553 QFETCH(QRectF, rect);
605 554 createTestData();
606 555 QRectF marigns = m_chart->margins();
607 556 rect.adjust(marigns.left(),marigns.top(),-marigns.right(),-marigns.bottom());
608 557 qreal minX = m_chart->axisX()->min();
609 558 qreal minY = m_chart->axisY()->min();
610 559 qreal maxX = m_chart->axisX()->max();
611 560 qreal maxY = m_chart->axisY()->max();
612 561 m_chart->zoomIn(rect);
613 562 if(rect.isValid()){
614 563 QVERIFY(minX<m_chart->axisX()->min());
615 564 QVERIFY(maxX>m_chart->axisX()->max());
616 565 QVERIFY(minY<m_chart->axisY()->min());
617 566 QVERIFY(maxY>m_chart->axisY()->max());
618 567 }
619 568 */
620 569 }
621 570
622 571 void tst_QChart::zoomOut_data()
623 572 {
624 573
625 574 }
626 575
627 576 void tst_QChart::zoomOut()
628 577 {
629 578 qFatal("implement me");
630 579 createTestData();
631 580 /*
632 581 qreal minX = m_chart->axisX()->min();
633 582 qreal minY = m_chart->axisY()->min();
634 583 qreal maxX = m_chart->axisX()->max();
635 584 qreal maxY = m_chart->axisY()->max();
636 585
637 586 m_chart->zoomIn();
638 587
639 588 QVERIFY(minX < m_chart->axisX()->min());
640 589 QVERIFY(maxX > m_chart->axisX()->max());
641 590 QVERIFY(minY < m_chart->axisY()->min());
642 591 QVERIFY(maxY > m_chart->axisY()->max());
643 592
644 593 m_chart->zoomOut();
645 594
646 595 // min x may be a zero value
647 596 if (qFuzzyIsNull(minX))
648 597 QVERIFY(qFuzzyIsNull(m_chart->axisX()->min()));
649 598 else
650 599 QCOMPARE(minX, m_chart->axisX()->min());
651 600
652 601 // min y may be a zero value
653 602 if (qFuzzyIsNull(minY))
654 603 QVERIFY(qFuzzyIsNull(m_chart->axisY()->min()));
655 604 else
656 605 QCOMPARE(minY, m_chart->axisY()->min());
657 606
658 607 QVERIFY(maxX == m_chart->axisX()->max());
659 608 QVERIFY(maxY == m_chart->axisY()->max());
660 609 */
661 610 }
662 611
663 612 QTEST_MAIN(tst_QChart)
664 613 #include "tst_qchart.moc"
665 614
General Comments 0
You need to be logged in to leave comments. Login now