##// END OF EJS Templates
QML methods of series: several fixes and documentation
Tero Ahola -
r1521:dbd0ff0f2ce9
parent child
Show More
@@ -1,77 +1,79
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 \raw HTML
12 \raw HTML
13 <table cellpadding="2" cellspacing="1" border="0" width="95%" class="indextable">
13 <table cellpadding="2" cellspacing="1" border="0" width="95%" class="indextable">
14 <tr>
14 <tr>
15 <th class="titleheader" width="25%"> ChartView and it's properties </th>
15 <th class="titleheader" width="25%"> ChartView and it's properties </th>
16 </tr>
16 </tr>
17 <tr>
17 <tr>
18 <td valign="top">
18 <td valign="top">
19 <ul>
19 <ul>
20 <li><a href="qml-chartview.html">ChartView</a></li>
20 <li><a href="qml-chartview.html">ChartView</a></li>
21 <li><a href="qml-axis.html">Axis</a></li>
21 <li><a href="qml-axis.html">Axis</a></li>
22 <li><a href="qml-legend.html">Legend</a></li>
22 <li><a href="qml-legend.html">Legend</a></li>
23 <li><a href="qml-abstractseries.html">AbstractSeries</a></li>
23 </ul>
24 </ul>
24 </td>
25 </td>
25 </tr>
26 </tr>
26 </table>
27 </table>
27 <table cellpadding="2" cellspacing="1" border="0" width="95%" class="indextable">
28 <table cellpadding="2" cellspacing="1" border="0" width="95%" class="indextable">
28 <tr>
29 <tr>
29 <th class="titleheader" width="25%"> XY chart </th>
30 <th class="titleheader" width="25%"> XY chart </th>
30 </tr>
31 </tr>
31 <tr>
32 <tr>
32 <td valign="top">
33 <td valign="top">
33 <ul>
34 <ul>
35 <li><a href="qml-xyseries.html">XYSeries</a></li>
34 <li><a href="qml-lineseries.html">LineSeries</a></li>
36 <li><a href="qml-lineseries.html">LineSeries</a></li>
35 <li><a href="qml-areaseries.html">AreaSeries</a></li>
37 <li><a href="qml-areaseries.html">AreaSeries</a></li>
36 <li><a href="qml-scatterseries.html">ScatterSeries</a></li>
38 <li><a href="qml-scatterseries.html">ScatterSeries</a></li>
37 <li><a href="qml-splineseries.html">SplineSeries</a></li>
39 <li><a href="qml-splineseries.html">SplineSeries</a></li>
38 <li><a href="qml-xypoint.html">XyPoint</a></li>
40 <li><a href="qml-xypoint.html">XyPoint</a></li>
39 <li><a href="qml-hxymodelmapper.html">HXYModelMapper</a></li>
41 <li><a href="qml-hxymodelmapper.html">HXYModelMapper</a></li>
40 <li><a href="qml-vxymodelmapper.html">VXYModelMapper</a></li>
42 <li><a href="qml-vxymodelmapper.html">VXYModelMapper</a></li>
41 </ul>
43 </ul>
42 </td>
44 </td>
43 </tr>
45 </tr>
44 </table>
46 </table>
45 <table cellpadding="2" cellspacing="1" border="0" width="95%" class="indextable">
47 <table cellpadding="2" cellspacing="1" border="0" width="95%" class="indextable">
46 <tr>
48 <tr>
47 <th class="titleheader" width="25%"> Pie chart </th>
49 <th class="titleheader" width="25%"> Pie chart </th>
48 <tr>
50 <tr>
49 <td valign="top">
51 <td valign="top">
50 <ul>
52 <ul>
51 <li><a href="qml-pieseries.html">PieSeries</a></li>
53 <li><a href="qml-pieseries.html">PieSeries</a></li>
52 <li><a href="qml-pieslice.html">PieSlice</a></li>
54 <li><a href="qml-pieslice.html">PieSlice</a></li>
53 <li><a href="qml-hpiemodelmapper.html">HPieModelMapper</a></li>
55 <li><a href="qml-hpiemodelmapper.html">HPieModelMapper</a></li>
54 <li><a href="qml-vpiemodelmapper.html">VPieModelMapper</a></li>
56 <li><a href="qml-vpiemodelmapper.html">VPieModelMapper</a></li>
55 </ul>
57 </ul>
56 </td>
58 </td>
57 </tr>
59 </tr>
58 </table>
60 </table>
59 <table cellpadding="2" cellspacing="1" border="0" width="95%" class="indextable">
61 <table cellpadding="2" cellspacing="1" border="0" width="95%" class="indextable">
60 <tr>
62 <tr>
61 <th class="titleheader" width="25%"> Bar chart </th>
63 <th class="titleheader" width="25%"> Bar chart </th>
62 <tr>
64 <tr>
63 <td valign="top">
65 <td valign="top">
64 <ul>
66 <ul>
65 <li><a href="qml-barseries.html">BarSeries</a></li>
67 <li><a href="qml-barseries.html">BarSeries</a></li>
66 <li><a href="qml-groupedbarseries.html">GroupedBarSeries</a></li>
68 <li><a href="qml-groupedbarseries.html">GroupedBarSeries</a></li>
67 <li><a href="qml-stackedbarseries.html">StackedBarSeries</a></li>
69 <li><a href="qml-stackedbarseries.html">StackedBarSeries</a></li>
68 <li><a href="qml-percentbarseries.html">PercentBarSeries</a></li>
70 <li><a href="qml-percentbarseries.html">PercentBarSeries</a></li>
69 <li><a href="qml-barset.html">BarSet</a></li>
71 <li><a href="qml-barset.html">BarSet</a></li>
70 <li><a href="qml-hbarmodelmapper.html">HBarModelMapper</a></li>
72 <li><a href="qml-hbarmodelmapper.html">HBarModelMapper</a></li>
71 <li><a href="qml-vbarmodelmapper.html">VBarModelMapper</a></li>
73 <li><a href="qml-vbarmodelmapper.html">VBarModelMapper</a></li>
72 </ul>
74 </ul>
73 </td>
75 </td>
74 </tr>
76 </tr>
75 </table>
77 </table>
76 \endraw
78 \endraw
77 */
79 */
@@ -1,308 +1,314
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 "declarativebarseries.h"
21 #include "declarativebarseries.h"
22 #include "declarativechart.h"
22 #include "declarativechart.h"
23 #include <QBarSet>
23 #include <QBarSet>
24 #include <QVBarModelMapper>
24 #include <QVBarModelMapper>
25 #include <QHBarModelMapper>
25 #include <QHBarModelMapper>
26
26
27 QTCOMMERCIALCHART_BEGIN_NAMESPACE
27 QTCOMMERCIALCHART_BEGIN_NAMESPACE
28
28
29 DeclarativeBarSet::DeclarativeBarSet(QObject *parent) :
29 DeclarativeBarSet::DeclarativeBarSet(QObject *parent) :
30 QBarSet("", parent)
30 QBarSet("", parent)
31 {
31 {
32 connect(this, SIGNAL(valuesAdded(int,int)), this, SLOT(handleCountChanged(int, int)));
32 connect(this, SIGNAL(valuesAdded(int,int)), this, SLOT(handleCountChanged(int, int)));
33 connect(this, SIGNAL(valuesRemoved(int,int)), this, SLOT(handleCountChanged(int, int)));
33 connect(this, SIGNAL(valuesRemoved(int,int)), this, SLOT(handleCountChanged(int, int)));
34 }
34 }
35
35
36 void DeclarativeBarSet::handleCountChanged(int index, int count)
36 void DeclarativeBarSet::handleCountChanged(int index, int count)
37 {
37 {
38 Q_UNUSED(index)
38 Q_UNUSED(index)
39 Q_UNUSED(count)
39 Q_UNUSED(count)
40 emit countChanged(QBarSet::count());
40 emit countChanged(QBarSet::count());
41 }
41 }
42
42
43 QVariantList DeclarativeBarSet::values()
43 QVariantList DeclarativeBarSet::values()
44 {
44 {
45 QVariantList values;
45 QVariantList values;
46 for (int i(0); i < count(); i++)
46 for (int i(0); i < count(); i++)
47 values.append(QVariant(QBarSet::at(i)));
47 values.append(QVariant(QBarSet::at(i)));
48 return values;
48 return values;
49 }
49 }
50
50
51 void DeclarativeBarSet::setValues(QVariantList values)
51 void DeclarativeBarSet::setValues(QVariantList values)
52 {
52 {
53 while (count())
53 while (count())
54 remove(count() - 1);
54 remove(count() - 1);
55
55
56 for (int i(0); i < values.count(); i++) {
56 for (int i(0); i < values.count(); i++) {
57 if (values.at(i).canConvert(QVariant::Double))
57 if (values.at(i).canConvert(QVariant::Double))
58 QBarSet::append(values[i].toDouble());
58 QBarSet::append(values[i].toDouble());
59 else if (values.at(i).canConvert(QVariant::PointF))
59 else if (values.at(i).canConvert(QVariant::PointF))
60 QBarSet::append(values[i].toPointF());
60 QBarSet::append(values[i].toPointF());
61 }
61 }
62 }
62 }
63
63
64 DeclarativeBarSeries::DeclarativeBarSeries(QDeclarativeItem *parent) :
64 DeclarativeBarSeries::DeclarativeBarSeries(QDeclarativeItem *parent) :
65 QBarSeries(parent)
65 QBarSeries(parent)
66 {
66 {
67 connect(this, SIGNAL(barsetsAdded(QList<QBarSet*>)), this, SLOT(handleAdded(QList<QBarSet*>)));
67 connect(this, SIGNAL(barsetsAdded(QList<QBarSet*>)), this, SLOT(handleAdded(QList<QBarSet*>)));
68 connect(this, SIGNAL(barsetsRemoved(QList<QBarSet*>)), this, SLOT(handleRemoved(QList<QBarSet*>)));
68 connect(this, SIGNAL(barsetsRemoved(QList<QBarSet*>)), this, SLOT(handleRemoved(QList<QBarSet*>)));
69 }
69 }
70
70
71 void DeclarativeBarSeries::handleAdded(QList<QBarSet* > barsets)
71 void DeclarativeBarSeries::handleAdded(QList<QBarSet* > barsets)
72 {
72 {
73 foreach(QBarSet *b, barsets) {
73 foreach(QBarSet *b, barsets) {
74 DeclarativeBarSet *barset = qobject_cast<DeclarativeBarSet *>(b);
74 DeclarativeBarSet *barset = qobject_cast<DeclarativeBarSet *>(b);
75 emit added(barset);
75 emit added(barset);
76 }
76 }
77 }
77 }
78
78
79 void DeclarativeBarSeries::handleRemoved(QList<QBarSet* > barsets)
79 void DeclarativeBarSeries::handleRemoved(QList<QBarSet* > barsets)
80 {
80 {
81 foreach(QBarSet *b, barsets) {
81 foreach(QBarSet *b, barsets) {
82 DeclarativeBarSet *barset = qobject_cast<DeclarativeBarSet *>(b);
82 DeclarativeBarSet *barset = qobject_cast<DeclarativeBarSet *>(b);
83 emit removed(barset);
83 emit removed(barset);
84 }
84 }
85 }
85 }
86
86
87 void DeclarativeBarSeries::classBegin()
87 void DeclarativeBarSeries::classBegin()
88 {
88 {
89 }
89 }
90
90
91 void DeclarativeBarSeries::componentComplete()
91 void DeclarativeBarSeries::componentComplete()
92 {
92 {
93 foreach(QObject *child, children()) {
93 foreach(QObject *child, children()) {
94 if (qobject_cast<DeclarativeBarSet *>(child)) {
94 if (qobject_cast<DeclarativeBarSet *>(child)) {
95 QBarSeries::append(qobject_cast<DeclarativeBarSet *>(child));
95 QBarSeries::append(qobject_cast<DeclarativeBarSet *>(child));
96 } else if(qobject_cast<QVBarModelMapper *>(child)) {
96 } else if(qobject_cast<QVBarModelMapper *>(child)) {
97 QVBarModelMapper *mapper = qobject_cast<QVBarModelMapper *>(child);
97 QVBarModelMapper *mapper = qobject_cast<QVBarModelMapper *>(child);
98 mapper->setSeries(this);
98 mapper->setSeries(this);
99 } else if(qobject_cast<QHBarModelMapper *>(child)) {
99 } else if(qobject_cast<QHBarModelMapper *>(child)) {
100 QHBarModelMapper *mapper = qobject_cast<QHBarModelMapper *>(child);
100 QHBarModelMapper *mapper = qobject_cast<QHBarModelMapper *>(child);
101 mapper->setSeries(this);
101 mapper->setSeries(this);
102 }
102 }
103 }
103 }
104 }
104 }
105
105
106 QDeclarativeListProperty<QObject> DeclarativeBarSeries::seriesChildren()
106 QDeclarativeListProperty<QObject> DeclarativeBarSeries::seriesChildren()
107 {
107 {
108 return QDeclarativeListProperty<QObject>(this, 0, &DeclarativeBarSeries::appendSeriesChildren);
108 return QDeclarativeListProperty<QObject>(this, 0, &DeclarativeBarSeries::appendSeriesChildren);
109 }
109 }
110
110
111 void DeclarativeBarSeries::appendSeriesChildren(QDeclarativeListProperty<QObject> * list, QObject *element)
111 void DeclarativeBarSeries::appendSeriesChildren(QDeclarativeListProperty<QObject> * list, QObject *element)
112 {
112 {
113 // Empty implementation; the children are parsed in componentComplete instead
113 // Empty implementation; the children are parsed in componentComplete instead
114 Q_UNUSED(list);
114 Q_UNUSED(list);
115 Q_UNUSED(element);
115 Q_UNUSED(element);
116 }
116 }
117
117
118 DeclarativeBarSet *DeclarativeBarSeries::at(int index)
118 DeclarativeBarSet *DeclarativeBarSeries::at(int index)
119 {
119 {
120 QList<QBarSet*> setList = barSets();
120 QList<QBarSet*> setList = barSets();
121 if (index >= 0 && index < setList.count())
121 if (index >= 0 && index < setList.count())
122 return qobject_cast<DeclarativeBarSet *>(setList[index]);
122 return qobject_cast<DeclarativeBarSet *>(setList[index]);
123
123
124 return 0;
124 return 0;
125 }
125 }
126
126
127 DeclarativeBarSet *DeclarativeBarSeries::insert(int index, QString label, QVariantList values)
127 DeclarativeBarSet *DeclarativeBarSeries::insert(int index, QString label, QVariantList values)
128 {
128 {
129 int insertIndex = index;
130 if (insertIndex < 0)
131 insertIndex = 0;
132 else if (insertIndex > count())
133 insertIndex = count();
134
129 DeclarativeBarSet *barset = new DeclarativeBarSet(this);
135 DeclarativeBarSet *barset = new DeclarativeBarSet(this);
130 barset->setLabel(label);
136 barset->setLabel(label);
131 barset->setValues(values);
137 barset->setValues(values);
132 if (QBarSeries::insert(index, barset))
138 if (QBarSeries::insert(insertIndex, barset))
133 return barset;
139 return barset;
134 delete barset;
140 delete barset;
135 return 0;
141 return 0;
136 }
142 }
137
143
138 DeclarativeGroupedBarSeries::DeclarativeGroupedBarSeries(QDeclarativeItem *parent) :
144 DeclarativeGroupedBarSeries::DeclarativeGroupedBarSeries(QDeclarativeItem *parent) :
139 QGroupedBarSeries(parent)
145 QGroupedBarSeries(parent)
140 {
146 {
141 }
147 }
142
148
143 void DeclarativeGroupedBarSeries::classBegin()
149 void DeclarativeGroupedBarSeries::classBegin()
144 {
150 {
145 }
151 }
146
152
147 void DeclarativeGroupedBarSeries::componentComplete()
153 void DeclarativeGroupedBarSeries::componentComplete()
148 {
154 {
149 foreach(QObject *child, children()) {
155 foreach(QObject *child, children()) {
150 if (qobject_cast<DeclarativeBarSet *>(child)) {
156 if (qobject_cast<DeclarativeBarSet *>(child)) {
151 QBarSeries::append(qobject_cast<DeclarativeBarSet *>(child));
157 QBarSeries::append(qobject_cast<DeclarativeBarSet *>(child));
152 } else if(qobject_cast<QVBarModelMapper *>(child)) {
158 } else if(qobject_cast<QVBarModelMapper *>(child)) {
153 QVBarModelMapper *mapper = qobject_cast<QVBarModelMapper *>(child);
159 QVBarModelMapper *mapper = qobject_cast<QVBarModelMapper *>(child);
154 mapper->setSeries(this);
160 mapper->setSeries(this);
155 } else if(qobject_cast<QHBarModelMapper *>(child)) {
161 } else if(qobject_cast<QHBarModelMapper *>(child)) {
156 QHBarModelMapper *mapper = qobject_cast<QHBarModelMapper *>(child);
162 QHBarModelMapper *mapper = qobject_cast<QHBarModelMapper *>(child);
157 mapper->setSeries(this);
163 mapper->setSeries(this);
158 }
164 }
159 }
165 }
160 }
166 }
161
167
162 QDeclarativeListProperty<QObject> DeclarativeGroupedBarSeries::seriesChildren()
168 QDeclarativeListProperty<QObject> DeclarativeGroupedBarSeries::seriesChildren()
163 {
169 {
164 return QDeclarativeListProperty<QObject>(this, 0, &DeclarativeBarSeries::appendSeriesChildren);
170 return QDeclarativeListProperty<QObject>(this, 0, &DeclarativeBarSeries::appendSeriesChildren);
165 }
171 }
166
172
167 void DeclarativeGroupedBarSeries::appendSeriesChildren(QDeclarativeListProperty<QObject> * list, QObject *element)
173 void DeclarativeGroupedBarSeries::appendSeriesChildren(QDeclarativeListProperty<QObject> * list, QObject *element)
168 {
174 {
169 // Empty implementation; the children are parsed in componentComplete instead
175 // Empty implementation; the children are parsed in componentComplete instead
170 Q_UNUSED(list);
176 Q_UNUSED(list);
171 Q_UNUSED(element);
177 Q_UNUSED(element);
172 }
178 }
173
179
174 DeclarativeBarSet *DeclarativeGroupedBarSeries::at(int index)
180 DeclarativeBarSet *DeclarativeGroupedBarSeries::at(int index)
175 {
181 {
176 QList<QBarSet*> setList = barSets();
182 QList<QBarSet*> setList = barSets();
177 if (index >= 0 && index < setList.count())
183 if (index >= 0 && index < setList.count())
178 return qobject_cast<DeclarativeBarSet *>(setList[index]);
184 return qobject_cast<DeclarativeBarSet *>(setList[index]);
179
185
180 return 0;
186 return 0;
181 }
187 }
182
188
183 DeclarativeBarSet *DeclarativeGroupedBarSeries::insert(int index, QString label, QVariantList values)
189 DeclarativeBarSet *DeclarativeGroupedBarSeries::insert(int index, QString label, QVariantList values)
184 {
190 {
185 DeclarativeBarSet *barset = new DeclarativeBarSet(this);
191 DeclarativeBarSet *barset = new DeclarativeBarSet(this);
186 barset->setLabel(label);
192 barset->setLabel(label);
187 barset->setValues(values);
193 barset->setValues(values);
188 if (QGroupedBarSeries::insert(index, barset))
194 if (QGroupedBarSeries::insert(index, barset))
189 return barset;
195 return barset;
190 delete barset;
196 delete barset;
191 return 0;
197 return 0;
192 }
198 }
193
199
194 DeclarativeStackedBarSeries::DeclarativeStackedBarSeries(QDeclarativeItem *parent) :
200 DeclarativeStackedBarSeries::DeclarativeStackedBarSeries(QDeclarativeItem *parent) :
195 QStackedBarSeries(parent)
201 QStackedBarSeries(parent)
196 {
202 {
197 }
203 }
198
204
199 void DeclarativeStackedBarSeries::classBegin()
205 void DeclarativeStackedBarSeries::classBegin()
200 {
206 {
201 }
207 }
202
208
203 void DeclarativeStackedBarSeries::componentComplete()
209 void DeclarativeStackedBarSeries::componentComplete()
204 {
210 {
205 foreach(QObject *child, children()) {
211 foreach(QObject *child, children()) {
206 if (qobject_cast<DeclarativeBarSet *>(child)) {
212 if (qobject_cast<DeclarativeBarSet *>(child)) {
207 QBarSeries::append(qobject_cast<DeclarativeBarSet *>(child));
213 QBarSeries::append(qobject_cast<DeclarativeBarSet *>(child));
208 } else if(qobject_cast<QVBarModelMapper *>(child)) {
214 } else if(qobject_cast<QVBarModelMapper *>(child)) {
209 QVBarModelMapper *mapper = qobject_cast<QVBarModelMapper *>(child);
215 QVBarModelMapper *mapper = qobject_cast<QVBarModelMapper *>(child);
210 mapper->setSeries(this);
216 mapper->setSeries(this);
211 } else if(qobject_cast<QHBarModelMapper *>(child)) {
217 } else if(qobject_cast<QHBarModelMapper *>(child)) {
212 QHBarModelMapper *mapper = qobject_cast<QHBarModelMapper *>(child);
218 QHBarModelMapper *mapper = qobject_cast<QHBarModelMapper *>(child);
213 mapper->setSeries(this);
219 mapper->setSeries(this);
214 }
220 }
215 }
221 }
216 }
222 }
217
223
218 QDeclarativeListProperty<QObject> DeclarativeStackedBarSeries::seriesChildren()
224 QDeclarativeListProperty<QObject> DeclarativeStackedBarSeries::seriesChildren()
219 {
225 {
220 return QDeclarativeListProperty<QObject>(this, 0, &DeclarativeBarSeries::appendSeriesChildren);
226 return QDeclarativeListProperty<QObject>(this, 0, &DeclarativeBarSeries::appendSeriesChildren);
221 }
227 }
222
228
223 void DeclarativeStackedBarSeries::appendSeriesChildren(QDeclarativeListProperty<QObject> * list, QObject *element)
229 void DeclarativeStackedBarSeries::appendSeriesChildren(QDeclarativeListProperty<QObject> * list, QObject *element)
224 {
230 {
225 // Empty implementation; the children are parsed in componentComplete instead
231 // Empty implementation; the children are parsed in componentComplete instead
226 Q_UNUSED(list);
232 Q_UNUSED(list);
227 Q_UNUSED(element);
233 Q_UNUSED(element);
228 }
234 }
229
235
230 DeclarativeBarSet *DeclarativeStackedBarSeries::at(int index)
236 DeclarativeBarSet *DeclarativeStackedBarSeries::at(int index)
231 {
237 {
232 QList<QBarSet*> setList = barSets();
238 QList<QBarSet*> setList = barSets();
233 if (index >= 0 && index < setList.count())
239 if (index >= 0 && index < setList.count())
234 return qobject_cast<DeclarativeBarSet *>(setList[index]);
240 return qobject_cast<DeclarativeBarSet *>(setList[index]);
235
241
236 return 0;
242 return 0;
237 }
243 }
238
244
239 DeclarativeBarSet *DeclarativeStackedBarSeries::insert(int index, QString label, QVariantList values)
245 DeclarativeBarSet *DeclarativeStackedBarSeries::insert(int index, QString label, QVariantList values)
240 {
246 {
241 DeclarativeBarSet *barset = new DeclarativeBarSet(this);
247 DeclarativeBarSet *barset = new DeclarativeBarSet(this);
242 barset->setLabel(label);
248 barset->setLabel(label);
243 barset->setValues(values);
249 barset->setValues(values);
244 if (QStackedBarSeries::insert(index, barset))
250 if (QStackedBarSeries::insert(index, barset))
245 return barset;
251 return barset;
246 delete barset;
252 delete barset;
247 return 0;
253 return 0;
248 }
254 }
249
255
250 DeclarativePercentBarSeries::DeclarativePercentBarSeries(QDeclarativeItem *parent) :
256 DeclarativePercentBarSeries::DeclarativePercentBarSeries(QDeclarativeItem *parent) :
251 QPercentBarSeries(parent)
257 QPercentBarSeries(parent)
252 {
258 {
253 }
259 }
254
260
255 void DeclarativePercentBarSeries::classBegin()
261 void DeclarativePercentBarSeries::classBegin()
256 {
262 {
257 }
263 }
258
264
259 void DeclarativePercentBarSeries::componentComplete()
265 void DeclarativePercentBarSeries::componentComplete()
260 {
266 {
261 foreach(QObject *child, children()) {
267 foreach(QObject *child, children()) {
262 if (qobject_cast<DeclarativeBarSet *>(child)) {
268 if (qobject_cast<DeclarativeBarSet *>(child)) {
263 QBarSeries::append(qobject_cast<DeclarativeBarSet *>(child));
269 QBarSeries::append(qobject_cast<DeclarativeBarSet *>(child));
264 } else if(qobject_cast<QVBarModelMapper *>(child)) {
270 } else if(qobject_cast<QVBarModelMapper *>(child)) {
265 QVBarModelMapper *mapper = qobject_cast<QVBarModelMapper *>(child);
271 QVBarModelMapper *mapper = qobject_cast<QVBarModelMapper *>(child);
266 mapper->setSeries(this);
272 mapper->setSeries(this);
267 } else if(qobject_cast<QHBarModelMapper *>(child)) {
273 } else if(qobject_cast<QHBarModelMapper *>(child)) {
268 QHBarModelMapper *mapper = qobject_cast<QHBarModelMapper *>(child);
274 QHBarModelMapper *mapper = qobject_cast<QHBarModelMapper *>(child);
269 mapper->setSeries(this);
275 mapper->setSeries(this);
270 }
276 }
271 }
277 }
272 }
278 }
273
279
274 QDeclarativeListProperty<QObject> DeclarativePercentBarSeries::seriesChildren()
280 QDeclarativeListProperty<QObject> DeclarativePercentBarSeries::seriesChildren()
275 {
281 {
276 return QDeclarativeListProperty<QObject>(this, 0, &DeclarativeBarSeries::appendSeriesChildren);
282 return QDeclarativeListProperty<QObject>(this, 0, &DeclarativeBarSeries::appendSeriesChildren);
277 }
283 }
278
284
279 void DeclarativePercentBarSeries::appendSeriesChildren(QDeclarativeListProperty<QObject> * list, QObject *element)
285 void DeclarativePercentBarSeries::appendSeriesChildren(QDeclarativeListProperty<QObject> * list, QObject *element)
280 {
286 {
281 // Empty implementation; the children are parsed in componentComplete instead
287 // Empty implementation; the children are parsed in componentComplete instead
282 Q_UNUSED(list);
288 Q_UNUSED(list);
283 Q_UNUSED(element);
289 Q_UNUSED(element);
284 }
290 }
285
291
286 DeclarativeBarSet *DeclarativePercentBarSeries::at(int index)
292 DeclarativeBarSet *DeclarativePercentBarSeries::at(int index)
287 {
293 {
288 QList<QBarSet*> setList = barSets();
294 QList<QBarSet*> setList = barSets();
289 if (index >= 0 && index < setList.count())
295 if (index >= 0 && index < setList.count())
290 return qobject_cast<DeclarativeBarSet *>(setList[index]);
296 return qobject_cast<DeclarativeBarSet *>(setList[index]);
291
297
292 return 0;
298 return 0;
293 }
299 }
294
300
295 DeclarativeBarSet *DeclarativePercentBarSeries::insert(int index, QString label, QVariantList values)
301 DeclarativeBarSet *DeclarativePercentBarSeries::insert(int index, QString label, QVariantList values)
296 {
302 {
297 DeclarativeBarSet *barset = new DeclarativeBarSet(this);
303 DeclarativeBarSet *barset = new DeclarativeBarSet(this);
298 barset->setLabel(label);
304 barset->setLabel(label);
299 barset->setValues(values);
305 barset->setValues(values);
300 if (QPercentBarSeries::insert(index, barset))
306 if (QPercentBarSeries::insert(index, barset))
301 return barset;
307 return barset;
302 delete barset;
308 delete barset;
303 return 0;
309 return 0;
304 }
310 }
305
311
306 #include "moc_declarativebarseries.cpp"
312 #include "moc_declarativebarseries.cpp"
307
313
308 QTCOMMERCIALCHART_END_NAMESPACE
314 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,392 +1,441
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 chart with one pie series:
37 The following QML shows how to create a simple chart with one pie series:
38 \snippet ../examples/qmlpiechart/qml/qmlpiechart/main.qml 1
38 \snippet ../examples/qmlpiechart/qml/qmlpiechart/main.qml 1
39 \snippet ../examples/qmlpiechart/qml/qmlpiechart/main.qml 2
39 \snippet ../examples/qmlpiechart/qml/qmlpiechart/main.qml 2
40 \snippet ../examples/qmlpiechart/qml/qmlpiechart/main.qml 3
40 \snippet ../examples/qmlpiechart/qml/qmlpiechart/main.qml 3
41
41
42 \beginfloatleft
42 \beginfloatleft
43 \image examples_qmlpiechart.png
43 \image examples_qmlpiechart.png
44 \endfloat
44 \endfloat
45 \clearfloat
45 \clearfloat
46 */
46 */
47
47
48 /*!
48 /*!
49 \qmlproperty Theme ChartView::theme
49 \qmlproperty Theme ChartView::theme
50 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
51 widths and chart background.
51 widths and chart background.
52 */
52 */
53
53
54 /*!
54 /*!
55 \qmlproperty Animation ChartView::animation
55 \qmlproperty Animation ChartView::animation
56 Animation configuration of the chart. One of ChartView.NoAnimation, ChartView.GridAxisAnimations,
56 Animation configuration of the chart. One of ChartView.NoAnimation, ChartView.GridAxisAnimations,
57 ChartView.SeriesAnimations or ChartView.AllAnimations.
57 ChartView.SeriesAnimations or ChartView.AllAnimations.
58 */
58 */
59
59
60 /*!
60 /*!
61 \qmlproperty Font ChartView::titleFont
61 \qmlproperty Font ChartView::titleFont
62 The title font of the chart
62 The title font of the chart
63
63
64 See the \l {Font} {QML Font Element} for detailed documentation.
64 See the \l {Font} {QML Font Element} for detailed documentation.
65 */
65 */
66
66
67 /*!
67 /*!
68 \qmlproperty string ChartView::title
68 \qmlproperty string ChartView::title
69 The title of the chart, shown on top of the chart.
69 The title of the chart, shown on top of the chart.
70 \sa ChartView::titleColor
70 \sa ChartView::titleColor
71 */
71 */
72
72
73 /*!
73 /*!
74 \qmlproperty string ChartView::titleColor
74 \qmlproperty string ChartView::titleColor
75 The color of the title text.
75 The color of the title text.
76 */
76 */
77
77
78 /*!
78 /*!
79 \qmlproperty Axis ChartView::axisX
79 \qmlproperty Axis ChartView::axisX
80 The x-axis of the chart.
80 The x-axis of the chart.
81 */
81 */
82
82
83 /*!
83 /*!
84 \qmlproperty Axis ChartView::axisY
84 \qmlproperty Axis ChartView::axisY
85 The default y-axis of the chart.
85 The default y-axis of the chart.
86 */
86 */
87
87
88 /*!
88 /*!
89 \qmlproperty Legend ChartView::legend
89 \qmlproperty Legend ChartView::legend
90 The legend of the chart. Legend lists all the series, pie slices and bar sets added on the chart.
90 The legend of the chart. Legend lists all the series, pie slices and bar sets added on the chart.
91 */
91 */
92
92
93 /*!
93 /*!
94 \qmlproperty int ChartView::count
94 \qmlproperty int ChartView::count
95 The count of series added to the chart.
95 The count of series added to the chart.
96 */
96 */
97
97
98 /*!
98 /*!
99 \qmlproperty color ChartView::backgroundColor
99 \qmlproperty color ChartView::backgroundColor
100 The color of the chart's background. By default background color is defined by chart theme.
100 The color of the chart's background. By default background color is defined by chart theme.
101 \sa ChartView::theme
101 \sa ChartView::theme
102 */
102 */
103
103
104 /*!
104 /*!
105 \qmlproperty bool ChartView::dropShadowEnabled
105 \qmlproperty bool ChartView::dropShadowEnabled
106 The chart's border drop shadow. Set to true to enable drop shadow.
106 The chart's border drop shadow. Set to true to enable drop shadow.
107 */
107 */
108
108
109 /*!
109 /*!
110 \qmlmethod AbstractSeries ChartView::series(int index)
111 Returns the series with \a index on the chart. This allows you to loop through the series of a chart together with
112 the count property of the chart.
113 */
114
115 /*!
116 \qmlmethod AbstractSeries ChartView::series(string name)
117 Returns the first series on the chart with \a name. If there is no series with that name, returns null.
118 */
119
120 /*!
121 \qmlmethod AbstractSeries ChartView::createSeries(SeriesType type, string name)
122 Creates a series object of \a type to the chart. For example:
123 \code
124 var scatter = chartView.createSeries(ChartView.SeriesTypeScatter, "scatter series");
125 scatter.markerSize = 22;
126 scatter.append(1.1, 2.0);
127 \endcode
128 */
129
130 /*!
110 \qmlmethod Axis ChartView::axisY(QAbstractSeries *series)
131 \qmlmethod Axis ChartView::axisY(QAbstractSeries *series)
111 The y-axis of the series. This is the same as the default y-axis of the chart, unless you have
132 The y-axis of the series. This is the same as the default y-axis of the chart as multiple y-axes are not yet supported.
112 explicitly defined the series to have a non-default y-axis.
133 */
134
135 /*!
136 \qmlmethod ChartView::zoomY(real factor)
137 Zooms in by \a factor on the center of the chart.
138 */
139
140 /*!
141 \qmlmethod ChartView::scrollLeft(real pixels)
142 Scrolls to left by \a pixels. This is a convenience function that suits for example for key navigation.
143 \sa Axis::min, Axis::max
144 */
145
146 /*!
147 \qmlmethod ChartView::scrollRight(real pixels)
148 Scrolls to right by \a pixels. This is a convenience function that suits for example for key navigation.
149 \sa Axis::min, Axis::max
150 */
151
152 /*!
153 \qmlmethod ChartView::scrollUp(real pixels)
154 Scrolls up by \a pixels. This is a convenience function that suits for example for key navigation.
155 \sa Axis::min, Axis::max
156 */
157
158 /*!
159 \qmlmethod ChartView::scrollDown(real pixels)
160 Scrolls down by \a pixels. This is a convenience function that suits for example for key navigation.
161 \sa Axis::min, Axis::max
113 */
162 */
114
163
115 DeclarativeChart::DeclarativeChart(QDeclarativeItem *parent)
164 DeclarativeChart::DeclarativeChart(QDeclarativeItem *parent)
116 : QDeclarativeItem(parent),
165 : QDeclarativeItem(parent),
117 m_chart(new QChart(this))
166 m_chart(new QChart(this))
118 {
167 {
119 setFlag(QGraphicsItem::ItemHasNoContents, false);
168 setFlag(QGraphicsItem::ItemHasNoContents, false);
120 // m_chart->axisX()->setNiceNumbersEnabled(false);
169 // m_chart->axisX()->setNiceNumbersEnabled(false);
121 }
170 }
122
171
123 DeclarativeChart::~DeclarativeChart()
172 DeclarativeChart::~DeclarativeChart()
124 {
173 {
125 delete m_chart;
174 delete m_chart;
126 }
175 }
127
176
128 void DeclarativeChart::childEvent(QChildEvent *event)
177 void DeclarativeChart::childEvent(QChildEvent *event)
129 {
178 {
130 if (event->type() == QEvent::ChildAdded) {
179 if (event->type() == QEvent::ChildAdded) {
131 if (qobject_cast<QAbstractSeries *>(event->child())) {
180 if (qobject_cast<QAbstractSeries *>(event->child())) {
132 m_chart->addSeries(qobject_cast<QAbstractSeries *>(event->child()));
181 m_chart->addSeries(qobject_cast<QAbstractSeries *>(event->child()));
133 }
182 }
134 }
183 }
135 }
184 }
136
185
137 void DeclarativeChart::componentComplete()
186 void DeclarativeChart::componentComplete()
138 {
187 {
139 foreach(QObject *child, children()) {
188 foreach(QObject *child, children()) {
140 if (qobject_cast<QAbstractSeries *>(child)) {
189 if (qobject_cast<QAbstractSeries *>(child)) {
141 // qDebug() << "DeclarativeChart::componentComplete(), add: " << child;
190 // qDebug() << "DeclarativeChart::componentComplete(), add: " << child;
142 // TODO: how about optional y-axis?
191 // TODO: how about optional y-axis?
143 m_chart->addSeries(qobject_cast<QAbstractSeries *>(child));
192 m_chart->addSeries(qobject_cast<QAbstractSeries *>(child));
144 }
193 }
145 }
194 }
146 QDeclarativeItem::componentComplete();
195 QDeclarativeItem::componentComplete();
147 }
196 }
148
197
149 void DeclarativeChart::geometryChanged(const QRectF &newGeometry, const QRectF &oldGeometry)
198 void DeclarativeChart::geometryChanged(const QRectF &newGeometry, const QRectF &oldGeometry)
150 {
199 {
151 // qDebug() << "DeclarativeChart::geometryChanged" << newGeometry.width() << newGeometry.height();
200 // qDebug() << "DeclarativeChart::geometryChanged" << newGeometry.width() << newGeometry.height();
152 if (newGeometry.isValid()) {
201 if (newGeometry.isValid()) {
153 if (newGeometry.width() > 0 && newGeometry.height() > 0) {
202 if (newGeometry.width() > 0 && newGeometry.height() > 0) {
154 m_chart->resize(newGeometry.width(), newGeometry.height());
203 m_chart->resize(newGeometry.width(), newGeometry.height());
155 }
204 }
156 }
205 }
157 QDeclarativeItem::geometryChanged(newGeometry, oldGeometry);
206 QDeclarativeItem::geometryChanged(newGeometry, oldGeometry);
158 }
207 }
159
208
160 void DeclarativeChart::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
209 void DeclarativeChart::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
161 {
210 {
162 Q_UNUSED(option)
211 Q_UNUSED(option)
163 Q_UNUSED(widget)
212 Q_UNUSED(widget)
164
213
165 // TODO: optimized?
214 // TODO: optimized?
166 painter->setRenderHint(QPainter::Antialiasing, true);
215 painter->setRenderHint(QPainter::Antialiasing, true);
167 }
216 }
168
217
169 void DeclarativeChart::setTheme(DeclarativeChart::Theme theme)
218 void DeclarativeChart::setTheme(DeclarativeChart::Theme theme)
170 {
219 {
171 QChart::ChartTheme chartTheme = (QChart::ChartTheme) theme;
220 QChart::ChartTheme chartTheme = (QChart::ChartTheme) theme;
172 if (chartTheme != m_chart->theme())
221 if (chartTheme != m_chart->theme())
173 m_chart->setTheme(chartTheme);
222 m_chart->setTheme(chartTheme);
174 }
223 }
175
224
176 DeclarativeChart::Theme DeclarativeChart::theme()
225 DeclarativeChart::Theme DeclarativeChart::theme()
177 {
226 {
178 return (DeclarativeChart::Theme) m_chart->theme();
227 return (DeclarativeChart::Theme) m_chart->theme();
179 }
228 }
180
229
181 void DeclarativeChart::setAnimationOptions(DeclarativeChart::Animation animations)
230 void DeclarativeChart::setAnimationOptions(DeclarativeChart::Animation animations)
182 {
231 {
183 QChart::AnimationOption animationOptions = (QChart::AnimationOption) animations;
232 QChart::AnimationOption animationOptions = (QChart::AnimationOption) animations;
184 if (animationOptions != m_chart->animationOptions())
233 if (animationOptions != m_chart->animationOptions())
185 m_chart->setAnimationOptions(animationOptions);
234 m_chart->setAnimationOptions(animationOptions);
186 }
235 }
187
236
188 DeclarativeChart::Animation DeclarativeChart::animationOptions()
237 DeclarativeChart::Animation DeclarativeChart::animationOptions()
189 {
238 {
190 if (m_chart->animationOptions().testFlag(QChart::AllAnimations))
239 if (m_chart->animationOptions().testFlag(QChart::AllAnimations))
191 return DeclarativeChart::AllAnimations;
240 return DeclarativeChart::AllAnimations;
192 else if (m_chart->animationOptions().testFlag(QChart::GridAxisAnimations))
241 else if (m_chart->animationOptions().testFlag(QChart::GridAxisAnimations))
193 return DeclarativeChart::GridAxisAnimations;
242 return DeclarativeChart::GridAxisAnimations;
194 else if (m_chart->animationOptions().testFlag(QChart::SeriesAnimations))
243 else if (m_chart->animationOptions().testFlag(QChart::SeriesAnimations))
195 return DeclarativeChart::SeriesAnimations;
244 return DeclarativeChart::SeriesAnimations;
196 else
245 else
197 return DeclarativeChart::NoAnimation;
246 return DeclarativeChart::NoAnimation;
198 }
247 }
199
248
200 void DeclarativeChart::setTitle(QString title)
249 void DeclarativeChart::setTitle(QString title)
201 {
250 {
202 if (title != m_chart->title())
251 if (title != m_chart->title())
203 m_chart->setTitle(title);
252 m_chart->setTitle(title);
204 }
253 }
205 QString DeclarativeChart::title()
254 QString DeclarativeChart::title()
206 {
255 {
207 return m_chart->title();
256 return m_chart->title();
208 }
257 }
209
258
210 QAxis *DeclarativeChart::axisX()
259 QAxis *DeclarativeChart::axisX()
211 {
260 {
212 return m_chart->axisX();
261 return m_chart->axisX();
213 }
262 }
214
263
215 QAxis *DeclarativeChart::axisY(QAbstractSeries *series)
264 QAxis *DeclarativeChart::axisY(QAbstractSeries *series)
216 {
265 {
217 return m_chart->axisY(series);
266 return m_chart->axisY(series);
218 }
267 }
219
268
220 QLegend *DeclarativeChart::legend()
269 QLegend *DeclarativeChart::legend()
221 {
270 {
222 return m_chart->legend();
271 return m_chart->legend();
223 }
272 }
224
273
225 QVariantList DeclarativeChart::axisXLabels()
274 QVariantList DeclarativeChart::axisXLabels()
226 {
275 {
227 QVariantList labels;
276 QVariantList labels;
228 foreach (qreal value, m_chart->axisX()->categories()->values()) {
277 foreach (qreal value, m_chart->axisX()->categories()->values()) {
229 labels.append(value);
278 labels.append(value);
230 labels.append(m_chart->axisX()->categories()->label(value));
279 labels.append(m_chart->axisX()->categories()->label(value));
231 }
280 }
232 return labels;
281 return labels;
233 }
282 }
234
283
235 void DeclarativeChart::setAxisXLabels(QVariantList list)
284 void DeclarativeChart::setAxisXLabels(QVariantList list)
236 {
285 {
237 QVariant value(QVariant::Invalid);
286 QVariant value(QVariant::Invalid);
238 foreach (QVariant element, list) {
287 foreach (QVariant element, list) {
239 if (value.isValid() && element.type() == QVariant::String) {
288 if (value.isValid() && element.type() == QVariant::String) {
240 m_chart->axisX()->categories()->insert(value.toDouble(), element.toString());
289 m_chart->axisX()->categories()->insert(value.toDouble(), element.toString());
241 value = QVariant(QVariant::Invalid);
290 value = QVariant(QVariant::Invalid);
242 } else {
291 } else {
243 if (element.canConvert(QVariant::Double))
292 if (element.canConvert(QVariant::Double))
244 value = element;
293 value = element;
245 }
294 }
246 }
295 }
247 emit axisLabelsChanged();
296 emit axisLabelsChanged();
248 }
297 }
249
298
250 void DeclarativeChart::setTitleColor(QColor color)
299 void DeclarativeChart::setTitleColor(QColor color)
251 {
300 {
252 QBrush b = m_chart->titleBrush();
301 QBrush b = m_chart->titleBrush();
253 if (color != b.color()) {
302 if (color != b.color()) {
254 b.setColor(color);
303 b.setColor(color);
255 m_chart->setTitleBrush(b);
304 m_chart->setTitleBrush(b);
256 emit titleColorChanged();
305 emit titleColorChanged();
257 }
306 }
258 }
307 }
259
308
260 QFont DeclarativeChart::titleFont() const
309 QFont DeclarativeChart::titleFont() const
261 {
310 {
262 return m_chart->titleFont();
311 return m_chart->titleFont();
263 }
312 }
264
313
265 void DeclarativeChart::setTitleFont(const QFont& font)
314 void DeclarativeChart::setTitleFont(const QFont& font)
266 {
315 {
267 m_chart->setTitleFont(font);
316 m_chart->setTitleFont(font);
268 }
317 }
269
318
270 QColor DeclarativeChart::titleColor()
319 QColor DeclarativeChart::titleColor()
271 {
320 {
272 return m_chart->titleBrush().color();
321 return m_chart->titleBrush().color();
273 }
322 }
274
323
275 void DeclarativeChart::setBackgroundColor(QColor color)
324 void DeclarativeChart::setBackgroundColor(QColor color)
276 {
325 {
277 QBrush b = m_chart->backgroundBrush();
326 QBrush b = m_chart->backgroundBrush();
278 if (b.style() != Qt::SolidPattern || color != b.color()) {
327 if (b.style() != Qt::SolidPattern || color != b.color()) {
279 b.setStyle(Qt::SolidPattern);
328 b.setStyle(Qt::SolidPattern);
280 b.setColor(color);
329 b.setColor(color);
281 m_chart->setBackgroundBrush(b);
330 m_chart->setBackgroundBrush(b);
282 emit backgroundColorChanged();
331 emit backgroundColorChanged();
283 }
332 }
284 }
333 }
285
334
286 QColor DeclarativeChart::backgroundColor()
335 QColor DeclarativeChart::backgroundColor()
287 {
336 {
288 return m_chart->backgroundBrush().color();
337 return m_chart->backgroundBrush().color();
289 }
338 }
290
339
291 int DeclarativeChart::count()
340 int DeclarativeChart::count()
292 {
341 {
293 return m_chart->series().count();
342 return m_chart->series().count();
294 }
343 }
295
344
296 void DeclarativeChart::setDropShadowEnabled(bool enabled)
345 void DeclarativeChart::setDropShadowEnabled(bool enabled)
297 {
346 {
298 if (enabled != m_chart->isDropShadowEnabled()) {
347 if (enabled != m_chart->isDropShadowEnabled()) {
299 m_chart->setDropShadowEnabled(enabled);
348 m_chart->setDropShadowEnabled(enabled);
300 dropShadowEnabledChanged(enabled);
349 dropShadowEnabledChanged(enabled);
301 }
350 }
302 }
351 }
303
352
304 bool DeclarativeChart::dropShadowEnabled()
353 bool DeclarativeChart::dropShadowEnabled()
305 {
354 {
306 return m_chart->isDropShadowEnabled();
355 return m_chart->isDropShadowEnabled();
307 }
356 }
308
357
309 void DeclarativeChart::zoom(qreal factor)
358 void DeclarativeChart::zoom(qreal factor)
310 {
359 {
311 m_chart->zoom(factor);
360 m_chart->zoom(factor);
312 }
361 }
313
362
314 void DeclarativeChart::scrollLeft(qreal pixels)
363 void DeclarativeChart::scrollLeft(qreal pixels)
315 {
364 {
316 m_chart->scroll(QPointF(pixels, 0));
365 m_chart->scroll(QPointF(pixels, 0));
317 }
366 }
318
367
319 void DeclarativeChart::scrollRight(qreal pixels)
368 void DeclarativeChart::scrollRight(qreal pixels)
320 {
369 {
321 m_chart->scroll(QPointF(-pixels, 0));
370 m_chart->scroll(QPointF(-pixels, 0));
322 }
371 }
323
372
324 void DeclarativeChart::scrollUp(qreal pixels)
373 void DeclarativeChart::scrollUp(qreal pixels)
325 {
374 {
326 m_chart->scroll(QPointF(0, pixels));
375 m_chart->scroll(QPointF(0, pixels));
327 }
376 }
328
377
329 void DeclarativeChart::scrollDown(qreal pixels)
378 void DeclarativeChart::scrollDown(qreal pixels)
330 {
379 {
331 m_chart->scroll(QPointF(0, -pixels));
380 m_chart->scroll(QPointF(0, -pixels));
332 }
381 }
333
382
334 QAbstractSeries *DeclarativeChart::series(int index)
383 QAbstractSeries *DeclarativeChart::series(int index)
335 {
384 {
336 if (index < m_chart->series().count()) {
385 if (index < m_chart->series().count()) {
337 return m_chart->series().at(index);
386 return m_chart->series().at(index);
338 }
387 }
339 return 0;
388 return 0;
340 }
389 }
341
390
342 QAbstractSeries *DeclarativeChart::series(QString seriesName)
391 QAbstractSeries *DeclarativeChart::series(QString seriesName)
343 {
392 {
344 foreach(QAbstractSeries *series, m_chart->series()) {
393 foreach(QAbstractSeries *series, m_chart->series()) {
345 if (series->name() == seriesName)
394 if (series->name() == seriesName)
346 return series;
395 return series;
347 }
396 }
348 return 0;
397 return 0;
349 }
398 }
350
399
351 QAbstractSeries *DeclarativeChart::createSeries(DeclarativeChart::SeriesType type, QString name)
400 QAbstractSeries *DeclarativeChart::createSeries(DeclarativeChart::SeriesType type, QString name)
352 {
401 {
353 QAbstractSeries *series = 0;
402 QAbstractSeries *series = 0;
354 switch (type) {
403 switch (type) {
355 case DeclarativeChart::SeriesTypeLine:
404 case DeclarativeChart::SeriesTypeLine:
356 series = new DeclarativeLineSeries();
405 series = new DeclarativeLineSeries();
357 break;
406 break;
358 case DeclarativeChart::SeriesTypeArea:
407 case DeclarativeChart::SeriesTypeArea:
359 series = new DeclarativeAreaSeries();
408 series = new DeclarativeAreaSeries();
360 break;
409 break;
361 case DeclarativeChart::SeriesTypeBar:
410 case DeclarativeChart::SeriesTypeBar:
362 series = new DeclarativeBarSeries();
411 series = new DeclarativeBarSeries();
363 break;
412 break;
364 case DeclarativeChart::SeriesTypeStackedBar:
413 case DeclarativeChart::SeriesTypeStackedBar:
365 // TODO
414 // TODO
366 break;
415 break;
367 case DeclarativeChart::SeriesTypePercentBar:
416 case DeclarativeChart::SeriesTypePercentBar:
368 // TODO
417 // TODO
369 break;
418 break;
370 case DeclarativeChart::SeriesTypeGroupedBar:
419 case DeclarativeChart::SeriesTypeGroupedBar:
371 series = new DeclarativeGroupedBarSeries();
420 series = new DeclarativeGroupedBarSeries();
372 break;
421 break;
373 case DeclarativeChart::SeriesTypePie:
422 case DeclarativeChart::SeriesTypePie:
374 series = new DeclarativePieSeries();
423 series = new DeclarativePieSeries();
375 break;
424 break;
376 case DeclarativeChart::SeriesTypeScatter:
425 case DeclarativeChart::SeriesTypeScatter:
377 series = new DeclarativeScatterSeries();
426 series = new DeclarativeScatterSeries();
378 break;
427 break;
379 case DeclarativeChart::SeriesTypeSpline:
428 case DeclarativeChart::SeriesTypeSpline:
380 series = new DeclarativeSplineSeries();
429 series = new DeclarativeSplineSeries();
381 break;
430 break;
382 default:
431 default:
383 qWarning() << "Illegal series type";
432 qWarning() << "Illegal series type";
384 }
433 }
385 series->setName(name);
434 series->setName(name);
386 m_chart->addSeries(series);
435 m_chart->addSeries(series);
387 return series;
436 return series;
388 }
437 }
389
438
390 #include "moc_declarativechart.cpp"
439 #include "moc_declarativechart.cpp"
391
440
392 QTCOMMERCIALCHART_END_NAMESPACE
441 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,139 +1,141
1 /****************************************************************************
1 /****************************************************************************
2 **
2 **
3 ** Copyright (C) 2012 Digia Plc
3 ** Copyright (C) 2012 Digia Plc
4 ** All rights reserved.
4 ** All rights reserved.
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 **
6 **
7 ** This file is part of the Qt Commercial Charts Add-on.
7 ** This file is part of the Qt Commercial Charts Add-on.
8 **
8 **
9 ** $QT_BEGIN_LICENSE$
9 ** $QT_BEGIN_LICENSE$
10 ** Licensees holding valid Qt Commercial licenses may use this file in
10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 ** accordance with the Qt Commercial License Agreement provided with the
11 ** accordance with the Qt Commercial License Agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia.
13 ** a written agreement between you and Digia.
14 **
14 **
15 ** If you have questions regarding the use of this file, please use
15 ** If you have questions regarding the use of this file, please use
16 ** contact form at http://qt.digia.com
16 ** contact form at http://qt.digia.com
17 ** $QT_END_LICENSE$
17 ** $QT_END_LICENSE$
18 **
18 **
19 ****************************************************************************/
19 ****************************************************************************/
20
20
21 #ifndef DECLARATIVECHART_H
21 #ifndef DECLARATIVECHART_H
22 #define DECLARATIVECHART_H
22 #define DECLARATIVECHART_H
23
23
24 #include <QtCore/QtGlobal>
24 #include <QtCore/QtGlobal>
25 #include <QDeclarativeItem>
25 #include <QDeclarativeItem>
26 #include <qchart.h>
26 #include <qchart.h>
27 #include <QAxis>
27 #include <QAxis>
28
28
29 QTCOMMERCIALCHART_BEGIN_NAMESPACE
29 QTCOMMERCIALCHART_BEGIN_NAMESPACE
30
30
31 // TODO: Derive from QChart for easier definition of properties?
31 // TODO: Derive from QChart for easier definition of properties?
32 class DeclarativeChart : public QDeclarativeItem
32 class DeclarativeChart : public QDeclarativeItem
33 // TODO: for QTQUICK2: extend QQuickPainterItem instead
33 // TODO: for QTQUICK2: extend QQuickPainterItem instead
34 //class DeclarativeChart : public QQuickPaintedItem, public Chart
34 //class DeclarativeChart : public QQuickPaintedItem, public Chart
35 {
35 {
36 Q_OBJECT
36 Q_OBJECT
37 Q_PROPERTY(Theme theme READ theme WRITE setTheme)
37 Q_PROPERTY(Theme theme READ theme WRITE setTheme)
38 Q_PROPERTY(Animation animationOptions READ animationOptions WRITE setAnimationOptions)
38 Q_PROPERTY(Animation animationOptions READ animationOptions WRITE setAnimationOptions)
39 Q_PROPERTY(QString title READ title WRITE setTitle)
39 Q_PROPERTY(QString title READ title WRITE setTitle)
40 Q_PROPERTY(QFont titleFont READ titleFont WRITE setTitleFont)
40 Q_PROPERTY(QFont titleFont READ titleFont WRITE setTitleFont)
41 Q_PROPERTY(QColor titleColor READ titleColor WRITE setTitleColor NOTIFY titleColorChanged)
41 Q_PROPERTY(QColor titleColor READ titleColor WRITE setTitleColor NOTIFY titleColorChanged)
42 Q_PROPERTY(QAxis *axisX READ axisX)
42 Q_PROPERTY(QAxis *axisX READ axisX)
43 Q_PROPERTY(QAxis *axisY READ axisY)
43 Q_PROPERTY(QAxis *axisY READ axisY)
44 Q_PROPERTY(QLegend *legend READ legend)
44 Q_PROPERTY(QLegend *legend READ legend)
45 // TODO: how to define axis labels? This is not very convenient
45 // TODO: how to define axis labels? This is not very convenient
46 Q_PROPERTY(QVariantList axisXLabels READ axisXLabels WRITE setAxisXLabels NOTIFY axisLabelsChanged)
46 Q_PROPERTY(QVariantList axisXLabels READ axisXLabels WRITE setAxisXLabels NOTIFY axisLabelsChanged)
47 Q_PROPERTY(int count READ count)
47 Q_PROPERTY(int count READ count)
48 Q_PROPERTY(QColor backgroundColor READ backgroundColor WRITE setBackgroundColor NOTIFY backgroundColorChanged)
48 Q_PROPERTY(QColor backgroundColor READ backgroundColor WRITE setBackgroundColor NOTIFY backgroundColorChanged)
49 Q_PROPERTY(bool dropShadowEnabled READ dropShadowEnabled WRITE setDropShadowEnabled NOTIFY dropShadowEnabledChanged)
49 Q_PROPERTY(bool dropShadowEnabled READ dropShadowEnabled WRITE setDropShadowEnabled NOTIFY dropShadowEnabledChanged)
50 Q_ENUMS(Animation)
50 Q_ENUMS(Animation)
51 Q_ENUMS(Theme)
51 Q_ENUMS(Theme)
52 Q_ENUMS(SeriesType)
52 Q_ENUMS(SeriesType)
53
53
54 public:
54 public:
55 // duplicating enums from QChart to make the QML api namings 1-to-1 with the C++ api
55 // duplicating enums from QChart to make the QML api namings 1-to-1 with the C++ api
56 enum Theme {
56 enum Theme {
57 ChartThemeLight = 0,
57 ChartThemeLight = 0,
58 ChartThemeBlueCerulean,
58 ChartThemeBlueCerulean,
59 ChartThemeDark,
59 ChartThemeDark,
60 ChartThemeBrownSand,
60 ChartThemeBrownSand,
61 ChartThemeBlueNcs,
61 ChartThemeBlueNcs,
62 ChartThemeHighContrast,
62 ChartThemeHighContrast,
63 ChartThemeBlueIcy
63 ChartThemeBlueIcy
64 };
64 };
65
65
66 enum Animation {
66 enum Animation {
67 NoAnimation = 0x0,
67 NoAnimation = 0x0,
68 GridAxisAnimations = 0x1,
68 GridAxisAnimations = 0x1,
69 SeriesAnimations =0x2,
69 SeriesAnimations =0x2,
70 AllAnimations = 0x3
70 AllAnimations = 0x3
71 };
71 };
72
72
73 enum SeriesType {
73 enum SeriesType {
74 SeriesTypeLine,
74 SeriesTypeLine,
75 SeriesTypeArea,
75 SeriesTypeArea,
76 SeriesTypeBar,
76 SeriesTypeBar,
77 SeriesTypeStackedBar,
77 SeriesTypeStackedBar,
78 SeriesTypePercentBar,
78 SeriesTypePercentBar,
79 SeriesTypeGroupedBar,
79 SeriesTypeGroupedBar,
80 SeriesTypePie,
80 SeriesTypePie,
81 SeriesTypeScatter,
81 SeriesTypeScatter,
82 SeriesTypeSpline
82 SeriesTypeSpline
83 };
83 };
84
84
85 public:
85 public:
86 DeclarativeChart(QDeclarativeItem *parent = 0);
86 DeclarativeChart(QDeclarativeItem *parent = 0);
87 ~DeclarativeChart();
87 ~DeclarativeChart();
88
88
89 public: // From QDeclarativeItem/QGraphicsItem
89 public: // From QDeclarativeItem/QGraphicsItem
90 void childEvent(QChildEvent *event);
90 void childEvent(QChildEvent *event);
91 void componentComplete();
91 void componentComplete();
92 void geometryChanged(const QRectF &newGeometry, const QRectF &oldGeometry);
92 void geometryChanged(const QRectF &newGeometry, const QRectF &oldGeometry);
93 void paint (QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0);
93 void paint (QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0);
94
94
95 public:
95 public:
96 void setTheme(DeclarativeChart::Theme theme);
96 void setTheme(DeclarativeChart::Theme theme);
97 DeclarativeChart::Theme theme();
97 DeclarativeChart::Theme theme();
98 void setAnimationOptions(DeclarativeChart::Animation animations);
98 void setAnimationOptions(DeclarativeChart::Animation animations);
99 DeclarativeChart::Animation animationOptions();
99 DeclarativeChart::Animation animationOptions();
100 void setTitle(QString title);
100 void setTitle(QString title);
101 QString title();
101 QString title();
102 QAxis *axisX();
102 QAxis *axisX();
103 Q_INVOKABLE QAxis *axisY(QAbstractSeries *series = 0);
104 QLegend *legend();
103 QLegend *legend();
105 QVariantList axisXLabels();
104 QVariantList axisXLabels();
106 void setAxisXLabels(QVariantList list);
105 void setAxisXLabels(QVariantList list);
107 QFont titleFont() const;
106 QFont titleFont() const;
108 void setTitleFont(const QFont& font);
107 void setTitleFont(const QFont& font);
109 void setTitleColor(QColor color);
108 void setTitleColor(QColor color);
110 QColor titleColor();
109 QColor titleColor();
111 void setBackgroundColor(QColor color);
110 void setBackgroundColor(QColor color);
112 QColor backgroundColor();
111 QColor backgroundColor();
113 int count();
112 int count();
114 void setDropShadowEnabled(bool enabled);
113 void setDropShadowEnabled(bool enabled);
115 bool dropShadowEnabled();
114 bool dropShadowEnabled();
115
116 public:
117 Q_INVOKABLE QAbstractSeries *series(int index);
118 Q_INVOKABLE QAbstractSeries *series(QString seriesName);
119 Q_INVOKABLE QAbstractSeries *createSeries(DeclarativeChart::SeriesType type, QString name = "");
120 Q_INVOKABLE QAxis *axisY(QAbstractSeries *series = 0);
116 Q_INVOKABLE void zoom(qreal factor);
121 Q_INVOKABLE void zoom(qreal factor);
117 Q_INVOKABLE void scrollLeft(qreal pixels);
122 Q_INVOKABLE void scrollLeft(qreal pixels);
118 Q_INVOKABLE void scrollRight(qreal pixels);
123 Q_INVOKABLE void scrollRight(qreal pixels);
119 Q_INVOKABLE void scrollUp(qreal pixels);
124 Q_INVOKABLE void scrollUp(qreal pixels);
120 Q_INVOKABLE void scrollDown(qreal pixels);
125 Q_INVOKABLE void scrollDown(qreal pixels);
121 Q_INVOKABLE QAbstractSeries *series(int index);
122 Q_INVOKABLE QAbstractSeries *series(QString seriesName);
123 Q_INVOKABLE QAbstractSeries *createSeries(DeclarativeChart::SeriesType type, QString name = "");
124
126
125 Q_SIGNALS:
127 Q_SIGNALS:
126 void axisLabelsChanged();
128 void axisLabelsChanged();
127 void titleColorChanged();
129 void titleColorChanged();
128 void backgroundColorChanged();
130 void backgroundColorChanged();
129 void dropShadowEnabledChanged(bool enabled);
131 void dropShadowEnabledChanged(bool enabled);
130
132
131 public:
133 public:
132 // Extending QChart with DeclarativeChart is not possible because QObject does not support
134 // Extending QChart with DeclarativeChart is not possible because QObject does not support
133 // multi inheritance, so we now have a QChart as a member instead
135 // multi inheritance, so we now have a QChart as a member instead
134 QChart *m_chart;
136 QChart *m_chart;
135 };
137 };
136
138
137 QTCOMMERCIALCHART_END_NAMESPACE
139 QTCOMMERCIALCHART_END_NAMESPACE
138
140
139 #endif // DECLARATIVECHART_H
141 #endif // DECLARATIVECHART_H
@@ -1,68 +1,68
1 /****************************************************************************
1 /****************************************************************************
2 **
2 **
3 ** Copyright (C) 2012 Digia Plc
3 ** Copyright (C) 2012 Digia Plc
4 ** All rights reserved.
4 ** All rights reserved.
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 **
6 **
7 ** This file is part of the Qt Commercial Charts Add-on.
7 ** This file is part of the Qt Commercial Charts Add-on.
8 **
8 **
9 ** $QT_BEGIN_LICENSE$
9 ** $QT_BEGIN_LICENSE$
10 ** Licensees holding valid Qt Commercial licenses may use this file in
10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 ** accordance with the Qt Commercial License Agreement provided with the
11 ** accordance with the Qt Commercial License Agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia.
13 ** a written agreement between you and Digia.
14 **
14 **
15 ** If you have questions regarding the use of this file, please use
15 ** If you have questions regarding the use of this file, please use
16 ** contact form at http://qt.digia.com
16 ** contact form at http://qt.digia.com
17 ** $QT_END_LICENSE$
17 ** $QT_END_LICENSE$
18 **
18 **
19 ****************************************************************************/
19 ****************************************************************************/
20
20
21 #ifndef DECLARATIVELINESERIES_H
21 #ifndef DECLARATIVELINESERIES_H
22 #define DECLARATIVELINESERIES_H
22 #define DECLARATIVELINESERIES_H
23
23
24 #include "qchartglobal.h"
24 #include "qchartglobal.h"
25 #include "qlineseries.h"
25 #include "qlineseries.h"
26 #include "declarativexyseries.h"
26 #include "declarativexyseries.h"
27 #include <QDeclarativeParserStatus>
27 #include <QDeclarativeParserStatus>
28 #include <QDeclarativeListProperty>
28 #include <QDeclarativeListProperty>
29 #include <QDeclarativeParserStatus>
29 #include <QDeclarativeParserStatus>
30
30
31 QTCOMMERCIALCHART_BEGIN_NAMESPACE
31 QTCOMMERCIALCHART_BEGIN_NAMESPACE
32
32
33 class DeclarativeLineSeries : public QLineSeries, public DeclarativeXySeries, public QDeclarativeParserStatus
33 class DeclarativeLineSeries : public QLineSeries, public DeclarativeXySeries, public QDeclarativeParserStatus
34 {
34 {
35 Q_OBJECT
35 Q_OBJECT
36 Q_INTERFACES(QDeclarativeParserStatus)
36 Q_INTERFACES(QDeclarativeParserStatus)
37 Q_PROPERTY(int count READ count NOTIFY countChanged)
37 Q_PROPERTY(int count READ count NOTIFY countChanged)
38 Q_PROPERTY(QDeclarativeListProperty<QObject> declarativeChildren READ declarativeChildren)
38 Q_PROPERTY(QDeclarativeListProperty<QObject> declarativeChildren READ declarativeChildren)
39 Q_CLASSINFO("DefaultProperty", "declarativeChildren")
39 Q_CLASSINFO("DefaultProperty", "declarativeChildren")
40
40
41 public:
41 public:
42 explicit DeclarativeLineSeries(QObject *parent = 0);
42 explicit DeclarativeLineSeries(QObject *parent = 0);
43 QXYSeries *xySeries();
43 QXYSeries *xySeries();
44 QDeclarativeListProperty<QObject> declarativeChildren();
44 QDeclarativeListProperty<QObject> declarativeChildren();
45
45
46 public: // from QDeclarativeParserStatus
46 public: // from QDeclarativeParserStatus
47 void classBegin() { DeclarativeXySeries::classBegin(); }
47 void classBegin() { DeclarativeXySeries::classBegin(); }
48 void componentComplete() { DeclarativeXySeries::componentComplete(); }
48 void componentComplete() { DeclarativeXySeries::componentComplete(); }
49
49
50 public: // from QLineSeries
50 public:
51 Q_INVOKABLE void append(qreal x, qreal y) { QLineSeries::append(x, y); }
51 Q_INVOKABLE void append(qreal x, qreal y) { DeclarativeXySeries::append(x, y); }
52 Q_INVOKABLE void replace(qreal oldX, qreal oldY, qreal newX, qreal newY) { QLineSeries::replace(oldX, oldY, newX, newY); }
52 Q_INVOKABLE void replace(qreal oldX, qreal oldY, qreal newX, qreal newY) { DeclarativeXySeries::replace(oldX, oldY, newX, newY); }
53 Q_INVOKABLE void remove(qreal x, qreal y) { QLineSeries::remove(x, y); }
53 Q_INVOKABLE void remove(qreal x, qreal y) { DeclarativeXySeries::remove(x, y); }
54 Q_INVOKABLE void insert(int index, qreal x, qreal y) { QLineSeries::insert(index, QPointF(x, y)); }
54 Q_INVOKABLE void insert(int index, qreal x, qreal y) { DeclarativeXySeries::insert(index, x, y); }
55 Q_INVOKABLE void clear() { QLineSeries::clear(); }
55 Q_INVOKABLE void clear() { DeclarativeXySeries::clear(); }
56 Q_INVOKABLE DeclarativeXyPoint *at(int index) { return DeclarativeXySeries::at(index); }
56 Q_INVOKABLE QPointF at(int index) { return DeclarativeXySeries::at(index); }
57
57
58 Q_SIGNALS:
58 Q_SIGNALS:
59 void countChanged(int count);
59 void countChanged(int count);
60
60
61 public Q_SLOTS:
61 public Q_SLOTS:
62 static void appendDeclarativeChildren(QDeclarativeListProperty<QObject> *list, QObject *element);
62 static void appendDeclarativeChildren(QDeclarativeListProperty<QObject> *list, QObject *element);
63 void handleCountChanged(int index);
63 void handleCountChanged(int index);
64 };
64 };
65
65
66 QTCOMMERCIALCHART_END_NAMESPACE
66 QTCOMMERCIALCHART_END_NAMESPACE
67
67
68 #endif // DECLARATIVELINESERIES_H
68 #endif // DECLARATIVELINESERIES_H
@@ -1,67 +1,67
1 /****************************************************************************
1 /****************************************************************************
2 **
2 **
3 ** Copyright (C) 2012 Digia Plc
3 ** Copyright (C) 2012 Digia Plc
4 ** All rights reserved.
4 ** All rights reserved.
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 **
6 **
7 ** This file is part of the Qt Commercial Charts Add-on.
7 ** This file is part of the Qt Commercial Charts Add-on.
8 **
8 **
9 ** $QT_BEGIN_LICENSE$
9 ** $QT_BEGIN_LICENSE$
10 ** Licensees holding valid Qt Commercial licenses may use this file in
10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 ** accordance with the Qt Commercial License Agreement provided with the
11 ** accordance with the Qt Commercial License Agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia.
13 ** a written agreement between you and Digia.
14 **
14 **
15 ** If you have questions regarding the use of this file, please use
15 ** If you have questions regarding the use of this file, please use
16 ** contact form at http://qt.digia.com
16 ** contact form at http://qt.digia.com
17 ** $QT_END_LICENSE$
17 ** $QT_END_LICENSE$
18 **
18 **
19 ****************************************************************************/
19 ****************************************************************************/
20
20
21 #ifndef DECLARATIVESCATTERSERIES_H
21 #ifndef DECLARATIVESCATTERSERIES_H
22 #define DECLARATIVESCATTERSERIES_H
22 #define DECLARATIVESCATTERSERIES_H
23
23
24 #include "qchartglobal.h"
24 #include "qchartglobal.h"
25 #include "qscatterseries.h"
25 #include "qscatterseries.h"
26 #include "declarativexyseries.h"
26 #include "declarativexyseries.h"
27 #include <QDeclarativeListProperty>
27 #include <QDeclarativeListProperty>
28 #include <QDeclarativeParserStatus>
28 #include <QDeclarativeParserStatus>
29
29
30 QTCOMMERCIALCHART_BEGIN_NAMESPACE
30 QTCOMMERCIALCHART_BEGIN_NAMESPACE
31
31
32 class DeclarativeScatterSeries : public QScatterSeries, public DeclarativeXySeries, public QDeclarativeParserStatus
32 class DeclarativeScatterSeries : public QScatterSeries, public DeclarativeXySeries, public QDeclarativeParserStatus
33 {
33 {
34 Q_OBJECT
34 Q_OBJECT
35 Q_INTERFACES(QDeclarativeParserStatus)
35 Q_INTERFACES(QDeclarativeParserStatus)
36 Q_PROPERTY(int count READ count NOTIFY countChanged)
36 Q_PROPERTY(int count READ count NOTIFY countChanged)
37 Q_PROPERTY(QDeclarativeListProperty<QObject> declarativeChildren READ declarativeChildren)
37 Q_PROPERTY(QDeclarativeListProperty<QObject> declarativeChildren READ declarativeChildren)
38 Q_CLASSINFO("DefaultProperty", "declarativeChildren")
38 Q_CLASSINFO("DefaultProperty", "declarativeChildren")
39
39
40 public:
40 public:
41 explicit DeclarativeScatterSeries(QObject *parent = 0);
41 explicit DeclarativeScatterSeries(QObject *parent = 0);
42 QXYSeries *xySeries();
42 QXYSeries *xySeries();
43 QDeclarativeListProperty<QObject> declarativeChildren();
43 QDeclarativeListProperty<QObject> declarativeChildren();
44
44
45 public: // from QDeclarativeParserStatus
45 public: // from QDeclarativeParserStatus
46 void classBegin() { DeclarativeXySeries::classBegin(); }
46 void classBegin() { DeclarativeXySeries::classBegin(); }
47 void componentComplete() { DeclarativeXySeries::componentComplete(); }
47 void componentComplete() { DeclarativeXySeries::componentComplete(); }
48
48
49 public: // from QScatterSeries
49 public:
50 Q_INVOKABLE void append(qreal x, qreal y) { QScatterSeries::append(x, y); }
50 Q_INVOKABLE void append(qreal x, qreal y) { DeclarativeXySeries::append(x, y); }
51 Q_INVOKABLE void replace(qreal oldX, qreal oldY, qreal newX, qreal newY) { QScatterSeries::replace(oldX, oldY, newX, newY); }
51 Q_INVOKABLE void replace(qreal oldX, qreal oldY, qreal newX, qreal newY) { DeclarativeXySeries::replace(oldX, oldY, newX, newY); }
52 Q_INVOKABLE void remove(qreal x, qreal y) { QScatterSeries::remove(x, y); }
52 Q_INVOKABLE void remove(qreal x, qreal y) { DeclarativeXySeries::remove(x, y); }
53 Q_INVOKABLE void clear() { QScatterSeries::clear(); }
53 Q_INVOKABLE void insert(int index, qreal x, qreal y) { DeclarativeXySeries::insert(index, x, y); }
54 Q_INVOKABLE void insert(int index, qreal x, qreal y) { QScatterSeries::insert(index, QPointF(x, y)); }
54 Q_INVOKABLE void clear() { DeclarativeXySeries::clear(); }
55 Q_INVOKABLE DeclarativeXyPoint *at(int index) { return DeclarativeXySeries::at(index); }
55 Q_INVOKABLE QPointF at(int index) { return DeclarativeXySeries::at(index); }
56
56
57 Q_SIGNALS:
57 Q_SIGNALS:
58 void countChanged(int count);
58 void countChanged(int count);
59
59
60 public Q_SLOTS:
60 public Q_SLOTS:
61 static void appendDeclarativeChildren(QDeclarativeListProperty<QObject> *list, QObject *element);
61 static void appendDeclarativeChildren(QDeclarativeListProperty<QObject> *list, QObject *element);
62 void handleCountChanged(int index);
62 void handleCountChanged(int index);
63 };
63 };
64
64
65 QTCOMMERCIALCHART_END_NAMESPACE
65 QTCOMMERCIALCHART_END_NAMESPACE
66
66
67 #endif // DECLARATIVESCATTERSERIES_H
67 #endif // DECLARATIVESCATTERSERIES_H
@@ -1,68 +1,68
1 /****************************************************************************
1 /****************************************************************************
2 **
2 **
3 ** Copyright (C) 2012 Digia Plc
3 ** Copyright (C) 2012 Digia Plc
4 ** All rights reserved.
4 ** All rights reserved.
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 **
6 **
7 ** This file is part of the Qt Commercial Charts Add-on.
7 ** This file is part of the Qt Commercial Charts Add-on.
8 **
8 **
9 ** $QT_BEGIN_LICENSE$
9 ** $QT_BEGIN_LICENSE$
10 ** Licensees holding valid Qt Commercial licenses may use this file in
10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 ** accordance with the Qt Commercial License Agreement provided with the
11 ** accordance with the Qt Commercial License Agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia.
13 ** a written agreement between you and Digia.
14 **
14 **
15 ** If you have questions regarding the use of this file, please use
15 ** If you have questions regarding the use of this file, please use
16 ** contact form at http://qt.digia.com
16 ** contact form at http://qt.digia.com
17 ** $QT_END_LICENSE$
17 ** $QT_END_LICENSE$
18 **
18 **
19 ****************************************************************************/
19 ****************************************************************************/
20
20
21 #ifndef DECLARATIVESPLINESERIES_H
21 #ifndef DECLARATIVESPLINESERIES_H
22 #define DECLARATIVESPLINESERIES_H
22 #define DECLARATIVESPLINESERIES_H
23
23
24 #include "qchartglobal.h"
24 #include "qchartglobal.h"
25 #include "qsplineseries.h"
25 #include "qsplineseries.h"
26 #include "declarativexyseries.h"
26 #include "declarativexyseries.h"
27 #include <QDeclarativeParserStatus>
27 #include <QDeclarativeParserStatus>
28 #include <QDeclarativeListProperty>
28 #include <QDeclarativeListProperty>
29 #include <QDeclarativeParserStatus>
29 #include <QDeclarativeParserStatus>
30
30
31 QTCOMMERCIALCHART_BEGIN_NAMESPACE
31 QTCOMMERCIALCHART_BEGIN_NAMESPACE
32
32
33 class DeclarativeSplineSeries : public QSplineSeries, public DeclarativeXySeries, public QDeclarativeParserStatus
33 class DeclarativeSplineSeries : public QSplineSeries, public DeclarativeXySeries, public QDeclarativeParserStatus
34 {
34 {
35 Q_OBJECT
35 Q_OBJECT
36 Q_INTERFACES(QDeclarativeParserStatus)
36 Q_INTERFACES(QDeclarativeParserStatus)
37 Q_PROPERTY(int count READ count NOTIFY countChanged)
37 Q_PROPERTY(int count READ count NOTIFY countChanged)
38 Q_PROPERTY(QDeclarativeListProperty<QObject> declarativeChildren READ declarativeChildren)
38 Q_PROPERTY(QDeclarativeListProperty<QObject> declarativeChildren READ declarativeChildren)
39 Q_CLASSINFO("DefaultProperty", "declarativeChildren")
39 Q_CLASSINFO("DefaultProperty", "declarativeChildren")
40
40
41 public:
41 public:
42 explicit DeclarativeSplineSeries(QObject *parent = 0);
42 explicit DeclarativeSplineSeries(QObject *parent = 0);
43 QXYSeries *xySeries();
43 QXYSeries *xySeries();
44 QDeclarativeListProperty<QObject> declarativeChildren();
44 QDeclarativeListProperty<QObject> declarativeChildren();
45
45
46 public: // from QDeclarativeParserStatus
46 public: // from QDeclarativeParserStatus
47 void classBegin() { DeclarativeXySeries::classBegin(); }
47 void classBegin() { DeclarativeXySeries::classBegin(); }
48 void componentComplete() { DeclarativeXySeries::componentComplete(); }
48 void componentComplete() { DeclarativeXySeries::componentComplete(); }
49
49
50 public: // from QSplineSeries
50 public:
51 Q_INVOKABLE void append(qreal x, qreal y) { QSplineSeries::append(x, y); }
51 Q_INVOKABLE void append(qreal x, qreal y) { DeclarativeXySeries::append(x, y); }
52 Q_INVOKABLE void replace(qreal oldX, qreal oldY, qreal newX, qreal newY) { QSplineSeries::replace(oldX, oldY, newX, newY); }
52 Q_INVOKABLE void replace(qreal oldX, qreal oldY, qreal newX, qreal newY) { DeclarativeXySeries::replace(oldX, oldY, newX, newY); }
53 Q_INVOKABLE void remove(qreal x, qreal y) { QSplineSeries::remove(x, y); }
53 Q_INVOKABLE void remove(qreal x, qreal y) { DeclarativeXySeries::remove(x, y); }
54 Q_INVOKABLE void clear() { QSplineSeries::clear(); }
54 Q_INVOKABLE void insert(int index, qreal x, qreal y) { DeclarativeXySeries::insert(index, x, y); }
55 Q_INVOKABLE void insert(int index, qreal x, qreal y) { QSplineSeries::insert(index, QPointF(x, y)); }
55 Q_INVOKABLE void clear() { DeclarativeXySeries::clear(); }
56 Q_INVOKABLE DeclarativeXyPoint *at(int index) { return DeclarativeXySeries::at(index); }
56 Q_INVOKABLE QPointF at(int index) { return DeclarativeXySeries::at(index); }
57
57
58 Q_SIGNALS:
58 Q_SIGNALS:
59 void countChanged(int count);
59 void countChanged(int count);
60
60
61 public Q_SLOTS:
61 public Q_SLOTS:
62 static void appendDeclarativeChildren(QDeclarativeListProperty<QObject> *list, QObject *element);
62 static void appendDeclarativeChildren(QDeclarativeListProperty<QObject> *list, QObject *element);
63 void handleCountChanged(int index);
63 void handleCountChanged(int index);
64 };
64 };
65
65
66 QTCOMMERCIALCHART_END_NAMESPACE
66 QTCOMMERCIALCHART_END_NAMESPACE
67
67
68 #endif // DECLARATIVESPLINESERIES_H
68 #endif // DECLARATIVESPLINESERIES_H
@@ -1,77 +1,106
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 "DeclarativeXySeries.h"
21 //#include "DeclarativeXySeries.h"
22 #include "declarativexyseries.h"
22 #include "declarativexyseries.h"
23 #include "declarativechart.h"
23 #include "declarativechart.h"
24 #include <QXYSeries>
24 #include <QXYSeries>
25 #include <QVXYModelMapper>
25 #include <QVXYModelMapper>
26 #include <QHXYModelMapper>
26 #include <QHXYModelMapper>
27 #include <QDeclarativeListProperty>
27 #include <QDeclarativeListProperty>
28
28
29 QTCOMMERCIALCHART_BEGIN_NAMESPACE
29 QTCOMMERCIALCHART_BEGIN_NAMESPACE
30
30
31 DeclarativeXySeries::DeclarativeXySeries()
31 DeclarativeXySeries::DeclarativeXySeries()
32 {
32 {
33 }
33 }
34
34
35 DeclarativeXySeries::~DeclarativeXySeries()
35 DeclarativeXySeries::~DeclarativeXySeries()
36 {
36 {
37 }
37 }
38
38
39 void DeclarativeXySeries::classBegin()
39 void DeclarativeXySeries::classBegin()
40 {
40 {
41 }
41 }
42
42
43 void DeclarativeXySeries::componentComplete()
43 void DeclarativeXySeries::componentComplete()
44 {
44 {
45 QXYSeries *series = qobject_cast<QXYSeries *>(xySeries());
45 QXYSeries *series = qobject_cast<QXYSeries *>(xySeries());
46 Q_ASSERT(series);
46 Q_ASSERT(series);
47
47
48 foreach(QObject *child, series->children()) {
48 foreach(QObject *child, series->children()) {
49 if (qobject_cast<DeclarativeXyPoint *>(child)) {
49 if (qobject_cast<DeclarativeXyPoint *>(child)) {
50 DeclarativeXyPoint *point = qobject_cast<DeclarativeXyPoint *>(child);
50 DeclarativeXyPoint *point = qobject_cast<DeclarativeXyPoint *>(child);
51 series->append(point->x(), point->y());
51 series->append(point->x(), point->y());
52 } else if(qobject_cast<QVXYModelMapper *>(child)) {
52 } else if(qobject_cast<QVXYModelMapper *>(child)) {
53 QVXYModelMapper *mapper = qobject_cast<QVXYModelMapper *>(child);
53 QVXYModelMapper *mapper = qobject_cast<QVXYModelMapper *>(child);
54 mapper->setSeries(series);
54 mapper->setSeries(series);
55 } else if(qobject_cast<QHXYModelMapper *>(child)) {
55 } else if(qobject_cast<QHXYModelMapper *>(child)) {
56 QHXYModelMapper *mapper = qobject_cast<QHXYModelMapper *>(child);
56 QHXYModelMapper *mapper = qobject_cast<QHXYModelMapper *>(child);
57 mapper->setSeries(series);
57 mapper->setSeries(series);
58 }
58 }
59 }
59 }
60 }
60 }
61
61
62 DeclarativeXyPoint *DeclarativeXySeries::at(int index)
62 void DeclarativeXySeries::append(qreal x, qreal y)
63 {
63 {
64 QXYSeries *series = qobject_cast<QXYSeries *>(xySeries());
64 QXYSeries *series = qobject_cast<QXYSeries *>(xySeries());
65 Q_ASSERT(series);
65 Q_ASSERT(series);
66 if (index < series->count()) {
66 series->append(x, y);
67 QPointF point = series->points().at(index);
68 DeclarativeXyPoint *xyPoint = new DeclarativeXyPoint(series);
69 xyPoint->setX(point.x());
70 xyPoint->setY(point.y());
71 return xyPoint;
72 }
73 return 0;
74 }
67 }
75
68
69 void DeclarativeXySeries::replace(qreal oldX, qreal oldY, qreal newX, qreal newY)
70 {
71 QXYSeries *series = qobject_cast<QXYSeries *>(xySeries());
72 Q_ASSERT(series);
73 series->replace(oldX, oldY, newX, newY);
74 }
75
76 void DeclarativeXySeries::remove(qreal x, qreal y)
77 {
78 QXYSeries *series = qobject_cast<QXYSeries *>(xySeries());
79 Q_ASSERT(series);
80 series->remove(x, y);
81 }
82
83 void DeclarativeXySeries::insert(int index, qreal x, qreal y)
84 {
85 QXYSeries *series = qobject_cast<QXYSeries *>(xySeries());
86 Q_ASSERT(series);
87 series->insert(index, QPointF(x, y));
88 }
89
90 void DeclarativeXySeries::clear()
91 {
92 QXYSeries *series = qobject_cast<QXYSeries *>(xySeries());
93 Q_ASSERT(series);
94 series->clear();
95 }
96
97 QPointF DeclarativeXySeries::at(int index)
98 {
99 QXYSeries *series = qobject_cast<QXYSeries *>(xySeries());
100 Q_ASSERT(series);
101 if (index >= 0 || index < series->count())
102 return series->points().at(index);
103 return QPointF(0, 0);
104 }
76
105
77 QTCOMMERCIALCHART_END_NAMESPACE
106 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,49 +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 #ifndef DECLARATIVE_XY_SERIES_H
21 #ifndef DECLARATIVE_XY_SERIES_H
22 #define DECLARATIVE_XY_SERIES_H
22 #define DECLARATIVE_XY_SERIES_H
23
23
24 #include "qchartglobal.h"
24 #include "qchartglobal.h"
25 #include "declarativexypoint.h"
25 #include "declarativexypoint.h"
26 #include <QColor>
26 #include <QColor>
27 #include <QXYSeries>
27 #include <QXYSeries>
28
28
29 QTCOMMERCIALCHART_BEGIN_NAMESPACE
29 QTCOMMERCIALCHART_BEGIN_NAMESPACE
30
30
31 class QChart;
31 class QChart;
32 class QAbstractSeries;
32 class QAbstractSeries;
33
33
34 class DeclarativeXySeries
34 class DeclarativeXySeries
35 {
35 {
36 public:
36 public:
37 explicit DeclarativeXySeries();
37 explicit DeclarativeXySeries();
38 ~DeclarativeXySeries();
38 ~DeclarativeXySeries();
39
39
40 public:
40 public:
41 void classBegin();
41 void classBegin();
42 void componentComplete();
42 void componentComplete();
43 virtual QXYSeries *xySeries() = 0;
43 virtual QXYSeries *xySeries() = 0;
44 DeclarativeXyPoint *at(int index);
44
45 void append(qreal x, qreal y);
46 void replace(qreal oldX, qreal oldY, qreal newX, qreal newY);
47 void remove(qreal x, qreal y);
48 void insert(int index, qreal x, qreal y);
49 void clear();
50 QPointF at(int index);
45 };
51 };
46
52
47 QTCOMMERCIALCHART_END_NAMESPACE
53 QTCOMMERCIALCHART_END_NAMESPACE
48
54
49 #endif // DECLARATIVE_XY_SERIES_H
55 #endif // DECLARATIVE_XY_SERIES_H
@@ -1,688 +1,722
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 "qbarseries.h"
21 #include "qbarseries.h"
22 #include "qbarseries_p.h"
22 #include "qbarseries_p.h"
23 #include "qbarset.h"
23 #include "qbarset.h"
24 #include "qbarset_p.h"
24 #include "qbarset_p.h"
25 #include "domain_p.h"
25 #include "domain_p.h"
26 #include "legendmarker_p.h"
26 #include "legendmarker_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 QBarSeries
34 \class QBarSeries
35 \brief Series for creating a bar chart
35 \brief Series for creating a bar chart
36 \mainclass
36 \mainclass
37
37
38 QBarSeries represents a series of data shown as bars. The purpose of this class is to draw bars to
38 QBarSeries represents a series of data shown as bars. The purpose of this class is to draw bars to
39 the position defined by data. Single bar is defined by QPointF, where x value is the x-coordinate of the bar
39 the position defined by data. Single bar is defined by QPointF, where x value is the x-coordinate of the bar
40 and y-value is the height of the bar. The category names are ignored with this series and x-axis
40 and y-value is the height of the bar. The category names are ignored with this series and x-axis
41 shows the x-values.
41 shows the x-values.
42
42
43 See the \l {BarChart Example} {bar chart example} to learn how to create a simple bar chart.
43 See the \l {BarChart Example} {bar chart example} to learn how to create a simple bar chart.
44 \image examples_barchart.png
44 \image examples_barchart.png
45
45
46 \sa QBarSet, QStackedBarSeries, QPercentBarSeries
46 \sa QBarSet, QStackedBarSeries, QPercentBarSeries
47 */
47 */
48 /*!
48 /*!
49 \qmlclass BarSeries QBarSeries
49 \qmlclass BarSeries QBarSeries
50 \inherits AbstractSeries
51
52 The following QML shows how to create a simple bar chart:
53 \snippet ../demos/qmlchart/qml/qmlchart/View6.qml 1
50
54
51 \beginfloatleft
55 \beginfloatleft
52 \image demos_qmlchart6.png
56 \image demos_qmlchart6.png
53 \endfloat
57 \endfloat
54 \clearfloat
58 \clearfloat
55
56 The following QML shows how to create a simple bar chart:
57 \snippet ../demos/qmlchart/qml/qmlchart/View6.qml 1
58 */
59 */
59
60
60 /*!
61 /*!
61 \property QBarSeries::barWidth
62 \property QBarSeries::barWidth
62 The width of the bars of the series. The unit of \a width is the unit of x-axis. The minimum width for bars
63 The width of the bars of the series. The unit of \a width is the unit of x-axis. The minimum width for bars
63 is zero and negative values are treated as zero. Setting the width to zero means that width of the bar on screen
64 is zero and negative values are treated as zero. Setting the width to zero means that width of the bar on screen
64 is one pixel no matter what the scale of x-axis is. Bars wider than zero are scaled with x-axis.
65 is one pixel no matter what the scale of x-axis is. Bars wider than zero are scaled with x-axis.
65 Note that with QGroupedBarSeries this value means the width of one group of bars instead of just one bar.
66 Note that with QGroupedBarSeries this value means the width of one group of bars instead of just one bar.
66 \sa QGroupedBarSeries
67 \sa QGroupedBarSeries
67 */
68 */
68 /*!
69 /*!
69 \qmlproperty real BarSeries::barWidth
70 \qmlproperty real BarSeries::barWidth
70 The width of the bars of the series. The unit of width is the unit of x-axis. The minimum width for bars
71 The width of the bars of the series. The unit of width is the unit of x-axis. The minimum width for bars
71 is zero and negative values are treated as zero. Setting the width to zero means that width of the bar on screen
72 is zero and negative values are treated as zero. Setting the width to zero means that width of the bar on screen
72 is one pixel no matter what the scale of x-axis is. Bars wider than zero are scaled with x-axis.
73 is one pixel no matter what the scale of x-axis is. Bars wider than zero are scaled with x-axis.
73 Note that with QGroupedBarSeries this value means the width of one group of bars instead of just one bar.
74 Note that with QGroupedBarSeries this value means the width of one group of bars instead of just one bar.
74 */
75 */
75
76
76 /*!
77 /*!
77 \property QBarSeries::count
78 \property QBarSeries::count
78 Holds the number of sets in series.
79 Holds the number of sets in series.
79 */
80 */
80 /*!
81 /*!
81 \qmlproperty int BarSeries::count
82 \qmlproperty int BarSeries::count
82 Holds the number of sets in series.
83 Holds the number of sets in series.
83 */
84 */
84
85
85 /*!
86 /*!
86 \property QBarSeries::labelsVisible
87 \property QBarSeries::labelsVisible
87 Defines the visibility of the labels in series
88 Defines the visibility of the labels in series
88 */
89 */
89 /*!
90 /*!
90 \qmlproperty bool BarSeries::labelsVisible
91 \qmlproperty bool BarSeries::labelsVisible
91 Defines the visibility of the labels in series
92 Defines the visibility of the labels in series
92 */
93 */
93
94
94 /*!
95 /*!
95 \fn void QBarSeries::clicked(QBarSet *barset, int index)
96 \fn void QBarSeries::clicked(QBarSet *barset, int index)
96
97
97 The signal is emitted if the user clicks with a mouse on top of QBarSet \a barset.
98 The signal is emitted if the user clicks with a mouse on top of QBarSet \a barset.
98 Clicked bar inside set is indexed by \a index
99 Clicked bar inside set is indexed by \a index
99 */
100 */
100 /*!
101 /*!
101 \qmlsignal BarSeries::onClicked(BarSet barset, int index)
102 \qmlsignal BarSeries::onClicked(BarSet barset, int index)
102
103
103 The signal is emitted if the user clicks with a mouse on top of BarSet.
104 The signal is emitted if the user clicks with a mouse on top of BarSet.
104 Clicked bar inside set is indexed by \a index
105 Clicked bar inside set is indexed by \a index
105 */
106 */
106
107
107 /*!
108 /*!
108 \fn void QBarSeries::hovered(QBarSet* barset, bool status)
109 \fn void QBarSeries::hovered(QBarSet* barset, bool status)
109
110
110 The signal is emitted if mouse is hovered on top of series.
111 The signal is emitted if mouse is hovered on top of series.
111 Parameter \a barset is the pointer of barset, where hover happened.
112 Parameter \a barset is the pointer of barset, where hover happened.
112 Parameter \a status is true, if mouse entered on top of series, false if mouse left from top of series.
113 Parameter \a status is true, if mouse entered on top of series, false if mouse left from top of series.
113 */
114 */
114 /*!
115 /*!
115 \qmlsignal BarSeries::onHovered(BarSet barset, bool status)
116 \qmlsignal BarSeries::onHovered(BarSet barset, bool status)
116
117
117 The signal is emitted if mouse is hovered on top of series.
118 The signal is emitted if mouse is hovered on top of series.
118 Parameter \a barset is the pointer of barset, where hover happened.
119 Parameter \a barset is the pointer of barset, where hover happened.
119 Parameter \a status is true, if mouse entered on top of series, false if mouse left from top of series.
120 Parameter \a status is true, if mouse entered on top of series, false if mouse left from top of series.
120 */
121 */
121
122
122 /*!
123 /*!
123 \fn void QBarSeries::countChanged()
124 \fn void QBarSeries::countChanged()
124 This signal is emitted when barset count has been changed, for example by append or remove.
125 This signal is emitted when barset count has been changed, for example by append or remove.
125 */
126 */
126 /*!
127 /*!
127 \qmlsignal BarSeries::countChanged()
128 \qmlsignal BarSeries::countChanged()
128 This signal is emitted when barset count has been changed, for example by append or remove.
129 This signal is emitted when barset count has been changed, for example by append or remove.
129 */
130 */
130
131
131 /*!
132 /*!
132 \fn void QBarSeries::labelsVisibleChanged()
133 \fn void QBarSeries::labelsVisibleChanged()
133 This signal is emitted when labels visibility have changed.
134 This signal is emitted when labels visibility have changed.
134 \sa isLabelsVisible(), setLabelsVisible()
135 \sa isLabelsVisible(), setLabelsVisible()
135 */
136 */
136
137
137 /*!
138 /*!
138 \fn void QBarSeries::barsetsAdded(QList<QBarSet*> sets)
139 \fn void QBarSeries::barsetsAdded(QList<QBarSet*> sets)
139 This signal is emitted when \a sets have been added to the series.
140 This signal is emitted when \a sets have been added to the series.
140 \sa append(), insert()
141 \sa append(), insert()
141 */
142 */
142 /*!
143 /*!
143 \qmlsignal BarSeries::added(BarSet barset)
144 \qmlsignal BarSeries::added(BarSet barset)
144 Emitted when \a barset has been added to the series.
145 Emitted when \a barset has been added to the series.
145 */
146 */
146
147
147 /*!
148 /*!
148 \fn void QBarSeries::barsetsRemoved(QList<QBarSet*> sets)
149 \fn void QBarSeries::barsetsRemoved(QList<QBarSet*> sets)
149 This signal is emitted when \a sets have been removed from the series.
150 This signal is emitted when \a sets have been removed from the series.
150 \sa remove()
151 \sa remove()
151 */
152 */
152 /*!
153 /*!
153 \qmlsignal BarSeries::removed(BarSet barset)
154 \qmlsignal BarSeries::removed(BarSet barset)
154 Emitted when \a barset has been removed from the series.
155 Emitted when \a barset has been removed from the series.
155 */
156 */
156
157
157 /*!
158 /*!
159 \qmlmethod BarSet BarSeries::at(int index)
160 Returns bar set at \a index. Returns null if the index is not valid.
161 */
162
163 /*!
164 \qmlmethod BarSet BarSeries::append(string label, VariantList values)
165 Adds a new bar set with \a label and \a values to \a index. Values can be a list of reals or a list of XyPoints.
166 For example:
167 \code
168 myBarSeries.append("set 1", [0, 0.2, 0.2, 0.5, 0.4, 1.5, 0.9]);
169 myBarSeries.append("set 2", [Qt.point(0, 1), Qt.point(2, 2.5), Qt.point(3.5, 2.2)]);
170 \endcode
171 */
172
173 /*!
174 \qmlmethod BarSet BarSeries::insert(int index, string label, VariantList values)
175 Inserts a new bar set with \a label and \a values to \a index. Values can be a list of reals or a list of XyPoints.
176 If index is zero or smaller, the new barset is prepended. If the index is count or bigger, the new barset is
177 appended.
178 \sa BarSeries::append()
179 */
180
181 /*!
182 \qmlmethod bool BarSeries::remove(BarSet barset)
183 Removes the barset from the series. Returns true if successfull, false otherwise.
184 */
185
186 /*!
187 \qmlmethod BarSeries::clear()
188 Removes all barsets from the series.
189 */
190
191 /*!
158 Constructs empty QBarSeries.
192 Constructs empty QBarSeries.
159 QBarSeries is QObject which is a child of a \a parent.
193 QBarSeries is QObject which is a child of a \a parent.
160 */
194 */
161 QBarSeries::QBarSeries(QObject *parent) :
195 QBarSeries::QBarSeries(QObject *parent) :
162 QAbstractSeries(*new QBarSeriesPrivate(this),parent)
196 QAbstractSeries(*new QBarSeriesPrivate(this),parent)
163 {
197 {
164 }
198 }
165
199
166 /*!
200 /*!
167 Destructs barseries and owned barsets.
201 Destructs barseries and owned barsets.
168 */
202 */
169 QBarSeries::~QBarSeries()
203 QBarSeries::~QBarSeries()
170 {
204 {
171 Q_D(QBarSeries);
205 Q_D(QBarSeries);
172 if(d->m_dataset){
206 if(d->m_dataset){
173 d->m_dataset->removeSeries(this);
207 d->m_dataset->removeSeries(this);
174 }
208 }
175 }
209 }
176
210
177 /*!
211 /*!
178 \internal
212 \internal
179 */
213 */
180 QBarSeries::QBarSeries(QBarSeriesPrivate &d, QObject *parent) :
214 QBarSeries::QBarSeries(QBarSeriesPrivate &d, QObject *parent) :
181 QAbstractSeries(d,parent)
215 QAbstractSeries(d,parent)
182 {
216 {
183 }
217 }
184
218
185 /*!
219 /*!
186 Returns the type of series. Derived classes override this.
220 Returns the type of series. Derived classes override this.
187 */
221 */
188 QAbstractSeries::SeriesType QBarSeries::type() const
222 QAbstractSeries::SeriesType QBarSeries::type() const
189 {
223 {
190 return QAbstractSeries::SeriesTypeBar;
224 return QAbstractSeries::SeriesTypeBar;
191 }
225 }
192
226
193 /*!
227 /*!
194 Sets the width of the bars of the series. The unit of \a width is the unit of x-axis. The minimum width for bars
228 Sets the width of the bars of the series. The unit of \a width is the unit of x-axis. The minimum width for bars
195 is zero and negative values are treated as zero. Setting the width to zero means that width of the bar on screen
229 is zero and negative values are treated as zero. Setting the width to zero means that width of the bar on screen
196 is one pixel no matter what the scale of x-axis is. Bars wider than zero are scaled with x-axis.
230 is one pixel no matter what the scale of x-axis is. Bars wider than zero are scaled with x-axis.
197 Note that with \link QGroupedBarSeries \endlink this value means the width of one group of bars instead of just one bar.
231 Note that with \link QGroupedBarSeries \endlink this value means the width of one group of bars instead of just one bar.
198 */
232 */
199 void QBarSeries::setBarWidth(qreal width)
233 void QBarSeries::setBarWidth(qreal width)
200 {
234 {
201 Q_D(QBarSeries);
235 Q_D(QBarSeries);
202 d->setBarWidth(width);
236 d->setBarWidth(width);
203 }
237 }
204
238
205 /*!
239 /*!
206 Returns the width of the bars of the series.
240 Returns the width of the bars of the series.
207 \sa setBarWidth()
241 \sa setBarWidth()
208 */
242 */
209 qreal QBarSeries::barWidth() const
243 qreal QBarSeries::barWidth() const
210 {
244 {
211 Q_D(const QBarSeries);
245 Q_D(const QBarSeries);
212 return d->barWidth();
246 return d->barWidth();
213 }
247 }
214
248
215 /*!
249 /*!
216 Adds a set of bars to series. Takes ownership of \a set. If the set is null or is already in series, it won't be appended.
250 Adds a set of bars to series. Takes ownership of \a set. If the set is null or is already in series, it won't be appended.
217 Returns true, if appending succeeded.
251 Returns true, if appending succeeded.
218 */
252 */
219 bool QBarSeries::append(QBarSet *set)
253 bool QBarSeries::append(QBarSet *set)
220 {
254 {
221 Q_D(QBarSeries);
255 Q_D(QBarSeries);
222 bool success = d->append(set);
256 bool success = d->append(set);
223 if (success) {
257 if (success) {
224 QList<QBarSet*> sets;
258 QList<QBarSet*> sets;
225 sets.append(set);
259 sets.append(set);
226 emit barsetsAdded(sets);
260 emit barsetsAdded(sets);
227 emit countChanged();
261 emit countChanged();
228 }
262 }
229 return success;
263 return success;
230 }
264 }
231
265
232 /*!
266 /*!
233 Removes a set of bars from series. Releases ownership of \a set. Doesn't delete \a set.
267 Removes a set of bars from series. Releases ownership of \a set. Doesn't delete \a set.
234 Returns true, if set was removed.
268 Returns true, if set was removed.
235 */
269 */
236 bool QBarSeries::remove(QBarSet *set)
270 bool QBarSeries::remove(QBarSet *set)
237 {
271 {
238 Q_D(QBarSeries);
272 Q_D(QBarSeries);
239 bool success = d->remove(set);
273 bool success = d->remove(set);
240 if (success) {
274 if (success) {
241 QList<QBarSet*> sets;
275 QList<QBarSet*> sets;
242 sets.append(set);
276 sets.append(set);
243 emit barsetsRemoved(sets);
277 emit barsetsRemoved(sets);
244 emit countChanged();
278 emit countChanged();
245 }
279 }
246 return success;
280 return success;
247 }
281 }
248
282
249 /*!
283 /*!
250 Adds a list of barsets to series. Takes ownership of \a sets.
284 Adds a list of barsets to series. Takes ownership of \a sets.
251 Returns true, if all sets were appended succesfully. If any of the sets is null or is already appended to series,
285 Returns true, if all sets were appended succesfully. If any of the sets is null or is already appended to series,
252 nothing is appended and function returns false. If any of the sets is in list more than once, nothing is appended
286 nothing is appended and function returns false. If any of the sets is in list more than once, nothing is appended
253 and function returns false.
287 and function returns false.
254 */
288 */
255 bool QBarSeries::append(QList<QBarSet* > sets)
289 bool QBarSeries::append(QList<QBarSet* > sets)
256 {
290 {
257 Q_D(QBarSeries);
291 Q_D(QBarSeries);
258 bool success = d->append(sets);
292 bool success = d->append(sets);
259 if (success) {
293 if (success) {
260 emit barsetsAdded(sets);
294 emit barsetsAdded(sets);
261 emit countChanged();
295 emit countChanged();
262 }
296 }
263 return success;
297 return success;
264 }
298 }
265
299
266 /*!
300 /*!
267 Insert a set of bars to series at \a index postion. Takes ownership of \a set. If the set is null or is already in series, it won't be appended.
301 Insert a set of bars to series at \a index postion. Takes ownership of \a set. If the set is null or is already in series, it won't be appended.
268 Returns true, if inserting succeeded.
302 Returns true, if inserting succeeded.
269
303
270 */
304 */
271 bool QBarSeries::insert(int index, QBarSet *set)
305 bool QBarSeries::insert(int index, QBarSet *set)
272 {
306 {
273 Q_D(QBarSeries);
307 Q_D(QBarSeries);
274 bool success = d->insert(index, set);
308 bool success = d->insert(index, set);
275 if (success) {
309 if (success) {
276 QList<QBarSet*> sets;
310 QList<QBarSet*> sets;
277 sets.append(set);
311 sets.append(set);
278 emit barsetsAdded(sets);
312 emit barsetsAdded(sets);
279 emit countChanged();
313 emit countChanged();
280 }
314 }
281 return success;
315 return success;
282 }
316 }
283
317
284 /*!
318 /*!
285 Removes all of the bar sets from the series
319 Removes all of the bar sets from the series
286 */
320 */
287 void QBarSeries::clear()
321 void QBarSeries::clear()
288 {
322 {
289 Q_D(QBarSeries);
323 Q_D(QBarSeries);
290 QList<QBarSet *> sets = barSets();
324 QList<QBarSet *> sets = barSets();
291 bool success = d->remove(sets);
325 bool success = d->remove(sets);
292 if (success) {
326 if (success) {
293 emit barsetsRemoved(sets);
327 emit barsetsRemoved(sets);
294 emit countChanged();
328 emit countChanged();
295 }
329 }
296 }
330 }
297
331
298 /*!
332 /*!
299 Returns number of sets in series.
333 Returns number of sets in series.
300 */
334 */
301 int QBarSeries::count() const
335 int QBarSeries::count() const
302 {
336 {
303 Q_D(const QBarSeries);
337 Q_D(const QBarSeries);
304 return d->m_barSets.count();
338 return d->m_barSets.count();
305 }
339 }
306
340
307 /*!
341 /*!
308 Returns a list of sets in series. Keeps ownership of sets.
342 Returns a list of sets in series. Keeps ownership of sets.
309 */
343 */
310 QList<QBarSet*> QBarSeries::barSets() const
344 QList<QBarSet*> QBarSeries::barSets() const
311 {
345 {
312 Q_D(const QBarSeries);
346 Q_D(const QBarSeries);
313 return d->m_barSets;
347 return d->m_barSets;
314 }
348 }
315
349
316 /*!
350 /*!
317 Sets the visibility of labels in series to \a visible
351 Sets the visibility of labels in series to \a visible
318 */
352 */
319 void QBarSeries::setLabelsVisible(bool visible)
353 void QBarSeries::setLabelsVisible(bool visible)
320 {
354 {
321 Q_D(QBarSeries);
355 Q_D(QBarSeries);
322 if (d->m_labelsVisible != visible) {
356 if (d->m_labelsVisible != visible) {
323 d->setLabelsVisible(visible);
357 d->setLabelsVisible(visible);
324 emit labelsVisibleChanged();
358 emit labelsVisibleChanged();
325 }
359 }
326 }
360 }
327
361
328 /*!
362 /*!
329 Returns the visibility of labels
363 Returns the visibility of labels
330 */
364 */
331 bool QBarSeries::isLabelsVisible() const
365 bool QBarSeries::isLabelsVisible() const
332 {
366 {
333 Q_D(const QBarSeries);
367 Q_D(const QBarSeries);
334 return d->m_labelsVisible;
368 return d->m_labelsVisible;
335 }
369 }
336
370
337 ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
371 ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
338
372
339 QBarSeriesPrivate::QBarSeriesPrivate(QBarSeries *q) :
373 QBarSeriesPrivate::QBarSeriesPrivate(QBarSeries *q) :
340 QAbstractSeriesPrivate(q),
374 QAbstractSeriesPrivate(q),
341 m_barWidth(0.5), // Default value is 50% of category width
375 m_barWidth(0.5), // Default value is 50% of category width
342 m_labelsVisible(false),
376 m_labelsVisible(false),
343 m_visible(true)
377 m_visible(true)
344 {
378 {
345 }
379 }
346
380
347 int QBarSeriesPrivate::categoryCount() const
381 int QBarSeriesPrivate::categoryCount() const
348 {
382 {
349 // No categories defined. return count of longest set.
383 // No categories defined. return count of longest set.
350 int count = 0;
384 int count = 0;
351 for (int i=0; i<m_barSets.count(); i++) {
385 for (int i=0; i<m_barSets.count(); i++) {
352 if (m_barSets.at(i)->count() > count) {
386 if (m_barSets.at(i)->count() > count) {
353 count = m_barSets.at(i)->count();
387 count = m_barSets.at(i)->count();
354 }
388 }
355 }
389 }
356
390
357 return count;
391 return count;
358 }
392 }
359
393
360 void QBarSeriesPrivate::setBarWidth(qreal width)
394 void QBarSeriesPrivate::setBarWidth(qreal width)
361 {
395 {
362 if (width < 0.0) {
396 if (width < 0.0) {
363 width = 0.0;
397 width = 0.0;
364 }
398 }
365 m_barWidth = width;
399 m_barWidth = width;
366 emit updatedBars();
400 emit updatedBars();
367 }
401 }
368
402
369 qreal QBarSeriesPrivate::barWidth() const
403 qreal QBarSeriesPrivate::barWidth() const
370 {
404 {
371 return m_barWidth;
405 return m_barWidth;
372 }
406 }
373
407
374 QBarSet* QBarSeriesPrivate::barsetAt(int index)
408 QBarSet* QBarSeriesPrivate::barsetAt(int index)
375 {
409 {
376 return m_barSets.at(index);
410 return m_barSets.at(index);
377 }
411 }
378
412
379 void QBarSeriesPrivate::setVisible(bool visible)
413 void QBarSeriesPrivate::setVisible(bool visible)
380 {
414 {
381 m_visible = visible;
415 m_visible = visible;
382 emit updatedBars();
416 emit updatedBars();
383 }
417 }
384
418
385 void QBarSeriesPrivate::setLabelsVisible(bool visible)
419 void QBarSeriesPrivate::setLabelsVisible(bool visible)
386 {
420 {
387 m_labelsVisible = visible;
421 m_labelsVisible = visible;
388 emit labelsVisibleChanged(visible);
422 emit labelsVisibleChanged(visible);
389 }
423 }
390
424
391 qreal QBarSeriesPrivate::min()
425 qreal QBarSeriesPrivate::min()
392 {
426 {
393 if (m_barSets.count() <= 0) {
427 if (m_barSets.count() <= 0) {
394 return 0;
428 return 0;
395 }
429 }
396 qreal min = INT_MAX;
430 qreal min = INT_MAX;
397
431
398 for (int i = 0; i < m_barSets.count(); i++) {
432 for (int i = 0; i < m_barSets.count(); i++) {
399 int categoryCount = m_barSets.at(i)->count();
433 int categoryCount = m_barSets.at(i)->count();
400 for (int j = 0; j < categoryCount; j++) {
434 for (int j = 0; j < categoryCount; j++) {
401 qreal temp = m_barSets.at(i)->at(j).y();
435 qreal temp = m_barSets.at(i)->at(j).y();
402 if (temp < min)
436 if (temp < min)
403 min = temp;
437 min = temp;
404 }
438 }
405 }
439 }
406 return min;
440 return min;
407 }
441 }
408
442
409 qreal QBarSeriesPrivate::max()
443 qreal QBarSeriesPrivate::max()
410 {
444 {
411 if (m_barSets.count() <= 0) {
445 if (m_barSets.count() <= 0) {
412 return 0;
446 return 0;
413 }
447 }
414 qreal max = INT_MIN;
448 qreal max = INT_MIN;
415
449
416 for (int i = 0; i < m_barSets.count(); i++) {
450 for (int i = 0; i < m_barSets.count(); i++) {
417 int categoryCount = m_barSets.at(i)->count();
451 int categoryCount = m_barSets.at(i)->count();
418 for (int j = 0; j < categoryCount; j++) {
452 for (int j = 0; j < categoryCount; j++) {
419 qreal temp = m_barSets.at(i)->at(j).y();
453 qreal temp = m_barSets.at(i)->at(j).y();
420 if (temp > max)
454 if (temp > max)
421 max = temp;
455 max = temp;
422 }
456 }
423 }
457 }
424
458
425 return max;
459 return max;
426 }
460 }
427
461
428 qreal QBarSeriesPrivate::valueAt(int set, int category)
462 qreal QBarSeriesPrivate::valueAt(int set, int category)
429 {
463 {
430 if ((set < 0) || (set >= m_barSets.count())) {
464 if ((set < 0) || (set >= m_barSets.count())) {
431 // No set, no value.
465 // No set, no value.
432 return 0;
466 return 0;
433 } else if ((category < 0) || (category >= m_barSets.at(set)->count())) {
467 } else if ((category < 0) || (category >= m_barSets.at(set)->count())) {
434 // No category, no value.
468 // No category, no value.
435 return 0;
469 return 0;
436 }
470 }
437
471
438 return m_barSets.at(set)->at(category).y();
472 return m_barSets.at(set)->at(category).y();
439 }
473 }
440
474
441 qreal QBarSeriesPrivate::percentageAt(int set, int category)
475 qreal QBarSeriesPrivate::percentageAt(int set, int category)
442 {
476 {
443 if ((set < 0) || (set >= m_barSets.count())) {
477 if ((set < 0) || (set >= m_barSets.count())) {
444 // No set, no value.
478 // No set, no value.
445 return 0;
479 return 0;
446 } else if ((category < 0) || (category >= m_barSets.at(set)->count())) {
480 } else if ((category < 0) || (category >= m_barSets.at(set)->count())) {
447 // No category, no value.
481 // No category, no value.
448 return 0;
482 return 0;
449 }
483 }
450
484
451 qreal value = m_barSets.at(set)->at(category).y();
485 qreal value = m_barSets.at(set)->at(category).y();
452 qreal sum = categorySum(category);
486 qreal sum = categorySum(category);
453 if ( qFuzzyIsNull(sum) ) {
487 if ( qFuzzyIsNull(sum) ) {
454 return 0;
488 return 0;
455 }
489 }
456
490
457 return value / sum;
491 return value / sum;
458 }
492 }
459
493
460 qreal QBarSeriesPrivate::categorySum(int category)
494 qreal QBarSeriesPrivate::categorySum(int category)
461 {
495 {
462 qreal sum(0);
496 qreal sum(0);
463 int count = m_barSets.count(); // Count sets
497 int count = m_barSets.count(); // Count sets
464 for (int set = 0; set < count; set++) {
498 for (int set = 0; set < count; set++) {
465 if (category < m_barSets.at(set)->count())
499 if (category < m_barSets.at(set)->count())
466 sum += m_barSets.at(set)->at(category).y();
500 sum += m_barSets.at(set)->at(category).y();
467 }
501 }
468 return sum;
502 return sum;
469 }
503 }
470
504
471 qreal QBarSeriesPrivate::absoluteCategorySum(int category)
505 qreal QBarSeriesPrivate::absoluteCategorySum(int category)
472 {
506 {
473 qreal sum(0);
507 qreal sum(0);
474 int count = m_barSets.count(); // Count sets
508 int count = m_barSets.count(); // Count sets
475 for (int set = 0; set < count; set++) {
509 for (int set = 0; set < count; set++) {
476 if (category < m_barSets.at(set)->count())
510 if (category < m_barSets.at(set)->count())
477 sum += qAbs(m_barSets.at(set)->at(category).y());
511 sum += qAbs(m_barSets.at(set)->at(category).y());
478 }
512 }
479 return sum;
513 return sum;
480 }
514 }
481
515
482 qreal QBarSeriesPrivate::maxCategorySum()
516 qreal QBarSeriesPrivate::maxCategorySum()
483 {
517 {
484 qreal max = INT_MIN;
518 qreal max = INT_MIN;
485 int count = categoryCount();
519 int count = categoryCount();
486 for (int i = 0; i < count; i++) {
520 for (int i = 0; i < count; i++) {
487 qreal sum = categorySum(i);
521 qreal sum = categorySum(i);
488 if (sum > max)
522 if (sum > max)
489 max = sum;
523 max = sum;
490 }
524 }
491 return max;
525 return max;
492 }
526 }
493
527
494 qreal QBarSeriesPrivate::minX()
528 qreal QBarSeriesPrivate::minX()
495 {
529 {
496 if (m_barSets.count() <= 0) {
530 if (m_barSets.count() <= 0) {
497 return 0;
531 return 0;
498 }
532 }
499 qreal min = INT_MAX;
533 qreal min = INT_MAX;
500
534
501 for (int i = 0; i < m_barSets.count(); i++) {
535 for (int i = 0; i < m_barSets.count(); i++) {
502 int categoryCount = m_barSets.at(i)->count();
536 int categoryCount = m_barSets.at(i)->count();
503 for (int j = 0; j < categoryCount; j++) {
537 for (int j = 0; j < categoryCount; j++) {
504 qreal temp = m_barSets.at(i)->at(j).x();
538 qreal temp = m_barSets.at(i)->at(j).x();
505 if (temp < min)
539 if (temp < min)
506 min = temp;
540 min = temp;
507 }
541 }
508 }
542 }
509 return min;
543 return min;
510 }
544 }
511
545
512 qreal QBarSeriesPrivate::maxX()
546 qreal QBarSeriesPrivate::maxX()
513 {
547 {
514 if (m_barSets.count() <= 0) {
548 if (m_barSets.count() <= 0) {
515 return 0;
549 return 0;
516 }
550 }
517 qreal max = INT_MIN;
551 qreal max = INT_MIN;
518
552
519 for (int i = 0; i < m_barSets.count(); i++) {
553 for (int i = 0; i < m_barSets.count(); i++) {
520 int categoryCount = m_barSets.at(i)->count();
554 int categoryCount = m_barSets.at(i)->count();
521 for (int j = 0; j < categoryCount; j++) {
555 for (int j = 0; j < categoryCount; j++) {
522 qreal temp = m_barSets.at(i)->at(j).x();
556 qreal temp = m_barSets.at(i)->at(j).x();
523 if (temp > max)
557 if (temp > max)
524 max = temp;
558 max = temp;
525 }
559 }
526 }
560 }
527
561
528 return max;
562 return max;
529 }
563 }
530
564
531
565
532 void QBarSeriesPrivate::scaleDomain(Domain& domain)
566 void QBarSeriesPrivate::scaleDomain(Domain& domain)
533 {
567 {
534 qreal minX(domain.minX());
568 qreal minX(domain.minX());
535 qreal minY(domain.minY());
569 qreal minY(domain.minY());
536 qreal maxX(domain.maxX());
570 qreal maxX(domain.maxX());
537 qreal maxY(domain.maxY());
571 qreal maxY(domain.maxY());
538 int tickXCount(domain.tickXCount());
572 int tickXCount(domain.tickXCount());
539 int tickYCount(domain.tickYCount());
573 int tickYCount(domain.tickYCount());
540
574
541 qreal seriesMinX = this->minX();
575 qreal seriesMinX = this->minX();
542 qreal seriesMaxX = this->maxX();
576 qreal seriesMaxX = this->maxX();
543 qreal y = max();
577 qreal y = max();
544 minX = qMin(minX, seriesMinX - 0.5);
578 minX = qMin(minX, seriesMinX - 0.5);
545 minY = qMin(minY, y);
579 minY = qMin(minY, y);
546 maxX = qMax(maxX, seriesMaxX + 0.5);
580 maxX = qMax(maxX, seriesMaxX + 0.5);
547 maxY = qMax(maxY, y);
581 maxY = qMax(maxY, y);
548 tickXCount = categoryCount()+1;
582 tickXCount = categoryCount()+1;
549
583
550 domain.setRange(minX,maxX,minY,maxY,tickXCount,tickYCount);
584 domain.setRange(minX,maxX,minY,maxY,tickXCount,tickYCount);
551 }
585 }
552
586
553 Chart* QBarSeriesPrivate::createGraphics(ChartPresenter* presenter)
587 Chart* QBarSeriesPrivate::createGraphics(ChartPresenter* presenter)
554 {
588 {
555 Q_Q(QBarSeries);
589 Q_Q(QBarSeries);
556
590
557 BarChartItem* bar = new BarChartItem(q,presenter);
591 BarChartItem* bar = new BarChartItem(q,presenter);
558 if(presenter->animationOptions().testFlag(QChart::SeriesAnimations)) {
592 if(presenter->animationOptions().testFlag(QChart::SeriesAnimations)) {
559 presenter->animator()->addAnimation(bar);
593 presenter->animator()->addAnimation(bar);
560 }
594 }
561 presenter->chartTheme()->decorate(q, presenter->dataSet()->seriesIndex(q));
595 presenter->chartTheme()->decorate(q, presenter->dataSet()->seriesIndex(q));
562 return bar;
596 return bar;
563
597
564 }
598 }
565
599
566 QList<LegendMarker*> QBarSeriesPrivate::createLegendMarker(QLegend* legend)
600 QList<LegendMarker*> QBarSeriesPrivate::createLegendMarker(QLegend* legend)
567 {
601 {
568 Q_Q(QBarSeries);
602 Q_Q(QBarSeries);
569 QList<LegendMarker*> markers;
603 QList<LegendMarker*> markers;
570 foreach(QBarSet* set, q->barSets()) {
604 foreach(QBarSet* set, q->barSets()) {
571 BarLegendMarker* marker = new BarLegendMarker(q,set,legend);
605 BarLegendMarker* marker = new BarLegendMarker(q,set,legend);
572 markers << marker;
606 markers << marker;
573 }
607 }
574
608
575 return markers;
609 return markers;
576 }
610 }
577
611
578 bool QBarSeriesPrivate::append(QBarSet *set)
612 bool QBarSeriesPrivate::append(QBarSet *set)
579 {
613 {
580 Q_Q(QBarSeries);
614 Q_Q(QBarSeries);
581 if ((m_barSets.contains(set)) || (set == 0)) {
615 if ((m_barSets.contains(set)) || (set == 0)) {
582 // Fail if set is already in list or set is null.
616 // Fail if set is already in list or set is null.
583 return false;
617 return false;
584 }
618 }
585 m_barSets.append(set);
619 m_barSets.append(set);
586 QObject::connect(set->d_ptr.data(), SIGNAL(updatedBars()), this, SIGNAL(updatedBars()));
620 QObject::connect(set->d_ptr.data(), SIGNAL(updatedBars()), this, SIGNAL(updatedBars()));
587 QObject::connect(set->d_ptr.data(), SIGNAL(restructuredBars()), this, SIGNAL(restructuredBars()));
621 QObject::connect(set->d_ptr.data(), SIGNAL(restructuredBars()), this, SIGNAL(restructuredBars()));
588 emit restructuredBars(); // this notifies barchartitem
622 emit restructuredBars(); // this notifies barchartitem
589 if (m_dataset) {
623 if (m_dataset) {
590 m_dataset->updateSeries(q); // this notifies legend
624 m_dataset->updateSeries(q); // this notifies legend
591 }
625 }
592 return true;
626 return true;
593 }
627 }
594
628
595 bool QBarSeriesPrivate::remove(QBarSet *set)
629 bool QBarSeriesPrivate::remove(QBarSet *set)
596 {
630 {
597 Q_Q(QBarSeries);
631 Q_Q(QBarSeries);
598 if (!m_barSets.contains(set)) {
632 if (!m_barSets.contains(set)) {
599 // Fail if set is not in list
633 // Fail if set is not in list
600 return false;
634 return false;
601 }
635 }
602 m_barSets.removeOne(set);
636 m_barSets.removeOne(set);
603 QObject::disconnect(set->d_ptr.data(), SIGNAL(updatedBars()), this, SIGNAL(updatedBars()));
637 QObject::disconnect(set->d_ptr.data(), SIGNAL(updatedBars()), this, SIGNAL(updatedBars()));
604 QObject::disconnect(set->d_ptr.data(), SIGNAL(restructuredBars()), this, SIGNAL(restructuredBars()));
638 QObject::disconnect(set->d_ptr.data(), SIGNAL(restructuredBars()), this, SIGNAL(restructuredBars()));
605 emit restructuredBars(); // this notifies barchartitem
639 emit restructuredBars(); // this notifies barchartitem
606 if (m_dataset) {
640 if (m_dataset) {
607 m_dataset->updateSeries(q); // this notifies legend
641 m_dataset->updateSeries(q); // this notifies legend
608 }
642 }
609 return true;
643 return true;
610 }
644 }
611
645
612 bool QBarSeriesPrivate::append(QList<QBarSet* > sets)
646 bool QBarSeriesPrivate::append(QList<QBarSet* > sets)
613 {
647 {
614 Q_Q(QBarSeries);
648 Q_Q(QBarSeries);
615 foreach (QBarSet* set, sets) {
649 foreach (QBarSet* set, sets) {
616 if ((set == 0) || (m_barSets.contains(set))) {
650 if ((set == 0) || (m_barSets.contains(set))) {
617 // Fail if any of the sets is null or is already appended.
651 // Fail if any of the sets is null or is already appended.
618 return false;
652 return false;
619 }
653 }
620 if (sets.count(set) != 1) {
654 if (sets.count(set) != 1) {
621 // Also fail if same set is more than once in given list.
655 // Also fail if same set is more than once in given list.
622 return false;
656 return false;
623 }
657 }
624 }
658 }
625
659
626 foreach (QBarSet* set, sets) {
660 foreach (QBarSet* set, sets) {
627 m_barSets.append(set);
661 m_barSets.append(set);
628 QObject::connect(set->d_ptr.data(), SIGNAL(updatedBars()), this, SIGNAL(updatedBars()));
662 QObject::connect(set->d_ptr.data(), SIGNAL(updatedBars()), this, SIGNAL(updatedBars()));
629 QObject::connect(set->d_ptr.data(), SIGNAL(restructuredBars()), this, SIGNAL(restructuredBars()));
663 QObject::connect(set->d_ptr.data(), SIGNAL(restructuredBars()), this, SIGNAL(restructuredBars()));
630 }
664 }
631 emit restructuredBars(); // this notifies barchartitem
665 emit restructuredBars(); // this notifies barchartitem
632 if (m_dataset) {
666 if (m_dataset) {
633 m_dataset->updateSeries(q); // this notifies legend
667 m_dataset->updateSeries(q); // this notifies legend
634 }
668 }
635 return true;
669 return true;
636 }
670 }
637
671
638 bool QBarSeriesPrivate::remove(QList<QBarSet* > sets)
672 bool QBarSeriesPrivate::remove(QList<QBarSet* > sets)
639 {
673 {
640 Q_Q(QBarSeries);
674 Q_Q(QBarSeries);
641 if (sets.count() == 0) {
675 if (sets.count() == 0) {
642 return false;
676 return false;
643 }
677 }
644 foreach (QBarSet* set, sets) {
678 foreach (QBarSet* set, sets) {
645 if ((set == 0) || (!m_barSets.contains(set))) {
679 if ((set == 0) || (!m_barSets.contains(set))) {
646 // Fail if any of the sets is null or is not in series
680 // Fail if any of the sets is null or is not in series
647 return false;
681 return false;
648 }
682 }
649 if (sets.count(set) != 1) {
683 if (sets.count(set) != 1) {
650 // Also fail if same set is more than once in given list.
684 // Also fail if same set is more than once in given list.
651 return false;
685 return false;
652 }
686 }
653 }
687 }
654
688
655 foreach (QBarSet* set, sets) {
689 foreach (QBarSet* set, sets) {
656 m_barSets.removeOne(set);
690 m_barSets.removeOne(set);
657 QObject::disconnect(set->d_ptr.data(), SIGNAL(updatedBars()), this, SIGNAL(updatedBars()));
691 QObject::disconnect(set->d_ptr.data(), SIGNAL(updatedBars()), this, SIGNAL(updatedBars()));
658 QObject::disconnect(set->d_ptr.data(), SIGNAL(restructuredBars()), this, SIGNAL(restructuredBars()));
692 QObject::disconnect(set->d_ptr.data(), SIGNAL(restructuredBars()), this, SIGNAL(restructuredBars()));
659 }
693 }
660
694
661 emit restructuredBars(); // this notifies barchartitem
695 emit restructuredBars(); // this notifies barchartitem
662 if (m_dataset) {
696 if (m_dataset) {
663 m_dataset->updateSeries(q); // this notifies legend
697 m_dataset->updateSeries(q); // this notifies legend
664 }
698 }
665 return true;
699 return true;
666 }
700 }
667
701
668 bool QBarSeriesPrivate::insert(int index, QBarSet *set)
702 bool QBarSeriesPrivate::insert(int index, QBarSet *set)
669 {
703 {
670 Q_Q(QBarSeries);
704 Q_Q(QBarSeries);
671 if ((m_barSets.contains(set)) || (set == 0)) {
705 if ((m_barSets.contains(set)) || (set == 0)) {
672 // Fail if set is already in list or set is null.
706 // Fail if set is already in list or set is null.
673 return false;
707 return false;
674 }
708 }
675 m_barSets.insert(index, set);
709 m_barSets.insert(index, set);
676 QObject::connect(set->d_ptr.data(), SIGNAL(updatedBars()), this, SIGNAL(updatedBars()));
710 QObject::connect(set->d_ptr.data(), SIGNAL(updatedBars()), this, SIGNAL(updatedBars()));
677 QObject::connect(set->d_ptr.data(), SIGNAL(restructuredBars()), this, SIGNAL(restructuredBars()));
711 QObject::connect(set->d_ptr.data(), SIGNAL(restructuredBars()), this, SIGNAL(restructuredBars()));
678 emit restructuredBars(); // this notifies barchartitem
712 emit restructuredBars(); // this notifies barchartitem
679 if (m_dataset) {
713 if (m_dataset) {
680 m_dataset->updateSeries(q); // this notifies legend
714 m_dataset->updateSeries(q); // this notifies legend
681 }
715 }
682 return true;
716 return true;
683 }
717 }
684
718
685 #include "moc_qbarseries.cpp"
719 #include "moc_qbarseries.cpp"
686 #include "moc_qbarseries_p.cpp"
720 #include "moc_qbarseries_p.cpp"
687
721
688 QTCOMMERCIALCHART_END_NAMESPACE
722 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,725 +1,751
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 /*!
51 /*!
52 \qmlclass PieSeries QPieSeries
52 \qmlclass PieSeries QPieSeries
53 \inherits AbstractSeries
53
54
54 The following QML shows how to create a simple pie chart.
55 The following QML shows how to create a simple pie chart.
55
56
56 \snippet ../demos/qmlchart/qml/qmlchart/View1.qml 1
57 \snippet ../demos/qmlchart/qml/qmlchart/View1.qml 1
57
58
58 \beginfloatleft
59 \beginfloatleft
59 \image demos_qmlchart1.png
60 \image demos_qmlchart1.png
60 \endfloat
61 \endfloat
61 \clearfloat
62 \clearfloat
62 */
63 */
63
64
64 /*!
65 /*!
65 \property QPieSeries::horizontalPosition
66 \property QPieSeries::horizontalPosition
66 \brief Defines the horizontal position of the pie.
67 \brief Defines the horizontal position of the pie.
67
68
68 The value is a relative value to the chart rectangle where:
69 The value is a relative value to the chart rectangle where:
69
70
70 \list
71 \list
71 \o 0.0 is the absolute left.
72 \o 0.0 is the absolute left.
72 \o 1.0 is the absolute right.
73 \o 1.0 is the absolute right.
73 \endlist
74 \endlist
74 Default value is 0.5 (center).
75 Default value is 0.5 (center).
75 \sa verticalPosition
76 \sa verticalPosition
76 */
77 */
77
78
78 /*!
79 /*!
79 \qmlproperty real PieSeries::horizontalPosition
80 \qmlproperty real PieSeries::horizontalPosition
80
81
81 Defines the horizontal position of the pie.
82 Defines the horizontal position of the pie.
82
83
83 The value is a relative value to the chart rectangle where:
84 The value is a relative value to the chart rectangle where:
84
85
85 \list
86 \list
86 \o 0.0 is the absolute left.
87 \o 0.0 is the absolute left.
87 \o 1.0 is the absolute right.
88 \o 1.0 is the absolute right.
88 \endlist
89 \endlist
89 Default value is 0.5 (center).
90 Default value is 0.5 (center).
90 \sa verticalPosition
91 \sa verticalPosition
91 */
92 */
92
93
93 /*!
94 /*!
94 \property QPieSeries::verticalPosition
95 \property QPieSeries::verticalPosition
95 \brief Defines the vertical position of the pie.
96 \brief Defines the vertical position of the pie.
96
97
97 The value is a relative value to the chart rectangle where:
98 The value is a relative value to the chart rectangle where:
98
99
99 \list
100 \list
100 \o 0.0 is the absolute top.
101 \o 0.0 is the absolute top.
101 \o 1.0 is the absolute bottom.
102 \o 1.0 is the absolute bottom.
102 \endlist
103 \endlist
103 Default value is 0.5 (center).
104 Default value is 0.5 (center).
104 \sa horizontalPosition
105 \sa horizontalPosition
105 */
106 */
106
107
107 /*!
108 /*!
108 \qmlproperty real PieSeries::verticalPosition
109 \qmlproperty real PieSeries::verticalPosition
109
110
110 Defines the vertical position of the pie.
111 Defines the vertical position of the pie.
111
112
112 The value is a relative value to the chart rectangle where:
113 The value is a relative value to the chart rectangle where:
113
114
114 \list
115 \list
115 \o 0.0 is the absolute top.
116 \o 0.0 is the absolute top.
116 \o 1.0 is the absolute bottom.
117 \o 1.0 is the absolute bottom.
117 \endlist
118 \endlist
118 Default value is 0.5 (center).
119 Default value is 0.5 (center).
119 \sa horizontalPosition
120 \sa horizontalPosition
120 */
121 */
121
122
122 /*!
123 /*!
123 \property QPieSeries::size
124 \property QPieSeries::size
124 \brief Defines the pie size.
125 \brief Defines the pie size.
125
126
126 The value is a relative value to the chart rectangle where:
127 The value is a relative value to the chart rectangle where:
127
128
128 \list
129 \list
129 \o 0.0 is the minimum size (pie not drawn).
130 \o 0.0 is the minimum size (pie not drawn).
130 \o 1.0 is the maximum size that can fit the chart.
131 \o 1.0 is the maximum size that can fit the chart.
131 \endlist
132 \endlist
132
133
133 Default value is 0.7.
134 Default value is 0.7.
134 */
135 */
135
136
136 /*!
137 /*!
137 \qmlproperty real PieSeries::size
138 \qmlproperty real PieSeries::size
138
139
139 Defines the pie size.
140 Defines the pie size.
140
141
141 The value is a relative value to the chart rectangle where:
142 The value is a relative value to the chart rectangle where:
142
143
143 \list
144 \list
144 \o 0.0 is the minimum size (pie not drawn).
145 \o 0.0 is the minimum size (pie not drawn).
145 \o 1.0 is the maximum size that can fit the chart.
146 \o 1.0 is the maximum size that can fit the chart.
146 \endlist
147 \endlist
147
148
148 Default value is 0.7.
149 Default value is 0.7.
149 */
150 */
150
151
151 /*!
152 /*!
152 \property QPieSeries::startAngle
153 \property QPieSeries::startAngle
153 \brief Defines the starting angle of the pie.
154 \brief Defines the starting angle of the pie.
154
155
155 Full pie is 360 degrees where 0 degrees is at 12 a'clock.
156 Full pie is 360 degrees where 0 degrees is at 12 a'clock.
156
157
157 Default is value is 0.
158 Default is value is 0.
158 */
159 */
159
160
160 /*!
161 /*!
161 \qmlproperty real PieSeries::startAngle
162 \qmlproperty real PieSeries::startAngle
162
163
163 Defines the starting angle of the pie.
164 Defines the starting angle of the pie.
164
165
165 Full pie is 360 degrees where 0 degrees is at 12 a'clock.
166 Full pie is 360 degrees where 0 degrees is at 12 a'clock.
166
167
167 Default is value is 0.
168 Default is value is 0.
168 */
169 */
169
170
170 /*!
171 /*!
171 \property QPieSeries::endAngle
172 \property QPieSeries::endAngle
172 \brief Defines the ending angle of the pie.
173 \brief Defines the ending angle of the pie.
173
174
174 Full pie is 360 degrees where 0 degrees is at 12 a'clock.
175 Full pie is 360 degrees where 0 degrees is at 12 a'clock.
175
176
176 Default is value is 360.
177 Default is value is 360.
177 */
178 */
178
179
179 /*!
180 /*!
180 \qmlproperty real PieSeries::endAngle
181 \qmlproperty real PieSeries::endAngle
181
182
182 Defines the ending angle of the pie.
183 Defines the ending angle of the pie.
183
184
184 Full pie is 360 degrees where 0 degrees is at 12 a'clock.
185 Full pie is 360 degrees where 0 degrees is at 12 a'clock.
185
186
186 Default is value is 360.
187 Default is value is 360.
187 */
188 */
188
189
189 /*!
190 /*!
190 \property QPieSeries::count
191 \property QPieSeries::count
191
192
192 Number of slices in the series.
193 Number of slices in the series.
193 */
194 */
194
195
195 /*!
196 /*!
196 \qmlproperty int PieSeries::count
197 \qmlproperty int PieSeries::count
197
198
198 Number of slices in the series.
199 Number of slices in the series.
199 */
200 */
200
201
201 /*!
202 /*!
202 \fn void QPieSeries::countChanged()
203 \fn void QPieSeries::countChanged()
203
204
204 Emitted when the slice count has changed.
205 Emitted when the slice count has changed.
205
206
206 \sa count
207 \sa count
207 */
208 */
208
209
209 /*!
210 /*!
210 \property QPieSeries::sum
211 \property QPieSeries::sum
211
212
212 Sum of all slices.
213 Sum of all slices.
213
214
214 The series keeps track of the sum of all slices it holds.
215 The series keeps track of the sum of all slices it holds.
215 */
216 */
216
217
217 /*!
218 /*!
218 \qmlproperty real PieSeries::sum
219 \qmlproperty real PieSeries::sum
219
220
220 Sum of all slices.
221 Sum of all slices.
221
222
222 The series keeps track of the sum of all slices it holds.
223 The series keeps track of the sum of all slices it holds.
223 */
224 */
224
225
225 /*!
226 /*!
226 \fn void QPieSeries::sumChanged()
227 \fn void QPieSeries::sumChanged()
227
228
228 Emitted when the sum of all slices has changed.
229 Emitted when the sum of all slices has changed.
229
230
230 \sa sum
231 \sa sum
231 */
232 */
232
233
233 /*!
234 /*!
234 \fn void QPieSeries::added(QList<QPieSlice*> slices)
235 \fn void QPieSeries::added(QList<QPieSlice*> slices)
235
236
236 This signal is emitted when \a slices have been added to the series.
237 This signal is emitted when \a slices have been added to the series.
237
238
238 \sa append(), insert()
239 \sa append(), insert()
239 */
240 */
240 /*!
241 /*!
241 \qmlsignal PieSeries::added(PieSlice slice)
242 \qmlsignal PieSeries::added(PieSlice slice)
242 Emitted when \a slice has been added to the series.
243 Emitted when \a slice has been added to the series.
243 */
244 */
244
245
245 /*!
246 /*!
246 \fn void QPieSeries::removed(QList<QPieSlice*> slices)
247 \fn void QPieSeries::removed(QList<QPieSlice*> slices)
247 This signal is emitted when \a slices have been removed from the series.
248 This signal is emitted when \a slices have been removed from the series.
248 \sa remove()
249 \sa remove()
249 */
250 */
250 /*!
251 /*!
251 \qmlsignal PieSeries::removed(PieSlice slice)
252 \qmlsignal PieSeries::removed(PieSlice slice)
252 Emitted when \a slice has been removed from the series.
253 Emitted when \a slice has been removed from the series.
253 */
254 */
254
255
255 /*!
256 /*!
256 \fn void QPieSeries::clicked(QPieSlice* slice)
257 \fn void QPieSeries::clicked(QPieSlice* slice)
257
258
258 This signal is emitted when a \a slice has been clicked.
259 This signal is emitted when a \a slice has been clicked.
259
260
260 \sa QPieSlice::clicked()
261 \sa QPieSlice::clicked()
261 */
262 */
262
263
263 /*!
264 /*!
264 \fn void QPieSeries::hovered(QPieSlice* slice, bool state)
265 \fn void QPieSeries::hovered(QPieSlice* slice, bool state)
265
266
266 This signal is emitted when user has hovered over or away from the \a slice.
267 This signal is emitted when user has hovered over or away from the \a slice.
267
268
268 \a state is true when user has hovered over the slice and false when hover has moved away from the slice.
269 \a state is true when user has hovered over the slice and false when hover has moved away from the slice.
269
270
270 \sa QPieSlice::hovered()
271 \sa QPieSlice::hovered()
271 */
272 */
272
273
273 /*!
274 /*!
275 \qmlmethod PieSlice PieSeries::at(int index)
276 Returns slice at \a index. Returns null if the index is not valid.
277 */
278
279 /*!
280 \qmlmethod PieSlice PieSeries::find(string label)
281 Returns the first slice with \a label. Returns null if the index is not valid.
282 */
283
284 /*!
285 \qmlmethod PieSlice PieSeries::append(string label, real value)
286 Adds a new slice with \a label and \a value to the pie.
287 */
288
289 /*!
290 \qmlmethod bool PieSeries::remove(PieSlice slice)
291 Removes the \a slice from the pie. Returns true if the removal was successfull, false otherwise.
292 */
293
294 /*!
295 \qmlmethod PieSeries::clear()
296 Removes all slices from the pie.
297 */
298
299 /*!
274 Constructs a series object which is a child of \a parent.
300 Constructs a series object which is a child of \a parent.
275 */
301 */
276 QPieSeries::QPieSeries(QObject *parent) :
302 QPieSeries::QPieSeries(QObject *parent) :
277 QAbstractSeries(*new QPieSeriesPrivate(this),parent)
303 QAbstractSeries(*new QPieSeriesPrivate(this),parent)
278 {
304 {
279
305
280 }
306 }
281
307
282 /*!
308 /*!
283 Destroys the series and its slices.
309 Destroys the series and its slices.
284 */
310 */
285 QPieSeries::~QPieSeries()
311 QPieSeries::~QPieSeries()
286 {
312 {
287 // NOTE: d_prt destroyed by QObject
313 // NOTE: d_prt destroyed by QObject
288 }
314 }
289
315
290 /*!
316 /*!
291 Returns QChartSeries::SeriesTypePie.
317 Returns QChartSeries::SeriesTypePie.
292 */
318 */
293 QAbstractSeries::SeriesType QPieSeries::type() const
319 QAbstractSeries::SeriesType QPieSeries::type() const
294 {
320 {
295 return QAbstractSeries::SeriesTypePie;
321 return QAbstractSeries::SeriesTypePie;
296 }
322 }
297
323
298 /*!
324 /*!
299 Appends a single \a slice to the series.
325 Appends a single \a slice to the series.
300 Slice ownership is passed to the series.
326 Slice ownership is passed to the series.
301
327
302 Returns true if append was succesfull.
328 Returns true if append was succesfull.
303 */
329 */
304 bool QPieSeries::append(QPieSlice* slice)
330 bool QPieSeries::append(QPieSlice* slice)
305 {
331 {
306 return append(QList<QPieSlice*>() << slice);
332 return append(QList<QPieSlice*>() << slice);
307 }
333 }
308
334
309 /*!
335 /*!
310 Appends an array of \a slices to the series.
336 Appends an array of \a slices to the series.
311 Slice ownership is passed to the series.
337 Slice ownership is passed to the series.
312
338
313 Returns true if append was successfull.
339 Returns true if append was successfull.
314 */
340 */
315 bool QPieSeries::append(QList<QPieSlice*> slices)
341 bool QPieSeries::append(QList<QPieSlice*> slices)
316 {
342 {
317 Q_D(QPieSeries);
343 Q_D(QPieSeries);
318
344
319 if (slices.count() == 0)
345 if (slices.count() == 0)
320 return false;
346 return false;
321
347
322 foreach (QPieSlice* s, slices) {
348 foreach (QPieSlice* s, slices) {
323 if (!s || d->m_slices.contains(s))
349 if (!s || d->m_slices.contains(s))
324 return false;
350 return false;
325 if (s->series()) // already added to some series
351 if (s->series()) // already added to some series
326 return false;
352 return false;
327 }
353 }
328
354
329 foreach (QPieSlice* s, slices) {
355 foreach (QPieSlice* s, slices) {
330 s->setParent(this);
356 s->setParent(this);
331 QPieSlicePrivate::fromSlice(s)->m_series = this;
357 QPieSlicePrivate::fromSlice(s)->m_series = this;
332 d->m_slices << s;
358 d->m_slices << s;
333 }
359 }
334
360
335 d->updateDerivativeData();
361 d->updateDerivativeData();
336
362
337 foreach (QPieSlice* s, slices) {
363 foreach (QPieSlice* s, slices) {
338 connect(s, SIGNAL(valueChanged()), d, SLOT(sliceValueChanged()));
364 connect(s, SIGNAL(valueChanged()), d, SLOT(sliceValueChanged()));
339 connect(s, SIGNAL(clicked()), d, SLOT(sliceClicked()));
365 connect(s, SIGNAL(clicked()), d, SLOT(sliceClicked()));
340 connect(s, SIGNAL(hovered(bool)), d, SLOT(sliceHovered(bool)));
366 connect(s, SIGNAL(hovered(bool)), d, SLOT(sliceHovered(bool)));
341 }
367 }
342
368
343 emit added(slices);
369 emit added(slices);
344 emit countChanged();
370 emit countChanged();
345
371
346 return true;
372 return true;
347 }
373 }
348
374
349 /*!
375 /*!
350 Appends a single \a slice to the series and returns a reference to the series.
376 Appends a single \a slice to the series and returns a reference to the series.
351 Slice ownership is passed to the series.
377 Slice ownership is passed to the series.
352 */
378 */
353 QPieSeries& QPieSeries::operator << (QPieSlice* slice)
379 QPieSeries& QPieSeries::operator << (QPieSlice* slice)
354 {
380 {
355 append(slice);
381 append(slice);
356 return *this;
382 return *this;
357 }
383 }
358
384
359
385
360 /*!
386 /*!
361 Appends a single slice to the series with give \a value and \a label.
387 Appends a single slice to the series with give \a value and \a label.
362 Slice ownership is passed to the series.
388 Slice ownership is passed to the series.
363 */
389 */
364 QPieSlice* QPieSeries::append(QString label, qreal value)
390 QPieSlice* QPieSeries::append(QString label, qreal value)
365 {
391 {
366 QPieSlice* slice = new QPieSlice(label, value);
392 QPieSlice* slice = new QPieSlice(label, value);
367 append(slice);
393 append(slice);
368 return slice;
394 return slice;
369 }
395 }
370
396
371 /*!
397 /*!
372 Inserts a single \a slice to the series before the slice at \a index position.
398 Inserts a single \a slice to the series before the slice at \a index position.
373 Slice ownership is passed to the series.
399 Slice ownership is passed to the series.
374
400
375 Returns true if insert was successfull.
401 Returns true if insert was successfull.
376 */
402 */
377 bool QPieSeries::insert(int index, QPieSlice* slice)
403 bool QPieSeries::insert(int index, QPieSlice* slice)
378 {
404 {
379 Q_D(QPieSeries);
405 Q_D(QPieSeries);
380
406
381 if (index < 0 || index > d->m_slices.count())
407 if (index < 0 || index > d->m_slices.count())
382 return false;
408 return false;
383
409
384 if (!slice || d->m_slices.contains(slice))
410 if (!slice || d->m_slices.contains(slice))
385 return false;
411 return false;
386
412
387 if (slice->series()) // already added to some series
413 if (slice->series()) // already added to some series
388 return false;
414 return false;
389
415
390 slice->setParent(this);
416 slice->setParent(this);
391 QPieSlicePrivate::fromSlice(slice)->m_series = this;
417 QPieSlicePrivate::fromSlice(slice)->m_series = this;
392 d->m_slices.insert(index, slice);
418 d->m_slices.insert(index, slice);
393
419
394 d->updateDerivativeData();
420 d->updateDerivativeData();
395
421
396 connect(slice, SIGNAL(valueChanged()), d, SLOT(sliceValueChanged()));
422 connect(slice, SIGNAL(valueChanged()), d, SLOT(sliceValueChanged()));
397 connect(slice, SIGNAL(clicked()), d, SLOT(sliceClicked()));
423 connect(slice, SIGNAL(clicked()), d, SLOT(sliceClicked()));
398 connect(slice, SIGNAL(hovered(bool)), d, SLOT(sliceHovered(bool)));
424 connect(slice, SIGNAL(hovered(bool)), d, SLOT(sliceHovered(bool)));
399
425
400 emit added(QList<QPieSlice*>() << slice);
426 emit added(QList<QPieSlice*>() << slice);
401 emit countChanged();
427 emit countChanged();
402
428
403 return true;
429 return true;
404 }
430 }
405
431
406 /*!
432 /*!
407 Removes a single \a slice from the series and deletes the slice.
433 Removes a single \a slice from the series and deletes the slice.
408
434
409 Do not reference the pointer after this call.
435 Do not reference the pointer after this call.
410
436
411 Returns true if remove was successfull.
437 Returns true if remove was successfull.
412 */
438 */
413 bool QPieSeries::remove(QPieSlice* slice)
439 bool QPieSeries::remove(QPieSlice* slice)
414 {
440 {
415 Q_D(QPieSeries);
441 Q_D(QPieSeries);
416
442
417 if (!d->m_slices.removeOne(slice))
443 if (!d->m_slices.removeOne(slice))
418 return false;
444 return false;
419
445
420 d->updateDerivativeData();
446 d->updateDerivativeData();
421
447
422 emit removed(QList<QPieSlice*>() << slice);
448 emit removed(QList<QPieSlice*>() << slice);
423 emit countChanged();
449 emit countChanged();
424
450
425 delete slice;
451 delete slice;
426 slice = 0;
452 slice = 0;
427
453
428 return true;
454 return true;
429 }
455 }
430
456
431 /*!
457 /*!
432 Clears all slices from the series.
458 Clears all slices from the series.
433 */
459 */
434 void QPieSeries::clear()
460 void QPieSeries::clear()
435 {
461 {
436 Q_D(QPieSeries);
462 Q_D(QPieSeries);
437 if (d->m_slices.count() == 0)
463 if (d->m_slices.count() == 0)
438 return;
464 return;
439
465
440 QList<QPieSlice*> slices = d->m_slices;
466 QList<QPieSlice*> slices = d->m_slices;
441 foreach (QPieSlice* s, d->m_slices) {
467 foreach (QPieSlice* s, d->m_slices) {
442 d->m_slices.removeOne(s);
468 d->m_slices.removeOne(s);
443 delete s;
469 delete s;
444 }
470 }
445
471
446 d->updateDerivativeData();
472 d->updateDerivativeData();
447
473
448 emit removed(slices);
474 emit removed(slices);
449 emit countChanged();
475 emit countChanged();
450 }
476 }
451
477
452 /*!
478 /*!
453 Returns a list of slices that belong to this series.
479 Returns a list of slices that belong to this series.
454 */
480 */
455 QList<QPieSlice*> QPieSeries::slices() const
481 QList<QPieSlice*> QPieSeries::slices() const
456 {
482 {
457 Q_D(const QPieSeries);
483 Q_D(const QPieSeries);
458 return d->m_slices;
484 return d->m_slices;
459 }
485 }
460
486
461 /*!
487 /*!
462 returns the number of the slices in this series.
488 returns the number of the slices in this series.
463 */
489 */
464 int QPieSeries::count() const
490 int QPieSeries::count() const
465 {
491 {
466 Q_D(const QPieSeries);
492 Q_D(const QPieSeries);
467 return d->m_slices.count();
493 return d->m_slices.count();
468 }
494 }
469
495
470 /*!
496 /*!
471 Returns true is the series is empty.
497 Returns true is the series is empty.
472 */
498 */
473 bool QPieSeries::isEmpty() const
499 bool QPieSeries::isEmpty() const
474 {
500 {
475 Q_D(const QPieSeries);
501 Q_D(const QPieSeries);
476 return d->m_slices.isEmpty();
502 return d->m_slices.isEmpty();
477 }
503 }
478
504
479 /*!
505 /*!
480 Returns the sum of all slice values in this series.
506 Returns the sum of all slice values in this series.
481
507
482 \sa QPieSlice::value(), QPieSlice::setValue(), QPieSlice::percentage()
508 \sa QPieSlice::value(), QPieSlice::setValue(), QPieSlice::percentage()
483 */
509 */
484 qreal QPieSeries::sum() const
510 qreal QPieSeries::sum() const
485 {
511 {
486 Q_D(const QPieSeries);
512 Q_D(const QPieSeries);
487 return d->m_sum;
513 return d->m_sum;
488 }
514 }
489
515
490 void QPieSeries::setHorizontalPosition(qreal relativePosition)
516 void QPieSeries::setHorizontalPosition(qreal relativePosition)
491 {
517 {
492 Q_D(QPieSeries);
518 Q_D(QPieSeries);
493
519
494 if (relativePosition < 0.0)
520 if (relativePosition < 0.0)
495 relativePosition = 0.0;
521 relativePosition = 0.0;
496 if (relativePosition > 1.0)
522 if (relativePosition > 1.0)
497 relativePosition = 1.0;
523 relativePosition = 1.0;
498
524
499 if (!qFuzzyIsNull(d->m_pieRelativeHorPos - relativePosition)) {
525 if (!qFuzzyIsNull(d->m_pieRelativeHorPos - relativePosition)) {
500 d->m_pieRelativeHorPos = relativePosition;
526 d->m_pieRelativeHorPos = relativePosition;
501 emit d->horizontalPositionChanged();
527 emit d->horizontalPositionChanged();
502 }
528 }
503 }
529 }
504
530
505 qreal QPieSeries::horizontalPosition() const
531 qreal QPieSeries::horizontalPosition() const
506 {
532 {
507 Q_D(const QPieSeries);
533 Q_D(const QPieSeries);
508 return d->m_pieRelativeHorPos;
534 return d->m_pieRelativeHorPos;
509 }
535 }
510
536
511 void QPieSeries::setVerticalPosition(qreal relativePosition)
537 void QPieSeries::setVerticalPosition(qreal relativePosition)
512 {
538 {
513 Q_D(QPieSeries);
539 Q_D(QPieSeries);
514
540
515 if (relativePosition < 0.0)
541 if (relativePosition < 0.0)
516 relativePosition = 0.0;
542 relativePosition = 0.0;
517 if (relativePosition > 1.0)
543 if (relativePosition > 1.0)
518 relativePosition = 1.0;
544 relativePosition = 1.0;
519
545
520 if (!qFuzzyIsNull(d->m_pieRelativeVerPos - relativePosition)) {
546 if (!qFuzzyIsNull(d->m_pieRelativeVerPos - relativePosition)) {
521 d->m_pieRelativeVerPos = relativePosition;
547 d->m_pieRelativeVerPos = relativePosition;
522 emit d->verticalPositionChanged();
548 emit d->verticalPositionChanged();
523 }
549 }
524 }
550 }
525
551
526 qreal QPieSeries::verticalPosition() const
552 qreal QPieSeries::verticalPosition() const
527 {
553 {
528 Q_D(const QPieSeries);
554 Q_D(const QPieSeries);
529 return d->m_pieRelativeVerPos;
555 return d->m_pieRelativeVerPos;
530 }
556 }
531
557
532 void QPieSeries::setPieSize(qreal relativeSize)
558 void QPieSeries::setPieSize(qreal relativeSize)
533 {
559 {
534 Q_D(QPieSeries);
560 Q_D(QPieSeries);
535
561
536 if (relativeSize < 0.0)
562 if (relativeSize < 0.0)
537 relativeSize = 0.0;
563 relativeSize = 0.0;
538 if (relativeSize > 1.0)
564 if (relativeSize > 1.0)
539 relativeSize = 1.0;
565 relativeSize = 1.0;
540
566
541 if (!qFuzzyIsNull(d->m_pieRelativeSize - relativeSize)) {
567 if (!qFuzzyIsNull(d->m_pieRelativeSize - relativeSize)) {
542 d->m_pieRelativeSize = relativeSize;
568 d->m_pieRelativeSize = relativeSize;
543 emit d->pieSizeChanged();
569 emit d->pieSizeChanged();
544 }
570 }
545 }
571 }
546
572
547 qreal QPieSeries::pieSize() const
573 qreal QPieSeries::pieSize() const
548 {
574 {
549 Q_D(const QPieSeries);
575 Q_D(const QPieSeries);
550 return d->m_pieRelativeSize;
576 return d->m_pieRelativeSize;
551 }
577 }
552
578
553
579
554 void QPieSeries::setPieStartAngle(qreal angle)
580 void QPieSeries::setPieStartAngle(qreal angle)
555 {
581 {
556 Q_D(QPieSeries);
582 Q_D(QPieSeries);
557 if (qFuzzyIsNull(d->m_pieStartAngle - angle))
583 if (qFuzzyIsNull(d->m_pieStartAngle - angle))
558 return;
584 return;
559 d->m_pieStartAngle = angle;
585 d->m_pieStartAngle = angle;
560 d->updateDerivativeData();
586 d->updateDerivativeData();
561 emit d->pieStartAngleChanged();
587 emit d->pieStartAngleChanged();
562 }
588 }
563
589
564 qreal QPieSeries::pieStartAngle() const
590 qreal QPieSeries::pieStartAngle() const
565 {
591 {
566 Q_D(const QPieSeries);
592 Q_D(const QPieSeries);
567 return d->m_pieStartAngle;
593 return d->m_pieStartAngle;
568 }
594 }
569
595
570 /*!
596 /*!
571 Sets the end angle of the pie.
597 Sets the end angle of the pie.
572
598
573 Full pie is 360 degrees where 0 degrees is at 12 a'clock.
599 Full pie is 360 degrees where 0 degrees is at 12 a'clock.
574
600
575 \a angle must be greater than start angle.
601 \a angle must be greater than start angle.
576
602
577 \sa pieEndAngle(), pieStartAngle(), setPieStartAngle()
603 \sa pieEndAngle(), pieStartAngle(), setPieStartAngle()
578 */
604 */
579 void QPieSeries::setPieEndAngle(qreal angle)
605 void QPieSeries::setPieEndAngle(qreal angle)
580 {
606 {
581 Q_D(QPieSeries);
607 Q_D(QPieSeries);
582 if (qFuzzyIsNull(d->m_pieEndAngle - angle))
608 if (qFuzzyIsNull(d->m_pieEndAngle - angle))
583 return;
609 return;
584 d->m_pieEndAngle = angle;
610 d->m_pieEndAngle = angle;
585 d->updateDerivativeData();
611 d->updateDerivativeData();
586 emit d->pieEndAngleChanged();
612 emit d->pieEndAngleChanged();
587 }
613 }
588
614
589 /*!
615 /*!
590 Returns the end angle of the pie.
616 Returns the end angle of the pie.
591
617
592 Full pie is 360 degrees where 0 degrees is at 12 a'clock.
618 Full pie is 360 degrees where 0 degrees is at 12 a'clock.
593
619
594 \sa setPieEndAngle(), pieStartAngle(), setPieStartAngle()
620 \sa setPieEndAngle(), pieStartAngle(), setPieStartAngle()
595 */
621 */
596 qreal QPieSeries::pieEndAngle() const
622 qreal QPieSeries::pieEndAngle() const
597 {
623 {
598 Q_D(const QPieSeries);
624 Q_D(const QPieSeries);
599 return d->m_pieEndAngle;
625 return d->m_pieEndAngle;
600 }
626 }
601
627
602 /*!
628 /*!
603 Sets the all the slice labels \a visible or invisible.
629 Sets the all the slice labels \a visible or invisible.
604
630
605 Note that this affects only the current slices in the series.
631 Note that this affects only the current slices in the series.
606 If user adds a new slice the default label visibility is false.
632 If user adds a new slice the default label visibility is false.
607
633
608 \sa QPieSlice::isLabelVisible(), QPieSlice::setLabelVisible()
634 \sa QPieSlice::isLabelVisible(), QPieSlice::setLabelVisible()
609 */
635 */
610 void QPieSeries::setLabelsVisible(bool visible)
636 void QPieSeries::setLabelsVisible(bool visible)
611 {
637 {
612 Q_D(QPieSeries);
638 Q_D(QPieSeries);
613 foreach (QPieSlice* s, d->m_slices)
639 foreach (QPieSlice* s, d->m_slices)
614 s->setLabelVisible(visible);
640 s->setLabelVisible(visible);
615 }
641 }
616
642
617 ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
643 ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
618
644
619
645
620 QPieSeriesPrivate::QPieSeriesPrivate(QPieSeries *parent) :
646 QPieSeriesPrivate::QPieSeriesPrivate(QPieSeries *parent) :
621 QAbstractSeriesPrivate(parent),
647 QAbstractSeriesPrivate(parent),
622 m_pieRelativeHorPos(0.5),
648 m_pieRelativeHorPos(0.5),
623 m_pieRelativeVerPos(0.5),
649 m_pieRelativeVerPos(0.5),
624 m_pieRelativeSize(0.7),
650 m_pieRelativeSize(0.7),
625 m_pieStartAngle(0),
651 m_pieStartAngle(0),
626 m_pieEndAngle(360),
652 m_pieEndAngle(360),
627 m_sum(0)
653 m_sum(0)
628 {
654 {
629 }
655 }
630
656
631 QPieSeriesPrivate::~QPieSeriesPrivate()
657 QPieSeriesPrivate::~QPieSeriesPrivate()
632 {
658 {
633 }
659 }
634
660
635 void QPieSeriesPrivate::updateDerivativeData()
661 void QPieSeriesPrivate::updateDerivativeData()
636 {
662 {
637 // calculate sum of all slices
663 // calculate sum of all slices
638 qreal sum = 0;
664 qreal sum = 0;
639 foreach (QPieSlice* s, m_slices)
665 foreach (QPieSlice* s, m_slices)
640 sum += s->value();
666 sum += s->value();
641
667
642 if (!qFuzzyIsNull(m_sum - sum)) {
668 if (!qFuzzyIsNull(m_sum - sum)) {
643 m_sum = sum;
669 m_sum = sum;
644 emit q_func()->sumChanged();
670 emit q_func()->sumChanged();
645 }
671 }
646
672
647 // nothing to show..
673 // nothing to show..
648 if (qFuzzyIsNull(m_sum))
674 if (qFuzzyIsNull(m_sum))
649 return;
675 return;
650
676
651 // update slice attributes
677 // update slice attributes
652 qreal sliceAngle = m_pieStartAngle;
678 qreal sliceAngle = m_pieStartAngle;
653 qreal pieSpan = m_pieEndAngle - m_pieStartAngle;
679 qreal pieSpan = m_pieEndAngle - m_pieStartAngle;
654 QVector<QPieSlice*> changed;
680 QVector<QPieSlice*> changed;
655 foreach (QPieSlice* s, m_slices) {
681 foreach (QPieSlice* s, m_slices) {
656 QPieSlicePrivate *d = QPieSlicePrivate::fromSlice(s);
682 QPieSlicePrivate *d = QPieSlicePrivate::fromSlice(s);
657 d->setPercentage(s->value() / m_sum);
683 d->setPercentage(s->value() / m_sum);
658 d->setStartAngle(sliceAngle);
684 d->setStartAngle(sliceAngle);
659 d->setAngleSpan(pieSpan * s->percentage());
685 d->setAngleSpan(pieSpan * s->percentage());
660 sliceAngle += s->angleSpan();
686 sliceAngle += s->angleSpan();
661 }
687 }
662
688
663
689
664 emit calculatedDataChanged();
690 emit calculatedDataChanged();
665 }
691 }
666
692
667 QPieSeriesPrivate* QPieSeriesPrivate::fromSeries(QPieSeries *series)
693 QPieSeriesPrivate* QPieSeriesPrivate::fromSeries(QPieSeries *series)
668 {
694 {
669 return series->d_func();
695 return series->d_func();
670 }
696 }
671
697
672 void QPieSeriesPrivate::sliceValueChanged()
698 void QPieSeriesPrivate::sliceValueChanged()
673 {
699 {
674 Q_ASSERT(m_slices.contains(qobject_cast<QPieSlice *>(sender())));
700 Q_ASSERT(m_slices.contains(qobject_cast<QPieSlice *>(sender())));
675 updateDerivativeData();
701 updateDerivativeData();
676 }
702 }
677
703
678 void QPieSeriesPrivate::sliceClicked()
704 void QPieSeriesPrivate::sliceClicked()
679 {
705 {
680 QPieSlice* slice = qobject_cast<QPieSlice *>(sender());
706 QPieSlice* slice = qobject_cast<QPieSlice *>(sender());
681 Q_ASSERT(m_slices.contains(slice));
707 Q_ASSERT(m_slices.contains(slice));
682 Q_Q(QPieSeries);
708 Q_Q(QPieSeries);
683 emit q->clicked(slice);
709 emit q->clicked(slice);
684 }
710 }
685
711
686 void QPieSeriesPrivate::sliceHovered(bool state)
712 void QPieSeriesPrivate::sliceHovered(bool state)
687 {
713 {
688 QPieSlice* slice = qobject_cast<QPieSlice *>(sender());
714 QPieSlice* slice = qobject_cast<QPieSlice *>(sender());
689 Q_ASSERT(m_slices.contains(slice));
715 Q_ASSERT(m_slices.contains(slice));
690 Q_Q(QPieSeries);
716 Q_Q(QPieSeries);
691 emit q->hovered(slice, state);
717 emit q->hovered(slice, state);
692 }
718 }
693
719
694 void QPieSeriesPrivate::scaleDomain(Domain& domain)
720 void QPieSeriesPrivate::scaleDomain(Domain& domain)
695 {
721 {
696 Q_UNUSED(domain);
722 Q_UNUSED(domain);
697 // does not apply to pie
723 // does not apply to pie
698 }
724 }
699
725
700 Chart* QPieSeriesPrivate::createGraphics(ChartPresenter* presenter)
726 Chart* QPieSeriesPrivate::createGraphics(ChartPresenter* presenter)
701 {
727 {
702 Q_Q(QPieSeries);
728 Q_Q(QPieSeries);
703 PieChartItem* pie = new PieChartItem(q,presenter);
729 PieChartItem* pie = new PieChartItem(q,presenter);
704 if(presenter->animationOptions().testFlag(QChart::SeriesAnimations)) {
730 if(presenter->animationOptions().testFlag(QChart::SeriesAnimations)) {
705 presenter->animator()->addAnimation(pie);
731 presenter->animator()->addAnimation(pie);
706 }
732 }
707 presenter->chartTheme()->decorate(q, presenter->dataSet()->seriesIndex(q));
733 presenter->chartTheme()->decorate(q, presenter->dataSet()->seriesIndex(q));
708 return pie;
734 return pie;
709 }
735 }
710
736
711 QList<LegendMarker*> QPieSeriesPrivate::createLegendMarker(QLegend* legend)
737 QList<LegendMarker*> QPieSeriesPrivate::createLegendMarker(QLegend* legend)
712 {
738 {
713 Q_Q(QPieSeries);
739 Q_Q(QPieSeries);
714 QList<LegendMarker*> markers;
740 QList<LegendMarker*> markers;
715 foreach(QPieSlice* slice, q->slices()) {
741 foreach(QPieSlice* slice, q->slices()) {
716 PieLegendMarker* marker = new PieLegendMarker(q,slice,legend);
742 PieLegendMarker* marker = new PieLegendMarker(q,slice,legend);
717 markers << marker;
743 markers << marker;
718 }
744 }
719 return markers;
745 return markers;
720 }
746 }
721
747
722 #include "moc_qpieseries.cpp"
748 #include "moc_qpieseries.cpp"
723 #include "moc_qpieseries_p.cpp"
749 #include "moc_qpieseries_p.cpp"
724
750
725 QTCOMMERCIALCHART_END_NAMESPACE
751 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,173 +1,175
1 /****************************************************************************
1 /****************************************************************************
2 **
2 **
3 ** Copyright (C) 2012 Digia Plc
3 ** Copyright (C) 2012 Digia Plc
4 ** All rights reserved.
4 ** All rights reserved.
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 **
6 **
7 ** This file is part of the Qt Commercial Charts Add-on.
7 ** This file is part of the Qt Commercial Charts Add-on.
8 **
8 **
9 ** $QT_BEGIN_LICENSE$
9 ** $QT_BEGIN_LICENSE$
10 ** Licensees holding valid Qt Commercial licenses may use this file in
10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 ** accordance with the Qt Commercial License Agreement provided with the
11 ** accordance with the Qt Commercial License Agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia.
13 ** a written agreement between you and Digia.
14 **
14 **
15 ** If you have questions regarding the use of this file, please use
15 ** If you have questions regarding the use of this file, please use
16 ** contact form at http://qt.digia.com
16 ** contact form at http://qt.digia.com
17 ** $QT_END_LICENSE$
17 ** $QT_END_LICENSE$
18 **
18 **
19 ****************************************************************************/
19 ****************************************************************************/
20
20
21 #include "qabstractseries.h"
21 #include "qabstractseries.h"
22 #include "qabstractseries_p.h"
22 #include "qabstractseries_p.h"
23 #include "chartdataset_p.h"
23 #include "chartdataset_p.h"
24
24
25 QTCOMMERCIALCHART_BEGIN_NAMESPACE
25 QTCOMMERCIALCHART_BEGIN_NAMESPACE
26
26
27 /*!
27 /*!
28 \class QAbstractSeries
28 \class QAbstractSeries
29 \brief Base class for all QtCommercial Chart series.
29 \brief Base class for all QtCommercial Chart series.
30 \mainclass
30 \mainclass
31
31
32 Usually you use the series type specific inherited classes instead of the base class.
32 Usually you use the series type specific inherited classes instead of the base class.
33 \sa QXYSeries, QLineSeries, QSplineSeries, QScatterSeries, QAreaSeries, QBarSeries, QStackedBarSeries,
33 \sa QXYSeries, QLineSeries, QSplineSeries, QScatterSeries, QAreaSeries, QBarSeries, QStackedBarSeries,
34 QPercentBarSeries, QPieSeries
34 QPercentBarSeries, QPieSeries
35 */
35 */
36 /*!
37 \qmlclass AbstractSeries
38 AbstractSeries is the base class for all series.
39 The class cannot be instantiated by the user.
40 */
36
41
37 /*!
42 /*!
38 \enum QAbstractSeries::SeriesType
43 \enum QAbstractSeries::SeriesType
39
44
40 The type of the series object.
45 The type of the series object.
41
46
42 \value SeriesTypeLine
47 \value SeriesTypeLine
43 \value SeriesTypeArea
48 \value SeriesTypeArea
44 \value SeriesTypeBar
49 \value SeriesTypeBar
45 \value SeriesTypeStackedBar
50 \value SeriesTypeStackedBar
46 \value SeriesTypePercentBar
51 \value SeriesTypePercentBar
47 \value SeriesTypeGroupedBar
52 \value SeriesTypeGroupedBar
48 \value SeriesTypePie
53 \value SeriesTypePie
49 \value SeriesTypeScatter
54 \value SeriesTypeScatter
50 \value SeriesTypeSpline
55 \value SeriesTypeSpline
51 */
56 */
52
57
53 /*!
58 /*!
54 \property QAbstractSeries::type
59 \property QAbstractSeries::type
55 The type of the series.
60 The type of the series.
56 */
61 */
62 /*!
63 \qmlproperty ChartView.SeriesType AbstractSeries::type
64 The type of the series.
65 */
57
66
58 /*!
67 /*!
59 \property QAbstractSeries::name
68 \property QAbstractSeries::name
60 \brief name of the series property
69 \brief name of the series property. The name is shown in legend for QXYSeries.
70 */
71 /*!
72 \qmlproperty string AbstractSeries::name
73 Name of the series. The name is shown in legend for QXYSeries.
61 */
74 */
62
75
63 /*!
76 /*!
64 \fn void QAbstractSeries::nameChanged()
77 \fn void QAbstractSeries::nameChanged()
65
66 This signal is emitted when the series name changes.
78 This signal is emitted when the series name changes.
67
79 */
68 \sa name
80 /*!
81 \qmlsignal AbstractSeries::nameChanged()
82 This signal is emitted when the series name changes.
69 */
83 */
70
84
71 /*!
85 /*!
72 \property QAbstractSeries::visible
86 \property QAbstractSeries::visible
73 \brief whether the series is visible or not; true by default.
87 \brief whether the series is visible or not; true by default.
74 */
88 */
75
89
76 /*!
90 /*!
77 \fn void QAbstractSeries::visibleChanged()
91 \fn void QAbstractSeries::visibleChanged()
78 Emitted when the series visibility changes.
92 Emitted when the series visibility changes.
79 */
93 */
80
94
81 /*!
95 /*!
82 \internal
96 \internal
83 \brief Constructs ChartSeries object with \a parent.
97 \brief Constructs ChartSeries object with \a parent.
84 */
98 */
85 QAbstractSeries::QAbstractSeries(QAbstractSeriesPrivate &d, QObject *parent) :
99 QAbstractSeries::QAbstractSeries(QAbstractSeriesPrivate &d, QObject *parent) :
86 QObject(parent),
100 QObject(parent),
87 d_ptr(&d)
101 d_ptr(&d)
88 {
102 {
89 }
103 }
90
104
91 /*!
105 /*!
92 \brief Virtual destructor for the chart series.
106 \brief Virtual destructor for the chart series.
93 */
107 */
94 QAbstractSeries::~QAbstractSeries()
108 QAbstractSeries::~QAbstractSeries()
95 {
109 {
96 if(d_ptr->m_dataset) qFatal("Still binded series detected !");
110 if(d_ptr->m_dataset) qFatal("Still binded series detected !");
97 }
111 }
98
112
99 /*!
100 \brief Sets a \a name for the series.
101
102 The name of a series is shown in the legend for QXYSeries.
103 \sa QChart::setTitle()
104 \sa QPieSlice::setLabel()
105 \sa QBarSet::setName()
106 */
107 void QAbstractSeries::setName(const QString& name)
113 void QAbstractSeries::setName(const QString& name)
108 {
114 {
109 if (name != d_ptr->m_name) {
115 if (name != d_ptr->m_name) {
110 d_ptr->m_name = name;
116 d_ptr->m_name = name;
111 emit nameChanged();
117 emit nameChanged();
112 }
118 }
113 }
119 }
114
120
115 /*!
116 \brief Returns the name of the series.
117 \sa setName()
118 */
119 QString QAbstractSeries::name() const
121 QString QAbstractSeries::name() const
120 {
122 {
121 return d_ptr->m_name;
123 return d_ptr->m_name;
122 }
124 }
123
125
124 /*!
126 /*!
125 Sets the visibility of series to \a visible
127 Sets the visibility of series to \a visible
126 */
128 */
127 void QAbstractSeries::setVisible(bool visible)
129 void QAbstractSeries::setVisible(bool visible)
128 {
130 {
129 if (visible != d_ptr->m_visible) {
131 if (visible != d_ptr->m_visible) {
130 d_ptr->m_visible = visible;
132 d_ptr->m_visible = visible;
131 emit visibleChanged();
133 emit visibleChanged();
132 }
134 }
133 }
135 }
134
136
135 /*!
137 /*!
136 Returns the visibility of series
138 Returns the visibility of series
137 */
139 */
138 bool QAbstractSeries::isVisible() const
140 bool QAbstractSeries::isVisible() const
139 {
141 {
140 return d_ptr->m_visible;
142 return d_ptr->m_visible;
141 }
143 }
142
144
143 /*!
145 /*!
144 \brief Returns the chart where series belongs to.
146 \brief Returns the chart where series belongs to.
145
147
146 Set automatically when the series is added to the chart
148 Set automatically when the series is added to the chart
147 and unset when the series is removed from the chart.
149 and unset when the series is removed from the chart.
148 */
150 */
149 QChart* QAbstractSeries::chart() const
151 QChart* QAbstractSeries::chart() const
150 {
152 {
151 return d_ptr->m_chart;
153 return d_ptr->m_chart;
152 }
154 }
153
155
154 ///////////////////////////////////////////////////////////////////////////////////////////////////
156 ///////////////////////////////////////////////////////////////////////////////////////////////////
155
157
156 QAbstractSeriesPrivate::QAbstractSeriesPrivate(QAbstractSeries* q):
158 QAbstractSeriesPrivate::QAbstractSeriesPrivate(QAbstractSeries* q):
157 q_ptr(q),
159 q_ptr(q),
158 m_chart(0),
160 m_chart(0),
159 m_dataset(0),
161 m_dataset(0),
160 m_visible(true)
162 m_visible(true)
161 {
163 {
162 }
164 }
163
165
164 QAbstractSeriesPrivate::~QAbstractSeriesPrivate()
166 QAbstractSeriesPrivate::~QAbstractSeriesPrivate()
165 {
167 {
166 }
168 }
167
169
168 #include "moc_qabstractseries.cpp"
170 #include "moc_qabstractseries.cpp"
169 #include "moc_qabstractseries_p.cpp"
171 #include "moc_qabstractseries_p.cpp"
170
172
171 QTCOMMERCIALCHART_END_NAMESPACE
173 QTCOMMERCIALCHART_END_NAMESPACE
172
174
173
175
@@ -1,415 +1,439
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 /*!
32 /*!
33 \qmlclass XYSeries
33 \qmlclass XYSeries
34 \brief The XYSeries class is a base class for line, spline and scatter series.
34 \inherits AbstractSeries
35 The XYSeries class is a base class for line, spline and scatter series.
35
36
36 The class cannot be instantiated directly.
37 The class cannot be instantiated directly.
37 */
38 */
38
39
39 /*!
40 /*!
40 \property QXYSeries::pointsVisible
41 \property QXYSeries::pointsVisible
41 Controls if the data points are visible and should be drawn.
42 Controls if the data points are visible and should be drawn.
42 */
43 */
43 /*!
44 /*!
44 \qmlproperty bool XYSeries::pointsVisible
45 \qmlproperty bool XYSeries::pointsVisible
45 Controls if the data points are visible and should be drawn.
46 Controls if the data points are visible and should be drawn.
46 */
47 */
47
48
48 /*!
49 /*!
49 \fn QPen QXYSeries::pen() const
50 \fn QPen QXYSeries::pen() const
50 \brief Returns pen used to draw points for series.
51 \brief Returns pen used to draw points for series.
51 \sa setPen()
52 \sa setPen()
52 */
53 */
53
54
54 /*!
55 /*!
55 \fn QBrush QXYSeries::brush() const
56 \fn QBrush QXYSeries::brush() const
56 \brief Returns brush used to draw points for series.
57 \brief Returns brush used to draw points for series.
57 \sa setBrush()
58 \sa setBrush()
58 */
59 */
59
60
60 /*!
61 /*!
61 \property QXYSeries::color
62 \property QXYSeries::color
62 The color of the series. This is line (pen) color in case of QLineSeries or QSplineSeries and
63 The color of the series. This is line (pen) color in case of QLineSeries or QSplineSeries and
63 fill (brush) color in case of QScatterSeries or QAreaSeries.
64 fill (brush) color in case of QScatterSeries or QAreaSeries.
64 \sa QXYSeries::pen(), QXYSeries::brush()
65 \sa QXYSeries::pen(), QXYSeries::brush()
65 */
66 */
66 /*!
67 /*!
67 \qmlproperty color XYSeries::color
68 \qmlproperty color XYSeries::color
68 The color of the series. This is line (pen) color in case of LineSeries or SplineSeries and
69 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.
70 fill (brush) color in case of ScatterSeries or AreaSeries.
70 */
71 */
71
72
72 /*!
73 /*!
73 \fn void QXYSeries::clicked(const QPointF& point)
74 \fn void QXYSeries::clicked(const QPointF& point)
74 \brief Signal is emitted when user clicks the \a point on chart.
75 \brief Signal is emitted when user clicks the \a point on chart.
75 */
76 */
76 /*!
77 /*!
77 \qmlsignal XYSeries::onClicked(QPointF point)
78 \qmlsignal XYSeries::onClicked(QPointF point)
78 Signal is emitted when user clicks the \a point on chart. For example:
79 Signal is emitted when user clicks the \a point on chart. For example:
79 \code
80 \code
80 LineSeries {
81 LineSeries {
81 XyPoint { x: 0; y: 0 }
82 XyPoint { x: 0; y: 0 }
82 XyPoint { x: 1.1; y: 2.1 }
83 XyPoint { x: 1.1; y: 2.1 }
83 onClicked: console.log("onClicked: " + point.x + ", " + point.y);
84 onClicked: console.log("onClicked: " + point.x + ", " + point.y);
84 }
85 }
85 \endcode
86 \endcode
86 */
87 */
87
88
88 /*!
89 /*!
89 \fn void QXYSeries::pointReplaced(int index)
90 \fn void QXYSeries::pointReplaced(int index)
90 Signal is emitted when a point has been replaced at \a index.
91 Signal is emitted when a point has been replaced at \a index.
91 \sa replace()
92 \sa replace()
92 */
93 */
93 /*!
94 /*!
94 \qmlsignal XYSeries::pointReplaced(int index)
95 \qmlsignal XYSeries::pointReplaced(int index)
95 Signal is emitted when a point has been replaced at \a index.
96 Signal is emitted when a point has been replaced at \a index.
96 */
97 */
97
98
98 /*!
99 /*!
99 \fn void QXYSeries::pointAdded(int index)
100 \fn void QXYSeries::pointAdded(int index)
100 Signal is emitted when a point has been added at \a index.
101 Signal is emitted when a point has been added at \a index.
101 \sa append(), insert()
102 \sa append(), insert()
102 */
103 */
103 /*!
104 /*!
104 \qmlsignal XYSeries::pointAdded(int index)
105 \qmlsignal XYSeries::pointAdded(int index)
105 Signal is emitted when a point has been added at \a index.
106 Signal is emitted when a point has been added at \a index.
106 */
107 */
107
108
108 /*!
109 /*!
109 \fn void QXYSeries::pointRemoved(int index)
110 \fn void QXYSeries::pointRemoved(int index)
110 Signal is emitted when a point has been removed from \a index.
111 Signal is emitted when a point has been removed from \a index.
111 \sa remove()
112 \sa remove()
112 */
113 */
113 /*!
114 /*!
114 \qmlsignal XYSeries::pointRemoved(int index)
115 \qmlsignal XYSeries::pointRemoved(int index)
115 Signal is emitted when a point has been removed from \a index.
116 Signal is emitted when a point has been removed from \a index.
116 */
117 */
117
118
118 /*!
119 /*!
119 \fn void QXYSeries::colorChanged(QColor color)
120 \fn void QXYSeries::colorChanged(QColor color)
120 \brief Signal is emitted when the line (pen) color has changed to \a color.
121 \brief Signal is emitted when the line (pen) color has changed to \a color.
121 */
122 */
122 /*!
123 /*!
123 \qmlsignal XYSeries::colorChanged(QColor color)
124 \qmlsignal XYSeries::colorChanged(QColor color)
124 Signal is emitted when the line (pen) color has changed to \a color.
125 Signal is emitted when the line (pen) color has changed to \a color.
125 */
126 */
126
127
127 /*!
128 /*!
128 \fn void QXYSeriesPrivate::updated()
129 \fn void QXYSeriesPrivate::updated()
129 \brief \internal
130 \brief \internal
130 */
131 */
131
132
132 /*!
133 /*!
133 \qmlmethod XyPoint XYSeries::at(int index)
134 \qmlmethod XYSeries::append(real x, real y)
135 Append point (\a x, \a y) to the series
136 */
137
138 /*!
139 \qmlmethod XYSeries::replace(real oldX, real oldY, real newX, real newY)
140 Replaces point (\a oldX, \a oldY) with point (\a newX, \a newY). Does nothing, if point (oldX, oldY) does not
141 exist.
142 */
143
144 /*!
145 \qmlmethod XYSeries::remove(real x, real y)
146 Removes point (\a x, \a y) from the series. Does nothing, if point (x, y) does not exist.
147 */
148
149 /*!
150 \qmlmethod XYSeries::insert(int index, real x, real y)
151 Inserts point (\a x, \a y) to the \a index. If index is 0 or smaller than 0 the point is prepended to the list of
152 points. If index is the same as or bigger than count, the point is appended to the list of points.
153 */
154
155 /*!
156 \qmlmethod QPointF XYSeries::at(int index)
157 Returns point at \a index. Returns (0, 0) if the index is not valid.
134 */
158 */
135
159
136 /*!
160 /*!
137 \internal
161 \internal
138
162
139 Constructs empty series object which is a child of \a parent.
163 Constructs empty series object which is a child of \a parent.
140 When series object is added to QChartView or QChart instance ownerships is transferred.
164 When series object is added to QChartView or QChart instance ownerships is transferred.
141 */
165 */
142 QXYSeries::QXYSeries(QXYSeriesPrivate &d,QObject *parent) : QAbstractSeries(d, parent)
166 QXYSeries::QXYSeries(QXYSeriesPrivate &d,QObject *parent) : QAbstractSeries(d, parent)
143 {
167 {
144 }
168 }
145
169
146 /*!
170 /*!
147 Destroys the object. Series added to QChartView or QChart instances are owned by those,
171 Destroys the object. Series added to QChartView or QChart instances are owned by those,
148 and are deleted when mentioned object are destroyed.
172 and are deleted when mentioned object are destroyed.
149 */
173 */
150 QXYSeries::~QXYSeries()
174 QXYSeries::~QXYSeries()
151 {
175 {
152 }
176 }
153
177
154 /*!
178 /*!
155 Adds data point \a x \a y to the series. Points are connected with lines on the chart.
179 Adds data point \a x \a y to the series. Points are connected with lines on the chart.
156 */
180 */
157 void QXYSeries::append(qreal x,qreal y)
181 void QXYSeries::append(qreal x,qreal y)
158 {
182 {
159 append(QPointF(x,y));
183 append(QPointF(x,y));
160 }
184 }
161
185
162 /*!
186 /*!
163 This is an overloaded function.
187 This is an overloaded function.
164 Adds data \a point to the series. Points are connected with lines on the chart.
188 Adds data \a point to the series. Points are connected with lines on the chart.
165 */
189 */
166 void QXYSeries::append(const QPointF &point)
190 void QXYSeries::append(const QPointF &point)
167 {
191 {
168 Q_D(QXYSeries);
192 Q_D(QXYSeries);
169 d->m_points<<point;
193 d->m_points<<point;
170 // emit d->pointAdded(d->m_points.count()-1);
194 // emit d->pointAdded(d->m_points.count()-1);
171 emit pointAdded(d->m_points.count()-1);
195 emit pointAdded(d->m_points.count()-1);
172 }
196 }
173
197
174 /*!
198 /*!
175 This is an overloaded function.
199 This is an overloaded function.
176 Adds list of data \a points to the series. Points are connected with lines on the chart.
200 Adds list of data \a points to the series. Points are connected with lines on the chart.
177 */
201 */
178 void QXYSeries::append(const QList<QPointF> &points)
202 void QXYSeries::append(const QList<QPointF> &points)
179 {
203 {
180 foreach(const QPointF& point , points) {
204 foreach(const QPointF& point , points) {
181 append(point);
205 append(point);
182 }
206 }
183 }
207 }
184
208
185 /*!
209 /*!
186 Replaces data point \a oldX \a oldY with data point \a newX \a newY.
210 Replaces data point \a oldX \a oldY with data point \a newX \a newY.
187 */
211 */
188 void QXYSeries::replace(qreal oldX,qreal oldY,qreal newX,qreal newY)
212 void QXYSeries::replace(qreal oldX,qreal oldY,qreal newX,qreal newY)
189 {
213 {
190 replace(QPointF(oldX,oldY),QPointF(newX,newY));
214 replace(QPointF(oldX,oldY),QPointF(newX,newY));
191 }
215 }
192
216
193 /*!
217 /*!
194 Replaces \a oldPoint with \a newPoint.
218 Replaces \a oldPoint with \a newPoint.
195 */
219 */
196 void QXYSeries::replace(const QPointF &oldPoint,const QPointF &newPoint)
220 void QXYSeries::replace(const QPointF &oldPoint,const QPointF &newPoint)
197 {
221 {
198 Q_D(QXYSeries);
222 Q_D(QXYSeries);
199 int index = d->m_points.indexOf(oldPoint);
223 int index = d->m_points.indexOf(oldPoint);
200 if(index==-1) return;
224 if(index==-1) return;
201 d->m_points[index] = newPoint;
225 d->m_points[index] = newPoint;
202 // emit d->pointReplaced(index);
226 // emit d->pointReplaced(index);
203 emit pointReplaced(index);
227 emit pointReplaced(index);
204 }
228 }
205
229
206 /*!
230 /*!
207 Removes current \a x and \a y value.
231 Removes current \a x and \a y value.
208 */
232 */
209 void QXYSeries::remove(qreal x,qreal y)
233 void QXYSeries::remove(qreal x,qreal y)
210 {
234 {
211 remove(QPointF(x,y));
235 remove(QPointF(x,y));
212 }
236 }
213
237
214 /*!
238 /*!
215 Removes current \a point x value.
239 Removes current \a point x value.
216
240
217 Note: point y value is ignored.
241 Note: point y value is ignored.
218 */
242 */
219 void QXYSeries::remove(const QPointF &point)
243 void QXYSeries::remove(const QPointF &point)
220 {
244 {
221 Q_D(QXYSeries);
245 Q_D(QXYSeries);
222 int index = d->m_points.indexOf(point);
246 int index = d->m_points.indexOf(point);
223 if(index==-1) return;
247 if(index==-1) return;
224 d->m_points.remove(index);
248 d->m_points.remove(index);
225 // emit d->pointRemoved(index);
249 // emit d->pointRemoved(index);
226 emit pointRemoved(index);
250 emit pointRemoved(index);
227 }
251 }
228
252
229 /*!
253 /*!
230 Inserts a \a point in the series at \a index position.
254 Inserts a \a point in the series at \a index position.
231 */
255 */
232 void QXYSeries::insert(int index, const QPointF &point)
256 void QXYSeries::insert(int index, const QPointF &point)
233 {
257 {
234 Q_D(QXYSeries);
258 Q_D(QXYSeries);
235 d->m_points.insert(index, point);
259 d->m_points.insert(index, point);
236 // emit d->pointAdded(index);
260 // emit d->pointAdded(index);
237 emit pointAdded(index);
261 emit pointAdded(index);
238 }
262 }
239
263
240 /*!
264 /*!
241 Removes all points from the series.
265 Removes all points from the series.
242 */
266 */
243 void QXYSeries::clear()
267 void QXYSeries::clear()
244 {
268 {
245 Q_D(QXYSeries);
269 Q_D(QXYSeries);
246 for (int i = d->m_points.size() - 1; i >= 0; i--)
270 for (int i = d->m_points.size() - 1; i >= 0; i--)
247 remove(d->m_points.at(i));
271 remove(d->m_points.at(i));
248 }
272 }
249
273
250 /*!
274 /*!
251 \internal \a pos
275 \internal \a pos
252 */
276 */
253 QList<QPointF> QXYSeries::points() const
277 QList<QPointF> QXYSeries::points() const
254 {
278 {
255 Q_D(const QXYSeries);
279 Q_D(const QXYSeries);
256 return d->m_points.toList();
280 return d->m_points.toList();
257 }
281 }
258
282
259 /*!
283 /*!
260 Returns number of data points within series.
284 Returns number of data points within series.
261 */
285 */
262 int QXYSeries::count() const
286 int QXYSeries::count() const
263 {
287 {
264 Q_D(const QXYSeries);
288 Q_D(const QXYSeries);
265 return d->m_points.count();
289 return d->m_points.count();
266 }
290 }
267
291
268
292
269 /*!
293 /*!
270 Sets \a pen used for drawing points on the chart. If the pen is not defined, the
294 Sets \a pen used for drawing points on the chart. If the pen is not defined, the
271 pen from chart theme is used.
295 pen from chart theme is used.
272 \sa QChart::setTheme()
296 \sa QChart::setTheme()
273 */
297 */
274 void QXYSeries::setPen(const QPen &pen)
298 void QXYSeries::setPen(const QPen &pen)
275 {
299 {
276 Q_D(QXYSeries);
300 Q_D(QXYSeries);
277 if (d->m_pen!=pen) {
301 if (d->m_pen!=pen) {
278 d->m_pen = pen;
302 d->m_pen = pen;
279 emit d->updated();
303 emit d->updated();
280 }
304 }
281 }
305 }
282
306
283 QPen QXYSeries::pen() const
307 QPen QXYSeries::pen() const
284 {
308 {
285 Q_D(const QXYSeries);
309 Q_D(const QXYSeries);
286 return d->m_pen;
310 return d->m_pen;
287 }
311 }
288
312
289 /*!
313 /*!
290 Sets \a brush used for drawing points on the chart. If the brush is not defined, brush
314 Sets \a brush used for drawing points on the chart. If the brush is not defined, brush
291 from chart theme setting is used.
315 from chart theme setting is used.
292 \sa QChart::setTheme()
316 \sa QChart::setTheme()
293 */
317 */
294 void QXYSeries::setBrush(const QBrush &brush)
318 void QXYSeries::setBrush(const QBrush &brush)
295 {
319 {
296 Q_D(QXYSeries);
320 Q_D(QXYSeries);
297 if (d->m_brush!=brush) {
321 if (d->m_brush!=brush) {
298 d->m_brush = brush;
322 d->m_brush = brush;
299 emit d->updated();
323 emit d->updated();
300 }
324 }
301 }
325 }
302
326
303 QBrush QXYSeries::brush() const
327 QBrush QXYSeries::brush() const
304 {
328 {
305 Q_D(const QXYSeries);
329 Q_D(const QXYSeries);
306 return d->m_brush;
330 return d->m_brush;
307 }
331 }
308
332
309 void QXYSeries::setColor(const QColor &color)
333 void QXYSeries::setColor(const QColor &color)
310 {
334 {
311 QPen p = pen();
335 QPen p = pen();
312 if (p.color() != color) {
336 if (p.color() != color) {
313 p.setColor(color);
337 p.setColor(color);
314 setPen(p);
338 setPen(p);
315 emit colorChanged(color);
339 emit colorChanged(color);
316 }
340 }
317 }
341 }
318
342
319 QColor QXYSeries::color() const
343 QColor QXYSeries::color() const
320 {
344 {
321 return pen().color();
345 return pen().color();
322 }
346 }
323
347
324 void QXYSeries::setPointsVisible(bool visible)
348 void QXYSeries::setPointsVisible(bool visible)
325 {
349 {
326 Q_D(QXYSeries);
350 Q_D(QXYSeries);
327 if (d->m_pointsVisible != visible){
351 if (d->m_pointsVisible != visible){
328 d->m_pointsVisible = visible;
352 d->m_pointsVisible = visible;
329 emit d->updated();
353 emit d->updated();
330 }
354 }
331 }
355 }
332
356
333 bool QXYSeries::pointsVisible() const
357 bool QXYSeries::pointsVisible() const
334 {
358 {
335 Q_D(const QXYSeries);
359 Q_D(const QXYSeries);
336 return d->m_pointsVisible;
360 return d->m_pointsVisible;
337 }
361 }
338
362
339
363
340 /*!
364 /*!
341 Stream operator for adding a data \a point to the series.
365 Stream operator for adding a data \a point to the series.
342 \sa append()
366 \sa append()
343 */
367 */
344 QXYSeries& QXYSeries::operator<< (const QPointF &point)
368 QXYSeries& QXYSeries::operator<< (const QPointF &point)
345 {
369 {
346 append(point);
370 append(point);
347 return *this;
371 return *this;
348 }
372 }
349
373
350
374
351 /*!
375 /*!
352 Stream operator for adding a list of \a points to the series.
376 Stream operator for adding a list of \a points to the series.
353 \sa append()
377 \sa append()
354 */
378 */
355
379
356 QXYSeries& QXYSeries::operator<< (const QList<QPointF>& points)
380 QXYSeries& QXYSeries::operator<< (const QList<QPointF>& points)
357 {
381 {
358 append(points);
382 append(points);
359 return *this;
383 return *this;
360 }
384 }
361
385
362 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
386 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
363
387
364
388
365 QXYSeriesPrivate::QXYSeriesPrivate(QXYSeries *q) :
389 QXYSeriesPrivate::QXYSeriesPrivate(QXYSeries *q) :
366 QAbstractSeriesPrivate(q),
390 QAbstractSeriesPrivate(q),
367 m_pointsVisible(false)
391 m_pointsVisible(false)
368 {
392 {
369 }
393 }
370
394
371 void QXYSeriesPrivate::scaleDomain(Domain& domain)
395 void QXYSeriesPrivate::scaleDomain(Domain& domain)
372 {
396 {
373 qreal minX(domain.minX());
397 qreal minX(domain.minX());
374 qreal minY(domain.minY());
398 qreal minY(domain.minY());
375 qreal maxX(domain.maxX());
399 qreal maxX(domain.maxX());
376 qreal maxY(domain.maxY());
400 qreal maxY(domain.maxY());
377 int tickXCount(domain.tickXCount());
401 int tickXCount(domain.tickXCount());
378 int tickYCount(domain.tickYCount());
402 int tickYCount(domain.tickYCount());
379
403
380 Q_Q(QXYSeries);
404 Q_Q(QXYSeries);
381
405
382 const QList<QPointF>& points = q->points();
406 const QList<QPointF>& points = q->points();
383
407
384
408
385 if(points.isEmpty()){
409 if(points.isEmpty()){
386 minX=0.0;
410 minX=0.0;
387 minY=0.0;
411 minY=0.0;
388 maxX=1.0;
412 maxX=1.0;
389 maxY=1.0;
413 maxY=1.0;
390 }
414 }
391
415
392 for (int i = 0; i < points.count(); i++)
416 for (int i = 0; i < points.count(); i++)
393 {
417 {
394 qreal x = points[i].x();
418 qreal x = points[i].x();
395 qreal y = points[i].y();
419 qreal y = points[i].y();
396 minX = qMin(minX, x);
420 minX = qMin(minX, x);
397 minY = qMin(minY, y);
421 minY = qMin(minY, y);
398 maxX = qMax(maxX, x);
422 maxX = qMax(maxX, x);
399 maxY = qMax(maxY, y);
423 maxY = qMax(maxY, y);
400 }
424 }
401
425
402 domain.setRange(minX,maxX,minY,maxY,tickXCount,tickYCount);
426 domain.setRange(minX,maxX,minY,maxY,tickXCount,tickYCount);
403 }
427 }
404
428
405 QList<LegendMarker*> QXYSeriesPrivate::createLegendMarker(QLegend* legend)
429 QList<LegendMarker*> QXYSeriesPrivate::createLegendMarker(QLegend* legend)
406 {
430 {
407 Q_Q(QXYSeries);
431 Q_Q(QXYSeries);
408 QList<LegendMarker*> list;
432 QList<LegendMarker*> list;
409 return list << new XYLegendMarker(q,legend);
433 return list << new XYLegendMarker(q,legend);
410 }
434 }
411
435
412 #include "moc_qxyseries.cpp"
436 #include "moc_qxyseries.cpp"
413 #include "moc_qxyseries_p.cpp"
437 #include "moc_qxyseries_p.cpp"
414
438
415 QTCOMMERCIALCHART_END_NAMESPACE
439 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,362 +1,409
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 "tst_qxyseries.h"
21 #include "tst_qxyseries.h"
22
22
23 Q_DECLARE_METATYPE(QList<QPointF>)
23 Q_DECLARE_METATYPE(QList<QPointF>)
24
24
25 void tst_QXYSeries::initTestCase()
25 void tst_QXYSeries::initTestCase()
26 {
26 {
27 }
27 }
28
28
29 void tst_QXYSeries::cleanupTestCase()
29 void tst_QXYSeries::cleanupTestCase()
30 {
30 {
31 }
31 }
32
32
33 void tst_QXYSeries::init()
33 void tst_QXYSeries::init()
34 {
34 {
35 m_view = new QChartView(new QChart());
35 m_view = new QChartView(new QChart());
36 m_chart = m_view->chart();
36 m_chart = m_view->chart();
37 }
37 }
38
38
39 void tst_QXYSeries::cleanup()
39 void tst_QXYSeries::cleanup()
40 {
40 {
41 delete m_view;
41 delete m_view;
42 m_view = 0;
42 m_view = 0;
43 m_chart = 0;
43 m_chart = 0;
44 m_series = 0;
44 m_series = 0;
45 }
45 }
46
46
47 void tst_QXYSeries::seriesName()
48 {
49 QSignalSpy nameSpy(m_series, SIGNAL(nameChanged()));
50 QCOMPARE(m_series->name(), QString());
51 m_series->setName("seriesname");
52 QCOMPARE(m_series->name(), QString("seriesname"));
53 TRY_COMPARE(nameSpy.count(), 1);
54 }
55
56 void tst_QXYSeries::seriesVisible()
57 {
58 QSignalSpy visibleSpy(m_series, SIGNAL(visibleChanged()));
59 QCOMPARE(m_series->isVisible(), true);
60 m_series->setVisible(false);
61 QCOMPARE(m_series->isVisible(), false);
62 m_series->setVisible(true);
63 TRY_COMPARE(visibleSpy.count(), 2);
64 }
65
47 void tst_QXYSeries::append_data()
66 void tst_QXYSeries::append_data()
48 {
67 {
49 QTest::addColumn< QList<QPointF> >("points");
68 QTest::addColumn< QList<QPointF> >("points");
50 QTest::newRow("0,0 1,1 2,2 3,3") << (QList<QPointF>() << QPointF(0,0) << QPointF(1,1) << QPointF(2,2) << QPointF(3,3));
69 QTest::newRow("0,0 1,1 2,2 3,3") << (QList<QPointF>() << QPointF(0,0) << QPointF(1,1) << QPointF(2,2) << QPointF(3,3));
51 QTest::newRow("0,0 -1,-1 -2,-2 -3,-3") << (QList<QPointF>() << QPointF(0,0) << QPointF(-1,-1) << QPointF(-2,-2) << QPointF(-3,-3));
70 QTest::newRow("0,0 -1,-1 -2,-2 -3,-3") << (QList<QPointF>() << QPointF(0,0) << QPointF(-1,-1) << QPointF(-2,-2) << QPointF(-3,-3));
52 }
71 }
53
72
54
73
55 void tst_QXYSeries::append_raw_data()
74 void tst_QXYSeries::append_raw_data()
56 {
75 {
57 append_data();
76 append_data();
58 }
77 }
59
78
60 void tst_QXYSeries::append_raw()
79 void tst_QXYSeries::append_raw()
61 {
80 {
62 QFETCH(QList<QPointF>, points);
81 QFETCH(QList<QPointF>, points);
63 QSignalSpy spy0(m_series, SIGNAL(clicked(QPointF const&)));
82 QSignalSpy spy0(m_series, SIGNAL(clicked(QPointF const&)));
83 QSignalSpy addedSpy(m_series, SIGNAL(pointAdded(int)));
64 m_series->append(points);
84 m_series->append(points);
65 TRY_COMPARE(spy0.count(), 0);
85 TRY_COMPARE(spy0.count(), 0);
86 TRY_COMPARE(addedSpy.count(), points.count());
66 QCOMPARE(m_series->points(), points);
87 QCOMPARE(m_series->points(), points);
67 }
88 }
68
89
69 void tst_QXYSeries::chart_append_data()
90 void tst_QXYSeries::chart_append_data()
70 {
91 {
71 append_data();
92 append_data();
72 }
93 }
73
94
74 void tst_QXYSeries::chart_append()
95 void tst_QXYSeries::chart_append()
75 {
96 {
76 append_raw();
97 append_raw();
77 m_chart->addSeries(m_series);
98 m_chart->addSeries(m_series);
78 m_view->show();
99 m_view->show();
79 QTest::qWaitForWindowShown(m_view);
100 QTest::qWaitForWindowShown(m_view);
80 }
101 }
81
102
82 void tst_QXYSeries::append_chart_data()
103 void tst_QXYSeries::append_chart_data()
83 {
104 {
84 append_data();
105 append_data();
85 }
106 }
86
107
87 void tst_QXYSeries::append_chart()
108 void tst_QXYSeries::append_chart()
88 {
109 {
89 m_view->show();
110 m_view->show();
90 m_chart->addSeries(m_series);
111 m_chart->addSeries(m_series);
91 QTest::qWaitForWindowShown(m_view);
112 QTest::qWaitForWindowShown(m_view);
92 append_raw();
113 append_raw();
93
114
94 }
115 }
95
116
96 void tst_QXYSeries::append_chart_animation_data()
117 void tst_QXYSeries::append_chart_animation_data()
97 {
118 {
98 append_data();
119 append_data();
99 }
120 }
100
121
101 void tst_QXYSeries::append_chart_animation()
122 void tst_QXYSeries::append_chart_animation()
102 {
123 {
103 m_chart->setAnimationOptions(QChart::AllAnimations);
124 m_chart->setAnimationOptions(QChart::AllAnimations);
104 append_chart();
125 append_chart();
105 }
126 }
106
127
107 void tst_QXYSeries::count_data()
128 void tst_QXYSeries::count_data()
108 {
129 {
109 QTest::addColumn<int>("count");
130 QTest::addColumn<int>("count");
110 QTest::newRow("0") << 0;
131 QTest::newRow("0") << 0;
111 QTest::newRow("5") << 5;
132 QTest::newRow("5") << 5;
112 QTest::newRow("10") << 5;
133 QTest::newRow("10") << 5;
113 }
134 }
114
135
115 void tst_QXYSeries::count_raw_data()
136 void tst_QXYSeries::count_raw_data()
116 {
137 {
117 count_data();
138 count_data();
118 }
139 }
119
140
120 void tst_QXYSeries::count_raw()
141 void tst_QXYSeries::count_raw()
121 {
142 {
122 QFETCH(int, count);
143 QFETCH(int, count);
123
144
124 QSignalSpy spy0(m_series, SIGNAL(clicked(QPointF const&)));
145 QSignalSpy spy0(m_series, SIGNAL(clicked(QPointF const&)));
125
146
126 for(int i=0 ; i< count; ++i)
147 for(int i=0 ; i< count; ++i)
127 m_series->append(i,i);
148 m_series->append(i,i);
128
149
129 TRY_COMPARE(spy0.count(), 0);
150 TRY_COMPARE(spy0.count(), 0);
130 QCOMPARE(m_series->count(), count);
151 QCOMPARE(m_series->count(), count);
131 }
152 }
132
153
133 void tst_QXYSeries::remove_raw_data()
154 void tst_QXYSeries::remove_raw_data()
134 {
155 {
135 append_data();
156 append_data();
136 }
157 }
137
158
138 void tst_QXYSeries::remove_raw()
159 void tst_QXYSeries::remove_raw()
139 {
160 {
140 QFETCH(QList<QPointF>, points);
161 QFETCH(QList<QPointF>, points);
141 QSignalSpy spy0(m_series, SIGNAL(clicked(QPointF const&)));
162 QSignalSpy spy0(m_series, SIGNAL(clicked(QPointF const&)));
142 m_series->append(points);
163 m_series->append(points);
143 TRY_COMPARE(spy0.count(), 0);
164 TRY_COMPARE(spy0.count(), 0);
144 QCOMPARE(m_series->points(), points);
165 QCOMPARE(m_series->points(), points);
145
166
146 foreach(const QPointF& point,points)
167 foreach(const QPointF& point,points)
147 m_series->remove(point);
168 m_series->remove(point);
148
169
149 QCOMPARE(m_series->points().count(), 0);
170 QCOMPARE(m_series->points().count(), 0);
150 TRY_COMPARE(spy0.count(), 0);
171 TRY_COMPARE(spy0.count(), 0);
151
172
152 m_series->append(points);
173 m_series->append(points);
153 QCOMPARE(m_series->points(), points);
174 QCOMPARE(m_series->points(), points);
154
175
155 //reverse order
176 //reverse order
156 for(int i = points.count()-1 ; i>=0; i--){
177 for(int i = points.count()-1 ; i>=0; i--){
157 m_series->remove(points[i]);
178 m_series->remove(points[i]);
158 }
179 }
159 QCOMPARE(m_series->points().count(), 0);
180 QCOMPARE(m_series->points().count(), 0);
160 }
181 }
161
182
162 void tst_QXYSeries::remove_chart_data()
183 void tst_QXYSeries::remove_chart_data()
163 {
184 {
164 append_data();
185 append_data();
165 }
186 }
166
187
167 void tst_QXYSeries::remove_chart()
188 void tst_QXYSeries::remove_chart()
168 {
189 {
169 m_view->show();
190 m_view->show();
170 m_chart->addSeries(m_series);
191 m_chart->addSeries(m_series);
171 QTest::qWaitForWindowShown(m_view);
192 QTest::qWaitForWindowShown(m_view);
172 remove_raw();
193 remove_raw();
173 }
194 }
174
195
175 void tst_QXYSeries::remove_chart_animation_data()
196 void tst_QXYSeries::remove_chart_animation_data()
176 {
197 {
177 append_data();
198 append_data();
178 }
199 }
179
200
180 void tst_QXYSeries::remove_chart_animation()
201 void tst_QXYSeries::remove_chart_animation()
181 {
202 {
182 m_chart->setAnimationOptions(QChart::AllAnimations);
203 m_chart->setAnimationOptions(QChart::AllAnimations);
183 remove_chart();
204 remove_chart();
184 }
205 }
185
206
186
207
187 void tst_QXYSeries::clear_raw_data()
208 void tst_QXYSeries::clear_raw_data()
188 {
209 {
189 append_data();
210 append_data();
190 }
211 }
191
212
192 void tst_QXYSeries::clear_raw()
213 void tst_QXYSeries::clear_raw()
193 {
214 {
194 QFETCH(QList<QPointF>, points);
215 QFETCH(QList<QPointF>, points);
195 QSignalSpy spy0(m_series, SIGNAL(clicked(QPointF const&)));
216 QSignalSpy spy0(m_series, SIGNAL(clicked(QPointF const&)));
196 m_series->append(points);
217 m_series->append(points);
197 TRY_COMPARE(spy0.count(), 0);
218 TRY_COMPARE(spy0.count(), 0);
198 QCOMPARE(m_series->points(), points);
219 QCOMPARE(m_series->points(), points);
199 m_series->clear();
220 m_series->clear();
200 TRY_COMPARE(spy0.count(), 0);
221 TRY_COMPARE(spy0.count(), 0);
201 QCOMPARE(m_series->points().count(), 0);
222 QCOMPARE(m_series->points().count(), 0);
202 }
223 }
203
224
204 void tst_QXYSeries::clear_chart_data()
225 void tst_QXYSeries::clear_chart_data()
205 {
226 {
206 append_data();
227 append_data();
207 }
228 }
208
229
209 void tst_QXYSeries::clear_chart()
230 void tst_QXYSeries::clear_chart()
210 {
231 {
211 m_view->show();
232 m_view->show();
212 m_chart->addSeries(m_series);
233 m_chart->addSeries(m_series);
213 QTest::qWaitForWindowShown(m_view);
234 QTest::qWaitForWindowShown(m_view);
214 clear_raw();
235 clear_raw();
215 }
236 }
216
237
217 void tst_QXYSeries::clear_chart_animation_data()
238 void tst_QXYSeries::clear_chart_animation_data()
218 {
239 {
219 append_data();
240 append_data();
220 }
241 }
221
242
222 void tst_QXYSeries::clear_chart_animation()
243 void tst_QXYSeries::clear_chart_animation()
223 {
244 {
224 m_chart->setAnimationOptions(QChart::AllAnimations);
245 m_chart->setAnimationOptions(QChart::AllAnimations);
225 clear_chart();
246 clear_chart();
226 }
247 }
227
248
228 void tst_QXYSeries::replace_raw_data()
249 void tst_QXYSeries::replace_raw_data()
229 {
250 {
230 append_data();
251 append_data();
231 }
252 }
232
253
233 void tst_QXYSeries::replace_raw()
254 void tst_QXYSeries::replace_raw()
234 {
255 {
235 QFETCH(QList<QPointF>, points);
256 QFETCH(QList<QPointF>, points);
236 QSignalSpy spy0(m_series, SIGNAL(clicked(QPointF const&)));
257 QSignalSpy replacedSpy(m_series, SIGNAL(pointReplaced(int)));
237 m_series->append(points);
258 m_series->append(points);
238 TRY_COMPARE(spy0.count(), 0);
259 TRY_COMPARE(replacedSpy.count(), 0);
239 QCOMPARE(m_series->points(), points);
260 QCOMPARE(m_series->points(), points);
240
261
241 foreach(const QPointF& point,points)
262 foreach(const QPointF& point, points)
242 m_series->replace(point.x(),point.y(),point.x(),0);
263 m_series->replace(point.x(),point.y(),point.x(),0);
264 TRY_COMPARE(replacedSpy.count(), points.count());
265
266 // Replace a point that does not exist
267 m_series->replace(-123, 999, 0, 0);
268 TRY_COMPARE(replacedSpy.count(), points.count());
243
269
244 QList<QPointF> newPoints = m_series->points();
270 QList<QPointF> newPoints = m_series->points();
245
271
246 QCOMPARE(newPoints.count(), points.count());
272 QCOMPARE(newPoints.count(), points.count());
247
273
248 for(int i =0 ; i<points.count() ; ++i) {
274 for(int i =0 ; i<points.count() ; ++i) {
249 QCOMPARE(points[i].x(), newPoints[i].x());
275 QCOMPARE(points[i].x(), newPoints[i].x());
250 QCOMPARE(newPoints[i].y(), 0.0);
276 QCOMPARE(newPoints[i].y(), 0.0);
251 }
277 }
252 }
278 }
253
279
254
280
255 void tst_QXYSeries::replace_chart_data()
281 void tst_QXYSeries::replace_chart_data()
256 {
282 {
257 append_data();
283 append_data();
258 }
284 }
259
285
260 void tst_QXYSeries::replace_chart()
286 void tst_QXYSeries::replace_chart()
261 {
287 {
262 m_view->show();
288 m_view->show();
263 m_chart->addSeries(m_series);
289 m_chart->addSeries(m_series);
264 QTest::qWaitForWindowShown(m_view);
290 QTest::qWaitForWindowShown(m_view);
265 replace_raw();
291 replace_raw();
266 }
292 }
267
293
268 void tst_QXYSeries::replace_chart_animation_data()
294 void tst_QXYSeries::replace_chart_animation_data()
269 {
295 {
270 append_data();
296 append_data();
271 }
297 }
272
298
273 void tst_QXYSeries::replace_chart_animation()
299 void tst_QXYSeries::replace_chart_animation()
274 {
300 {
275 m_chart->setAnimationOptions(QChart::AllAnimations);
301 m_chart->setAnimationOptions(QChart::AllAnimations);
276 replace_chart();
302 replace_chart();
277 }
303 }
278
304
305 void tst_QXYSeries::insert_data()
306 {
307 append_data();
308 }
309
310 void tst_QXYSeries::insert()
311 {
312 QFETCH(QList<QPointF>, points);
313 m_series->append(points);
314
315 QSignalSpy addedSpy(m_series, SIGNAL(pointAdded(int)));
316
317 m_series->insert(0, QPointF(5, 5));
318 TRY_COMPARE(addedSpy.count(), 1);
319 QCOMPARE(m_series->points().count(), points.count() + 1);
320
321 m_series->insert(m_series->count(), QPointF(6, 6));
322 TRY_COMPARE(addedSpy.count(), 2);
323 QCOMPARE(m_series->points().count(), points.count() + 2);
324 }
325
279 void tst_QXYSeries::oper_data()
326 void tst_QXYSeries::oper_data()
280 {
327 {
281 append_data();
328 append_data();
282 }
329 }
283
330
284 void tst_QXYSeries::oper()
331 void tst_QXYSeries::oper()
285 {
332 {
286 QFETCH(QList<QPointF>, points);
333 QFETCH(QList<QPointF>, points);
287
334
288 QSignalSpy spy0(m_series, SIGNAL(clicked(QPointF const&)));
335 QSignalSpy spy0(m_series, SIGNAL(clicked(QPointF const&)));
289
336
290 foreach(const QPointF& point,points)
337 foreach(const QPointF& point,points)
291 {
338 {
292 *m_series<<point;
339 *m_series<<point;
293 }
340 }
294
341
295 QCOMPARE(m_series->points(), points);
342 QCOMPARE(m_series->points(), points);
296 TRY_COMPARE(spy0.count(), 0);
343 TRY_COMPARE(spy0.count(), 0);
297 }
344 }
298
345
299
346
300 void tst_QXYSeries::pen_data()
347 void tst_QXYSeries::pen_data()
301 {
348 {
302 QTest::addColumn<QPen>("pen");
349 QTest::addColumn<QPen>("pen");
303 QTest::newRow("null") << QPen();
350 QTest::newRow("null") << QPen();
304 QTest::newRow("blue") << QPen(Qt::blue);
351 QTest::newRow("blue") << QPen(Qt::blue);
305 QTest::newRow("black") << QPen(Qt::black);
352 QTest::newRow("black") << QPen(Qt::black);
306 QTest::newRow("red") << QPen(Qt::red);
353 QTest::newRow("red") << QPen(Qt::red);
307 }
354 }
308
355
309 void tst_QXYSeries::pen()
356 void tst_QXYSeries::pen()
310 {
357 {
311 QFETCH(QPen, pen);
358 QFETCH(QPen, pen);
312
359
313 QSignalSpy spy0(m_series, SIGNAL(clicked(QPointF const&)));
360 QSignalSpy spy0(m_series, SIGNAL(clicked(QPointF const&)));
314 m_series->setPen(pen);
361 m_series->setPen(pen);
315
362
316 TRY_COMPARE(spy0.count(), 0);
363 TRY_COMPARE(spy0.count(), 0);
317 QCOMPARE(m_series->pen(), pen);
364 QCOMPARE(m_series->pen(), pen);
318
365
319 m_chart->addSeries(m_series);
366 m_chart->addSeries(m_series);
320
367
321 if (pen != QPen())
368 if (pen != QPen())
322 QCOMPARE(m_series->pen(), pen);
369 QCOMPARE(m_series->pen(), pen);
323
370
324 m_chart->setTheme(QChart::ChartThemeDark);
371 m_chart->setTheme(QChart::ChartThemeDark);
325
372
326 // setting a theme will overwrite all customizations
373 // setting a theme will overwrite all customizations
327 if (pen != QPen())
374 if (pen != QPen())
328 QVERIFY(m_series->pen() != pen);
375 QVERIFY(m_series->pen() != pen);
329 }
376 }
330
377
331 void tst_QXYSeries::pointsVisible_data()
378 void tst_QXYSeries::pointsVisible_data()
332 {
379 {
333 QTest::addColumn<bool>("pointsVisible");
380 QTest::addColumn<bool>("pointsVisible");
334 QTest::newRow("true") << true;
381 QTest::newRow("true") << true;
335 QTest::newRow("false") << false;
382 QTest::newRow("false") << false;
336 }
383 }
337
384
338 void tst_QXYSeries::pointsVisible_raw_data()
385 void tst_QXYSeries::pointsVisible_raw_data()
339 {
386 {
340 pointsVisible_data();
387 pointsVisible_data();
341 }
388 }
342
389
343 void tst_QXYSeries::pointsVisible_raw()
390 void tst_QXYSeries::pointsVisible_raw()
344 {
391 {
345 QFETCH(bool, pointsVisible);
392 QFETCH(bool, pointsVisible);
346 QSignalSpy spy0(m_series, SIGNAL(clicked(QPointF const&)));
393 QSignalSpy spy0(m_series, SIGNAL(clicked(QPointF const&)));
347 m_series->setPointsVisible(pointsVisible);
394 m_series->setPointsVisible(pointsVisible);
348 TRY_COMPARE(spy0.count(), 0);
395 TRY_COMPARE(spy0.count(), 0);
349 QCOMPARE(m_series->pointsVisible(), pointsVisible);
396 QCOMPARE(m_series->pointsVisible(), pointsVisible);
350 }
397 }
351
398
352 void tst_QXYSeries::changedSignals()
399 void tst_QXYSeries::changedSignals()
353 {
400 {
354 QSignalSpy visibleSpy(m_series, SIGNAL(visibleChanged()));
401 QSignalSpy visibleSpy(m_series, SIGNAL(visibleChanged()));
355
402
356 m_series->setVisible(false);
403 m_series->setVisible(false);
357 m_series->setVisible(false);
404 m_series->setVisible(false);
358 TRY_COMPARE(visibleSpy.count(), 1);
405 TRY_COMPARE(visibleSpy.count(), 1);
359 m_series->setVisible(true);
406 m_series->setVisible(true);
360 TRY_COMPARE(visibleSpy.count(), 2);
407 TRY_COMPARE(visibleSpy.count(), 2);
361 }
408 }
362
409
@@ -1,89 +1,93
1 /****************************************************************************
1 /****************************************************************************
2 **
2 **
3 ** Copyright (C) 2012 Digia Plc
3 ** Copyright (C) 2012 Digia Plc
4 ** All rights reserved.
4 ** All rights reserved.
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 **
6 **
7 ** This file is part of the Qt Commercial Charts Add-on.
7 ** This file is part of the Qt Commercial Charts Add-on.
8 **
8 **
9 ** $QT_BEGIN_LICENSE$
9 ** $QT_BEGIN_LICENSE$
10 ** Licensees holding valid Qt Commercial licenses may use this file in
10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 ** accordance with the Qt Commercial License Agreement provided with the
11 ** accordance with the Qt Commercial License Agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia.
13 ** a written agreement between you and Digia.
14 **
14 **
15 ** If you have questions regarding the use of this file, please use
15 ** If you have questions regarding the use of this file, please use
16 ** contact form at http://qt.digia.com
16 ** contact form at http://qt.digia.com
17 ** $QT_END_LICENSE$
17 ** $QT_END_LICENSE$
18 **
18 **
19 ****************************************************************************/
19 ****************************************************************************/
20
20
21 #ifndef TST_QXYSERIES_H
21 #ifndef TST_QXYSERIES_H
22 #define TST_QXYSERIES_H
22 #define TST_QXYSERIES_H
23
23
24 #include <QtTest/QtTest>
24 #include <QtTest/QtTest>
25 #include <qxyseries.h>
25 #include <qxyseries.h>
26 #include <qchartview.h>
26 #include <qchartview.h>
27 #include <QStandardItemModel>
27 #include <QStandardItemModel>
28 #include <tst_definitions.h>
28 #include <tst_definitions.h>
29
29
30 QTCOMMERCIALCHART_USE_NAMESPACE
30 QTCOMMERCIALCHART_USE_NAMESPACE
31
31
32 class tst_QXYSeries : public QObject
32 class tst_QXYSeries : public QObject
33 {
33 {
34 Q_OBJECT
34 Q_OBJECT
35
35
36 public slots:
36 public slots:
37 virtual void initTestCase();
37 virtual void initTestCase();
38 virtual void cleanupTestCase();
38 virtual void cleanupTestCase();
39 virtual void init();
39 virtual void init();
40 virtual void cleanup();
40 virtual void cleanup();
41
41
42 private slots:
42 private slots:
43 void seriesName();
44 void seriesVisible();
43 void oper_data();
45 void oper_data();
44 void oper();
46 void oper();
45 void pen_data();
47 void pen_data();
46 void pen();
48 void pen();
47 void pointsVisible_raw_data();
49 void pointsVisible_raw_data();
48 void pointsVisible_raw();
50 void pointsVisible_raw();
49 void append_raw_data();
51 void append_raw_data();
50 void append_raw();
52 void append_raw();
51 void append_chart_data();
53 void append_chart_data();
52 void append_chart();
54 void append_chart();
53 void append_chart_animation_data();
55 void append_chart_animation_data();
54 void append_chart_animation();
56 void append_chart_animation();
55 void chart_append_data();
57 void chart_append_data();
56 void chart_append();
58 void chart_append();
57 void count_raw_data();
59 void count_raw_data();
58 void count_raw();
60 void count_raw();
59 void remove_raw_data();
61 void remove_raw_data();
60 void remove_raw();
62 void remove_raw();
61 void remove_chart_data();
63 void remove_chart_data();
62 void remove_chart();
64 void remove_chart();
63 void remove_chart_animation_data();
65 void remove_chart_animation_data();
64 void remove_chart_animation();
66 void remove_chart_animation();
65 void clear_raw_data();
67 void clear_raw_data();
66 void clear_raw();
68 void clear_raw();
67 void clear_chart_data();
69 void clear_chart_data();
68 void clear_chart();
70 void clear_chart();
69 void clear_chart_animation_data();
71 void clear_chart_animation_data();
70 void clear_chart_animation();
72 void clear_chart_animation();
71 void replace_raw_data();
73 void replace_raw_data();
72 void replace_raw();
74 void replace_raw();
73 void replace_chart_data();
75 void replace_chart_data();
74 void replace_chart();
76 void replace_chart();
75 void replace_chart_animation_data();
77 void replace_chart_animation_data();
76 void replace_chart_animation();
78 void replace_chart_animation();
79 void insert_data();
80 void insert();
77 void changedSignals();
81 void changedSignals();
78 protected:
82 protected:
79 void append_data();
83 void append_data();
80 void count_data();
84 void count_data();
81 void pointsVisible_data();
85 void pointsVisible_data();
82
86
83 protected:
87 protected:
84 QChartView* m_view;
88 QChartView* m_view;
85 QChart* m_chart;
89 QChart* m_chart;
86 QXYSeries* m_series;
90 QXYSeries* m_series;
87 };
91 };
88
92
89 #endif
93 #endif
@@ -1,66 +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
24
25 Flow {
25 Flow {
26 id: flow
26 id: flow
27 spacing: 5
27 spacing: 5
28 flow: Flow.TopToBottom
28 flow: Flow.TopToBottom
29 property variant series
29 property variant series
30
30
31 Button {
31 Button {
32 text: "visible"
32 text: "visible"
33 onClicked: series.visible = !series.visible;
33 onClicked: series.visible = !series.visible;
34 }
34 }
35 Button {
35 Button {
36 text: "color"
36 text: "color"
37 onClicked: series.color = main.nextColor();
37 onClicked: series.color = main.nextColor();
38 }
38 }
39 Button {
39 Button {
40 text: "points visible"
40 text: "points visible"
41 onClicked: series.pointsVisible = !series.pointsVisible;
41 onClicked: series.pointsVisible = !series.pointsVisible;
42 }
42 }
43 Button {
43 Button {
44 text: "append point"
44 text: "append point"
45 onClicked: series.append(series.count - 1, series.count - 1);
45 onClicked: series.append(series.count - 1, series.count - 1);
46 }
46 }
47 Button {
47 Button {
48 text: "replace point"
48 text: "replace point"
49 onClicked: {
49 onClicked: {
50 var xyPoint = series.at(series.count - 1);
50 var xyPoint = series.at(series.count - 1);
51 series.replace(xyPoint.x, xyPoint.y, xyPoint.x, xyPoint.y + 0.1);
51 series.replace(xyPoint.x, xyPoint.y, xyPoint.x, xyPoint.y + 0.1);
52 }
52 }
53 }
53 }
54 Button {
54 Button {
55 text: "remove point"
55 text: "remove point"
56 onClicked: series.remove(series.at(series.count - 1).x, series.at(series.count - 1).y);
56 onClicked: series.remove(series.at(series.count - 1).x, series.at(series.count - 1).y);
57 }
57 }
58 Button {
58 Button {
59 text: "insert point"
59 text: "insert point"
60 onClicked: series.insert(0, series.count - 1, series.count - 1);
60 onClicked: series.insert(series.count - 2, series.count - 2, series.count - 2);
61 }
61 }
62 Button {
62 Button {
63 text: "clear"
63 text: "clear"
64 onClicked: series.clear();
64 onClicked: series.clear();
65 }
65 }
66 }
66 }
@@ -1,78 +1,78
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
24
25 Flow {
25 Flow {
26 id: flow
26 id: flow
27 spacing: 5
27 spacing: 5
28 flow: Flow.TopToBottom
28 flow: Flow.TopToBottom
29 property variant series
29 property variant series
30
30
31 Button {
31 Button {
32 text: "visible"
32 text: "visible"
33 onClicked: series.visible = !series.visible;
33 onClicked: series.visible = !series.visible;
34 }
34 }
35 Button {
35 Button {
36 text: "color"
36 text: "color"
37 onClicked: series.color = main.nextColor();
37 onClicked: series.color = main.nextColor();
38 }
38 }
39 Button {
39 Button {
40 text: "borderColor"
40 text: "borderColor"
41 onClicked: series.borderColor = main.nextColor();
41 onClicked: series.borderColor = main.nextColor();
42 }
42 }
43 Button {
43 Button {
44 text: "markerSize +"
44 text: "markerSize +"
45 onClicked: series.markerSize += 1.0;
45 onClicked: series.markerSize += 1.0;
46 }
46 }
47 Button {
47 Button {
48 text: "markerSize -"
48 text: "markerSize -"
49 onClicked: series.markerSize -= 1.0;
49 onClicked: series.markerSize -= 1.0;
50 }
50 }
51 Button {
51 Button {
52 text: "markerShape"
52 text: "markerShape"
53 onClicked: series.markerShape = ((series.markerShape + 1) % 2);
53 onClicked: series.markerShape = ((series.markerShape + 1) % 2);
54 }
54 }
55 Button {
55 Button {
56 text: "append point"
56 text: "append point"
57 onClicked: series.append(series.count - 1, series.count - 1);
57 onClicked: series.append(series.count - 1, series.count - 1);
58 }
58 }
59 Button {
59 Button {
60 text: "replace point"
60 text: "replace point"
61 onClicked: {
61 onClicked: {
62 var xyPoint = series.at(series.count - 1);
62 var xyPoint = series.at(series.count - 1);
63 series.replace(xyPoint.x, xyPoint.y, xyPoint.x, xyPoint.y + 0.1);
63 series.replace(xyPoint.x, xyPoint.y, xyPoint.x, xyPoint.y + 0.1);
64 }
64 }
65 }
65 }
66 Button {
66 Button {
67 text: "remove point"
67 text: "remove point"
68 onClicked: series.remove(series.at(series.count - 1).x, series.at(series.count - 1).y);
68 onClicked: series.remove(series.at(series.count - 1).x, series.at(series.count - 1).y);
69 }
69 }
70 Button {
70 Button {
71 text: "insert point"
71 text: "insert point"
72 onClicked: series.insert(0, series.count - 1, series.count - 1);
72 onClicked: series.insert(series.count - 2, series.count - 2, series.count - 2);
73 }
73 }
74 Button {
74 Button {
75 text: "clear"
75 text: "clear"
76 onClicked: series.clear();
76 onClicked: series.clear();
77 }
77 }
78 }
78 }
General Comments 0
You need to be logged in to leave comments. Login now