##// END OF EJS Templates
Documenting xy-series
Tero Ahola -
r1491:abdb70920d73
parent child
Show More
@@ -1,76 +1,71
1 /*!
1 /*!
2 \page qml.html
2 \page qml.html
3 \title QtCommercial Charts QML API
3 \title QtCommercial Charts QML API
4 \keyword Charts QML API
4 \keyword Charts QML API
5
5
6 QtCommercial Charts QML API is an intuitive and simple way to show charts in your QML
6 QtCommercial Charts QML API is an intuitive and simple way to show charts in your QML
7 applications. The following QML shows you to create a simple pie chart:
7 applications. The following QML shows you to create a simple pie chart:
8 \snippet ../examples/qmlpiechart/qml/qmlpiechart/main.qml 1
8 \snippet ../examples/qmlpiechart/qml/qmlpiechart/main.qml 1
9 \snippet ../examples/qmlpiechart/qml/qmlpiechart/main.qml 2
9 \snippet ../examples/qmlpiechart/qml/qmlpiechart/main.qml 2
10 \snippet ../examples/qmlpiechart/qml/qmlpiechart/main.qml 3
10 \snippet ../examples/qmlpiechart/qml/qmlpiechart/main.qml 3
11
11
12 \beginfloatleft
13 \image examples_qmlpiechart.png
14 \endfloat
15 \clearfloat
16
17 \raw HTML
12 \raw HTML
18 <table cellpadding="2" cellspacing="1" border="0" width="95%" class="indextable">
13 <table cellpadding="2" cellspacing="1" border="0" width="95%" class="indextable">
19 <tr>
14 <tr>
20 <th class="titleheader" width="25%"> ChartView and it's properties </th>
15 <th class="titleheader" width="25%"> ChartView and it's properties </th>
21 </tr>
16 </tr>
22 <tr>
17 <tr>
23 <td valign="top">
18 <td valign="top">
24 <ul>
19 <ul>
25 <li><a href="qml-chartview.html">ChartView</a></li>
20 <li><a href="qml-chartview.html">ChartView</a></li>
26 <li><a href="qml-axis.html">Axis</a></li>
21 <li><a href="qml-axis.html">Axis</a></li>
27 <li><a href="qml-legend.html">Legend</a></li>
22 <li><a href="qml-legend.html">Legend</a></li>
28 </ul>
23 </ul>
29 </td>
24 </td>
30 </tr>
25 </tr>
31 </table>
26 </table>
32 <table cellpadding="2" cellspacing="1" border="0" width="95%" class="indextable">
27 <table cellpadding="2" cellspacing="1" border="0" width="95%" class="indextable">
33 <tr>
28 <tr>
34 <th class="titleheader" width="25%"> XY chart </th>
29 <th class="titleheader" width="25%"> XY chart </th>
35 </tr>
30 </tr>
36 <tr>
31 <tr>
37 <td valign="top">
32 <td valign="top">
38 <ul>
33 <ul>
39 <li><a href="qml-lineseries.html">LineSeries</a></li>
34 <li><a href="qml-lineseries.html">LineSeries</a></li>
40 <li><a href="qml-areaseries.html">AreaSeries</a></li>
35 <li><a href="qml-areaseries.html">AreaSeries</a></li>
41 <li><a href="qml-scatterseries.html">ScatterSeries</a></li>
36 <li><a href="qml-scatterseries.html">ScatterSeries</a></li>
42 <li><a href="qml-splineseries.html">SplineSeries</a></li>
37 <li><a href="qml-splineseries.html">SplineSeries</a></li>
43 <li><a href="qml-xypoint.html">XyPoint</a></li>
38 <li><a href="qml-xypoint.html">XyPoint</a></li>
44 </ul>
39 </ul>
45 </td>
40 </td>
46 </tr>
41 </tr>
47 </table>
42 </table>
48 <table cellpadding="2" cellspacing="1" border="0" width="95%" class="indextable">
43 <table cellpadding="2" cellspacing="1" border="0" width="95%" class="indextable">
49 <tr>
44 <tr>
50 <th class="titleheader" width="25%"> Pie chart </th>
45 <th class="titleheader" width="25%"> Pie chart </th>
51 <tr>
46 <tr>
52 <td valign="top">
47 <td valign="top">
53 <ul>
48 <ul>
54 <li><a href="qml-pieseries.html">PieSeries</a></li>
49 <li><a href="qml-pieseries.html">PieSeries</a></li>
55 <li><a href="qml-pieslice.html">PieSlice</a></li>
50 <li><a href="qml-pieslice.html">PieSlice</a></li>
56 </ul>
51 </ul>
57 </td>
52 </td>
58 </tr>
53 </tr>
59 </table>
54 </table>
60 <table cellpadding="2" cellspacing="1" border="0" width="95%" class="indextable">
55 <table cellpadding="2" cellspacing="1" border="0" width="95%" class="indextable">
61 <tr>
56 <tr>
62 <th class="titleheader" width="25%"> Bar chart </th>
57 <th class="titleheader" width="25%"> Bar chart </th>
63 <tr>
58 <tr>
64 <td valign="top">
59 <td valign="top">
65 <ul>
60 <ul>
66 <li><a href="qml-barseries.html">BarSeries</a></li>
61 <li><a href="qml-barseries.html">BarSeries</a></li>
67 <li><a href="qml-groupedbarseries.html">GroupedBarSeries</a></li>
62 <li><a href="qml-groupedbarseries.html">GroupedBarSeries</a></li>
68 <li><a href="qml-stackedbarseries.html">StackedBarSeries</a></li>
63 <li><a href="qml-stackedbarseries.html">StackedBarSeries</a></li>
69 <li><a href="qml-percentbarseries.html">PercentBarSeries</a></li>
64 <li><a href="qml-percentbarseries.html">PercentBarSeries</a></li>
70 <li><a href="qml-barset.html">BarSet</a></li>
65 <li><a href="qml-barset.html">BarSet</a></li>
71 </ul>
66 </ul>
72 </td>
67 </td>
73 </tr>
68 </tr>
74 </table>
69 </table>
75 \endraw
70 \endraw
76 */
71 */
@@ -1,69 +1,55
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 "declarativeareaseries.h"
21 #include "declarativeareaseries.h"
22 #include "declarativechart.h"
22 #include "declarativechart.h"
23 #include "qchart.h"
23 #include "qchart.h"
24 #include "qxymodelmapper.h"
24 #include "qxymodelmapper.h"
25
25
26 QTCOMMERCIALCHART_BEGIN_NAMESPACE
26 QTCOMMERCIALCHART_BEGIN_NAMESPACE
27
27
28 /*!
29 \qmlclass AreaSeries QAreaSeries
30
31 \section1 Example Usage
32
33 \beginfloatleft
34 \image demos_qmlchart4.png
35 \endfloat
36 \clearfloat
37
38 The following QML shows how to create a simple area chart:
39 \snippet ../demos/qmlchart/qml/qmlchart/View4.qml 1
40 */
41
42 DeclarativeAreaSeries::DeclarativeAreaSeries(QObject *parent) :
28 DeclarativeAreaSeries::DeclarativeAreaSeries(QObject *parent) :
43 QAreaSeries(parent)
29 QAreaSeries(parent)
44 {
30 {
45 }
31 }
46
32
47 void DeclarativeAreaSeries::setUpperSeries(DeclarativeLineSeries* series)
33 void DeclarativeAreaSeries::setUpperSeries(DeclarativeLineSeries* series)
48 {
34 {
49 QAreaSeries::setUpperSeries(series);
35 QAreaSeries::setUpperSeries(series);
50 }
36 }
51
37
52 DeclarativeLineSeries* DeclarativeAreaSeries::upperSeries() const
38 DeclarativeLineSeries* DeclarativeAreaSeries::upperSeries() const
53 {
39 {
54 return qobject_cast<DeclarativeLineSeries *>(QAreaSeries::upperSeries());
40 return qobject_cast<DeclarativeLineSeries *>(QAreaSeries::upperSeries());
55 }
41 }
56
42
57 void DeclarativeAreaSeries::setLowerSeries(DeclarativeLineSeries* series)
43 void DeclarativeAreaSeries::setLowerSeries(DeclarativeLineSeries* series)
58 {
44 {
59 QAreaSeries::setLowerSeries(series);
45 QAreaSeries::setLowerSeries(series);
60 }
46 }
61
47
62 DeclarativeLineSeries* DeclarativeAreaSeries::lowerSeries() const
48 DeclarativeLineSeries* DeclarativeAreaSeries::lowerSeries() const
63 {
49 {
64 return qobject_cast<DeclarativeLineSeries *>(QAreaSeries::lowerSeries());
50 return qobject_cast<DeclarativeLineSeries *>(QAreaSeries::lowerSeries());
65 }
51 }
66
52
67 #include "moc_declarativeareaseries.cpp"
53 #include "moc_declarativeareaseries.cpp"
68
54
69 QTCOMMERCIALCHART_END_NAMESPACE
55 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,373 +1,375
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
29
30 QTCOMMERCIALCHART_BEGIN_NAMESPACE
30 QTCOMMERCIALCHART_BEGIN_NAMESPACE
31
31
32 /*!
32 /*!
33 \qmlclass ChartView DeclarativeChart
33 \qmlclass ChartView DeclarativeChart
34
34
35 ChartView element is the parent that is responsible for showing different chart series types.
35 ChartView element is the parent that is responsible for showing different chart series types.
36
36
37 The following QML shows how to create a simple line chart:
37 The following QML shows how to create a simple chart with one pie series:
38 \snippet ../demos/qmlchart/qml/qmlchart/View2.qml 1
38 \snippet ../examples/qmlpiechart/qml/qmlpiechart/main.qml 1
39 \snippet ../examples/qmlpiechart/qml/qmlpiechart/main.qml 2
40 \snippet ../examples/qmlpiechart/qml/qmlpiechart/main.qml 3
39
41
40 \beginfloatleft
42 \beginfloatleft
41 \image demos_qmlchart2.png
43 \image examples_qmlpiechart.png
42 \endfloat
44 \endfloat
43 \clearfloat
45 \clearfloat
44 */
46 */
45
47
46 /*!
48 /*!
47 \qmlproperty Theme ChartView::theme
49 \qmlproperty Theme ChartView::theme
48 Theme defines the visual appearance of the chart, including for example colors, fonts, line
50 Theme defines the visual appearance of the chart, including for example colors, fonts, line
49 widths and chart background.
51 widths and chart background.
50 */
52 */
51
53
52 /*!
54 /*!
53 \qmlproperty Animation ChartView::animation
55 \qmlproperty Animation ChartView::animation
54 Animation configuration of the chart. One of ChartView.NoAnimation, ChartView.GridAxisAnimations,
56 Animation configuration of the chart. One of ChartView.NoAnimation, ChartView.GridAxisAnimations,
55 ChartView.SeriesAnimations or ChartView.AllAnimations.
57 ChartView.SeriesAnimations or ChartView.AllAnimations.
56 */
58 */
57
59
58 /*!
60 /*!
59 \qmlproperty string ChartView::title
61 \qmlproperty string ChartView::title
60 The title of the chart, shown on top of the chart.
62 The title of the chart, shown on top of the chart.
61 \sa ChartView::titleColor
63 \sa ChartView::titleColor
62 */
64 */
63
65
64 /*!
66 /*!
65 \qmlproperty string ChartView::titleColor
67 \qmlproperty string ChartView::titleColor
66 The color of the title text.
68 The color of the title text.
67 */
69 */
68
70
69 /*!
71 /*!
70 \qmlproperty Axis ChartView::axisX
72 \qmlproperty Axis ChartView::axisX
71 The x-axis of the chart.
73 The x-axis of the chart.
72 */
74 */
73
75
74 /*!
76 /*!
75 \qmlproperty Axis ChartView::axisY
77 \qmlproperty Axis ChartView::axisY
76 The default y-axis of the chart.
78 The default y-axis of the chart.
77 */
79 */
78
80
79 /*!
81 /*!
80 \qmlproperty Legend ChartView::legend
82 \qmlproperty Legend ChartView::legend
81 The legend of the chart. Legend lists all the series, pie slices and bar sets added on the chart.
83 The legend of the chart. Legend lists all the series, pie slices and bar sets added on the chart.
82 */
84 */
83
85
84 /*!
86 /*!
85 \qmlproperty int ChartView::count
87 \qmlproperty int ChartView::count
86 The count of series added to the chart.
88 The count of series added to the chart.
87 */
89 */
88
90
89 /*!
91 /*!
90 \qmlproperty color ChartView::backgroundColor
92 \qmlproperty color ChartView::backgroundColor
91 The color of the chart's background. By default background color is defined by chart theme.
93 The color of the chart's background. By default background color is defined by chart theme.
92 \sa ChartView::theme
94 \sa ChartView::theme
93 */
95 */
94
96
95 /*!
97 /*!
96 \qmlproperty bool ChartView::dropShadowEnabled
98 \qmlproperty bool ChartView::dropShadowEnabled
97 The chart's border drop shadow. Set to true to enable drop shadow.
99 The chart's border drop shadow. Set to true to enable drop shadow.
98 */
100 */
99
101
100 /*!
102 /*!
101 \qmlmethod Axis ChartView::axisY(QAbstractSeries *series)
103 \qmlmethod Axis ChartView::axisY(QAbstractSeries *series)
102 The y-axis of the series. This is the same as the default y-axis of the chart, unless you have
104 The y-axis of the series. This is the same as the default y-axis of the chart, unless you have
103 explicitly defined the series to have a non-default y-axis.
105 explicitly defined the series to have a non-default y-axis.
104 */
106 */
105
107
106 DeclarativeChart::DeclarativeChart(QDeclarativeItem *parent)
108 DeclarativeChart::DeclarativeChart(QDeclarativeItem *parent)
107 : QDeclarativeItem(parent),
109 : QDeclarativeItem(parent),
108 m_chart(new QChart(this))
110 m_chart(new QChart(this))
109 {
111 {
110 setFlag(QGraphicsItem::ItemHasNoContents, false);
112 setFlag(QGraphicsItem::ItemHasNoContents, false);
111 // m_chart->axisX()->setNiceNumbersEnabled(false);
113 // m_chart->axisX()->setNiceNumbersEnabled(false);
112 }
114 }
113
115
114 DeclarativeChart::~DeclarativeChart()
116 DeclarativeChart::~DeclarativeChart()
115 {
117 {
116 delete m_chart;
118 delete m_chart;
117 }
119 }
118
120
119 void DeclarativeChart::childEvent(QChildEvent *event)
121 void DeclarativeChart::childEvent(QChildEvent *event)
120 {
122 {
121 if (event->type() == QEvent::ChildAdded) {
123 if (event->type() == QEvent::ChildAdded) {
122 if (qobject_cast<QAbstractSeries *>(event->child())) {
124 if (qobject_cast<QAbstractSeries *>(event->child())) {
123 m_chart->addSeries(qobject_cast<QAbstractSeries *>(event->child()));
125 m_chart->addSeries(qobject_cast<QAbstractSeries *>(event->child()));
124 }
126 }
125 }
127 }
126 }
128 }
127
129
128 void DeclarativeChart::componentComplete()
130 void DeclarativeChart::componentComplete()
129 {
131 {
130 foreach(QObject *child, children()) {
132 foreach(QObject *child, children()) {
131 if (qobject_cast<QAbstractSeries *>(child)) {
133 if (qobject_cast<QAbstractSeries *>(child)) {
132 // qDebug() << "DeclarativeChart::componentComplete(), add: " << child;
134 // qDebug() << "DeclarativeChart::componentComplete(), add: " << child;
133 // TODO: how about optional y-axis?
135 // TODO: how about optional y-axis?
134 m_chart->addSeries(qobject_cast<QAbstractSeries *>(child));
136 m_chart->addSeries(qobject_cast<QAbstractSeries *>(child));
135 }
137 }
136 }
138 }
137 QDeclarativeItem::componentComplete();
139 QDeclarativeItem::componentComplete();
138 }
140 }
139
141
140 void DeclarativeChart::geometryChanged(const QRectF &newGeometry, const QRectF &oldGeometry)
142 void DeclarativeChart::geometryChanged(const QRectF &newGeometry, const QRectF &oldGeometry)
141 {
143 {
142 // qDebug() << "DeclarativeChart::geometryChanged" << newGeometry.width() << newGeometry.height();
144 // qDebug() << "DeclarativeChart::geometryChanged" << newGeometry.width() << newGeometry.height();
143 if (newGeometry.isValid()) {
145 if (newGeometry.isValid()) {
144 if (newGeometry.width() > 0 && newGeometry.height() > 0) {
146 if (newGeometry.width() > 0 && newGeometry.height() > 0) {
145 m_chart->resize(newGeometry.width(), newGeometry.height());
147 m_chart->resize(newGeometry.width(), newGeometry.height());
146 }
148 }
147 }
149 }
148 QDeclarativeItem::geometryChanged(newGeometry, oldGeometry);
150 QDeclarativeItem::geometryChanged(newGeometry, oldGeometry);
149 }
151 }
150
152
151 void DeclarativeChart::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
153 void DeclarativeChart::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
152 {
154 {
153 Q_UNUSED(option)
155 Q_UNUSED(option)
154 Q_UNUSED(widget)
156 Q_UNUSED(widget)
155
157
156 // TODO: optimized?
158 // TODO: optimized?
157 painter->setRenderHint(QPainter::Antialiasing, true);
159 painter->setRenderHint(QPainter::Antialiasing, true);
158 }
160 }
159
161
160 void DeclarativeChart::setTheme(DeclarativeChart::Theme theme)
162 void DeclarativeChart::setTheme(DeclarativeChart::Theme theme)
161 {
163 {
162 QChart::ChartTheme chartTheme = (QChart::ChartTheme) theme;
164 QChart::ChartTheme chartTheme = (QChart::ChartTheme) theme;
163 if (chartTheme != m_chart->theme())
165 if (chartTheme != m_chart->theme())
164 m_chart->setTheme(chartTheme);
166 m_chart->setTheme(chartTheme);
165 }
167 }
166
168
167 DeclarativeChart::Theme DeclarativeChart::theme()
169 DeclarativeChart::Theme DeclarativeChart::theme()
168 {
170 {
169 return (DeclarativeChart::Theme) m_chart->theme();
171 return (DeclarativeChart::Theme) m_chart->theme();
170 }
172 }
171
173
172 void DeclarativeChart::setAnimationOptions(DeclarativeChart::Animation animations)
174 void DeclarativeChart::setAnimationOptions(DeclarativeChart::Animation animations)
173 {
175 {
174 QChart::AnimationOption animationOptions = (QChart::AnimationOption) animations;
176 QChart::AnimationOption animationOptions = (QChart::AnimationOption) animations;
175 if (animationOptions != m_chart->animationOptions())
177 if (animationOptions != m_chart->animationOptions())
176 m_chart->setAnimationOptions(animationOptions);
178 m_chart->setAnimationOptions(animationOptions);
177 }
179 }
178
180
179 DeclarativeChart::Animation DeclarativeChart::animationOptions()
181 DeclarativeChart::Animation DeclarativeChart::animationOptions()
180 {
182 {
181 if (m_chart->animationOptions().testFlag(QChart::AllAnimations))
183 if (m_chart->animationOptions().testFlag(QChart::AllAnimations))
182 return DeclarativeChart::AllAnimations;
184 return DeclarativeChart::AllAnimations;
183 else if (m_chart->animationOptions().testFlag(QChart::GridAxisAnimations))
185 else if (m_chart->animationOptions().testFlag(QChart::GridAxisAnimations))
184 return DeclarativeChart::GridAxisAnimations;
186 return DeclarativeChart::GridAxisAnimations;
185 else if (m_chart->animationOptions().testFlag(QChart::SeriesAnimations))
187 else if (m_chart->animationOptions().testFlag(QChart::SeriesAnimations))
186 return DeclarativeChart::SeriesAnimations;
188 return DeclarativeChart::SeriesAnimations;
187 else
189 else
188 return DeclarativeChart::NoAnimation;
190 return DeclarativeChart::NoAnimation;
189 }
191 }
190
192
191 void DeclarativeChart::setTitle(QString title)
193 void DeclarativeChart::setTitle(QString title)
192 {
194 {
193 if (title != m_chart->title())
195 if (title != m_chart->title())
194 m_chart->setTitle(title);
196 m_chart->setTitle(title);
195 }
197 }
196 QString DeclarativeChart::title()
198 QString DeclarativeChart::title()
197 {
199 {
198 return m_chart->title();
200 return m_chart->title();
199 }
201 }
200
202
201 QAxis *DeclarativeChart::axisX()
203 QAxis *DeclarativeChart::axisX()
202 {
204 {
203 return m_chart->axisX();
205 return m_chart->axisX();
204 }
206 }
205
207
206 QAxis *DeclarativeChart::axisY(QAbstractSeries *series)
208 QAxis *DeclarativeChart::axisY(QAbstractSeries *series)
207 {
209 {
208 return m_chart->axisY(series);
210 return m_chart->axisY(series);
209 }
211 }
210
212
211 QLegend *DeclarativeChart::legend()
213 QLegend *DeclarativeChart::legend()
212 {
214 {
213 return m_chart->legend();
215 return m_chart->legend();
214 }
216 }
215
217
216 QVariantList DeclarativeChart::axisXLabels()
218 QVariantList DeclarativeChart::axisXLabels()
217 {
219 {
218 QVariantList labels;
220 QVariantList labels;
219 foreach (qreal value, m_chart->axisX()->categories()->values()) {
221 foreach (qreal value, m_chart->axisX()->categories()->values()) {
220 labels.append(value);
222 labels.append(value);
221 labels.append(m_chart->axisX()->categories()->label(value));
223 labels.append(m_chart->axisX()->categories()->label(value));
222 }
224 }
223 return labels;
225 return labels;
224 }
226 }
225
227
226 void DeclarativeChart::setAxisXLabels(QVariantList list)
228 void DeclarativeChart::setAxisXLabels(QVariantList list)
227 {
229 {
228 QVariant value(QVariant::Invalid);
230 QVariant value(QVariant::Invalid);
229 foreach (QVariant element, list) {
231 foreach (QVariant element, list) {
230 if (value.isValid() && element.type() == QVariant::String) {
232 if (value.isValid() && element.type() == QVariant::String) {
231 m_chart->axisX()->categories()->insert(value.toDouble(), element.toString());
233 m_chart->axisX()->categories()->insert(value.toDouble(), element.toString());
232 value = QVariant(QVariant::Invalid);
234 value = QVariant(QVariant::Invalid);
233 } else {
235 } else {
234 if (element.canConvert(QVariant::Double))
236 if (element.canConvert(QVariant::Double))
235 value = element;
237 value = element;
236 }
238 }
237 }
239 }
238 emit axisLabelsChanged();
240 emit axisLabelsChanged();
239 }
241 }
240
242
241 void DeclarativeChart::setTitleColor(QColor color)
243 void DeclarativeChart::setTitleColor(QColor color)
242 {
244 {
243 QBrush b = m_chart->titleBrush();
245 QBrush b = m_chart->titleBrush();
244 if (color != b.color()) {
246 if (color != b.color()) {
245 b.setColor(color);
247 b.setColor(color);
246 m_chart->setTitleBrush(b);
248 m_chart->setTitleBrush(b);
247 emit titleColorChanged();
249 emit titleColorChanged();
248 }
250 }
249 }
251 }
250
252
251 QColor DeclarativeChart::titleColor()
253 QColor DeclarativeChart::titleColor()
252 {
254 {
253 return m_chart->titleBrush().color();
255 return m_chart->titleBrush().color();
254 }
256 }
255
257
256 void DeclarativeChart::setBackgroundColor(QColor color)
258 void DeclarativeChart::setBackgroundColor(QColor color)
257 {
259 {
258 QBrush b = m_chart->backgroundBrush();
260 QBrush b = m_chart->backgroundBrush();
259 if (b.style() != Qt::SolidPattern || color != b.color()) {
261 if (b.style() != Qt::SolidPattern || color != b.color()) {
260 b.setStyle(Qt::SolidPattern);
262 b.setStyle(Qt::SolidPattern);
261 b.setColor(color);
263 b.setColor(color);
262 m_chart->setBackgroundBrush(b);
264 m_chart->setBackgroundBrush(b);
263 emit backgroundColorChanged();
265 emit backgroundColorChanged();
264 }
266 }
265 }
267 }
266
268
267 QColor DeclarativeChart::backgroundColor()
269 QColor DeclarativeChart::backgroundColor()
268 {
270 {
269 return m_chart->backgroundBrush().color();
271 return m_chart->backgroundBrush().color();
270 }
272 }
271
273
272 int DeclarativeChart::count()
274 int DeclarativeChart::count()
273 {
275 {
274 return m_chart->series().count();
276 return m_chart->series().count();
275 }
277 }
276
278
277 void DeclarativeChart::setDropShadowEnabled(bool enabled)
279 void DeclarativeChart::setDropShadowEnabled(bool enabled)
278 {
280 {
279 if (enabled != m_chart->isDropShadowEnabled()) {
281 if (enabled != m_chart->isDropShadowEnabled()) {
280 m_chart->setDropShadowEnabled(enabled);
282 m_chart->setDropShadowEnabled(enabled);
281 dropShadowEnabledChanged(enabled);
283 dropShadowEnabledChanged(enabled);
282 }
284 }
283 }
285 }
284
286
285 bool DeclarativeChart::dropShadowEnabled()
287 bool DeclarativeChart::dropShadowEnabled()
286 {
288 {
287 return m_chart->isDropShadowEnabled();
289 return m_chart->isDropShadowEnabled();
288 }
290 }
289
291
290 void DeclarativeChart::zoom(qreal factor)
292 void DeclarativeChart::zoom(qreal factor)
291 {
293 {
292 m_chart->zoom(factor);
294 m_chart->zoom(factor);
293 }
295 }
294
296
295 void DeclarativeChart::scrollLeft(qreal pixels)
297 void DeclarativeChart::scrollLeft(qreal pixels)
296 {
298 {
297 m_chart->scroll(QPointF(pixels, 0));
299 m_chart->scroll(QPointF(pixels, 0));
298 }
300 }
299
301
300 void DeclarativeChart::scrollRight(qreal pixels)
302 void DeclarativeChart::scrollRight(qreal pixels)
301 {
303 {
302 m_chart->scroll(QPointF(-pixels, 0));
304 m_chart->scroll(QPointF(-pixels, 0));
303 }
305 }
304
306
305 void DeclarativeChart::scrollUp(qreal pixels)
307 void DeclarativeChart::scrollUp(qreal pixels)
306 {
308 {
307 m_chart->scroll(QPointF(0, pixels));
309 m_chart->scroll(QPointF(0, pixels));
308 }
310 }
309
311
310 void DeclarativeChart::scrollDown(qreal pixels)
312 void DeclarativeChart::scrollDown(qreal pixels)
311 {
313 {
312 m_chart->scroll(QPointF(0, -pixels));
314 m_chart->scroll(QPointF(0, -pixels));
313 }
315 }
314
316
315 QAbstractSeries *DeclarativeChart::series(int index)
317 QAbstractSeries *DeclarativeChart::series(int index)
316 {
318 {
317 if (index < m_chart->series().count()) {
319 if (index < m_chart->series().count()) {
318 return m_chart->series().at(index);
320 return m_chart->series().at(index);
319 }
321 }
320 return 0;
322 return 0;
321 }
323 }
322
324
323 QAbstractSeries *DeclarativeChart::series(QString seriesName)
325 QAbstractSeries *DeclarativeChart::series(QString seriesName)
324 {
326 {
325 foreach(QAbstractSeries *series, m_chart->series()) {
327 foreach(QAbstractSeries *series, m_chart->series()) {
326 if (series->name() == seriesName)
328 if (series->name() == seriesName)
327 return series;
329 return series;
328 }
330 }
329 return 0;
331 return 0;
330 }
332 }
331
333
332 QAbstractSeries *DeclarativeChart::createSeries(DeclarativeChart::SeriesType type, QString name)
334 QAbstractSeries *DeclarativeChart::createSeries(DeclarativeChart::SeriesType type, QString name)
333 {
335 {
334 QAbstractSeries *series = 0;
336 QAbstractSeries *series = 0;
335 switch (type) {
337 switch (type) {
336 case DeclarativeChart::SeriesTypeLine:
338 case DeclarativeChart::SeriesTypeLine:
337 series = new DeclarativeLineSeries();
339 series = new DeclarativeLineSeries();
338 break;
340 break;
339 case DeclarativeChart::SeriesTypeArea:
341 case DeclarativeChart::SeriesTypeArea:
340 series = new DeclarativeAreaSeries();
342 series = new DeclarativeAreaSeries();
341 break;
343 break;
342 case DeclarativeChart::SeriesTypeBar:
344 case DeclarativeChart::SeriesTypeBar:
343 series = new DeclarativeBarSeries();
345 series = new DeclarativeBarSeries();
344 break;
346 break;
345 case DeclarativeChart::SeriesTypeStackedBar:
347 case DeclarativeChart::SeriesTypeStackedBar:
346 // TODO
348 // TODO
347 break;
349 break;
348 case DeclarativeChart::SeriesTypePercentBar:
350 case DeclarativeChart::SeriesTypePercentBar:
349 // TODO
351 // TODO
350 break;
352 break;
351 case DeclarativeChart::SeriesTypeGroupedBar:
353 case DeclarativeChart::SeriesTypeGroupedBar:
352 series = new DeclarativeGroupedBarSeries();
354 series = new DeclarativeGroupedBarSeries();
353 break;
355 break;
354 case DeclarativeChart::SeriesTypePie:
356 case DeclarativeChart::SeriesTypePie:
355 series = new DeclarativePieSeries();
357 series = new DeclarativePieSeries();
356 break;
358 break;
357 case DeclarativeChart::SeriesTypeScatter:
359 case DeclarativeChart::SeriesTypeScatter:
358 series = new DeclarativeScatterSeries();
360 series = new DeclarativeScatterSeries();
359 break;
361 break;
360 case DeclarativeChart::SeriesTypeSpline:
362 case DeclarativeChart::SeriesTypeSpline:
361 series = new DeclarativeSplineSeries();
363 series = new DeclarativeSplineSeries();
362 break;
364 break;
363 default:
365 default:
364 qWarning() << "Illegal series type";
366 qWarning() << "Illegal series type";
365 }
367 }
366 series->setName(name);
368 series->setName(name);
367 m_chart->addSeries(series);
369 m_chart->addSeries(series);
368 return series;
370 return series;
369 }
371 }
370
372
371 #include "moc_declarativechart.cpp"
373 #include "moc_declarativechart.cpp"
372
374
373 QTCOMMERCIALCHART_END_NAMESPACE
375 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,72 +1,60
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 "declarativelineseries.h"
21 #include "declarativelineseries.h"
22 #include "declarativechart.h"
22 #include "declarativechart.h"
23 #include "qchart.h"
23 #include "qchart.h"
24 #include "qlineseries.h"
24 #include "qlineseries.h"
25
25
26 QTCOMMERCIALCHART_BEGIN_NAMESPACE
26 QTCOMMERCIALCHART_BEGIN_NAMESPACE
27
27
28 /*!
29 \qmlclass LineSeries QLineSeries
30
31 \beginfloatleft
32 \image demos_qmlchart2.png
33 \endfloat
34 \clearfloat
35
36 The following QML shows how to create a simple line chart:
37 \snippet ../demos/qmlchart/qml/qmlchart/View2.qml 1
38 */
39
40 DeclarativeLineSeries::DeclarativeLineSeries(QObject *parent) :
28 DeclarativeLineSeries::DeclarativeLineSeries(QObject *parent) :
41 QLineSeries(parent)
29 QLineSeries(parent)
42 {
30 {
43 connect(this, SIGNAL(pointAdded(int)), this, SLOT(handleCountChanged(int)));
31 connect(this, SIGNAL(pointAdded(int)), this, SLOT(handleCountChanged(int)));
44 connect(this, SIGNAL(pointRemoved(int)), this, SLOT(handleCountChanged(int)));
32 connect(this, SIGNAL(pointRemoved(int)), this, SLOT(handleCountChanged(int)));
45 }
33 }
46
34
47 QXYSeries *DeclarativeLineSeries::xySeries()
35 QXYSeries *DeclarativeLineSeries::xySeries()
48 {
36 {
49 return this;
37 return this;
50 }
38 }
51
39
52 void DeclarativeLineSeries::handleCountChanged(int index)
40 void DeclarativeLineSeries::handleCountChanged(int index)
53 {
41 {
54 Q_UNUSED(index)
42 Q_UNUSED(index)
55 emit countChanged(points().count());
43 emit countChanged(points().count());
56 }
44 }
57
45
58 QDeclarativeListProperty<QObject> DeclarativeLineSeries::declarativeChildren()
46 QDeclarativeListProperty<QObject> DeclarativeLineSeries::declarativeChildren()
59 {
47 {
60 return QDeclarativeListProperty<QObject>(this, 0, &appendDeclarativeChildren);
48 return QDeclarativeListProperty<QObject>(this, 0, &appendDeclarativeChildren);
61 }
49 }
62
50
63 void DeclarativeLineSeries::appendDeclarativeChildren(QDeclarativeListProperty<QObject> *list, QObject *element)
51 void DeclarativeLineSeries::appendDeclarativeChildren(QDeclarativeListProperty<QObject> *list, QObject *element)
64 {
52 {
65 Q_UNUSED(list)
53 Q_UNUSED(list)
66 Q_UNUSED(element)
54 Q_UNUSED(element)
67 // Empty implementation, childs are parsed in componentComplete
55 // Empty implementation, childs are parsed in componentComplete
68 }
56 }
69
57
70 #include "moc_declarativelineseries.cpp"
58 #include "moc_declarativelineseries.cpp"
71
59
72 QTCOMMERCIALCHART_END_NAMESPACE
60 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,143 +1,96
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 "declarativepieseries.h"
21 #include "declarativepieseries.h"
22 #include "declarativechart.h"
22 #include "declarativechart.h"
23 #include "qchart.h"
23 #include "qchart.h"
24 #include <qdeclarativelist.h>
24 #include <qdeclarativelist.h>
25 #include <QVPieModelMapper>
25 #include <QVPieModelMapper>
26 #include <QHPieModelMapper>
26 #include <QHPieModelMapper>
27
27
28 QTCOMMERCIALCHART_BEGIN_NAMESPACE
28 QTCOMMERCIALCHART_BEGIN_NAMESPACE
29
29
30 /*!
31 \qmlclass PieSeries QPieSeries
32
33 \section1 Example Usage
34
35 \beginfloatleft
36 \image demos_qmlchart1.png
37 \endfloat
38 \clearfloat
39
40 The following QML shows how to create a simple pie chart.
41
42 \snippet ../demos/qmlchart/qml/qmlchart/View1.qml 1
43 */
44
45 /*!
46 \qmlproperty real PieSeries::horizontalPosition
47 \brief Defines the horizontal position of the pie.
48
49 The value is a relative value to the chart rectangle where:
50
51 \list
52 \o 0.0 is the absolute left.
53 \o 1.0 is the absolute right.
54 \endlist
55
56 Default value is 0.5 (center).
57
58 \sa verticalPosition
59 */
60
61 /*!
62 \qmlproperty real PieSeries::verticalPosition
63 \brief Defines the vertical position of the pie.
64
65 The value is a relative value to the chart rectangle where:
66
67 \list
68 \o 0.0 is the absolute top.
69 \o 1.0 is the absolute bottom.
70 \endlist
71
72 Default value is 0.5 (center).
73
74 \sa horizontalPosition
75 */
76
77 DeclarativePieSeries::DeclarativePieSeries(QObject *parent) :
30 DeclarativePieSeries::DeclarativePieSeries(QObject *parent) :
78 QPieSeries(parent)
31 QPieSeries(parent)
79 {
32 {
80 }
33 }
81
34
82 void DeclarativePieSeries::classBegin()
35 void DeclarativePieSeries::classBegin()
83 {
36 {
84 }
37 }
85
38
86 void DeclarativePieSeries::componentComplete()
39 void DeclarativePieSeries::componentComplete()
87 {
40 {
88 foreach(QObject *child, children()) {
41 foreach(QObject *child, children()) {
89 if (qobject_cast<QPieSlice *>(child)) {
42 if (qobject_cast<QPieSlice *>(child)) {
90 QPieSeries::append(qobject_cast<QPieSlice *>(child));
43 QPieSeries::append(qobject_cast<QPieSlice *>(child));
91 } else if(qobject_cast<QVPieModelMapper *>(child)) {
44 } else if(qobject_cast<QVPieModelMapper *>(child)) {
92 QVPieModelMapper *mapper = qobject_cast<QVPieModelMapper *>(child);
45 QVPieModelMapper *mapper = qobject_cast<QVPieModelMapper *>(child);
93 mapper->setSeries(this);
46 mapper->setSeries(this);
94 } else if(qobject_cast<QHPieModelMapper *>(child)) {
47 } else if(qobject_cast<QHPieModelMapper *>(child)) {
95 QHPieModelMapper *mapper = qobject_cast<QHPieModelMapper *>(child);
48 QHPieModelMapper *mapper = qobject_cast<QHPieModelMapper *>(child);
96 mapper->setSeries(this);
49 mapper->setSeries(this);
97 }
50 }
98 }
51 }
99 }
52 }
100
53
101 QDeclarativeListProperty<QObject> DeclarativePieSeries::seriesChildren()
54 QDeclarativeListProperty<QObject> DeclarativePieSeries::seriesChildren()
102 {
55 {
103 return QDeclarativeListProperty<QObject>(this, 0, &DeclarativePieSeries::appendSeriesChildren);
56 return QDeclarativeListProperty<QObject>(this, 0, &DeclarativePieSeries::appendSeriesChildren);
104 }
57 }
105
58
106 void DeclarativePieSeries::appendSeriesChildren(QDeclarativeListProperty<QObject> * list, QObject *element)
59 void DeclarativePieSeries::appendSeriesChildren(QDeclarativeListProperty<QObject> * list, QObject *element)
107 {
60 {
108 // Empty implementation; the children are parsed in componentComplete instead
61 // Empty implementation; the children are parsed in componentComplete instead
109 Q_UNUSED(list);
62 Q_UNUSED(list);
110 Q_UNUSED(element);
63 Q_UNUSED(element);
111 }
64 }
112
65
113 QPieSlice *DeclarativePieSeries::at(int index)
66 QPieSlice *DeclarativePieSeries::at(int index)
114 {
67 {
115 QList<QPieSlice*> sliceList = slices();
68 QList<QPieSlice*> sliceList = slices();
116 if (index < sliceList.count())
69 if (index < sliceList.count())
117 return sliceList[index];
70 return sliceList[index];
118
71
119 return 0;
72 return 0;
120 }
73 }
121
74
122 QPieSlice* DeclarativePieSeries::find(QString label)
75 QPieSlice* DeclarativePieSeries::find(QString label)
123 {
76 {
124 foreach (QPieSlice *slice, slices()) {
77 foreach (QPieSlice *slice, slices()) {
125 if (slice->label() == label)
78 if (slice->label() == label)
126 return slice;
79 return slice;
127 }
80 }
128 return 0;
81 return 0;
129 }
82 }
130
83
131 QPieSlice* DeclarativePieSeries::append(QString label, qreal value)
84 QPieSlice* DeclarativePieSeries::append(QString label, qreal value)
132 {
85 {
133 // TODO: parameter order is wrong, switch it:
86 // TODO: parameter order is wrong, switch it:
134 QPieSlice *slice = new QPieSlice(this);
87 QPieSlice *slice = new QPieSlice(this);
135 slice->setLabel(label);
88 slice->setLabel(label);
136 slice->setValue(value);
89 slice->setValue(value);
137 QPieSeries::append(slice);
90 QPieSeries::append(slice);
138 return slice;
91 return slice;
139 }
92 }
140
93
141 #include "moc_declarativepieseries.cpp"
94 #include "moc_declarativepieseries.cpp"
142
95
143 QTCOMMERCIALCHART_END_NAMESPACE
96 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,73 +1,60
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 "declarativescatterseries.h"
21 #include "declarativescatterseries.h"
22 #include "declarativechart.h"
22 #include "declarativechart.h"
23 #include "qchart.h"
23 #include "qchart.h"
24 #include "qscatterseries.h"
24 #include "qscatterseries.h"
25
25
26 QTCOMMERCIALCHART_BEGIN_NAMESPACE
26 QTCOMMERCIALCHART_BEGIN_NAMESPACE
27
27
28 /*!
29 \qmlclass ScatterSeries QScatterSeries
30
31 The following QML shows how to create a chart with two simple scatter series:
32 \snippet ../demos/qmlchart/qml/qmlchart/View5.qml 1
33 \snippet ../demos/qmlchart/qml/qmlchart/View5.qml 2
34
35 \beginfloatleft
36 \image demos_qmlchart5.png
37 \endfloat
38 \clearfloat
39 */
40
41 DeclarativeScatterSeries::DeclarativeScatterSeries(QObject *parent) :
28 DeclarativeScatterSeries::DeclarativeScatterSeries(QObject *parent) :
42 QScatterSeries(parent)
29 QScatterSeries(parent)
43 {
30 {
44 connect(this, SIGNAL(pointAdded(int)), this, SLOT(handleCountChanged(int)));
31 connect(this, SIGNAL(pointAdded(int)), this, SLOT(handleCountChanged(int)));
45 connect(this, SIGNAL(pointRemoved(int)), this, SLOT(handleCountChanged(int)));
32 connect(this, SIGNAL(pointRemoved(int)), this, SLOT(handleCountChanged(int)));
46 }
33 }
47
34
48 QXYSeries *DeclarativeScatterSeries::xySeries()
35 QXYSeries *DeclarativeScatterSeries::xySeries()
49 {
36 {
50 return this;
37 return this;
51 }
38 }
52
39
53 void DeclarativeScatterSeries::handleCountChanged(int index)
40 void DeclarativeScatterSeries::handleCountChanged(int index)
54 {
41 {
55 Q_UNUSED(index)
42 Q_UNUSED(index)
56 emit countChanged(QScatterSeries::count());
43 emit countChanged(QScatterSeries::count());
57 }
44 }
58
45
59 QDeclarativeListProperty<QObject> DeclarativeScatterSeries::declarativeChildren()
46 QDeclarativeListProperty<QObject> DeclarativeScatterSeries::declarativeChildren()
60 {
47 {
61 return QDeclarativeListProperty<QObject>(this, 0, &appendDeclarativeChildren);
48 return QDeclarativeListProperty<QObject>(this, 0, &appendDeclarativeChildren);
62 }
49 }
63
50
64 void DeclarativeScatterSeries::appendDeclarativeChildren(QDeclarativeListProperty<QObject> *list, QObject *element)
51 void DeclarativeScatterSeries::appendDeclarativeChildren(QDeclarativeListProperty<QObject> *list, QObject *element)
65 {
52 {
66 Q_UNUSED(list)
53 Q_UNUSED(list)
67 Q_UNUSED(element)
54 Q_UNUSED(element)
68 // Empty implementation, childs are parsed in componentComplete
55 // Empty implementation, childs are parsed in componentComplete
69 }
56 }
70
57
71 #include "moc_declarativescatterseries.cpp"
58 #include "moc_declarativescatterseries.cpp"
72
59
73 QTCOMMERCIALCHART_END_NAMESPACE
60 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,74 +1,60
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 "declarativesplineseries.h"
21 #include "declarativesplineseries.h"
22 #include "declarativechart.h"
22 #include "declarativechart.h"
23 #include <QChart>
23 #include <QChart>
24 #include "declarativexypoint.h"
24 #include "declarativexypoint.h"
25
25
26 QTCOMMERCIALCHART_BEGIN_NAMESPACE
26 QTCOMMERCIALCHART_BEGIN_NAMESPACE
27
27
28 /*!
29 \qmlclass SplineSeries QSplineSeries
30
31 \section1 Example Usage
32
33 \beginfloatleft
34 \image demos_qmlchart3.png
35 \endfloat
36 \clearfloat
37
38 The following QML shows how to create a simple spline chart:
39 \snippet ../demos/qmlchart/qml/qmlchart/View3.qml 1
40 */
41
42 DeclarativeSplineSeries::DeclarativeSplineSeries(QObject *parent) :
28 DeclarativeSplineSeries::DeclarativeSplineSeries(QObject *parent) :
43 QSplineSeries(parent)
29 QSplineSeries(parent)
44 {
30 {
45 connect(this, SIGNAL(pointAdded(int)), this, SLOT(handleCountChanged(int)));
31 connect(this, SIGNAL(pointAdded(int)), this, SLOT(handleCountChanged(int)));
46 connect(this, SIGNAL(pointRemoved(int)), this, SLOT(handleCountChanged(int)));
32 connect(this, SIGNAL(pointRemoved(int)), this, SLOT(handleCountChanged(int)));
47 }
33 }
48
34
49 QXYSeries *DeclarativeSplineSeries::xySeries()
35 QXYSeries *DeclarativeSplineSeries::xySeries()
50 {
36 {
51 return this;
37 return this;
52 }
38 }
53
39
54 void DeclarativeSplineSeries::handleCountChanged(int index)
40 void DeclarativeSplineSeries::handleCountChanged(int index)
55 {
41 {
56 Q_UNUSED(index)
42 Q_UNUSED(index)
57 emit countChanged(points().count());
43 emit countChanged(points().count());
58 }
44 }
59
45
60 QDeclarativeListProperty<QObject> DeclarativeSplineSeries::declarativeChildren()
46 QDeclarativeListProperty<QObject> DeclarativeSplineSeries::declarativeChildren()
61 {
47 {
62 return QDeclarativeListProperty<QObject>(this, 0, &appendDeclarativeChildren);
48 return QDeclarativeListProperty<QObject>(this, 0, &appendDeclarativeChildren);
63 }
49 }
64
50
65 void DeclarativeSplineSeries::appendDeclarativeChildren(QDeclarativeListProperty<QObject> *list, QObject *element)
51 void DeclarativeSplineSeries::appendDeclarativeChildren(QDeclarativeListProperty<QObject> *list, QObject *element)
66 {
52 {
67 Q_UNUSED(list)
53 Q_UNUSED(list)
68 Q_UNUSED(element)
54 Q_UNUSED(element)
69 // Empty implementation, childs are parsed in componentComplete
55 // Empty implementation, childs are parsed in componentComplete
70 }
56 }
71
57
72 #include "moc_declarativesplineseries.cpp"
58 #include "moc_declarativesplineseries.cpp"
73
59
74 QTCOMMERCIALCHART_END_NAMESPACE
60 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,34 +1,51
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 "declarativexypoint.h"
21 #include "declarativexypoint.h"
22
22
23 QTCOMMERCIALCHART_BEGIN_NAMESPACE
23 QTCOMMERCIALCHART_BEGIN_NAMESPACE
24
24
25 /*!
26 \qmlclass XyPoint QPointF
27 XyPoint is a convenience element for initializing XY-series with static coordinate data. To
28 manipulate an XY-series dynamically, use it's data manipulation functions instead.
29 \sa LineSeries, AreaSeries, ScatterSeries, SplineSeries
30 */
31
32 /*!
33 \qmlproperty real XyPoint::x
34 The x-coordinate of the point.
35 */
36
37 /*!
38 \qmlproperty real XyPoint::y
39 The y-coordinate of the point.
40 */
41
25 DeclarativeXyPoint::DeclarativeXyPoint(QObject *parent) :
42 DeclarativeXyPoint::DeclarativeXyPoint(QObject *parent) :
26 QObject(parent)
43 QObject(parent)
27 {
44 {
28 setX(0.0);
45 setX(0.0);
29 setY(0.0);
46 setY(0.0);
30 }
47 }
31
48
32 #include "moc_declarativexypoint.cpp"
49 #include "moc_declarativexypoint.cpp"
33
50
34 QTCOMMERCIALCHART_END_NAMESPACE
51 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,105 +1,105
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 <QtDeclarative/qdeclarativeextensionplugin.h>
21 #include <QtDeclarative/qdeclarativeextensionplugin.h>
22 #include <QtDeclarative/qdeclarative.h>
22 #include <QtDeclarative/qdeclarative.h>
23 #include "qchart.h"
23 #include "qchart.h"
24 #include "qaxiscategories.h"
24 #include "qaxiscategories.h"
25 #include "declarativechart.h"
25 #include "declarativechart.h"
26 #include "declarativexypoint.h"
26 #include "declarativexypoint.h"
27 #include "declarativelineseries.h"
27 #include "declarativelineseries.h"
28 #include "declarativesplineseries.h"
28 #include "declarativesplineseries.h"
29 #include "declarativeareaseries.h"
29 #include "declarativeareaseries.h"
30 #include "declarativescatterseries.h"
30 #include "declarativescatterseries.h"
31 #include "declarativebarseries.h"
31 #include "declarativebarseries.h"
32 #include "declarativepieseries.h"
32 #include "declarativepieseries.h"
33 #include <QVXYModelMapper>
33 #include <QVXYModelMapper>
34 #include <QHXYModelMapper>
34 #include <QHXYModelMapper>
35 #include <QHPieModelMapper>
35 #include <QHPieModelMapper>
36 #include <QVPieModelMapper>
36 #include <QVPieModelMapper>
37 #include <QHBarModelMapper>
37 #include <QHBarModelMapper>
38 #include <QVBarModelMapper>
38 #include <QVBarModelMapper>
39
39
40 QTCOMMERCIALCHART_BEGIN_NAMESPACE
40 QTCOMMERCIALCHART_BEGIN_NAMESPACE
41
41
42 class ChartQmlPlugin : public QDeclarativeExtensionPlugin
42 class ChartQmlPlugin : public QDeclarativeExtensionPlugin
43 {
43 {
44 Q_OBJECT
44 Q_OBJECT
45 public:
45 public:
46 virtual void registerTypes(const char *uri)
46 virtual void registerTypes(const char *uri)
47 {
47 {
48 Q_ASSERT(QLatin1String(uri) == QLatin1String("QtCommercial.Chart"));
48 Q_ASSERT(QLatin1String(uri) == QLatin1String("QtCommercial.Chart"));
49
49
50 qmlRegisterType<DeclarativeChart>(uri, 1, 0, "ChartView");
50 qmlRegisterType<DeclarativeChart>(uri, 1, 0, "ChartView");
51 qmlRegisterType<DeclarativeXyPoint>(uri, 1, 0, "XyPoint");
51 qmlRegisterType<DeclarativeXyPoint>(uri, 1, 0, "XyPoint");
52 qmlRegisterType<DeclarativeScatterSeries>(uri, 1, 0, "ScatterSeries");
52 qmlRegisterType<DeclarativeScatterSeries>(uri, 1, 0, "ScatterSeries");
53 qmlRegisterType<DeclarativeLineSeries>(uri, 1, 0, "LineSeries");
53 qmlRegisterType<DeclarativeLineSeries>(uri, 1, 0, "LineSeries");
54 qmlRegisterType<DeclarativeSplineSeries>(uri, 1, 0, "SplineSeries");
54 qmlRegisterType<DeclarativeSplineSeries>(uri, 1, 0, "SplineSeries");
55 qmlRegisterType<DeclarativeAreaSeries>(uri, 1, 0, "AreaSeries");
55 qmlRegisterType<DeclarativeAreaSeries>(uri, 1, 0, "AreaSeries");
56 qmlRegisterType<DeclarativeBarSeries>(uri, 1, 0, "BarSeries");
56 qmlRegisterType<DeclarativeBarSeries>(uri, 1, 0, "BarSeries");
57 qmlRegisterType<DeclarativeGroupedBarSeries>(uri, 1, 0, "GroupedBarSeries");
57 qmlRegisterType<DeclarativeGroupedBarSeries>(uri, 1, 0, "GroupedBarSeries");
58 qmlRegisterType<DeclarativeStackedBarSeries>(uri, 1, 0, "StackedBarSeries");
58 qmlRegisterType<DeclarativeStackedBarSeries>(uri, 1, 0, "StackedBarSeries");
59 qmlRegisterType<DeclarativePercentBarSeries>(uri, 1, 0, "PercentBarSeries");
59 qmlRegisterType<DeclarativePercentBarSeries>(uri, 1, 0, "PercentBarSeries");
60 qmlRegisterType<DeclarativePieSeries>(uri, 1, 0, "PieSeries");
60 qmlRegisterType<DeclarativePieSeries>(uri, 1, 0, "PieSeries");
61 qmlRegisterType<QPieSlice>(uri, 1, 0, "PieSlice");
61 qmlRegisterType<QPieSlice>(uri, 1, 0, "PieSlice");
62 qmlRegisterType<DeclarativeBarSet>(uri, 1, 0, "BarSet");
62 qmlRegisterType<DeclarativeBarSet>(uri, 1, 0, "BarSet");
63 qmlRegisterType<QHXYModelMapper>(uri, 1, 0, "HXYModelMapper");
63 qmlRegisterType<QHXYModelMapper>(uri, 1, 0, "HXYModelMapper");
64 qmlRegisterType<QVXYModelMapper>(uri, 1, 0, "VXYModelMapper");
64 qmlRegisterType<QVXYModelMapper>(uri, 1, 0, "VXYModelMapper");
65 qmlRegisterType<QHPieModelMapper>(uri, 1, 0, "HPieModelMapper");
65 qmlRegisterType<QHPieModelMapper>(uri, 1, 0, "HPieModelMapper");
66 qmlRegisterType<QVPieModelMapper>(uri, 1, 0, "VPieModelMapper");
66 qmlRegisterType<QVPieModelMapper>(uri, 1, 0, "VPieModelMapper");
67 qmlRegisterType<QHBarModelMapper>(uri, 1, 0, "HBarModelMapper");
67 qmlRegisterType<QHBarModelMapper>(uri, 1, 0, "HBarModelMapper");
68 qmlRegisterType<QVBarModelMapper>(uri, 1, 0, "VBarModelMapper");
68 qmlRegisterType<QVBarModelMapper>(uri, 1, 0, "VBarModelMapper");
69
69
70 qmlRegisterUncreatableType<QLegend>(uri, 1, 0, "Legend",
70 qmlRegisterUncreatableType<QLegend>(uri, 1, 0, "Legend",
71 QLatin1String("Trying to create uncreatable: Legend."));
71 QLatin1String("Trying to create uncreatable: Legend."));
72 qmlRegisterUncreatableType<QXYSeries>(uri, 1, 0, "QXYSeries",
72 qmlRegisterUncreatableType<QXYSeries>(uri, 1, 0, "XYSeries",
73 QLatin1String("Trying to create uncreatable: QXYSeries."));
73 QLatin1String("Trying to create uncreatable: XYSeries."));
74 qmlRegisterUncreatableType<QScatterSeries>(uri, 1, 0, "QScatterSeries",
74 qmlRegisterUncreatableType<QScatterSeries>(uri, 1, 0, "QScatterSeries",
75 QLatin1String("Trying to create uncreatable: QScatterSeries."));
75 QLatin1String("Trying to create uncreatable: QScatterSeries."));
76 qmlRegisterUncreatableType<QPieSeries>(uri, 1, 0, "QPieSeries",
76 qmlRegisterUncreatableType<QPieSeries>(uri, 1, 0, "QPieSeries",
77 QLatin1String("Trying to create uncreatable: QPieSeries."));
77 QLatin1String("Trying to create uncreatable: QPieSeries."));
78 qmlRegisterUncreatableType<QBarSet>(uri, 1, 0, "QBarSet",
78 qmlRegisterUncreatableType<QBarSet>(uri, 1, 0, "QBarSet",
79 QLatin1String("Trying to create uncreatable: QBarSet."));
79 QLatin1String("Trying to create uncreatable: QBarSet."));
80 qmlRegisterUncreatableType<QAbstractItemModel>(uri, 1, 0, "AbstractItemModel",
80 qmlRegisterUncreatableType<QAbstractItemModel>(uri, 1, 0, "AbstractItemModel",
81 QLatin1String("Trying to create uncreatable: AbstractItemModel."));
81 QLatin1String("Trying to create uncreatable: AbstractItemModel."));
82 qmlRegisterUncreatableType<QXYModelMapper>(uri, 1, 0, "XYModelMapper",
82 qmlRegisterUncreatableType<QXYModelMapper>(uri, 1, 0, "XYModelMapper",
83 QLatin1String("Trying to create uncreatable: XYModelMapper."));
83 QLatin1String("Trying to create uncreatable: XYModelMapper."));
84 qmlRegisterUncreatableType<QPieModelMapper>(uri, 1, 0, "PieModelMapper",
84 qmlRegisterUncreatableType<QPieModelMapper>(uri, 1, 0, "PieModelMapper",
85 QLatin1String("Trying to create uncreatable: PieModelMapper."));
85 QLatin1String("Trying to create uncreatable: PieModelMapper."));
86 qmlRegisterUncreatableType<QBarModelMapper>(uri, 1, 0, "BarModelMapper",
86 qmlRegisterUncreatableType<QBarModelMapper>(uri, 1, 0, "BarModelMapper",
87 QLatin1String("Trying to create uncreatable: BarModelMapper."));
87 QLatin1String("Trying to create uncreatable: BarModelMapper."));
88 qmlRegisterUncreatableType<QAbstractSeries>(uri, 1, 0, "AbstractSeries",
88 qmlRegisterUncreatableType<QAbstractSeries>(uri, 1, 0, "AbstractSeries",
89 QLatin1String("Trying to create uncreatable: AbstractSeries."));
89 QLatin1String("Trying to create uncreatable: AbstractSeries."));
90 qmlRegisterUncreatableType<QAxis>(uri, 1, 0, "Axis",
90 qmlRegisterUncreatableType<QAxis>(uri, 1, 0, "Axis",
91 QLatin1String("Trying to create uncreatable: Axis."));
91 QLatin1String("Trying to create uncreatable: Axis."));
92 qmlRegisterUncreatableType<QPieModelMapper>(uri, 1, 0, "PieModelMapper",
92 qmlRegisterUncreatableType<QPieModelMapper>(uri, 1, 0, "PieModelMapper",
93 QLatin1String("Trying to create uncreatable: PieModelMapper."));
93 QLatin1String("Trying to create uncreatable: PieModelMapper."));
94 qmlRegisterUncreatableType<QXYModelMapper>(uri, 1, 0, "XYModelMapper",
94 qmlRegisterUncreatableType<QXYModelMapper>(uri, 1, 0, "XYModelMapper",
95 QLatin1String("Trying to create uncreatable: XYModelMapper."));
95 QLatin1String("Trying to create uncreatable: XYModelMapper."));
96 }
96 }
97 };
97 };
98
98
99 #include "plugin.moc"
99 #include "plugin.moc"
100
100
101 QTCOMMERCIALCHART_END_NAMESPACE
101 QTCOMMERCIALCHART_END_NAMESPACE
102
102
103 QTCOMMERCIALCHART_USE_NAMESPACE
103 QTCOMMERCIALCHART_USE_NAMESPACE
104
104
105 Q_EXPORT_PLUGIN2(qtcommercialchartqml, QT_PREPEND_NAMESPACE(ChartQmlPlugin))
105 Q_EXPORT_PLUGIN2(qtcommercialchartqml, QT_PREPEND_NAMESPACE(ChartQmlPlugin))
@@ -1,344 +1,385
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 "qareaseries.h"
21 #include "qareaseries.h"
22 #include "qareaseries_p.h"
22 #include "qareaseries_p.h"
23 #include "qlineseries.h"
23 #include "qlineseries.h"
24 #include "areachartitem_p.h"
24 #include "areachartitem_p.h"
25 #include "legendmarker_p.h"
25 #include "legendmarker_p.h"
26 #include "domain_p.h"
26 #include "domain_p.h"
27 #include "chartdataset_p.h"
27 #include "chartdataset_p.h"
28 #include "charttheme_p.h"
28 #include "charttheme_p.h"
29 #include "chartanimator_p.h"
29 #include "chartanimator_p.h"
30
30
31 QTCOMMERCIALCHART_BEGIN_NAMESPACE
31 QTCOMMERCIALCHART_BEGIN_NAMESPACE
32
32
33 /*!
33 /*!
34 \class QAreaSeries
34 \class QAreaSeries
35 \brief The QAreaSeries class is used for making area charts.
35 \brief The QAreaSeries class is used for making area charts.
36
36
37 \mainclass
37 \mainclass
38
38
39 An area chart is used to show quantitative data. It is based on line chart, in the way that area between axis and the line
39 An area chart is used to show quantitative data. It is based on line chart, in the way that area between axis and the line
40 is emphasized with color. Since the area chart is based on line chart, QAreaSeries constructor needs QLineSeries instance,
40 is emphasized with color. Since the area chart is based on line chart, QAreaSeries constructor needs QLineSeries instance,
41 which defines "upper" boundary of the area. "Lower" boundary is defined by default by axis X. Instead of axis X "lower" boundary can be specified by other line.
41 which defines "upper" boundary of the area. "Lower" boundary is defined by default by axis X. Instead of axis X "lower" boundary can be specified by other line.
42 In that case QAreaSeries should be initiated with two QLineSerie instances. Please note terms "upper" and "lower" boundary can be misleading in cases
42 In that case QAreaSeries should be initiated with two QLineSerie instances. Please note terms "upper" and "lower" boundary can be misleading in cases
43 where "lower" boundary had bigger values than the "upper" one, however the main point that area between these two boundary lines will be filled.
43 where "lower" boundary had bigger values than the "upper" one, however the main point that area between these two boundary lines will be filled.
44
44
45 See the \l {AreaChart Example} {area chart example} to learn how to create a simple area chart.
45 See the \l {AreaChart Example} {area chart example} to learn how to create a simple area chart.
46 \image examples_areachart.png
46 \image examples_areachart.png
47 */
47 */
48 /*!
49 \qmlclass AreaSeries QAreaSeries
50
51 The following QML shows how to create a simple area chart:
52 \snippet ../demos/qmlchart/qml/qmlchart/View4.qml 1
53 \beginfloatleft
54 \image demos_qmlchart4.png
55 \endfloat
56 \clearfloat
57 */
48
58
49 /*!
59 /*!
50 \property QAreaSeries::upperSeries
60 \property QAreaSeries::upperSeries
51 \brief The upper one of the two line series used to define area series boundaries.
61 \brief The upper one of the two line series used to define area series boundaries.
52 */
62 */
63 /*!
64 \qmlproperty LineSeries AreaSeries::upperSeries
65 The upper one of the two line series used to define area series boundaries.
66 */
53
67
54 /*!
68 /*!
55 \property QAreaSeries::lowerSeries
69 \property QAreaSeries::lowerSeries
56 The lower one of the two line series used to define are series boundaries. Note if
70 The lower one of the two line series used to define are series boundaries. Note if
57 QAreaSeries was counstucted wihtout a\ lowerSeries this is null.
71 QAreaSeries was counstucted wihtout a\ lowerSeries this is null.
58 */
72 */
73 /*!
74 \qmlproperty LineSeries AreaSeries::lowerSeries
75 The lower one of the two line series used to define are series boundaries. Note if
76 AreaSeries was counstucted wihtout a\ lowerSeries this is null.
77 */
59
78
60 /*!
79 /*!
61 \property QAreaSeries::color
80 \property QAreaSeries::color
62 Fill (brush) color of the series. This is a convenience property for modifying the color of brush.
81 Fill (brush) color of the series. This is a convenience property for modifying the color of brush.
63 \sa QAreaSeries::brush()
82 \sa QAreaSeries::brush()
64 */
83 */
84 /*!
85 \qmlproperty color AreaSeries::color
86 Fill (brush) color of the series.
87 */
65
88
66 /*!
89 /*!
67 \property QAreaSeries::borderColor
90 \property QAreaSeries::borderColor
68 Line (pen) color of the series. This is a convenience property for modifying the color of pen.
91 Line (pen) color of the series. This is a convenience property for modifying the color of pen.
69 \sa QAreaSeries::pen()
92 \sa QAreaSeries::pen()
70 */
93 */
94 /*!
95 \qmlproperty color AreaSeries::borderColor
96 Line (pen) color of the series.
97 */
71
98
72 /*!
99 /*!
73 \fn QPen QAreaSeries::pen() const
100 \fn QPen QAreaSeries::pen() const
74 \brief Returns the pen used to draw line for this series.
101 \brief Returns the pen used to draw line for this series.
75 \sa setPen()
102 \sa setPen()
76 */
103 */
77
104
78 /*!
105 /*!
79 \fn QPen QAreaSeries::brush() const
106 \fn QPen QAreaSeries::brush() const
80 \brief Returns the brush used to draw line for this series.
107 \brief Returns the brush used to draw line for this series.
81 \sa setBrush()
108 \sa setBrush()
82 */
109 */
83
110
84 /*!
111 /*!
85 \fn void QAreaSeries::colorChanged(QColor color)
112 \fn void QAreaSeries::colorChanged(QColor color)
86 \brief Signal is emitted when the fill (brush) color has changed to \a color.
113 \brief Signal is emitted when the fill (brush) color has changed to \a color.
87 */
114 */
115 /*!
116 \qmlsignal AreaSeries::colorChanged(color color)
117 Signal is emitted when the fill (brush) color has changed to \a color.
118 */
88
119
89 /*!
120 /*!
90 \fn void QAreaSeries::borderColorChanged(QColor color)
121 \fn void QAreaSeries::borderColorChanged(QColor color)
91 \brief Signal is emitted when the line (pen) color has changed to \a color.
122 \brief Signal is emitted when the line (pen) color has changed to \a color.
92 */
123 */
93
94 /*!
124 /*!
95 \fn bool QAreaSeries::pointsVisible() const
125 \qmlsignal AreaSeries::borderColorChanged(color color)
96 \brief Returns if the points are drawn for this series.
126 Signal is emitted when the line (pen) color has changed to \a color.
97 \sa setPointsVisible()
98 */
127 */
99
128
100 /*!
129 /*!
101 \fn void QAreaSeries::clicked(const QPointF& point)
130 \fn void QAreaSeries::clicked(const QPointF& point)
102 \brief Signal is emitted when user clicks the \a point on area chart.
131 \brief Signal is emitted when user clicks the \a point on area chart.
103 */
132 */
133 /*!
134 \qmlsignal AreaSeries::clicked(QPointF point)
135 Signal is emitted when user clicks the \a point on area chart.
136 */
104
137
105 /*!
138 /*!
106 \fn void QAreaSeries::selected()
139 \fn void QAreaSeries::selected()
107
108 The signal is emitted if the user selects/deselects the XY series. The logic for maintaining selections should be
140 The signal is emitted if the user selects/deselects the XY series. The logic for maintaining selections should be
109 implemented by the user of QAreaSeries API.
141 implemented by the user of QAreaSeries API.
110 */
142 */
143 /*!
144 \qmlsignal AreaSeries::selected()
145 The signal is emitted if the user selects/deselects the XY series. The logic for maintaining selections should be
146 implemented by the user of AreaSeries API.
147 */
111
148
112 /*!
149 /*!
113 \fn void QAreaSeriesPrivate::updated()
150 \fn void QAreaSeriesPrivate::updated()
114 \brief \internal
151 \brief \internal
115 */
152 */
116
153
117 /*!
154 /*!
118 Constructs area series object which is a child of \a upperSeries. Area will be spanned between \a
155 Constructs area series object which is a child of \a upperSeries. Area will be spanned between \a
119 upperSeries line and \a lowerSeries line. If no \a lowerSeries is passed to constructor, area is specified by axis x (y=0) instead.
156 upperSeries line and \a lowerSeries line. If no \a lowerSeries is passed to constructor, area is specified by axis x (y=0) instead.
120 When series object is added to QChartView or QChart instance ownerships is transferred.
157 When series object is added to QChartView or QChart instance ownerships is transferred.
121 */
158 */
122 QAreaSeries::QAreaSeries(QLineSeries *upperSeries, QLineSeries *lowerSeries)
159 QAreaSeries::QAreaSeries(QLineSeries *upperSeries, QLineSeries *lowerSeries)
123 : QAbstractSeries(*new QAreaSeriesPrivate(upperSeries,lowerSeries,this),upperSeries)
160 : QAbstractSeries(*new QAreaSeriesPrivate(upperSeries,lowerSeries,this),upperSeries)
124 {
161 {
125 }
162 }
126
163
127 /*!
164 /*!
128 Constructs area series object without upper or lower series with \a parent object.
165 Constructs area series object without upper or lower series with \a parent object.
129 */
166 */
130 QAreaSeries::QAreaSeries(QObject *parent)
167 QAreaSeries::QAreaSeries(QObject *parent)
131 : QAbstractSeries(*new QAreaSeriesPrivate(0, 0, this), parent)
168 : QAbstractSeries(*new QAreaSeriesPrivate(0, 0, this), parent)
132 {
169 {
133 }
170 }
134
171
135 /*!
172 /*!
136 Destroys the object. Series added to QChartView or QChart instances are owned by those,
173 Destroys the object. Series added to QChartView or QChart instances are owned by those,
137 and are deleted when mentioned object are destroyed.
174 and are deleted when mentioned object are destroyed.
138 */
175 */
139 QAreaSeries::~QAreaSeries()
176 QAreaSeries::~QAreaSeries()
140 {
177 {
141 }
178 }
142
179
143 /*!
180 /*!
144 Returns QChartSeries::SeriesTypeArea.
181 Returns QChartSeries::SeriesTypeArea.
145 */
182 */
146 QAbstractSeries::SeriesType QAreaSeries::type() const
183 QAbstractSeries::SeriesType QAreaSeries::type() const
147 {
184 {
148 return QAbstractSeries::SeriesTypeArea;
185 return QAbstractSeries::SeriesTypeArea;
149 }
186 }
150
187
151 /*!
188 /*!
152 Sets the \a series that is to be used as the area chart upper series.
189 Sets the \a series that is to be used as the area chart upper series.
153 */
190 */
154 void QAreaSeries::setUpperSeries(QLineSeries* series)
191 void QAreaSeries::setUpperSeries(QLineSeries* series)
155 {
192 {
156 Q_D(QAreaSeries);
193 Q_D(QAreaSeries);
157 d->m_upperSeries = series;
194 d->m_upperSeries = series;
158 }
195 }
159
196
160 QLineSeries* QAreaSeries::upperSeries() const
197 QLineSeries* QAreaSeries::upperSeries() const
161 {
198 {
162 Q_D(const QAreaSeries);
199 Q_D(const QAreaSeries);
163 return d->m_upperSeries;
200 return d->m_upperSeries;
164 }
201 }
165
202
166 /*!
203 /*!
167 Sets the \a series that is to be used as the area chart lower series.
204 Sets the \a series that is to be used as the area chart lower series.
168 */
205 */
169 void QAreaSeries::setLowerSeries(QLineSeries* series)
206 void QAreaSeries::setLowerSeries(QLineSeries* series)
170 {
207 {
171 Q_D(QAreaSeries);
208 Q_D(QAreaSeries);
172 d->m_lowerSeries = series;
209 d->m_lowerSeries = series;
173 }
210 }
174
211
175 QLineSeries* QAreaSeries::lowerSeries() const
212 QLineSeries* QAreaSeries::lowerSeries() const
176 {
213 {
177 Q_D(const QAreaSeries);
214 Q_D(const QAreaSeries);
178 return d->m_lowerSeries;
215 return d->m_lowerSeries;
179 }
216 }
180
217
181 /*!
218 /*!
182 Sets \a pen used for drawing area outline.
219 Sets \a pen used for drawing area outline.
183 */
220 */
184 void QAreaSeries::setPen(const QPen &pen)
221 void QAreaSeries::setPen(const QPen &pen)
185 {
222 {
186 Q_D(QAreaSeries);
223 Q_D(QAreaSeries);
187 if (d->m_pen != pen) {
224 if (d->m_pen != pen) {
188 d->m_pen = pen;
225 d->m_pen = pen;
189 emit d->updated();
226 emit d->updated();
190 }
227 }
191 }
228 }
192
229
193 QPen QAreaSeries::pen() const
230 QPen QAreaSeries::pen() const
194 {
231 {
195 Q_D(const QAreaSeries);
232 Q_D(const QAreaSeries);
196 return d->m_pen;
233 return d->m_pen;
197 }
234 }
198
235
199 /*!
236 /*!
200 Sets \a brush used for filling the area.
237 Sets \a brush used for filling the area.
201 */
238 */
202 void QAreaSeries::setBrush(const QBrush &brush)
239 void QAreaSeries::setBrush(const QBrush &brush)
203 {
240 {
204 Q_D(QAreaSeries);
241 Q_D(QAreaSeries);
205 if (d->m_brush != brush) {
242 if (d->m_brush != brush) {
206 d->m_brush = brush;
243 d->m_brush = brush;
207 emit d->updated();
244 emit d->updated();
208 }
245 }
209 }
246 }
210
247
211 QBrush QAreaSeries::brush() const
248 QBrush QAreaSeries::brush() const
212 {
249 {
213 Q_D(const QAreaSeries);
250 Q_D(const QAreaSeries);
214 return d->m_brush;
251 return d->m_brush;
215 }
252 }
216
253
217 void QAreaSeries::setColor(const QColor &color)
254 void QAreaSeries::setColor(const QColor &color)
218 {
255 {
219 QBrush b = brush();
256 QBrush b = brush();
220 if (b.color() != color) {
257 if (b.color() != color) {
221 b.setColor(color);
258 b.setColor(color);
222 setBrush(b);
259 setBrush(b);
223 emit colorChanged(color);
260 emit colorChanged(color);
224 }
261 }
225 }
262 }
226
263
227 QColor QAreaSeries::color() const
264 QColor QAreaSeries::color() const
228 {
265 {
229 return brush().color();
266 return brush().color();
230 }
267 }
231
268
232 void QAreaSeries::setBorderColor(const QColor &color)
269 void QAreaSeries::setBorderColor(const QColor &color)
233 {
270 {
234 QPen p = pen();
271 QPen p = pen();
235 if (p.color() != color) {
272 if (p.color() != color) {
236 p.setColor(color);
273 p.setColor(color);
237 setPen(p);
274 setPen(p);
238 emit borderColorChanged(color);
275 emit borderColorChanged(color);
239 }
276 }
240 }
277 }
241
278
242 QColor QAreaSeries::borderColor() const
279 QColor QAreaSeries::borderColor() const
243 {
280 {
244 return pen().color();
281 return pen().color();
245 }
282 }
246
283
247 /*!
284 /*!
248 Sets if data points are \a visible and should be drawn on line.
285 Sets if data points are \a visible and should be drawn on line.
249 */
286 */
250 void QAreaSeries::setPointsVisible(bool visible)
287 void QAreaSeries::setPointsVisible(bool visible)
251 {
288 {
252 Q_D(QAreaSeries);
289 Q_D(QAreaSeries);
253 if (d->m_pointsVisible != visible) {
290 if (d->m_pointsVisible != visible) {
254 d->m_pointsVisible = visible;
291 d->m_pointsVisible = visible;
255 emit d->updated();
292 emit d->updated();
256 }
293 }
257 }
294 }
258
295
296 /*!
297 Returns if the points are drawn for this series.
298 \sa setPointsVisible()
299 */
259 bool QAreaSeries::pointsVisible() const
300 bool QAreaSeries::pointsVisible() const
260 {
301 {
261 Q_D(const QAreaSeries);
302 Q_D(const QAreaSeries);
262 return d->m_pointsVisible;
303 return d->m_pointsVisible;
263 }
304 }
264
305
265 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
306 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
266
307
267 QAreaSeriesPrivate::QAreaSeriesPrivate(QLineSeries *upperSeries, QLineSeries *lowerSeries,QAreaSeries* q) :
308 QAreaSeriesPrivate::QAreaSeriesPrivate(QLineSeries *upperSeries, QLineSeries *lowerSeries,QAreaSeries* q) :
268 QAbstractSeriesPrivate(q),
309 QAbstractSeriesPrivate(q),
269 m_upperSeries(upperSeries),
310 m_upperSeries(upperSeries),
270 m_lowerSeries(lowerSeries),
311 m_lowerSeries(lowerSeries),
271 m_pointsVisible(false)
312 m_pointsVisible(false)
272 {
313 {
273 }
314 }
274
315
275 void QAreaSeriesPrivate::scaleDomain(Domain& domain)
316 void QAreaSeriesPrivate::scaleDomain(Domain& domain)
276 {
317 {
277 Q_Q(QAreaSeries);
318 Q_Q(QAreaSeries);
278
319
279 qreal minX(domain.minX());
320 qreal minX(domain.minX());
280 qreal minY(domain.minY());
321 qreal minY(domain.minY());
281 qreal maxX(domain.maxX());
322 qreal maxX(domain.maxX());
282 qreal maxY(domain.maxY());
323 qreal maxY(domain.maxY());
283 int tickXCount(domain.tickXCount());
324 int tickXCount(domain.tickXCount());
284 int tickYCount(domain.tickYCount());
325 int tickYCount(domain.tickYCount());
285
326
286 QLineSeries* upperSeries = q->upperSeries();
327 QLineSeries* upperSeries = q->upperSeries();
287 QLineSeries* lowerSeries = q->lowerSeries();
328 QLineSeries* lowerSeries = q->lowerSeries();
288
329
289 const QList<QPointF>& points = upperSeries->points();
330 const QList<QPointF>& points = upperSeries->points();
290
331
291 for (int i = 0; i < points.count(); i++)
332 for (int i = 0; i < points.count(); i++)
292 {
333 {
293 qreal x = points[i].x();
334 qreal x = points[i].x();
294 qreal y = points[i].y();
335 qreal y = points[i].y();
295 minX = qMin(minX, x);
336 minX = qMin(minX, x);
296 minY = qMin(minY, y);
337 minY = qMin(minY, y);
297 maxX = qMax(maxX, x);
338 maxX = qMax(maxX, x);
298 maxY = qMax(maxY, y);
339 maxY = qMax(maxY, y);
299 }
340 }
300 if(lowerSeries) {
341 if(lowerSeries) {
301
342
302 const QList<QPointF>& points = lowerSeries->points();
343 const QList<QPointF>& points = lowerSeries->points();
303
344
304 for (int i = 0; i < points.count(); i++)
345 for (int i = 0; i < points.count(); i++)
305 {
346 {
306 qreal x = points[i].x();
347 qreal x = points[i].x();
307 qreal y = points[i].y();
348 qreal y = points[i].y();
308 minX = qMin(minX, x);
349 minX = qMin(minX, x);
309 minY = qMin(minY, y);
350 minY = qMin(minY, y);
310 maxX = qMax(maxX, x);
351 maxX = qMax(maxX, x);
311 maxY = qMax(maxY, y);
352 maxY = qMax(maxY, y);
312 }}
353 }}
313
354
314 domain.setRange(minX,maxX,minY,maxY,tickXCount,tickYCount);
355 domain.setRange(minX,maxX,minY,maxY,tickXCount,tickYCount);
315 }
356 }
316
357
317 Chart* QAreaSeriesPrivate::createGraphics(ChartPresenter* presenter)
358 Chart* QAreaSeriesPrivate::createGraphics(ChartPresenter* presenter)
318 {
359 {
319 Q_Q(QAreaSeries);
360 Q_Q(QAreaSeries);
320
361
321 AreaChartItem* area = new AreaChartItem(q,presenter);
362 AreaChartItem* area = new AreaChartItem(q,presenter);
322 if(presenter->animationOptions().testFlag(QChart::SeriesAnimations)) {
363 if(presenter->animationOptions().testFlag(QChart::SeriesAnimations)) {
323 area->upperLineItem()->setAnimator(presenter->animator());
364 area->upperLineItem()->setAnimator(presenter->animator());
324 area->upperLineItem()->setAnimation(new XYAnimation(area->upperLineItem()));
365 area->upperLineItem()->setAnimation(new XYAnimation(area->upperLineItem()));
325 if(q->lowerSeries()) {
366 if(q->lowerSeries()) {
326 area->lowerLineItem()->setAnimator(presenter->animator());
367 area->lowerLineItem()->setAnimator(presenter->animator());
327 area->lowerLineItem()->setAnimation(new XYAnimation(area->lowerLineItem()));
368 area->lowerLineItem()->setAnimation(new XYAnimation(area->lowerLineItem()));
328 }
369 }
329 }
370 }
330 presenter->chartTheme()->decorate(q, presenter->dataSet()->seriesIndex(q));
371 presenter->chartTheme()->decorate(q, presenter->dataSet()->seriesIndex(q));
331 return area;
372 return area;
332 }
373 }
333
374
334 QList<LegendMarker*> QAreaSeriesPrivate::createLegendMarker(QLegend* legend)
375 QList<LegendMarker*> QAreaSeriesPrivate::createLegendMarker(QLegend* legend)
335 {
376 {
336 Q_Q(QAreaSeries);
377 Q_Q(QAreaSeries);
337 QList<LegendMarker*> list;
378 QList<LegendMarker*> list;
338 return list << new AreaLegendMarker(q,legend);
379 return list << new AreaLegendMarker(q,legend);
339 }
380 }
340
381
341 #include "moc_qareaseries.cpp"
382 #include "moc_qareaseries.cpp"
342 #include "moc_qareaseries_p.cpp"
383 #include "moc_qareaseries_p.cpp"
343
384
344 QTCOMMERCIALCHART_END_NAMESPACE
385 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,123 +1,134
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 "qlineseries.h"
21 #include "qlineseries.h"
22 #include "qlineseries_p.h"
22 #include "qlineseries_p.h"
23 #include "linechartitem_p.h"
23 #include "linechartitem_p.h"
24 #include "chartdataset_p.h"
24 #include "chartdataset_p.h"
25 #include "charttheme_p.h"
25 #include "charttheme_p.h"
26 #include "chartanimator_p.h"
26 #include "chartanimator_p.h"
27
27
28 QTCOMMERCIALCHART_BEGIN_NAMESPACE
28 QTCOMMERCIALCHART_BEGIN_NAMESPACE
29
29
30 /*!
30 /*!
31 \class QLineSeries
31 \class QLineSeries
32 \brief The QLineSeries class is used for making line charts.
32 \brief The QLineSeries class is used for making line charts.
33
33
34 \mainclass
34 \mainclass
35
35
36 A line chart is used to show information as a series of data points
36 A line chart is used to show information as a series of data points
37 connected by straight lines.
37 connected by straight lines.
38
38
39 \image examples_linechart.png
39 \image examples_linechart.png
40
40
41 Creating basic line chart is simple:
41 Creating basic line chart is simple:
42 \code
42 \code
43 QLineSeries* series = new QLineSeries();
43 QLineSeries* series = new QLineSeries();
44 series->append(0, 6);
44 series->append(0, 6);
45 series->append(2, 4);
45 series->append(2, 4);
46 ...
46 ...
47 chart->addSeries(series);
47 chart->addSeries(series);
48 \endcode
48 \endcode
49 */
49 */
50 /*!
51 \qmlclass LineSeries QLineSeries
52 \inherits XYSeries
53
54 The following QML shows how to create a simple line chart:
55 \snippet ../demos/qmlchart/qml/qmlchart/View2.qml 1
56 \beginfloatleft
57 \image demos_qmlchart2.png
58 \endfloat
59 \clearfloat
60 */
50
61
51 /*!
62 /*!
52 \fn virtual SeriesType QLineSeries::type() const
63 \fn virtual SeriesType QLineSeries::type() const
53 \brief Returns type of series.
64 \brief Returns type of series.
54 \sa QAbstractSeries, SeriesType
65 \sa QAbstractSeries, SeriesType
55 */
66 */
56
67
57 /*!
68 /*!
58 Constructs empty series object which is a child of \a parent.
69 Constructs empty series object which is a child of \a parent.
59 When series object is added to QChartView or QChart instance ownerships is transferred.
70 When series object is added to QChartView or QChart instance ownerships is transferred.
60 */
71 */
61 QLineSeries::QLineSeries(QObject *parent) : QXYSeries(*new QLineSeriesPrivate(this),parent)
72 QLineSeries::QLineSeries(QObject *parent) : QXYSeries(*new QLineSeriesPrivate(this),parent)
62 {
73 {
63
74
64 }
75 }
65
76
66 /*!
77 /*!
67 \internal
78 \internal
68 */
79 */
69 QLineSeries::QLineSeries(QLineSeriesPrivate &d,QObject *parent) : QXYSeries (d,parent)
80 QLineSeries::QLineSeries(QLineSeriesPrivate &d,QObject *parent) : QXYSeries (d,parent)
70 {
81 {
71
82
72 }
83 }
73 /*!
84 /*!
74 Destroys the object. Series added to QChartView or QChart instances are owned by those,
85 Destroys the object. Series added to QChartView or QChart instances are owned by those,
75 and are deleted when mentioned object are destroyed.
86 and are deleted when mentioned object are destroyed.
76 */
87 */
77 QLineSeries::~QLineSeries()
88 QLineSeries::~QLineSeries()
78 {
89 {
79 Q_D(QLineSeries);
90 Q_D(QLineSeries);
80 if(d->m_dataset){
91 if(d->m_dataset){
81 d->m_dataset->removeSeries(this);
92 d->m_dataset->removeSeries(this);
82 }
93 }
83 }
94 }
84
95
85 QAbstractSeries::SeriesType QLineSeries::type() const
96 QAbstractSeries::SeriesType QLineSeries::type() const
86 {
97 {
87 return QAbstractSeries::SeriesTypeLine;
98 return QAbstractSeries::SeriesTypeLine;
88 }
99 }
89
100
90 /*
101 /*
91 QDebug operator<< (QDebug debug, const QLineSeries series)
102 QDebug operator<< (QDebug debug, const QLineSeries series)
92 {
103 {
93 Q_ASSERT(series.d_func()->m_x.size() == series.d_func()->m_y.size());
104 Q_ASSERT(series.d_func()->m_x.size() == series.d_func()->m_y.size());
94 int size = series.d_func()->m_x.size();
105 int size = series.d_func()->m_x.size();
95 for (int i=0; i<size; i++) {
106 for (int i=0; i<size; i++) {
96 debug.nospace() << "(" << series.d_func()->m_x.at(i) << ','<< series.d_func()->m_y.at(i) << ") ";
107 debug.nospace() << "(" << series.d_func()->m_x.at(i) << ','<< series.d_func()->m_y.at(i) << ") ";
97 }
108 }
98 return debug.space();
109 return debug.space();
99 }
110 }
100 */
111 */
101
112
102 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
113 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
103
114
104 QLineSeriesPrivate::QLineSeriesPrivate(QLineSeries* q):QXYSeriesPrivate(q)
115 QLineSeriesPrivate::QLineSeriesPrivate(QLineSeries* q):QXYSeriesPrivate(q)
105 {
116 {
106
117
107 };
118 };
108
119
109 Chart* QLineSeriesPrivate::createGraphics(ChartPresenter* presenter)
120 Chart* QLineSeriesPrivate::createGraphics(ChartPresenter* presenter)
110 {
121 {
111 Q_Q(QLineSeries);
122 Q_Q(QLineSeries);
112 LineChartItem* line = new LineChartItem(q,presenter);
123 LineChartItem* line = new LineChartItem(q,presenter);
113 if(presenter->animationOptions().testFlag(QChart::SeriesAnimations)) {
124 if(presenter->animationOptions().testFlag(QChart::SeriesAnimations)) {
114 line->setAnimator(presenter->animator());
125 line->setAnimator(presenter->animator());
115 line->setAnimation(new XYAnimation(line));
126 line->setAnimation(new XYAnimation(line));
116 }
127 }
117 presenter->chartTheme()->decorate(q, presenter->dataSet()->seriesIndex(q));
128 presenter->chartTheme()->decorate(q, presenter->dataSet()->seriesIndex(q));
118 return line;
129 return line;
119 }
130 }
120
131
121 #include "moc_qlineseries.cpp"
132 #include "moc_qlineseries.cpp"
122
133
123 QTCOMMERCIALCHART_END_NAMESPACE
134 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,632 +1,654
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 "qpieseries.h"
21 #include "qpieseries.h"
22 #include "qpieseries_p.h"
22 #include "qpieseries_p.h"
23 #include "qpieslice.h"
23 #include "qpieslice.h"
24 #include "qpieslice_p.h"
24 #include "qpieslice_p.h"
25 #include "pieslicedata_p.h"
25 #include "pieslicedata_p.h"
26 #include "chartdataset_p.h"
26 #include "chartdataset_p.h"
27 #include "charttheme_p.h"
27 #include "charttheme_p.h"
28 #include "chartanimator_p.h"
28 #include "chartanimator_p.h"
29 #include "legendmarker_p.h"
29 #include "legendmarker_p.h"
30
30
31 QTCOMMERCIALCHART_BEGIN_NAMESPACE
31 QTCOMMERCIALCHART_BEGIN_NAMESPACE
32
32
33 /*!
33 /*!
34 \class QPieSeries
34 \class QPieSeries
35 \brief Pie series API for QtCommercial Charts
35 \brief Pie series API for QtCommercial Charts
36
36
37 The pie series defines a pie chart which consists of pie slices which are defined as QPieSlice objects.
37 The pie series defines a pie chart which consists of pie slices which are defined as QPieSlice objects.
38 The slices can have any values as the QPieSeries will calculate its relative value to the sum of all slices.
38 The slices can have any values as the QPieSeries will calculate its relative value to the sum of all slices.
39 The actual slice size is determined by that relative value.
39 The actual slice size is determined by that relative value.
40
40
41 Pie size and position on the chart is controlled by using relative values which range from 0.0 to 1.0
41 Pie size and position on the chart is controlled by using relative values which range from 0.0 to 1.0
42 These relate to the actual chart rectangle.
42 These relate to the actual chart rectangle.
43
43
44 By default the pie is defined as a full pie but it can also be a partial pie.
44 By default the pie is defined as a full pie but it can also be a partial pie.
45 This can be done by setting a starting angle and angle span to the series.
45 This can be done by setting a starting angle and angle span to the series.
46 Full pie is 360 degrees where 0 is at 12 a'clock.
46 Full pie is 360 degrees where 0 is at 12 a'clock.
47
47
48 See the \l {PieChart Example} {pie chart example} to learn how to create a simple pie chart.
48 See the \l {PieChart Example} {pie chart example} to learn how to create a simple pie chart.
49 \image examples_piechart.png
49 \image examples_piechart.png
50 */
50 */
51 /*!
52 \qmlclass PieSeries QPieSeries
53
54 The following QML shows how to create a simple pie chart.
55 \snippet ../demos/qmlchart/qml/qmlchart/View1.qml 1
56 \beginfloatleft
57 \image demos_qmlchart1.png
58 \endfloat
59 \clearfloat
60 */
51
61
52 /*!
62 /*!
53 \property QPieSeries::horizontalPosition
63 \property QPieSeries::horizontalPosition
54 \brief Defines the horizontal position of the pie.
64 \brief Defines the horizontal position of the pie.
55
56 The value is a relative value to the chart rectangle where:
65 The value is a relative value to the chart rectangle where:
57
58 \list
66 \list
59 \o 0.0 is the absolute left.
67 \o 0.0 is the absolute left.
60 \o 1.0 is the absolute right.
68 \o 1.0 is the absolute right.
61 \endlist
69 \endlist
62
63 Default value is 0.5 (center).
70 Default value is 0.5 (center).
64
71 \sa verticalPosition
72 */
73 /*!
74 \qmlproperty real PieSeries::horizontalPosition
75 Defines the horizontal position of the pie. The value is a relative value to the chart rectangle where:
76 \list
77 \o 0.0 is the absolute left.
78 \o 1.0 is the absolute right.
79 \endlist
80 Default value is 0.5 (center).
65 \sa verticalPosition
81 \sa verticalPosition
66 */
82 */
67
83
68 /*!
84 /*!
69 \property QPieSeries::verticalPosition
85 \property QPieSeries::verticalPosition
70 \brief Defines the vertical position of the pie.
86 \brief Defines the vertical position of the pie.
71
72 The value is a relative value to the chart rectangle where:
87 The value is a relative value to the chart rectangle where:
73
74 \list
88 \list
75 \o 0.0 is the absolute top.
89 \o 0.0 is the absolute top.
76 \o 1.0 is the absolute bottom.
90 \o 1.0 is the absolute bottom.
77 \endlist
91 \endlist
78
79 Default value is 0.5 (center).
92 Default value is 0.5 (center).
80
93 \sa horizontalPosition
94 */
95 /*!
96 \qmlproperty real PieSeries::verticalPosition
97 Defines the vertical position of the pie. The value is a relative value to the chart rectangle where:
98 \list
99 \o 0.0 is the absolute top.
100 \o 1.0 is the absolute bottom.
101 \endlist
102 Default value is 0.5 (center).
81 \sa horizontalPosition
103 \sa horizontalPosition
82 */
104 */
83
105
84 /*!
106 /*!
85 \property QPieSeries::size
107 \property QPieSeries::size
86 \brief Defines the pie size.
108 \brief Defines the pie size.
87
109
88 The value is a relative value to the chart rectangle where:
110 The value is a relative value to the chart rectangle where:
89
111
90 \list
112 \list
91 \o 0.0 is the minimum size (pie not drawn).
113 \o 0.0 is the minimum size (pie not drawn).
92 \o 1.0 is the maximum size that can fit the chart.
114 \o 1.0 is the maximum size that can fit the chart.
93 \endlist
115 \endlist
94
116
95 Default value is 0.7.
117 Default value is 0.7.
96 */
118 */
97
119
98 /*!
120 /*!
99 \property QPieSeries::startAngle
121 \property QPieSeries::startAngle
100 \brief Defines the starting angle of the pie.
122 \brief Defines the starting angle of the pie.
101
123
102 Full pie is 360 degrees where 0 degrees is at 12 a'clock.
124 Full pie is 360 degrees where 0 degrees is at 12 a'clock.
103
125
104 Default is value is 0.
126 Default is value is 0.
105 */
127 */
106
128
107 /*!
129 /*!
108 \property QPieSeries::endAngle
130 \property QPieSeries::endAngle
109 \brief Defines the ending angle of the pie.
131 \brief Defines the ending angle of the pie.
110
132
111 Full pie is 360 degrees where 0 degrees is at 12 a'clock.
133 Full pie is 360 degrees where 0 degrees is at 12 a'clock.
112
134
113 Default is value is 360.
135 Default is value is 360.
114 */
136 */
115
137
116 /*!
138 /*!
117 \property QPieSeries::count
139 \property QPieSeries::count
118
140
119 Number of slices in the series.
141 Number of slices in the series.
120 */
142 */
121
143
122 /*!
144 /*!
123 \fn void QPieSeries::countChanged()
145 \fn void QPieSeries::countChanged()
124
146
125 Emitted when the slice count has changed.
147 Emitted when the slice count has changed.
126
148
127 \sa count
149 \sa count
128 */
150 */
129
151
130 /*!
152 /*!
131 \property QPieSeries::sum
153 \property QPieSeries::sum
132
154
133 Sum of all slices.
155 Sum of all slices.
134
156
135 The series keeps track of the sum of all slices it holds.
157 The series keeps track of the sum of all slices it holds.
136 */
158 */
137
159
138 /*!
160 /*!
139 \fn void QPieSeries::sumChanged()
161 \fn void QPieSeries::sumChanged()
140
162
141 Emitted when the sum of all slices has changed.
163 Emitted when the sum of all slices has changed.
142
164
143 \sa sum
165 \sa sum
144 */
166 */
145
167
146 /*!
168 /*!
147 \fn void QPieSeries::added(QList<QPieSlice*> slices)
169 \fn void QPieSeries::added(QList<QPieSlice*> slices)
148
170
149 This signal is emitted when \a slices have been added to the series.
171 This signal is emitted when \a slices have been added to the series.
150
172
151 \sa append(), insert()
173 \sa append(), insert()
152 */
174 */
153
175
154 /*!
176 /*!
155 \fn void QPieSeries::removed(QList<QPieSlice*> slices)
177 \fn void QPieSeries::removed(QList<QPieSlice*> slices)
156
178
157 This signal is emitted when \a slices have been removed from the series.
179 This signal is emitted when \a slices have been removed from the series.
158
180
159 \sa remove()
181 \sa remove()
160 */
182 */
161
183
162 /*!
184 /*!
163 \fn void QPieSeries::clicked(QPieSlice* slice)
185 \fn void QPieSeries::clicked(QPieSlice* slice)
164
186
165 This signal is emitted when a \a slice has been clicked.
187 This signal is emitted when a \a slice has been clicked.
166
188
167 \sa QPieSlice::clicked()
189 \sa QPieSlice::clicked()
168 */
190 */
169
191
170 /*!
192 /*!
171 \fn void QPieSeries::hovered(QPieSlice* slice, bool state)
193 \fn void QPieSeries::hovered(QPieSlice* slice, bool state)
172
194
173 This signal is emitted when user has hovered over or away from the \a slice.
195 This signal is emitted when user has hovered over or away from the \a slice.
174
196
175 \a state is true when user has hovered over the slice and false when hover has moved away from the slice.
197 \a state is true when user has hovered over the slice and false when hover has moved away from the slice.
176
198
177 \sa QPieSlice::hovered()
199 \sa QPieSlice::hovered()
178 */
200 */
179
201
180 /*!
202 /*!
181 Constructs a series object which is a child of \a parent.
203 Constructs a series object which is a child of \a parent.
182 */
204 */
183 QPieSeries::QPieSeries(QObject *parent) :
205 QPieSeries::QPieSeries(QObject *parent) :
184 QAbstractSeries(*new QPieSeriesPrivate(this),parent)
206 QAbstractSeries(*new QPieSeriesPrivate(this),parent)
185 {
207 {
186
208
187 }
209 }
188
210
189 /*!
211 /*!
190 Destroys the series and its slices.
212 Destroys the series and its slices.
191 */
213 */
192 QPieSeries::~QPieSeries()
214 QPieSeries::~QPieSeries()
193 {
215 {
194 // NOTE: d_prt destroyed by QObject
216 // NOTE: d_prt destroyed by QObject
195 }
217 }
196
218
197 /*!
219 /*!
198 Returns QChartSeries::SeriesTypePie.
220 Returns QChartSeries::SeriesTypePie.
199 */
221 */
200 QAbstractSeries::SeriesType QPieSeries::type() const
222 QAbstractSeries::SeriesType QPieSeries::type() const
201 {
223 {
202 return QAbstractSeries::SeriesTypePie;
224 return QAbstractSeries::SeriesTypePie;
203 }
225 }
204
226
205 /*!
227 /*!
206 Appends a single \a slice to the series.
228 Appends a single \a slice to the series.
207 Slice ownership is passed to the series.
229 Slice ownership is passed to the series.
208
230
209 Returns true if append was succesfull.
231 Returns true if append was succesfull.
210 */
232 */
211 bool QPieSeries::append(QPieSlice* slice)
233 bool QPieSeries::append(QPieSlice* slice)
212 {
234 {
213 return append(QList<QPieSlice*>() << slice);
235 return append(QList<QPieSlice*>() << slice);
214 }
236 }
215
237
216 /*!
238 /*!
217 Appends an array of \a slices to the series.
239 Appends an array of \a slices to the series.
218 Slice ownership is passed to the series.
240 Slice ownership is passed to the series.
219
241
220 Returns true if append was successfull.
242 Returns true if append was successfull.
221 */
243 */
222 bool QPieSeries::append(QList<QPieSlice*> slices)
244 bool QPieSeries::append(QList<QPieSlice*> slices)
223 {
245 {
224 Q_D(QPieSeries);
246 Q_D(QPieSeries);
225
247
226 if (slices.count() == 0)
248 if (slices.count() == 0)
227 return false;
249 return false;
228
250
229 foreach (QPieSlice* s, slices) {
251 foreach (QPieSlice* s, slices) {
230 if (!s || d->m_slices.contains(s))
252 if (!s || d->m_slices.contains(s))
231 return false;
253 return false;
232 if (s->series()) // already added to some series
254 if (s->series()) // already added to some series
233 return false;
255 return false;
234 }
256 }
235
257
236 foreach (QPieSlice* s, slices) {
258 foreach (QPieSlice* s, slices) {
237 s->setParent(this);
259 s->setParent(this);
238 QPieSlicePrivate::fromSlice(s)->m_series = this;
260 QPieSlicePrivate::fromSlice(s)->m_series = this;
239 d->m_slices << s;
261 d->m_slices << s;
240 }
262 }
241
263
242 d->updateDerivativeData();
264 d->updateDerivativeData();
243
265
244 foreach (QPieSlice* s, slices) {
266 foreach (QPieSlice* s, slices) {
245 connect(s, SIGNAL(valueChanged()), d, SLOT(sliceValueChanged()));
267 connect(s, SIGNAL(valueChanged()), d, SLOT(sliceValueChanged()));
246 connect(s, SIGNAL(clicked()), d, SLOT(sliceClicked()));
268 connect(s, SIGNAL(clicked()), d, SLOT(sliceClicked()));
247 connect(s, SIGNAL(hovered(bool)), d, SLOT(sliceHovered(bool)));
269 connect(s, SIGNAL(hovered(bool)), d, SLOT(sliceHovered(bool)));
248 }
270 }
249
271
250 emit added(slices);
272 emit added(slices);
251 emit countChanged();
273 emit countChanged();
252
274
253 return true;
275 return true;
254 }
276 }
255
277
256 /*!
278 /*!
257 Appends a single \a slice to the series and returns a reference to the series.
279 Appends a single \a slice to the series and returns a reference to the series.
258 Slice ownership is passed to the series.
280 Slice ownership is passed to the series.
259 */
281 */
260 QPieSeries& QPieSeries::operator << (QPieSlice* slice)
282 QPieSeries& QPieSeries::operator << (QPieSlice* slice)
261 {
283 {
262 append(slice);
284 append(slice);
263 return *this;
285 return *this;
264 }
286 }
265
287
266
288
267 /*!
289 /*!
268 Appends a single slice to the series with give \a value and \a label.
290 Appends a single slice to the series with give \a value and \a label.
269 Slice ownership is passed to the series.
291 Slice ownership is passed to the series.
270 */
292 */
271 QPieSlice* QPieSeries::append(QString label, qreal value)
293 QPieSlice* QPieSeries::append(QString label, qreal value)
272 {
294 {
273 QPieSlice* slice = new QPieSlice(label, value);
295 QPieSlice* slice = new QPieSlice(label, value);
274 append(slice);
296 append(slice);
275 return slice;
297 return slice;
276 }
298 }
277
299
278 /*!
300 /*!
279 Inserts a single \a slice to the series before the slice at \a index position.
301 Inserts a single \a slice to the series before the slice at \a index position.
280 Slice ownership is passed to the series.
302 Slice ownership is passed to the series.
281
303
282 Returns true if insert was successfull.
304 Returns true if insert was successfull.
283 */
305 */
284 bool QPieSeries::insert(int index, QPieSlice* slice)
306 bool QPieSeries::insert(int index, QPieSlice* slice)
285 {
307 {
286 Q_D(QPieSeries);
308 Q_D(QPieSeries);
287
309
288 if (index < 0 || index > d->m_slices.count())
310 if (index < 0 || index > d->m_slices.count())
289 return false;
311 return false;
290
312
291 if (!slice || d->m_slices.contains(slice))
313 if (!slice || d->m_slices.contains(slice))
292 return false;
314 return false;
293
315
294 if (slice->series()) // already added to some series
316 if (slice->series()) // already added to some series
295 return false;
317 return false;
296
318
297 slice->setParent(this);
319 slice->setParent(this);
298 QPieSlicePrivate::fromSlice(slice)->m_series = this;
320 QPieSlicePrivate::fromSlice(slice)->m_series = this;
299 d->m_slices.insert(index, slice);
321 d->m_slices.insert(index, slice);
300
322
301 d->updateDerivativeData();
323 d->updateDerivativeData();
302
324
303 connect(slice, SIGNAL(valueChanged()), d, SLOT(sliceValueChanged()));
325 connect(slice, SIGNAL(valueChanged()), d, SLOT(sliceValueChanged()));
304 connect(slice, SIGNAL(clicked()), d, SLOT(sliceClicked()));
326 connect(slice, SIGNAL(clicked()), d, SLOT(sliceClicked()));
305 connect(slice, SIGNAL(hovered(bool)), d, SLOT(sliceHovered(bool)));
327 connect(slice, SIGNAL(hovered(bool)), d, SLOT(sliceHovered(bool)));
306
328
307 emit added(QList<QPieSlice*>() << slice);
329 emit added(QList<QPieSlice*>() << slice);
308 emit countChanged();
330 emit countChanged();
309
331
310 return true;
332 return true;
311 }
333 }
312
334
313 /*!
335 /*!
314 Removes a single \a slice from the series and deletes the slice.
336 Removes a single \a slice from the series and deletes the slice.
315
337
316 Do not reference the pointer after this call.
338 Do not reference the pointer after this call.
317
339
318 Returns true if remove was successfull.
340 Returns true if remove was successfull.
319 */
341 */
320 bool QPieSeries::remove(QPieSlice* slice)
342 bool QPieSeries::remove(QPieSlice* slice)
321 {
343 {
322 Q_D(QPieSeries);
344 Q_D(QPieSeries);
323
345
324 if (!d->m_slices.removeOne(slice))
346 if (!d->m_slices.removeOne(slice))
325 return false;
347 return false;
326
348
327 d->updateDerivativeData();
349 d->updateDerivativeData();
328
350
329 emit removed(QList<QPieSlice*>() << slice);
351 emit removed(QList<QPieSlice*>() << slice);
330 emit countChanged();
352 emit countChanged();
331
353
332 delete slice;
354 delete slice;
333 slice = 0;
355 slice = 0;
334
356
335 return true;
357 return true;
336 }
358 }
337
359
338 /*!
360 /*!
339 Clears all slices from the series.
361 Clears all slices from the series.
340 */
362 */
341 void QPieSeries::clear()
363 void QPieSeries::clear()
342 {
364 {
343 Q_D(QPieSeries);
365 Q_D(QPieSeries);
344 if (d->m_slices.count() == 0)
366 if (d->m_slices.count() == 0)
345 return;
367 return;
346
368
347 QList<QPieSlice*> slices = d->m_slices;
369 QList<QPieSlice*> slices = d->m_slices;
348 foreach (QPieSlice* s, d->m_slices) {
370 foreach (QPieSlice* s, d->m_slices) {
349 d->m_slices.removeOne(s);
371 d->m_slices.removeOne(s);
350 delete s;
372 delete s;
351 }
373 }
352
374
353 d->updateDerivativeData();
375 d->updateDerivativeData();
354
376
355 emit removed(slices);
377 emit removed(slices);
356 emit countChanged();
378 emit countChanged();
357 }
379 }
358
380
359 /*!
381 /*!
360 Returns a list of slices that belong to this series.
382 Returns a list of slices that belong to this series.
361 */
383 */
362 QList<QPieSlice*> QPieSeries::slices() const
384 QList<QPieSlice*> QPieSeries::slices() const
363 {
385 {
364 Q_D(const QPieSeries);
386 Q_D(const QPieSeries);
365 return d->m_slices;
387 return d->m_slices;
366 }
388 }
367
389
368 /*!
390 /*!
369 returns the number of the slices in this series.
391 returns the number of the slices in this series.
370 */
392 */
371 int QPieSeries::count() const
393 int QPieSeries::count() const
372 {
394 {
373 Q_D(const QPieSeries);
395 Q_D(const QPieSeries);
374 return d->m_slices.count();
396 return d->m_slices.count();
375 }
397 }
376
398
377 /*!
399 /*!
378 Returns true is the series is empty.
400 Returns true is the series is empty.
379 */
401 */
380 bool QPieSeries::isEmpty() const
402 bool QPieSeries::isEmpty() const
381 {
403 {
382 Q_D(const QPieSeries);
404 Q_D(const QPieSeries);
383 return d->m_slices.isEmpty();
405 return d->m_slices.isEmpty();
384 }
406 }
385
407
386 /*!
408 /*!
387 Returns the sum of all slice values in this series.
409 Returns the sum of all slice values in this series.
388
410
389 \sa QPieSlice::value(), QPieSlice::setValue(), QPieSlice::percentage()
411 \sa QPieSlice::value(), QPieSlice::setValue(), QPieSlice::percentage()
390 */
412 */
391 qreal QPieSeries::sum() const
413 qreal QPieSeries::sum() const
392 {
414 {
393 Q_D(const QPieSeries);
415 Q_D(const QPieSeries);
394 return d->m_sum;
416 return d->m_sum;
395 }
417 }
396
418
397 void QPieSeries::setHorizontalPosition(qreal relativePosition)
419 void QPieSeries::setHorizontalPosition(qreal relativePosition)
398 {
420 {
399 Q_D(QPieSeries);
421 Q_D(QPieSeries);
400
422
401 if (relativePosition < 0.0)
423 if (relativePosition < 0.0)
402 relativePosition = 0.0;
424 relativePosition = 0.0;
403 if (relativePosition > 1.0)
425 if (relativePosition > 1.0)
404 relativePosition = 1.0;
426 relativePosition = 1.0;
405
427
406 if (!qFuzzyIsNull(d->m_pieRelativeHorPos - relativePosition)) {
428 if (!qFuzzyIsNull(d->m_pieRelativeHorPos - relativePosition)) {
407 d->m_pieRelativeHorPos = relativePosition;
429 d->m_pieRelativeHorPos = relativePosition;
408 emit d->horizontalPositionChanged();
430 emit d->horizontalPositionChanged();
409 }
431 }
410 }
432 }
411
433
412 qreal QPieSeries::horizontalPosition() const
434 qreal QPieSeries::horizontalPosition() const
413 {
435 {
414 Q_D(const QPieSeries);
436 Q_D(const QPieSeries);
415 return d->m_pieRelativeHorPos;
437 return d->m_pieRelativeHorPos;
416 }
438 }
417
439
418 void QPieSeries::setVerticalPosition(qreal relativePosition)
440 void QPieSeries::setVerticalPosition(qreal relativePosition)
419 {
441 {
420 Q_D(QPieSeries);
442 Q_D(QPieSeries);
421
443
422 if (relativePosition < 0.0)
444 if (relativePosition < 0.0)
423 relativePosition = 0.0;
445 relativePosition = 0.0;
424 if (relativePosition > 1.0)
446 if (relativePosition > 1.0)
425 relativePosition = 1.0;
447 relativePosition = 1.0;
426
448
427 if (!qFuzzyIsNull(d->m_pieRelativeVerPos - relativePosition)) {
449 if (!qFuzzyIsNull(d->m_pieRelativeVerPos - relativePosition)) {
428 d->m_pieRelativeVerPos = relativePosition;
450 d->m_pieRelativeVerPos = relativePosition;
429 emit d->verticalPositionChanged();
451 emit d->verticalPositionChanged();
430 }
452 }
431 }
453 }
432
454
433 qreal QPieSeries::verticalPosition() const
455 qreal QPieSeries::verticalPosition() const
434 {
456 {
435 Q_D(const QPieSeries);
457 Q_D(const QPieSeries);
436 return d->m_pieRelativeVerPos;
458 return d->m_pieRelativeVerPos;
437 }
459 }
438
460
439 void QPieSeries::setPieSize(qreal relativeSize)
461 void QPieSeries::setPieSize(qreal relativeSize)
440 {
462 {
441 Q_D(QPieSeries);
463 Q_D(QPieSeries);
442
464
443 if (relativeSize < 0.0)
465 if (relativeSize < 0.0)
444 relativeSize = 0.0;
466 relativeSize = 0.0;
445 if (relativeSize > 1.0)
467 if (relativeSize > 1.0)
446 relativeSize = 1.0;
468 relativeSize = 1.0;
447
469
448 if (!qFuzzyIsNull(d->m_pieRelativeSize - relativeSize)) {
470 if (!qFuzzyIsNull(d->m_pieRelativeSize - relativeSize)) {
449 d->m_pieRelativeSize = relativeSize;
471 d->m_pieRelativeSize = relativeSize;
450 emit d->pieSizeChanged();
472 emit d->pieSizeChanged();
451 }
473 }
452 }
474 }
453
475
454 qreal QPieSeries::pieSize() const
476 qreal QPieSeries::pieSize() const
455 {
477 {
456 Q_D(const QPieSeries);
478 Q_D(const QPieSeries);
457 return d->m_pieRelativeSize;
479 return d->m_pieRelativeSize;
458 }
480 }
459
481
460
482
461 void QPieSeries::setPieStartAngle(qreal angle)
483 void QPieSeries::setPieStartAngle(qreal angle)
462 {
484 {
463 Q_D(QPieSeries);
485 Q_D(QPieSeries);
464 if (qFuzzyIsNull(d->m_pieStartAngle - angle))
486 if (qFuzzyIsNull(d->m_pieStartAngle - angle))
465 return;
487 return;
466 d->m_pieStartAngle = angle;
488 d->m_pieStartAngle = angle;
467 d->updateDerivativeData();
489 d->updateDerivativeData();
468 emit d->pieStartAngleChanged();
490 emit d->pieStartAngleChanged();
469 }
491 }
470
492
471 qreal QPieSeries::pieStartAngle() const
493 qreal QPieSeries::pieStartAngle() const
472 {
494 {
473 Q_D(const QPieSeries);
495 Q_D(const QPieSeries);
474 return d->m_pieStartAngle;
496 return d->m_pieStartAngle;
475 }
497 }
476
498
477 /*!
499 /*!
478 Sets the end angle of the pie.
500 Sets the end angle of the pie.
479
501
480 Full pie is 360 degrees where 0 degrees is at 12 a'clock.
502 Full pie is 360 degrees where 0 degrees is at 12 a'clock.
481
503
482 \a angle must be greater than start angle.
504 \a angle must be greater than start angle.
483
505
484 \sa pieEndAngle(), pieStartAngle(), setPieStartAngle()
506 \sa pieEndAngle(), pieStartAngle(), setPieStartAngle()
485 */
507 */
486 void QPieSeries::setPieEndAngle(qreal angle)
508 void QPieSeries::setPieEndAngle(qreal angle)
487 {
509 {
488 Q_D(QPieSeries);
510 Q_D(QPieSeries);
489 if (qFuzzyIsNull(d->m_pieEndAngle - angle))
511 if (qFuzzyIsNull(d->m_pieEndAngle - angle))
490 return;
512 return;
491 d->m_pieEndAngle = angle;
513 d->m_pieEndAngle = angle;
492 d->updateDerivativeData();
514 d->updateDerivativeData();
493 emit d->pieEndAngleChanged();
515 emit d->pieEndAngleChanged();
494 }
516 }
495
517
496 /*!
518 /*!
497 Returns the end angle of the pie.
519 Returns the end angle of the pie.
498
520
499 Full pie is 360 degrees where 0 degrees is at 12 a'clock.
521 Full pie is 360 degrees where 0 degrees is at 12 a'clock.
500
522
501 \sa setPieEndAngle(), pieStartAngle(), setPieStartAngle()
523 \sa setPieEndAngle(), pieStartAngle(), setPieStartAngle()
502 */
524 */
503 qreal QPieSeries::pieEndAngle() const
525 qreal QPieSeries::pieEndAngle() const
504 {
526 {
505 Q_D(const QPieSeries);
527 Q_D(const QPieSeries);
506 return d->m_pieEndAngle;
528 return d->m_pieEndAngle;
507 }
529 }
508
530
509 /*!
531 /*!
510 Sets the all the slice labels \a visible or invisible.
532 Sets the all the slice labels \a visible or invisible.
511
533
512 Note that this affects only the current slices in the series.
534 Note that this affects only the current slices in the series.
513 If user adds a new slice the default label visibility is false.
535 If user adds a new slice the default label visibility is false.
514
536
515 \sa QPieSlice::isLabelVisible(), QPieSlice::setLabelVisible()
537 \sa QPieSlice::isLabelVisible(), QPieSlice::setLabelVisible()
516 */
538 */
517 void QPieSeries::setLabelsVisible(bool visible)
539 void QPieSeries::setLabelsVisible(bool visible)
518 {
540 {
519 Q_D(QPieSeries);
541 Q_D(QPieSeries);
520 foreach (QPieSlice* s, d->m_slices)
542 foreach (QPieSlice* s, d->m_slices)
521 s->setLabelVisible(visible);
543 s->setLabelVisible(visible);
522 }
544 }
523
545
524 ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
546 ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
525
547
526
548
527 QPieSeriesPrivate::QPieSeriesPrivate(QPieSeries *parent) :
549 QPieSeriesPrivate::QPieSeriesPrivate(QPieSeries *parent) :
528 QAbstractSeriesPrivate(parent),
550 QAbstractSeriesPrivate(parent),
529 m_pieRelativeHorPos(0.5),
551 m_pieRelativeHorPos(0.5),
530 m_pieRelativeVerPos(0.5),
552 m_pieRelativeVerPos(0.5),
531 m_pieRelativeSize(0.7),
553 m_pieRelativeSize(0.7),
532 m_pieStartAngle(0),
554 m_pieStartAngle(0),
533 m_pieEndAngle(360),
555 m_pieEndAngle(360),
534 m_sum(0)
556 m_sum(0)
535 {
557 {
536 }
558 }
537
559
538 QPieSeriesPrivate::~QPieSeriesPrivate()
560 QPieSeriesPrivate::~QPieSeriesPrivate()
539 {
561 {
540 }
562 }
541
563
542 void QPieSeriesPrivate::updateDerivativeData()
564 void QPieSeriesPrivate::updateDerivativeData()
543 {
565 {
544 // calculate sum of all slices
566 // calculate sum of all slices
545 qreal sum = 0;
567 qreal sum = 0;
546 foreach (QPieSlice* s, m_slices)
568 foreach (QPieSlice* s, m_slices)
547 sum += s->value();
569 sum += s->value();
548
570
549 if (!qFuzzyIsNull(m_sum - sum)) {
571 if (!qFuzzyIsNull(m_sum - sum)) {
550 m_sum = sum;
572 m_sum = sum;
551 emit q_func()->sumChanged();
573 emit q_func()->sumChanged();
552 }
574 }
553
575
554 // nothing to show..
576 // nothing to show..
555 if (qFuzzyIsNull(m_sum))
577 if (qFuzzyIsNull(m_sum))
556 return;
578 return;
557
579
558 // update slice attributes
580 // update slice attributes
559 qreal sliceAngle = m_pieStartAngle;
581 qreal sliceAngle = m_pieStartAngle;
560 qreal pieSpan = m_pieEndAngle - m_pieStartAngle;
582 qreal pieSpan = m_pieEndAngle - m_pieStartAngle;
561 QVector<QPieSlice*> changed;
583 QVector<QPieSlice*> changed;
562 foreach (QPieSlice* s, m_slices) {
584 foreach (QPieSlice* s, m_slices) {
563 QPieSlicePrivate *d = QPieSlicePrivate::fromSlice(s);
585 QPieSlicePrivate *d = QPieSlicePrivate::fromSlice(s);
564 d->setPercentage(s->value() / m_sum);
586 d->setPercentage(s->value() / m_sum);
565 d->setStartAngle(sliceAngle);
587 d->setStartAngle(sliceAngle);
566 d->setAngleSpan(pieSpan * s->percentage());
588 d->setAngleSpan(pieSpan * s->percentage());
567 sliceAngle += s->angleSpan();
589 sliceAngle += s->angleSpan();
568 }
590 }
569
591
570
592
571 emit calculatedDataChanged();
593 emit calculatedDataChanged();
572 }
594 }
573
595
574 QPieSeriesPrivate* QPieSeriesPrivate::fromSeries(QPieSeries *series)
596 QPieSeriesPrivate* QPieSeriesPrivate::fromSeries(QPieSeries *series)
575 {
597 {
576 return series->d_func();
598 return series->d_func();
577 }
599 }
578
600
579 void QPieSeriesPrivate::sliceValueChanged()
601 void QPieSeriesPrivate::sliceValueChanged()
580 {
602 {
581 Q_ASSERT(m_slices.contains(qobject_cast<QPieSlice *>(sender())));
603 Q_ASSERT(m_slices.contains(qobject_cast<QPieSlice *>(sender())));
582 updateDerivativeData();
604 updateDerivativeData();
583 }
605 }
584
606
585 void QPieSeriesPrivate::sliceClicked()
607 void QPieSeriesPrivate::sliceClicked()
586 {
608 {
587 QPieSlice* slice = qobject_cast<QPieSlice *>(sender());
609 QPieSlice* slice = qobject_cast<QPieSlice *>(sender());
588 Q_ASSERT(m_slices.contains(slice));
610 Q_ASSERT(m_slices.contains(slice));
589 Q_Q(QPieSeries);
611 Q_Q(QPieSeries);
590 emit q->clicked(slice);
612 emit q->clicked(slice);
591 }
613 }
592
614
593 void QPieSeriesPrivate::sliceHovered(bool state)
615 void QPieSeriesPrivate::sliceHovered(bool state)
594 {
616 {
595 QPieSlice* slice = qobject_cast<QPieSlice *>(sender());
617 QPieSlice* slice = qobject_cast<QPieSlice *>(sender());
596 Q_ASSERT(m_slices.contains(slice));
618 Q_ASSERT(m_slices.contains(slice));
597 Q_Q(QPieSeries);
619 Q_Q(QPieSeries);
598 emit q->hovered(slice, state);
620 emit q->hovered(slice, state);
599 }
621 }
600
622
601 void QPieSeriesPrivate::scaleDomain(Domain& domain)
623 void QPieSeriesPrivate::scaleDomain(Domain& domain)
602 {
624 {
603 Q_UNUSED(domain);
625 Q_UNUSED(domain);
604 // does not apply to pie
626 // does not apply to pie
605 }
627 }
606
628
607 Chart* QPieSeriesPrivate::createGraphics(ChartPresenter* presenter)
629 Chart* QPieSeriesPrivate::createGraphics(ChartPresenter* presenter)
608 {
630 {
609 Q_Q(QPieSeries);
631 Q_Q(QPieSeries);
610 PieChartItem* pie = new PieChartItem(q,presenter);
632 PieChartItem* pie = new PieChartItem(q,presenter);
611 if(presenter->animationOptions().testFlag(QChart::SeriesAnimations)) {
633 if(presenter->animationOptions().testFlag(QChart::SeriesAnimations)) {
612 presenter->animator()->addAnimation(pie);
634 presenter->animator()->addAnimation(pie);
613 }
635 }
614 presenter->chartTheme()->decorate(q, presenter->dataSet()->seriesIndex(q));
636 presenter->chartTheme()->decorate(q, presenter->dataSet()->seriesIndex(q));
615 return pie;
637 return pie;
616 }
638 }
617
639
618 QList<LegendMarker*> QPieSeriesPrivate::createLegendMarker(QLegend* legend)
640 QList<LegendMarker*> QPieSeriesPrivate::createLegendMarker(QLegend* legend)
619 {
641 {
620 Q_Q(QPieSeries);
642 Q_Q(QPieSeries);
621 QList<LegendMarker*> markers;
643 QList<LegendMarker*> markers;
622 foreach(QPieSlice* slice, q->slices()) {
644 foreach(QPieSlice* slice, q->slices()) {
623 PieLegendMarker* marker = new PieLegendMarker(q,slice,legend);
645 PieLegendMarker* marker = new PieLegendMarker(q,slice,legend);
624 markers << marker;
646 markers << marker;
625 }
647 }
626 return markers;
648 return markers;
627 }
649 }
628
650
629 #include "moc_qpieseries.cpp"
651 #include "moc_qpieseries.cpp"
630 #include "moc_qpieseries_p.cpp"
652 #include "moc_qpieseries_p.cpp"
631
653
632 QTCOMMERCIALCHART_END_NAMESPACE
654 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,207 +1,232
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 "qscatterseries.h"
21 #include "qscatterseries.h"
22 #include "qscatterseries_p.h"
22 #include "qscatterseries_p.h"
23 #include "scatterchartitem_p.h"
23 #include "scatterchartitem_p.h"
24 #include "chartdataset_p.h"
24 #include "chartdataset_p.h"
25 #include "charttheme_p.h"
25 #include "charttheme_p.h"
26 #include "chartanimator_p.h"
26 #include "chartanimator_p.h"
27
27
28 /*!
28 /*!
29 \class QScatterSeries
29 \class QScatterSeries
30 \brief The QScatterSeries class is used for making scatter charts.
30 \brief The QScatterSeries class is used for making scatter charts.
31
31
32 \mainclass
32 \mainclass
33
33
34 The scatter data is displayed as a collection of points on the chart. Each point determines the position on the horizontal axis
34 The scatter data is displayed as a collection of points on the chart. Each point determines the position on the horizontal axis
35 and the vertical axis.
35 and the vertical axis.
36
36
37 \image examples_scatterchart.png
37 \image examples_scatterchart.png
38
38
39 Creating basic scatter chart is simple:
39 Creating basic scatter chart is simple:
40 \code
40 \code
41 QScatterSeries* series = new QScatterSeries();
41 QScatterSeries* series = new QScatterSeries();
42 series->append(0, 6);
42 series->append(0, 6);
43 series->append(2, 4);
43 series->append(2, 4);
44 ...
44 ...
45 chart->addSeries(series);
45 chart->addSeries(series);
46 \endcode
46 \endcode
47 */
47 */
48 /*!
49 \qmlclass ScatterSeries QScatterSeries
50 \inherits XYSeries
51
52 The following QML shows how to create a chart with two simple scatter series:
53 \snippet ../demos/qmlchart/qml/qmlchart/View5.qml 1
54 \snippet ../demos/qmlchart/qml/qmlchart/View5.qml 2
55
56 \beginfloatleft
57 \image demos_qmlchart5.png
58 \endfloat
59 \clearfloat
60 */
48
61
49 /*!
62 /*!
50 \enum QScatterSeries::MarkerShape
63 \enum QScatterSeries::MarkerShape
51
64
52 This enum describes the shape used when rendering marker items.
65 This enum describes the shape used when rendering marker items.
53
66
54 \value MarkerShapeCircle
67 \value MarkerShapeCircle
55 \value MarkerShapeRectangle
68 \value MarkerShapeRectangle
56 */
69 */
57
70
58 /*!
71 /*!
59 \property QScatterSeries::color
72 \property QScatterSeries::color
60 Fill (brush) color of the series. This is a convenience property for modifying the color of brush.
73 Fill (brush) color of the series. This is a convenience property for modifying the color of brush.
61 \sa QScatterSeries::brush()
74 \sa QScatterSeries::brush()
62 */
75 */
63
76
64 /*!
77 /*!
65 \property QScatterSeries::borderColor
78 \property QScatterSeries::borderColor
66 Line (pen) color of the series. This is a convenience property for modifying the color of pen.
79 Line (pen) color of the series. This is a convenience property for modifying the color of pen.
67 \sa QScatterSeries::pen()
80 \sa QScatterSeries::pen()
68 */
81 */
69
82
70 /*!
83 /*!
71 \property QScatterSeries::markerShape
84 \property QScatterSeries::markerShape
72
85 Defines the shape of the marker used to draw the points in the series. The default shape is MarkerShapeCircle.
73 Defines the shape of the marker used to draw the points in the series. The default shape is MarkerShapeCircle.
74 */
86 */
75
76 /*!
87 /*!
77 \property QScatterSeries::markerSize
88 \qmlproperty MarkerShape ScatterSeries::markerShape
89 Defines the shape of the marker used to draw the points in the series. One of ScatterSeries
90 ScatterSeries.MarkerShapeCircle or ScatterSeries.MarkerShapeRectangle.
91 The default shape is ScatterSeries.MarkerShapeCircle.
92 */
78
93
79 Defines the size of the marker used to draw the points in the series. The default size is 15.0.
94 /*!
95 \property QScatterSeries::markerSize
96 Defines the size of the marker used to draw the points in the series. The default size is 15.0.
97 */
98 /*!
99 \qmlproperty real ScatterSeries::markerSize
100 Defines the size of the marker used to draw the points in the series. The default size is 15.0.
80 */
101 */
81
102
82 /*!
103 /*!
83 \fn void QScatterSeries::colorChanged(QColor color)
104 \fn void QScatterSeries::colorChanged(QColor color)
84 \brief Signal is emitted when the fill (brush) color has changed to \a color.
105 Signal is emitted when the fill (brush) color has changed to \a color.
85 */
106 */
86
107
87 /*!
108 /*!
88 \fn void QScatterSeries::borderColorChanged(QColor color)
109 \fn void QScatterSeries::borderColorChanged(QColor color)
89 \brief Signal is emitted when the line (pen) color has changed to \a color.
110 Signal is emitted when the line (pen) color has changed to \a color.
111 */
112 /*!
113 \qmlsignal ScatterSeries::borderColorChanged(color color)
114 Signal is emitted when the line (pen) color has changed to \a color.
90 */
115 */
91
116
92 /*!
117 /*!
93 \fn QChartSeriesType QScatterSeries::type() const
118 \fn QChartSeriesType QScatterSeries::type() const
94 \brief Returns QChartSeries::SeriesTypeScatter.
119 Returns QChartSeries::SeriesTypeScatter.
95 \sa QAbstractSeries, SeriesType
120 \sa QAbstractSeries, SeriesType
96 */
121 */
97
122
98 QTCOMMERCIALCHART_BEGIN_NAMESPACE
123 QTCOMMERCIALCHART_BEGIN_NAMESPACE
99
124
100 /*!
125 /*!
101 Constructs a series object which is a child of \a parent.
126 Constructs a series object which is a child of \a parent.
102 */
127 */
103 QScatterSeries::QScatterSeries(QObject *parent) : QXYSeries(*new QScatterSeriesPrivate(this),parent)
128 QScatterSeries::QScatterSeries(QObject *parent) : QXYSeries(*new QScatterSeriesPrivate(this),parent)
104 {
129 {
105 }
130 }
106
131
107 /*!
132 /*!
108 Destroys the object. Note that adding series to QChart transfers the ownership to the chart.
133 Destroys the object. Note that adding series to QChart transfers the ownership to the chart.
109 */
134 */
110 QScatterSeries::~QScatterSeries()
135 QScatterSeries::~QScatterSeries()
111 {
136 {
112 Q_D(QScatterSeries);
137 Q_D(QScatterSeries);
113 if(d->m_dataset) {
138 if(d->m_dataset) {
114 d->m_dataset->removeSeries(this);
139 d->m_dataset->removeSeries(this);
115 }
140 }
116 }
141 }
117
142
118 QAbstractSeries::SeriesType QScatterSeries::type() const
143 QAbstractSeries::SeriesType QScatterSeries::type() const
119 {
144 {
120 return QAbstractSeries::SeriesTypeScatter;
145 return QAbstractSeries::SeriesTypeScatter;
121 }
146 }
122
147
123 void QScatterSeries::setColor(const QColor &color)
148 void QScatterSeries::setColor(const QColor &color)
124 {
149 {
125 QBrush b = brush();
150 QBrush b = brush();
126 if (b.color() != color) {
151 if (b.color() != color) {
127 b.setColor(color);
152 b.setColor(color);
128 setBrush(b);
153 setBrush(b);
129 emit colorChanged(color);
154 emit colorChanged(color);
130 }
155 }
131 }
156 }
132
157
133 QColor QScatterSeries::color() const
158 QColor QScatterSeries::color() const
134 {
159 {
135 return brush().color();
160 return brush().color();
136 }
161 }
137
162
138 void QScatterSeries::setBorderColor(const QColor &color)
163 void QScatterSeries::setBorderColor(const QColor &color)
139 {
164 {
140 QPen p = pen();
165 QPen p = pen();
141 if (p.color() != color) {
166 if (p.color() != color) {
142 p.setColor(color);
167 p.setColor(color);
143 setPen(p);
168 setPen(p);
144 emit borderColorChanged(color);
169 emit borderColorChanged(color);
145 }
170 }
146 }
171 }
147
172
148 QColor QScatterSeries::borderColor() const
173 QColor QScatterSeries::borderColor() const
149 {
174 {
150 return pen().color();
175 return pen().color();
151 }
176 }
152
177
153 QScatterSeries::MarkerShape QScatterSeries::markerShape() const
178 QScatterSeries::MarkerShape QScatterSeries::markerShape() const
154 {
179 {
155 Q_D(const QScatterSeries);
180 Q_D(const QScatterSeries);
156 return d->m_shape;
181 return d->m_shape;
157 }
182 }
158
183
159 void QScatterSeries::setMarkerShape(MarkerShape shape)
184 void QScatterSeries::setMarkerShape(MarkerShape shape)
160 {
185 {
161 Q_D(QScatterSeries);
186 Q_D(QScatterSeries);
162 if (d->m_shape != shape) {
187 if (d->m_shape != shape) {
163 d->m_shape = shape;
188 d->m_shape = shape;
164 emit d->updated();
189 emit d->updated();
165 }
190 }
166 }
191 }
167
192
168 qreal QScatterSeries::markerSize() const
193 qreal QScatterSeries::markerSize() const
169 {
194 {
170 Q_D(const QScatterSeries);
195 Q_D(const QScatterSeries);
171 return d->m_size;
196 return d->m_size;
172 }
197 }
173
198
174 void QScatterSeries::setMarkerSize(qreal size)
199 void QScatterSeries::setMarkerSize(qreal size)
175 {
200 {
176 Q_D(QScatterSeries);
201 Q_D(QScatterSeries);
177
202
178 if (!qFuzzyIsNull(d->m_size - size)) {
203 if (!qFuzzyIsNull(d->m_size - size)) {
179 d->m_size = size;
204 d->m_size = size;
180 emit d->updated();
205 emit d->updated();
181 }
206 }
182 }
207 }
183
208
184 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
209 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
185
210
186 QScatterSeriesPrivate::QScatterSeriesPrivate(QScatterSeries* q):QXYSeriesPrivate(q),
211 QScatterSeriesPrivate::QScatterSeriesPrivate(QScatterSeries* q):QXYSeriesPrivate(q),
187 m_shape(QScatterSeries::MarkerShapeCircle),
212 m_shape(QScatterSeries::MarkerShapeCircle),
188 m_size(15.0)
213 m_size(15.0)
189 {
214 {
190
215
191 };
216 };
192
217
193 Chart* QScatterSeriesPrivate::createGraphics(ChartPresenter* presenter)
218 Chart* QScatterSeriesPrivate::createGraphics(ChartPresenter* presenter)
194 {
219 {
195 Q_Q(QScatterSeries);
220 Q_Q(QScatterSeries);
196 ScatterChartItem *scatter = new ScatterChartItem(q,presenter);
221 ScatterChartItem *scatter = new ScatterChartItem(q,presenter);
197 if(presenter->animationOptions().testFlag(QChart::SeriesAnimations)) {
222 if(presenter->animationOptions().testFlag(QChart::SeriesAnimations)) {
198 scatter->setAnimator(presenter->animator());
223 scatter->setAnimator(presenter->animator());
199 scatter->setAnimation(new XYAnimation(scatter));
224 scatter->setAnimation(new XYAnimation(scatter));
200 }
225 }
201 presenter->chartTheme()->decorate(q, presenter->dataSet()->seriesIndex(q));
226 presenter->chartTheme()->decorate(q, presenter->dataSet()->seriesIndex(q));
202 return scatter;
227 return scatter;
203 }
228 }
204
229
205 #include "moc_qscatterseries.cpp"
230 #include "moc_qscatterseries.cpp"
206
231
207 QTCOMMERCIALCHART_END_NAMESPACE
232 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,224 +1,236
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 "qsplineseries.h"
21 #include "qsplineseries.h"
22 #include "qsplineseries_p.h"
22 #include "qsplineseries_p.h"
23 #include "splinechartitem_p.h"
23 #include "splinechartitem_p.h"
24 #include "chartdataset_p.h"
24 #include "chartdataset_p.h"
25 #include "charttheme_p.h"
25 #include "charttheme_p.h"
26 #include "chartanimator_p.h"
26 #include "chartanimator_p.h"
27
27
28 /*!
28 /*!
29 \class QSplineSeries
29 \class QSplineSeries
30 \brief Series type used to store data needed to draw a spline.
30 \brief Series type used to store data needed to draw a spline.
31
31
32 QSplineSeries stores the data points along with the segment control points needed by QPainterPath to draw spline
32 QSplineSeries stores the data points along with the segment control points needed by QPainterPath to draw spline
33 Control points are automatically calculated when data changes. The algorithm computes the points so that the normal spline can be drawn.
33 Control points are automatically calculated when data changes. The algorithm computes the points so that the normal spline can be drawn.
34
34
35 \image examples_splinechart.png
35 \image examples_splinechart.png
36
36
37 Creating basic spline chart is simple:
37 Creating basic spline chart is simple:
38 \code
38 \code
39 QSplineSeries* series = new QSplineSeries();
39 QSplineSeries* series = new QSplineSeries();
40 series->append(0, 6);
40 series->append(0, 6);
41 series->append(2, 4);
41 series->append(2, 4);
42 ...
42 ...
43 chart->addSeries(series);
43 chart->addSeries(series);
44 \endcode
44 \endcode
45 */
45 */
46
46
47 /*!
47 /*!
48 \fn QSeriesType QSplineSeries::type() const
48 \qmlclass SplineSeries QSplineSeries
49 Returns the type of the series
49 \inherits XYSeries
50 */
50
51 The following QML shows how to create a simple spline chart:
52 \snippet ../demos/qmlchart/qml/qmlchart/View3.qml 1
53 \beginfloatleft
54 \image demos_qmlchart3.png
55 \endfloat
56 \clearfloat
57 */
58
59 /*!
60 \fn QSeriesType QSplineSeries::type() const
61 Returns the type of the series
62 */
51
63
52 QTCOMMERCIALCHART_BEGIN_NAMESPACE
64 QTCOMMERCIALCHART_BEGIN_NAMESPACE
53
65
54 /*!
66 /*!
55 Constructs empty series object which is a child of \a parent.
67 Constructs empty series object which is a child of \a parent.
56 When series object is added to QChartView or QChart instance then the ownerships is transferred.
68 When series object is added to QChartView or QChart instance then the ownerships is transferred.
57 */
69 */
58
70
59 QSplineSeries::QSplineSeries(QObject *parent) :
71 QSplineSeries::QSplineSeries(QObject *parent) :
60 QLineSeries(*new QSplineSeriesPrivate(this),parent)
72 QLineSeries(*new QSplineSeriesPrivate(this),parent)
61 {
73 {
62 Q_D(QSplineSeries);
74 Q_D(QSplineSeries);
63 QObject::connect(this,SIGNAL(pointAdded(int)), d, SLOT(updateControlPoints()));
75 QObject::connect(this,SIGNAL(pointAdded(int)), d, SLOT(updateControlPoints()));
64 QObject::connect(this,SIGNAL(pointRemoved(int)), d, SLOT(updateControlPoints()));
76 QObject::connect(this,SIGNAL(pointRemoved(int)), d, SLOT(updateControlPoints()));
65 QObject::connect(this,SIGNAL(pointReplaced(int)), d, SLOT(updateControlPoints()));
77 QObject::connect(this,SIGNAL(pointReplaced(int)), d, SLOT(updateControlPoints()));
66 }
78 }
67
79
68 /*!
80 /*!
69 Destroys the object.
81 Destroys the object.
70 */
82 */
71 QSplineSeries::~QSplineSeries()
83 QSplineSeries::~QSplineSeries()
72 {
84 {
73 Q_D(QSplineSeries);
85 Q_D(QSplineSeries);
74 if(d->m_dataset){
86 if(d->m_dataset){
75 d->m_dataset->removeSeries(this);
87 d->m_dataset->removeSeries(this);
76 }
88 }
77 }
89 }
78
90
79 QAbstractSeries::SeriesType QSplineSeries::type() const
91 QAbstractSeries::SeriesType QSplineSeries::type() const
80 {
92 {
81 return QAbstractSeries::SeriesTypeSpline;
93 return QAbstractSeries::SeriesTypeSpline;
82 }
94 }
83
95
84 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
96 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
85
97
86 QSplineSeriesPrivate::QSplineSeriesPrivate(QSplineSeries* q):QLineSeriesPrivate(q)
98 QSplineSeriesPrivate::QSplineSeriesPrivate(QSplineSeries* q):QLineSeriesPrivate(q)
87 {
99 {
88 }
100 }
89
101
90 /*!
102 /*!
91 Calculates control points which are needed by QPainterPath.cubicTo function to draw the cubic Bezier cureve between two points.
103 Calculates control points which are needed by QPainterPath.cubicTo function to draw the cubic Bezier cureve between two points.
92 */
104 */
93 void QSplineSeriesPrivate::calculateControlPoints()
105 void QSplineSeriesPrivate::calculateControlPoints()
94 {
106 {
95 Q_Q(QSplineSeries);
107 Q_Q(QSplineSeries);
96
108
97 const QList<QPointF>& points = q->points();
109 const QList<QPointF>& points = q->points();
98
110
99 int n = points.count() - 1;
111 int n = points.count() - 1;
100
112
101 if (n == 1)
113 if (n == 1)
102 {
114 {
103 //for n==1
115 //for n==1
104 m_controlPoints[0].setX((2 * points[0].x() + points[1].x()) / 3);
116 m_controlPoints[0].setX((2 * points[0].x() + points[1].x()) / 3);
105 m_controlPoints[0].setY((2 * points[0].y() + points[1].y()) / 3);
117 m_controlPoints[0].setY((2 * points[0].y() + points[1].y()) / 3);
106 m_controlPoints[1].setX(2 * m_controlPoints[0].x() - points[0].x());
118 m_controlPoints[1].setX(2 * m_controlPoints[0].x() - points[0].x());
107 m_controlPoints[1].setY(2 * m_controlPoints[0].y() - points[0].y());
119 m_controlPoints[1].setY(2 * m_controlPoints[0].y() - points[0].y());
108 return;
120 return;
109 }
121 }
110
122
111 // Calculate first Bezier control points
123 // Calculate first Bezier control points
112 // Set of equations for P0 to Pn points.
124 // Set of equations for P0 to Pn points.
113 //
125 //
114 // | 2 1 0 0 ... 0 0 0 ... 0 0 0 | | P1_1 | | P0 + 2 * P1 |
126 // | 2 1 0 0 ... 0 0 0 ... 0 0 0 | | P1_1 | | P0 + 2 * P1 |
115 // | 1 4 1 0 ... 0 0 0 ... 0 0 0 | | P1_2 | | 4 * P1 + 2 * P2 |
127 // | 1 4 1 0 ... 0 0 0 ... 0 0 0 | | P1_2 | | 4 * P1 + 2 * P2 |
116 // | 0 1 4 1 ... 0 0 0 ... 0 0 0 | | P1_3 | | 4 * P2 + 2 * P3 |
128 // | 0 1 4 1 ... 0 0 0 ... 0 0 0 | | P1_3 | | 4 * P2 + 2 * P3 |
117 // | . . . . . . . . . . . . | | ... | | ... |
129 // | . . . . . . . . . . . . | | ... | | ... |
118 // | 0 0 0 0 ... 1 4 1 ... 0 0 0 | * | P1_i | = | 4 * P(i-1) + 2 * Pi |
130 // | 0 0 0 0 ... 1 4 1 ... 0 0 0 | * | P1_i | = | 4 * P(i-1) + 2 * Pi |
119 // | . . . . . . . . . . . . | | ... | | ... |
131 // | . . . . . . . . . . . . | | ... | | ... |
120 // | 0 0 0 0 0 0 0 0 ... 1 4 1 | | P1_(n-1)| | 4 * P(n-2) + 2 * P(n-1) |
132 // | 0 0 0 0 0 0 0 0 ... 1 4 1 | | P1_(n-1)| | 4 * P(n-2) + 2 * P(n-1) |
121 // | 0 0 0 0 0 0 0 0 ... 0 2 7 | | P1_n | | 8 * P(n-1) + Pn |
133 // | 0 0 0 0 0 0 0 0 ... 0 2 7 | | P1_n | | 8 * P(n-1) + Pn |
122 //
134 //
123 QVector<qreal> vector;
135 QVector<qreal> vector;
124 vector.resize(n);
136 vector.resize(n);
125
137
126 vector[0] = points[0].x() + 2 * points[1].x();
138 vector[0] = points[0].x() + 2 * points[1].x();
127
139
128
140
129 for (int i = 1; i < n - 1; ++i){
141 for (int i = 1; i < n - 1; ++i){
130 vector[i] = 4 * points[i].x() + 2 * points[i + 1].x();
142 vector[i] = 4 * points[i].x() + 2 * points[i + 1].x();
131 }
143 }
132
144
133 vector[n - 1] = (8 * points[n-1].x() + points[n].x()) / 2.0;
145 vector[n - 1] = (8 * points[n-1].x() + points[n].x()) / 2.0;
134
146
135 QVector<qreal> xControl = firstControlPoints(vector);
147 QVector<qreal> xControl = firstControlPoints(vector);
136
148
137 vector[0] = points[0].y() + 2 * points[1].y();
149 vector[0] = points[0].y() + 2 * points[1].y();
138
150
139 for (int i = 1; i < n - 1; ++i) {
151 for (int i = 1; i < n - 1; ++i) {
140 vector[i] = 4 * points[i].y() + 2 * points[i + 1].y();
152 vector[i] = 4 * points[i].y() + 2 * points[i + 1].y();
141 }
153 }
142
154
143 vector[n - 1] = (8 * points[n-1].y() + points[n].y()) / 2.0;
155 vector[n - 1] = (8 * points[n-1].y() + points[n].y()) / 2.0;
144
156
145 QVector<qreal> yControl = firstControlPoints(vector);
157 QVector<qreal> yControl = firstControlPoints(vector);
146
158
147 for (int i = 0,j =0; i < n; ++i, ++j) {
159 for (int i = 0,j =0; i < n; ++i, ++j) {
148
160
149 m_controlPoints[j].setX(xControl[i]);
161 m_controlPoints[j].setX(xControl[i]);
150 m_controlPoints[j].setY(yControl[i]);
162 m_controlPoints[j].setY(yControl[i]);
151
163
152 j++;
164 j++;
153
165
154 if (i < n - 1){
166 if (i < n - 1){
155 m_controlPoints[j].setX(2 * points[i+1].x() - xControl[i + 1]);
167 m_controlPoints[j].setX(2 * points[i+1].x() - xControl[i + 1]);
156 m_controlPoints[j].setY(2 * points[i+1].y() - yControl[i + 1]);
168 m_controlPoints[j].setY(2 * points[i+1].y() - yControl[i + 1]);
157 }else{
169 }else{
158 m_controlPoints[j].setX((points[n].x() + xControl[n - 1]) / 2);
170 m_controlPoints[j].setX((points[n].x() + xControl[n - 1]) / 2);
159 m_controlPoints[j].setY((points[n].y() + yControl[n - 1]) / 2);
171 m_controlPoints[j].setY((points[n].y() + yControl[n - 1]) / 2);
160 }
172 }
161 }
173 }
162 }
174 }
163
175
164 QVector<qreal> QSplineSeriesPrivate::firstControlPoints(const QVector<qreal>& vector)
176 QVector<qreal> QSplineSeriesPrivate::firstControlPoints(const QVector<qreal>& vector)
165 {
177 {
166 QVector<qreal> result;
178 QVector<qreal> result;
167
179
168 int count = vector.count();
180 int count = vector.count();
169 result.resize(count);
181 result.resize(count);
170 result[0] = vector[0] / 2.0;
182 result[0] = vector[0] / 2.0;
171
183
172 QVector<qreal> temp;
184 QVector<qreal> temp;
173 temp.resize(count);
185 temp.resize(count);
174 temp[0] = 0;
186 temp[0] = 0;
175
187
176 qreal b = 2.0;
188 qreal b = 2.0;
177
189
178 for (int i = 1; i < count; i++) {
190 for (int i = 1; i < count; i++) {
179 temp[i] = 1 / b;
191 temp[i] = 1 / b;
180 b = (i < count - 1 ? 4.0 : 3.5) - temp[i];
192 b = (i < count - 1 ? 4.0 : 3.5) - temp[i];
181 result[i]=(vector[i] - result[i - 1]) / b;
193 result[i]=(vector[i] - result[i - 1]) / b;
182 }
194 }
183 for (int i = 1; i < count; i++)
195 for (int i = 1; i < count; i++)
184 result[count - i - 1] -= temp[count - i] * result[count - i];
196 result[count - i - 1] -= temp[count - i] * result[count - i];
185
197
186 return result;
198 return result;
187 }
199 }
188
200
189 QPointF QSplineSeriesPrivate::controlPoint(int index) const
201 QPointF QSplineSeriesPrivate::controlPoint(int index) const
190 {
202 {
191 // Q_D(const QSplineSeries);
203 // Q_D(const QSplineSeries);
192 // return d->m_controlPoints[index];
204 // return d->m_controlPoints[index];
193 return m_controlPoints[index];
205 return m_controlPoints[index];
194 }
206 }
195
207
196 /*!
208 /*!
197 Updates the control points, besed on currently avaiable knots.
209 Updates the control points, besed on currently avaiable knots.
198 */
210 */
199 void QSplineSeriesPrivate::updateControlPoints()
211 void QSplineSeriesPrivate::updateControlPoints()
200 {
212 {
201 Q_Q(QSplineSeries);
213 Q_Q(QSplineSeries);
202 if (q->count() > 1) {
214 if (q->count() > 1) {
203 m_controlPoints.resize(2*q->count()-2);
215 m_controlPoints.resize(2*q->count()-2);
204 calculateControlPoints();
216 calculateControlPoints();
205 }
217 }
206 }
218 }
207
219
208 Chart* QSplineSeriesPrivate::createGraphics(ChartPresenter* presenter)
220 Chart* QSplineSeriesPrivate::createGraphics(ChartPresenter* presenter)
209 {
221 {
210 Q_Q(QSplineSeries);
222 Q_Q(QSplineSeries);
211 SplineChartItem* spline = new SplineChartItem(q,presenter);
223 SplineChartItem* spline = new SplineChartItem(q,presenter);
212 if(presenter->animationOptions().testFlag(QChart::SeriesAnimations)) {
224 if(presenter->animationOptions().testFlag(QChart::SeriesAnimations)) {
213 spline->setAnimator(presenter->animator());
225 spline->setAnimator(presenter->animator());
214 spline->setAnimation(new SplineAnimation(spline));
226 spline->setAnimation(new SplineAnimation(spline));
215 }
227 }
216
228
217 presenter->chartTheme()->decorate(q, presenter->dataSet()->seriesIndex(q));
229 presenter->chartTheme()->decorate(q, presenter->dataSet()->seriesIndex(q));
218 return spline;
230 return spline;
219 }
231 }
220
232
221 #include "moc_qsplineseries.cpp"
233 #include "moc_qsplineseries.cpp"
222 #include "moc_qsplineseries_p.cpp"
234 #include "moc_qsplineseries_p.cpp"
223
235
224 QTCOMMERCIALCHART_END_NAMESPACE
236 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,369 +1,415
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 "qxyseries.h"
21 #include "qxyseries.h"
22 #include "qxyseries_p.h"
22 #include "qxyseries_p.h"
23 #include "domain_p.h"
23 #include "domain_p.h"
24 #include "legendmarker_p.h"
24 #include "legendmarker_p.h"
25
25
26 QTCOMMERCIALCHART_BEGIN_NAMESPACE
26 QTCOMMERCIALCHART_BEGIN_NAMESPACE
27
27
28 /*!
28 /*!
29 \class QXYSeries
29 \class QXYSeries
30 \brief The QXYSeries class is a base class for line, spline and scatter series.
30 \brief The QXYSeries class is a base class for line, spline and scatter series.
31 */
31 */
32 /*!
33 \qmlclass XYSeries
34 \brief The XYSeries class is a base class for line, spline and scatter series.
35
36 The class cannot be instantiated directly.
37 */
32
38
33 /*!
39 /*!
34 \property QXYSeries::pointsVisible
40 \property QXYSeries::pointsVisible
35
41 Controls if the data points are visible and should be drawn.
42 */
43 /*!
44 \qmlproperty bool XYSeries::pointsVisible
36 Controls if the data points are visible and should be drawn.
45 Controls if the data points are visible and should be drawn.
37 */
46 */
38
47
39 /*!
48 /*!
40 \fn QPen QXYSeries::pen() const
49 \fn QPen QXYSeries::pen() const
41 \brief Returns pen used to draw points for series.
50 \brief Returns pen used to draw points for series.
42 \sa setPen()
51 \sa setPen()
43 */
52 */
44
53
45 /*!
54 /*!
46 \fn QBrush QXYSeries::brush() const
55 \fn QBrush QXYSeries::brush() const
47 \brief Returns brush used to draw points for series.
56 \brief Returns brush used to draw points for series.
48 \sa setBrush()
57 \sa setBrush()
49 */
58 */
50
59
51 /*!
60 /*!
52 \property QXYSeries::color
61 \property QXYSeries::color
53 Line (pen) color of the series. This is a convenience property for modifying the color of pen.
62 The color of the series. This is line (pen) color in case of QLineSeries or QSplineSeries and
54 \sa QXYSeries::pen()
63 fill (brush) color in case of QScatterSeries or QAreaSeries.
64 \sa QXYSeries::pen(), QXYSeries::brush()
65 */
66 /*!
67 \qmlproperty color XYSeries::color
68 The color of the series. This is line (pen) color in case of LineSeries or SplineSeries and
69 fill (brush) color in case of ScatterSeries or AreaSeries.
55 */
70 */
56
71
57 /*!
72 /*!
58 \fn void QXYSeries::clicked(const QPointF& point)
73 \fn void QXYSeries::clicked(const QPointF& point)
59 \brief Signal is emitted when user clicks the \a point on chart.
74 \brief Signal is emitted when user clicks the \a point on chart.
60 */
75 */
76 /*!
77 \qmlsignal XYSeries::onClicked(QPointF point)
78 Signal is emitted when user clicks the \a point on chart. For example:
79 \code
80 LineSeries {
81 XyPoint { x: 0; y: 0 }
82 XyPoint { x: 1.1; y: 2.1 }
83 onClicked: console.log("onClicked: " + point.x + ", " + point.y);
84 }
85 \endcode
86 */
61
87
62 /*!
88 /*!
63 \fn void QXYSeries::pointReplaced(int index)
89 \fn void QXYSeries::pointReplaced(int index)
64 \brief Signal is emitted when user replaces a point at \a index.
90 Signal is emitted when a point has been replaced at \a index.
65 \sa replace()
91 \sa replace()
66 */
92 */
93 /*!
94 \qmlsignal XYSeries::pointReplaced(int index)
95 Signal is emitted when a point has been replaced at \a index.
96 */
67
97
68 /*!
98 /*!
69 \fn void QXYSeries::pointAdded(int index)
99 \fn void QXYSeries::pointAdded(int index)
70 \brief Signal is emitted when user adds a point at \a index.
100 Signal is emitted when a point has been added at \a index.
71 \sa append(), insert()
101 \sa append(), insert()
72 */
102 */
103 /*!
104 \qmlsignal XYSeries::pointAdded(int index)
105 Signal is emitted when a point has been added at \a index.
106 */
73
107
74 /*!
108 /*!
75 \fn void QXYSeries::pointRemoved(int index)
109 \fn void QXYSeries::pointRemoved(int index)
76 \brief Signal is emitted when user removes a point at \a index.
110 Signal is emitted when a point has been removed from \a index.
77 \sa remove()
111 \sa remove()
78 */
112 */
113 /*!
114 \qmlsignal XYSeries::pointRemoved(int index)
115 Signal is emitted when a point has been removed from \a index.
116 */
79
117
80 /*!
118 /*!
81 \fn void QXYSeries::colorChanged(QColor color)
119 \fn void QXYSeries::colorChanged(QColor color)
82 \brief Signal is emitted when the line (pen) color has changed to \a color.
120 \brief Signal is emitted when the line (pen) color has changed to \a color.
83 */
121 */
122 /*!
123 \qmlsignal XYSeries::colorChanged(QColor color)
124 Signal is emitted when the line (pen) color has changed to \a color.
125 */
84
126
85 /*!
127 /*!
86 \fn void QXYSeriesPrivate::updated()
128 \fn void QXYSeriesPrivate::updated()
87 \brief \internal
129 \brief \internal
88 */
130 */
89
131
90 /*!
132 /*!
133 \qmlmethod XyPoint XYSeries::at(int index)
134 */
135
136 /*!
91 \internal
137 \internal
92
138
93 Constructs empty series object which is a child of \a parent.
139 Constructs empty series object which is a child of \a parent.
94 When series object is added to QChartView or QChart instance ownerships is transferred.
140 When series object is added to QChartView or QChart instance ownerships is transferred.
95 */
141 */
96 QXYSeries::QXYSeries(QXYSeriesPrivate &d,QObject *parent) : QAbstractSeries(d, parent)
142 QXYSeries::QXYSeries(QXYSeriesPrivate &d,QObject *parent) : QAbstractSeries(d, parent)
97 {
143 {
98 }
144 }
99
145
100 /*!
146 /*!
101 Destroys the object. Series added to QChartView or QChart instances are owned by those,
147 Destroys the object. Series added to QChartView or QChart instances are owned by those,
102 and are deleted when mentioned object are destroyed.
148 and are deleted when mentioned object are destroyed.
103 */
149 */
104 QXYSeries::~QXYSeries()
150 QXYSeries::~QXYSeries()
105 {
151 {
106 }
152 }
107
153
108 /*!
154 /*!
109 Adds data point \a x \a y to the series. Points are connected with lines on the chart.
155 Adds data point \a x \a y to the series. Points are connected with lines on the chart.
110 */
156 */
111 void QXYSeries::append(qreal x,qreal y)
157 void QXYSeries::append(qreal x,qreal y)
112 {
158 {
113 append(QPointF(x,y));
159 append(QPointF(x,y));
114 }
160 }
115
161
116 /*!
162 /*!
117 This is an overloaded function.
163 This is an overloaded function.
118 Adds data \a point to the series. Points are connected with lines on the chart.
164 Adds data \a point to the series. Points are connected with lines on the chart.
119 */
165 */
120 void QXYSeries::append(const QPointF &point)
166 void QXYSeries::append(const QPointF &point)
121 {
167 {
122 Q_D(QXYSeries);
168 Q_D(QXYSeries);
123 d->m_points<<point;
169 d->m_points<<point;
124 // emit d->pointAdded(d->m_points.count()-1);
170 // emit d->pointAdded(d->m_points.count()-1);
125 emit pointAdded(d->m_points.count()-1);
171 emit pointAdded(d->m_points.count()-1);
126 }
172 }
127
173
128 /*!
174 /*!
129 This is an overloaded function.
175 This is an overloaded function.
130 Adds list of data \a points to the series. Points are connected with lines on the chart.
176 Adds list of data \a points to the series. Points are connected with lines on the chart.
131 */
177 */
132 void QXYSeries::append(const QList<QPointF> &points)
178 void QXYSeries::append(const QList<QPointF> &points)
133 {
179 {
134 foreach(const QPointF& point , points) {
180 foreach(const QPointF& point , points) {
135 append(point);
181 append(point);
136 }
182 }
137 }
183 }
138
184
139 /*!
185 /*!
140 Replaces data point \a oldX \a oldY with data point \a newX \a newY.
186 Replaces data point \a oldX \a oldY with data point \a newX \a newY.
141 */
187 */
142 void QXYSeries::replace(qreal oldX,qreal oldY,qreal newX,qreal newY)
188 void QXYSeries::replace(qreal oldX,qreal oldY,qreal newX,qreal newY)
143 {
189 {
144 replace(QPointF(oldX,oldY),QPointF(newX,newY));
190 replace(QPointF(oldX,oldY),QPointF(newX,newY));
145 }
191 }
146
192
147 /*!
193 /*!
148 Replaces \a oldPoint with \a newPoint.
194 Replaces \a oldPoint with \a newPoint.
149 */
195 */
150 void QXYSeries::replace(const QPointF &oldPoint,const QPointF &newPoint)
196 void QXYSeries::replace(const QPointF &oldPoint,const QPointF &newPoint)
151 {
197 {
152 Q_D(QXYSeries);
198 Q_D(QXYSeries);
153 int index = d->m_points.indexOf(oldPoint);
199 int index = d->m_points.indexOf(oldPoint);
154 if(index==-1) return;
200 if(index==-1) return;
155 d->m_points[index] = newPoint;
201 d->m_points[index] = newPoint;
156 // emit d->pointReplaced(index);
202 // emit d->pointReplaced(index);
157 emit pointReplaced(index);
203 emit pointReplaced(index);
158 }
204 }
159
205
160 /*!
206 /*!
161 Removes current \a x and \a y value.
207 Removes current \a x and \a y value.
162 */
208 */
163 void QXYSeries::remove(qreal x,qreal y)
209 void QXYSeries::remove(qreal x,qreal y)
164 {
210 {
165 remove(QPointF(x,y));
211 remove(QPointF(x,y));
166 }
212 }
167
213
168 /*!
214 /*!
169 Removes current \a point x value.
215 Removes current \a point x value.
170
216
171 Note: point y value is ignored.
217 Note: point y value is ignored.
172 */
218 */
173 void QXYSeries::remove(const QPointF &point)
219 void QXYSeries::remove(const QPointF &point)
174 {
220 {
175 Q_D(QXYSeries);
221 Q_D(QXYSeries);
176 int index = d->m_points.indexOf(point);
222 int index = d->m_points.indexOf(point);
177 if(index==-1) return;
223 if(index==-1) return;
178 d->m_points.remove(index);
224 d->m_points.remove(index);
179 // emit d->pointRemoved(index);
225 // emit d->pointRemoved(index);
180 emit pointRemoved(index);
226 emit pointRemoved(index);
181 }
227 }
182
228
183 /*!
229 /*!
184 Inserts a \a point in the series at \a index position.
230 Inserts a \a point in the series at \a index position.
185 */
231 */
186 void QXYSeries::insert(int index, const QPointF &point)
232 void QXYSeries::insert(int index, const QPointF &point)
187 {
233 {
188 Q_D(QXYSeries);
234 Q_D(QXYSeries);
189 d->m_points.insert(index, point);
235 d->m_points.insert(index, point);
190 // emit d->pointAdded(index);
236 // emit d->pointAdded(index);
191 emit pointAdded(index);
237 emit pointAdded(index);
192 }
238 }
193
239
194 /*!
240 /*!
195 Removes all points from the series.
241 Removes all points from the series.
196 */
242 */
197 void QXYSeries::clear()
243 void QXYSeries::clear()
198 {
244 {
199 Q_D(QXYSeries);
245 Q_D(QXYSeries);
200 for (int i = d->m_points.size() - 1; i >= 0; i--)
246 for (int i = d->m_points.size() - 1; i >= 0; i--)
201 remove(d->m_points.at(i));
247 remove(d->m_points.at(i));
202 }
248 }
203
249
204 /*!
250 /*!
205 \internal \a pos
251 \internal \a pos
206 */
252 */
207 QList<QPointF> QXYSeries::points() const
253 QList<QPointF> QXYSeries::points() const
208 {
254 {
209 Q_D(const QXYSeries);
255 Q_D(const QXYSeries);
210 return d->m_points.toList();
256 return d->m_points.toList();
211 }
257 }
212
258
213 /*!
259 /*!
214 Returns number of data points within series.
260 Returns number of data points within series.
215 */
261 */
216 int QXYSeries::count() const
262 int QXYSeries::count() const
217 {
263 {
218 Q_D(const QXYSeries);
264 Q_D(const QXYSeries);
219 return d->m_points.count();
265 return d->m_points.count();
220 }
266 }
221
267
222
268
223 /*!
269 /*!
224 Sets \a pen used for drawing points on the chart. If the pen is not defined, the
270 Sets \a pen used for drawing points on the chart. If the pen is not defined, the
225 pen from chart theme is used.
271 pen from chart theme is used.
226 \sa QChart::setTheme()
272 \sa QChart::setTheme()
227 */
273 */
228 void QXYSeries::setPen(const QPen &pen)
274 void QXYSeries::setPen(const QPen &pen)
229 {
275 {
230 Q_D(QXYSeries);
276 Q_D(QXYSeries);
231 if (d->m_pen!=pen) {
277 if (d->m_pen!=pen) {
232 d->m_pen = pen;
278 d->m_pen = pen;
233 emit d->updated();
279 emit d->updated();
234 }
280 }
235 }
281 }
236
282
237 QPen QXYSeries::pen() const
283 QPen QXYSeries::pen() const
238 {
284 {
239 Q_D(const QXYSeries);
285 Q_D(const QXYSeries);
240 return d->m_pen;
286 return d->m_pen;
241 }
287 }
242
288
243 /*!
289 /*!
244 Sets \a brush used for drawing points on the chart. If the brush is not defined, brush
290 Sets \a brush used for drawing points on the chart. If the brush is not defined, brush
245 from chart theme setting is used.
291 from chart theme setting is used.
246 \sa QChart::setTheme()
292 \sa QChart::setTheme()
247 */
293 */
248 void QXYSeries::setBrush(const QBrush &brush)
294 void QXYSeries::setBrush(const QBrush &brush)
249 {
295 {
250 Q_D(QXYSeries);
296 Q_D(QXYSeries);
251 if (d->m_brush!=brush) {
297 if (d->m_brush!=brush) {
252 d->m_brush = brush;
298 d->m_brush = brush;
253 emit d->updated();
299 emit d->updated();
254 }
300 }
255 }
301 }
256
302
257 QBrush QXYSeries::brush() const
303 QBrush QXYSeries::brush() const
258 {
304 {
259 Q_D(const QXYSeries);
305 Q_D(const QXYSeries);
260 return d->m_brush;
306 return d->m_brush;
261 }
307 }
262
308
263 void QXYSeries::setColor(const QColor &color)
309 void QXYSeries::setColor(const QColor &color)
264 {
310 {
265 QPen p = pen();
311 QPen p = pen();
266 if (p.color() != color) {
312 if (p.color() != color) {
267 p.setColor(color);
313 p.setColor(color);
268 setPen(p);
314 setPen(p);
269 emit colorChanged(color);
315 emit colorChanged(color);
270 }
316 }
271 }
317 }
272
318
273 QColor QXYSeries::color() const
319 QColor QXYSeries::color() const
274 {
320 {
275 return pen().color();
321 return pen().color();
276 }
322 }
277
323
278 void QXYSeries::setPointsVisible(bool visible)
324 void QXYSeries::setPointsVisible(bool visible)
279 {
325 {
280 Q_D(QXYSeries);
326 Q_D(QXYSeries);
281 if (d->m_pointsVisible != visible){
327 if (d->m_pointsVisible != visible){
282 d->m_pointsVisible = visible;
328 d->m_pointsVisible = visible;
283 emit d->updated();
329 emit d->updated();
284 }
330 }
285 }
331 }
286
332
287 bool QXYSeries::pointsVisible() const
333 bool QXYSeries::pointsVisible() const
288 {
334 {
289 Q_D(const QXYSeries);
335 Q_D(const QXYSeries);
290 return d->m_pointsVisible;
336 return d->m_pointsVisible;
291 }
337 }
292
338
293
339
294 /*!
340 /*!
295 Stream operator for adding a data \a point to the series.
341 Stream operator for adding a data \a point to the series.
296 \sa append()
342 \sa append()
297 */
343 */
298 QXYSeries& QXYSeries::operator<< (const QPointF &point)
344 QXYSeries& QXYSeries::operator<< (const QPointF &point)
299 {
345 {
300 append(point);
346 append(point);
301 return *this;
347 return *this;
302 }
348 }
303
349
304
350
305 /*!
351 /*!
306 Stream operator for adding a list of \a points to the series.
352 Stream operator for adding a list of \a points to the series.
307 \sa append()
353 \sa append()
308 */
354 */
309
355
310 QXYSeries& QXYSeries::operator<< (const QList<QPointF>& points)
356 QXYSeries& QXYSeries::operator<< (const QList<QPointF>& points)
311 {
357 {
312 append(points);
358 append(points);
313 return *this;
359 return *this;
314 }
360 }
315
361
316 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
362 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
317
363
318
364
319 QXYSeriesPrivate::QXYSeriesPrivate(QXYSeries *q) :
365 QXYSeriesPrivate::QXYSeriesPrivate(QXYSeries *q) :
320 QAbstractSeriesPrivate(q),
366 QAbstractSeriesPrivate(q),
321 m_pointsVisible(false)
367 m_pointsVisible(false)
322 {
368 {
323 }
369 }
324
370
325 void QXYSeriesPrivate::scaleDomain(Domain& domain)
371 void QXYSeriesPrivate::scaleDomain(Domain& domain)
326 {
372 {
327 qreal minX(domain.minX());
373 qreal minX(domain.minX());
328 qreal minY(domain.minY());
374 qreal minY(domain.minY());
329 qreal maxX(domain.maxX());
375 qreal maxX(domain.maxX());
330 qreal maxY(domain.maxY());
376 qreal maxY(domain.maxY());
331 int tickXCount(domain.tickXCount());
377 int tickXCount(domain.tickXCount());
332 int tickYCount(domain.tickYCount());
378 int tickYCount(domain.tickYCount());
333
379
334 Q_Q(QXYSeries);
380 Q_Q(QXYSeries);
335
381
336 const QList<QPointF>& points = q->points();
382 const QList<QPointF>& points = q->points();
337
383
338
384
339 if(points.isEmpty()){
385 if(points.isEmpty()){
340 minX=0.0;
386 minX=0.0;
341 minY=0.0;
387 minY=0.0;
342 maxX=1.0;
388 maxX=1.0;
343 maxY=1.0;
389 maxY=1.0;
344 }
390 }
345
391
346 for (int i = 0; i < points.count(); i++)
392 for (int i = 0; i < points.count(); i++)
347 {
393 {
348 qreal x = points[i].x();
394 qreal x = points[i].x();
349 qreal y = points[i].y();
395 qreal y = points[i].y();
350 minX = qMin(minX, x);
396 minX = qMin(minX, x);
351 minY = qMin(minY, y);
397 minY = qMin(minY, y);
352 maxX = qMax(maxX, x);
398 maxX = qMax(maxX, x);
353 maxY = qMax(maxY, y);
399 maxY = qMax(maxY, y);
354 }
400 }
355
401
356 domain.setRange(minX,maxX,minY,maxY,tickXCount,tickYCount);
402 domain.setRange(minX,maxX,minY,maxY,tickXCount,tickYCount);
357 }
403 }
358
404
359 QList<LegendMarker*> QXYSeriesPrivate::createLegendMarker(QLegend* legend)
405 QList<LegendMarker*> QXYSeriesPrivate::createLegendMarker(QLegend* legend)
360 {
406 {
361 Q_Q(QXYSeries);
407 Q_Q(QXYSeries);
362 QList<LegendMarker*> list;
408 QList<LegendMarker*> list;
363 return list << new XYLegendMarker(q,legend);
409 return list << new XYLegendMarker(q,legend);
364 }
410 }
365
411
366 #include "moc_qxyseries.cpp"
412 #include "moc_qxyseries.cpp"
367 #include "moc_qxyseries_p.cpp"
413 #include "moc_qxyseries_p.cpp"
368
414
369 QTCOMMERCIALCHART_END_NAMESPACE
415 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,64 +1,66
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 import QtQuick 1.0
21 import QtQuick 1.0
22 import QtCommercial.Chart 1.0
22 import QtCommercial.Chart 1.0
23
23
24 ChartView {
24 ChartView {
25 title: "area series"
25 title: "area series"
26 anchors.fill: parent
26 anchors.fill: parent
27 axisXLabels: ["0", "2000", "1", "2001", "2", "2002", "3", "2003", "4", "2004", "5", "2005",
27 axisXLabels: ["0", "2000", "1", "2001", "2", "2002", "3", "2003", "4", "2004", "5", "2005",
28 "6", "2006", "7", "2007", "8", "2008", "9", "2009", "10", "2010", "11", "2011"]
28 "6", "2006", "7", "2007", "8", "2008", "9", "2009", "10", "2010", "11", "2011"]
29
29
30 property variant series: daSeries
30 property variant series: daSeries
31
31
32 AreaSeries {
32 AreaSeries {
33 id: daSeries
33 id: daSeries
34 name: "area 1"
34 name: "area 1"
35 onSelected: console.log("areaSeries.onSelected");
36 onClicked: console.log("areaSeries.onClicked: " + point.x + ", " + point.y);
35 upperSeries: LineSeries {
37 upperSeries: LineSeries {
36 XyPoint { x: 0; y: 1 }
38 XyPoint { x: 0; y: 1 }
37 XyPoint { x: 1; y: 1 }
39 XyPoint { x: 1; y: 1 }
38 XyPoint { x: 2; y: 3 }
40 XyPoint { x: 2; y: 3 }
39 XyPoint { x: 3; y: 3 }
41 XyPoint { x: 3; y: 3 }
40 XyPoint { x: 4; y: 2 }
42 XyPoint { x: 4; y: 2 }
41 XyPoint { x: 5; y: 0 }
43 XyPoint { x: 5; y: 0 }
42 XyPoint { x: 6; y: 2 }
44 XyPoint { x: 6; y: 2 }
43 XyPoint { x: 7; y: 1 }
45 XyPoint { x: 7; y: 1 }
44 XyPoint { x: 8; y: 2 }
46 XyPoint { x: 8; y: 2 }
45 XyPoint { x: 9; y: 1 }
47 XyPoint { x: 9; y: 1 }
46 XyPoint { x: 10; y: 3 }
48 XyPoint { x: 10; y: 3 }
47 XyPoint { x: 11; y: 3 }
49 XyPoint { x: 11; y: 3 }
48 }
50 }
49 lowerSeries: LineSeries {
51 lowerSeries: LineSeries {
50 XyPoint { x: 0; y: 0 }
52 XyPoint { x: 0; y: 0 }
51 XyPoint { x: 1; y: 0 }
53 XyPoint { x: 1; y: 0 }
52 XyPoint { x: 2; y: 0 }
54 XyPoint { x: 2; y: 0 }
53 XyPoint { x: 3; y: 0 }
55 XyPoint { x: 3; y: 0 }
54 XyPoint { x: 4; y: 0 }
56 XyPoint { x: 4; y: 0 }
55 XyPoint { x: 5; y: 0 }
57 XyPoint { x: 5; y: 0 }
56 XyPoint { x: 6; y: 0 }
58 XyPoint { x: 6; y: 0 }
57 XyPoint { x: 7; y: 0 }
59 XyPoint { x: 7; y: 0 }
58 XyPoint { x: 8; y: 0 }
60 XyPoint { x: 8; y: 0 }
59 XyPoint { x: 9; y: 0 }
61 XyPoint { x: 9; y: 0 }
60 XyPoint { x: 10; y: 0 }
62 XyPoint { x: 10; y: 0 }
61 XyPoint { x: 11; y: 0 }
63 XyPoint { x: 11; y: 0 }
62 }
64 }
63 }
65 }
64 }
66 }
@@ -1,42 +1,45
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 import QtQuick 1.0
21 import QtQuick 1.0
22 import QtCommercial.Chart 1.0
22 import QtCommercial.Chart 1.0
23
23
24 ChartView {
24 ChartView {
25 title: "Bar series"
25 title: "Bar series"
26 anchors.fill: parent
26 anchors.fill: parent
27 theme: ChartView.ChartThemeLight
27 theme: ChartView.ChartThemeLight
28 legend.alignment: Qt.AlignBottom
28 legend.alignment: Qt.AlignBottom
29 axisXLabels: ["0", "2007", "1", "2008", "2", "2009", "3", "2010", "4", "2011", "5", "2012"]
29 axisXLabels: ["0", "2007", "1", "2008", "2", "2009", "3", "2010", "4", "2011", "5", "2012"]
30
30
31 property variant series: daSeries
31 property variant series: daSeries
32
32
33 BarSeries {
33 BarSeries {
34 id: daSeries
34 id: daSeries
35 name: "bar"
35 name: "bar"
36 onClicked: console.log("onClicked: " + barset + " " + index);
36 onClicked: console.log("onClicked: " + barset + " " + index);
37 onHovered: console.log("onHovered: " + barset + " " + status);
37 onHovered: console.log("onHovered: " + barset + " " + status);
38 BarSet { label: "Bob"; values: [4, 7, 3, 10, 5, 6] }
38 BarSet { label: "Bob"; values: [4, 7, 3, 10, 5, 6]
39 onClicked: console.log("barset.onClicked: " + index);
40 onHovered: console.log("barset.onHovered: " + status);
41 }
39 BarSet { label: "Susan"; values: [5, 1, 2, 4, 1, 8] }
42 BarSet { label: "Susan"; values: [5, 1, 2, 4, 1, 8] }
40 BarSet { label: "James"; values: [3, 5, 8, 5, 4, 7] }
43 BarSet { label: "James"; values: [3, 5, 8, 5, 4, 7] }
41 }
44 }
42 }
45 }
@@ -1,51 +1,52
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 import QtQuick 1.0
21 import QtQuick 1.0
22 import QtCommercial.Chart 1.0
22 import QtCommercial.Chart 1.0
23
23
24 ChartView {
24 ChartView {
25 title: "line series"
25 title: "line series"
26 anchors.fill: parent
26 anchors.fill: parent
27
27
28 property variant series: daSeries
28 property variant series: daSeries
29
29
30 LineSeries {
30 LineSeries {
31 id: daSeries
31 id: daSeries
32 name: "line 1"
32 name: "line 1"
33 onClicked: console.log("onClicked: " + point.x + ", " + point.y);
33 XyPoint { x: 0; y: 0 }
34 XyPoint { x: 0; y: 0 }
34 XyPoint { x: 1.1; y: 2.1 }
35 XyPoint { x: 1.1; y: 2.1 }
35 XyPoint { x: 1.9; y: 3.3 }
36 XyPoint { x: 1.9; y: 3.3 }
36 XyPoint { x: 2.1; y: 2.1 }
37 XyPoint { x: 2.1; y: 2.1 }
37 XyPoint { x: 2.9; y: 4.9 }
38 XyPoint { x: 2.9; y: 4.9 }
38 XyPoint { x: 3.4; y: 3.0 }
39 XyPoint { x: 3.4; y: 3.0 }
39 XyPoint { x: 4.1; y: 3.3 }
40 XyPoint { x: 4.1; y: 3.3 }
40 }
41 }
41
42
42 LineSeries {
43 LineSeries {
43 name: "line 2"
44 name: "line 2"
44 XyPoint { x: 1.1; y: 1.1 }
45 XyPoint { x: 1.1; y: 1.1 }
45 XyPoint { x: 1.9; y: 2.3 }
46 XyPoint { x: 1.9; y: 2.3 }
46 XyPoint { x: 2.1; y: 1.1 }
47 XyPoint { x: 2.1; y: 1.1 }
47 XyPoint { x: 2.9; y: 3.9 }
48 XyPoint { x: 2.9; y: 3.9 }
48 XyPoint { x: 3.4; y: 2.0 }
49 XyPoint { x: 3.4; y: 2.0 }
49 XyPoint { x: 4.1; y: 2.3 }
50 XyPoint { x: 4.1; y: 2.3 }
50 }
51 }
51 }
52 }
General Comments 0
You need to be logged in to leave comments. Login now