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