##// 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 27 : QDeclarativeItem(parent),
28 28 m_chart(new QChart(this))
29 29 {
30 m_chart->setAnimationOptions(QChart::SeriesAnimations);
30 // m_chart->setAnimationOptions(QChart::SeriesAnimations);
31 31 setFlag(QGraphicsItem::ItemHasNoContents, false);
32 32 }
33 33
@@ -22,7 +22,6
22 22 #include "declarativexyseries.h"
23 23 #include "qxyseries.h"
24 24 #include "declarativechart.h"
25 #include <QObject>
26 25
27 26 QTCOMMERCIALCHART_BEGIN_NAMESPACE
28 27
@@ -41,8 +40,6 void DeclarativeXySeries::classBegin()
41 40 void DeclarativeXySeries::componentComplete()
42 41 {
43 42 QSeries *thisObj = reinterpret_cast<QSeries *>(series());
44 // QSeries *thisObj = qobject_cast<QSeries *>(this);
45 // Q_ASSERT(thisObj);
46 43 DeclarativeChart *declarativeChart = qobject_cast<DeclarativeChart *>(thisObj->parent());
47 44
48 45 if (declarativeChart) {
@@ -25,6 +25,7
25 25 #include "declarativexypoint.h"
26 26 #include "declarativelineseries.h"
27 27 #include "declarativesplineseries.h"
28 #include "declarativeareaseries.h"
28 29 #include "declarativescatterseries.h"
29 30 #include "declarativebarseries.h"
30 31 #include "declarativepieseries.h"
@@ -44,6 +45,7 public:
44 45 qmlRegisterType<DeclarativeScatterSeries>(uri, 1, 0, "ScatterSeries");
45 46 qmlRegisterType<DeclarativeLineSeries>(uri, 1, 0, "LineSeries");
46 47 qmlRegisterType<DeclarativeSplineSeries>(uri, 1, 0, "SplineSeries");
48 qmlRegisterType<DeclarativeAreaSeries>(uri, 1, 0, "AreaSeries");
47 49 qmlRegisterType<DeclarativeBarSeries>(uri, 1, 0, "BarSeries");
48 50 qmlRegisterType<DeclarativePieSeries>(uri, 1, 0, "PieSeries");
49 51 qmlRegisterType<QPieSlice>(uri, 1, 0, "PieSlice");
@@ -28,6 +28,7 SOURCES += \
28 28 declarativexypoint.cpp \
29 29 declarativelineseries.cpp \
30 30 declarativesplineseries.cpp \
31 declarativeareaseries.cpp \
31 32 declarativescatterseries.cpp \
32 33 declarativepieseries.cpp \
33 34 declarativebarseries.cpp
@@ -37,6 +38,7 HEADERS += \
37 38 declarativexypoint.h \
38 39 declarativelineseries.h \
39 40 declarativesplineseries.h \
41 declarativeareaseries.h \
40 42 declarativescatterseries.h \
41 43 declarativepieseries.h \
42 44 declarativebarseries.h
@@ -49,8 +49,6 QPainterPath LineChartItem::shape() const
49 49
50 50 void LineChartItem::setLayout(QVector<QPointF>& points)
51 51 {
52 // qDebug() << "line: " << points.count();
53
54 52 if(points.size()==0)
55 53 {
56 54 XYChartItem::setLayout(points);
@@ -70,6 +68,7 void LineChartItem::setLayout(QVector<QPointF>& points)
70 68 m_rect = linePath.boundingRect();
71 69
72 70 XYChartItem::setLayout(points);
71
73 72 }
74 73
75 74 void LineChartItem::handleUpdated()
@@ -102,7 +102,6 void ScatterChartItem::markerSelected(Marker *marker)
102 102
103 103 void ScatterChartItem::setLayout(QVector<QPointF>& points)
104 104 {
105 // qDebug() << "scatter: " << points.count();
106 105 if(points.size()==0)
107 106 {
108 107 XYChartItem::setLayout(points);
@@ -121,10 +120,8 void ScatterChartItem::setLayout(QVector<QPointF>& points)
121 120 if(diff!=0) handleUpdated();
122 121
123 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++) {
127 Q_ASSERT(i < items.count());
124 for (int i = 0; i < points.size(); i++) {
128 125 Marker* item = static_cast<Marker*>(items.at(i));
129 126 const QPointF& point = points.at(i);
130 127 const QRectF& rect = item->boundingRect();
@@ -54,7 +54,7 Rectangle {
54 54 anchors.left: parent.left
55 55 anchors.right: parent.right
56 56 height: parent.height / 2
57 theme: Chart.ChartThemeBlueCerulean
57 theme: Chart.ChartThemeDark
58 58
59 59 BarSeries {
60 60 barCategories: [ "2008", "2009", "2010", "2011", "2012" ]
@@ -79,7 +79,7 Rectangle {
79 79 anchors.bottom: parent.bottom
80 80 anchors.left: parent.left
81 81 anchors.right: parent.right
82 theme: Chart.ChartThemeHighContrast
82 theme: Chart.ChartThemeBrownSand
83 83
84 84 LineSeries {
85 85 points: [
@@ -90,13 +90,26 Rectangle {
90 90 ]
91 91 }
92 92
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 // }
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
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 114 ScatterSeries {
102 115 points: [
@@ -105,19 +118,19 Rectangle {
105 118 XyPoint { x: 1.57; y: 1.55 }
106 119 ]
107 120 }
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 // }
121 ScatterSeries {
122 points: [
123 XyPoint { x: 2.0; y: 2.0 },
124 XyPoint { x: 2.0; y: 2.1 },
125 XyPoint { x: 2.07; y: 2.05 }
126 ]
127 }
128 ScatterSeries {
129 points: [
130 XyPoint { x: 2.6; y: 2.6 },
131 XyPoint { x: 2.6; y: 2.7 },
132 XyPoint { x: 2.67; y: 2.65 }
133 ]
134 }
122 135 }
123 136 }
General Comments 0
You need to be logged in to leave comments. Login now