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