##// END OF EJS Templates
Began documenting the QML api
Tero Ahola -
r1443:08af46f754b9
parent child
Show More
@@ -0,0 +1,14
1 /*!
2 \page qml.html
3 \title QtCommercial Charts QML API
4 \keyword Charts QML API
5
6 Charts QML API is an intuitive and simple way to use QtCommercial Charts in your QML applications.
7
8 \raw HTML
9 <ul>
10 <li><a href="qml-chartview.html">ChartView</a></li>
11 <li><a href="qml-pieseries.html">PieSeries</a></li>
12 </ul>
13 \endraw
14 */
@@ -1,58 +1,59
1 include(qchart-html.qdocconf)
1 include(qchart-html.qdocconf)
2
2
3 HTML.postheader = \
3 HTML.postheader = \
4 "<div class=\"header\" id=\"qtdocheader\">\n" \
4 "<div class=\"header\" id=\"qtdocheader\">\n" \
5 " <div class=\"content\"> \n" \
5 " <div class=\"content\"> \n" \
6 " <img src=\"images/qcharts.png\" alt=\"qcharts\"/>\n" \
6 " <img src=\"images/qcharts.png\" alt=\"qcharts\"/>\n" \
7 " <p class=\"qtref\"> \n" \
7 " <p class=\"qtref\"> \n" \
8 " <span>Reference Documentation</span>\n" \
8 " <span>Reference Documentation</span>\n" \
9 " </p>\n" \
9 " </p>\n" \
10 " </div>\n" \
10 " </div>\n" \
11 " <div class=\"breadcrumb toolblock\">\n" \
11 " <div class=\"breadcrumb toolblock\">\n" \
12 " <ul>\n" \
12 " <ul>\n" \
13 " <li class=\"first\"><a href=\"index.html\">About</a></li>\n" \
13 " <li class=\"first\"><a href=\"index.html\">About</a></li>\n" \
14 " <li><a href=\"introduction.html\">Getting started</a></li>\n" \
14 " <li><a href=\"introduction.html\">Getting started</a></li>\n" \
15 " <li><a href=\"classes.html\">API Classes</a></li>\n" \
15 " <li><a href=\"classes.html\">API Classes</a></li>\n" \
16 " <li><a href=\"qml.html\">QML API</a></li>\n" \
16 " <li><a href=\"examples.html\">Examples</a></li>\n" \
17 " <li><a href=\"examples.html\">Examples</a></li>\n" \
17 " <li><a href=\"demos.html\">Demos</a></li>\n" \
18 " <li><a href=\"demos.html\">Demos</a></li>\n" \
18 " <!-- Breadcrumbs go here -->\n"
19 " <!-- Breadcrumbs go here -->\n"
19
20
20 HTML.postpostheader = \
21 HTML.postpostheader = \
21 " </ul>\n" \
22 " </ul>\n" \
22 " </div>\n" \
23 " </div>\n" \
23 "</div>\n" \
24 "</div>\n" \
24 "<div class=\"content mainContent\">\n"
25 "<div class=\"content mainContent\">\n"
25
26
26 HTML.footer = \
27 HTML.footer = \
27 " <div class=\"ft\">\n" \
28 " <div class=\"ft\">\n" \
28 " <span></span>\n" \
29 " <span></span>\n" \
29 " </div>\n" \
30 " </div>\n" \
30 "</div> \n" \
31 "</div> \n" \
31 "<div class=\"footer\">\n" \
32 "<div class=\"footer\">\n" \
32 " <p>\n" \
33 " <p>\n" \
33 " <acronym title=\"Copyright\">&copy;</acronym> 2012 Digia ." \
34 " <acronym title=\"Copyright\">&copy;</acronym> 2012 Digia ." \
34 " Qt and Qt logos are trademarks of of Nokia Corporation \n" \
35 " Qt and Qt logos are trademarks of of Nokia Corporation \n" \
35 " in Finland and/or other countries worldwide.</p>\n" \
36 " in Finland and/or other countries worldwide.</p>\n" \
36 " <p>\n" \
37 " <p>\n" \
37 " All other trademarks are property of their respective owners.</p>\n" \
38 " All other trademarks are property of their respective owners.</p>\n" \
38 " <br />\n" \
39 " <br />\n" \
39 " <p>\n" \
40 " <p>\n" \
40 " Licensees holding valid Qt Commercial licenses may use this document in accordance with the" \
41 " Licensees holding valid Qt Commercial licenses may use this document in accordance with the" \
41 " Qt Commercial License Agreement provided with the Software or, alternatively, in accordance" \
42 " Qt Commercial License Agreement provided with the Software or, alternatively, in accordance" \
42 " with the terms contained in a written agreement between you and Digia.</p>\n" \
43 " with the terms contained in a written agreement between you and Digia.</p>\n" \
43 " <p>\n" \
44 " <p>\n" \
44 " <img src=\"images/digia_logo.png\" alt=\"digia\" /></p>\n" \
45 " <img src=\"images/digia_logo.png\" alt=\"digia\" /></p>\n" \
45 "</div>\n" \
46 "</div>\n" \
46
47
47 # Files not referenced in any qdoc file.
48 # Files not referenced in any qdoc file.
48 # See also extraimages.HTML
49 # See also extraimages.HTML
49 qhp.QDoc.extraFiles = index.html \
50 qhp.QDoc.extraFiles = index.html \
50 images/arrow_down.png \
51 images/arrow_down.png \
51 images/breadcrumb.png \
52 images/breadcrumb.png \
52 images/bullet_gt.png \
53 images/bullet_gt.png \
53 images/bullet_dn.png \
54 images/bullet_dn.png \
54 images/bullet_sq.png \
55 images/bullet_sq.png \
55 images/bullet_up.png \
56 images/bullet_up.png \
56 images/horBar.png \
57 images/horBar.png \
57 images/qcharts.png \
58 images/qcharts.png \
58 style/offline.css
59 style/offline.css
@@ -1,46 +1,48
1 include(compat.qdocconf)
1 include(compat.qdocconf)
2 include(macros.qdocconf)
2 include(macros.qdocconf)
3 include(qchart-html-template.qdocconf)
3 include(qchart-html-template.qdocconf)
4
4
5 project = QtCommercialCharts
5 project = QtCommercialCharts
6 description = Library for creating charts
6 description = Library for creating charts
7
7
8 sourcedirs = ../src \
8 sourcedirs = ../src \
9 ../examples \
9 ../examples \
10 ./src
10 ./src \
11 ../plugins/declarative
11 headerdirs = ../src \
12 headerdirs = ../src \
12 ../examples
13 ../examples \
14 ../plugins/declarative
13 exampledirs = ../ \
15 exampledirs = ../ \
14 ../src \
16 ../src \
15 ../examples
17 ../examples
16
18
17 excludefiles += ../examples/linechart/linechart.pro
19 excludefiles += ../examples/linechart/linechart.pro
18
20
19 sources.fileextensions = *.cpp *.qdoc *.mm *.qml
21 sources.fileextensions = *.cpp *.qdoc *.mm *.qml
20 headers.fileextensions = *.h *.ch *.h++ *.hh *.hpp *.hxx
22 headers.fileextensions = *.h *.ch *.h++ *.hh *.hpp *.hxx
21 examples.fileextensions = *.cpp *.h *.js *.xq *.svg *.xml *.ui *.qhp *.qhcp *.qml
23 examples.fileextensions = *.cpp *.h *.js *.xq *.svg *.xml *.ui *.qhp *.qhcp *.qml
22 examples.imageextensions = *.png *.jpeg *.jpg *.gif *.mng
24 examples.imageextensions = *.png *.jpeg *.jpg *.gif *.mng
23
25
24 imagedirs = ./images
26 imagedirs = ./images
25 outputdir = ./html
27 outputdir = ./html
26
28
27
29
28 Cpp.ignoretokens = QTCOMMERCIALCHART_EXPORT \
30 Cpp.ignoretokens = QTCOMMERCIALCHART_EXPORT \
29 QTCOMMERCIALCHART_END_NAMESPACE \
31 QTCOMMERCIALCHART_END_NAMESPACE \
30 QTCOMMERCIALCHART_BEGIN_NAMESPACE
32 QTCOMMERCIALCHART_BEGIN_NAMESPACE
31 Cpp.ignoredirectives = Q_DECLARE_HANDLE \
33 Cpp.ignoredirectives = Q_DECLARE_HANDLE \
32 Q_DECLARE_INTERFACE \
34 Q_DECLARE_INTERFACE \
33 Q_DECLARE_METATYPE \
35 Q_DECLARE_METATYPE \
34 Q_DECLARE_OPERATORS_FOR_FLAGS \
36 Q_DECLARE_OPERATORS_FOR_FLAGS \
35 Q_DECLARE_PRIVATE \
37 Q_DECLARE_PRIVATE \
36 Q_DECLARE_PUBLIC \
38 Q_DECLARE_PUBLIC \
37 Q_DECLARE_SHARED \
39 Q_DECLARE_SHARED \
38 Q_DECLARE_TR_FUNCTIONS \
40 Q_DECLARE_TR_FUNCTIONS \
39 Q_DECLARE_TYPEINFO \
41 Q_DECLARE_TYPEINFO \
40 Q_DISABLE_COPY \
42 Q_DISABLE_COPY \
41 QT_FORWARD_DECLARE_CLASS \
43 QT_FORWARD_DECLARE_CLASS \
42 Q_DUMMY_COMPARISON_OPERATOR \
44 Q_DUMMY_COMPARISON_OPERATOR \
43 Q_ENUMS \
45 Q_ENUMS \
44 Q_FLAGS \
46 Q_FLAGS \
45 Q_INTERFACES \
47 Q_INTERFACES \
46 __attribute__ No newline at end of file
48 __attribute__
@@ -1,268 +1,281
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 /*!
33 \qmlclass ChartView DeclarativeChart
34
35 ChartView element is the parent that is responsible for showing different chart series types.
36
37 \section1 Example Usage
38
39 \beginfloatleft
40 \image demos_qmlchart1.png
41 \endfloat
42 \clearfloat
43 */
44
32 DeclarativeChart::DeclarativeChart(QDeclarativeItem *parent)
45 DeclarativeChart::DeclarativeChart(QDeclarativeItem *parent)
33 : QDeclarativeItem(parent),
46 : QDeclarativeItem(parent),
34 m_chart(new QChart(this))
47 m_chart(new QChart(this))
35 {
48 {
36 setFlag(QGraphicsItem::ItemHasNoContents, false);
49 setFlag(QGraphicsItem::ItemHasNoContents, false);
37 // m_chart->axisX()->setNiceNumbersEnabled(false);
50 // m_chart->axisX()->setNiceNumbersEnabled(false);
38 }
51 }
39
52
40 DeclarativeChart::~DeclarativeChart()
53 DeclarativeChart::~DeclarativeChart()
41 {
54 {
42 delete m_chart;
55 delete m_chart;
43 }
56 }
44
57
45 void DeclarativeChart::childEvent(QChildEvent *event)
58 void DeclarativeChart::childEvent(QChildEvent *event)
46 {
59 {
47 if (event->type() == QEvent::ChildAdded) {
60 if (event->type() == QEvent::ChildAdded) {
48 if (qobject_cast<QAbstractSeries *>(event->child())) {
61 if (qobject_cast<QAbstractSeries *>(event->child())) {
49 m_chart->addSeries(qobject_cast<QAbstractSeries *>(event->child()));
62 m_chart->addSeries(qobject_cast<QAbstractSeries *>(event->child()));
50 }
63 }
51 }
64 }
52 }
65 }
53
66
54 void DeclarativeChart::componentComplete()
67 void DeclarativeChart::componentComplete()
55 {
68 {
56 // qDebug() << "DeclarativeChart::componentComplete(), maxX: " << axisX()->max();
69 // qDebug() << "DeclarativeChart::componentComplete(), maxX: " << axisX()->max();
57 foreach(QObject *child, children()) {
70 foreach(QObject *child, children()) {
58 if (qobject_cast<QAbstractSeries *>(child)) {
71 if (qobject_cast<QAbstractSeries *>(child)) {
59 // qDebug() << "DeclarativeChart::componentComplete(), add: " << child;
72 // qDebug() << "DeclarativeChart::componentComplete(), add: " << child;
60 m_chart->addSeries(qobject_cast<QAbstractSeries *>(child));
73 m_chart->addSeries(qobject_cast<QAbstractSeries *>(child));
61 }
74 }
62 }
75 }
63 // qDebug() << "DeclarativeChart::componentComplete(), maxX: " << axisX()->max();
76 // qDebug() << "DeclarativeChart::componentComplete(), maxX: " << axisX()->max();
64
77
65 QDeclarativeItem::componentComplete();
78 QDeclarativeItem::componentComplete();
66 }
79 }
67
80
68 void DeclarativeChart::geometryChanged(const QRectF &newGeometry, const QRectF &oldGeometry)
81 void DeclarativeChart::geometryChanged(const QRectF &newGeometry, const QRectF &oldGeometry)
69 {
82 {
70 // qDebug() << "DeclarativeChart::geometryChanged" << newGeometry.width() << newGeometry.height();
83 // qDebug() << "DeclarativeChart::geometryChanged" << newGeometry.width() << newGeometry.height();
71 if (newGeometry.isValid()) {
84 if (newGeometry.isValid()) {
72 if (newGeometry.width() > 0 && newGeometry.height() > 0) {
85 if (newGeometry.width() > 0 && newGeometry.height() > 0) {
73 m_chart->resize(newGeometry.width(), newGeometry.height());
86 m_chart->resize(newGeometry.width(), newGeometry.height());
74 }
87 }
75 }
88 }
76 QDeclarativeItem::geometryChanged(newGeometry, oldGeometry);
89 QDeclarativeItem::geometryChanged(newGeometry, oldGeometry);
77 }
90 }
78
91
79 void DeclarativeChart::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
92 void DeclarativeChart::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
80 {
93 {
81 Q_UNUSED(option)
94 Q_UNUSED(option)
82 Q_UNUSED(widget)
95 Q_UNUSED(widget)
83
96
84 // TODO: optimized?
97 // TODO: optimized?
85 painter->setRenderHint(QPainter::Antialiasing, true);
98 painter->setRenderHint(QPainter::Antialiasing, true);
86 }
99 }
87
100
88 void DeclarativeChart::setTheme(DeclarativeChart::Theme theme)
101 void DeclarativeChart::setTheme(DeclarativeChart::Theme theme)
89 {
102 {
90 QChart::ChartTheme chartTheme = (QChart::ChartTheme) theme;
103 QChart::ChartTheme chartTheme = (QChart::ChartTheme) theme;
91 if (chartTheme != m_chart->theme()) {
104 if (chartTheme != m_chart->theme()) {
92 m_chart->setTheme(chartTheme);
105 m_chart->setTheme(chartTheme);
93 themeChanged();
106 themeChanged();
94 }
107 }
95 }
108 }
96
109
97 DeclarativeChart::Theme DeclarativeChart::theme()
110 DeclarativeChart::Theme DeclarativeChart::theme()
98 {
111 {
99 return (DeclarativeChart::Theme) m_chart->theme();
112 return (DeclarativeChart::Theme) m_chart->theme();
100 }
113 }
101
114
102 void DeclarativeChart::setAnimationOptions(DeclarativeChart::Animation animations)
115 void DeclarativeChart::setAnimationOptions(DeclarativeChart::Animation animations)
103 {
116 {
104 QChart::AnimationOption animationOptions = (QChart::AnimationOption) animations;
117 QChart::AnimationOption animationOptions = (QChart::AnimationOption) animations;
105 if (animationOptions != m_chart->animationOptions()) {
118 if (animationOptions != m_chart->animationOptions()) {
106 m_chart->setAnimationOptions(animationOptions);
119 m_chart->setAnimationOptions(animationOptions);
107 animationOptionsChanged();
120 animationOptionsChanged();
108 }
121 }
109 }
122 }
110
123
111 DeclarativeChart::Animation DeclarativeChart::animationOptions()
124 DeclarativeChart::Animation DeclarativeChart::animationOptions()
112 {
125 {
113 if (m_chart->animationOptions().testFlag(QChart::AllAnimations))
126 if (m_chart->animationOptions().testFlag(QChart::AllAnimations))
114 return DeclarativeChart::AllAnimations;
127 return DeclarativeChart::AllAnimations;
115 else if (m_chart->animationOptions().testFlag(QChart::GridAxisAnimations))
128 else if (m_chart->animationOptions().testFlag(QChart::GridAxisAnimations))
116 return DeclarativeChart::GridAxisAnimations;
129 return DeclarativeChart::GridAxisAnimations;
117 else if (m_chart->animationOptions().testFlag(QChart::SeriesAnimations))
130 else if (m_chart->animationOptions().testFlag(QChart::SeriesAnimations))
118 return DeclarativeChart::SeriesAnimations;
131 return DeclarativeChart::SeriesAnimations;
119 else
132 else
120 return DeclarativeChart::NoAnimation;
133 return DeclarativeChart::NoAnimation;
121 }
134 }
122
135
123 void DeclarativeChart::setTitle(QString title)
136 void DeclarativeChart::setTitle(QString title)
124 {
137 {
125 if (title != m_chart->title()) {
138 if (title != m_chart->title()) {
126 m_chart->setTitle(title);
139 m_chart->setTitle(title);
127 emit titleChanged();
140 emit titleChanged();
128 }
141 }
129 }
142 }
130 QString DeclarativeChart::title()
143 QString DeclarativeChart::title()
131 {
144 {
132 return m_chart->title();
145 return m_chart->title();
133 }
146 }
134
147
135 QAxis *DeclarativeChart::axisX()
148 QAxis *DeclarativeChart::axisX()
136 {
149 {
137 return m_chart->axisX();
150 return m_chart->axisX();
138 }
151 }
139
152
140 QAxis *DeclarativeChart::axisY()
153 QAxis *DeclarativeChart::axisY()
141 {
154 {
142 return m_chart->axisY();
155 return m_chart->axisY();
143 }
156 }
144
157
145 QLegend *DeclarativeChart::legend()
158 QLegend *DeclarativeChart::legend()
146 {
159 {
147 return m_chart->legend();
160 return m_chart->legend();
148 }
161 }
149
162
150 QVariantList DeclarativeChart::axisXLabels()
163 QVariantList DeclarativeChart::axisXLabels()
151 {
164 {
152 QVariantList labels;
165 QVariantList labels;
153 foreach (qreal value, m_chart->axisX()->categories()->values()) {
166 foreach (qreal value, m_chart->axisX()->categories()->values()) {
154 labels.append(value);
167 labels.append(value);
155 labels.append(m_chart->axisX()->categories()->label(value));
168 labels.append(m_chart->axisX()->categories()->label(value));
156 }
169 }
157 return labels;
170 return labels;
158 }
171 }
159
172
160 void DeclarativeChart::setAxisXLabels(QVariantList list)
173 void DeclarativeChart::setAxisXLabels(QVariantList list)
161 {
174 {
162 QVariant value(QVariant::Invalid);
175 QVariant value(QVariant::Invalid);
163 foreach (QVariant element, list) {
176 foreach (QVariant element, list) {
164 if (value.isValid() && element.type() == QVariant::String) {
177 if (value.isValid() && element.type() == QVariant::String) {
165 m_chart->axisX()->categories()->insert(value.toDouble(), element.toString());
178 m_chart->axisX()->categories()->insert(value.toDouble(), element.toString());
166 value = QVariant(QVariant::Invalid);
179 value = QVariant(QVariant::Invalid);
167 } else {
180 } else {
168 if (element.canConvert(QVariant::Double))
181 if (element.canConvert(QVariant::Double))
169 value = element;
182 value = element;
170 }
183 }
171 }
184 }
172 emit axisLabelsChanged();
185 emit axisLabelsChanged();
173 }
186 }
174
187
175 void DeclarativeChart::setTitleColor(QColor color)
188 void DeclarativeChart::setTitleColor(QColor color)
176 {
189 {
177 QBrush b = m_chart->titleBrush();
190 QBrush b = m_chart->titleBrush();
178 if (color != b.color()) {
191 if (color != b.color()) {
179 b.setColor(color);
192 b.setColor(color);
180 m_chart->setTitleBrush(b);
193 m_chart->setTitleBrush(b);
181 emit titleColorChanged();
194 emit titleColorChanged();
182 }
195 }
183 }
196 }
184
197
185 QColor DeclarativeChart::titleColor()
198 QColor DeclarativeChart::titleColor()
186 {
199 {
187 return m_chart->titleBrush().color();
200 return m_chart->titleBrush().color();
188 }
201 }
189
202
190 void DeclarativeChart::setBackgroundColor(QColor color)
203 void DeclarativeChart::setBackgroundColor(QColor color)
191 {
204 {
192 QBrush b = m_chart->backgroundBrush();
205 QBrush b = m_chart->backgroundBrush();
193 if (color != b.color()) {
206 if (color != b.color()) {
194 b.setColor(color);
207 b.setColor(color);
195 m_chart->setBackgroundBrush(b);
208 m_chart->setBackgroundBrush(b);
196 emit backgroundColorChanged();
209 emit backgroundColorChanged();
197 }
210 }
198 }
211 }
199
212
200 QColor DeclarativeChart::backgroundColor()
213 QColor DeclarativeChart::backgroundColor()
201 {
214 {
202 return m_chart->backgroundBrush().color();
215 return m_chart->backgroundBrush().color();
203 }
216 }
204
217
205 int DeclarativeChart::count()
218 int DeclarativeChart::count()
206 {
219 {
207 return m_chart->series().count();
220 return m_chart->series().count();
208 }
221 }
209
222
210 QAbstractSeries *DeclarativeChart::series(int index)
223 QAbstractSeries *DeclarativeChart::series(int index)
211 {
224 {
212 if (index < m_chart->series().count()) {
225 if (index < m_chart->series().count()) {
213 return m_chart->series().at(index);
226 return m_chart->series().at(index);
214 }
227 }
215 return 0;
228 return 0;
216 }
229 }
217
230
218 QAbstractSeries *DeclarativeChart::series(QString seriesName)
231 QAbstractSeries *DeclarativeChart::series(QString seriesName)
219 {
232 {
220 foreach(QAbstractSeries *series, m_chart->series()) {
233 foreach(QAbstractSeries *series, m_chart->series()) {
221 if (series->name() == seriesName)
234 if (series->name() == seriesName)
222 return series;
235 return series;
223 }
236 }
224 return 0;
237 return 0;
225 }
238 }
226
239
227 QAbstractSeries *DeclarativeChart::createSeries(DeclarativeChart::SeriesType type, QString name)
240 QAbstractSeries *DeclarativeChart::createSeries(DeclarativeChart::SeriesType type, QString name)
228 {
241 {
229 QAbstractSeries *series = 0;
242 QAbstractSeries *series = 0;
230 switch (type) {
243 switch (type) {
231 case DeclarativeChart::SeriesTypeLine:
244 case DeclarativeChart::SeriesTypeLine:
232 series = new DeclarativeLineSeries();
245 series = new DeclarativeLineSeries();
233 break;
246 break;
234 case DeclarativeChart::SeriesTypeArea:
247 case DeclarativeChart::SeriesTypeArea:
235 series = new DeclarativeAreaSeries();
248 series = new DeclarativeAreaSeries();
236 break;
249 break;
237 case DeclarativeChart::SeriesTypeBar:
250 case DeclarativeChart::SeriesTypeBar:
238 series = new DeclarativeBarSeries();
251 series = new DeclarativeBarSeries();
239 break;
252 break;
240 case DeclarativeChart::SeriesTypeStackedBar:
253 case DeclarativeChart::SeriesTypeStackedBar:
241 // TODO
254 // TODO
242 break;
255 break;
243 case DeclarativeChart::SeriesTypePercentBar:
256 case DeclarativeChart::SeriesTypePercentBar:
244 // TODO
257 // TODO
245 break;
258 break;
246 case DeclarativeChart::SeriesTypeGroupedBar:
259 case DeclarativeChart::SeriesTypeGroupedBar:
247 series = new DeclarativeGroupedBarSeries();
260 series = new DeclarativeGroupedBarSeries();
248 break;
261 break;
249 case DeclarativeChart::SeriesTypePie:
262 case DeclarativeChart::SeriesTypePie:
250 series = new DeclarativePieSeries();
263 series = new DeclarativePieSeries();
251 break;
264 break;
252 case DeclarativeChart::SeriesTypeScatter:
265 case DeclarativeChart::SeriesTypeScatter:
253 series = new DeclarativeScatterSeries();
266 series = new DeclarativeScatterSeries();
254 break;
267 break;
255 case DeclarativeChart::SeriesTypeSpline:
268 case DeclarativeChart::SeriesTypeSpline:
256 series = new DeclarativeSplineSeries();
269 series = new DeclarativeSplineSeries();
257 break;
270 break;
258 default:
271 default:
259 qWarning() << "Illegal series type";
272 qWarning() << "Illegal series type";
260 }
273 }
261 series->setName(name);
274 series->setName(name);
262 m_chart->addSeries(series);
275 m_chart->addSeries(series);
263 return series;
276 return series;
264 }
277 }
265
278
266 #include "moc_declarativechart.cpp"
279 #include "moc_declarativechart.cpp"
267
280
268 QTCOMMERCIALCHART_END_NAMESPACE
281 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,96 +1,143
1 /****************************************************************************
1 /****************************************************************************
2 **
2 **
3 ** Copyright (C) 2012 Digia Plc
3 ** Copyright (C) 2012 Digia Plc
4 ** All rights reserved.
4 ** All rights reserved.
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 **
6 **
7 ** This file is part of the Qt Commercial Charts Add-on.
7 ** This file is part of the Qt Commercial Charts Add-on.
8 **
8 **
9 ** $QT_BEGIN_LICENSE$
9 ** $QT_BEGIN_LICENSE$
10 ** Licensees holding valid Qt Commercial licenses may use this file in
10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 ** accordance with the Qt Commercial License Agreement provided with the
11 ** accordance with the Qt Commercial License Agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia.
13 ** a written agreement between you and Digia.
14 **
14 **
15 ** If you have questions regarding the use of this file, please use
15 ** If you have questions regarding the use of this file, please use
16 ** contact form at http://qt.digia.com
16 ** contact form at http://qt.digia.com
17 ** $QT_END_LICENSE$
17 ** $QT_END_LICENSE$
18 **
18 **
19 ****************************************************************************/
19 ****************************************************************************/
20
20
21 #include "declarativepieseries.h"
21 #include "declarativepieseries.h"
22 #include "declarativechart.h"
22 #include "declarativechart.h"
23 #include "qchart.h"
23 #include "qchart.h"
24 #include <qdeclarativelist.h>
24 #include <qdeclarativelist.h>
25 #include <QVPieModelMapper>
25 #include <QVPieModelMapper>
26 #include <QHPieModelMapper>
26 #include <QHPieModelMapper>
27
27
28 QTCOMMERCIALCHART_BEGIN_NAMESPACE
28 QTCOMMERCIALCHART_BEGIN_NAMESPACE
29
29
30 /*!
31 \qmlclass PieSeries DeclarativePieSeries
32
33 \section1 Example Usage
34
35 \beginfloatleft
36 \image demos_qmlchart1.png
37 \endfloat
38 \clearfloat
39
40 The following QML shows how to create a simple pie chart.
41
42 \snippet ../demos/qmlchart/qml/qmlchart/View1.qml 1
43 */
44
45 /*!
46 \qmlproperty real PieSeries::horizontalPosition
47 \brief Defines the horizontal position of the pie.
48
49 The value is a relative value to the chart rectangle where:
50
51 \list
52 \o 0.0 is the absolute left.
53 \o 1.0 is the absolute right.
54 \endlist
55
56 Default value is 0.5 (center).
57
58 \sa verticalPosition
59 */
60
61 /*!
62 \qmlproperty real PieSeries::verticalPosition
63 \brief Defines the vertical position of the pie.
64
65 The value is a relative value to the chart rectangle where:
66
67 \list
68 \o 0.0 is the absolute top.
69 \o 1.0 is the absolute bottom.
70 \endlist
71
72 Default value is 0.5 (center).
73
74 \sa horizontalPosition
75 */
76
30 DeclarativePieSeries::DeclarativePieSeries(QObject *parent) :
77 DeclarativePieSeries::DeclarativePieSeries(QObject *parent) :
31 QPieSeries(parent)
78 QPieSeries(parent)
32 {
79 {
33 }
80 }
34
81
35 void DeclarativePieSeries::classBegin()
82 void DeclarativePieSeries::classBegin()
36 {
83 {
37 }
84 }
38
85
39 void DeclarativePieSeries::componentComplete()
86 void DeclarativePieSeries::componentComplete()
40 {
87 {
41 foreach(QObject *child, children()) {
88 foreach(QObject *child, children()) {
42 if (qobject_cast<QPieSlice *>(child)) {
89 if (qobject_cast<QPieSlice *>(child)) {
43 QPieSeries::append(qobject_cast<QPieSlice *>(child));
90 QPieSeries::append(qobject_cast<QPieSlice *>(child));
44 } else if(qobject_cast<QVPieModelMapper *>(child)) {
91 } else if(qobject_cast<QVPieModelMapper *>(child)) {
45 QVPieModelMapper *mapper = qobject_cast<QVPieModelMapper *>(child);
92 QVPieModelMapper *mapper = qobject_cast<QVPieModelMapper *>(child);
46 mapper->setSeries(this);
93 mapper->setSeries(this);
47 } else if(qobject_cast<QHPieModelMapper *>(child)) {
94 } else if(qobject_cast<QHPieModelMapper *>(child)) {
48 QHPieModelMapper *mapper = qobject_cast<QHPieModelMapper *>(child);
95 QHPieModelMapper *mapper = qobject_cast<QHPieModelMapper *>(child);
49 mapper->setSeries(this);
96 mapper->setSeries(this);
50 }
97 }
51 }
98 }
52 }
99 }
53
100
54 QDeclarativeListProperty<QObject> DeclarativePieSeries::seriesChildren()
101 QDeclarativeListProperty<QObject> DeclarativePieSeries::seriesChildren()
55 {
102 {
56 return QDeclarativeListProperty<QObject>(this, 0, &DeclarativePieSeries::appendSeriesChildren);
103 return QDeclarativeListProperty<QObject>(this, 0, &DeclarativePieSeries::appendSeriesChildren);
57 }
104 }
58
105
59 void DeclarativePieSeries::appendSeriesChildren(QDeclarativeListProperty<QObject> * list, QObject *element)
106 void DeclarativePieSeries::appendSeriesChildren(QDeclarativeListProperty<QObject> * list, QObject *element)
60 {
107 {
61 // Empty implementation; the children are parsed in componentComplete instead
108 // Empty implementation; the children are parsed in componentComplete instead
62 Q_UNUSED(list);
109 Q_UNUSED(list);
63 Q_UNUSED(element);
110 Q_UNUSED(element);
64 }
111 }
65
112
66 QPieSlice *DeclarativePieSeries::at(int index)
113 QPieSlice *DeclarativePieSeries::at(int index)
67 {
114 {
68 QList<QPieSlice*> sliceList = slices();
115 QList<QPieSlice*> sliceList = slices();
69 if (index < sliceList.count())
116 if (index < sliceList.count())
70 return sliceList[index];
117 return sliceList[index];
71
118
72 return 0;
119 return 0;
73 }
120 }
74
121
75 QPieSlice* DeclarativePieSeries::find(QString label)
122 QPieSlice* DeclarativePieSeries::find(QString label)
76 {
123 {
77 foreach (QPieSlice *slice, slices()) {
124 foreach (QPieSlice *slice, slices()) {
78 if (slice->label() == label)
125 if (slice->label() == label)
79 return slice;
126 return slice;
80 }
127 }
81 return 0;
128 return 0;
82 }
129 }
83
130
84 QPieSlice* DeclarativePieSeries::append(QString label, qreal value)
131 QPieSlice* DeclarativePieSeries::append(QString label, qreal value)
85 {
132 {
86 // TODO: parameter order is wrong, switch it:
133 // TODO: parameter order is wrong, switch it:
87 QPieSlice *slice = new QPieSlice(this);
134 QPieSlice *slice = new QPieSlice(this);
88 slice->setLabel(label);
135 slice->setLabel(label);
89 slice->setValue(value);
136 slice->setValue(value);
90 QPieSeries::append(slice);
137 QPieSeries::append(slice);
91 return slice;
138 return slice;
92 }
139 }
93
140
94 #include "moc_declarativepieseries.cpp"
141 #include "moc_declarativepieseries.cpp"
95
142
96 QTCOMMERCIALCHART_END_NAMESPACE
143 QTCOMMERCIALCHART_END_NAMESPACE
General Comments 0
You need to be logged in to leave comments. Login now