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