##// END OF EJS Templates
Fix some more Cppcheck findings
Jani Honkonen -
r1921:e9f381914c53
parent child
Show More
@@ -1,343 +1,343
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 "qdatetimeaxis.h"
21 #include "qdatetimeaxis.h"
22 #include "qdatetimeaxis_p.h"
22 #include "qdatetimeaxis_p.h"
23 #include "chartdatetimeaxisx_p.h"
23 #include "chartdatetimeaxisx_p.h"
24 #include "chartdatetimeaxisy_p.h"
24 #include "chartdatetimeaxisy_p.h"
25 #include "domain_p.h"
25 #include "domain_p.h"
26 #include <cmath>
26 #include <cmath>
27 #include <QDebug>
27 #include <QDebug>
28
28
29 QTCOMMERCIALCHART_BEGIN_NAMESPACE
29 QTCOMMERCIALCHART_BEGIN_NAMESPACE
30 /*!
30 /*!
31 \class QDateTimeAxis
31 \class QDateTimeAxis
32 \brief The QDateTimeAxis class is used for manipulating chart's axis.
32 \brief The QDateTimeAxis class is used for manipulating chart's axis.
33 \mainclass
33 \mainclass
34
34
35 The labels can be configured by setting an appropriate DateTime format.
35 The labels can be configured by setting an appropriate DateTime format.
36 Note that any date before 4714 BCE or after about 1.4 million CE may not be accurately stored.
36 Note that any date before 4714 BCE or after about 1.4 million CE may not be accurately stored.
37 QDateTimeAxis can be setup to show axis line with tick marks, grid lines and shades.
37 QDateTimeAxis can be setup to show axis line with tick marks, grid lines and shades.
38
38
39 \image api_datatime_axis.png
39 \image api_datatime_axis.png
40
40
41 Example code on how to use QDateTimeAxis.
41 Example code on how to use QDateTimeAxis.
42 \code
42 \code
43 QChartView *chartView = new QChartView;
43 QChartView *chartView = new QChartView;
44 QLineSeries *series = new QLineSeries;
44 QLineSeries *series = new QLineSeries;
45
45
46 QDateTime xValue;
46 QDateTime xValue;
47 xValue.setDate(QDate(2012, 1 , 18));
47 xValue.setDate(QDate(2012, 1 , 18));
48 xValue.setTime(QTime(9, 34));
48 xValue.setTime(QTime(9, 34));
49 series->append(xValue.toMSecsSinceEpoch(), 12);
49 series->append(xValue.toMSecsSinceEpoch(), 12);
50
50
51 xValue.setDate(QDate(2013, 5 , 11));
51 xValue.setDate(QDate(2013, 5 , 11));
52 xValue.setTime(QTime(11, 14));
52 xValue.setTime(QTime(11, 14));
53 series->append(xValue.toMSecsSinceEpoch(), 22);
53 series->append(xValue.toMSecsSinceEpoch(), 22);
54 chartView->chart()->addSeries(series);
54 chartView->chart()->addSeries(series);
55
55
56 // ...
56 // ...
57 QDateTimeAxis *axisX = new QDateTimeAxis;
57 QDateTimeAxis *axisX = new QDateTimeAxis;
58 axisX->setFormat("dd-MM-yyyy h:mm");
58 axisX->setFormat("dd-MM-yyyy h:mm");
59 chartView->chart()->setAxisX(series, axisX);
59 chartView->chart()->setAxisX(series, axisX);
60 \endcode
60 \endcode
61 */
61 */
62
62
63 /*!
63 /*!
64 \qmlclass DateTimeAxis QDateTimeAxis
64 \qmlclass DateTimeAxis QDateTimeAxis
65 \brief The DateTimeAxis element is used for manipulating chart's axes
65 \brief The DateTimeAxis element is used for manipulating chart's axes
66
66
67 The labels can be configured by setting an appropriate DateTime format.
67 The labels can be configured by setting an appropriate DateTime format.
68 Note that any date before 4714 BCE or after about 1.4 million CE may not be accurately stored.
68 Note that any date before 4714 BCE or after about 1.4 million CE may not be accurately stored.
69 DateTimeAxis can be setup to show axis line with tick marks, grid lines and shades.
69 DateTimeAxis can be setup to show axis line with tick marks, grid lines and shades.
70 */
70 */
71
71
72 /*!
72 /*!
73 \property QDateTimeAxis::min
73 \property QDateTimeAxis::min
74 Defines the minimum value on the axis.
74 Defines the minimum value on the axis.
75 When setting this property the max is adjusted if necessary, to ensure that the range remains valid.
75 When setting this property the max is adjusted if necessary, to ensure that the range remains valid.
76 */
76 */
77 /*!
77 /*!
78 \qmlproperty real ValuesAxis::min
78 \qmlproperty real ValuesAxis::min
79 Defines the minimum value on the axis.
79 Defines the minimum value on the axis.
80 When setting this property the max is adjusted if necessary, to ensure that the range remains valid.
80 When setting this property the max is adjusted if necessary, to ensure that the range remains valid.
81 */
81 */
82
82
83 /*!
83 /*!
84 \property QDateTimeAxis::max
84 \property QDateTimeAxis::max
85 Defines the maximum value on the axis.
85 Defines the maximum value on the axis.
86 When setting this property the min is adjusted if necessary, to ensure that the range remains valid.
86 When setting this property the min is adjusted if necessary, to ensure that the range remains valid.
87 */
87 */
88 /*!
88 /*!
89 \qmlproperty real ValuesAxis::max
89 \qmlproperty real ValuesAxis::max
90 Defines the maximum value on the axis.
90 Defines the maximum value on the axis.
91 When setting this property the min is adjusted if necessary, to ensure that the range remains valid.
91 When setting this property the min is adjusted if necessary, to ensure that the range remains valid.
92 */
92 */
93
93
94 /*!
94 /*!
95 \fn void QDateTimeAxis::minChanged(QDateTime min)
95 \fn void QDateTimeAxis::minChanged(QDateTime min)
96 Axis emits signal when \a min of axis has changed.
96 Axis emits signal when \a min of axis has changed.
97 */
97 */
98 /*!
98 /*!
99 \qmlsignal ValuesAxis::onMinChanged(QDateTime min)
99 \qmlsignal ValuesAxis::onMinChanged(QDateTime min)
100 Axis emits signal when \a min of axis has changed.
100 Axis emits signal when \a min of axis has changed.
101 */
101 */
102
102
103 /*!
103 /*!
104 \fn void QDateTimeAxis::maxChanged(QDateTime max)
104 \fn void QDateTimeAxis::maxChanged(QDateTime max)
105 Axis emits signal when \a max of axis has changed.
105 Axis emits signal when \a max of axis has changed.
106 */
106 */
107 /*!
107 /*!
108 \qmlsignal ValuesAxis::onMaxChanged(QDateTime max)
108 \qmlsignal ValuesAxis::onMaxChanged(QDateTime max)
109 Axis emits signal when \a max of axis has changed.
109 Axis emits signal when \a max of axis has changed.
110 */
110 */
111
111
112 /*!
112 /*!
113 \fn void QDateTimeAxis::rangeChanged(QDateTime min, QDateTime max)
113 \fn void QDateTimeAxis::rangeChanged(QDateTime min, QDateTime max)
114 Axis emits signal when \a min or \a max of axis has changed.
114 Axis emits signal when \a min or \a max of axis has changed.
115 */
115 */
116
116
117 /*!
117 /*!
118 \property QDateTimeAxis::tickCount
118 \property QDateTimeAxis::tickCount
119 The number of tick marks for the axis.
119 The number of tick marks for the axis.
120 */
120 */
121
121
122 /*!
122 /*!
123 \qmlproperty int ValuesAxis::tickCount
123 \qmlproperty int ValuesAxis::tickCount
124 The number of tick marks for the axis.
124 The number of tick marks for the axis.
125 */
125 */
126
126
127 /*!
127 /*!
128 Constructs an axis object which is a child of \a parent.
128 Constructs an axis object which is a child of \a parent.
129 */
129 */
130 QDateTimeAxis::QDateTimeAxis(QObject *parent) :
130 QDateTimeAxis::QDateTimeAxis(QObject *parent) :
131 QAbstractAxis(*new QDateTimeAxisPrivate(this),parent)
131 QAbstractAxis(*new QDateTimeAxisPrivate(this),parent)
132 {
132 {
133
133
134 }
134 }
135
135
136 /*!
136 /*!
137 \internal
137 \internal
138 */
138 */
139 QDateTimeAxis::QDateTimeAxis(QDateTimeAxisPrivate &d,QObject *parent) : QAbstractAxis(d,parent)
139 QDateTimeAxis::QDateTimeAxis(QDateTimeAxisPrivate &d,QObject *parent) : QAbstractAxis(d,parent)
140 {
140 {
141
141
142 }
142 }
143
143
144 /*!
144 /*!
145 Destroys the object
145 Destroys the object
146 */
146 */
147 QDateTimeAxis::~QDateTimeAxis()
147 QDateTimeAxis::~QDateTimeAxis()
148 {
148 {
149
149
150 }
150 }
151
151
152 void QDateTimeAxis::setMin(QDateTime min)
152 void QDateTimeAxis::setMin(QDateTime min)
153 {
153 {
154 Q_D(QDateTimeAxis);
154 Q_D(QDateTimeAxis);
155 if (min.isValid())
155 if (min.isValid())
156 setRange(min, qMax(d->m_max, min));
156 setRange(min, qMax(d->m_max, min));
157 }
157 }
158
158
159 QDateTime QDateTimeAxis::min() const
159 QDateTime QDateTimeAxis::min() const
160 {
160 {
161 Q_D(const QDateTimeAxis);
161 Q_D(const QDateTimeAxis);
162 return d->m_min;
162 return d->m_min;
163 }
163 }
164
164
165 void QDateTimeAxis::setMax(QDateTime max)
165 void QDateTimeAxis::setMax(QDateTime max)
166 {
166 {
167 Q_D(QDateTimeAxis);
167 Q_D(QDateTimeAxis);
168 if (max.isValid())
168 if (max.isValid())
169 setRange(qMin(d->m_min, max), max);
169 setRange(qMin(d->m_min, max), max);
170 }
170 }
171
171
172 QDateTime QDateTimeAxis::max() const
172 QDateTime QDateTimeAxis::max() const
173 {
173 {
174 Q_D(const QDateTimeAxis);
174 Q_D(const QDateTimeAxis);
175 return d->m_max;
175 return d->m_max;
176 }
176 }
177
177
178 /*!
178 /*!
179 Sets range from \a min to \a max on the axis.
179 Sets range from \a min to \a max on the axis.
180 If min is greater than max then this function returns without making any changes.
180 If min is greater than max then this function returns without making any changes.
181 */
181 */
182 void QDateTimeAxis::setRange(QDateTime min, QDateTime max)
182 void QDateTimeAxis::setRange(QDateTime min, QDateTime max)
183 {
183 {
184 Q_D(QDateTimeAxis);
184 Q_D(QDateTimeAxis);
185 if (!min.isValid() || !max.isValid() || min > max)
185 if (!min.isValid() || !max.isValid() || min > max)
186 return;
186 return;
187
187
188 bool changed = false;
188 bool changed = false;
189 if (d->m_min != min) {
189 if (d->m_min != min) {
190 d->m_min = min;
190 d->m_min = min;
191 changed = true;
191 changed = true;
192 emit minChanged(min);
192 emit minChanged(min);
193 }
193 }
194
194
195 if (d->m_max != max) {
195 if (d->m_max != max) {
196 d->m_max = max;
196 d->m_max = max;
197 changed = true;
197 changed = true;
198 emit maxChanged(max);
198 emit maxChanged(max);
199 }
199 }
200
200
201 if (changed) {
201 if (changed) {
202 emit rangeChanged(d->m_min,d->m_max);
202 emit rangeChanged(d->m_min,d->m_max);
203 d->emitUpdated();
203 d->emitUpdated();
204 }
204 }
205 }
205 }
206
206
207 /*!
207 /*!
208 Sets \a format string that is used when creating label for the axis out of the QDateTime object.
208 Sets \a format string that is used when creating label for the axis out of the QDateTime object.
209 Check QDateTime documentation for information on how the string should be defined.
209 Check QDateTime documentation for information on how the string should be defined.
210 \sa format()
210 \sa format()
211 */
211 */
212 void QDateTimeAxis::setFormat(QString format)
212 void QDateTimeAxis::setFormat(QString format)
213 {
213 {
214 Q_D(QDateTimeAxis);
214 Q_D(QDateTimeAxis);
215 d->m_format = format;
215 d->m_format = format;
216 }
216 }
217
217
218 /*!
218 /*!
219 Returns the format string that is used when creating label for the axis out of the QDateTime object.
219 Returns the format string that is used when creating label for the axis out of the QDateTime object.
220 Check QDateTime documentation for information on how the string should be defined.
220 Check QDateTime documentation for information on how the string should be defined.
221 \sa setFormat()
221 \sa setFormat()
222 */
222 */
223 QString QDateTimeAxis::format() const
223 QString QDateTimeAxis::format() const
224 {
224 {
225 Q_D(const QDateTimeAxis);
225 Q_D(const QDateTimeAxis);
226 return d->m_format;
226 return d->m_format;
227 }
227 }
228
228
229 /*!
229 /*!
230 Sets \a count for ticks on the axis.
230 Sets \a count for ticks on the axis.
231 */
231 */
232 void QDateTimeAxis::setTickCount(int count)
232 void QDateTimeAxis::setTickCount(int count)
233 {
233 {
234 Q_D(QDateTimeAxis);
234 Q_D(QDateTimeAxis);
235 if (d->m_tickCount != count && count >=2) {
235 if (d->m_tickCount != count && count >=2) {
236 d->m_tickCount = count;
236 d->m_tickCount = count;
237 d->emitUpdated();
237 d->emitUpdated();
238 }
238 }
239 }
239 }
240
240
241 /*!
241 /*!
242 \fn int QDateTimeAxis::tickCount() const
242 \fn int QDateTimeAxis::tickCount() const
243 Return number of ticks on the axis
243 Return number of ticks on the axis
244 */
244 */
245 int QDateTimeAxis::tickCount() const
245 int QDateTimeAxis::tickCount() const
246 {
246 {
247 Q_D(const QDateTimeAxis);
247 Q_D(const QDateTimeAxis);
248 return d->m_tickCount;
248 return d->m_tickCount;
249 }
249 }
250
250
251 /*!
251 /*!
252 Returns the type of the axis
252 Returns the type of the axis
253 */
253 */
254 QAbstractAxis::AxisType QDateTimeAxis::type() const
254 QAbstractAxis::AxisType QDateTimeAxis::type() const
255 {
255 {
256 return AxisTypeDateTime;
256 return AxisTypeDateTime;
257 }
257 }
258
258
259 /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
259 /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
260
260
261 QDateTimeAxisPrivate::QDateTimeAxisPrivate(QDateTimeAxis* q):
261 QDateTimeAxisPrivate::QDateTimeAxisPrivate(QDateTimeAxis* q):
262 QAbstractAxisPrivate(q),
262 QAbstractAxisPrivate(q),
263 m_min(QDateTime::fromMSecsSinceEpoch(0)),
264 m_max(QDateTime::fromMSecsSinceEpoch(0)),
263 m_tickCount(5)
265 m_tickCount(5)
264 {
266 {
265 m_min = QDateTime::fromMSecsSinceEpoch(0);
266 m_max = QDateTime::fromMSecsSinceEpoch(0);
267 m_format = "dd-MM-yyyy\nh:mm";
267 m_format = "dd-MM-yyyy\nh:mm";
268 }
268 }
269
269
270 QDateTimeAxisPrivate::~QDateTimeAxisPrivate()
270 QDateTimeAxisPrivate::~QDateTimeAxisPrivate()
271 {
271 {
272
272
273 }
273 }
274
274
275 void QDateTimeAxisPrivate::handleDomainUpdated()
275 void QDateTimeAxisPrivate::handleDomainUpdated()
276 {
276 {
277 Q_Q(QDateTimeAxis);
277 Q_Q(QDateTimeAxis);
278 Domain* domain = qobject_cast<Domain*>(sender());
278 Domain* domain = qobject_cast<Domain*>(sender());
279 Q_ASSERT(domain);
279 Q_ASSERT(domain);
280
280
281 if(orientation()==Qt::Horizontal){
281 if(orientation()==Qt::Horizontal){
282 q->setRange(QDateTime::fromMSecsSinceEpoch(domain->minX()), QDateTime::fromMSecsSinceEpoch(domain->maxX()));
282 q->setRange(QDateTime::fromMSecsSinceEpoch(domain->minX()), QDateTime::fromMSecsSinceEpoch(domain->maxX()));
283 }else if(orientation()==Qt::Vertical){
283 }else if(orientation()==Qt::Vertical){
284 q->setRange(QDateTime::fromMSecsSinceEpoch(domain->minY()), QDateTime::fromMSecsSinceEpoch(domain->maxY()));
284 q->setRange(QDateTime::fromMSecsSinceEpoch(domain->minY()), QDateTime::fromMSecsSinceEpoch(domain->maxY()));
285 }
285 }
286 }
286 }
287
287
288
288
289 void QDateTimeAxisPrivate::setMin(const QVariant &min)
289 void QDateTimeAxisPrivate::setMin(const QVariant &min)
290 {
290 {
291 Q_Q(QDateTimeAxis);
291 Q_Q(QDateTimeAxis);
292 if (min.canConvert(QVariant::DateTime))
292 if (min.canConvert(QVariant::DateTime))
293 q->setMin(min.toDateTime());
293 q->setMin(min.toDateTime());
294 }
294 }
295
295
296 void QDateTimeAxisPrivate::setMax(const QVariant &max)
296 void QDateTimeAxisPrivate::setMax(const QVariant &max)
297 {
297 {
298
298
299 Q_Q(QDateTimeAxis);
299 Q_Q(QDateTimeAxis);
300 if (max.canConvert(QVariant::DateTime))
300 if (max.canConvert(QVariant::DateTime))
301 q->setMax(max.toDateTime());
301 q->setMax(max.toDateTime());
302 }
302 }
303
303
304 void QDateTimeAxisPrivate::setRange(const QVariant &min, const QVariant &max)
304 void QDateTimeAxisPrivate::setRange(const QVariant &min, const QVariant &max)
305 {
305 {
306 Q_Q(QDateTimeAxis);
306 Q_Q(QDateTimeAxis);
307 if (min.canConvert(QVariant::DateTime) && max.canConvert(QVariant::DateTime))
307 if (min.canConvert(QVariant::DateTime) && max.canConvert(QVariant::DateTime))
308 q->setRange(min.toDateTime(), max.toDateTime());
308 q->setRange(min.toDateTime(), max.toDateTime());
309 }
309 }
310
310
311 ChartAxis* QDateTimeAxisPrivate::createGraphics(ChartPresenter* presenter)
311 ChartAxis* QDateTimeAxisPrivate::createGraphics(ChartPresenter* presenter)
312 {
312 {
313 Q_Q(QDateTimeAxis);
313 Q_Q(QDateTimeAxis);
314 if(m_orientation == Qt::Vertical){
314 if(m_orientation == Qt::Vertical){
315 return new ChartDateTimeAxisY(q,presenter);
315 return new ChartDateTimeAxisY(q,presenter);
316 }else{
316 }else{
317 return new ChartDateTimeAxisX(q,presenter);
317 return new ChartDateTimeAxisX(q,presenter);
318 }
318 }
319
319
320 }
320 }
321
321
322 void QDateTimeAxisPrivate::intializeDomain(Domain* domain)
322 void QDateTimeAxisPrivate::intializeDomain(Domain* domain)
323 {
323 {
324 Q_Q(QDateTimeAxis);
324 Q_Q(QDateTimeAxis);
325 if(m_max == m_min) {
325 if(m_max == m_min) {
326 if(m_orientation==Qt::Vertical){
326 if(m_orientation==Qt::Vertical){
327 q->setRange(QDateTime::fromMSecsSinceEpoch(domain->minY()), QDateTime::fromMSecsSinceEpoch(domain->maxY()));
327 q->setRange(QDateTime::fromMSecsSinceEpoch(domain->minY()), QDateTime::fromMSecsSinceEpoch(domain->maxY()));
328 }else{
328 }else{
329 q->setRange(QDateTime::fromMSecsSinceEpoch(domain->minX()), QDateTime::fromMSecsSinceEpoch(domain->maxX()));
329 q->setRange(QDateTime::fromMSecsSinceEpoch(domain->minX()), QDateTime::fromMSecsSinceEpoch(domain->maxX()));
330 }
330 }
331 } else {
331 } else {
332 if(m_orientation==Qt::Vertical){
332 if(m_orientation==Qt::Vertical){
333 domain->setRangeY(m_min.toMSecsSinceEpoch(), m_max.toMSecsSinceEpoch());
333 domain->setRangeY(m_min.toMSecsSinceEpoch(), m_max.toMSecsSinceEpoch());
334 }else{
334 }else{
335 domain->setRangeX(m_min.toMSecsSinceEpoch(), m_max.toMSecsSinceEpoch());
335 domain->setRangeX(m_min.toMSecsSinceEpoch(), m_max.toMSecsSinceEpoch());
336 }
336 }
337 }
337 }
338 }
338 }
339
339
340 #include "moc_qdatetimeaxis.cpp"
340 #include "moc_qdatetimeaxis.cpp"
341 #include "moc_qdatetimeaxis_p.cpp"
341 #include "moc_qdatetimeaxis_p.cpp"
342
342
343 QTCOMMERCIALCHART_END_NAMESPACE
343 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,146 +1,142
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 // W A R N I N G
21 // W A R N I N G
22 // -------------
22 // -------------
23 //
23 //
24 // This file is not part of the QtCommercial Chart API. It exists purely as an
24 // This file is not part of the QtCommercial Chart API. It exists purely as an
25 // implementation detail. This header file may change from version to
25 // implementation detail. This header file may change from version to
26 // version without notice, or even be removed.
26 // version without notice, or even be removed.
27 //
27 //
28 // We mean it.
28 // We mean it.
29
29
30 #ifndef PIESLICEDATA_P_H
30 #ifndef PIESLICEDATA_P_H
31 #define PIESLICEDATA_P_H
31 #define PIESLICEDATA_P_H
32
32
33 #include "qchartglobal.h"
33 #include "qchartglobal.h"
34 #include "qpieslice.h"
34 #include "qpieslice.h"
35 #include <QPen>
35 #include <QPen>
36 #include <QBrush>
36 #include <QBrush>
37
37
38 QTCOMMERCIALCHART_BEGIN_NAMESPACE
38 QTCOMMERCIALCHART_BEGIN_NAMESPACE
39
39
40 template <class T>
40 template <class T>
41 class Themed : public T
41 class Themed : public T
42 {
42 {
43 public:
43 public:
44 Themed():m_isThemed(true) {}
44 Themed():m_isThemed(true) {}
45
45
46 inline T &operator=(const T &other) { return T::operator =(other); }
46 inline T &operator=(const T &other) { return T::operator =(other); }
47
47
48 inline bool operator!=(const T &other) const { return T::operator !=(other); }
48 inline bool operator!=(const T &other) const { return T::operator !=(other); }
49 inline bool operator!=(const Themed &other) const
49 inline bool operator!=(const Themed &other) const
50 {
50 {
51 if (T::operator !=(other))
51 if (T::operator !=(other))
52 return true;
52 return true;
53
53
54 if (m_isThemed != other.m_isThemed)
54 if (m_isThemed != other.m_isThemed)
55 return true;
55 return true;
56
56
57 return false;
57 return false;
58 }
58 }
59
59
60 inline void setThemed(bool state) { m_isThemed = state; }
60 inline void setThemed(bool state) { m_isThemed = state; }
61 inline bool isThemed() const { return m_isThemed; }
61 inline bool isThemed() const { return m_isThemed; }
62
62
63 private:
63 private:
64 bool m_isThemed;
64 bool m_isThemed;
65 };
65 };
66
66
67 class PieSliceData
67 class PieSliceData
68 {
68 {
69 public:
69 public:
70 PieSliceData()
70 PieSliceData() :
71 m_value(0),
72 m_isExploded(false),
73 m_explodeDistanceFactor(0.15),
74 m_isLabelVisible(false),
75 m_labelPosition(QPieSlice::LabelOutside),
76 m_labelArmLengthFactor(0.15),
77 m_percentage(0),
78 m_radius(0),
79 m_startAngle(0),
80 m_angleSpan(0),
81 m_holeRadius(0)
71 {
82 {
72 m_value = 0;
73
74 m_isExploded = false;
75 m_explodeDistanceFactor = 0.15;
76
77 m_isLabelVisible = false;
78 m_labelPosition = QPieSlice::LabelOutside;
79 m_labelArmLengthFactor = 0.15;
80
81 m_percentage = 0;
82 m_radius = 0;
83 m_startAngle = 0;
84 m_angleSpan = 0;
85
86 m_holeRadius = 0;
87 }
83 }
88
84
89 bool operator!=(const PieSliceData &other) const
85 bool operator!=(const PieSliceData &other) const
90 {
86 {
91 if (!qFuzzyIsNull(m_value - other.m_value))
87 if (!qFuzzyIsNull(m_value - other.m_value))
92 return true;
88 return true;
93
89
94 if (m_slicePen != other.m_slicePen ||
90 if (m_slicePen != other.m_slicePen ||
95 m_sliceBrush != other.m_sliceBrush)
91 m_sliceBrush != other.m_sliceBrush)
96 return true;
92 return true;
97
93
98 if (m_isExploded != other.m_isExploded ||
94 if (m_isExploded != other.m_isExploded ||
99 !qFuzzyIsNull(m_explodeDistanceFactor - other.m_explodeDistanceFactor))
95 !qFuzzyIsNull(m_explodeDistanceFactor - other.m_explodeDistanceFactor))
100 return true;
96 return true;
101
97
102 if (m_isLabelVisible != other.m_isLabelVisible ||
98 if (m_isLabelVisible != other.m_isLabelVisible ||
103 m_labelText != other.m_labelText ||
99 m_labelText != other.m_labelText ||
104 m_labelFont != other.m_labelFont ||
100 m_labelFont != other.m_labelFont ||
105 m_labelPosition != other.m_labelPosition ||
101 m_labelPosition != other.m_labelPosition ||
106 !qFuzzyIsNull(m_labelArmLengthFactor - other.m_labelArmLengthFactor) ||
102 !qFuzzyIsNull(m_labelArmLengthFactor - other.m_labelArmLengthFactor) ||
107 m_labelBrush != other.m_labelBrush)
103 m_labelBrush != other.m_labelBrush)
108 return true;
104 return true;
109
105
110 if (!qFuzzyIsNull(m_percentage - other.m_percentage) ||
106 if (!qFuzzyIsNull(m_percentage - other.m_percentage) ||
111 m_center != other.m_center ||
107 m_center != other.m_center ||
112 !qFuzzyIsNull(m_radius - other.m_radius) ||
108 !qFuzzyIsNull(m_radius - other.m_radius) ||
113 !qFuzzyIsNull(m_startAngle - other.m_startAngle) ||
109 !qFuzzyIsNull(m_startAngle - other.m_startAngle) ||
114 !qFuzzyIsNull(m_angleSpan - other.m_angleSpan))
110 !qFuzzyIsNull(m_angleSpan - other.m_angleSpan))
115 return true;
111 return true;
116
112
117 return false;
113 return false;
118 }
114 }
119
115
120 qreal m_value;
116 qreal m_value;
121
117
122 Themed<QPen> m_slicePen;
118 Themed<QPen> m_slicePen;
123 Themed<QBrush> m_sliceBrush;
119 Themed<QBrush> m_sliceBrush;
124
120
125 bool m_isExploded;
121 bool m_isExploded;
126 qreal m_explodeDistanceFactor;
122 qreal m_explodeDistanceFactor;
127
123
128 bool m_isLabelVisible;
124 bool m_isLabelVisible;
129 QString m_labelText;
125 QString m_labelText;
130 Themed<QFont> m_labelFont;
126 Themed<QFont> m_labelFont;
131 QPieSlice::LabelPosition m_labelPosition;
127 QPieSlice::LabelPosition m_labelPosition;
132 qreal m_labelArmLengthFactor;
128 qreal m_labelArmLengthFactor;
133 Themed<QBrush> m_labelBrush;
129 Themed<QBrush> m_labelBrush;
134
130
135 qreal m_percentage;
131 qreal m_percentage;
136 QPointF m_center;
132 QPointF m_center;
137 qreal m_radius;
133 qreal m_radius;
138 qreal m_startAngle;
134 qreal m_startAngle;
139 qreal m_angleSpan;
135 qreal m_angleSpan;
140
136
141 qreal m_holeRadius;
137 qreal m_holeRadius;
142 };
138 };
143
139
144 QTCOMMERCIALCHART_END_NAMESPACE
140 QTCOMMERCIALCHART_END_NAMESPACE
145
141
146 #endif // PIESLICEDATA_P_H
142 #endif // PIESLICEDATA_P_H
General Comments 0
You need to be logged in to leave comments. Login now