##// END OF EJS Templates
Minor fixes and started changing ReadMe
Marek Rosa -
r1363:ed768c7affdd
parent child
Show More
@@ -1,60 +1,57
1 --------------------------------
1 --------------------------------
2 Commercial Charts Add-on Preview
2 Commercial Charts Add-on Beta
3 --------------------------------
3 --------------------------------
4
4
5 Whats in Qt Commercial Charts
5 Whats in Qt Commercial Charts
6 =============================
6 =============================
7
7
8 Directory structure:
8 Directory structure:
9
9
10 src/
10 src/
11 Source code of the Qt Commercial Charts
11 Source code of the Qt Commercial Charts
12 qmlplugin/
12 qmlplugin/
13 QML bindings for the charts
13 QML bindings for the charts
14 examples/
14 examples/
15 Some examples of using Qt Commercial Charts
15 Some examples of using Qt Commercial Charts
16 demos/
16 demos/
17 More versatile example applications showing how to customize charts,
17 More versatile example applications showing how to customize charts,
18 combine several chart types and implement interaction in charts
18 combine several chart types and implement interaction in charts
19 doc/
19 doc/
20 Documentation
20 Documentation
21 licenses/
21 licenses/
22 Licensing infromation
22 Licensing infromation
23
23
24 Building
24 Building
25 ========
25 ========
26
26
27 Configure project with qmake:
27 Configure project with qmake:
28 qmake CONFIG+=release
28 qmake CONFIG+=release
29
29
30 Build poject with make:
30 Build poject with make:
31 (Linux) make
31 (Linux) make
32 (Windows with MinGw) mingw32-make
32 (Windows with MinGw) mingw32-make
33 (Visual Studio) namke
33 (Visual Studio) namke
34
34
35 If you want to install the libraries to your Qt library directory use:
35 If you want to install the libraries to your Qt library directory use:
36 make install
36 make install
37
37
38 If you want to uninstall the libraries
38 If you want to uninstall the libraries
39 make uninstall
39 make uninstall
40
40
41 Documentation
41 Documentation
42 =============
42 =============
43
43
44 The documentation can be generated with "make docs". It will be placed
44 The documentation can be generated with "make docs". It will be placed
45 into "doc/html" in the build directory.
45 into "doc/html" in the build directory.
46
46
47 KNOWN ISSUES
47 KNOWN ISSUES
48 ============
48 ============
49 * The preview version of Qt Commercial Charts is still under development
49 * The Charts API should be stable, but might still change between the Beta and first official release
50 and thus should not be used in e.g. product development
51 * The Charts API might change between the Preview and first official release
52 * Some areas will be refactored before the first official release
50 * Some areas will be refactored before the first official release
53 * Qt Designer plugin is missing
54 * Enable/disable tooltip is missing from the API
51 * Enable/disable tooltip is missing from the API
55 * Mutliple axis are not suported at the moment.
52 * Mutliple axis are not suported at the moment.
56 * Logartmic, polar axis are not supported at the moment.
53 * Logartmic, polar axis are not supported at the moment.
57 * Getting data from QAbstractItemModel is not feature complete.
54 * Model support for QBarSeries is not complete.
58 * Interlnal layout hadnling is not working properly.
55 * Interlnal layout hadnling is not working properly.
59 * The QML Bindings are still under development and to be considered as early draft
56 * The QML Bindings are still under development and to be considered as early draft
60 * All the current QML APIs are shown in qmlchart demo app
57 * All the current QML APIs are shown in qmlchart demo app
@@ -1,40 +1,41
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 "drilldownseries.h"
21 #include "drilldownseries.h"
22
22
23 QTCOMMERCIALCHART_USE_NAMESPACE
23 QTCOMMERCIALCHART_USE_NAMESPACE
24
24
25 DrilldownBarSeries::DrilldownBarSeries(QStringList categories, QObject *parent)
25 DrilldownBarSeries::DrilldownBarSeries(QStringList categories, QObject *parent)
26 : QStackedBarSeries(parent)
26 : QStackedBarSeries(parent)
27 {
27 {
28 Q_UNUSED(categories);
28 }
29 }
29
30
30 void DrilldownBarSeries::mapDrilldownSeries(int index, DrilldownBarSeries* drilldownSeries)
31 void DrilldownBarSeries::mapDrilldownSeries(int index, DrilldownBarSeries* drilldownSeries)
31 {
32 {
32 mDrilldownSeries[index] = drilldownSeries;
33 mDrilldownSeries[index] = drilldownSeries;
33 }
34 }
34
35
35 DrilldownBarSeries* DrilldownBarSeries::drilldownSeries(int index)
36 DrilldownBarSeries* DrilldownBarSeries::drilldownSeries(int index)
36 {
37 {
37 return mDrilldownSeries[index];
38 return mDrilldownSeries[index];
38 }
39 }
39
40
40 #include "moc_drilldownseries.cpp"
41 #include "moc_drilldownseries.cpp"
@@ -1,650 +1,654
1 /****************************************************************************
1 /****************************************************************************
2 **
2 **
3 ** Copyright (C) 2012 Digia Plc
3 ** Copyright (C) 2012 Digia Plc
4 ** All rights reserved.
4 ** All rights reserved.
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 **
6 **
7 ** This file is part of the Qt Commercial Charts Add-on.
7 ** This file is part of the Qt Commercial Charts Add-on.
8 **
8 **
9 ** $QT_BEGIN_LICENSE$
9 ** $QT_BEGIN_LICENSE$
10 ** Licensees holding valid Qt Commercial licenses may use this file in
10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 ** accordance with the Qt Commercial License Agreement provided with the
11 ** accordance with the Qt Commercial License Agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia.
13 ** a written agreement between you and Digia.
14 **
14 **
15 ** If you have questions regarding the use of this file, please use
15 ** If you have questions regarding the use of this file, please use
16 ** contact form at http://qt.digia.com
16 ** contact form at http://qt.digia.com
17 ** $QT_END_LICENSE$
17 ** $QT_END_LICENSE$
18 **
18 **
19 ****************************************************************************/
19 ****************************************************************************/
20
20
21 #include "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 part of QtCommercial chart API.
35 \brief part of QtCommercial chart API.
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 /*!
49 /*!
50 \property QBarSeries::barMargin
50 \property QBarSeries::barMargin
51 \brief Defines the margin around bars.
51 \brief Defines the margin around bars.
52
52
53 Value is from 0 to 1 and represents
53 Value is from 0 to 1 and represents
54 percentage of margin compared to bars
54 percentage of margin compared to bars
55 */
55 */
56
56
57 /*!
57 /*!
58 \property QBarSeries::count
58 \property QBarSeries::count
59 \brief Holds the number of sets in series.
59 \brief Holds the number of sets in series.
60 */
60 */
61
61
62 /*!
62 /*!
63 \property QBarSeries::labelsVisible
63 \property QBarSeries::labelsVisible
64 \brief Defines the visibility of the labels in series
64 \brief Defines the visibility of the labels in series
65 */
65 */
66
66
67 /*!
67 /*!
68 \fn void QBarSeries::clicked(QBarSet *barset, int index)
68 \fn void QBarSeries::clicked(QBarSet *barset, int index)
69
69
70 The signal is emitted if the user clicks with a mouse on top of QBarSet \a barset.
70 The signal is emitted if the user clicks with a mouse on top of QBarSet \a barset.
71 Clicked bar inside set is indexed by \a index
71 Clicked bar inside set is indexed by \a index
72 */
72 */
73
73
74 /*!
74 /*!
75 \fn void QBarSeries::hovered(QBarSet* barset, bool status)
75 \fn void QBarSeries::hovered(QBarSet* barset, bool status)
76
76
77 The signal is emitted if mouse is hovered on top of series.
77 The signal is emitted if mouse is hovered on top of series.
78 Parameter \a barset is the pointer of barset, where hover happened.
78 Parameter \a barset is the pointer of barset, where hover happened.
79 Parameter \a status is true, if mouse entered on top of series, false if mouse left from top of series.
79 Parameter \a status is true, if mouse entered on top of series, false if mouse left from top of series.
80 */
80 */
81
81
82 /*!
82 /*!
83 \fn void QBarSeries::visibleChanged()
83 \fn void QBarSeries::visibleChanged()
84 */
84 */
85
85
86 /*!
86 /*!
87 \fn void QBarSeries::labelsVisibleChanged()
87 \fn void QBarSeries::labelsVisibleChanged()
88
88
89 This signal is emitted when labels visibility have changed.
89 This signal is emitted when labels visibility have changed.
90
90
91 \sa isLabelsVisible(), setLabelsVisible()
91 \sa isLabelsVisible(), setLabelsVisible()
92 */
92 */
93
93
94 /*!
94 /*!
95 \fn void QBarSeries::barsetsAdded(QList<QBarSet*> sets)
95 \fn void QBarSeries::barsetsAdded(QList<QBarSet*> sets)
96
96
97 This signal is emitted when \a sets have been added to the series.
97 This signal is emitted when \a sets have been added to the series.
98
98
99 \sa append(), insert()
99 \sa append(), insert()
100 */
100 */
101
101
102 /*!
102 /*!
103 \fn void QBarSeries::barsetsRemoved(QList<QBarSet*> sets)
103 \fn void QBarSeries::barsetsRemoved(QList<QBarSet*> sets)
104
104
105 This signal is emitted when \a sets have been removed from the series.
105 This signal is emitted when \a sets have been removed from the series.
106
106
107 \sa remove()
107 \sa remove()
108 */
108 */
109
109
110 /*!
110 /*!
111 Constructs empty QBarSeries.
111 Constructs empty QBarSeries.
112 QBarSeries is QObject which is a child of a \a parent.
112 QBarSeries is QObject which is a child of a \a parent.
113 */
113 */
114 QBarSeries::QBarSeries(QObject *parent) :
114 QBarSeries::QBarSeries(QObject *parent) :
115 QAbstractSeries(*new QBarSeriesPrivate(this),parent)
115 QAbstractSeries(*new QBarSeriesPrivate(this),parent)
116 {
116 {
117 }
117 }
118
118
119 /*!
119 /*!
120 Destructs barseries and owned barsets.
120 Destructs barseries and owned barsets.
121 */
121 */
122 QBarSeries::~QBarSeries()
122 QBarSeries::~QBarSeries()
123 {
123 {
124 Q_D(QBarSeries);
124 Q_D(QBarSeries);
125 if(d->m_dataset){
125 if(d->m_dataset){
126 d->m_dataset->removeSeries(this);
126 d->m_dataset->removeSeries(this);
127 }
127 }
128 }
128 }
129
129
130 /*!
130 /*!
131 \internal
131 \internal
132 */
132 */
133 QBarSeries::QBarSeries(QBarSeriesPrivate &d, QObject *parent) :
133 QBarSeries::QBarSeries(QBarSeriesPrivate &d, QObject *parent) :
134 QAbstractSeries(d,parent)
134 QAbstractSeries(d,parent)
135 {
135 {
136 }
136 }
137
137
138 /*!
138 /*!
139 Returns the type of series. Derived classes override this.
139 Returns the type of series. Derived classes override this.
140 */
140 */
141 QAbstractSeries::SeriesType QBarSeries::type() const
141 QAbstractSeries::SeriesType QBarSeries::type() const
142 {
142 {
143 return QAbstractSeries::SeriesTypeBar;
143 return QAbstractSeries::SeriesTypeBar;
144 }
144 }
145
145
146 /*!
146 /*!
147 Sets the margin around bars. Parameter \a margin is from 0 to 1 and represents
147 Sets the margin around bars. Parameter \a margin is from 0 to 1 and represents
148 percentage of margin compared to bars
148 percentage of margin compared to bars
149 */
149 */
150 void QBarSeries::setBarMargin(qreal margin)
150 void QBarSeries::setBarMargin(qreal margin)
151 {
151 {
152 Q_D(QBarSeries);
152 Q_D(QBarSeries);
153 d->setBarMargin(margin);
153 d->setBarMargin(margin);
154 }
154 }
155
155
156 /*!
156 /*!
157 Returns the margin around bars
157 Returns the margin around bars
158 */
158 */
159 qreal QBarSeries::barMargin() const
159 qreal QBarSeries::barMargin() const
160 {
160 {
161 Q_D(const QBarSeries);
161 Q_D(const QBarSeries);
162 return d->barMargin();
162 return d->barMargin();
163 }
163 }
164
164
165 /*!
165 /*!
166 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.
166 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.
167 Returns true, if appending succeeded.
167 Returns true, if appending succeeded.
168
168
169 */
169 */
170 bool QBarSeries::append(QBarSet *set)
170 bool QBarSeries::append(QBarSet *set)
171 {
171 {
172 Q_D(QBarSeries);
172 Q_D(QBarSeries);
173 bool success = d->append(set);
173 bool success = d->append(set);
174 if (success) {
174 if (success) {
175 QList<QBarSet*> sets;
175 QList<QBarSet*> sets;
176 sets.append(set);
176 sets.append(set);
177 emit barsetsAdded(sets);
177 emit barsetsAdded(sets);
178 }
178 }
179 return success;
179 return success;
180 }
180 }
181
181
182 /*!
182 /*!
183 Removes a set of bars from series. Releases ownership of \a set. Doesn't delete \a set.
183 Removes a set of bars from series. Releases ownership of \a set. Doesn't delete \a set.
184 Returns true, if set was removed.
184 Returns true, if set was removed.
185 */
185 */
186 bool QBarSeries::remove(QBarSet *set)
186 bool QBarSeries::remove(QBarSet *set)
187 {
187 {
188 Q_D(QBarSeries);
188 Q_D(QBarSeries);
189 bool success = d->remove(set);
189 bool success = d->remove(set);
190 if (success) {
190 if (success) {
191 QList<QBarSet*> sets;
191 QList<QBarSet*> sets;
192 sets.append(set);
192 sets.append(set);
193 emit barsetsRemoved(sets);
193 emit barsetsRemoved(sets);
194 }
194 }
195 return success;
195 return success;
196 }
196 }
197
197
198 /*!
198 /*!
199 Adds a list of barsets to series. Takes ownership of \a sets.
199 Adds a list of barsets to series. Takes ownership of \a sets.
200 Returns true, if all sets were appended succesfully. If any of the sets is null or is already appended to series,
200 Returns true, if all sets were appended succesfully. If any of the sets is null or is already appended to series,
201 nothing is appended and function returns false. If any of the sets is in list more than once, nothing is appended
201 nothing is appended and function returns false. If any of the sets is in list more than once, nothing is appended
202 and function returns false.
202 and function returns false.
203 */
203 */
204 bool QBarSeries::append(QList<QBarSet* > sets)
204 bool QBarSeries::append(QList<QBarSet* > sets)
205 {
205 {
206 Q_D(QBarSeries);
206 Q_D(QBarSeries);
207 bool success = d->append(sets);
207 bool success = d->append(sets);
208 if (success) {
208 if (success) {
209 emit barsetsAdded(sets);
209 emit barsetsAdded(sets);
210 }
210 }
211 return success;
211 return success;
212 }
212 }
213
213
214 /*!
214 /*!
215 Removes a list of barsets from series. Releases ownership of \a sets. Doesn't delete \a sets.
215 Removes a list of barsets from series. Releases ownership of \a sets. Doesn't delete \a sets.
216 */
216 */
217 bool QBarSeries::remove(QList<QBarSet* > sets)
217 bool QBarSeries::remove(QList<QBarSet* > sets)
218 {
218 {
219 Q_D(QBarSeries);
219 Q_D(QBarSeries);
220 bool success = d->remove(sets);
220 bool success = d->remove(sets);
221 if (success) {
221 if (success) {
222 emit barsetsRemoved(sets);
222 emit barsetsRemoved(sets);
223 }
223 }
224 return success;
224 return success;
225 }
225 }
226
226
227 /*!
227 /*!
228 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.
228 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.
229 Returns true, if inserting succeeded.
229 Returns true, if inserting succeeded.
230
230
231 */
231 */
232 bool QBarSeries::insert(int index, QBarSet *set)
232 bool QBarSeries::insert(int index, QBarSet *set)
233 {
233 {
234 Q_D(QBarSeries);
234 Q_D(QBarSeries);
235 bool success = d->insert(index, set);
235 bool success = d->insert(index, set);
236 if (success) {
236 if (success) {
237 QList<QBarSet*> sets;
237 QList<QBarSet*> sets;
238 sets.append(set);
238 sets.append(set);
239 emit barsetsAdded(sets);
239 emit barsetsAdded(sets);
240 }
240 }
241 return success;
241 return success;
242 }
242 }
243
243
244 /*!
244 /*!
245 Removes all of the bar sets from the series
245 Removes all of the bar sets from the series
246 */
246 */
247 void QBarSeries::clear()
247 void QBarSeries::clear()
248 {
248 {
249 Q_D(QBarSeries);
249 Q_D(QBarSeries);
250 d->remove(barSets());
250 bool success = d->remove(barSets());
251 if (success) {
252 emit barsetsRemoved(sets);
253 }
254 return success;
251 }
255 }
252
256
253 /*!
257 /*!
254 Returns number of sets in series.
258 Returns number of sets in series.
255 */
259 */
256 int QBarSeries::barsetCount() const
260 int QBarSeries::barsetCount() const
257 {
261 {
258 Q_D(const QBarSeries);
262 Q_D(const QBarSeries);
259 return d->m_barSets.count();
263 return d->m_barSets.count();
260 }
264 }
261
265
262 /*!
266 /*!
263 Returns a list of sets in series. Keeps ownership of sets.
267 Returns a list of sets in series. Keeps ownership of sets.
264 */
268 */
265 QList<QBarSet*> QBarSeries::barSets() const
269 QList<QBarSet*> QBarSeries::barSets() const
266 {
270 {
267 Q_D(const QBarSeries);
271 Q_D(const QBarSeries);
268 return d->m_barSets;
272 return d->m_barSets;
269 }
273 }
270
274
271 /*!
275 /*!
272 Sets the visibility of labels in series to \a visible
276 Sets the visibility of labels in series to \a visible
273 */
277 */
274 void QBarSeries::setLabelsVisible(bool visible)
278 void QBarSeries::setLabelsVisible(bool visible)
275 {
279 {
276 Q_D(QBarSeries);
280 Q_D(QBarSeries);
277 if (d->m_labelsVisible != visible) {
281 if (d->m_labelsVisible != visible) {
278 d->setLabelsVisible(visible);
282 d->setLabelsVisible(visible);
279 emit labelsVisibleChanged();
283 emit labelsVisibleChanged();
280 }
284 }
281 }
285 }
282
286
283 /*!
287 /*!
284 Returns the visibility of labels
288 Returns the visibility of labels
285 */
289 */
286 bool QBarSeries::isLabelsVisible() const
290 bool QBarSeries::isLabelsVisible() const
287 {
291 {
288 Q_D(const QBarSeries);
292 Q_D(const QBarSeries);
289 return d->m_labelsVisible;
293 return d->m_labelsVisible;
290 }
294 }
291
295
292 ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
296 ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
293
297
294 QBarSeriesPrivate::QBarSeriesPrivate(QBarSeries *q) :
298 QBarSeriesPrivate::QBarSeriesPrivate(QBarSeries *q) :
295 QAbstractSeriesPrivate(q),
299 QAbstractSeriesPrivate(q),
296 m_barMargin(0.5), // Default value is 50% of category width
300 m_barMargin(0.5), // Default value is 50% of category width
297 m_labelsVisible(false),
301 m_labelsVisible(false),
298 m_visible(true)
302 m_visible(true)
299 {
303 {
300 }
304 }
301
305
302 void QBarSeriesPrivate::setCategories(QStringList categories)
306 void QBarSeriesPrivate::setCategories(QStringList categories)
303 {
307 {
304 m_categories = categories;
308 m_categories = categories;
305 }
309 }
306
310
307 void QBarSeriesPrivate::insertCategory(int index, const QString category)
311 void QBarSeriesPrivate::insertCategory(int index, const QString category)
308 {
312 {
309 m_categories.insert(index, category);
313 m_categories.insert(index, category);
310 emit categoriesUpdated();
314 emit categoriesUpdated();
311 }
315 }
312
316
313 void QBarSeriesPrivate::removeCategory(int index)
317 void QBarSeriesPrivate::removeCategory(int index)
314 {
318 {
315 m_categories.removeAt(index);
319 m_categories.removeAt(index);
316 emit categoriesUpdated();
320 emit categoriesUpdated();
317 }
321 }
318
322
319 int QBarSeriesPrivate::categoryCount() const
323 int QBarSeriesPrivate::categoryCount() const
320 {
324 {
321 if (m_categories.count() > 0) {
325 if (m_categories.count() > 0) {
322 return m_categories.count();
326 return m_categories.count();
323 }
327 }
324
328
325 // No categories defined. return count of longest set.
329 // No categories defined. return count of longest set.
326 int count = 0;
330 int count = 0;
327 for (int i=0; i<m_barSets.count(); i++) {
331 for (int i=0; i<m_barSets.count(); i++) {
328 if (m_barSets.at(i)->count() > count) {
332 if (m_barSets.at(i)->count() > count) {
329 count = m_barSets.at(i)->count();
333 count = m_barSets.at(i)->count();
330 }
334 }
331 }
335 }
332
336
333 return count;
337 return count;
334 }
338 }
335
339
336 QStringList QBarSeriesPrivate::categories() const
340 QStringList QBarSeriesPrivate::categories() const
337 {
341 {
338 if (m_categories.count() > 0) {
342 if (m_categories.count() > 0) {
339 return m_categories;
343 return m_categories;
340 }
344 }
341
345
342 // No categories defined. retun list of indices.
346 // No categories defined. retun list of indices.
343 QStringList categories;
347 QStringList categories;
344
348
345 int count = categoryCount();
349 int count = categoryCount();
346 for (int i = 0; i < count; i++) {
350 for (int i = 0; i < count; i++) {
347 categories.append(QString::number(i));
351 categories.append(QString::number(i));
348 }
352 }
349 return categories;
353 return categories;
350 }
354 }
351
355
352 void QBarSeriesPrivate::setBarMargin(qreal margin)
356 void QBarSeriesPrivate::setBarMargin(qreal margin)
353 {
357 {
354 if (margin > 1.0) {
358 if (margin > 1.0) {
355 margin = 1.0;
359 margin = 1.0;
356 } else if (margin < 0.0) {
360 } else if (margin < 0.0) {
357 margin = 0.0;
361 margin = 0.0;
358 }
362 }
359
363
360 m_barMargin = margin;
364 m_barMargin = margin;
361 emit updatedBars();
365 emit updatedBars();
362 }
366 }
363
367
364 qreal QBarSeriesPrivate::barMargin() const
368 qreal QBarSeriesPrivate::barMargin() const
365 {
369 {
366 return m_barMargin;
370 return m_barMargin;
367 }
371 }
368
372
369 QBarSet* QBarSeriesPrivate::barsetAt(int index)
373 QBarSet* QBarSeriesPrivate::barsetAt(int index)
370 {
374 {
371 return m_barSets.at(index);
375 return m_barSets.at(index);
372 }
376 }
373
377
374 void QBarSeriesPrivate::setVisible(bool visible)
378 void QBarSeriesPrivate::setVisible(bool visible)
375 {
379 {
376 m_visible = visible;
380 m_visible = visible;
377 emit updatedBars();
381 emit updatedBars();
378 }
382 }
379
383
380 void QBarSeriesPrivate::setLabelsVisible(bool visible)
384 void QBarSeriesPrivate::setLabelsVisible(bool visible)
381 {
385 {
382 m_labelsVisible = visible;
386 m_labelsVisible = visible;
383 emit labelsVisibleChanged(visible);
387 emit labelsVisibleChanged(visible);
384 }
388 }
385
389
386 QString QBarSeriesPrivate::categoryName(int category)
390 QString QBarSeriesPrivate::categoryName(int category)
387 {
391 {
388 if ((category >= 0) && (category < m_categories.count())) {
392 if ((category >= 0) && (category < m_categories.count())) {
389 return m_categories.at(category);
393 return m_categories.at(category);
390 }
394 }
391
395
392 return QString::number(category);
396 return QString::number(category);
393 }
397 }
394
398
395 qreal QBarSeriesPrivate::min()
399 qreal QBarSeriesPrivate::min()
396 {
400 {
397 if (m_barSets.count() <= 0) {
401 if (m_barSets.count() <= 0) {
398 return 0;
402 return 0;
399 }
403 }
400 qreal min = INT_MAX;
404 qreal min = INT_MAX;
401
405
402 for (int i = 0; i < m_barSets.count(); i++) {
406 for (int i = 0; i < m_barSets.count(); i++) {
403 int categoryCount = m_barSets.at(i)->count();
407 int categoryCount = m_barSets.at(i)->count();
404 for (int j = 0; j < categoryCount; j++) {
408 for (int j = 0; j < categoryCount; j++) {
405 qreal temp = m_barSets.at(i)->at(j).y();
409 qreal temp = m_barSets.at(i)->at(j).y();
406 if (temp < min)
410 if (temp < min)
407 min = temp;
411 min = temp;
408 }
412 }
409 }
413 }
410 return min;
414 return min;
411 }
415 }
412
416
413 qreal QBarSeriesPrivate::max()
417 qreal QBarSeriesPrivate::max()
414 {
418 {
415 if (m_barSets.count() <= 0) {
419 if (m_barSets.count() <= 0) {
416 return 0;
420 return 0;
417 }
421 }
418 qreal max = INT_MIN;
422 qreal max = INT_MIN;
419
423
420 for (int i = 0; i < m_barSets.count(); i++) {
424 for (int i = 0; i < m_barSets.count(); i++) {
421 int categoryCount = m_barSets.at(i)->count();
425 int categoryCount = m_barSets.at(i)->count();
422 for (int j = 0; j < categoryCount; j++) {
426 for (int j = 0; j < categoryCount; j++) {
423 qreal temp = m_barSets.at(i)->at(j).y();
427 qreal temp = m_barSets.at(i)->at(j).y();
424 if (temp > max)
428 if (temp > max)
425 max = temp;
429 max = temp;
426 }
430 }
427 }
431 }
428
432
429 return max;
433 return max;
430 }
434 }
431
435
432 qreal QBarSeriesPrivate::valueAt(int set, int category)
436 qreal QBarSeriesPrivate::valueAt(int set, int category)
433 {
437 {
434 if ((set < 0) || (set >= m_barSets.count())) {
438 if ((set < 0) || (set >= m_barSets.count())) {
435 // No set, no value.
439 // No set, no value.
436 return 0;
440 return 0;
437 } else if ((category < 0) || (category >= m_barSets.at(set)->count())) {
441 } else if ((category < 0) || (category >= m_barSets.at(set)->count())) {
438 // No category, no value.
442 // No category, no value.
439 return 0;
443 return 0;
440 }
444 }
441
445
442 return m_barSets.at(set)->at(category).y();
446 return m_barSets.at(set)->at(category).y();
443 }
447 }
444
448
445 qreal QBarSeriesPrivate::percentageAt(int set, int category)
449 qreal QBarSeriesPrivate::percentageAt(int set, int category)
446 {
450 {
447 if ((set < 0) || (set >= m_barSets.count())) {
451 if ((set < 0) || (set >= m_barSets.count())) {
448 // No set, no value.
452 // No set, no value.
449 return 0;
453 return 0;
450 } else if ((category < 0) || (category >= m_barSets.at(set)->count())) {
454 } else if ((category < 0) || (category >= m_barSets.at(set)->count())) {
451 // No category, no value.
455 // No category, no value.
452 return 0;
456 return 0;
453 }
457 }
454
458
455 qreal value = m_barSets.at(set)->at(category).y();
459 qreal value = m_barSets.at(set)->at(category).y();
456 qreal sum = categorySum(category);
460 qreal sum = categorySum(category);
457 if ( qFuzzyIsNull(sum) ) {
461 if ( qFuzzyIsNull(sum) ) {
458 return 0;
462 return 0;
459 }
463 }
460
464
461 return value / sum;
465 return value / sum;
462 }
466 }
463
467
464 qreal QBarSeriesPrivate::categorySum(int category)
468 qreal QBarSeriesPrivate::categorySum(int category)
465 {
469 {
466 qreal sum(0);
470 qreal sum(0);
467 int count = m_barSets.count(); // Count sets
471 int count = m_barSets.count(); // Count sets
468 for (int set = 0; set < count; set++) {
472 for (int set = 0; set < count; set++) {
469 if (category < m_barSets.at(set)->count())
473 if (category < m_barSets.at(set)->count())
470 sum += m_barSets.at(set)->at(category).y();
474 sum += m_barSets.at(set)->at(category).y();
471 }
475 }
472 return sum;
476 return sum;
473 }
477 }
474
478
475 qreal QBarSeriesPrivate::absoluteCategorySum(int category)
479 qreal QBarSeriesPrivate::absoluteCategorySum(int category)
476 {
480 {
477 qreal sum(0);
481 qreal sum(0);
478 int count = m_barSets.count(); // Count sets
482 int count = m_barSets.count(); // Count sets
479 for (int set = 0; set < count; set++) {
483 for (int set = 0; set < count; set++) {
480 if (category < m_barSets.at(set)->count())
484 if (category < m_barSets.at(set)->count())
481 sum += qAbs(m_barSets.at(set)->at(category).y());
485 sum += qAbs(m_barSets.at(set)->at(category).y());
482 }
486 }
483 return sum;
487 return sum;
484 }
488 }
485
489
486 qreal QBarSeriesPrivate::maxCategorySum()
490 qreal QBarSeriesPrivate::maxCategorySum()
487 {
491 {
488 qreal max = INT_MIN;
492 qreal max = INT_MIN;
489 int count = categoryCount();
493 int count = categoryCount();
490 for (int i = 0; i < count; i++) {
494 for (int i = 0; i < count; i++) {
491 qreal sum = categorySum(i);
495 qreal sum = categorySum(i);
492 if (sum > max)
496 if (sum > max)
493 max = sum;
497 max = sum;
494 }
498 }
495 return max;
499 return max;
496 }
500 }
497
501
498 void QBarSeriesPrivate::scaleDomain(Domain& domain)
502 void QBarSeriesPrivate::scaleDomain(Domain& domain)
499 {
503 {
500 qreal minX(domain.minX());
504 qreal minX(domain.minX());
501 qreal minY(domain.minY());
505 qreal minY(domain.minY());
502 qreal maxX(domain.maxX());
506 qreal maxX(domain.maxX());
503 qreal maxY(domain.maxY());
507 qreal maxY(domain.maxY());
504 int tickXCount(domain.tickXCount());
508 int tickXCount(domain.tickXCount());
505 int tickYCount(domain.tickYCount());
509 int tickYCount(domain.tickYCount());
506
510
507 qreal x = categoryCount();
511 qreal x = categoryCount();
508 qreal y = max();
512 qreal y = max();
509 minX = qMin(minX, x) - 0.5;
513 minX = qMin(minX, x) - 0.5;
510 minY = qMin(minY, y);
514 minY = qMin(minY, y);
511 maxX = qMax(maxX, x) - 0.5;
515 maxX = qMax(maxX, x) - 0.5;
512 maxY = qMax(maxY, y);
516 maxY = qMax(maxY, y);
513 tickXCount = x+1;
517 tickXCount = x+1;
514
518
515 domain.setRange(minX,maxX,minY,maxY,tickXCount,tickYCount);
519 domain.setRange(minX,maxX,minY,maxY,tickXCount,tickYCount);
516 }
520 }
517
521
518 Chart* QBarSeriesPrivate::createGraphics(ChartPresenter* presenter)
522 Chart* QBarSeriesPrivate::createGraphics(ChartPresenter* presenter)
519 {
523 {
520 Q_Q(QBarSeries);
524 Q_Q(QBarSeries);
521
525
522 BarChartItem* bar = new BarChartItem(q,presenter);
526 BarChartItem* bar = new BarChartItem(q,presenter);
523 if(presenter->animationOptions().testFlag(QChart::SeriesAnimations)) {
527 if(presenter->animationOptions().testFlag(QChart::SeriesAnimations)) {
524 presenter->animator()->addAnimation(bar);
528 presenter->animator()->addAnimation(bar);
525 }
529 }
526 presenter->chartTheme()->decorate(q, presenter->dataSet()->seriesIndex(q));
530 presenter->chartTheme()->decorate(q, presenter->dataSet()->seriesIndex(q));
527 return bar;
531 return bar;
528
532
529 }
533 }
530
534
531 QList<LegendMarker*> QBarSeriesPrivate::createLegendMarker(QLegend* legend)
535 QList<LegendMarker*> QBarSeriesPrivate::createLegendMarker(QLegend* legend)
532 {
536 {
533 Q_Q(QBarSeries);
537 Q_Q(QBarSeries);
534 QList<LegendMarker*> markers;
538 QList<LegendMarker*> markers;
535 foreach(QBarSet* set, q->barSets()) {
539 foreach(QBarSet* set, q->barSets()) {
536 BarLegendMarker* marker = new BarLegendMarker(q,set,legend);
540 BarLegendMarker* marker = new BarLegendMarker(q,set,legend);
537 markers << marker;
541 markers << marker;
538 }
542 }
539
543
540 return markers;
544 return markers;
541 }
545 }
542
546
543 bool QBarSeriesPrivate::append(QBarSet *set)
547 bool QBarSeriesPrivate::append(QBarSet *set)
544 {
548 {
545 Q_Q(QBarSeries);
549 Q_Q(QBarSeries);
546 if ((m_barSets.contains(set)) || (set == 0)) {
550 if ((m_barSets.contains(set)) || (set == 0)) {
547 // Fail if set is already in list or set is null.
551 // Fail if set is already in list or set is null.
548 return false;
552 return false;
549 }
553 }
550 m_barSets.append(set);
554 m_barSets.append(set);
551 QObject::connect(set->d_ptr.data(), SIGNAL(updatedBars()), this, SIGNAL(updatedBars()));
555 QObject::connect(set->d_ptr.data(), SIGNAL(updatedBars()), this, SIGNAL(updatedBars()));
552 QObject::connect(set->d_ptr.data(), SIGNAL(restructuredBars()), this, SIGNAL(restructuredBars()));
556 QObject::connect(set->d_ptr.data(), SIGNAL(restructuredBars()), this, SIGNAL(restructuredBars()));
553 if (m_dataset) {
557 if (m_dataset) {
554 m_dataset->updateSeries(q); // this notifies legend
558 m_dataset->updateSeries(q); // this notifies legend
555 }
559 }
556 emit restructuredBars(); // this notifies barchartitem
560 emit restructuredBars(); // this notifies barchartitem
557 return true;
561 return true;
558 }
562 }
559
563
560 bool QBarSeriesPrivate::remove(QBarSet *set)
564 bool QBarSeriesPrivate::remove(QBarSet *set)
561 {
565 {
562 Q_Q(QBarSeries);
566 Q_Q(QBarSeries);
563 if (!m_barSets.contains(set)) {
567 if (!m_barSets.contains(set)) {
564 // Fail if set is not in list
568 // Fail if set is not in list
565 return false;
569 return false;
566 }
570 }
567 m_barSets.removeOne(set);
571 m_barSets.removeOne(set);
568 QObject::disconnect(set->d_ptr.data(), SIGNAL(updatedBars()), this, SIGNAL(updatedBars()));
572 QObject::disconnect(set->d_ptr.data(), SIGNAL(updatedBars()), this, SIGNAL(updatedBars()));
569 QObject::disconnect(set->d_ptr.data(), SIGNAL(restructuredBars()), this, SIGNAL(restructuredBars()));
573 QObject::disconnect(set->d_ptr.data(), SIGNAL(restructuredBars()), this, SIGNAL(restructuredBars()));
570 if (m_dataset) {
574 if (m_dataset) {
571 m_dataset->updateSeries(q); // this notifies legend
575 m_dataset->updateSeries(q); // this notifies legend
572 }
576 }
573 emit restructuredBars(); // this notifies barchartitem
577 emit restructuredBars(); // this notifies barchartitem
574 return true;
578 return true;
575 }
579 }
576
580
577 bool QBarSeriesPrivate::append(QList<QBarSet* > sets)
581 bool QBarSeriesPrivate::append(QList<QBarSet* > sets)
578 {
582 {
579 Q_Q(QBarSeries);
583 Q_Q(QBarSeries);
580 foreach (QBarSet* set, sets) {
584 foreach (QBarSet* set, sets) {
581 if ((set == 0) || (m_barSets.contains(set))) {
585 if ((set == 0) || (m_barSets.contains(set))) {
582 // Fail if any of the sets is null or is already appended.
586 // Fail if any of the sets is null or is already appended.
583 return false;
587 return false;
584 }
588 }
585 if (sets.count(set) != 1) {
589 if (sets.count(set) != 1) {
586 // Also fail if same set is more than once in given list.
590 // Also fail if same set is more than once in given list.
587 return false;
591 return false;
588 }
592 }
589 }
593 }
590
594
591 foreach (QBarSet* set, sets) {
595 foreach (QBarSet* set, sets) {
592 m_barSets.append(set);
596 m_barSets.append(set);
593 QObject::connect(set->d_ptr.data(), SIGNAL(updatedBars()), this, SIGNAL(updatedBars()));
597 QObject::connect(set->d_ptr.data(), SIGNAL(updatedBars()), this, SIGNAL(updatedBars()));
594 QObject::connect(set->d_ptr.data(), SIGNAL(restructuredBars()), this, SIGNAL(restructuredBars()));
598 QObject::connect(set->d_ptr.data(), SIGNAL(restructuredBars()), this, SIGNAL(restructuredBars()));
595 }
599 }
596 if (m_dataset) {
600 if (m_dataset) {
597 m_dataset->updateSeries(q); // this notifies legend
601 m_dataset->updateSeries(q); // this notifies legend
598 }
602 }
599 emit restructuredBars(); // this notifies barchartitem
603 emit restructuredBars(); // this notifies barchartitem
600 return true;
604 return true;
601 }
605 }
602
606
603 bool QBarSeriesPrivate::remove(QList<QBarSet* > sets)
607 bool QBarSeriesPrivate::remove(QList<QBarSet* > sets)
604 {
608 {
605 Q_Q(QBarSeries);
609 Q_Q(QBarSeries);
606 foreach (QBarSet* set, sets) {
610 foreach (QBarSet* set, sets) {
607 if ((set == 0) || (!m_barSets.contains(set))) {
611 if ((set == 0) || (!m_barSets.contains(set))) {
608 // Fail if any of the sets is null or is not in series
612 // Fail if any of the sets is null or is not in series
609 return false;
613 return false;
610 }
614 }
611 if (sets.count(set) != 1) {
615 if (sets.count(set) != 1) {
612 // Also fail if same set is more than once in given list.
616 // Also fail if same set is more than once in given list.
613 return false;
617 return false;
614 }
618 }
615 }
619 }
616
620
617 foreach (QBarSet* set, sets) {
621 foreach (QBarSet* set, sets) {
618 m_barSets.removeOne(set);
622 m_barSets.removeOne(set);
619 QObject::disconnect(set->d_ptr.data(), SIGNAL(updatedBars()), this, SIGNAL(updatedBars()));
623 QObject::disconnect(set->d_ptr.data(), SIGNAL(updatedBars()), this, SIGNAL(updatedBars()));
620 QObject::disconnect(set->d_ptr.data(), SIGNAL(restructuredBars()), this, SIGNAL(restructuredBars()));
624 QObject::disconnect(set->d_ptr.data(), SIGNAL(restructuredBars()), this, SIGNAL(restructuredBars()));
621 }
625 }
622
626
623 if (m_dataset) {
627 if (m_dataset) {
624 m_dataset->updateSeries(q); // this notifies legend
628 m_dataset->updateSeries(q); // this notifies legend
625 }
629 }
626 emit restructuredBars(); // this notifies barchartitem
630 emit restructuredBars(); // this notifies barchartitem
627 return true;
631 return true;
628 }
632 }
629
633
630 bool QBarSeriesPrivate::insert(int index, QBarSet *set)
634 bool QBarSeriesPrivate::insert(int index, QBarSet *set)
631 {
635 {
632 Q_Q(QBarSeries);
636 Q_Q(QBarSeries);
633 if ((m_barSets.contains(set)) || (set == 0)) {
637 if ((m_barSets.contains(set)) || (set == 0)) {
634 // Fail if set is already in list or set is null.
638 // Fail if set is already in list or set is null.
635 return false;
639 return false;
636 }
640 }
637 m_barSets.insert(index, set);
641 m_barSets.insert(index, set);
638 QObject::connect(set->d_ptr.data(), SIGNAL(updatedBars()), this, SIGNAL(updatedBars()));
642 QObject::connect(set->d_ptr.data(), SIGNAL(updatedBars()), this, SIGNAL(updatedBars()));
639 QObject::connect(set->d_ptr.data(), SIGNAL(restructuredBars()), this, SIGNAL(restructuredBars()));
643 QObject::connect(set->d_ptr.data(), SIGNAL(restructuredBars()), this, SIGNAL(restructuredBars()));
640 if (m_dataset) {
644 if (m_dataset) {
641 m_dataset->updateSeries(q); // this notifies legend
645 m_dataset->updateSeries(q); // this notifies legend
642 }
646 }
643 emit restructuredBars(); // this notifies barchartitem
647 emit restructuredBars(); // this notifies barchartitem
644 return true;
648 return true;
645 }
649 }
646
650
647 #include "moc_qbarseries.cpp"
651 #include "moc_qbarseries.cpp"
648 #include "moc_qbarseries_p.cpp"
652 #include "moc_qbarseries_p.cpp"
649
653
650 QTCOMMERCIALCHART_END_NAMESPACE
654 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,225 +1,224
1 /****************************************************************************
1 /****************************************************************************
2 **
2 **
3 ** Copyright (C) 2012 Digia Plc
3 ** Copyright (C) 2012 Digia Plc
4 ** All rights reserved.
4 ** All rights reserved.
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 **
6 **
7 ** This file is part of the Qt Commercial Charts Add-on.
7 ** This file is part of the Qt Commercial Charts Add-on.
8 **
8 **
9 ** $QT_BEGIN_LICENSE$
9 ** $QT_BEGIN_LICENSE$
10 ** Licensees holding valid Qt Commercial licenses may use this file in
10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 ** accordance with the Qt Commercial License Agreement provided with the
11 ** accordance with the Qt Commercial License Agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia.
13 ** a written agreement between you and Digia.
14 **
14 **
15 ** If you have questions regarding the use of this file, please use
15 ** If you have questions regarding the use of this file, please use
16 ** contact form at http://qt.digia.com
16 ** contact form at http://qt.digia.com
17 ** $QT_END_LICENSE$
17 ** $QT_END_LICENSE$
18 **
18 **
19 ****************************************************************************/
19 ****************************************************************************/
20
20
21 #include "qsplineseries.h"
21 #include "qsplineseries.h"
22 #include "qsplineseries_p.h"
22 #include "qsplineseries_p.h"
23 #include "splinechartitem_p.h"
23 #include "splinechartitem_p.h"
24 #include "chartdataset_p.h"
24 #include "chartdataset_p.h"
25 #include "charttheme_p.h"
25 #include "charttheme_p.h"
26 #include "chartanimator_p.h"
26 #include "chartanimator_p.h"
27
27
28 /*!
28 /*!
29 \class QSplineSeries
29 \class QSplineSeries
30 \brief Series type used to store data needed to draw a spline.
30 \brief Series type used to store data needed to draw a spline.
31
31
32 QSplineSeries stores the data points along with the segment control points needed by QPainterPath to draw spline
32 QSplineSeries stores the data points along with the segment control points needed by QPainterPath to draw spline
33 Control points are automatically calculated when data changes. The algorithm computes the points so that the normal spline can be drawn.
33 Control points are automatically calculated when data changes. The algorithm computes the points so that the normal spline can be drawn.
34
34
35 \image examples_splinechart.png
35 \image examples_splinechart.png
36
36
37 Creating basic spline chart is simple:
37 Creating basic spline chart is simple:
38 \code
38 \code
39 QSplineSeries* series = new QSplineSeries();
39 QSplineSeries* series = new QSplineSeries();
40 series->append(0, 6);
40 series->append(0, 6);
41 series->append(2, 4);
41 series->append(2, 4);
42 ...
42 ...
43 chart->addSeries(series);
43 chart->addSeries(series);
44 \endcode
44 \endcode
45 */
45 */
46
46
47 /*!
47 /*!
48 \fn QSeriesType QSplineSeries::type() const
48 \fn QSeriesType QSplineSeries::type() const
49 Returns the type of the series
49 Returns the type of the series
50 */
50 */
51
51
52 QTCOMMERCIALCHART_BEGIN_NAMESPACE
52 QTCOMMERCIALCHART_BEGIN_NAMESPACE
53
53
54 /*!
54 /*!
55 Constructs empty series object which is a child of \a parent.
55 Constructs empty series object which is a child of \a parent.
56 When series object is added to QChartView or QChart instance then the ownerships is transferred.
56 When series object is added to QChartView or QChart instance then the ownerships is transferred.
57 */
57 */
58
58
59 QSplineSeries::QSplineSeries(QObject *parent) :
59 QSplineSeries::QSplineSeries(QObject *parent) :
60 QLineSeries(*new QSplineSeriesPrivate(this),parent)
60 QLineSeries(*new QSplineSeriesPrivate(this),parent)
61 {
61 {
62 Q_D(QSplineSeries);
62 Q_D(QSplineSeries);
63 QObject::connect(this,SIGNAL(pointAdded(int)), d, SLOT(updateControlPoints()));
63 QObject::connect(this,SIGNAL(pointAdded(int)), d, SLOT(updateControlPoints()));
64 QObject::connect(this,SIGNAL(pointRemoved(int)), d, SLOT(updateControlPoints()));
64 QObject::connect(this,SIGNAL(pointRemoved(int)), d, SLOT(updateControlPoints()));
65 QObject::connect(this,SIGNAL(pointReplaced(int)), d, SLOT(updateControlPoints()));
65 QObject::connect(this,SIGNAL(pointReplaced(int)), d, SLOT(updateControlPoints()));
66 }
66 }
67
67
68 /*!
68 /*!
69 Destroys the object.
69 Destroys the object.
70 */
70 */
71 QSplineSeries::~QSplineSeries()
71 QSplineSeries::~QSplineSeries()
72 {
72 {
73 Q_D(QSplineSeries);
73 Q_D(QSplineSeries);
74 if(d->m_dataset){
74 if(d->m_dataset){
75 d->m_dataset->removeSeries(this);
75 d->m_dataset->removeSeries(this);
76 }
76 }
77 }
77 }
78
78
79 QAbstractSeries::SeriesType QSplineSeries::type() const
79 QAbstractSeries::SeriesType QSplineSeries::type() const
80 {
80 {
81 return QAbstractSeries::SeriesTypeSpline;
81 return QAbstractSeries::SeriesTypeSpline;
82 }
82 }
83
83
84 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
84 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
85
85
86 QSplineSeriesPrivate::QSplineSeriesPrivate(QSplineSeries* q):QLineSeriesPrivate(q)
86 QSplineSeriesPrivate::QSplineSeriesPrivate(QSplineSeries* q):QLineSeriesPrivate(q)
87 {
87 {
88 }
88 }
89
89
90 /*!
90 /*!
91 Calculates control points which are needed by QPainterPath.cubicTo function to draw the cubic Bezier cureve between two points.
91 Calculates control points which are needed by QPainterPath.cubicTo function to draw the cubic Bezier cureve between two points.
92 */
92 */
93 void QSplineSeriesPrivate::calculateControlPoints()
93 void QSplineSeriesPrivate::calculateControlPoints()
94 {
94 {
95 Q_Q(QSplineSeries);
95 Q_Q(QSplineSeries);
96
96
97 const QList<QPointF>& points = q->points();
97 const QList<QPointF>& points = q->points();
98
98
99 int n = points.count() - 1;
99 int n = points.count() - 1;
100
100
101 if (n == 1)
101 if (n == 1)
102 {
102 {
103 //for n==1
103 //for n==1
104 m_controlPoints[0].setX((2 * points[0].x() + points[1].x()) / 3);
104 m_controlPoints[0].setX((2 * points[0].x() + points[1].x()) / 3);
105 m_controlPoints[0].setY((2 * points[0].y() + points[1].y()) / 3);
105 m_controlPoints[0].setY((2 * points[0].y() + points[1].y()) / 3);
106 m_controlPoints[1].setX(2 * m_controlPoints[0].x() - points[0].x());
106 m_controlPoints[1].setX(2 * m_controlPoints[0].x() - points[0].x());
107 m_controlPoints[1].setY(2 * m_controlPoints[0].y() - points[0].y());
107 m_controlPoints[1].setY(2 * m_controlPoints[0].y() - points[0].y());
108 return;
108 return;
109 }
109 }
110
110
111 // Calculate first Bezier control points
111 // Calculate first Bezier control points
112 // Right hand side vector
113 // Set of equations for P0 to Pn points.
112 // Set of equations for P0 to Pn points.
114 //
113 //
115 // | 2 1 0 0 ... 0 0 0 ... 0 0 0 | | P1_1 | | P0 + 2 * P1 |
114 // | 2 1 0 0 ... 0 0 0 ... 0 0 0 | | P1_1 | | P0 + 2 * P1 |
116 // | 1 4 1 0 ... 0 0 0 ... 0 0 0 | | P1_2 | | 4 * P1 + 2 * P2 |
115 // | 1 4 1 0 ... 0 0 0 ... 0 0 0 | | P1_2 | | 4 * P1 + 2 * P2 |
117 // | 0 1 4 1 ... 0 0 0 ... 0 0 0 | | P1_3 | | 4 * P2 + 2 * P3 |
116 // | 0 1 4 1 ... 0 0 0 ... 0 0 0 | | P1_3 | | 4 * P2 + 2 * P3 |
118 // | . . . . . . . . . . . . | | ... | | ... |
117 // | . . . . . . . . . . . . | | ... | | ... |
119 // | 0 0 0 0 ... 1 4 1 ... 0 0 0 | * | P1_i | = | 4 * P(i-1) + 2 * Pi |
118 // | 0 0 0 0 ... 1 4 1 ... 0 0 0 | * | P1_i | = | 4 * P(i-1) + 2 * Pi |
120 // | . . . . . . . . . . . . | | ... | | ... |
119 // | . . . . . . . . . . . . | | ... | | ... |
121 // | 0 0 0 0 0 0 0 0 ... 1 4 1 | | P1_(n-1)| | 4 * P(n-2) + 2 * P(n-1) |
120 // | 0 0 0 0 0 0 0 0 ... 1 4 1 | | P1_(n-1)| | 4 * P(n-2) + 2 * P(n-1) |
122 // | 0 0 0 0 0 0 0 0 ... 0 2 7 | | P1_n | | 8 * P(n-1) + Pn |
121 // | 0 0 0 0 0 0 0 0 ... 0 2 7 | | P1_n | | 8 * P(n-1) + Pn |
123 //
122 //
124 QVector<qreal> vector;
123 QVector<qreal> vector;
125 vector.resize(n);
124 vector.resize(n);
126
125
127 vector[0] = points[0].x() + 2 * points[1].x();
126 vector[0] = points[0].x() + 2 * points[1].x();
128
127
129
128
130 for (int i = 1; i < n - 1; ++i){
129 for (int i = 1; i < n - 1; ++i){
131 vector[i] = 4 * points[i].x() + 2 * points[i + 1].x();
130 vector[i] = 4 * points[i].x() + 2 * points[i + 1].x();
132 }
131 }
133
132
134 vector[n - 1] = (8 * points[n-1].x() + points[n].x()) / 2.0;
133 vector[n - 1] = (8 * points[n-1].x() + points[n].x()) / 2.0;
135
134
136 QVector<qreal> xControl = firstControlPoints(vector);
135 QVector<qreal> xControl = firstControlPoints(vector);
137
136
138 vector[0] = points[0].y() + 2 * points[1].y();
137 vector[0] = points[0].y() + 2 * points[1].y();
139
138
140 for (int i = 1; i < n - 1; ++i) {
139 for (int i = 1; i < n - 1; ++i) {
141 vector[i] = 4 * points[i].y() + 2 * points[i + 1].y();
140 vector[i] = 4 * points[i].y() + 2 * points[i + 1].y();
142 }
141 }
143
142
144 vector[n - 1] = (8 * points[n-1].y() + points[n].y()) / 2.0;
143 vector[n - 1] = (8 * points[n-1].y() + points[n].y()) / 2.0;
145
144
146 QVector<qreal> yControl = firstControlPoints(vector);
145 QVector<qreal> yControl = firstControlPoints(vector);
147
146
148 for (int i = 0,j =0; i < n; ++i, ++j) {
147 for (int i = 0,j =0; i < n; ++i, ++j) {
149
148
150 m_controlPoints[j].setX(xControl[i]);
149 m_controlPoints[j].setX(xControl[i]);
151 m_controlPoints[j].setY(yControl[i]);
150 m_controlPoints[j].setY(yControl[i]);
152
151
153 j++;
152 j++;
154
153
155 if (i < n - 1){
154 if (i < n - 1){
156 m_controlPoints[j].setX(2 * points[i+1].x() - xControl[i + 1]);
155 m_controlPoints[j].setX(2 * points[i+1].x() - xControl[i + 1]);
157 m_controlPoints[j].setY(2 * points[i+1].y() - yControl[i + 1]);
156 m_controlPoints[j].setY(2 * points[i+1].y() - yControl[i + 1]);
158 }else{
157 }else{
159 m_controlPoints[j].setX((points[n].x() + xControl[n - 1]) / 2);
158 m_controlPoints[j].setX((points[n].x() + xControl[n - 1]) / 2);
160 m_controlPoints[j].setY((points[n].y() + yControl[n - 1]) / 2);
159 m_controlPoints[j].setY((points[n].y() + yControl[n - 1]) / 2);
161 }
160 }
162 }
161 }
163 }
162 }
164
163
165 QVector<qreal> QSplineSeriesPrivate::firstControlPoints(const QVector<qreal>& vector)
164 QVector<qreal> QSplineSeriesPrivate::firstControlPoints(const QVector<qreal>& vector)
166 {
165 {
167 QVector<qreal> result;
166 QVector<qreal> result;
168
167
169 int count = vector.count();
168 int count = vector.count();
170 result.resize(count);
169 result.resize(count);
171 result[0] = vector[0] / 2.0;
170 result[0] = vector[0] / 2.0;
172
171
173 QVector<qreal> temp;
172 QVector<qreal> temp;
174 temp.resize(count);
173 temp.resize(count);
175 temp[0] = 0;
174 temp[0] = 0;
176
175
177 qreal b = 2.0;
176 qreal b = 2.0;
178
177
179 for (int i = 1; i < count; i++) {
178 for (int i = 1; i < count; i++) {
180 temp[i] = 1 / b;
179 temp[i] = 1 / b;
181 b = (i < count - 1 ? 4.0 : 3.5) - temp[i];
180 b = (i < count - 1 ? 4.0 : 3.5) - temp[i];
182 result[i]=(vector[i] - result[i - 1]) / b;
181 result[i]=(vector[i] - result[i - 1]) / b;
183 }
182 }
184 for (int i = 1; i < count; i++)
183 for (int i = 1; i < count; i++)
185 result[count - i - 1] -= temp[count - i] * result[count - i];
184 result[count - i - 1] -= temp[count - i] * result[count - i];
186
185
187 return result;
186 return result;
188 }
187 }
189
188
190 QPointF QSplineSeriesPrivate::controlPoint(int index) const
189 QPointF QSplineSeriesPrivate::controlPoint(int index) const
191 {
190 {
192 // Q_D(const QSplineSeries);
191 // Q_D(const QSplineSeries);
193 // return d->m_controlPoints[index];
192 // return d->m_controlPoints[index];
194 return m_controlPoints[index];
193 return m_controlPoints[index];
195 }
194 }
196
195
197 /*!
196 /*!
198 Updates the control points, besed on currently avaiable knots.
197 Updates the control points, besed on currently avaiable knots.
199 */
198 */
200 void QSplineSeriesPrivate::updateControlPoints()
199 void QSplineSeriesPrivate::updateControlPoints()
201 {
200 {
202 Q_Q(QSplineSeries);
201 Q_Q(QSplineSeries);
203 if (q->count() > 1) {
202 if (q->count() > 1) {
204 m_controlPoints.resize(2*q->count()-2);
203 m_controlPoints.resize(2*q->count()-2);
205 calculateControlPoints();
204 calculateControlPoints();
206 }
205 }
207 }
206 }
208
207
209 Chart* QSplineSeriesPrivate::createGraphics(ChartPresenter* presenter)
208 Chart* QSplineSeriesPrivate::createGraphics(ChartPresenter* presenter)
210 {
209 {
211 Q_Q(QSplineSeries);
210 Q_Q(QSplineSeries);
212 SplineChartItem* spline = new SplineChartItem(q,presenter);
211 SplineChartItem* spline = new SplineChartItem(q,presenter);
213 if(presenter->animationOptions().testFlag(QChart::SeriesAnimations)) {
212 if(presenter->animationOptions().testFlag(QChart::SeriesAnimations)) {
214 spline->setAnimator(presenter->animator());
213 spline->setAnimator(presenter->animator());
215 spline->setAnimation(new SplineAnimation(spline));
214 spline->setAnimation(new SplineAnimation(spline));
216 }
215 }
217
216
218 presenter->chartTheme()->decorate(q, presenter->dataSet()->seriesIndex(q));
217 presenter->chartTheme()->decorate(q, presenter->dataSet()->seriesIndex(q));
219 return spline;
218 return spline;
220 }
219 }
221
220
222 #include "moc_qsplineseries.cpp"
221 #include "moc_qsplineseries.cpp"
223 #include "moc_qsplineseries_p.cpp"
222 #include "moc_qsplineseries_p.cpp"
224
223
225 QTCOMMERCIALCHART_END_NAMESPACE
224 QTCOMMERCIALCHART_END_NAMESPACE
General Comments 0
You need to be logged in to leave comments. Login now