##// END OF EJS Templates
QML area series to use models
Tero Ahola -
r1161:122f80368c30
parent child
Show More
@@ -1,111 +1,111
1 /****************************************************************************
1 /****************************************************************************
2 **
2 **
3 ** Copyright (C) 2012 Digia Plc
3 ** Copyright (C) 2012 Digia Plc
4 ** All rights reserved.
4 ** All rights reserved.
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 **
6 **
7 ** This file is part of the Qt Commercial Charts Add-on.
7 ** This file is part of the Qt Commercial Charts Add-on.
8 **
8 **
9 ** $QT_BEGIN_LICENSE$
9 ** $QT_BEGIN_LICENSE$
10 ** Licensees holding valid Qt Commercial licenses may use this file in
10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 ** accordance with the Qt Commercial License Agreement provided with the
11 ** accordance with the Qt Commercial License Agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia.
13 ** a written agreement between you and Digia.
14 **
14 **
15 ** If you have questions regarding the use of this file, please use
15 ** If you have questions regarding the use of this file, please use
16 ** contact form at http://qt.digia.com
16 ** contact form at http://qt.digia.com
17 ** $QT_END_LICENSE$
17 ** $QT_END_LICENSE$
18 **
18 **
19 ****************************************************************************/
19 ****************************************************************************/
20
20
21 import QtQuick 1.0
21 import QtQuick 1.0
22 import QtCommercial.Chart 1.0
22 import QtCommercial.Chart 1.0
23
23
24 Rectangle {
24 Rectangle {
25 anchors.fill: parent
25 anchors.fill: parent
26
26
27 ChartView {
27 ChartView {
28 id: chart
28 id: chart
29 title: "Car brand shares in Finland"
29 title: "Top-5 car brand shares in Finland"
30 anchors.top: parent.top
30 anchors.top: parent.top
31 anchors.bottom: button.top
31 anchors.bottom: button.top
32 anchors.left: parent.left
32 anchors.left: parent.left
33 anchors.right: parent.right
33 anchors.right: parent.right
34 theme: ChartView.ChartThemeLight
34 theme: ChartView.ChartThemeLight
35 legend: ChartView.LegendBottom
35 legend: ChartView.LegendBottom
36 animationOptions: ChartView.SeriesAnimations
36 animationOptions: ChartView.SeriesAnimations
37
37
38 PieSeries {
38 PieSeries {
39 model: PieModel {
39 model: PieModel {
40 id: pieModel
40 id: pieModel
41 PieSlice { label: "Volkswagen"; value: 13.5 }
41 PieSlice { label: "Volkswagen"; value: 13.5 }
42 PieSlice { label: "Toyota"; value: 10.9 }
42 PieSlice { label: "Toyota"; value: 10.9 }
43 PieSlice { label: "Ford"; value: 8.6 }
43 PieSlice { label: "Ford"; value: 8.6 }
44 PieSlice { label: "Skoda"; value: 8.2 }
44 PieSlice { label: "Skoda"; value: 8.2 }
45 PieSlice { label: "Volvo"; value: 6.8 }
45 PieSlice { label: "Volvo"; value: 6.8 }
46 }
46 }
47 }
47 }
48 }
48 }
49
49
50 Rectangle {
50 Rectangle {
51 id: button
51 id: button
52 anchors.bottom: parent.bottom
52 anchors.bottom: parent.bottom
53 anchors.bottomMargin: 10
53 anchors.bottomMargin: 10
54 anchors.horizontalCenter: parent.horizontalCenter
54 anchors.horizontalCenter: parent.horizontalCenter
55 height: 40
55 height: 40
56 width: 100
56 width: 100
57 color: "orange"
57 color: "orange"
58 radius: 5
58 radius: 5
59 Text {
59 Text {
60 id: buttonText
60 id: buttonText
61 anchors.centerIn: parent
61 anchors.centerIn: parent
62 text: button.state == "" ? "Show others" : "Hide others"
62 text: button.state == "" ? "Show others" : "Hide others"
63 }
63 }
64 MouseArea {
64 MouseArea {
65 anchors.fill: parent
65 anchors.fill: parent
66 onClicked: {
66 onClicked: {
67 if (button.state == "") {
67 if (button.state == "") {
68 // The share of "others" was enabled -> append the data into the model
68 // The share of "others" was enabled -> append the data into the model
69 // TODO: this should also be doable by redefining the range inside the model
69 // TODO: this should also be doable by redefining the range inside the model
70 button.state = "show";
70 button.state = "show";
71 pieModel.append(["Others", 52.0]);
71 pieModel.append(["Others", 52.0]);
72 } else {
72 } else {
73 // The share of "others" was disabled -> remove the data from the model
73 // The share of "others" was disabled -> remove the data from the model
74 // TODO: this should also be doable by redefining the range inside the model
74 // TODO: this should also be doable by redefining the range inside the model
75 button.state = "";
75 button.state = "";
76 pieModel.removeRow(pieModel.count - 1);
76 pieModel.removeRow(pieModel.count - 1);
77 }
77 }
78 }
78 }
79 }
79 }
80 }
80 }
81
81
82
82
83 // TODO: Optional syntax for defining models for different series. Is this really needed?
83 // TODO: Optional syntax for defining models for different series. Is this really needed?
84 // ChartModel {
84 // ChartModel {
85 // id: chartModel
85 // id: chartModel
86 // ChartElement { column1: "Volkswagen"; column2: 13.5; column3: 1.2 }
86 // ChartElement { column1: "Volkswagen"; column2: 13.5; column3: 1.2 }
87 // ChartElement { column1: "Toyota"; column2: 10.9; column3: 2.5 }
87 // ChartElement { column1: "Toyota"; column2: 10.9; column3: 2.5 }
88 // }
88 // }
89 // // column3 not used by pie series
89 // // column3 not used by pie series
90 // PieSeries {
90 // PieSeries {
91 // model: chartModel
91 // model: chartModel
92 // mappings: [ {"column1":"label"}, {"column2":"value"} ]
92 // mappings: [ {"column1":"label"}, {"column2":"value"} ]
93 // }
93 // }
94
94
95
95
96 // TODO: show how to use data from a list model in a chart view
96 // TODO: show how to use data from a list model in a chart view
97 // i.e. copy the data into a chart model
97 // i.e. copy the data into a chart model
98 // ListModel {
98 // ListModel {
99 // id: listModel
99 // id: listModel
100 // ListElement {
100 // ListElement {
101 // label: "Volkswagen"
101 // label: "Volkswagen"
102 // value: 13.5
102 // value: 13.5
103 // }
103 // }
104 // ListElement {
104 // ListElement {
105 // label: "Toyota"
105 // label: "Toyota"
106 // value: 10.9
106 // value: 10.9
107 // }
107 // }
108 // // and so on...
108 // // and so on...
109 // }
109 // }
110
110
111 }
111 }
@@ -1,131 +1,115
1 /****************************************************************************
1 /****************************************************************************
2 **
2 **
3 ** Copyright (C) 2012 Digia Plc
3 ** Copyright (C) 2012 Digia Plc
4 ** All rights reserved.
4 ** All rights reserved.
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 **
6 **
7 ** This file is part of the Qt Commercial Charts Add-on.
7 ** This file is part of the Qt Commercial Charts Add-on.
8 **
8 **
9 ** $QT_BEGIN_LICENSE$
9 ** $QT_BEGIN_LICENSE$
10 ** Licensees holding valid Qt Commercial licenses may use this file in
10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 ** accordance with the Qt Commercial License Agreement provided with the
11 ** accordance with the Qt Commercial License Agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia.
13 ** a written agreement between you and Digia.
14 **
14 **
15 ** If you have questions regarding the use of this file, please use
15 ** If you have questions regarding the use of this file, please use
16 ** contact form at http://qt.digia.com
16 ** contact form at http://qt.digia.com
17 ** $QT_END_LICENSE$
17 ** $QT_END_LICENSE$
18 **
18 **
19 ****************************************************************************/
19 ****************************************************************************/
20
20
21 import QtQuick 1.0
21 import QtQuick 1.0
22 import QtCommercial.Chart 1.0
22 import QtCommercial.Chart 1.0
23
23
24 Rectangle {
24 Rectangle {
25 anchors.fill: parent
25 anchors.fill: parent
26
26
27 ChartView {
27 ChartView {
28 title: "NHL All-Star Team Players"
28 title: "NHL All-Star Team Players"
29 anchors.fill: parent
29 anchors.fill: parent
30 theme: ChartView.ChartThemeHighContrast
30 theme: ChartView.ChartThemeHighContrast
31 legend: ChartView.LegendTop
31 legend: ChartView.LegendTop
32 axisXLabels: ["0", "2000", "1", "2001", "2", "2002", "3", "2003", "4", "2004", "5", "2005",
32 axisXLabels: ["0", "2000", "1", "2001", "2", "2002", "3", "2003", "4", "2004", "5", "2005",
33 "6", "2006", "7", "2007", "8", "2008", "9", "2009", "10", "2010", "11", "2011"]
33 "6", "2006", "7", "2007", "8", "2008", "9", "2009", "10", "2010", "11", "2011"]
34
34
35 AreaSeries {
35 AreaSeries {
36 name: "Russian"
37 upperModel: russianModel
38 lowerModel: zerosModel
39 }
40 AreaSeries {
36 name: "Swedish"
41 name: "Swedish"
37 points: [
42 upperModel: swedishModel
38 XyPoint { x: 0; y: 1 },
43 lowerModel: zerosModel
39 XyPoint { x: 1; y: 1 },
40 XyPoint { x: 2; y: 3 },
41 XyPoint { x: 3; y: 3 },
42 XyPoint { x: 4; y: 2 },
43 XyPoint { x: 5; y: 0 },
44 XyPoint { x: 6; y: 2 },
45 XyPoint { x: 7; y: 1 },
46 XyPoint { x: 8; y: 2 },
47 XyPoint { x: 9; y: 1 },
48 XyPoint { x: 10; y: 3 },
49 XyPoint { x: 11; y: 3 }
50 ]
51 lowerPoints: [
52 XyPoint { x: 0; y: 0 },
53 XyPoint { x: 1; y: 0 },
54 XyPoint { x: 2; y: 0 },
55 XyPoint { x: 3; y: 0 },
56 XyPoint { x: 4; y: 0 },
57 XyPoint { x: 5; y: 0 },
58 XyPoint { x: 6; y: 0 },
59 XyPoint { x: 7; y: 0 },
60 XyPoint { x: 8; y: 0 },
61 XyPoint { x: 9; y: 0 },
62 XyPoint { x: 10; y: 0 },
63 XyPoint { x: 11; y: 0 }
64 ]
65 }
44 }
66
67 AreaSeries {
45 AreaSeries {
68 name: "Russian"
46 name: "Finnish"
69 points: [
47 upperModel: finnishModel
70 XyPoint { x: 0; y: 1 },
48 lowerModel: zerosModel
71 XyPoint { x: 1; y: 1 },
49 }
72 XyPoint { x: 2; y: 1 },
50 }
73 XyPoint { x: 3; y: 1 },
51
74 XyPoint { x: 4; y: 1 },
52 XYModel {
75 XyPoint { x: 5; y: 0 },
53 id: zerosModel
76 XyPoint { x: 6; y: 1 },
54 XyPoint { x: 0; y: 0 }
77 XyPoint { x: 7; y: 1 },
55 XyPoint { x: 1; y: 0 }
78 XyPoint { x: 8; y: 4 },
56 XyPoint { x: 2; y: 0 }
79 XyPoint { x: 9; y: 3 },
57 XyPoint { x: 3; y: 0 }
80 XyPoint { x: 10; y: 2 },
58 XyPoint { x: 4; y: 0 }
81 XyPoint { x: 11; y: 1 }
59 XyPoint { x: 5; y: 0 }
82 ]
60 XyPoint { x: 6; y: 0 }
83 lowerPoints: [
61 XyPoint { x: 7; y: 0 }
84 XyPoint { x: 0; y: 0 },
62 XyPoint { x: 8; y: 0 }
85 XyPoint { x: 1; y: 0 },
63 XyPoint { x: 9; y: 0 }
86 XyPoint { x: 2; y: 0 },
64 XyPoint { x: 10; y: 0 }
87 XyPoint { x: 3; y: 0 },
88 XyPoint { x: 4; y: 0 },
89 XyPoint { x: 5; y: 0 },
90 XyPoint { x: 6; y: 0 },
91 XyPoint { x: 7; y: 0 },
92 XyPoint { x: 8; y: 0 },
93 XyPoint { x: 9; y: 0 },
94 XyPoint { x: 10; y: 0 },
95 XyPoint { x: 11; y: 0 }
65 XyPoint { x: 11; y: 0 }
96 ]
97 }
66 }
98
67
99 AreaSeries {
68 XYModel {
100 name: "Finnish"
69 id: russianModel
101 points: [
70 XyPoint { x: 0; y: 1 }
102 XyPoint { x: 0; y: 0 },
71 XyPoint { x: 1; y: 1 }
103 XyPoint { x: 1; y: 0 },
72 XyPoint { x: 2; y: 1 }
104 XyPoint { x: 2; y: 0 },
73 XyPoint { x: 3; y: 1 }
105 XyPoint { x: 3; y: 0 },
74 XyPoint { x: 4; y: 1 }
106 XyPoint { x: 4; y: 0 },
75 XyPoint { x: 5; y: 0 }
107 XyPoint { x: 5; y: 0 },
76 XyPoint { x: 6; y: 1 }
108 XyPoint { x: 6; y: 1 },
77 XyPoint { x: 7; y: 1 }
109 XyPoint { x: 7; y: 0 },
78 XyPoint { x: 8; y: 4 }
110 XyPoint { x: 8; y: 0 },
79 XyPoint { x: 9; y: 3 }
111 XyPoint { x: 9; y: 0 },
80 XyPoint { x: 10; y: 2 }
112 XyPoint { x: 10; y: 0 },
113 XyPoint { x: 11; y: 1 }
81 XyPoint { x: 11; y: 1 }
114 ]
115 lowerPoints: [
116 XyPoint { x: 0; y: 0 },
117 XyPoint { x: 1; y: 0 },
118 XyPoint { x: 2; y: 0 },
119 XyPoint { x: 3; y: 0 },
120 XyPoint { x: 4; y: 0 },
121 XyPoint { x: 5; y: 0 },
122 XyPoint { x: 6; y: 0 },
123 XyPoint { x: 7; y: 0 },
124 XyPoint { x: 8; y: 0 },
125 XyPoint { x: 9; y: 0 },
126 XyPoint { x: 10; y: 0 },
127 XyPoint { x: 11; y: 0 }
128 ]
129 }
82 }
83
84 XYModel {
85 id: swedishModel
86 XyPoint { x: 0; y: 1 }
87 XyPoint { x: 1; y: 1 }
88 XyPoint { x: 2; y: 3 }
89 XyPoint { x: 3; y: 3 }
90 XyPoint { x: 4; y: 2 }
91 XyPoint { x: 5; y: 0 }
92 XyPoint { x: 6; y: 2 }
93 XyPoint { x: 7; y: 1 }
94 XyPoint { x: 8; y: 2 }
95 XyPoint { x: 9; y: 1 }
96 XyPoint { x: 10; y: 3 }
97 XyPoint { x: 11; y: 3 }
98 }
99
100 XYModel {
101 id: finnishModel
102 XyPoint { x: 0; y: 0 }
103 XyPoint { x: 1; y: 0 }
104 XyPoint { x: 2; y: 0 }
105 XyPoint { x: 3; y: 0 }
106 XyPoint { x: 4; y: 0 }
107 XyPoint { x: 5; y: 0 }
108 XyPoint { x: 6; y: 1 }
109 XyPoint { x: 7; y: 0 }
110 XyPoint { x: 8; y: 0 }
111 XyPoint { x: 9; y: 0 }
112 XyPoint { x: 10; y: 0 }
113 XyPoint { x: 11; y: 1 }
130 }
114 }
131 }
115 }
@@ -1,65 +1,70
1 /****************************************************************************
1 /****************************************************************************
2 **
2 **
3 ** Copyright (C) 2012 Digia Plc
3 ** Copyright (C) 2012 Digia Plc
4 ** All rights reserved.
4 ** All rights reserved.
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 **
6 **
7 ** This file is part of the Qt Commercial Charts Add-on.
7 ** This file is part of the Qt Commercial Charts Add-on.
8 **
8 **
9 ** $QT_BEGIN_LICENSE$
9 ** $QT_BEGIN_LICENSE$
10 ** Licensees holding valid Qt Commercial licenses may use this file in
10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 ** accordance with the Qt Commercial License Agreement provided with the
11 ** accordance with the Qt Commercial License Agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia.
13 ** a written agreement between you and Digia.
14 **
14 **
15 ** If you have questions regarding the use of this file, please use
15 ** If you have questions regarding the use of this file, please use
16 ** contact form at http://qt.digia.com
16 ** contact form at http://qt.digia.com
17 ** $QT_END_LICENSE$
17 ** $QT_END_LICENSE$
18 **
18 **
19 ****************************************************************************/
19 ****************************************************************************/
20
20
21 #include "declarativeareaseries.h"
21 #include "declarativeareaseries.h"
22 #include "declarativechart.h"
22 #include "declarativechart.h"
23 #include "qchart.h"
23 #include "qchart.h"
24 #include "qlineseries.h"
25
24
26 QTCOMMERCIALCHART_BEGIN_NAMESPACE
25 QTCOMMERCIALCHART_BEGIN_NAMESPACE
27
26
28 DeclarativeAreaSeries::DeclarativeAreaSeries(QObject *parent) :
27 DeclarativeAreaSeries::DeclarativeAreaSeries(QObject *parent) :
29 QAreaSeries(new QLineSeries(parent), new QLineSeries(parent))
28 QAreaSeries(new QLineSeries(parent), new QLineSeries(parent))
30 {
29 {
31 }
30 }
32
31
33 QDeclarativeListProperty<DeclarativeXyPoint> DeclarativeAreaSeries::points()
32 bool DeclarativeAreaSeries::setDeclarativeUpperModel(DeclarativeXyModel *model)
34 {
33 {
35 return QDeclarativeListProperty<DeclarativeXyPoint>(this, 0, &DeclarativeAreaSeries::appendPoints);
34 QAbstractItemModel *m = qobject_cast<QAbstractItemModel *>(model);
35 bool value(false);
36 if (m) {
37 upperSeries()->setModel(m);
38 upperSeries()->setModelMapping(0, 1, Qt::Vertical);
39 } else {
40 qWarning("DeclarativeAreaSeries: Illegal model");
41 }
42 return value;
36 }
43 }
37
44
38 QDeclarativeListProperty<DeclarativeXyPoint> DeclarativeAreaSeries::lowerPoints()
45 DeclarativeXyModel *DeclarativeAreaSeries::declarativeUpperModel()
39 {
46 {
40 return QDeclarativeListProperty<DeclarativeXyPoint>(this, 0, &DeclarativeAreaSeries::appendLowerPoints);
47 return qobject_cast<DeclarativeXyModel *>(upperSeries()->model());
41 }
48 }
42
49
43 void DeclarativeAreaSeries::appendPoints(QDeclarativeListProperty<DeclarativeXyPoint> *list,
50 bool DeclarativeAreaSeries::setDeclarativeLowerModel(DeclarativeXyModel *model)
44 DeclarativeXyPoint *element)
45 {
51 {
46 QAreaSeries *series = qobject_cast<QAreaSeries *>(list->object);
52 QAbstractItemModel *m = qobject_cast<QAbstractItemModel *>(model);
47 if (series) {
53 bool value(false);
48 QLineSeries *upper = series->upperSeries();
54 if (m) {
49 upper->append(element->x(), element->y());
55 lowerSeries()->setModel(m);
56 lowerSeries()->setModelMapping(0, 1, Qt::Vertical);
57 } else {
58 qWarning("DeclarativeAreaSeries: Illegal model");
50 }
59 }
60 return value;
51 }
61 }
52
62
53 void DeclarativeAreaSeries::appendLowerPoints(QDeclarativeListProperty<DeclarativeXyPoint> *list,
63 DeclarativeXyModel *DeclarativeAreaSeries::declarativeLowerModel()
54 DeclarativeXyPoint *element)
55 {
64 {
56 QAreaSeries *series = qobject_cast<QAreaSeries *>(list->object);
65 return qobject_cast<DeclarativeXyModel *>(lowerSeries()->model());
57 if (series) {
58 QLineSeries *lower = series->lowerSeries();
59 lower->append(element->x(), element->y());
60 }
61 }
66 }
62
67
63 #include "moc_declarativeareaseries.cpp"
68 #include "moc_declarativeareaseries.cpp"
64
69
65 QTCOMMERCIALCHART_END_NAMESPACE
70 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,52 +1,49
1 /****************************************************************************
1 /****************************************************************************
2 **
2 **
3 ** Copyright (C) 2012 Digia Plc
3 ** Copyright (C) 2012 Digia Plc
4 ** All rights reserved.
4 ** All rights reserved.
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 **
6 **
7 ** This file is part of the Qt Commercial Charts Add-on.
7 ** This file is part of the Qt Commercial Charts Add-on.
8 **
8 **
9 ** $QT_BEGIN_LICENSE$
9 ** $QT_BEGIN_LICENSE$
10 ** Licensees holding valid Qt Commercial licenses may use this file in
10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 ** accordance with the Qt Commercial License Agreement provided with the
11 ** accordance with the Qt Commercial License Agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia.
13 ** a written agreement between you and Digia.
14 **
14 **
15 ** If you have questions regarding the use of this file, please use
15 ** If you have questions regarding the use of this file, please use
16 ** contact form at http://qt.digia.com
16 ** contact form at http://qt.digia.com
17 ** $QT_END_LICENSE$
17 ** $QT_END_LICENSE$
18 **
18 **
19 ****************************************************************************/
19 ****************************************************************************/
20
20
21 #ifndef DECLARATIVEAREASERIES_H
21 #ifndef DECLARATIVEAREASERIES_H
22 #define DECLARATIVEAREASERIES_H
22 #define DECLARATIVEAREASERIES_H
23
23
24 #include "qchartglobal.h"
24 #include "qchartglobal.h"
25 #include "qareaseries.h"
25 #include "qareaseries.h"
26 #include "declarativelineseries.h"
26 #include "declarativexyseries.h"
27 #include "declarativexyseries.h"
27
28
28 QTCOMMERCIALCHART_BEGIN_NAMESPACE
29 QTCOMMERCIALCHART_BEGIN_NAMESPACE
29
30
30 class DeclarativeAreaSeries : public QAreaSeries, public DeclarativeXySeries
31 class DeclarativeAreaSeries : public QAreaSeries, public DeclarativeXySeries
31 {
32 {
32 Q_OBJECT
33 Q_OBJECT
33 Q_PROPERTY(QDeclarativeListProperty<DeclarativeXyPoint> points READ points)
34 Q_PROPERTY(DeclarativeXyModel *upperModel READ declarativeUpperModel WRITE setDeclarativeUpperModel)
34 Q_PROPERTY(QDeclarativeListProperty<DeclarativeXyPoint> lowerPoints READ lowerPoints)
35 Q_PROPERTY(DeclarativeXyModel *lowerModel READ declarativeLowerModel WRITE setDeclarativeLowerModel)
35
36
36 public:
37 public:
37 explicit DeclarativeAreaSeries(QObject *parent = 0);
38 explicit DeclarativeAreaSeries(QObject *parent = 0);
38
39
39 public:
40 public:
40 QDeclarativeListProperty<DeclarativeXyPoint> points();
41 bool setDeclarativeUpperModel(DeclarativeXyModel *model);
41 QDeclarativeListProperty<DeclarativeXyPoint> lowerPoints();
42 DeclarativeXyModel *declarativeUpperModel();
42
43 bool setDeclarativeLowerModel(DeclarativeXyModel *model);
43 public Q_SLOTS:
44 DeclarativeXyModel *declarativeLowerModel();
44 static void appendPoints(QDeclarativeListProperty<DeclarativeXyPoint> *list,
45 DeclarativeXyPoint *element);
46 static void appendLowerPoints(QDeclarativeListProperty<DeclarativeXyPoint> *list,
47 DeclarativeXyPoint *element);
48 };
45 };
49
46
50 QTCOMMERCIALCHART_END_NAMESPACE
47 QTCOMMERCIALCHART_END_NAMESPACE
51
48
52 #endif // DECLARATIVEAREASERIES_H
49 #endif // DECLARATIVEAREASERIES_H
@@ -1,141 +1,138
1 /****************************************************************************
1 /****************************************************************************
2 **
2 **
3 ** Copyright (C) 2012 Digia Plc
3 ** Copyright (C) 2012 Digia Plc
4 ** All rights reserved.
4 ** All rights reserved.
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 **
6 **
7 ** This file is part of the Qt Commercial Charts Add-on.
7 ** This file is part of the Qt Commercial Charts Add-on.
8 **
8 **
9 ** $QT_BEGIN_LICENSE$
9 ** $QT_BEGIN_LICENSE$
10 ** Licensees holding valid Qt Commercial licenses may use this file in
10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 ** accordance with the Qt Commercial License Agreement provided with the
11 ** accordance with the Qt Commercial License Agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia.
13 ** a written agreement between you and Digia.
14 **
14 **
15 ** If you have questions regarding the use of this file, please use
15 ** If you have questions regarding the use of this file, please use
16 ** contact form at http://qt.digia.com
16 ** contact form at http://qt.digia.com
17 ** $QT_END_LICENSE$
17 ** $QT_END_LICENSE$
18 **
18 **
19 ****************************************************************************/
19 ****************************************************************************/
20
20
21 #include "declarativemodel.h"
21 #include "declarativemodel.h"
22 #include <qdeclarativelist.h>
22 #include <qdeclarativelist.h>
23 #include <QDebug>
23 #include <QDebug>
24
24
25 QTCOMMERCIALCHART_BEGIN_NAMESPACE
25 QTCOMMERCIALCHART_BEGIN_NAMESPACE
26
26
27 ////////////// XY model ///////////////////////
27 ////////////// XY model ///////////////////////
28
28
29 DeclarativeXyModel::DeclarativeXyModel(QObject *parent) :
29 DeclarativeXyModel::DeclarativeXyModel(QObject *parent) :
30 ChartTableModel(parent)
30 ChartTableModel(parent)
31 {
31 {
32 }
32 }
33
33
34 void DeclarativeXyModel::append(DeclarativeXyPoint* point)
34 void DeclarativeXyModel::append(DeclarativeXyPoint* point)
35 {
35 {
36 // qDebug() << "DeclarativeXyModel::append:" << point->x() << " " << point->y();
36 // qDebug() << "DeclarativeXyModel::append:" << point->x() << " " << point->y();
37 insertRow(rowCount());
37 insertRow(rowCount());
38 QModelIndex xModelIndex = createIndex(rowCount() - 1, 0);
38 QModelIndex xModelIndex = createIndex(rowCount() - 1, 0);
39 QModelIndex yModelIndex = createIndex(rowCount() - 1, 1);
39 QModelIndex yModelIndex = createIndex(rowCount() - 1, 1);
40 setData(xModelIndex, point->x());
40 setData(xModelIndex, point->x());
41 setData(yModelIndex, point->y());
41 setData(yModelIndex, point->y());
42 dataChanged(xModelIndex, yModelIndex);
42 dataChanged(xModelIndex, yModelIndex);
43 }
43 }
44
44
45 void DeclarativeXyModel::append(QVariantList points)
45 void DeclarativeXyModel::append(QVariantList points)
46 {
46 {
47 qreal x = 0.0;
47 qreal x = 0.0;
48 for (int i(0); i < points.count(); i++) {
48 for (int i(0); i < points.count(); i++) {
49 if (i % 2) {
49 if (i % 2) {
50 bool ok(false);
50 bool ok(false);
51 qreal y = points.at(i).toReal(&ok);
51 qreal y = points.at(i).toReal(&ok);
52 if (ok) {
52 if (ok) {
53 DeclarativeXyPoint *point= new DeclarativeXyPoint();
53 DeclarativeXyPoint *point= new DeclarativeXyPoint();
54 point->setX(x);
54 point->setX(x);
55 point->setY(y);
55 point->setY(y);
56 append(point);
56 append(point);
57 } else {
57 } else {
58 qWarning() << "Illegal y value";
58 qWarning() << "Illegal y value";
59 }
59 }
60 } else {
60 } else {
61 bool ok(false);
61 bool ok(false);
62 x = points.at(i).toReal(&ok);
62 x = points.at(i).toReal(&ok);
63 if (!ok) {
63 if (!ok) {
64 qWarning() << "Illegal x value";
64 qWarning() << "Illegal x value";
65 }
65 }
66 }
66 }
67 }
67 }
68 }
68 }
69
69
70 QDeclarativeListProperty<DeclarativeXyPoint> DeclarativeXyModel::points()
70 QDeclarativeListProperty<DeclarativeXyPoint> DeclarativeXyModel::points()
71 {
71 {
72 return QDeclarativeListProperty<DeclarativeXyPoint>(this, 0, &DeclarativeXyModel::appendPoint);
72 return QDeclarativeListProperty<DeclarativeXyPoint>(this, 0, &DeclarativeXyModel::appendPoint);
73 }
73 }
74
74
75 void DeclarativeXyModel::appendPoint(QDeclarativeListProperty<DeclarativeXyPoint> *list,
75 void DeclarativeXyModel::appendPoint(QDeclarativeListProperty<DeclarativeXyPoint> *list,
76 DeclarativeXyPoint *point)
76 DeclarativeXyPoint *point)
77 {
77 {
78 DeclarativeXyModel *model = qobject_cast<DeclarativeXyModel *>(list->object);
78 DeclarativeXyModel *model = qobject_cast<DeclarativeXyModel *>(list->object);
79 if (model)
79 if (model)
80 model->append(point);
80 model->append(point);
81 else
81 else
82 qWarning() << "Illegal point item";
82 qWarning() << "Illegal point item";
83 }
83 }
84
84
85 ////////////// Pie model ///////////////////////
85 ////////////// Pie model ///////////////////////
86
86
87 DeclarativePieModel::DeclarativePieModel(QObject *parent) :
87 DeclarativePieModel::DeclarativePieModel(QObject *parent) :
88 ChartTableModel(parent)
88 ChartTableModel(parent)
89 {
89 {
90 }
90 }
91
91
92 void DeclarativePieModel::append(QPieSlice* slice)
92 void DeclarativePieModel::append(QPieSlice* slice)
93 {
93 {
94 qDebug() << "DeclarativePieModel::append:" << slice->label() << " " << slice->value();
94 // qDebug() << "DeclarativePieModel::append:" << slice->label() << " " << slice->value();
95 qDebug() << "rowCount:" << rowCount();
96 qDebug() << "coolCount:" << columnCount();
97 insertRow(rowCount());
95 insertRow(rowCount());
98 qDebug() << "new rowCount:" << rowCount();
99
96
100 qDebug() << setData(createIndex(rowCount() - 1, 0), slice->value());
97 setData(createIndex(rowCount() - 1, 0), slice->value());
101 qDebug() << setData(createIndex(rowCount() - 1, 1), slice->label());
98 setData(createIndex(rowCount() - 1, 1), slice->label());
102 }
99 }
103
100
104 void DeclarativePieModel::append(QVariantList slices)
101 void DeclarativePieModel::append(QVariantList slices)
105 {
102 {
106 qDebug() << "append:" << slices;
103 // qDebug() << "append:" << slices;
107 QString label = "";
104 QString label = "";
108 for (int i(0); i < slices.count(); i++) {
105 for (int i(0); i < slices.count(); i++) {
109 if (i % 2) {
106 if (i % 2) {
110 bool ok(false);
107 bool ok(false);
111 qreal value = slices.at(i).toReal(&ok);
108 qreal value = slices.at(i).toReal(&ok);
112 if (ok) {
109 if (ok) {
113 QPieSlice *slice = new QPieSlice(value, label);
110 QPieSlice *slice = new QPieSlice(value, label);
114 append(slice);
111 append(slice);
115 } else {
112 } else {
116 qWarning() << "Illegal slice item";
113 qWarning() << "Illegal slice item";
117 }
114 }
118 } else {
115 } else {
119 label = slices.at(i).toString();
116 label = slices.at(i).toString();
120 }
117 }
121 }
118 }
122 }
119 }
123
120
124 QDeclarativeListProperty<QPieSlice> DeclarativePieModel::slices()
121 QDeclarativeListProperty<QPieSlice> DeclarativePieModel::slices()
125 {
122 {
126 return QDeclarativeListProperty<QPieSlice>(this, 0, &DeclarativePieModel::appendSlice);
123 return QDeclarativeListProperty<QPieSlice>(this, 0, &DeclarativePieModel::appendSlice);
127 }
124 }
128
125
129 void DeclarativePieModel::appendSlice(QDeclarativeListProperty<QPieSlice> *list,
126 void DeclarativePieModel::appendSlice(QDeclarativeListProperty<QPieSlice> *list,
130 QPieSlice *slice)
127 QPieSlice *slice)
131 {
128 {
132 DeclarativePieModel *pieModel = qobject_cast<DeclarativePieModel *>(list->object);
129 DeclarativePieModel *pieModel = qobject_cast<DeclarativePieModel *>(list->object);
133 if (pieModel)
130 if (pieModel)
134 pieModel->append(slice);
131 pieModel->append(slice);
135 else
132 else
136 qWarning() << "Illegal slice item";
133 qWarning() << "Illegal slice item";
137 }
134 }
138
135
139 #include "moc_declarativemodel.cpp"
136 #include "moc_declarativemodel.cpp"
140
137
141 QTCOMMERCIALCHART_END_NAMESPACE
138 QTCOMMERCIALCHART_END_NAMESPACE
General Comments 0
You need to be logged in to leave comments. Login now