##// END OF EJS Templates
fix some Cppcheck findings
Jani Honkonen -
r1919:91b94c58701c
parent child
Show More
@@ -1,46 +1,45
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 #ifndef CHARTVIEW_H
22 22 #define CHARTVIEW_H
23 23
24 24 #include <QChartView>
25 25 #include <QRubberBand>
26 26
27 27 QTCOMMERCIALCHART_USE_NAMESPACE
28 28
29 29 class ChartView : public QChartView
30 30 {
31 31 public:
32 32 ChartView(QChart *chart, QWidget *parent = 0);
33 33 protected:
34 34 void mousePressEvent(QMouseEvent *event);
35 35 void mouseMoveEvent(QMouseEvent *event);
36 36 void mouseReleaseEvent(QMouseEvent *event);
37 37 void keyPressEvent(QKeyEvent *event);
38 38
39 39 private:
40 40 bool m_isScrolling;
41 bool m_isRubberBandShown;
42 41 QRubberBand m_rubberBand;
43 42 QPoint m_origin;
44 43 };
45 44
46 45 #endif
@@ -1,100 +1,98
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 CHARTDATASET_P_H
31 31 #define CHARTDATASET_P_H
32 32
33 33 #include "qabstractseries.h"
34 34 #include "domain_p.h"
35 35 #include "qabstractaxis_p.h"
36 36 #include <QVector>
37 37
38 38 QTCOMMERCIALCHART_BEGIN_NAMESPACE
39 39
40 40 class QAbstractAxis;
41 41
42 42 class QTCOMMERCIALCHART_AUTOTEST_EXPORT ChartDataSet : public QObject
43 43 {
44 44 Q_OBJECT
45 45 public:
46 46 ChartDataSet(QChart* parent=0);
47 47 virtual ~ChartDataSet();
48 48
49 49 void addSeries(QAbstractSeries* series);
50 50 void removeSeries(QAbstractSeries* series);
51 51 void removeAllSeries();
52 52 void updateSeries(QAbstractSeries* series);
53 53
54 54 void zoomInDomain(const QRectF& rect, const QSizeF& size);
55 55 void zoomOutDomain(const QRectF& rect, const QSizeF& size);
56 56 void scrollDomain(qreal dx,qreal dy,const QSizeF& size);
57 57
58 58 int seriesCount(QAbstractSeries::SeriesType type);
59 59 int seriesIndex(QAbstractSeries *series);
60 60
61 61 QAbstractAxis* axisX(QAbstractSeries *series) const;
62 62 QAbstractAxis* axisY(QAbstractSeries *series) const;
63 63
64 64 void setAxis(QAbstractSeries *series, QAbstractAxis *axis, Qt::Orientation orientation);
65 65
66 66 QList<QAbstractSeries*> series() const;
67 67 Domain* domain(QAbstractSeries *series) const;
68 68
69 69 void removeAxis(QAbstractAxis* axis);
70 70 void createDefaultAxes();
71 71
72 72 Q_SIGNALS:
73 73 void seriesAdded(QAbstractSeries* series, Domain* domain);
74 74 void seriesRemoved(QAbstractSeries* series);
75 75 void seriesUpdated(QAbstractSeries* series);
76 76 void axisAdded(QAbstractAxis* axis,Domain* domain);
77 77 void axisRemoved(QAbstractAxis* axis);
78 78
79 79 private:
80 80 void calculateDomain(QAbstractSeries* series,Domain* domain);
81 81 void createAxes(QAbstractAxis::AxisTypes type,Qt::Orientation orientation);
82 82 QAbstractAxis* createAxis(QAbstractAxis::AxisType type,Qt::Orientation orientation);
83 83 void initializeAxis(QAbstractAxis* axis,QAbstractSeries* series);
84 84 void removeAxes(QAbstractSeries* series);
85 85 void blockAxisSignals(bool enabled);
86 86 void createSeriesIndex(QAbstractSeries* series);
87 87 void removeSeriesIndex(QAbstractSeries* series);
88 88
89 89 private:
90 90 QMap<QAbstractSeries*, QAbstractAxis*> m_seriesAxisXMap;
91 91 QMap<QAbstractSeries*, QAbstractAxis*> m_seriesAxisYMap;
92 92 QMap<QAbstractSeries*, Domain*> m_seriesDomainMap;
93 93 QMap<int, QAbstractSeries*> m_indexSeriesMap;
94 int m_domainIndex;
95
96 94 };
97 95
98 96 QTCOMMERCIALCHART_END_NAMESPACE
99 97
100 98 #endif /* CHARTENGINE_P_H_ */
@@ -1,393 +1,393
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 "charttheme_p.h"
22 22 #include "qchart.h"
23 23 #include "qchart_p.h"
24 24 #include "qchartview.h"
25 25 #include "qlegend.h"
26 26 #include "qabstractaxis.h"
27 27 #include <QTime>
28 28
29 29 //series
30 30 #include "qbarset.h"
31 31 #include "qabstractbarseries.h"
32 32 #include "qstackedbarseries.h"
33 33 #include "qpercentbarseries.h"
34 34 #include "qlineseries.h"
35 35 #include "qareaseries.h"
36 36 #include "qscatterseries.h"
37 37 #include "qpieseries.h"
38 38 #include "qpieslice.h"
39 39 #include "qpieslice_p.h"
40 40 #include "qsplineseries.h"
41 41
42 42 //items
43 43 #include "chartaxis_p.h"
44 44 #include "abstractbarchartitem_p.h"
45 45 #include "stackedbarchartitem_p.h"
46 46 #include "percentbarchartitem_p.h"
47 47 #include "linechartitem_p.h"
48 48 #include "areachartitem_p.h"
49 49 #include "scatterchartitem_p.h"
50 50 #include "piechartitem_p.h"
51 51 #include "splinechartitem_p.h"
52 52
53 53 //themes
54 54 #include "chartthemesystem_p.h"
55 55 #include "chartthemelight_p.h"
56 56 #include "chartthemebluecerulean_p.h"
57 57 #include "chartthemedark_p.h"
58 58 #include "chartthemebrownsand_p.h"
59 59 #include "chartthemebluencs_p.h"
60 60 #include "chartthemehighcontrast_p.h"
61 61 #include "chartthemeblueicy_p.h"
62 62
63 63 QTCOMMERCIALCHART_BEGIN_NAMESPACE
64 64
65 65 ChartTheme::ChartTheme(QChart::ChartTheme id) :
66 m_id(id),
66 67 m_masterFont(QFont("arial", 14)),
67 68 m_labelFont(QFont("arial", 10)),
68 69 m_labelBrush(QColor(QRgb(0x000000))),
69 70 m_axisLinePen(QPen(QRgb(0x000000))),
70 71 m_backgroundShadesPen(Qt::NoPen),
71 72 m_backgroundShadesBrush(Qt::NoBrush),
72 73 m_backgroundShades(BackgroundShadesNone),
73 74 m_backgroundDropShadowEnabled(false),
74 75 m_gridLinePen(QPen(QRgb(0x000000))),
75 76 m_force(false)
76 77 {
77 m_id = id;
78 78 qsrand(QTime(0,0,0).secsTo(QTime::currentTime()));
79 79 }
80 80
81 81
82 82 ChartTheme* ChartTheme::createTheme(QChart::ChartTheme theme)
83 83 {
84 84 switch(theme) {
85 85 case QChart::ChartThemeLight:
86 86 return new ChartThemeLight();
87 87 case QChart::ChartThemeBlueCerulean:
88 88 return new ChartThemeBlueCerulean();
89 89 case QChart::ChartThemeDark:
90 90 return new ChartThemeDark();
91 91 case QChart::ChartThemeBrownSand:
92 92 return new ChartThemeBrownSand();
93 93 case QChart::ChartThemeBlueNcs:
94 94 return new ChartThemeBlueNcs();
95 95 case QChart::ChartThemeHighContrast:
96 96 return new ChartThemeHighContrast();
97 97 case QChart::ChartThemeBlueIcy:
98 98 return new ChartThemeBlueIcy();
99 99 default:
100 100 return new ChartThemeSystem();
101 101 }
102 102 }
103 103
104 104 void ChartTheme::decorate(QChart *chart)
105 105 {
106 106 QBrush brush;
107 107
108 108 if(m_force || brush == chart->backgroundBrush())
109 109 chart->setBackgroundBrush(m_chartBackgroundGradient);
110 110 chart->setTitleFont(m_masterFont);
111 111 chart->setTitleBrush(m_labelBrush);
112 112 chart->setDropShadowEnabled(m_backgroundDropShadowEnabled);
113 113 }
114 114
115 115 void ChartTheme::decorate(QLegend *legend)
116 116 {
117 117 QPen pen;
118 118 QBrush brush;
119 119 QFont font;
120 120
121 121 if (m_force || pen == legend->pen())
122 122 legend->setPen(m_axisLinePen);
123 123
124 124 if (m_force || brush == legend->brush())
125 125 legend->setBrush(m_chartBackgroundGradient);
126 126
127 127 if (m_force || font == legend->font())
128 128 legend->setFont(m_labelFont);
129 129
130 130 if (m_force || brush == legend->labelBrush())
131 131 legend->setLabelBrush(m_labelBrush);
132 132 }
133 133
134 134 void ChartTheme::decorate(QAreaSeries *series, int index)
135 135 {
136 136 QPen pen;
137 137 QBrush brush;
138 138
139 139 if (m_force || pen == series->pen()){
140 140 pen.setColor(colorAt(m_seriesGradients.at(index % m_seriesGradients.size()), 0.0));
141 141 pen.setWidthF(2);
142 142 series->setPen(pen);
143 143 }
144 144
145 145 if (m_force || brush == series->brush()) {
146 146 QBrush brush(m_seriesColors.at(index % m_seriesColors.size()));
147 147 series->setBrush(brush);
148 148 }
149 149 }
150 150
151 151
152 152 void ChartTheme::decorate(QLineSeries *series,int index)
153 153 {
154 154 QPen pen;
155 155 if(m_force || pen == series->pen()){
156 156 pen.setColor(m_seriesColors.at(index%m_seriesColors.size()));
157 157 pen.setWidthF(2);
158 158 series->setPen(pen);
159 159 }
160 160 }
161 161
162 162 void ChartTheme::decorate(QAbstractBarSeries *series, int index)
163 163 {
164 164 QBrush brush;
165 165 QPen pen;
166 166 QList<QBarSet *> sets = series->barSets();
167 167
168 168 qreal takeAtPos = 0.5;
169 169 qreal step = 0.2;
170 170 if (sets.count() > 1 ) {
171 171 step = 1.0 / (qreal) sets.count();
172 172 if (sets.count() % m_seriesGradients.count())
173 173 step *= m_seriesGradients.count();
174 174 else
175 175 step *= (m_seriesGradients.count() - 1);
176 176 }
177 177
178 178 for (int i(0); i < sets.count(); i++) {
179 179 int colorIndex = (index + i) % m_seriesGradients.count();
180 180 if (i > 0 && i % m_seriesGradients.count() == 0) {
181 181 // There is no dedicated base color for each sets, generate more colors
182 182 takeAtPos += step;
183 183 if (takeAtPos == 1.0)
184 184 takeAtPos += step;
185 185 takeAtPos -= (int) takeAtPos;
186 186 }
187 187 if (m_force || brush == sets.at(i)->brush())
188 188 sets.at(i)->setBrush(colorAt(m_seriesGradients.at(colorIndex), takeAtPos));
189 189
190 190 // Pick label color from the opposite end of the gradient.
191 191 // 0.3 as a boundary seems to work well.
192 192 if (m_force || brush == sets.at(i)->labelBrush()) {
193 193 if (takeAtPos < 0.3)
194 194 sets.at(i)->setLabelBrush(colorAt(m_seriesGradients.at(index % m_seriesGradients.size()), 1));
195 195 else
196 196 sets.at(i)->setLabelBrush(colorAt(m_seriesGradients.at(index % m_seriesGradients.size()), 0));
197 197 }
198 198
199 199 if (m_force || pen == sets.at(i)->pen()) {
200 200 QColor c = colorAt(m_seriesGradients.at(index % m_seriesGradients.size()), 0.0);
201 201 sets.at(i)->setPen(c);
202 202 }
203 203 }
204 204 }
205 205
206 206 void ChartTheme::decorate(QScatterSeries *series, int index)
207 207 {
208 208 QPen pen;
209 209 QBrush brush;
210 210
211 211 if (m_force || pen == series->pen()) {
212 212 pen.setColor(colorAt(m_seriesGradients.at(index % m_seriesGradients.size()), 0.0));
213 213 pen.setWidthF(2);
214 214 series->setPen(pen);
215 215 }
216 216
217 217 if (m_force || brush == series->brush()) {
218 218 QBrush brush(m_seriesColors.at(index % m_seriesColors.size()));
219 219 series->setBrush(brush);
220 220 }
221 221 }
222 222
223 223 void ChartTheme::decorate(QPieSeries *series, int index)
224 224 {
225 225
226 226 for (int i(0); i < series->slices().count(); i++) {
227 227
228 228 QColor penColor = colorAt(m_seriesGradients.at(index % m_seriesGradients.size()), 0.0);
229 229
230 230 // Get color for a slice from a gradient linearly, beginning from the start of the gradient
231 231 qreal pos = (qreal) (i + 1) / (qreal) series->count();
232 232 QColor brushColor = colorAt(m_seriesGradients.at(index % m_seriesGradients.size()), pos);
233 233
234 234 QPieSlice *s = series->slices().at(i);
235 235 QPieSlicePrivate *d = QPieSlicePrivate::fromSlice(s);
236 236
237 237 if (m_force || d->m_data.m_slicePen.isThemed())
238 238 d->setPen(penColor, true);
239 239
240 240 if (m_force || d->m_data.m_sliceBrush.isThemed())
241 241 d->setBrush(brushColor, true);
242 242
243 243 if (m_force || d->m_data.m_labelBrush.isThemed())
244 244 d->setLabelBrush(m_labelBrush.color(), true);
245 245
246 246 if (m_force || d->m_data.m_labelFont.isThemed())
247 247 d->setLabelFont(m_labelFont, true);
248 248 }
249 249 }
250 250
251 251 void ChartTheme::decorate(QSplineSeries *series, int index)
252 252 {
253 253 QPen pen;
254 254 if(m_force || pen == series->pen()){
255 255 pen.setColor(m_seriesColors.at(index%m_seriesColors.size()));
256 256 pen.setWidthF(2);
257 257 series->setPen(pen);
258 258 }
259 259 }
260 260
261 261 void ChartTheme::decorate(QAbstractAxis *axis)
262 262 {
263 263 QPen pen;
264 264 QBrush brush;
265 265 QFont font;
266 266
267 267 bool axisX = axis->orientation()== Qt::Horizontal;
268 268
269 269 if (axis->isLineVisible()) {
270 270
271 271 if(m_force || brush == axis->labelsBrush()){
272 272 axis->setLabelsBrush(m_labelBrush);
273 273 }
274 274 if(m_force || pen == axis->labelsPen()){
275 275 axis->setLabelsPen(Qt::NoPen); // NoPen for performance reasons
276 276 }
277 277
278 278
279 279 if (m_force || axis->shadesVisible()) {
280 280
281 281 if(m_force || brush == axis->shadesBrush()){
282 282 axis->setShadesBrush(m_backgroundShadesBrush);
283 283 }
284 284
285 285 if(m_force || pen == axis->shadesPen()){
286 286 axis->setShadesPen(m_backgroundShadesPen);
287 287 }
288 288
289 289 if( m_force && (m_backgroundShades == BackgroundShadesBoth
290 290 || (m_backgroundShades == BackgroundShadesVertical && axisX)
291 291 || (m_backgroundShades == BackgroundShadesHorizontal && !axisX))){
292 292 axis->setShadesVisible(true);
293 293
294 294 }
295 295 }
296 296
297 297 if(m_force || pen == axis->linePen()){
298 298 axis->setLinePen(m_axisLinePen);
299 299 }
300 300
301 301 if(m_force || pen == axis->gridLinePen()){
302 302 axis->setGridLinePen(m_gridLinePen);
303 303 }
304 304
305 305 if(m_force || font == axis->labelsFont()){
306 306 axis->setLabelsFont(m_labelFont);
307 307 }
308 308 }
309 309 }
310 310
311 311 void ChartTheme::generateSeriesGradients()
312 312 {
313 313 // Generate gradients in HSV color space
314 314 foreach (const QColor& color, m_seriesColors) {
315 315 QLinearGradient g;
316 316 qreal h = color.hsvHueF();
317 317 qreal s = color.hsvSaturationF();
318 318
319 319 // TODO: tune the algorithm to give nice results with most base colors defined in
320 320 // most themes. The rest of the gradients we can define manually in theme specific
321 321 // implementation.
322 322 QColor start = color;
323 323 start.setHsvF(h, 0.0, 1.0);
324 324 g.setColorAt(0.0, start);
325 325
326 326 g.setColorAt(0.5, color);
327 327
328 328 QColor end = color;
329 329 end.setHsvF(h, s, 0.25);
330 330 g.setColorAt(1.0, end);
331 331
332 332 m_seriesGradients << g;
333 333 }
334 334 }
335 335
336 336
337 337 QColor ChartTheme::colorAt(const QColor &start, const QColor &end, qreal pos)
338 338 {
339 339 Q_ASSERT(pos >= 0.0 && pos <= 1.0);
340 340 qreal r = start.redF() + ((end.redF() - start.redF()) * pos);
341 341 qreal g = start.greenF() + ((end.greenF() - start.greenF()) * pos);
342 342 qreal b = start.blueF() + ((end.blueF() - start.blueF()) * pos);
343 343 QColor c;
344 344 c.setRgbF(r, g, b);
345 345 return c;
346 346 }
347 347
348 348 QColor ChartTheme::colorAt(const QGradient &gradient, qreal pos)
349 349 {
350 350 Q_ASSERT(pos >= 0 && pos <= 1.0);
351 351
352 352 QGradientStops stops = gradient.stops();
353 353 int count = stops.count();
354 354
355 355 // find previous stop relative to position
356 356 QGradientStop prev = stops.first();
357 357 for (int i = 0; i < count; i++) {
358 358 QGradientStop stop = stops.at(i);
359 359 if (pos > stop.first)
360 360 prev = stop;
361 361
362 362 // given position is actually a stop position?
363 363 if (pos == stop.first) {
364 364 //qDebug() << "stop color" << pos;
365 365 return stop.second;
366 366 }
367 367 }
368 368
369 369 // find next stop relative to position
370 370 QGradientStop next = stops.last();
371 371 for (int i = count - 1; i >= 0; i--) {
372 372 QGradientStop stop = stops.at(i);
373 373 if (pos < stop.first)
374 374 next = stop;
375 375 }
376 376
377 377 //qDebug() << "prev" << prev.first << "pos" << pos << "next" << next.first;
378 378
379 379 qreal range = next.first - prev.first;
380 380 qreal posDelta = pos - prev.first;
381 381 qreal relativePos = posDelta / range;
382 382
383 383 //qDebug() << "range" << range << "posDelta" << posDelta << "relativePos" << relativePos;
384 384
385 385 return colorAt(prev.second, next.second, relativePos);
386 386 }
387 387
388 388 void ChartTheme::setForced(bool enabled)
389 389 {
390 390 m_force = enabled;
391 391 }
392 392
393 393 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,70 +1,67
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 #ifndef LEGENDLAYOUT_H_
22 22 #define LEGENDLAYOUT_H_
23 23 #include <QGraphicsLayout>
24 24 #include "qchartglobal.h"
25 25
26 26 QTCOMMERCIALCHART_BEGIN_NAMESPACE
27 27
28 28 class QLegend;
29 29
30 30 class LegendLayout : public QGraphicsLayout
31 31 {
32 32 public:
33 33
34 34 LegendLayout(QLegend* legend);
35 35 virtual ~LegendLayout();
36 36
37 37 void setGeometry(const QRectF& rect);
38 38
39 39 void setOffset(qreal x, qreal y);
40 40 QPointF offset() const;
41 41
42 42 protected:
43 43 QSizeF sizeHint ( Qt::SizeHint which, const QSizeF & constraint = QSizeF() ) const;
44 44 int count() const { return 0; }
45 45 QGraphicsLayoutItem* itemAt(int) const { return 0; };
46 46 void removeAt(int){};
47 47
48 48 private:
49 49 void setAttachedGeometry(const QRectF& rect);
50 50 void setDettachedGeometry(const QRectF& rect);
51 51
52 52 private:
53 53 QLegend* m_legend;
54 int m_marginBig;
55 int m_marginSmall;
56 int m_marginTiny;
57 54 qreal m_offsetX;
58 55 qreal m_offsetY;
59 56 qreal m_minOffsetX;
60 57 qreal m_minOffsetY;
61 58 qreal m_maxOffsetX;
62 59 qreal m_maxOffsetY;
63 60 qreal m_width;
64 61 qreal m_height;
65 62
66 63 };
67 64
68 65 QTCOMMERCIALCHART_END_NAMESPACE
69 66
70 67 #endif
General Comments 0
You need to be logged in to leave comments. Login now