##// END OF EJS Templates
random doc updates
Jani Honkonen -
r1351:e5c3ac6bb1ee
parent child
Show More
@@ -1,285 +1,285
1 /****************************************************************************
1 /****************************************************************************
2 **
2 **
3 ** Copyright (C) 2012 Digia Plc
3 ** Copyright (C) 2012 Digia Plc
4 ** All rights reserved.
4 ** All rights reserved.
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 **
6 **
7 ** This file is part of the Qt Commercial Charts Add-on.
7 ** This file is part of the Qt Commercial Charts Add-on.
8 **
8 **
9 ** $QT_BEGIN_LICENSE$
9 ** $QT_BEGIN_LICENSE$
10 ** Licensees holding valid Qt Commercial licenses may use this file in
10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 ** accordance with the Qt Commercial License Agreement provided with the
11 ** accordance with the Qt Commercial License Agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia.
13 ** a written agreement between you and Digia.
14 **
14 **
15 ** If you have questions regarding the use of this file, please use
15 ** If you have questions regarding the use of this file, please use
16 ** contact form at http://qt.digia.com
16 ** contact form at http://qt.digia.com
17 ** $QT_END_LICENSE$
17 ** $QT_END_LICENSE$
18 **
18 **
19 ****************************************************************************/
19 ****************************************************************************/
20
20
21 #include "qareaseries.h"
21 #include "qareaseries.h"
22 #include "qareaseries_p.h"
22 #include "qareaseries_p.h"
23 #include "qlineseries.h"
23 #include "qlineseries.h"
24 #include "areachartitem_p.h"
24 #include "areachartitem_p.h"
25 #include "legendmarker_p.h"
25 #include "legendmarker_p.h"
26 #include "domain_p.h"
26 #include "domain_p.h"
27 #include "chartdataset_p.h"
27 #include "chartdataset_p.h"
28 #include "charttheme_p.h"
28 #include "charttheme_p.h"
29 #include "chartanimator_p.h"
29 #include "chartanimator_p.h"
30
30
31 QTCOMMERCIALCHART_BEGIN_NAMESPACE
31 QTCOMMERCIALCHART_BEGIN_NAMESPACE
32
32
33 /*!
33 /*!
34 \class QAreaSeries
34 \class QAreaSeries
35 \brief The QAreaSeries class is used for making area charts.
35 \brief The QAreaSeries class is used for making area charts.
36
36
37 \mainclass
37 \mainclass
38
38
39 An area chart is used to show quantitative data. It is based on line chart, in the way that area between axis and the line
39 An area chart is used to show quantitative data. It is based on line chart, in the way that area between axis and the line
40 is emphasized with color. Since the area chart is based on line chart, QAreaSeries constructor needs QLineSeries instance,
40 is emphasized with color. Since the area chart is based on line chart, QAreaSeries constructor needs QLineSeries instance,
41 which defines "upper" boundary of the area. "Lower" boundary is defined by default by axis X. Instead of axis X "lower" boundary can be specified by other line.
41 which defines "upper" boundary of the area. "Lower" boundary is defined by default by axis X. Instead of axis X "lower" boundary can be specified by other line.
42 In that case QAreaSeries should be initiated with two QLineSerie instances. Please note terms "upper" and "lower" boundary can be misleading in cases
42 In that case QAreaSeries should be initiated with two QLineSerie instances. Please note terms "upper" and "lower" boundary can be misleading in cases
43 where "lower" boundary had bigger values than the "upper" one, however the main point that area between these two boundary lines will be filled.
43 where "lower" boundary had bigger values than the "upper" one, however the main point that area between these two boundary lines will be filled.
44
44
45 See the \l {AreaChart Example} {area chart example} to learn how to create a simple area chart.
45 See the \l {AreaChart Example} {area chart example} to learn how to create a simple area chart.
46 \image examples_areachart.png
46 \image examples_areachart.png
47 */
47 */
48
48
49 /*!
49 /*!
50 \fn QLineSeries* QAreaSeries::upperSeries() const
50 \fn QLineSeries* QAreaSeries::upperSeries() const
51 \brief Returns upperSeries used to define one of area boundaries.
51 \brief Returns upperSeries used to define one of area boundaries.
52 */
52 */
53
53
54 /*!
54 /*!
55 \fn QLineSeries* QAreaSeries::lowerSeries() const
55 \fn QLineSeries* QAreaSeries::lowerSeries() const
56 \brief Returns lowerSeries used to define one of area boundaries. Note if QAreaSeries where counstucted wihtout a\ lowerSeries
56 \brief Returns lowerSeries used to define one of area boundaries. Note if QAreaSeries where counstucted wihtout a\ lowerSeries
57 this function return Null pointer.
57 this function return Null pointer.
58 */
58 */
59
59
60 /*!
60 /*!
61 \fn QPen QAreaSeries::pen() const
61 \fn QPen QAreaSeries::pen() const
62 \brief Returns the pen used to draw line for this series.
62 \brief Returns the pen used to draw line for this series.
63 \sa setPen()
63 \sa setPen()
64 */
64 */
65
65
66 /*!
66 /*!
67 \fn QPen QAreaSeries::brush() const
67 \fn QPen QAreaSeries::brush() const
68 \brief Returns the brush used to draw line for this series.
68 \brief Returns the brush used to draw line for this series.
69 \sa setBrush()
69 \sa setBrush()
70 */
70 */
71
71
72 /*!
72 /*!
73 \fn bool QAreaSeries::pointsVisible() const
73 \fn bool QAreaSeries::pointsVisible() const
74 \brief Returns if the points are drawn for this series.
74 \brief Returns if the points are drawn for this series.
75 \sa setPointsVisible()
75 \sa setPointsVisible()
76 */
76 */
77
77
78 /*!
78 /*!
79 \fn void QAreaSeries::clicked(const QPointF& point)
79 \fn void QAreaSeries::clicked(const QPointF& point)
80 \brief Signal is emitted when user clicks the \a point on area chart.
80 \brief Signal is emitted when user clicks the \a point on area chart.
81 */
81 */
82
82
83 /*!
83 /*!
84 \fn void QAreaSeries::selected()
84 \fn void QAreaSeries::selected()
85
85
86 The signal is emitted if the user selects/deselects the XY series. The logic for maintaining selections should be
86 The signal is emitted if the user selects/deselects the XY series. The logic for maintaining selections should be
87 implemented by the user of QAreaSeries API.
87 implemented by the user of QAreaSeries API.
88 */
88 */
89
89
90 /*!
90 /*!
91 \fn void QAreaSeriesPrivate::updated()
91 \fn void QAreaSeriesPrivate::updated()
92 \brief \internal
92 \brief \internal
93 */
93 */
94
94
95 /*!
95 /*!
96 Constructs area series object which is a child of \a upperSeries. Area will be spanned between \a
96 Constructs area series object which is a child of \a upperSeries. Area will be spanned between \a
97 upperSeries line and \a lowerSeries line. If no \a lowerSeries is passed to constructor, area is specified by axis x (y=0) instead.
97 upperSeries line and \a lowerSeries line. If no \a lowerSeries is passed to constructor, area is specified by axis x (y=0) instead.
98 When series object is added to QChartView or QChart instance ownerships is transferred.
98 When series object is added to QChartView or QChart instance ownerships is transferred.
99 */
99 */
100 QAreaSeries::QAreaSeries(QLineSeries *upperSeries, QLineSeries *lowerSeries)
100 QAreaSeries::QAreaSeries(QLineSeries *upperSeries, QLineSeries *lowerSeries)
101 : QAbstractSeries(*new QAreaSeriesPrivate(upperSeries,lowerSeries,this),upperSeries)
101 : QAbstractSeries(*new QAreaSeriesPrivate(upperSeries,lowerSeries,this),upperSeries)
102 {
102 {
103 }
103 }
104
104
105 /*!
105 /*!
106 Constructs area series object without upper or lower series.
106 Constructs area series object without upper or lower series with \a parent object.
107 */
107 */
108 QAreaSeries::QAreaSeries(QObject *parent)
108 QAreaSeries::QAreaSeries(QObject *parent)
109 : QAbstractSeries(*new QAreaSeriesPrivate(0, 0, this), parent)
109 : QAbstractSeries(*new QAreaSeriesPrivate(0, 0, this), parent)
110 {
110 {
111 }
111 }
112
112
113 /*!
113 /*!
114 Destroys the object. Series added to QChartView or QChart instances are owned by those,
114 Destroys the object. Series added to QChartView or QChart instances are owned by those,
115 and are deleted when mentioned object are destroyed.
115 and are deleted when mentioned object are destroyed.
116 */
116 */
117 QAreaSeries::~QAreaSeries()
117 QAreaSeries::~QAreaSeries()
118 {
118 {
119 }
119 }
120
120
121 /*!
121 /*!
122 Returns QChartSeries::SeriesTypeArea.
122 Returns QChartSeries::SeriesTypeArea.
123 */
123 */
124 QAbstractSeries::SeriesType QAreaSeries::type() const
124 QAbstractSeries::SeriesType QAreaSeries::type() const
125 {
125 {
126 return QAbstractSeries::SeriesTypeArea;
126 return QAbstractSeries::SeriesTypeArea;
127 }
127 }
128
128
129 void QAreaSeries::setUpperSeries(QLineSeries* series)
129 void QAreaSeries::setUpperSeries(QLineSeries* series)
130 {
130 {
131 Q_D(QAreaSeries);
131 Q_D(QAreaSeries);
132 d->m_upperSeries = series;
132 d->m_upperSeries = series;
133 }
133 }
134
134
135 QLineSeries* QAreaSeries::upperSeries() const
135 QLineSeries* QAreaSeries::upperSeries() const
136 {
136 {
137 Q_D(const QAreaSeries);
137 Q_D(const QAreaSeries);
138 return d->m_upperSeries;
138 return d->m_upperSeries;
139 }
139 }
140
140
141 void QAreaSeries::setLowerSeries(QLineSeries* series)
141 void QAreaSeries::setLowerSeries(QLineSeries* series)
142 {
142 {
143 Q_D(QAreaSeries);
143 Q_D(QAreaSeries);
144 d->m_lowerSeries = series;
144 d->m_lowerSeries = series;
145 }
145 }
146
146
147 QLineSeries* QAreaSeries::lowerSeries() const
147 QLineSeries* QAreaSeries::lowerSeries() const
148 {
148 {
149 Q_D(const QAreaSeries);
149 Q_D(const QAreaSeries);
150 return d->m_lowerSeries;
150 return d->m_lowerSeries;
151 }
151 }
152
152
153 /*!
153 /*!
154 Sets \a pen used for drawing area outline.
154 Sets \a pen used for drawing area outline.
155 */
155 */
156 void QAreaSeries::setPen(const QPen &pen)
156 void QAreaSeries::setPen(const QPen &pen)
157 {
157 {
158 Q_D(QAreaSeries);
158 Q_D(QAreaSeries);
159 if (d->m_pen != pen) {
159 if (d->m_pen != pen) {
160 d->m_pen = pen;
160 d->m_pen = pen;
161 emit d->updated();
161 emit d->updated();
162 }
162 }
163 }
163 }
164
164
165 QPen QAreaSeries::pen() const
165 QPen QAreaSeries::pen() const
166 {
166 {
167 Q_D(const QAreaSeries);
167 Q_D(const QAreaSeries);
168 return d->m_pen;
168 return d->m_pen;
169 }
169 }
170
170
171 /*!
171 /*!
172 Sets \a brush used for filling the area.
172 Sets \a brush used for filling the area.
173 */
173 */
174 void QAreaSeries::setBrush(const QBrush &brush)
174 void QAreaSeries::setBrush(const QBrush &brush)
175 {
175 {
176 Q_D(QAreaSeries);
176 Q_D(QAreaSeries);
177 if (d->m_brush != brush) {
177 if (d->m_brush != brush) {
178 d->m_brush = brush;
178 d->m_brush = brush;
179 emit d->updated();
179 emit d->updated();
180 }
180 }
181 }
181 }
182
182
183 QBrush QAreaSeries::brush() const
183 QBrush QAreaSeries::brush() const
184 {
184 {
185 Q_D(const QAreaSeries);
185 Q_D(const QAreaSeries);
186 return d->m_brush;
186 return d->m_brush;
187 }
187 }
188 /*!
188 /*!
189 Sets if data points are \a visible and should be drawn on line.
189 Sets if data points are \a visible and should be drawn on line.
190 */
190 */
191 void QAreaSeries::setPointsVisible(bool visible)
191 void QAreaSeries::setPointsVisible(bool visible)
192 {
192 {
193 Q_D(QAreaSeries);
193 Q_D(QAreaSeries);
194 if (d->m_pointsVisible != visible) {
194 if (d->m_pointsVisible != visible) {
195 d->m_pointsVisible = visible;
195 d->m_pointsVisible = visible;
196 emit d->updated();
196 emit d->updated();
197 }
197 }
198 }
198 }
199
199
200 bool QAreaSeries::pointsVisible() const
200 bool QAreaSeries::pointsVisible() const
201 {
201 {
202 Q_D(const QAreaSeries);
202 Q_D(const QAreaSeries);
203 return d->m_pointsVisible;
203 return d->m_pointsVisible;
204 }
204 }
205
205
206 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
206 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
207
207
208 QAreaSeriesPrivate::QAreaSeriesPrivate(QLineSeries *upperSeries, QLineSeries *lowerSeries,QAreaSeries* q) :
208 QAreaSeriesPrivate::QAreaSeriesPrivate(QLineSeries *upperSeries, QLineSeries *lowerSeries,QAreaSeries* q) :
209 QAbstractSeriesPrivate(q),
209 QAbstractSeriesPrivate(q),
210 m_upperSeries(upperSeries),
210 m_upperSeries(upperSeries),
211 m_lowerSeries(lowerSeries),
211 m_lowerSeries(lowerSeries),
212 m_pointsVisible(false)
212 m_pointsVisible(false)
213 {
213 {
214 }
214 }
215
215
216 void QAreaSeriesPrivate::scaleDomain(Domain& domain)
216 void QAreaSeriesPrivate::scaleDomain(Domain& domain)
217 {
217 {
218 Q_Q(QAreaSeries);
218 Q_Q(QAreaSeries);
219
219
220 qreal minX(domain.minX());
220 qreal minX(domain.minX());
221 qreal minY(domain.minY());
221 qreal minY(domain.minY());
222 qreal maxX(domain.maxX());
222 qreal maxX(domain.maxX());
223 qreal maxY(domain.maxY());
223 qreal maxY(domain.maxY());
224 int tickXCount(domain.tickXCount());
224 int tickXCount(domain.tickXCount());
225 int tickYCount(domain.tickYCount());
225 int tickYCount(domain.tickYCount());
226
226
227 QLineSeries* upperSeries = q->upperSeries();
227 QLineSeries* upperSeries = q->upperSeries();
228 QLineSeries* lowerSeries = q->lowerSeries();
228 QLineSeries* lowerSeries = q->lowerSeries();
229
229
230 const QList<QPointF>& points = upperSeries->points();
230 const QList<QPointF>& points = upperSeries->points();
231
231
232 for (int i = 0; i < points.count(); i++)
232 for (int i = 0; i < points.count(); i++)
233 {
233 {
234 qreal x = points[i].x();
234 qreal x = points[i].x();
235 qreal y = points[i].y();
235 qreal y = points[i].y();
236 minX = qMin(minX, x);
236 minX = qMin(minX, x);
237 minY = qMin(minY, y);
237 minY = qMin(minY, y);
238 maxX = qMax(maxX, x);
238 maxX = qMax(maxX, x);
239 maxY = qMax(maxY, y);
239 maxY = qMax(maxY, y);
240 }
240 }
241 if(lowerSeries) {
241 if(lowerSeries) {
242
242
243 const QList<QPointF>& points = lowerSeries->points();
243 const QList<QPointF>& points = lowerSeries->points();
244
244
245 for (int i = 0; i < points.count(); i++)
245 for (int i = 0; i < points.count(); i++)
246 {
246 {
247 qreal x = points[i].x();
247 qreal x = points[i].x();
248 qreal y = points[i].y();
248 qreal y = points[i].y();
249 minX = qMin(minX, x);
249 minX = qMin(minX, x);
250 minY = qMin(minY, y);
250 minY = qMin(minY, y);
251 maxX = qMax(maxX, x);
251 maxX = qMax(maxX, x);
252 maxY = qMax(maxY, y);
252 maxY = qMax(maxY, y);
253 }}
253 }}
254
254
255 domain.setRange(minX,maxX,minY,maxY,tickXCount,tickYCount);
255 domain.setRange(minX,maxX,minY,maxY,tickXCount,tickYCount);
256 }
256 }
257
257
258 Chart* QAreaSeriesPrivate::createGraphics(ChartPresenter* presenter)
258 Chart* QAreaSeriesPrivate::createGraphics(ChartPresenter* presenter)
259 {
259 {
260 Q_Q(QAreaSeries);
260 Q_Q(QAreaSeries);
261
261
262 AreaChartItem* area = new AreaChartItem(q,presenter);
262 AreaChartItem* area = new AreaChartItem(q,presenter);
263 if(presenter->animationOptions().testFlag(QChart::SeriesAnimations)) {
263 if(presenter->animationOptions().testFlag(QChart::SeriesAnimations)) {
264 area->upperLineItem()->setAnimator(presenter->animator());
264 area->upperLineItem()->setAnimator(presenter->animator());
265 area->upperLineItem()->setAnimation(new XYAnimation(area->upperLineItem()));
265 area->upperLineItem()->setAnimation(new XYAnimation(area->upperLineItem()));
266 if(q->lowerSeries()) {
266 if(q->lowerSeries()) {
267 area->lowerLineItem()->setAnimator(presenter->animator());
267 area->lowerLineItem()->setAnimator(presenter->animator());
268 area->lowerLineItem()->setAnimation(new XYAnimation(area->lowerLineItem()));
268 area->lowerLineItem()->setAnimation(new XYAnimation(area->lowerLineItem()));
269 }
269 }
270 }
270 }
271 presenter->chartTheme()->decorate(q, presenter->dataSet()->seriesIndex(q));
271 presenter->chartTheme()->decorate(q, presenter->dataSet()->seriesIndex(q));
272 return area;
272 return area;
273 }
273 }
274
274
275 QList<LegendMarker*> QAreaSeriesPrivate::createLegendMarker(QLegend* legend)
275 QList<LegendMarker*> QAreaSeriesPrivate::createLegendMarker(QLegend* legend)
276 {
276 {
277 Q_Q(QAreaSeries);
277 Q_Q(QAreaSeries);
278 QList<LegendMarker*> list;
278 QList<LegendMarker*> list;
279 return list << new AreaLegendMarker(q,legend);
279 return list << new AreaLegendMarker(q,legend);
280 }
280 }
281
281
282 #include "moc_qareaseries.cpp"
282 #include "moc_qareaseries.cpp"
283 #include "moc_qareaseries_p.cpp"
283 #include "moc_qareaseries_p.cpp"
284
284
285 QTCOMMERCIALCHART_END_NAMESPACE
285 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,128 +1,131
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 "qaxiscategories.h"
21 #include "qaxiscategories.h"
22 #include "qaxiscategories_p.h"
22 #include "qaxiscategories_p.h"
23
23
24 QTCOMMERCIALCHART_BEGIN_NAMESPACE
24 QTCOMMERCIALCHART_BEGIN_NAMESPACE
25
25
26 /*!
26 /*!
27 \class QAxisCategories
27 \class QAxisCategories
28 \brief The QAxisCategoriess class is used for manipulating axis's categories.
28 \brief The QAxisCategoriess class is used for manipulating axis's categories.
29 \mainclass
29 \mainclass
30
30
31 Each axis can have categories instead of numerical representation. The typical use case
31 Each axis can have categories instead of numerical representation. The typical use case
32 is bar chart, where categories are always show on X axis.
32 is bar chart, where categories are always show on X axis.
33 */
33 */
34
34
35
35
36 QAxisCategories::QAxisCategories():
36 QAxisCategories::QAxisCategories():
37 d_ptr(new QAxisCategoriesPrivate(this))
37 d_ptr(new QAxisCategoriesPrivate(this))
38 {
38 {
39
39
40 }
40 }
41
41
42 /*!
43 Destroys the object.
44 */
42 QAxisCategories::~QAxisCategories()
45 QAxisCategories::~QAxisCategories()
43 {
46 {
44
47
45 }
48 }
46
49
47 /*!
50 /*!
48 Inserts \a categories to axis. First item in list is assumed to be at x = 0, next at x = 1 and so on
51 Inserts \a categories to axis. First item in list is assumed to be at x = 0, next at x = 1 and so on
49 */
52 */
50 void QAxisCategories::insert(const QStringList &categories)
53 void QAxisCategories::insert(const QStringList &categories)
51 {
54 {
52 int i=0;
55 int i=0;
53 foreach (const QString& string , categories) {
56 foreach (const QString& string , categories) {
54 d_ptr->m_map.insert(i,string);
57 d_ptr->m_map.insert(i,string);
55 i++;
58 i++;
56 }
59 }
57 emit d_ptr->updated();
60 emit d_ptr->updated();
58 }
61 }
59
62
60
63
61 /*!
64 /*!
62 Inserts category, instead of \a value on axis a \a label will be shown.
65 Inserts category, instead of \a value on axis a \a label will be shown.
63 */
66 */
64 void QAxisCategories::insert(qreal value,QString label)
67 void QAxisCategories::insert(qreal value,QString label)
65 {
68 {
66 d_ptr->m_map.insert(value,label);
69 d_ptr->m_map.insert(value,label);
67 emit d_ptr->updated();
70 emit d_ptr->updated();
68 }
71 }
69
72
70 /*!
73 /*!
71 Removes category for \a value.
74 Removes category for \a value.
72 */
75 */
73 void QAxisCategories::remove(qreal value)
76 void QAxisCategories::remove(qreal value)
74 {
77 {
75 d_ptr->m_map.remove(value);
78 d_ptr->m_map.remove(value);
76 emit d_ptr->updated();
79 emit d_ptr->updated();
77 }
80 }
78
81
79 /*!
82 /*!
80 Removes all categories.
83 Removes all categories.
81 */
84 */
82 void QAxisCategories::clear()
85 void QAxisCategories::clear()
83 {
86 {
84 d_ptr->m_map.clear();
87 d_ptr->m_map.clear();
85 emit d_ptr->updated();
88 emit d_ptr->updated();
86 }
89 }
87
90
88 /*!
91 /*!
89 Returns number of categories.
92 Returns number of categories.
90 */
93 */
91 int QAxisCategories::count()
94 int QAxisCategories::count()
92 {
95 {
93 return d_ptr->m_map.count();
96 return d_ptr->m_map.count();
94 }
97 }
95
98
96 /*!
99 /*!
97 Returns all values of categories.
100 Returns all values of categories.
98 */
101 */
99 QList<qreal> QAxisCategories::values() const
102 QList<qreal> QAxisCategories::values() const
100 {
103 {
101 return d_ptr->m_map.keys();
104 return d_ptr->m_map.keys();
102 }
105 }
103
106
104 /*!
107 /*!
105 Returns label for given \a value.
108 Returns label for given \a value.
106 */
109 */
107 QString QAxisCategories::label(qreal value) const
110 QString QAxisCategories::label(qreal value) const
108 {
111 {
109 return d_ptr->m_map.value(value);
112 return d_ptr->m_map.value(value);
110 }
113 }
111
114
112 /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
115 /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
113
116
114 QAxisCategoriesPrivate::QAxisCategoriesPrivate(QAxisCategories *q):
117 QAxisCategoriesPrivate::QAxisCategoriesPrivate(QAxisCategories *q):
115 q_ptr(q)
118 q_ptr(q)
116 {
119 {
117
120
118 }
121 }
119
122
120 QAxisCategoriesPrivate::~QAxisCategoriesPrivate()
123 QAxisCategoriesPrivate::~QAxisCategoriesPrivate()
121 {
124 {
122
125
123 }
126 }
124
127
125 #include "moc_qaxiscategories.cpp"
128 #include "moc_qaxiscategories.cpp"
126 #include "moc_qaxiscategories_p.cpp"
129 #include "moc_qaxiscategories_p.cpp"
127
130
128 QTCOMMERCIALCHART_END_NAMESPACE
131 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,222 +1,225
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 /*!
69 Destroys the object.
70 */
68 QSplineSeries::~QSplineSeries()
71 QSplineSeries::~QSplineSeries()
69 {
72 {
70 Q_D(QSplineSeries);
73 Q_D(QSplineSeries);
71 if(d->m_dataset){
74 if(d->m_dataset){
72 d->m_dataset->removeSeries(this);
75 d->m_dataset->removeSeries(this);
73 }
76 }
74 }
77 }
75
78
76 QAbstractSeries::SeriesType QSplineSeries::type() const
79 QAbstractSeries::SeriesType QSplineSeries::type() const
77 {
80 {
78 return QAbstractSeries::SeriesTypeSpline;
81 return QAbstractSeries::SeriesTypeSpline;
79 }
82 }
80
83
81 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
84 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
82
85
83 QSplineSeriesPrivate::QSplineSeriesPrivate(QSplineSeries* q):QLineSeriesPrivate(q)
86 QSplineSeriesPrivate::QSplineSeriesPrivate(QSplineSeries* q):QLineSeriesPrivate(q)
84 {
87 {
85 }
88 }
86
89
87 /*!
90 /*!
88 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.
89 */
92 */
90 void QSplineSeriesPrivate::calculateControlPoints()
93 void QSplineSeriesPrivate::calculateControlPoints()
91 {
94 {
92 Q_Q(QSplineSeries);
95 Q_Q(QSplineSeries);
93
96
94 const QList<QPointF>& points = q->points();
97 const QList<QPointF>& points = q->points();
95
98
96 int n = points.count() - 1;
99 int n = points.count() - 1;
97
100
98 if (n == 1)
101 if (n == 1)
99 {
102 {
100 //for n==1
103 //for n==1
101 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);
102 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);
103 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());
104 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());
105 return;
108 return;
106 }
109 }
107
110
108 // Calculate first Bezier control points
111 // Calculate first Bezier control points
109 // Right hand side vector
112 // Right hand side vector
110 // Set of equations for P0 to Pn points.
113 // Set of equations for P0 to Pn points.
111 //
114 //
112 // | 2 1 0 0 ... 0 0 0 ... 0 0 0 | | P1_1 | | P0 + 2 * P1 |
115 // | 2 1 0 0 ... 0 0 0 ... 0 0 0 | | P1_1 | | P0 + 2 * P1 |
113 // | 1 4 1 0 ... 0 0 0 ... 0 0 0 | | P1_2 | | 4 * P1 + 2 * P2 |
116 // | 1 4 1 0 ... 0 0 0 ... 0 0 0 | | P1_2 | | 4 * P1 + 2 * P2 |
114 // | 0 1 4 1 ... 0 0 0 ... 0 0 0 | | P1_3 | | 4 * P2 + 2 * P3 |
117 // | 0 1 4 1 ... 0 0 0 ... 0 0 0 | | P1_3 | | 4 * P2 + 2 * P3 |
115 // | . . . . . . . . . . . . | | ... | | ... |
118 // | . . . . . . . . . . . . | | ... | | ... |
116 // | 0 0 0 0 ... 1 4 1 ... 0 0 0 | * | P1_i | = | 4 * P(i-1) + 2 * Pi |
119 // | 0 0 0 0 ... 1 4 1 ... 0 0 0 | * | P1_i | = | 4 * P(i-1) + 2 * Pi |
117 // | . . . . . . . . . . . . | | ... | | ... |
120 // | . . . . . . . . . . . . | | ... | | ... |
118 // | 0 0 0 0 0 0 0 0 ... 1 4 1 | | P1_(n-1)| | 4 * P(n-2) + 2 * P(n-1) |
121 // | 0 0 0 0 0 0 0 0 ... 1 4 1 | | P1_(n-1)| | 4 * P(n-2) + 2 * P(n-1) |
119 // | 0 0 0 0 0 0 0 0 ... 0 2 7 | | P1_n | | 8 * P(n-1) + Pn |
122 // | 0 0 0 0 0 0 0 0 ... 0 2 7 | | P1_n | | 8 * P(n-1) + Pn |
120 //
123 //
121 QVector<qreal> vector;
124 QVector<qreal> vector;
122 vector.resize(n);
125 vector.resize(n);
123
126
124 vector[0] = points[0].x() + 2 * points[1].x();
127 vector[0] = points[0].x() + 2 * points[1].x();
125
128
126
129
127 for (int i = 1; i < n - 1; ++i){
130 for (int i = 1; i < n - 1; ++i){
128 vector[i] = 4 * points[i].x() + 2 * points[i + 1].x();
131 vector[i] = 4 * points[i].x() + 2 * points[i + 1].x();
129 }
132 }
130
133
131 vector[n - 1] = (8 * points[n-1].x() + points[n].x()) / 2.0;
134 vector[n - 1] = (8 * points[n-1].x() + points[n].x()) / 2.0;
132
135
133 QVector<qreal> xControl = firstControlPoints(vector);
136 QVector<qreal> xControl = firstControlPoints(vector);
134
137
135 vector[0] = points[0].y() + 2 * points[1].y();
138 vector[0] = points[0].y() + 2 * points[1].y();
136
139
137 for (int i = 1; i < n - 1; ++i) {
140 for (int i = 1; i < n - 1; ++i) {
138 vector[i] = 4 * points[i].y() + 2 * points[i + 1].y();
141 vector[i] = 4 * points[i].y() + 2 * points[i + 1].y();
139 }
142 }
140
143
141 vector[n - 1] = (8 * points[n-1].y() + points[n].y()) / 2.0;
144 vector[n - 1] = (8 * points[n-1].y() + points[n].y()) / 2.0;
142
145
143 QVector<qreal> yControl = firstControlPoints(vector);
146 QVector<qreal> yControl = firstControlPoints(vector);
144
147
145 for (int i = 0,j =0; i < n; ++i, ++j) {
148 for (int i = 0,j =0; i < n; ++i, ++j) {
146
149
147 m_controlPoints[j].setX(xControl[i]);
150 m_controlPoints[j].setX(xControl[i]);
148 m_controlPoints[j].setY(yControl[i]);
151 m_controlPoints[j].setY(yControl[i]);
149
152
150 j++;
153 j++;
151
154
152 if (i < n - 1){
155 if (i < n - 1){
153 m_controlPoints[j].setX(2 * points[i+1].x() - xControl[i + 1]);
156 m_controlPoints[j].setX(2 * points[i+1].x() - xControl[i + 1]);
154 m_controlPoints[j].setY(2 * points[i+1].y() - yControl[i + 1]);
157 m_controlPoints[j].setY(2 * points[i+1].y() - yControl[i + 1]);
155 }else{
158 }else{
156 m_controlPoints[j].setX((points[n].x() + xControl[n - 1]) / 2);
159 m_controlPoints[j].setX((points[n].x() + xControl[n - 1]) / 2);
157 m_controlPoints[j].setY((points[n].y() + yControl[n - 1]) / 2);
160 m_controlPoints[j].setY((points[n].y() + yControl[n - 1]) / 2);
158 }
161 }
159 }
162 }
160 }
163 }
161
164
162 QVector<qreal> QSplineSeriesPrivate::firstControlPoints(const QVector<qreal>& vector)
165 QVector<qreal> QSplineSeriesPrivate::firstControlPoints(const QVector<qreal>& vector)
163 {
166 {
164 QVector<qreal> result;
167 QVector<qreal> result;
165
168
166 int count = vector.count();
169 int count = vector.count();
167 result.resize(count);
170 result.resize(count);
168 result[0] = vector[0] / 2.0;
171 result[0] = vector[0] / 2.0;
169
172
170 QVector<qreal> temp;
173 QVector<qreal> temp;
171 temp.resize(count);
174 temp.resize(count);
172 temp[0] = 0;
175 temp[0] = 0;
173
176
174 qreal b = 2.0;
177 qreal b = 2.0;
175
178
176 for (int i = 1; i < count; i++) {
179 for (int i = 1; i < count; i++) {
177 temp[i] = 1 / b;
180 temp[i] = 1 / b;
178 b = (i < count - 1 ? 4.0 : 3.5) - temp[i];
181 b = (i < count - 1 ? 4.0 : 3.5) - temp[i];
179 result[i]=(vector[i] - result[i - 1]) / b;
182 result[i]=(vector[i] - result[i - 1]) / b;
180 }
183 }
181 for (int i = 1; i < count; i++)
184 for (int i = 1; i < count; i++)
182 result[count - i - 1] -= temp[count - i] * result[count - i];
185 result[count - i - 1] -= temp[count - i] * result[count - i];
183
186
184 return result;
187 return result;
185 }
188 }
186
189
187 QPointF QSplineSeriesPrivate::controlPoint(int index) const
190 QPointF QSplineSeriesPrivate::controlPoint(int index) const
188 {
191 {
189 // Q_D(const QSplineSeries);
192 // Q_D(const QSplineSeries);
190 // return d->m_controlPoints[index];
193 // return d->m_controlPoints[index];
191 return m_controlPoints[index];
194 return m_controlPoints[index];
192 }
195 }
193
196
194 /*!
197 /*!
195 Updates the control points, besed on currently avaiable knots.
198 Updates the control points, besed on currently avaiable knots.
196 */
199 */
197 void QSplineSeriesPrivate::updateControlPoints()
200 void QSplineSeriesPrivate::updateControlPoints()
198 {
201 {
199 Q_Q(QSplineSeries);
202 Q_Q(QSplineSeries);
200 if (q->count() > 1) {
203 if (q->count() > 1) {
201 m_controlPoints.resize(2*q->count()-2);
204 m_controlPoints.resize(2*q->count()-2);
202 calculateControlPoints();
205 calculateControlPoints();
203 }
206 }
204 }
207 }
205
208
206 Chart* QSplineSeriesPrivate::createGraphics(ChartPresenter* presenter)
209 Chart* QSplineSeriesPrivate::createGraphics(ChartPresenter* presenter)
207 {
210 {
208 Q_Q(QSplineSeries);
211 Q_Q(QSplineSeries);
209 SplineChartItem* spline = new SplineChartItem(q,presenter);
212 SplineChartItem* spline = new SplineChartItem(q,presenter);
210 if(presenter->animationOptions().testFlag(QChart::SeriesAnimations)) {
213 if(presenter->animationOptions().testFlag(QChart::SeriesAnimations)) {
211 spline->setAnimator(presenter->animator());
214 spline->setAnimator(presenter->animator());
212 spline->setAnimation(new SplineAnimation(spline));
215 spline->setAnimation(new SplineAnimation(spline));
213 }
216 }
214
217
215 presenter->chartTheme()->decorate(q, presenter->dataSet()->seriesIndex(q));
218 presenter->chartTheme()->decorate(q, presenter->dataSet()->seriesIndex(q));
216 return spline;
219 return spline;
217 }
220 }
218
221
219 #include "moc_qsplineseries.cpp"
222 #include "moc_qsplineseries.cpp"
220 #include "moc_qsplineseries_p.cpp"
223 #include "moc_qsplineseries_p.cpp"
221
224
222 QTCOMMERCIALCHART_END_NAMESPACE
225 QTCOMMERCIALCHART_END_NAMESPACE
General Comments 0
You need to be logged in to leave comments. Login now