##// END OF EJS Templates
Refactoring QML impl for series
Tero Ahola -
r846:accf902f8269
parent child
Show More
@@ -27,6 +27,7 DeclarativeChart::DeclarativeChart(QDeclarativeItem *parent)
27 : QDeclarativeItem(parent),
27 : QDeclarativeItem(parent),
28 m_chart(new QChart(this))
28 m_chart(new QChart(this))
29 {
29 {
30 m_chart->setAnimationOptions(QChart::SeriesAnimations);
30 setFlag(QGraphicsItem::ItemHasNoContents, false);
31 setFlag(QGraphicsItem::ItemHasNoContents, false);
31 }
32 }
32
33
@@ -30,15 +30,9 DeclarativeLineSeries::DeclarativeLineSeries(QObject *parent) :
30 {
30 {
31 }
31 }
32
32
33 void DeclarativeLineSeries::componentComplete()
33 QSeries *DeclarativeLineSeries::series()
34 {
34 {
35 DeclarativeChart *declarativeChart = qobject_cast<DeclarativeChart *>(parent());
35 return this;
36
37 if (declarativeChart) {
38 QChart *chart = qobject_cast<QChart *>(declarativeChart->m_chart);
39 Q_ASSERT(chart);
40 chart->addSeries(this);
41 }
42 }
36 }
43
37
44 QDeclarativeListProperty<DeclarativeXyPoint> DeclarativeLineSeries::points()
38 QDeclarativeListProperty<DeclarativeXyPoint> DeclarativeLineSeries::points()
@@ -37,7 +37,7 public:
37 explicit DeclarativeLineSeries(QObject *parent = 0);
37 explicit DeclarativeLineSeries(QObject *parent = 0);
38
38
39 public:
39 public:
40 void componentComplete();
40 QSeries *series();
41 QDeclarativeListProperty<DeclarativeXyPoint> points();
41 QDeclarativeListProperty<DeclarativeXyPoint> points();
42 };
42 };
43
43
@@ -30,16 +30,9 DeclarativeScatterSeries::DeclarativeScatterSeries(QObject *parent) :
30 {
30 {
31 }
31 }
32
32
33 void DeclarativeScatterSeries::componentComplete()
33 QSeries *DeclarativeScatterSeries::series()
34 {
34 {
35 DeclarativeChart *declarativeChart = qobject_cast<DeclarativeChart *>(parent());
35 return this;
36
37 if (declarativeChart) {
38 QChart *chart = qobject_cast<QChart *>(declarativeChart->m_chart);
39 Q_ASSERT(chart);
40 qDebug() << "chart:" << chart;
41 chart->addSeries(this);
42 }
43 }
36 }
44
37
45 QDeclarativeListProperty<DeclarativeXyPoint> DeclarativeScatterSeries::points()
38 QDeclarativeListProperty<DeclarativeXyPoint> DeclarativeScatterSeries::points()
@@ -37,7 +37,7 public:
37 explicit DeclarativeScatterSeries(QObject *parent = 0);
37 explicit DeclarativeScatterSeries(QObject *parent = 0);
38
38
39 public:
39 public:
40 void componentComplete();
40 QSeries *series();
41 QDeclarativeListProperty<DeclarativeXyPoint> points();
41 QDeclarativeListProperty<DeclarativeXyPoint> points();
42 };
42 };
43
43
@@ -29,15 +29,9 DeclarativeSplineSeries::DeclarativeSplineSeries(QObject *parent) :
29 {
29 {
30 }
30 }
31
31
32 void DeclarativeSplineSeries::componentComplete()
32 QSeries *DeclarativeSplineSeries::series()
33 {
33 {
34 DeclarativeChart *declarativeChart = qobject_cast<DeclarativeChart *>(parent());
34 return this;
35
36 if (declarativeChart) {
37 QChart *chart = qobject_cast<QChart *>(declarativeChart->m_chart);
38 Q_ASSERT(chart);
39 chart->addSeries(this);
40 }
41 }
35 }
42
36
43 QDeclarativeListProperty<DeclarativeXyPoint> DeclarativeSplineSeries::points()
37 QDeclarativeListProperty<DeclarativeXyPoint> DeclarativeSplineSeries::points()
@@ -37,7 +37,7 public:
37 explicit DeclarativeSplineSeries(QObject *parent = 0);
37 explicit DeclarativeSplineSeries(QObject *parent = 0);
38
38
39 public:
39 public:
40 virtual void componentComplete();
40 QSeries *series();
41 QDeclarativeListProperty<DeclarativeXyPoint> points();
41 QDeclarativeListProperty<DeclarativeXyPoint> points();
42 };
42 };
43
43
@@ -21,6 +21,8
21 //#include "DeclarativeXySeries.h"
21 //#include "DeclarativeXySeries.h"
22 #include "declarativexyseries.h"
22 #include "declarativexyseries.h"
23 #include "qxyseries.h"
23 #include "qxyseries.h"
24 #include "declarativechart.h"
25 #include <QObject>
24
26
25 QTCOMMERCIALCHART_BEGIN_NAMESPACE
27 QTCOMMERCIALCHART_BEGIN_NAMESPACE
26
28
@@ -36,12 +38,26 void DeclarativeXySeries::classBegin()
36 {
38 {
37 }
39 }
38
40
41 void DeclarativeXySeries::componentComplete()
42 {
43 QSeries *thisObj = reinterpret_cast<QSeries *>(series());
44 // QSeries *thisObj = qobject_cast<QSeries *>(this);
45 // Q_ASSERT(thisObj);
46 DeclarativeChart *declarativeChart = qobject_cast<DeclarativeChart *>(thisObj->parent());
47
48 if (declarativeChart) {
49 QChart *chart = qobject_cast<QChart *>(declarativeChart->m_chart);
50 Q_ASSERT(chart);
51 chart->addSeries(thisObj);
52 }
53 }
54
39 void DeclarativeXySeries::appendPoints(QDeclarativeListProperty<DeclarativeXyPoint> *list,
55 void DeclarativeXySeries::appendPoints(QDeclarativeListProperty<DeclarativeXyPoint> *list,
40 DeclarativeXyPoint *element)
56 DeclarativeXyPoint *element)
41 {
57 {
42 QXYSeries *series = qobject_cast<QXYSeries *>(list->object);
58 QXYSeries *series = qobject_cast<QXYSeries *>(list->object);
43 if (series)
59 if (series)
44 series->append(QPointF(element->x(), element->y()));
60 series->append(element->x(), element->y());
45 }
61 }
46
62
47 QTCOMMERCIALCHART_END_NAMESPACE
63 QTCOMMERCIALCHART_END_NAMESPACE
@@ -29,6 +29,7
29 QTCOMMERCIALCHART_BEGIN_NAMESPACE
29 QTCOMMERCIALCHART_BEGIN_NAMESPACE
30
30
31 class QChart;
31 class QChart;
32 class QSeries;
32
33
33 class DeclarativeXySeries : public QDeclarativeParserStatus
34 class DeclarativeXySeries : public QDeclarativeParserStatus
34 {
35 {
@@ -40,9 +41,10 public:
40
41
41 public: // from QDeclarativeParserStatus
42 public: // from QDeclarativeParserStatus
42 virtual void classBegin();
43 virtual void classBegin();
43 virtual void componentComplete() = 0;
44 virtual void componentComplete();
44
45
45 public:
46 public:
47 virtual QSeries *series() = 0;
46 virtual QDeclarativeListProperty<DeclarativeXyPoint> points() = 0;
48 virtual QDeclarativeListProperty<DeclarativeXyPoint> points() = 0;
47
49
48 public Q_SLOTS:
50 public Q_SLOTS:
@@ -49,6 +49,8 QPainterPath LineChartItem::shape() const
49
49
50 void LineChartItem::setLayout(QVector<QPointF>& points)
50 void LineChartItem::setLayout(QVector<QPointF>& points)
51 {
51 {
52 // qDebug() << "line: " << points.count();
53
52 if(points.size()==0)
54 if(points.size()==0)
53 {
55 {
54 XYChartItem::setLayout(points);
56 XYChartItem::setLayout(points);
@@ -68,7 +70,6 void LineChartItem::setLayout(QVector<QPointF>& points)
68 m_rect = linePath.boundingRect();
70 m_rect = linePath.boundingRect();
69
71
70 XYChartItem::setLayout(points);
72 XYChartItem::setLayout(points);
71
72 }
73 }
73
74
74 void LineChartItem::handleUpdated()
75 void LineChartItem::handleUpdated()
@@ -102,6 +102,7 void ScatterChartItem::markerSelected(Marker *marker)
102
102
103 void ScatterChartItem::setLayout(QVector<QPointF>& points)
103 void ScatterChartItem::setLayout(QVector<QPointF>& points)
104 {
104 {
105 // qDebug() << "scatter: " << points.count();
105 if(points.size()==0)
106 if(points.size()==0)
106 {
107 {
107 XYChartItem::setLayout(points);
108 XYChartItem::setLayout(points);
@@ -120,8 +121,10 void ScatterChartItem::setLayout(QVector<QPointF>& points)
120 if(diff!=0) handleUpdated();
121 if(diff!=0) handleUpdated();
121
122
122 QList<QGraphicsItem*> items = m_items.childItems();
123 QList<QGraphicsItem*> items = m_items.childItems();
124 // qDebug() << "items count" << items.count();
123
125
124 for(int i=0; i< points.size();i++) {
126 for (int i = 0; i < points.size() && i < items.count(); i++) {
127 Q_ASSERT(i < items.count());
125 Marker* item = static_cast<Marker*>(items.at(i));
128 Marker* item = static_cast<Marker*>(items.at(i));
126 const QPointF& point = points.at(i);
129 const QPointF& point = points.at(i);
127 const QRectF& rect = item->boundingRect();
130 const QRectF& rect = item->boundingRect();
@@ -90,13 +90,13 Rectangle {
90 ]
90 ]
91 }
91 }
92
92
93 SplineSeries {
93 // SplineSeries {
94 points: [
94 // points: [
95 XyPoint { x: 0.0; y: 0.3 },
95 // XyPoint { x: 0.0; y: 0.3 },
96 XyPoint { x: 1.1; y: 3.2 },
96 // XyPoint { x: 1.1; y: 3.2 },
97 XyPoint { x: 4.17; y: 3.15 }
97 // XyPoint { x: 4.17; y: 3.15 }
98 ]
98 // ]
99 }
99 // }
100
100
101 ScatterSeries {
101 ScatterSeries {
102 points: [
102 points: [
@@ -105,19 +105,19 Rectangle {
105 XyPoint { x: 1.57; y: 1.55 }
105 XyPoint { x: 1.57; y: 1.55 }
106 ]
106 ]
107 }
107 }
108 ScatterSeries {
108 // ScatterSeries {
109 points: [
109 // points: [
110 XyPoint { x: 2.0; y: 2.0 },
110 // XyPoint { x: 2.0; y: 2.0 },
111 XyPoint { x: 2.0; y: 2.1 },
111 // XyPoint { x: 2.0; y: 2.1 },
112 XyPoint { x: 2.07; y: 2.05 }
112 // XyPoint { x: 2.07; y: 2.05 }
113 ]
113 // ]
114 }
114 // }
115 ScatterSeries {
115 // ScatterSeries {
116 points: [
116 // points: [
117 XyPoint { x: 2.6; y: 2.6 },
117 // XyPoint { x: 2.6; y: 2.6 },
118 XyPoint { x: 2.6; y: 2.7 },
118 // XyPoint { x: 2.6; y: 2.7 },
119 XyPoint { x: 2.67; y: 2.65 }
119 // XyPoint { x: 2.67; y: 2.65 }
120 ]
120 // ]
121 }
121 // }
122 }
122 }
123 }
123 }
General Comments 0
You need to be logged in to leave comments. Login now