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