##// END OF EJS Templates
Use qobject_cast instead of reinterpret_cast in xy series casts
Tero Ahola -
r1401:853a3ddfabfc
parent child
Show More
@@ -1,48 +1,53
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 "declarativelineseries.h"
22 22 #include "declarativechart.h"
23 23 #include "qchart.h"
24 24 #include "qlineseries.h"
25 25
26 26 QTCOMMERCIALCHART_BEGIN_NAMESPACE
27 27
28 28 DeclarativeLineSeries::DeclarativeLineSeries(QObject *parent) :
29 29 QLineSeries(parent)
30 30 {
31 31 }
32 32
33 QXYSeries *DeclarativeLineSeries::xySeries()
34 {
35 return this;
36 }
37
33 38 QDeclarativeListProperty<QObject> DeclarativeLineSeries::declarativeChildren()
34 39 {
35 40 return QDeclarativeListProperty<QObject>(this, 0, &appendDeclarativeChildren);
36 41 }
37 42
38 43 void DeclarativeLineSeries::appendDeclarativeChildren(QDeclarativeListProperty<QObject> *list, QObject *element)
39 44 {
40 45 QXYSeries *series = qobject_cast<QXYSeries*>(list->object);
41 46 DeclarativeXyPoint *point = qobject_cast<DeclarativeXyPoint *>(element);
42 47 if (series && point)
43 48 series->append(*point);
44 49 }
45 50
46 51 #include "moc_declarativelineseries.cpp"
47 52
48 53 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,61 +1,62
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 DECLARATIVELINESERIES_H
22 22 #define DECLARATIVELINESERIES_H
23 23
24 24 #include "qchartglobal.h"
25 25 #include "qlineseries.h"
26 26 #include "declarativexyseries.h"
27 27 #include <QDeclarativeParserStatus>
28 28 #include <QDeclarativeListProperty>
29 29 #include <QDeclarativeParserStatus>
30 30
31 31 QTCOMMERCIALCHART_BEGIN_NAMESPACE
32 32
33 33 class DeclarativeLineSeries : public QLineSeries, public DeclarativeXySeries, public QDeclarativeParserStatus
34 34 {
35 35 Q_OBJECT
36 36 Q_INTERFACES(QDeclarativeParserStatus)
37 37 Q_PROPERTY(QColor color READ penColor WRITE setPenColor)
38 38 Q_PROPERTY(QDeclarativeListProperty<QObject> declarativeChildren READ declarativeChildren)
39 39 Q_CLASSINFO("DefaultProperty", "declarativeChildren")
40 40
41 41 public:
42 42 explicit DeclarativeLineSeries(QObject *parent = 0);
43 QXYSeries *xySeries();
43 44 QDeclarativeListProperty<QObject> declarativeChildren();
44 45
45 46 public: // from QDeclarativeParserStatus
46 47 void classBegin() { DeclarativeXySeries::classBegin(); }
47 48 void componentComplete() { DeclarativeXySeries::componentComplete(); }
48 49
49 50 public: // from QLineSeries
50 51 Q_INVOKABLE void append(qreal x, qreal y) { QLineSeries::append(x, y); }
51 52 Q_INVOKABLE void remove(qreal x, qreal y) { QLineSeries::remove(x, y); }
52 53 Q_INVOKABLE void clear() { QLineSeries::clear(); }
53 54 Q_INVOKABLE DeclarativeXyPoint *at(int index) { return DeclarativeXySeries::at(index); }
54 55
55 56 public Q_SLOTS:
56 57 static void appendDeclarativeChildren(QDeclarativeListProperty<QObject> *list, QObject *element);
57 58 };
58 59
59 60 QTCOMMERCIALCHART_END_NAMESPACE
60 61
61 62 #endif // DECLARATIVELINESERIES_H
@@ -1,60 +1,65
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 "declarativescatterseries.h"
22 22 #include "declarativechart.h"
23 23 #include "qchart.h"
24 24 #include "qscatterseries.h"
25 25
26 26 QTCOMMERCIALCHART_BEGIN_NAMESPACE
27 27
28 28 DeclarativeScatterSeries::DeclarativeScatterSeries(QObject *parent) :
29 29 QScatterSeries(parent)
30 30 {
31 31 }
32 32
33 QXYSeries *DeclarativeScatterSeries::xySeries()
34 {
35 return this;
36 }
37
33 38 QDeclarativeListProperty<QObject> DeclarativeScatterSeries::declarativeChildren()
34 39 {
35 40 return QDeclarativeListProperty<QObject>(this, 0, &appendDeclarativeChildren);
36 41 }
37 42
38 43 void DeclarativeScatterSeries::appendDeclarativeChildren(QDeclarativeListProperty<QObject> *list, QObject *element)
39 44 {
40 45 QXYSeries *series = qobject_cast<QXYSeries*>(list->object);
41 46 DeclarativeXyPoint *point = qobject_cast<DeclarativeXyPoint *>(element);
42 47 if (series && point)
43 48 series->append(*point);
44 49 }
45 50
46 51 QColor DeclarativeScatterSeries::brushColor()
47 52 {
48 53 return brush().color();
49 54 }
50 55
51 56 void DeclarativeScatterSeries::setBrushColor(QColor color)
52 57 {
53 58 QBrush b = brush();
54 59 b.setColor(color);
55 60 setBrush(b);
56 61 }
57 62
58 63 #include "moc_declarativescatterseries.cpp"
59 64
60 65 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,63 +1,64
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 DECLARATIVESCATTERSERIES_H
22 22 #define DECLARATIVESCATTERSERIES_H
23 23
24 24 #include "qchartglobal.h"
25 25 #include "qscatterseries.h"
26 26 #include "declarativexyseries.h"
27 27 #include <QDeclarativeListProperty>
28 28 #include <QDeclarativeParserStatus>
29 29
30 30 QTCOMMERCIALCHART_BEGIN_NAMESPACE
31 31
32 32 class DeclarativeScatterSeries : public QScatterSeries, public DeclarativeXySeries, public QDeclarativeParserStatus
33 33 {
34 34 Q_OBJECT
35 35 Q_INTERFACES(QDeclarativeParserStatus)
36 36 Q_PROPERTY(QColor color READ brushColor WRITE setBrushColor)
37 37 Q_PROPERTY(QColor borderColor READ penColor WRITE setPenColor)
38 38 Q_PROPERTY(QDeclarativeListProperty<QObject> declarativeChildren READ declarativeChildren)
39 39 Q_CLASSINFO("DefaultProperty", "declarativeChildren")
40 40
41 41 public:
42 42 explicit DeclarativeScatterSeries(QObject *parent = 0);
43 QXYSeries *xySeries();
43 44 QDeclarativeListProperty<QObject> declarativeChildren();
44 45 QColor brushColor();
45 46 void setBrushColor(QColor color);
46 47
47 48 public: // from QDeclarativeParserStatus
48 49 void classBegin() { DeclarativeXySeries::classBegin(); }
49 50 void componentComplete() { DeclarativeXySeries::componentComplete(); }
50 51
51 52 public: // from QScatterSeries
52 53 Q_INVOKABLE void append(qreal x, qreal y) { QScatterSeries::append(x, y); }
53 54 Q_INVOKABLE void remove(qreal x, qreal y) { QScatterSeries::remove(x, y); }
54 55 Q_INVOKABLE void clear() { QScatterSeries::clear(); }
55 56 Q_INVOKABLE DeclarativeXyPoint *at(int index) { return DeclarativeXySeries::at(index); }
56 57
57 58 public Q_SLOTS:
58 59 static void appendDeclarativeChildren(QDeclarativeListProperty<QObject> *list, QObject *element);
59 60 };
60 61
61 62 QTCOMMERCIALCHART_END_NAMESPACE
62 63
63 64 #endif // DECLARATIVESCATTERSERIES_H
@@ -1,48 +1,53
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 "declarativesplineseries.h"
22 22 #include "declarativechart.h"
23 23 #include <QChart>
24 24 #include "declarativexypoint.h"
25 25
26 26 QTCOMMERCIALCHART_BEGIN_NAMESPACE
27 27
28 28 DeclarativeSplineSeries::DeclarativeSplineSeries(QObject *parent) :
29 29 QSplineSeries(parent)
30 30 {
31 31 }
32 32
33 QXYSeries *DeclarativeSplineSeries::xySeries()
34 {
35 return this;
36 }
37
33 38 QDeclarativeListProperty<QObject> DeclarativeSplineSeries::declarativeChildren()
34 39 {
35 40 return QDeclarativeListProperty<QObject>(this, 0, &appendDeclarativeChildren);
36 41 }
37 42
38 43 void DeclarativeSplineSeries::appendDeclarativeChildren(QDeclarativeListProperty<QObject> *list, QObject *element)
39 44 {
40 45 QXYSeries *series = qobject_cast<QXYSeries*>(list->object);
41 46 DeclarativeXyPoint *point = qobject_cast<DeclarativeXyPoint *>(element);
42 47 if (series && point)
43 48 series->append(*point);
44 49 }
45 50
46 51 #include "moc_declarativesplineseries.cpp"
47 52
48 53 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,61 +1,62
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 DECLARATIVESPLINESERIES_H
22 22 #define DECLARATIVESPLINESERIES_H
23 23
24 24 #include "qchartglobal.h"
25 25 #include "qsplineseries.h"
26 26 #include "declarativexyseries.h"
27 27 #include <QDeclarativeParserStatus>
28 28 #include <QDeclarativeListProperty>
29 29 #include <QDeclarativeParserStatus>
30 30
31 31 QTCOMMERCIALCHART_BEGIN_NAMESPACE
32 32
33 33 class DeclarativeSplineSeries : public QSplineSeries, public DeclarativeXySeries, public QDeclarativeParserStatus
34 34 {
35 35 Q_OBJECT
36 36 Q_INTERFACES(QDeclarativeParserStatus)
37 37 Q_PROPERTY(QColor color READ penColor WRITE setPenColor)
38 38 Q_PROPERTY(QDeclarativeListProperty<QObject> declarativeChildren READ declarativeChildren)
39 39 Q_CLASSINFO("DefaultProperty", "declarativeChildren")
40 40
41 41 public:
42 42 explicit DeclarativeSplineSeries(QObject *parent = 0);
43 QXYSeries *xySeries();
43 44 QDeclarativeListProperty<QObject> declarativeChildren();
44 45
45 46 public: // from QDeclarativeParserStatus
46 47 void classBegin() { DeclarativeXySeries::classBegin(); }
47 48 void componentComplete() { DeclarativeXySeries::componentComplete(); }
48 49
49 50 public: // from QSplineSeries
50 51 Q_INVOKABLE void append(qreal x, qreal y) { QSplineSeries::append(x, y); }
51 52 Q_INVOKABLE void remove(qreal x, qreal y) { QSplineSeries::remove(x, y); }
52 53 Q_INVOKABLE void clear() { QSplineSeries::clear(); }
53 54 Q_INVOKABLE DeclarativeXyPoint *at(int index) { return DeclarativeXySeries::at(index); }
54 55
55 56 public Q_SLOTS:
56 57 static void appendDeclarativeChildren(QDeclarativeListProperty<QObject> *list, QObject *element);
57 58 };
58 59
59 60 QTCOMMERCIALCHART_END_NAMESPACE
60 61
61 62 #endif // DECLARATIVESPLINESERIES_H
@@ -1,90 +1,94
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 "DeclarativeXySeries.h"
22 22 #include "declarativexyseries.h"
23 23 #include "declarativechart.h"
24 24 #include <QXYSeries>
25 25 #include <QVXYModelMapper>
26 26 #include <QHXYModelMapper>
27 27 #include <QDeclarativeListProperty>
28 28
29 29 QTCOMMERCIALCHART_BEGIN_NAMESPACE
30 30
31 31 DeclarativeXySeries::DeclarativeXySeries()
32 32 {
33 33 }
34 34
35 35 DeclarativeXySeries::~DeclarativeXySeries()
36 36 {
37 37 }
38 38
39 39 void DeclarativeXySeries::classBegin()
40 40 {
41 41 }
42 42
43 43 void DeclarativeXySeries::componentComplete()
44 44 {
45 // All the inherited objects must be of type QXYSeries, so it is safe to cast
46 QXYSeries *series = reinterpret_cast<QXYSeries *>(this);
45 QXYSeries *series = qobject_cast<QXYSeries *>(xySeries());
46 Q_ASSERT(series);
47
47 48 foreach(QObject *child, series->children()) {
48 49 if (qobject_cast<DeclarativeXyPoint *>(child)) {
49 50 // TODO:
50 51 // series->append(qobject_cast<DeclarativeXyPoint *>(child));
51 52 } else if(qobject_cast<QVXYModelMapper *>(child)) {
52 53 QVXYModelMapper *mapper = qobject_cast<QVXYModelMapper *>(child);
53 54 mapper->setSeries(series);
54 55 } else if(qobject_cast<QHXYModelMapper *>(child)) {
55 56 QHXYModelMapper *mapper = qobject_cast<QHXYModelMapper *>(child);
56 57 mapper->setSeries(series);
57 58 }
58 59 }
59 60 }
60 61
61 62 QColor DeclarativeXySeries::penColor()
62 63 {
63 64 // All the inherited objects must be of type QXYSeries, so it is safe to cast
64 QXYSeries *series = reinterpret_cast<QXYSeries *>(this);
65 QXYSeries *series = qobject_cast<QXYSeries *>(xySeries());
66 Q_ASSERT(series);
65 67 return series->pen().color();
66 68 }
67 69
68 70 void DeclarativeXySeries::setPenColor(QColor color)
69 71 {
70 QXYSeries *series = reinterpret_cast<QXYSeries *>(this);
72 QXYSeries *series = qobject_cast<QXYSeries *>(xySeries());
73 Q_ASSERT(series);
71 74 QPen pen = series->pen();
72 75 pen.setColor(color);
73 76 series->setPen(pen);
74 77 }
75 78
76 79 DeclarativeXyPoint *DeclarativeXySeries::at(int index)
77 80 {
78 QXYSeries *series = reinterpret_cast<QXYSeries *>(this);
81 QXYSeries *series = qobject_cast<QXYSeries *>(xySeries());
82 Q_ASSERT(series);
79 83 if (index < series->count()) {
80 84 QPointF point = series->points().at(index);
81 85 DeclarativeXyPoint *xyPoint = new DeclarativeXyPoint(series);
82 86 xyPoint->setX(point.x());
83 87 xyPoint->setY(point.y());
84 88 return xyPoint;
85 89 }
86 90 return 0;
87 91 }
88 92
89 93
90 94 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,49 +1,51
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 DECLARATIVE_XY_SERIES_H
22 22 #define DECLARATIVE_XY_SERIES_H
23 23
24 24 #include "qchartglobal.h"
25 25 #include "declarativexypoint.h"
26 26 #include <QColor>
27 #include <QXYSeries>
27 28
28 29 QTCOMMERCIALCHART_BEGIN_NAMESPACE
29 30
30 31 class QChart;
31 32 class QAbstractSeries;
32 33
33 34 class DeclarativeXySeries
34 35 {
35 36 public:
36 37 explicit DeclarativeXySeries();
37 38 ~DeclarativeXySeries();
38 39
39 40 public:
40 41 void classBegin();
41 42 void componentComplete();
43 virtual QXYSeries *xySeries() = 0;
42 44 QColor penColor();
43 45 void setPenColor(QColor color);
44 46 DeclarativeXyPoint *at(int index);
45 47 };
46 48
47 49 QTCOMMERCIALCHART_END_NAMESPACE
48 50
49 51 #endif // DECLARATIVE_XY_SERIES_H
General Comments 0
You need to be logged in to leave comments. Login now