##// END OF EJS Templates
Simplified declarative implementation
Tero Ahola -
r1117:4e706181034e
parent child
Show More
@@ -31,9 +31,9 Rectangle {
31 31 legend: Chart.LegendBottom
32 32
33 33 PieSeries {
34 horizontalPosition: 0.2
35 verticalPosition: 0.3
36 size: 0.4
34 horizontalPosition: 0.5
35 verticalPosition: 0.5
36 size: 0.7
37 37 slices: [
38 38 PieSlice { label: "Volkswagen"; value: 13.5 },
39 39 PieSlice { label: "Toyota"; value: 10.9 },
@@ -43,10 +43,5 Rectangle {
43 43 PieSlice { label: "Others"; value: 52.0 }
44 44 ]
45 45 }
46
47 BarSeries {
48 barCategories: [ "2008", "2009", "2010", "2011", "2012" ]
49 // data implementation missing
50 }
51 46 }
52 47 }
@@ -31,20 +31,20 Rectangle {
31 31 legend: Chart.LegendTop
32 32
33 33 AreaSeries {
34 name: "Finnish"
34 name: "Swedish"
35 35 points: [
36 XyPoint { x: 0; y: 0 },
37 XyPoint { x: 1; y: 0 },
38 XyPoint { x: 2; y: 0 },
39 XyPoint { x: 3; y: 0 },
40 XyPoint { x: 4; y: 0 },
36 XyPoint { x: 0; y: 1 },
37 XyPoint { x: 1; y: 1 },
38 XyPoint { x: 2; y: 3 },
39 XyPoint { x: 3; y: 3 },
40 XyPoint { x: 4; y: 2 },
41 41 XyPoint { x: 5; y: 0 },
42 XyPoint { x: 6; y: 1 },
43 XyPoint { x: 7; y: 0 },
44 XyPoint { x: 8; y: 0 },
45 XyPoint { x: 9; y: 0 },
46 XyPoint { x: 10; y: 0 },
47 XyPoint { x: 11; y: 1 }
42 XyPoint { x: 6; y: 2 },
43 XyPoint { x: 7; y: 1 },
44 XyPoint { x: 8; y: 2 },
45 XyPoint { x: 9; y: 1 },
46 XyPoint { x: 10; y: 3 },
47 XyPoint { x: 11; y: 3 }
48 48 ]
49 49 lowerPoints: [
50 50 XyPoint { x: 0; y: 0 },
@@ -95,20 +95,20 Rectangle {
95 95 }
96 96
97 97 AreaSeries {
98 name: "Swedish"
98 name: "Finnish"
99 99 points: [
100 XyPoint { x: 0; y: 1 },
101 XyPoint { x: 1; y: 1 },
102 XyPoint { x: 2; y: 3 },
103 XyPoint { x: 3; y: 3 },
104 XyPoint { x: 4; y: 2 },
100 XyPoint { x: 0; y: 0 },
101 XyPoint { x: 1; y: 0 },
102 XyPoint { x: 2; y: 0 },
103 XyPoint { x: 3; y: 0 },
104 XyPoint { x: 4; y: 0 },
105 105 XyPoint { x: 5; y: 0 },
106 XyPoint { x: 6; y: 2 },
107 XyPoint { x: 7; y: 1 },
108 XyPoint { x: 8; y: 2 },
109 XyPoint { x: 9; y: 1 },
110 XyPoint { x: 10; y: 3 },
111 XyPoint { x: 11; y: 3 }
106 XyPoint { x: 6; y: 1 },
107 XyPoint { x: 7; y: 0 },
108 XyPoint { x: 8; y: 0 },
109 XyPoint { x: 9; y: 0 },
110 XyPoint { x: 10; y: 0 },
111 XyPoint { x: 11; y: 1 }
112 112 ]
113 113 lowerPoints: [
114 114 XyPoint { x: 0; y: 0 },
@@ -40,7 +40,7 Rectangle {
40 40 Loader {
41 41 id: loader
42 42 anchors.fill: parent
43 source: "View" + (__viewNumber % 4 + 1) + ".qml";
43 source: "View" + (__viewNumber % 5 + 1) + ".qml";
44 44 }
45 45
46 46 MouseArea {
@@ -6,5 +6,6
6 6 <file>qml/qmlchart/View2.qml</file>
7 7 <file>qml/qmlchart/View3.qml</file>
8 8 <file>qml/qmlchart/View4.qml</file>
9 <file>qml/qmlchart/View5.qml</file>
9 10 </qresource>
10 11 </RCC>
@@ -30,11 +30,6 DeclarativeAreaSeries::DeclarativeAreaSeries(QObject *parent) :
30 30 {
31 31 }
32 32
33 QAbstractSeries *DeclarativeAreaSeries::series()
34 {
35 return this;
36 }
37
38 33 QDeclarativeListProperty<DeclarativeXyPoint> DeclarativeAreaSeries::points()
39 34 {
40 35 return QDeclarativeListProperty<DeclarativeXyPoint>(this, 0, &DeclarativeAreaSeries::appendPoints);
@@ -37,7 +37,6 public:
37 37 explicit DeclarativeAreaSeries(QObject *parent = 0);
38 38
39 39 public:
40 QAbstractSeries *series();
41 40 QDeclarativeListProperty<DeclarativeXyPoint> points();
42 41 QDeclarativeListProperty<DeclarativeXyPoint> lowerPoints();
43 42
@@ -19,6 +19,7
19 19 ****************************************************************************/
20 20
21 21 #include "declarativechart.h"
22 #include "declarativepieseries.h"
22 23 #include <QPainter>
23 24
24 25 QTCOMMERCIALCHART_BEGIN_NAMESPACE
@@ -36,6 +37,26 DeclarativeChart::~DeclarativeChart()
36 37 delete m_chart;
37 38 }
38 39
40 void DeclarativeChart::childEvent(QChildEvent *event)
41 {
42 if (event->type() == QEvent::ChildAdded) {
43 if (qobject_cast<QAbstractSeries *>(event->child())) {
44 m_chart->addSeries(qobject_cast<QAbstractSeries *>(event->child()));
45 }
46 }
47 }
48
49 void DeclarativeChart::componentComplete()
50 {
51 foreach(QObject *child, children()) {
52 if (qobject_cast<QAbstractSeries *>(child)) {
53 m_chart->addSeries(qobject_cast<QAbstractSeries *>(child));
54 }
55 }
56
57 QDeclarativeItem::componentComplete();
58 }
59
39 60 void DeclarativeChart::geometryChanged(const QRectF &newGeometry, const QRectF &oldGeometry)
40 61 {
41 62 Q_UNUSED(oldGeometry)
@@ -53,6 +53,8 public:
53 53 ~DeclarativeChart();
54 54
55 55 public: // From QDeclarativeItem/QGraphicsItem
56 void childEvent(QChildEvent *event);
57 void componentComplete();
56 58 void geometryChanged(const QRectF &newGeometry, const QRectF &oldGeometry);
57 59 void paint (QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0);
58 60
@@ -30,11 +30,6 DeclarativeLineSeries::DeclarativeLineSeries(QObject *parent) :
30 30 {
31 31 }
32 32
33 QAbstractSeries *DeclarativeLineSeries::series()
34 {
35 return this;
36 }
37
38 33 QDeclarativeListProperty<DeclarativeXyPoint> DeclarativeLineSeries::points()
39 34 {
40 35 return QDeclarativeListProperty<DeclarativeXyPoint>(this, 0, &DeclarativeXySeries::appendPoints);
@@ -37,7 +37,6 public:
37 37 explicit DeclarativeLineSeries(QObject *parent = 0);
38 38
39 39 public:
40 QAbstractSeries *series();
41 40 QDeclarativeListProperty<DeclarativeXyPoint> points();
42 41 };
43 42
@@ -25,25 +25,10
25 25 QTCOMMERCIALCHART_BEGIN_NAMESPACE
26 26
27 27 DeclarativePieSeries::DeclarativePieSeries(QObject *parent) :
28 QPieSeries(parent),
29 m_chart(0)
28 QPieSeries(parent)
30 29 {
31 30 }
32 31
33 void DeclarativePieSeries::classBegin()
34 {
35 }
36
37 void DeclarativePieSeries::componentComplete()
38 {
39 DeclarativeChart *declarativeChart = qobject_cast<DeclarativeChart *>(parent());
40 if (declarativeChart) {
41 QChart *chart = qobject_cast<QChart *>(declarativeChart->m_chart);
42 Q_ASSERT(chart);
43 chart->addSeries(this);
44 }
45 }
46
47 32 QDeclarativeListProperty<QPieSlice> DeclarativePieSeries::slices()
48 33 {
49 34 return QDeclarativeListProperty<QPieSlice>(this, 0, &DeclarativePieSeries::appendSlice);
@@ -24,32 +24,24
24 24 #include "qchartglobal.h"
25 25 #include "qpieslice.h"
26 26 #include "qpieseries.h"
27 #include <QDeclarativeItem>
27 #include <QDeclarativeListProperty>
28 28
29 29 QTCOMMERCIALCHART_BEGIN_NAMESPACE
30 30
31 31 class QChart;
32 32
33 class DeclarativePieSeries : public QPieSeries, public QDeclarativeParserStatus
33 class DeclarativePieSeries : public QPieSeries
34 34 {
35 35 Q_OBJECT
36 Q_INTERFACES(QDeclarativeParserStatus)
37 36 Q_PROPERTY(QDeclarativeListProperty<QPieSlice> slices READ slices)
38 37
39 38 public:
40 39 explicit DeclarativePieSeries(QObject *parent = 0);
41 40 QDeclarativeListProperty<QPieSlice> slices();
42 41
43 public: // from QDeclarativeParserStatus
44 void classBegin();
45 void componentComplete();
46
47 42 public Q_SLOTS:
48 43 static void appendSlice(QDeclarativeListProperty<QPieSlice> *list,
49 44 QPieSlice *element);
50
51 private:
52 QChart *m_chart;
53 45 };
54 46
55 47 QTCOMMERCIALCHART_END_NAMESPACE
@@ -30,11 +30,6 DeclarativeScatterSeries::DeclarativeScatterSeries(QObject *parent) :
30 30 {
31 31 }
32 32
33 QAbstractSeries *DeclarativeScatterSeries::series()
34 {
35 return this;
36 }
37
38 33 QDeclarativeListProperty<DeclarativeXyPoint> DeclarativeScatterSeries::points()
39 34 {
40 35 return QDeclarativeListProperty<DeclarativeXyPoint>(this, 0, &DeclarativeXySeries::appendPoints);
@@ -37,7 +37,6 public:
37 37 explicit DeclarativeScatterSeries(QObject *parent = 0);
38 38
39 39 public:
40 QAbstractSeries *series();
41 40 QDeclarativeListProperty<DeclarativeXyPoint> points();
42 41 };
43 42
@@ -29,11 +29,6 DeclarativeSplineSeries::DeclarativeSplineSeries(QObject *parent) :
29 29 {
30 30 }
31 31
32 QAbstractSeries *DeclarativeSplineSeries::series()
33 {
34 return this;
35 }
36
37 32 QDeclarativeListProperty<DeclarativeXyPoint> DeclarativeSplineSeries::points()
38 33 {
39 34 return QDeclarativeListProperty<DeclarativeXyPoint>(this, 0, &DeclarativeXySeries::appendPoints);
@@ -37,7 +37,6 public:
37 37 explicit DeclarativeSplineSeries(QObject *parent = 0);
38 38
39 39 public:
40 QAbstractSeries *series();
41 40 QDeclarativeListProperty<DeclarativeXyPoint> points();
42 41 };
43 42
@@ -33,22 +33,6 DeclarativeXySeries::~DeclarativeXySeries()
33 33 {
34 34 }
35 35
36 void DeclarativeXySeries::classBegin()
37 {
38 }
39
40 void DeclarativeXySeries::componentComplete()
41 {
42 QAbstractSeries *thisObj = reinterpret_cast<QAbstractSeries *>(series());
43 DeclarativeChart *declarativeChart = qobject_cast<DeclarativeChart *>(thisObj->parent());
44
45 if (declarativeChart) {
46 QChart *chart = qobject_cast<QChart *>(declarativeChart->m_chart);
47 Q_ASSERT(chart);
48 chart->addSeries(thisObj);
49 }
50 }
51
52 36 void DeclarativeXySeries::appendPoints(QDeclarativeListProperty<DeclarativeXyPoint> *list,
53 37 DeclarativeXyPoint *element)
54 38 {
@@ -23,7 +23,6
23 23
24 24 #include "qchartglobal.h"
25 25 #include "declarativexypoint.h"
26 #include <QDeclarativeParserStatus>
27 26 #include <QDeclarativeListProperty>
28 27
29 28 QTCOMMERCIALCHART_BEGIN_NAMESPACE
@@ -31,7 +30,7 QTCOMMERCIALCHART_BEGIN_NAMESPACE
31 30 class QChart;
32 31 class QAbstractSeries;
33 32
34 class DeclarativeXySeries : public QDeclarativeParserStatus
33 class DeclarativeXySeries
35 34 {
36 35 Q_INTERFACES(QDeclarativeParserStatus)
37 36
@@ -39,12 +38,7 public:
39 38 explicit DeclarativeXySeries();
40 39 ~DeclarativeXySeries();
41 40
42 public: // from QDeclarativeParserStatus
43 virtual void classBegin();
44 virtual void componentComplete();
45
46 41 public:
47 virtual QAbstractSeries *series() = 0;
48 42 virtual QDeclarativeListProperty<DeclarativeXyPoint> points() = 0;
49 43
50 44 public Q_SLOTS:
General Comments 0
You need to be logged in to leave comments. Login now