##// END OF EJS Templates
Added area series to QML api
Tero Ahola -
r847:50493b5d7ed9
parent child
Show More
@@ -0,0 +1,70
1 /****************************************************************************
2 **
3 ** Copyright (C) 2012 Digia Plc
4 ** All rights reserved.
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 **
7 ** This file is part of the Qt Commercial Charts Add-on.
8 **
9 ** $QT_BEGIN_LICENSE$
10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 ** accordance with the Qt Commercial License Agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia.
14 **
15 ** If you have questions regarding the use of this file, please use
16 ** contact form at http://qt.digia.com
17 ** $QT_END_LICENSE$
18 **
19 ****************************************************************************/
20
21 #include "declarativeareaseries.h"
22 #include "declarativechart.h"
23 #include "qchart.h"
24 #include "qlineseries.h"
25
26 QTCOMMERCIALCHART_BEGIN_NAMESPACE
27
28 DeclarativeAreaSeries::DeclarativeAreaSeries(QObject *parent) :
29 QAreaSeries(new QLineSeries(parent), new QLineSeries(parent))
30 {
31 }
32
33 QSeries *DeclarativeAreaSeries::series()
34 {
35 return this;
36 }
37
38 QDeclarativeListProperty<DeclarativeXyPoint> DeclarativeAreaSeries::points()
39 {
40 return QDeclarativeListProperty<DeclarativeXyPoint>(this, 0, &DeclarativeAreaSeries::appendPoints);
41 }
42
43 QDeclarativeListProperty<DeclarativeXyPoint> DeclarativeAreaSeries::lowerPoints()
44 {
45 return QDeclarativeListProperty<DeclarativeXyPoint>(this, 0, &DeclarativeAreaSeries::appendLowerPoints);
46 }
47
48 void DeclarativeAreaSeries::appendPoints(QDeclarativeListProperty<DeclarativeXyPoint> *list,
49 DeclarativeXyPoint *element)
50 {
51 QAreaSeries *series = qobject_cast<QAreaSeries *>(list->object);
52 if (series) {
53 QLineSeries *upper = series->upperSeries();
54 upper->append(element->x(), element->y());
55 }
56 }
57
58 void DeclarativeAreaSeries::appendLowerPoints(QDeclarativeListProperty<DeclarativeXyPoint> *list,
59 DeclarativeXyPoint *element)
60 {
61 QAreaSeries *series = qobject_cast<QAreaSeries *>(list->object);
62 if (series) {
63 QLineSeries *lower = series->lowerSeries();
64 lower->append(element->x(), element->y());
65 }
66 }
67
68 #include "moc_declarativeareaseries.cpp"
69
70 QTCOMMERCIALCHART_END_NAMESPACE
@@ -0,0 +1,53
1 /****************************************************************************
2 **
3 ** Copyright (C) 2012 Digia Plc
4 ** All rights reserved.
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 **
7 ** This file is part of the Qt Commercial Charts Add-on.
8 **
9 ** $QT_BEGIN_LICENSE$
10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 ** accordance with the Qt Commercial License Agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia.
14 **
15 ** If you have questions regarding the use of this file, please use
16 ** contact form at http://qt.digia.com
17 ** $QT_END_LICENSE$
18 **
19 ****************************************************************************/
20
21 #ifndef DECLARATIVEAREASERIES_H
22 #define DECLARATIVEAREASERIES_H
23
24 #include "qchartglobal.h"
25 #include "qareaseries.h"
26 #include "declarativexyseries.h"
27
28 QTCOMMERCIALCHART_BEGIN_NAMESPACE
29
30 class DeclarativeAreaSeries : public QAreaSeries, public DeclarativeXySeries
31 {
32 Q_OBJECT
33 Q_PROPERTY(QDeclarativeListProperty<DeclarativeXyPoint> points READ points)
34 Q_PROPERTY(QDeclarativeListProperty<DeclarativeXyPoint> lowerPoints READ lowerPoints)
35
36 public:
37 explicit DeclarativeAreaSeries(QObject *parent = 0);
38
39 public:
40 QSeries *series();
41 QDeclarativeListProperty<DeclarativeXyPoint> points();
42 QDeclarativeListProperty<DeclarativeXyPoint> lowerPoints();
43
44 public Q_SLOTS:
45 static void appendPoints(QDeclarativeListProperty<DeclarativeXyPoint> *list,
46 DeclarativeXyPoint *element);
47 static void appendLowerPoints(QDeclarativeListProperty<DeclarativeXyPoint> *list,
48 DeclarativeXyPoint *element);
49 };
50
51 QTCOMMERCIALCHART_END_NAMESPACE
52
53 #endif // DECLARATIVEAREASERIES_H
@@ -27,7 +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 // m_chart->setAnimationOptions(QChart::SeriesAnimations);
31 setFlag(QGraphicsItem::ItemHasNoContents, false);
31 setFlag(QGraphicsItem::ItemHasNoContents, false);
32 }
32 }
33
33
@@ -22,7 +22,6
22 #include "declarativexyseries.h"
22 #include "declarativexyseries.h"
23 #include "qxyseries.h"
23 #include "qxyseries.h"
24 #include "declarativechart.h"
24 #include "declarativechart.h"
25 #include <QObject>
26
25
27 QTCOMMERCIALCHART_BEGIN_NAMESPACE
26 QTCOMMERCIALCHART_BEGIN_NAMESPACE
28
27
@@ -41,8 +40,6 void DeclarativeXySeries::classBegin()
41 void DeclarativeXySeries::componentComplete()
40 void DeclarativeXySeries::componentComplete()
42 {
41 {
43 QSeries *thisObj = reinterpret_cast<QSeries *>(series());
42 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());
43 DeclarativeChart *declarativeChart = qobject_cast<DeclarativeChart *>(thisObj->parent());
47
44
48 if (declarativeChart) {
45 if (declarativeChart) {
@@ -25,6 +25,7
25 #include "declarativexypoint.h"
25 #include "declarativexypoint.h"
26 #include "declarativelineseries.h"
26 #include "declarativelineseries.h"
27 #include "declarativesplineseries.h"
27 #include "declarativesplineseries.h"
28 #include "declarativeareaseries.h"
28 #include "declarativescatterseries.h"
29 #include "declarativescatterseries.h"
29 #include "declarativebarseries.h"
30 #include "declarativebarseries.h"
30 #include "declarativepieseries.h"
31 #include "declarativepieseries.h"
@@ -44,6 +45,7 public:
44 qmlRegisterType<DeclarativeScatterSeries>(uri, 1, 0, "ScatterSeries");
45 qmlRegisterType<DeclarativeScatterSeries>(uri, 1, 0, "ScatterSeries");
45 qmlRegisterType<DeclarativeLineSeries>(uri, 1, 0, "LineSeries");
46 qmlRegisterType<DeclarativeLineSeries>(uri, 1, 0, "LineSeries");
46 qmlRegisterType<DeclarativeSplineSeries>(uri, 1, 0, "SplineSeries");
47 qmlRegisterType<DeclarativeSplineSeries>(uri, 1, 0, "SplineSeries");
48 qmlRegisterType<DeclarativeAreaSeries>(uri, 1, 0, "AreaSeries");
47 qmlRegisterType<DeclarativeBarSeries>(uri, 1, 0, "BarSeries");
49 qmlRegisterType<DeclarativeBarSeries>(uri, 1, 0, "BarSeries");
48 qmlRegisterType<DeclarativePieSeries>(uri, 1, 0, "PieSeries");
50 qmlRegisterType<DeclarativePieSeries>(uri, 1, 0, "PieSeries");
49 qmlRegisterType<QPieSlice>(uri, 1, 0, "PieSlice");
51 qmlRegisterType<QPieSlice>(uri, 1, 0, "PieSlice");
@@ -28,6 +28,7 SOURCES += \
28 declarativexypoint.cpp \
28 declarativexypoint.cpp \
29 declarativelineseries.cpp \
29 declarativelineseries.cpp \
30 declarativesplineseries.cpp \
30 declarativesplineseries.cpp \
31 declarativeareaseries.cpp \
31 declarativescatterseries.cpp \
32 declarativescatterseries.cpp \
32 declarativepieseries.cpp \
33 declarativepieseries.cpp \
33 declarativebarseries.cpp
34 declarativebarseries.cpp
@@ -37,6 +38,7 HEADERS += \
37 declarativexypoint.h \
38 declarativexypoint.h \
38 declarativelineseries.h \
39 declarativelineseries.h \
39 declarativesplineseries.h \
40 declarativesplineseries.h \
41 declarativeareaseries.h \
40 declarativescatterseries.h \
42 declarativescatterseries.h \
41 declarativepieseries.h \
43 declarativepieseries.h \
42 declarativebarseries.h
44 declarativebarseries.h
@@ -49,8 +49,6 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
54 if(points.size()==0)
52 if(points.size()==0)
55 {
53 {
56 XYChartItem::setLayout(points);
54 XYChartItem::setLayout(points);
@@ -70,6 +68,7 void LineChartItem::setLayout(QVector<QPointF>& points)
70 m_rect = linePath.boundingRect();
68 m_rect = linePath.boundingRect();
71
69
72 XYChartItem::setLayout(points);
70 XYChartItem::setLayout(points);
71
73 }
72 }
74
73
75 void LineChartItem::handleUpdated()
74 void LineChartItem::handleUpdated()
@@ -102,7 +102,6 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();
106 if(points.size()==0)
105 if(points.size()==0)
107 {
106 {
108 XYChartItem::setLayout(points);
107 XYChartItem::setLayout(points);
@@ -121,10 +120,8 void ScatterChartItem::setLayout(QVector<QPointF>& points)
121 if(diff!=0) handleUpdated();
120 if(diff!=0) handleUpdated();
122
121
123 QList<QGraphicsItem*> items = m_items.childItems();
122 QList<QGraphicsItem*> items = m_items.childItems();
124 // qDebug() << "items count" << items.count();
125
123
126 for (int i = 0; i < points.size() && i < items.count(); i++) {
124 for (int i = 0; i < points.size(); i++) {
127 Q_ASSERT(i < items.count());
128 Marker* item = static_cast<Marker*>(items.at(i));
125 Marker* item = static_cast<Marker*>(items.at(i));
129 const QPointF& point = points.at(i);
126 const QPointF& point = points.at(i);
130 const QRectF& rect = item->boundingRect();
127 const QRectF& rect = item->boundingRect();
@@ -54,7 +54,7 Rectangle {
54 anchors.left: parent.left
54 anchors.left: parent.left
55 anchors.right: parent.right
55 anchors.right: parent.right
56 height: parent.height / 2
56 height: parent.height / 2
57 theme: Chart.ChartThemeBlueCerulean
57 theme: Chart.ChartThemeDark
58
58
59 BarSeries {
59 BarSeries {
60 barCategories: [ "2008", "2009", "2010", "2011", "2012" ]
60 barCategories: [ "2008", "2009", "2010", "2011", "2012" ]
@@ -79,7 +79,7 Rectangle {
79 anchors.bottom: parent.bottom
79 anchors.bottom: parent.bottom
80 anchors.left: parent.left
80 anchors.left: parent.left
81 anchors.right: parent.right
81 anchors.right: parent.right
82 theme: Chart.ChartThemeHighContrast
82 theme: Chart.ChartThemeBrownSand
83
83
84 LineSeries {
84 LineSeries {
85 points: [
85 points: [
@@ -90,13 +90,26 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
101 AreaSeries {
102 points: [
103 XyPoint { x: 0.0; y: 1.1 },
104 XyPoint { x: 2.5; y: 3.6 },
105 XyPoint { x: 3.57; y: 2.55 }
106 ]
107 lowerPoints: [
108 XyPoint { x: 0.0; y: 0.0 },
109 XyPoint { x: 2.5; y: 0.0 },
110 XyPoint { x: 3.57; y: 0.0 }
111 ]
112 }
100
113
101 ScatterSeries {
114 ScatterSeries {
102 points: [
115 points: [
@@ -105,19 +118,19 Rectangle {
105 XyPoint { x: 1.57; y: 1.55 }
118 XyPoint { x: 1.57; y: 1.55 }
106 ]
119 ]
107 }
120 }
108 // ScatterSeries {
121 ScatterSeries {
109 // points: [
122 points: [
110 // XyPoint { x: 2.0; y: 2.0 },
123 XyPoint { x: 2.0; y: 2.0 },
111 // XyPoint { x: 2.0; y: 2.1 },
124 XyPoint { x: 2.0; y: 2.1 },
112 // XyPoint { x: 2.07; y: 2.05 }
125 XyPoint { x: 2.07; y: 2.05 }
113 // ]
126 ]
114 // }
127 }
115 // ScatterSeries {
128 ScatterSeries {
116 // points: [
129 points: [
117 // XyPoint { x: 2.6; y: 2.6 },
130 XyPoint { x: 2.6; y: 2.6 },
118 // XyPoint { x: 2.6; y: 2.7 },
131 XyPoint { x: 2.6; y: 2.7 },
119 // XyPoint { x: 2.67; y: 2.65 }
132 XyPoint { x: 2.67; y: 2.65 }
120 // ]
133 ]
121 // }
134 }
122 }
135 }
123 }
136 }
General Comments 0
You need to be logged in to leave comments. Login now