##// END OF EJS Templates
Now using only one declarative model
Tero Ahola -
r1169:afaf49bc7dc0
parent child
Show More
@@ -1,138 +1,126
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 property int __explodedIndex: -1
27 27
28 ChartModel {
29 id: chartModel
30 ChartModelRow { values: ["Volkswagen", 13.5] }
31 ChartModelRow { values: ["Toyota", 10.9] }
32 ChartModelRow { values: ["Ford", 8.6] }
33 ChartModelRow { values: ["Skoda", 8.2] }
34 ChartModelRow { values: ["Volvo", 6.8] }
35 }
36
28 37 ChartView {
29 38 id: chart
30 39 title: "Top-5 car brand shares in Finland"
31 40 anchors.top: parent.top
32 41 anchors.bottom: button.top
33 42 anchors.left: parent.left
34 43 anchors.right: parent.right
35 44 theme: ChartView.ChartThemeLight
36 45 legend: ChartView.LegendBottom
37 46 animationOptions: ChartView.SeriesAnimations
38 47
39 48 PieSeries {
40 49 id: pieSeries
41 model: PieModel {
42 id: pieModel
43 // TODO: initializing properties does not work at the moment, see DeclarativePieModel::append
44 // TODO: explode range, color, border color, border thickness, font, ..
45 PieSlice { exploded: true; label: "Volkswagen"; value: 13.5 }
46 PieSlice { label: "Toyota"; value: 10.9 }
47 PieSlice { label: "Ford"; value: 8.6 }
48 PieSlice { label: "Skoda"; value: 8.2 }
49 PieSlice { label: "Volvo"; value: 6.8 }
50 }
50 model: chartModel
51 modelMapper.mapLabels: 0
52 modelMapper.mapValues: 1
53 modelMapper.first: 0
54 modelMapper.count: -1 // "Undefined" = -1 by default
55 modelMapper.orientation: PieModelMapper.Vertical
56
57 // TODO: PieSlice to append the data directly into the mapped columns
58 //PieSlice { label: "Toyota"; value: 10.9 }
51 59 }
52 60 }
53 61
62 Component.onCompleted: {
63 chartModel.append(["Others", 52.0]);
64 }
65
54 66 Timer {
55 67 repeat: true
56 68 interval: 2000
57 69 running: true
58 70 onTriggered: {
59 changeSliceExploded(__explodedIndex);
60 __explodedIndex = (__explodedIndex + 1) % pieModel.count;
61 changeSliceExploded(__explodedIndex);
62 }
63 }
71 // Set all slices as not exploded
72 for (var i = 0; i < pieSeries.count; i++)
73 pieSeries.slice(i).exploded = false;
64 74
65 function changeSliceExploded(index) {
66 if (index >= 0 && index < pieModel.count) {
67 pieSeries.slice(index).exploded = !pieSeries.slice(index).exploded;
75 // Explode one of the slices
76 __explodedIndex = (__explodedIndex + 1) % pieSeries.count;
77 pieSeries.slice(__explodedIndex).exploded = true;
68 78 }
69 79 }
70 80
71 81 Rectangle {
72 82 id: button
73 83 anchors.bottom: parent.bottom
74 84 anchors.bottomMargin: 10
75 85 anchors.horizontalCenter: parent.horizontalCenter
76 86 height: 40
77 87 width: 100
78 88 color: "orange"
79 89 radius: 5
80 90 Text {
81 91 id: buttonText
82 92 anchors.centerIn: parent
83 text: button.state == "" ? "Show others" : "Hide others"
93 text: "Hide others"
84 94 }
85 95 MouseArea {
86 96 anchors.fill: parent
87 97 onClicked: {
88 if (button.state == "") {
89 // The share of "others" was enabled -> append the data into the model
90 // TODO: this should also be doable by redefining the range inside the model
91 button.state = "show";
92 pieModel.append(["Others", 52.0]);
98 if (buttonText.text == "Show others") {
99 pieSeries.modelMapper.count = -1;
100 buttonText.text = "Hide others";
93 101 } else {
94 // The share of "others" was disabled -> remove the data from the model
95 // TODO: this should also be doable by redefining the range inside the model
96 button.state = "";
97 pieModel.removeRow(pieModel.count - 1);
102 pieSeries.modelMapper.count = 5;
103 buttonText.text = "Show others";
104 //pieModel.removeRow(pieModel.count - 1);
98 105 // TODO: removeAll("label") ?
99 106 }
100 107 }
101 108 }
102 109 }
103 110
104
105 // TODO: Optional syntax for defining models for different series. Is this really needed?
106 // ChartModel {
107 // id: chartModel
108 // ChartElement { column1: "Volkswagen"; column2: 13.5; column3: 1.2 }
109 // ChartElement { column1: "Toyota"; column2: 10.9; column3: 2.5 }
110 // }
111 // // column3 not used by pie series
112 // PieSeries {
113 // model: chartModel
114 // modelMapping: PieMapping {
115 // labels: 0 // undefined by default
116 // values: 1 // undefined by default
117 // first: 0 // 0 by default
118 // count: 10 // "Undefined" by default
119 // orientation: PieMapping.Vertical // Vertical by default
120 // }
121 // }
122
123 111 // TODO: show how to use data from a list model in a chart view
124 112 // i.e. copy the data into a chart model
125 113 // ListModel {
126 114 // id: listModel
127 115 // ListElement {
128 116 // label: "Volkswagen"
129 117 // value: 13.5
130 118 // }
131 119 // ListElement {
132 120 // label: "Toyota"
133 121 // value: 10.9
134 122 // }
135 123 // // and so on...
136 124 // }
137 125
138 126 }
@@ -1,58 +1,62
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: "Line&Spline"
29 29 anchors.fill: parent
30 30 theme: ChartView.ChartThemeBrownSand
31 31 animationOptions: ChartView.NoAnimation
32 32
33 33 LineSeries {
34 34 name: "Line"
35 model: XYModel {
36 XyPoint { x: 0.0; y: 0.0 }
37 XyPoint { x: 1.1; y: 2.1 }
38 XyPoint { x: 1.9; y: 3.3 }
39 XyPoint { x: 2.9; y: 4.9 }
40 XyPoint { x: 3.2; y: 3.0 }
41 XyPoint { x: 4.0; y: 3.3 }
42 }
35 model: chartModel
36 modelMapper.mapX: 0
37 modelMapper.mapY: 1
38 modelMapper.first: 0
39 modelMapper.count: -1
40 modelMapper.orientation: XYModelMapper.Vertical
43 41 }
44 42
45 43 SplineSeries {
46 44 name: "Spline"
47 model: XYModel {
48 XyPoint { x: 0.0; y: 0.3 }
49 XyPoint { x: 1.1; y: 3.2 }
50 XyPoint { x: 1.7; y: 2.4 }
51 XyPoint { x: 2.1; y: 2.1 }
52 XyPoint { x: 2.9; y: 2.6 }
53 XyPoint { x: 3.4; y: 2.3 }
54 XyPoint { x: 4.1; y: 3.1 }
55 }
45 model: chartModel
46 modelMapper.mapX: 0
47 modelMapper.mapY: 2
56 48 }
57 49 }
50
51 ChartModel {
52 id: chartModel
53 ChartModelRow { values: [0.0, 0.0, 0.3] }
54 ChartModelRow { values: [1.1, 2.1, 3.2] }
55 ChartModelRow { values: [1.9, 3.3, 2.4] }
56 ChartModelRow { values: [2.1, 2.1, 2.1] }
57 ChartModelRow { values: [2.9, 4.9, 2.6] }
58 ChartModelRow { values: [3.4, 3.0, 2.3] }
59 ChartModelRow { values: [4.1, 3.3, 3.1] }
60 }
61
58 62 }
@@ -1,128 +1,79
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 36 name: "Russian"
37 upperModel: russianModel
38 lowerModel: zerosModel
37 upperModel: chartModel
38 upperModelMapper.mapX: 0
39 upperModelMapper.mapY: 2
40 lowerModel: chartModel
41 lowerModelMapper.mapX: 0
42 lowerModelMapper.mapY: 1
39 43 }
40 44 AreaSeries {
41 45 name: "Swedish"
42 upperModel: swedishModel
43 lowerModel: zerosModel
46 upperModel: chartModel
47 upperModelMapper.mapX: 0
48 upperModelMapper.mapY: 3
49 lowerModel: chartModel
50 lowerModelMapper.mapX: 0
51 lowerModelMapper.mapY: 1
44 52 }
45 53 AreaSeries {
46 54 name: "Finnish"
47 upperModel: finnishModel
48 lowerModel: zerosModel
55 upperModel: chartModel
56 upperModelMapper.mapX: 0
57 upperModelMapper.mapY: 4
58 lowerModel: chartModel
59 lowerModelMapper.mapX: 0
60 lowerModelMapper.mapY: 1
49 61 }
50 62 }
51 63
52 // TODO: optional implementation with generic ChartModel
53 // AreaSeries {
54 // model: chartModel
55 // modelMapping: XyMapping {
56 // xValues: 0 // undefined by default
57 // yValues: 1 // undefined by default
58 // first: 0 // 0 by default
59 // count: 10 // "Undefined" by default
60 // orientation: XyMapping.Vertical // Vertical by default
61 // }
62 // }
63
64
65 XYModel {
66 id: zerosModel
67 XyPoint { x: 0; y: 0 }
68 XyPoint { x: 1; y: 0 }
69 XyPoint { x: 2; y: 0 }
70 XyPoint { x: 3; y: 0 }
71 XyPoint { x: 4; y: 0 }
72 XyPoint { x: 5; y: 0 }
73 XyPoint { x: 6; y: 0 }
74 XyPoint { x: 7; y: 0 }
75 XyPoint { x: 8; y: 0 }
76 XyPoint { x: 9; y: 0 }
77 XyPoint { x: 10; y: 0 }
78 XyPoint { x: 11; y: 0 }
79 }
80
81 XYModel {
82 id: russianModel
83 XyPoint { x: 0; y: 1 }
84 XyPoint { x: 1; y: 1 }
85 XyPoint { x: 2; y: 1 }
86 XyPoint { x: 3; y: 1 }
87 XyPoint { x: 4; y: 1 }
88 XyPoint { x: 5; y: 0 }
89 XyPoint { x: 6; y: 1 }
90 XyPoint { x: 7; y: 1 }
91 XyPoint { x: 8; y: 4 }
92 XyPoint { x: 9; y: 3 }
93 XyPoint { x: 10; y: 2 }
94 XyPoint { x: 11; y: 1 }
95 }
96
97 XYModel {
98 id: swedishModel
99 XyPoint { x: 0; y: 1 }
100 XyPoint { x: 1; y: 1 }
101 XyPoint { x: 2; y: 3 }
102 XyPoint { x: 3; y: 3 }
103 XyPoint { x: 4; y: 2 }
104 XyPoint { x: 5; y: 0 }
105 XyPoint { x: 6; y: 2 }
106 XyPoint { x: 7; y: 1 }
107 XyPoint { x: 8; y: 2 }
108 XyPoint { x: 9; y: 1 }
109 XyPoint { x: 10; y: 3 }
110 XyPoint { x: 11; y: 3 }
111 }
112
113 XYModel {
114 id: finnishModel
115 XyPoint { x: 0; y: 0 }
116 XyPoint { x: 1; y: 0 }
117 XyPoint { x: 2; y: 0 }
118 XyPoint { x: 3; y: 0 }
119 XyPoint { x: 4; y: 0 }
120 XyPoint { x: 5; y: 0 }
121 XyPoint { x: 6; y: 1 }
122 XyPoint { x: 7; y: 0 }
123 XyPoint { x: 8; y: 0 }
124 XyPoint { x: 9; y: 0 }
125 XyPoint { x: 10; y: 0 }
126 XyPoint { x: 11; y: 1 }
64 ChartModel {
65 id: chartModel
66 ChartModelRow { values: [0, 0, 1, 1, 0] }
67 ChartModelRow { values: [1, 0, 1, 1, 0] }
68 ChartModelRow { values: [2, 0, 1, 3, 0] }
69 ChartModelRow { values: [3, 0, 1, 3, 0] }
70 ChartModelRow { values: [4, 0, 1, 2, 0] }
71 ChartModelRow { values: [5, 0, 0, 0, 0] }
72 ChartModelRow { values: [6, 0, 1, 2, 1] }
73 ChartModelRow { values: [7, 0, 1, 1, 0] }
74 ChartModelRow { values: [8, 0, 4, 2, 0] }
75 ChartModelRow { values: [9, 0, 3, 1, 0] }
76 ChartModelRow { values: [10, 0, 2, 3, 0] }
77 ChartModelRow { values: [11, 0, 1, 3, 1] }
127 78 }
128 79 }
@@ -1,57 +1,57
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: "Scatters"
29 29 anchors.fill: parent
30 30 theme: ChartView.ChartThemeBlueCerulean
31 31
32 32 ScatterSeries {
33 33 id: scatter1
34 34 name: "Scatter1"
35 model: XYModel {
35 model: ChartModel {
36 36 XyPoint { x: 1.5; y: 1.5 }
37 37 XyPoint { x: 1.5; y: 1.6 }
38 38 XyPoint { x: 1.57; y: 1.55 }
39 39 XyPoint { x: 1.8; y: 1.8 }
40 40 XyPoint { x: 1.9; y: 1.6 }
41 41 XyPoint { x: 2.1; y: 1.3 }
42 42 XyPoint { x: 2.5; y: 2.1 }
43 43 }
44 44 }
45 45 ScatterSeries {
46 46 name: "Scatter2"
47 model: XYModel {
47 model: ChartModel {
48 48 XyPoint { x: 2.0; y: 2.0 }
49 49 XyPoint { x: 2.0; y: 2.1 }
50 50 XyPoint { x: 2.07; y: 2.05 }
51 51 XyPoint { x: 2.2; y: 2.9 }
52 52 XyPoint { x: 2.4; y: 2.7 }
53 53 XyPoint { x: 2.67; y: 2.65 }
54 54 }
55 55 }
56 56 }
57 57 }
@@ -1,147 +1,147
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.1
22 22 import QtCommercial.Chart 1.0
23 23
24 24 Rectangle {
25 25 width: 360
26 26 height: 360
27 27
28 28 ChartView {
29 29 id: chartView
30 30 anchors.top: parent.top
31 31 anchors.bottom: weatherImageRow.top
32 32 anchors.left: parent.left
33 33 anchors.right: parent.right
34 34 title: "Weather forecast"
35 35 axisX.min: 0
36 36 axisX.max: 4
37 37 axisY.min: 0
38 38 axisY.max: 0
39 39 legend: ChartView.LegendTop
40 40
41 41 LineSeries {
42 42 model: maxModel
43 43 name: "Max. temperature"
44 44 }
45 45
46 46 LineSeries {
47 47 model: minModel
48 48 name: "Min. temperature"
49 49 }
50 50
51 51 // TODO: use a single base model with mappings instead of two separate xy models
52 52 // LineSeries {
53 53 // model: chartModel
54 54 // modelMapping: XyModelMapping {
55 55 // xColumn: 0
56 56 // yColumn: 1
57 57 // }
58 58 // }
59 59 // LineSeries {
60 60 // model: chartModel
61 61 // modelMapping: XyModelMapping {
62 62 // xColumn: 0
63 63 // yColumn: 2
64 64 // }
65 65 // }
66 66 }
67 67
68 68 // ChartModel {
69 69 // id: chartModel
70 70 // }
71 71
72 XYModel {
72 ChartModel {
73 73 id: maxModel
74 74 }
75 75
76 XYModel {
76 ChartModel {
77 77 id: minModel
78 78 }
79 79
80 80 Component.onCompleted: {
81 81 if (weatherAppKey != "") {
82 82 var xhr = new XMLHttpRequest;
83 83 xhr.open("GET", "http://free.worldweatheronline.com/feed/weather.ashx?q=Jyv%c3%a4skyl%c3%a4,Finland&format=json&num_of_days=5&key=" + weatherAppKey);
84 84 xhr.onreadystatechange = function() {
85 85 if (xhr.readyState == XMLHttpRequest.DONE) {
86 86 var a = JSON.parse(xhr.responseText);
87 87 parseWeatherData(a);
88 88 }
89 89 }
90 90 xhr.send();
91 91 } else {
92 92 // No app key for worldweatheronline.com given by the user -> use static data
93 93 var responseText = "{ \"data\": { \"current_condition\": [ {\"cloudcover\": \"10\", \"humidity\": \"61\", \"observation_time\": \"06:26 AM\", \"precipMM\": \"0.0\", \"pressure\": \"1022\", \"temp_C\": \"6\", \"temp_F\": \"43\", \"visibility\": \"10\", \"weatherCode\": \"113\", \"weatherDesc\": [ {\"value\": \"Sunny\" } ], \"weatherIconUrl\": [ {\"value\": \"http:\/\/www.worldweatheronline.com\/images\/wsymbols01_png_64\/wsymbol_0001_sunny.png\" } ], \"winddir16Point\": \"SE\", \"winddirDegree\": \"140\", \"windspeedKmph\": \"7\", \"windspeedMiles\": \"4\" } ], \"request\": [ {\"query\": \"Jyvaskyla, Finland\", \"type\": \"City\" } ], \"weather\": [ {\"date\": \"2012-05-09\", \"precipMM\": \"0.4\", \"tempMaxC\": \"14\", \"tempMaxF\": \"57\", \"tempMinC\": \"7\", \"tempMinF\": \"45\", \"weatherCode\": \"116\", \"weatherDesc\": [ {\"value\": \"Partly Cloudy\" } ], \"weatherIconUrl\": [ {\"value\": \"http:\/\/www.worldweatheronline.com\/images\/wsymbols01_png_64\/wsymbol_0002_sunny_intervals.png\" } ], \"winddir16Point\": \"S\", \"winddirDegree\": \"179\", \"winddirection\": \"S\", \"windspeedKmph\": \"20\", \"windspeedMiles\": \"12\" }, {\"date\": \"2012-05-10\", \"precipMM\": \"2.4\", \"tempMaxC\": \"13\", \"tempMaxF\": \"55\", \"tempMinC\": \"8\", \"tempMinF\": \"46\", \"weatherCode\": \"266\", \"weatherDesc\": [ {\"value\": \"Light drizzle\" } ], \"weatherIconUrl\": [ {\"value\": \"http:\/\/www.worldweatheronline.com\/images\/wsymbols01_png_64\/wsymbol_0017_cloudy_with_light_rain.png\" } ], \"winddir16Point\": \"SW\", \"winddirDegree\": \"219\", \"winddirection\": \"SW\", \"windspeedKmph\": \"21\", \"windspeedMiles\": \"13\" }, {\"date\": \"2012-05-11\", \"precipMM\": \"11.1\", \"tempMaxC\": \"15\", \"tempMaxF\": \"59\", \"tempMinC\": \"7\", \"tempMinF\": \"44\", \"weatherCode\": \"266\", \"weatherDesc\": [ {\"value\": \"Light drizzle\" } ], \"weatherIconUrl\": [ {\"value\": \"http:\/\/www.worldweatheronline.com\/images\/wsymbols01_png_64\/wsymbol_0017_cloudy_with_light_rain.png\" } ], \"winddir16Point\": \"SSW\", \"winddirDegree\": \"200\", \"winddirection\": \"SSW\", \"windspeedKmph\": \"20\", \"windspeedMiles\": \"12\" }, {\"date\": \"2012-05-12\", \"precipMM\": \"2.8\", \"tempMaxC\": \"7\", \"tempMaxF\": \"44\", \"tempMinC\": \"2\", \"tempMinF\": \"35\", \"weatherCode\": \"317\", \"weatherDesc\": [ {\"value\": \"Light sleet\" } ], \"weatherIconUrl\": [ {\"value\": \"http:\/\/www.worldweatheronline.com\/images\/wsymbols01_png_64\/wsymbol_0021_cloudy_with_sleet.png\" } ], \"winddir16Point\": \"NW\", \"winddirDegree\": \"311\", \"winddirection\": \"NW\", \"windspeedKmph\": \"24\", \"windspeedMiles\": \"15\" }, {\"date\": \"2012-05-13\", \"precipMM\": \"0.4\", \"tempMaxC\": \"6\", \"tempMaxF\": \"42\", \"tempMinC\": \"2\", \"tempMinF\": \"35\", \"weatherCode\": \"116\", \"weatherDesc\": [ {\"value\": \"Partly Cloudy\" } ], \"weatherIconUrl\": [ {\"value\": \"http:\/\/www.worldweatheronline.com\/images\/wsymbols01_png_64\/wsymbol_0002_sunny_intervals.png\" } ], \"winddir16Point\": \"WNW\", \"winddirDegree\": \"281\", \"winddirection\": \"WNW\", \"windspeedKmph\": \"21\", \"windspeedMiles\": \"13\" } ] }}";
94 94 var a = JSON.parse(responseText);
95 95 parseWeatherData(a);
96 96 }
97 97 }
98 98
99 99 function parseWeatherData(weatherData) {
100 100 for (var i in weatherData.data.weather) {
101 101 var weatherObj = weatherData.data.weather[i];
102 102
103 103 // Add min and max temperature values into models used by series
104 104 maxModel.append([Number(i), weatherObj.tempMaxC]);
105 105 minModel.append([Number(i), weatherObj.tempMinC]);
106 106 weatherImageModel.append({"imageSource":weatherObj.weatherIconUrl[0].value});
107 107
108 108 // Update scale of the chart
109 109 while (chartView.axisY.min >= Number(weatherObj.tempMinC))
110 110 chartView.axisY.min = chartView.axisY.min - 10;
111 111 while (chartView.axisY.max <= Number(weatherObj.tempMaxC))
112 112 chartView.axisY.max = chartView.axisY.max + 10;
113 113
114 114 // Set the x-axis labels to the dates of the forecast
115 115 // TODO: the API could probably be more intuitive..
116 116 // Now it takes an array of strings: chartView.axisXLabels = ["value1", "label1", "value2", "label2", ...]
117 117 var xLabels = chartView.axisXLabels;
118 118 xLabels[Number(i) * 2] = i;
119 119 xLabels[(Number(i) * 2) + 1] = weatherObj.date.substring(5, 10);
120 120 chartView.axisXLabels = xLabels;
121 121 }
122 122 }
123 123
124 124 ListModel {
125 125 id: weatherImageModel
126 126 }
127 127
128 128 Row {
129 129 id: weatherImageRow
130 130 anchors.bottom: parent.bottom
131 131 anchors.bottomMargin: 10
132 132 anchors.left: parent.left
133 133 anchors.leftMargin: 25
134 134 anchors.right: parent.right
135 135 anchors.rightMargin: 25
136 136 Repeater {
137 137 id: repeater
138 138 model: weatherImageModel
139 139 delegate: Image {
140 140 source: imageSource
141 141 width: weatherImageRow.width / weatherImageModel.count
142 142 height: width
143 143 fillMode: Image.PreserveAspectCrop
144 144 }
145 145 }
146 146 }
147 147 }
@@ -1,77 +1,94
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 24 #include "qxymodelmapper.h"
25 25
26 26 QTCOMMERCIALCHART_BEGIN_NAMESPACE
27 27
28 28 DeclarativeAreaSeries::DeclarativeAreaSeries(QObject *parent) :
29 29 QAreaSeries(new QLineSeries(parent), new QLineSeries(parent))
30 30 {
31 QXYModelMapper *upperMapper = new QXYModelMapper(upperSeries());
32 upperMapper->setMapX(0);
33 upperMapper->setMapY(1);
34 upperMapper->setFirst(0);
35 upperMapper->setCount(-1);
36 upperMapper->setOrientation(Qt::Vertical);
37 upperSeries()->setModelMapper(upperMapper);
38
39 QXYModelMapper *lowerMapper = new QXYModelMapper(lowerSeries());
40 lowerMapper->setMapX(2);
41 lowerMapper->setMapY(3);
42 lowerMapper->setFirst(0);
43 lowerMapper->setCount(-1);
44 lowerMapper->setOrientation(Qt::Vertical);
45 lowerSeries()->setModelMapper(lowerMapper);
31 46 }
32 47
33 bool DeclarativeAreaSeries::setDeclarativeUpperModel(DeclarativeXyModel *model)
48 bool DeclarativeAreaSeries::setDeclarativeUpperModel(DeclarativeTableModel *model)
34 49 {
35 50 QAbstractItemModel *m = qobject_cast<QAbstractItemModel *>(model);
36 51 bool value(false);
37 52 if (m) {
38 53 upperSeries()->setModel(m);
39 QXYModelMapper *mapper = new QXYModelMapper;
40 mapper->setMapX(0);
41 mapper->setMapY(1);
42 upperSeries()->setModelMapper(mapper);
43 54 } else {
44 55 qWarning("DeclarativeAreaSeries: Illegal model");
45 56 }
46 57 return value;
47 58 }
48 59
49 DeclarativeXyModel *DeclarativeAreaSeries::declarativeUpperModel()
60 DeclarativeTableModel *DeclarativeAreaSeries::declarativeUpperModel()
50 61 {
51 return qobject_cast<DeclarativeXyModel *>(upperSeries()->model());
62 return qobject_cast<DeclarativeTableModel *>(upperSeries()->model());
52 63 }
53 64
54 bool DeclarativeAreaSeries::setDeclarativeLowerModel(DeclarativeXyModel *model)
65 bool DeclarativeAreaSeries::setDeclarativeLowerModel(DeclarativeTableModel *model)
55 66 {
56 67 QAbstractItemModel *m = qobject_cast<QAbstractItemModel *>(model);
57 68 bool value(false);
58 69 if (m) {
59 70 lowerSeries()->setModel(m);
60 QXYModelMapper *mapper = new QXYModelMapper;
61 mapper->setMapX(0);
62 mapper->setMapY(1);
63 lowerSeries()->setModelMapper(mapper);
64 71 } else {
65 72 qWarning("DeclarativeAreaSeries: Illegal model");
66 73 }
67 74 return value;
68 75 }
69 76
70 DeclarativeXyModel *DeclarativeAreaSeries::declarativeLowerModel()
77 DeclarativeTableModel *DeclarativeAreaSeries::declarativeLowerModel()
78 {
79 return qobject_cast<DeclarativeTableModel *>(lowerSeries()->model());
80 }
81
82 QXYModelMapper* DeclarativeAreaSeries::upperModelMapper() const
83 {
84 return upperSeries()->modelMapper();
85 }
86
87 QXYModelMapper* DeclarativeAreaSeries::lowerModelMapper() const
71 88 {
72 return qobject_cast<DeclarativeXyModel *>(lowerSeries()->model());
89 return lowerSeries()->modelMapper();
73 90 }
74 91
75 92 #include "moc_declarativeareaseries.cpp"
76 93
77 94 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,49 +1,52
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 26 #include "declarativelineseries.h"
27 #include "declarativexyseries.h"
28 27
29 28 QTCOMMERCIALCHART_BEGIN_NAMESPACE
30 29
31 class DeclarativeAreaSeries : public QAreaSeries, public DeclarativeXySeries
30 class DeclarativeAreaSeries : public QAreaSeries
32 31 {
33 32 Q_OBJECT
34 Q_PROPERTY(DeclarativeXyModel *upperModel READ declarativeUpperModel WRITE setDeclarativeUpperModel)
35 Q_PROPERTY(DeclarativeXyModel *lowerModel READ declarativeLowerModel WRITE setDeclarativeLowerModel)
33 Q_PROPERTY(DeclarativeTableModel *upperModel READ declarativeUpperModel WRITE setDeclarativeUpperModel)
34 Q_PROPERTY(DeclarativeTableModel *lowerModel READ declarativeLowerModel WRITE setDeclarativeLowerModel)
35 Q_PROPERTY(QXYModelMapper *upperModelMapper READ upperModelMapper)
36 Q_PROPERTY(QXYModelMapper *lowerModelMapper READ lowerModelMapper)
36 37
37 38 public:
38 39 explicit DeclarativeAreaSeries(QObject *parent = 0);
39 40
40 41 public:
41 bool setDeclarativeUpperModel(DeclarativeXyModel *model);
42 DeclarativeXyModel *declarativeUpperModel();
43 bool setDeclarativeLowerModel(DeclarativeXyModel *model);
44 DeclarativeXyModel *declarativeLowerModel();
42 bool setDeclarativeUpperModel(DeclarativeTableModel *model);
43 DeclarativeTableModel *declarativeUpperModel();
44 bool setDeclarativeLowerModel(DeclarativeTableModel *model);
45 DeclarativeTableModel *declarativeLowerModel();
46 QXYModelMapper* upperModelMapper() const;
47 QXYModelMapper* lowerModelMapper() const;
45 48 };
46 49
47 50 QTCOMMERCIALCHART_END_NAMESPACE
48 51
49 52 #endif // DECLARATIVEAREASERIES_H
@@ -1,42 +1,42
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 DECLARATIVELINESERIES_H
22 22 #define DECLARATIVELINESERIES_H
23 23
24 24 #include "qchartglobal.h"
25 25 #include "qlineseries.h"
26 26 #include "declarativexyseries.h"
27 27 #include <QDeclarativeParserStatus>
28 28
29 29 QTCOMMERCIALCHART_BEGIN_NAMESPACE
30 30
31 31 class DeclarativeLineSeries : public QLineSeries, public DeclarativeXySeries
32 32 {
33 33 Q_OBJECT
34 Q_PROPERTY(DeclarativeXyModel *model READ declarativeModel WRITE setDeclarativeModel)
34 Q_PROPERTY(DeclarativeTableModel *model READ declarativeModel WRITE setDeclarativeModel)
35 35
36 36 public:
37 37 explicit DeclarativeLineSeries(QObject *parent = 0);
38 38 };
39 39
40 40 QTCOMMERCIALCHART_END_NAMESPACE
41 41
42 42 #endif // DECLARATIVELINESERIES_H
@@ -1,177 +1,172
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 ////////////// Table model (base) ///////////////////
27
28 ////////////// Table model row ///////////////////
29
30 DeclarativeTableModelRow::DeclarativeTableModelRow(QObject *parent)
31 : QObject(parent)
32 {
33 }
34
35 QVariantList DeclarativeTableModelRow::values()
36 {
37 return m_values;
38 }
39
40 void DeclarativeTableModelRow::setValues(QVariantList values)
41 {
42 m_values = values;
43 }
44
45 ////////////// Table model ///////////////////
28 46
29 47 DeclarativeTableModel::DeclarativeTableModel(QObject *parent) :
30 48 ChartTableModel(parent)
31 49 {
32 50 }
33 51
34 52 void DeclarativeTableModel::classBegin()
35 53 {
36 54 }
37 55
38 56 void DeclarativeTableModel::componentComplete()
39 57 {
40 58 foreach (QObject *child, children())
41 59 appendToModel(child);
42 60 }
43 61
44 62 QDeclarativeListProperty<QObject> DeclarativeTableModel::modelChildren()
45 63 {
46 64 return QDeclarativeListProperty<QObject>(this, 0, &DeclarativeTableModel::appendModelChild);
47 65 }
48 66
49 67 void DeclarativeTableModel::appendModelChild(QDeclarativeListProperty<QObject> *list,
50 68 QObject *child)
51 69 {
52 70 // childs are added in componentComplete instead
53 71 Q_UNUSED(list)
54 72 Q_UNUSED(child)
55 73 }
56 74
57 void DeclarativeTableModel::appendToModel(QObject *object)
75 void DeclarativeTableModel::append(QVariantList values)
58 76 {
59 if (qobject_cast<DeclarativeBarModel *>(this)) {
60 DeclarativeBarModel *model = qobject_cast<DeclarativeBarModel *>(this);
61 model->append(qobject_cast<QBarSet *>(object));
62 } else if (qobject_cast<DeclarativePieModel *>(this)) {
63 DeclarativePieModel *model = qobject_cast<DeclarativePieModel *>(this);
64 model->append(qobject_cast<QPieSlice *>(object));
65 } else if (qobject_cast<DeclarativeXyModel *>(this)) {
66 DeclarativeXyModel *model = qobject_cast<DeclarativeXyModel *>(this);
67 model->append(qobject_cast<DeclarativeXyPoint *>(object));
68 }
69 }
77 // qDebug() << "DeclarativeTableModel::append:" << values;
70 78
71 ////////////// XY model ///////////////////////
79 while (columnCount() < values.count())
80 insertColumn(columnCount());
72 81
73 DeclarativeXyModel::DeclarativeXyModel(QObject *parent) :
74 DeclarativeTableModel(parent)
75 {
82 insertRow(rowCount());
83
84 QModelIndex beginIndex = QModelIndex();
85 QModelIndex endIndex = QModelIndex();
86 for (int i(0); i < values.count(); i++) {
87 QModelIndex modelIndex = createIndex(rowCount() - 1, i);
88 if (i == 0)
89 beginIndex = modelIndex;
90 if (i == (values.count() - 1))
91 endIndex = modelIndex;
92 setData(modelIndex, values.at(i));
93 }
94 dataChanged(beginIndex, endIndex);
76 95 }
77 96
78 void DeclarativeXyModel::append(DeclarativeXyPoint* point)
97 void DeclarativeTableModel::appendToModel(QObject *object)
79 98 {
80 // qDebug() << "DeclarativeXyModel::append:" << point->x() << " " << point->y();
81 insertRow(rowCount());
82 QModelIndex xModelIndex = createIndex(rowCount() - 1, 0);
83 QModelIndex yModelIndex = createIndex(rowCount() - 1, 1);
84 setData(xModelIndex, point->x());
85 setData(yModelIndex, point->y());
86 dataChanged(xModelIndex, yModelIndex);
99 if (qobject_cast<QBarSet *>(object)) {
100 DeclarativeBarModel *model = qobject_cast<DeclarativeBarModel *>(this);
101 Q_ASSERT(model);
102 model->append(qobject_cast<QBarSet *>(object));
103 } else if (qobject_cast<QPieSlice *>(object)) {
104 // TODO
105 } else if (qobject_cast<DeclarativeXyPoint *>(object)) {
106 // TODO
107 appendPoint(qobject_cast<DeclarativeXyPoint *>(object));
108 } else if (qobject_cast<DeclarativeTableModel *>(this)) {
109 append(qobject_cast<DeclarativeTableModelRow *>(object)->values());
110 }
87 111 }
88 112
89 void DeclarativeXyModel::append(QVariantList points)
113 void DeclarativeTableModel::appendPoints(QVariantList points)
90 114 {
91 115 qreal x = 0.0;
92 116 for (int i(0); i < points.count(); i++) {
93 117 if (i % 2) {
94 118 bool ok(false);
95 119 qreal y = points.at(i).toReal(&ok);
96 120 if (ok) {
97 121 DeclarativeXyPoint *point= new DeclarativeXyPoint();
98 122 point->setX(x);
99 123 point->setY(y);
100 append(point);
124 appendPoint(point);
101 125 } else {
102 126 qWarning() << "Illegal y value";
103 127 }
104 128 } else {
105 129 bool ok(false);
106 130 x = points.at(i).toReal(&ok);
107 131 if (!ok) {
108 132 qWarning() << "Illegal x value";
109 133 }
110 134 }
111 135 }
112 136 }
113 137
114 ////////////// Pie model ///////////////////////
115
116 DeclarativePieModel::DeclarativePieModel(QObject *parent) :
117 DeclarativeTableModel(parent)
138 void DeclarativeTableModel::appendPoint(DeclarativeXyPoint* point)
118 139 {
119 }
120
121 void DeclarativePieModel::append(QPieSlice* slice)
122 {
123 // qDebug() << "DeclarativePieModel::append:" << slice->label() << " " << slice->value();
140 // qDebug() << "DeclarativeTableModel::append:" << point->x() << " " << point->y();
124 141 insertRow(rowCount());
125
126 setData(createIndex(rowCount() - 1, 0), slice->value());
127 setData(createIndex(rowCount() - 1, 1), slice->label());
128 }
129
130 void DeclarativePieModel::append(QVariantList slices)
131 {
132 // qDebug() << "append:" << slices;
133 QString label = "";
134 for (int i(0); i < slices.count(); i++) {
135 if (i % 2) {
136 bool ok(false);
137 qreal value = slices.at(i).toReal(&ok);
138 if (ok) {
139 QPieSlice *slice = new QPieSlice(value, label);
140 append(slice);
141 // TODO: how to copy the properties to the newly added slice?
142 // (DeclarativePieModel::append only copies the label and value to the model)
143 // QPieSlice *addedSlice = append(slice);
144 // addedSlice->setExploded(slice->isExploded());
145 } else {
146 qWarning() << "Illegal slice item";
147 }
148 } else {
149 label = slices.at(i).toString();
150 }
151 }
142 QModelIndex xModelIndex = createIndex(rowCount() - 1, 0);
143 QModelIndex yModelIndex = createIndex(rowCount() - 1, 1);
144 setData(xModelIndex, point->x());
145 setData(yModelIndex, point->y());
146 dataChanged(xModelIndex, yModelIndex);
152 147 }
153 148
154 149 ////////////// Bar model ///////////////////////
155 150
156 151 DeclarativeBarModel::DeclarativeBarModel(QObject *parent) :
157 152 DeclarativeTableModel(parent)
158 153 {
159 154 }
160 155
161 156 void DeclarativeBarModel::append(QBarSet* barSet)
162 157 {
163 158 insertColumn(columnCount());
164 159 for (int i(0); i < barSet->count(); i++) {
165 160 if (rowCount() < (i + 1))
166 161 insertRow(rowCount());
167 162 setData(createIndex(i, columnCount() - 1), barSet->at(i));
168 163 // insertRow(rowCount());
169 164 // setData(createIndex(rowCount() - 1, 0), );
170 165 // setData(createIndex(rowCount() - 1, 1), barSet->at(i));
171 166 }
172 167 // TODO: setModelMapping(0, 1, columnCount(), Qt::Vertical);
173 168 }
174 169
175 170 #include "moc_declarativemodel.cpp"
176 171
177 172 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,94 +1,86
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 DECLARATIVEMODEL_H
22 22 #define DECLARATIVEMODEL_H
23 23
24 24 #include "qchartglobal.h"
25 25 #include "declarativexypoint.h"
26 26 #include <QPieSlice>
27 27 #include "../src/charttablemodel.h" // TODO
28 28 #include <QBarSet>
29 29 #include <QDeclarativeListProperty>
30 30 #include <QVariant>
31 31 #include <QDeclarativeParserStatus>
32 32
33 33 QTCOMMERCIALCHART_BEGIN_NAMESPACE
34 34
35 class DeclarativeTableModelRow : public QObject
36 {
37 Q_OBJECT
38 Q_PROPERTY(QVariantList values READ values WRITE setValues)
39
40 public:
41 explicit DeclarativeTableModelRow(QObject *parent = 0);
42 QVariantList values();
43 void setValues(QVariantList values);
44 private:
45 QVariantList m_values;
46 };
47
35 48 class DeclarativeTableModel : public ChartTableModel, public QDeclarativeParserStatus
36 49 {
37 50 Q_OBJECT
38 51 Q_INTERFACES(QDeclarativeParserStatus)
39 52 Q_PROPERTY(QDeclarativeListProperty<QObject> modelChildren READ modelChildren)
40 53 Q_CLASSINFO("DefaultProperty", "modelChildren")
41 54
42 55 public:
43 56 explicit DeclarativeTableModel(QObject *parent = 0);
44 57 QDeclarativeListProperty<QObject> modelChildren();
45 58
46 59 public: // from QDeclarativeParserStatus
47 60 void classBegin();
48 61 void componentComplete();
49 62
50 63 public Q_SLOTS:
64 void append(QVariantList slices);
65 void appendPoints(QVariantList points);
66 void appendPoint(DeclarativeXyPoint* point);
51 67 static void appendModelChild(QDeclarativeListProperty<QObject> *list,
52 68 QObject *element);
53 69 private:
54 70 void appendToModel(QObject *object);
55 71 };
56 72
57 class DeclarativeXyModel : public DeclarativeTableModel
58 {
59 Q_OBJECT
60
61 public:
62 explicit DeclarativeXyModel(QObject *parent = 0);
63
64 public Q_SLOTS:
65 void append(DeclarativeXyPoint* point);
66 void append(QVariantList points);
67 };
68
69 class DeclarativePieModel : public DeclarativeTableModel
70 {
71 Q_OBJECT
72
73 public:
74 explicit DeclarativePieModel(QObject *parent = 0);
75
76 public Q_SLOTS:
77 void append(QPieSlice* slice);
78 void append(QVariantList slices);
79 };
80
81 73 class DeclarativeBarModel : public DeclarativeTableModel
82 74 {
83 75 Q_OBJECT
84 76
85 77 public:
86 78 explicit DeclarativeBarModel(QObject *parent = 0);
87 79
88 80 public Q_SLOTS:
89 81 void append(QBarSet* barSet);
90 82 };
91 83
92 84 QTCOMMERCIALCHART_END_NAMESPACE
93 85
94 86 #endif // DECLARATIVEMODEL_H
@@ -1,65 +1,71
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 "declarativepieseries.h"
22 22 #include "declarativechart.h"
23 23 #include "qchart.h"
24 24 #include <qdeclarativelist.h>
25 25 #include "qpiemodelmapper.h"
26 26
27 27 QTCOMMERCIALCHART_BEGIN_NAMESPACE
28 28
29 29 DeclarativePieSeries::DeclarativePieSeries(QObject *parent) :
30 30 QPieSeries(parent)
31 31 {
32 // TODO: set default model on init?
33 // setModel(new DeclarativeTableModel());
34
35 // Set default mapper parameters to allow easy to use PieSeries api
36 QPieModelMapper *mapper = new QPieModelMapper();
37 mapper->setMapLabels(0);
38 mapper->setMapValues(1);
39 mapper->setOrientation(Qt::Vertical);
40 mapper->setFirst(0);
41 mapper->setCount(-1);
42 setModelMapper(mapper);
32 43 }
33 44
34 45 QPieSlice *DeclarativePieSeries::slice(int index)
35 46 {
36 47 QList<QPieSlice*> sliceList = slices();
37 48 if (index < sliceList.count())
38 49 return sliceList[index];
39 50
40 51 return 0;
41 52 }
42 53
43
44 void DeclarativePieSeries::setPieModel(DeclarativePieModel *model)
54 void DeclarativePieSeries::setPieModel(DeclarativeTableModel *model)
45 55 {
46 56 QAbstractItemModel *m = qobject_cast<QAbstractItemModel *>(model);
47 57 if (m) {
48 58 QPieSeries::setModel(m);
49 QPieModelMapper *mapper = new QPieModelMapper;
50 mapper->setMapValues(0);
51 mapper->setMapLabels(1);
52 QPieSeries::setModelMapper(mapper);
53 59 } else {
54 60 qWarning("DeclarativePieSeries: Illegal model");
55 61 }
56 62 }
57 63
58 DeclarativePieModel *DeclarativePieSeries::pieModel()
64 DeclarativeTableModel *DeclarativePieSeries::pieModel()
59 65 {
60 return qobject_cast<DeclarativePieModel *>(model());
66 return qobject_cast<DeclarativeTableModel *>(model());
61 67 }
62 68
63 69 #include "moc_declarativepieseries.cpp"
64 70
65 71 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,56 +1,54
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 DECLARATIVEPIESERIES_H
22 22 #define DECLARATIVEPIESERIES_H
23 23
24 24 #include "qchartglobal.h"
25 25 #include "qpieslice.h"
26 26 #include "qpieseries.h"
27 27 #include <QDeclarativeListProperty>
28 28 #include <QAbstractItemModel>
29 29 #include <QVariant>
30 30 #include "declarativemodel.h"
31 31
32 32 QTCOMMERCIALCHART_BEGIN_NAMESPACE
33 33
34 34 class QChart;
35 35
36 36 class DeclarativePieSeries : public QPieSeries
37 37 {
38 38 Q_OBJECT
39 Q_PROPERTY(DeclarativePieModel *model READ pieModel WRITE setPieModel)
39 Q_PROPERTY(DeclarativeTableModel *model READ pieModel WRITE setPieModel)
40 40
41 41 public:
42 42 explicit DeclarativePieSeries(QObject *parent = 0);
43 43
44 44 public:
45 45 Q_INVOKABLE QPieSlice *slice(int index);
46 46
47 public Q_SLOTS:
48
49 47 public:
50 void setPieModel(DeclarativePieModel *model);
51 DeclarativePieModel *pieModel();
48 void setPieModel(DeclarativeTableModel *model);
49 DeclarativeTableModel *pieModel();
52 50 };
53 51
54 52 QTCOMMERCIALCHART_END_NAMESPACE
55 53
56 54 #endif // DECLARATIVEPIESERIES_H
@@ -1,42 +1,42
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 DECLARATIVESCATTERSERIES_H
22 22 #define DECLARATIVESCATTERSERIES_H
23 23
24 24 #include "qchartglobal.h"
25 25 #include "qscatterseries.h"
26 26 #include "declarativexyseries.h"
27 27 #include <QDeclarativeParserStatus>
28 28
29 29 QTCOMMERCIALCHART_BEGIN_NAMESPACE
30 30
31 31 class DeclarativeScatterSeries : public QScatterSeries, public DeclarativeXySeries
32 32 {
33 33 Q_OBJECT
34 Q_PROPERTY(DeclarativeXyModel *model READ declarativeModel WRITE setDeclarativeModel)
34 Q_PROPERTY(DeclarativeTableModel *model READ declarativeModel WRITE setDeclarativeModel)
35 35
36 36 public:
37 37 explicit DeclarativeScatterSeries(QObject *parent = 0);
38 38 };
39 39
40 40 QTCOMMERCIALCHART_END_NAMESPACE
41 41
42 42 #endif // DECLARATIVESCATTERSERIES_H
@@ -1,34 +1,34
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 "declarativesplineseries.h"
22 22 #include "declarativechart.h"
23 #include "qchart.h"
23 #include <QChart>
24 24
25 25 QTCOMMERCIALCHART_BEGIN_NAMESPACE
26 26
27 27 DeclarativeSplineSeries::DeclarativeSplineSeries(QObject *parent) :
28 28 QSplineSeries(parent)
29 29 {
30 30 }
31 31
32 32 #include "moc_declarativesplineseries.cpp"
33 33
34 34 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,42 +1,42
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 DECLARATIVESPLINESERIES_H
22 22 #define DECLARATIVESPLINESERIES_H
23 23
24 24 #include "qchartglobal.h"
25 25 #include "qsplineseries.h"
26 26 #include "declarativexyseries.h"
27 27 #include <QDeclarativeParserStatus>
28 28
29 29 QTCOMMERCIALCHART_BEGIN_NAMESPACE
30 30
31 31 class DeclarativeSplineSeries : public QSplineSeries, public DeclarativeXySeries
32 32 {
33 33 Q_OBJECT
34 Q_PROPERTY(DeclarativeXyModel *model READ declarativeModel WRITE setDeclarativeModel)
34 Q_PROPERTY(DeclarativeTableModel *model READ declarativeModel WRITE setDeclarativeModel)
35 35
36 36 public:
37 37 explicit DeclarativeSplineSeries(QObject *parent = 0);
38 38 };
39 39
40 40 QTCOMMERCIALCHART_END_NAMESPACE
41 41
42 42 #endif // DECLARATIVESPLINESERIES_H
@@ -1,63 +1,71
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 "DeclarativeXySeries.h"
22 22 #include "declarativexyseries.h"
23 #include "qxyseries.h"
24 #include "qxymodelmapper.h"
23 #include <QXYSeries>
24 #include <QXYModelMapper>
25 25 #include "declarativechart.h"
26 26
27 27 QTCOMMERCIALCHART_BEGIN_NAMESPACE
28 28
29 29 DeclarativeXySeries::DeclarativeXySeries()
30 30 {
31 // All the inherited objects must be of type QXYSeries, so it is safe to cast
32 QXYSeries *series = reinterpret_cast<QXYSeries *>(this);
33 QXYModelMapper *mapper = new QXYModelMapper(series);
34 mapper->setMapX(0);
35 mapper->setMapY(1);
36 mapper->setFirst(0);
37 mapper->setCount(-1);
38 mapper->setOrientation(Qt::Vertical);
39 series->setModelMapper(mapper);
31 40 }
32 41
33 42 DeclarativeXySeries::~DeclarativeXySeries()
34 43 {
35 44 }
36 45
37 bool DeclarativeXySeries::setDeclarativeModel(DeclarativeXyModel *model)
46 bool DeclarativeXySeries::setDeclarativeModel(DeclarativeTableModel *model)
38 47 {
39 48 QAbstractItemModel *m = qobject_cast<QAbstractItemModel *>(model);
40 49 bool value(false);
41 50 if (m) {
42 51 // All the inherited objects must be of type QXYSeries, so it is safe to cast
43 52 QXYSeries *series = reinterpret_cast<QXYSeries *>(this);
44 53 series->setModel(m);
45 QXYModelMapper *mapper = new QXYModelMapper;
46 mapper->setMapX(0);
47 mapper->setMapY(1);
48 series->setModelMapper(mapper);
54 // QXYModelMapper *mapper = new QXYModelMapper;
55 // mapper->setMapX(0);
56 // mapper->setMapY(1);
57 // series->setModelMapper(mapper);
49 58 } else {
50 59 qWarning("DeclarativeXySeries: Illegal model");
51 60 }
52 61 return value;
53 62 }
54 63
55 DeclarativeXyModel *DeclarativeXySeries::declarativeModel()
64 DeclarativeTableModel *DeclarativeXySeries::declarativeModel()
56 65 {
57 66 // All the inherited objects must be of type QXYSeries, so it is safe to cast
58 67 QXYSeries *series = reinterpret_cast<QXYSeries *>(this);
59 Q_ASSERT(series);
60 return qobject_cast<DeclarativeXyModel *>(series->model());
68 return qobject_cast<DeclarativeTableModel *>(series->model());
61 69 }
62 70
63 71 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,48 +1,48
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 DECLARATIVE_XY_SERIES_H
22 22 #define DECLARATIVE_XY_SERIES_H
23 23
24 24 #include "qchartglobal.h"
25 25 #include "declarativexypoint.h"
26 26 #include "declarativemodel.h"
27 27
28 28 QTCOMMERCIALCHART_BEGIN_NAMESPACE
29 29
30 30 class QChart;
31 31 class QAbstractSeries;
32 32
33 33 class DeclarativeXySeries
34 34 {
35 35 Q_INTERFACES(QDeclarativeParserStatus)
36 36
37 37 public:
38 38 explicit DeclarativeXySeries();
39 39 ~DeclarativeXySeries();
40 40
41 41 public:
42 bool setDeclarativeModel(DeclarativeXyModel *model);
43 DeclarativeXyModel *declarativeModel();
42 bool setDeclarativeModel(DeclarativeTableModel *model);
43 DeclarativeTableModel *declarativeModel();
44 44 };
45 45
46 46 QTCOMMERCIALCHART_END_NAMESPACE
47 47
48 48 #endif // DECLARATIVE_XY_SERIES_H
@@ -1,69 +1,79
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 <QtDeclarative/qdeclarativeextensionplugin.h>
22 22 #include <QtDeclarative/qdeclarative.h>
23 23 #include "qchart.h"
24 24 #include "qaxiscategories.h"
25 25 #include "declarativechart.h"
26 26 #include "declarativexypoint.h"
27 27 #include "declarativelineseries.h"
28 28 #include "declarativesplineseries.h"
29 29 #include "declarativeareaseries.h"
30 30 #include "declarativescatterseries.h"
31 31 #include "declarativebarseries.h"
32 32 #include "declarativepieseries.h"
33 #include "declarativemodel.h"
34 #include <QPieModelMapper>
35 #include <QXYModelMapper>
33 36
34 37 QTCOMMERCIALCHART_BEGIN_NAMESPACE
35 38
36 39 class ChartQmlPlugin : public QDeclarativeExtensionPlugin
37 40 {
38 41 Q_OBJECT
39 42 public:
40 43 virtual void registerTypes(const char *uri)
41 44 {
42 45 Q_ASSERT(QLatin1String(uri) == QLatin1String("QtCommercial.Chart"));
43 46
44 47 qmlRegisterType<DeclarativeChart>(uri, 1, 0, "ChartView");
45 48 qmlRegisterUncreatableType<QAxis>(uri, 1, 0, "Axis",
46 QLatin1String("Trying to create uncreatable type: Axis."));
49 QLatin1String("Trying to create uncreatable: Axis."));
47 50 //qmlRegisterType<DeclarativeAxisCategory>(uri, 1, 0, "AxisCategory");
48 51 qmlRegisterType<DeclarativeXyPoint>(uri, 1, 0, "XyPoint");
49 52 qmlRegisterType<DeclarativeScatterSeries>(uri, 1, 0, "ScatterSeries");
50 53 qmlRegisterType<DeclarativeLineSeries>(uri, 1, 0, "LineSeries");
51 54 qmlRegisterType<DeclarativeSplineSeries>(uri, 1, 0, "SplineSeries");
52 55 qmlRegisterType<DeclarativeAreaSeries>(uri, 1, 0, "AreaSeries");
53 56 qmlRegisterType<DeclarativeBarSeries>(uri, 1, 0, "BarSeries");
54 57 qmlRegisterType<DeclarativePieSeries>(uri, 1, 0, "PieSeries");
55 58 qmlRegisterType<QPieSlice>(uri, 1, 0, "PieSlice");
56 qmlRegisterType<DeclarativePieModel>(uri, 1, 0, "PieModel");
57 qmlRegisterType<DeclarativeXyModel>(uri, 1, 0, "XYModel");
59 qmlRegisterType<DeclarativeTableModel>(uri, 1, 0, "ChartModel");
60 qmlRegisterType<DeclarativeTableModelRow>(uri, 1, 0, "ChartModelRow");
61 //qmlRegisterType<DeclarativePieMapping>(uri, 1, 0, "PieMapping");
62 //qmlRegisterType<QPieModelMapper>(uri, 1, 0, "PieModelMapper");
63 qmlRegisterUncreatableType<QPieModelMapper>(uri, 1, 0, "PieModelMapper",
64 QLatin1String("Trying to create uncreatable: PieModelMapper."));
65 qmlRegisterUncreatableType<QXYModelMapper>(uri, 1, 0, "XYModelMapper",
66 QLatin1String("Trying to create uncreatable: PieModelMapper."));
67
58 68 qmlRegisterType<DeclarativeBarModel>(uri, 1, 0, "BarModel");
59 69 qmlRegisterType<DeclarativeBarSet>(uri, 1, 0, "BarSet");
60 70 }
61 71 };
62 72
63 73 #include "plugin.moc"
64 74
65 75 QTCOMMERCIALCHART_END_NAMESPACE
66 76
67 77 QTCOMMERCIALCHART_USE_NAMESPACE
68 78
69 79 Q_EXPORT_PLUGIN2(qtcommercialchartqml, QT_PREPEND_NAMESPACE(ChartQmlPlugin))
@@ -1,140 +1,145
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 "charttablemodel.h"
22 22 #include <QVector>
23 23 #include <QTime>
24 24 #include <QRect>
25 25 #include <QColor>
26 26
27 27 QTCOMMERCIALCHART_USE_NAMESPACE
28 28
29 29 ChartTableModel::ChartTableModel(QObject *parent) :
30 30 QAbstractTableModel(parent)
31 31 {
32 32 qsrand(QTime(0,0,0).secsTo(QTime::currentTime()));
33 33
34 34 m_columnCount = 2;
35 35 m_rowCount = 0;
36 36
37 37 // m_data
38 38 for (int i = 0; i < m_rowCount; i++) {
39 39 QVector<QVariant>* dataVec = new QVector<QVariant>(m_columnCount);
40 40 for (int k = 0; k < dataVec->size(); k++) {
41 41 if (k%2 == 0)
42 42 dataVec->replace(k, i * 50 + qrand()%20);
43 43 else
44 44 dataVec->replace(k, qrand()%100);
45 45 }
46 46 m_data.append(dataVec);
47 47 }
48 48 }
49 49
50 50 int ChartTableModel::rowCount(const QModelIndex & parent) const
51 51 {
52 52 Q_UNUSED(parent)
53 53 return m_data.count();
54 54 }
55 55
56 56 int ChartTableModel::columnCount(const QModelIndex & parent) const
57 57 {
58 58 Q_UNUSED(parent)
59 59 return m_columnCount;
60 60 }
61 61
62 62 QVariant ChartTableModel::headerData (int section, Qt::Orientation orientation, int role ) const
63 63 {
64 64 if (role != Qt::DisplayRole)
65 65 return QVariant();
66 66
67 67 if (orientation == Qt::Horizontal) {
68 68 if (section % 2 == 0)
69 69 return "x";
70 70 else
71 71 return "y";
72 72 } else {
73 73 return QString("%1").arg(section + 1);
74 74 }
75 75 }
76 76
77 77 QVariant ChartTableModel::data(const QModelIndex &index, int role) const
78 78 {
79 79 if (role == Qt::DisplayRole) {
80 80 return m_data[index.row()]->at(index.column());
81 81 } else if (role == Qt::EditRole) {
82 82 return m_data[index.row()]->at(index.column());
83 83 }
84 84 return QVariant();
85 85 }
86 86
87 87 bool ChartTableModel::setData(const QModelIndex &index, const QVariant &value, int role)
88 88 {
89 89 if (index.isValid() && role == Qt::EditRole) {
90 90 m_data[index.row()]->replace(index.column(), value);
91 91 emit dataChanged(index, index);
92 92 return true;
93 93 }
94 94 return false;
95 95 }
96 96
97 void ChartTableModel::insertRow(int row, const QModelIndex &parent)
97 void ChartTableModel::insertColumn(int column, const QModelIndex &parent)
98 98 {
99 Q_UNUSED(parent)
99 beginInsertColumns(parent, column, column);
100 m_columnCount++;
101 endInsertColumns();
102 }
100 103
101 beginInsertRows(QModelIndex(), row, row);
104 void ChartTableModel::insertRow(int row, const QModelIndex &parent)
105 {
106 beginInsertRows(parent, row, row);
102 107 QVector<QVariant>* dataVec = new QVector<QVariant>(m_columnCount);
103 108 m_data.insert(row, dataVec);
104 109 endInsertRows();
105 110 }
106 111
107 112 //bool ChartTableModel::removeRow(int row, const QModelIndex &parent)
108 113 //{
109 114 // Q_UNUSED(parent)
110 115 // Q_ASSERT(row >= 0 && row < rowCount);
111 116
112 117 // beginRemoveRows(parent, row, row);
113 118 // m_data.removeAt(row);
114 119 // endRemoveRows();
115 120 // return true;
116 121 //}
117 122
118 123 bool ChartTableModel::removeRow(int row, const QModelIndex &parent)
119 124 {
120 125 return QAbstractTableModel::removeRow(row, parent);
121 126 }
122 127
123 128 bool ChartTableModel::removeRows(int row, int count, const QModelIndex &parent)
124 129 {
125 130 beginRemoveRows(parent, row, row + count - 1);
126 131 bool removed(false);
127 132 for (int i(row); i < (row + count); i++) {
128 133 m_data.removeAt(i);
129 134 removed = true;
130 135 }
131 136 endRemoveRows();
132 137 return removed;
133 138 }
134 139
135 140 Qt::ItemFlags ChartTableModel::flags ( const QModelIndex & index ) const
136 141 {
137 142 return QAbstractItemModel::flags(index) | Qt::ItemIsEditable;
138 143 }
139 144
140 145 #include "moc_charttablemodel.cpp"
@@ -1,58 +1,59
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 CHARTTABLEMODEL_H
22 22 #define CHARTTABLEMODEL_H
23 23
24 24 #include "qchartglobal.h"
25 25 #include <QAbstractTableModel>
26 26 #include <QHash>
27 27 #include <QRect>
28 28
29 29 QTCOMMERCIALCHART_BEGIN_NAMESPACE
30 30
31 31 class QTCOMMERCIALCHART_EXPORT ChartTableModel : public QAbstractTableModel
32 32 {
33 33 Q_OBJECT
34 34 Q_PROPERTY(int count READ rowCount)
35 35
36 36 public:
37 37 explicit ChartTableModel(QObject *parent = 0);
38 38
39 39 int rowCount ( const QModelIndex & parent = QModelIndex() ) const;
40 40 int columnCount ( const QModelIndex & parent = QModelIndex() ) const;
41 41 QVariant headerData (int section, Qt::Orientation orientation, int role = Qt::DisplayRole ) const;
42 42 QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const;
43 43 bool setData ( const QModelIndex & index, const QVariant & value, int role = Qt::EditRole );
44 44 Qt::ItemFlags flags ( const QModelIndex & index ) const;
45 void insertColumn(int column, const QModelIndex &parent = QModelIndex());
45 46 void insertRow(int row, const QModelIndex &parent = QModelIndex());
46 47 /*Q_INVOKABLE*/ //bool removeRow(int row, const QModelIndex &parent = QModelIndex());
47 48 Q_INVOKABLE bool removeRows(int row, int count, const QModelIndex & parent = QModelIndex());
48 49 Q_INVOKABLE bool removeRow (int row, const QModelIndex &parent = QModelIndex());
49 50
50 51 private:
51 52 QList<QVector<QVariant> * > m_data;
52 53 int m_columnCount;
53 54 int m_rowCount;
54 55 };
55 56
56 57 QTCOMMERCIALCHART_END_NAMESPACE
57 58
58 59 #endif // CHARTTABLEMODEL_H
@@ -1,46 +1,53
1 1 #ifndef QPIEMODELMAPPER_H
2 2 #define QPIEMODELMAPPER_H
3 3
4 4 #include "qchartglobal.h"
5 5 #include <QObject>
6 6
7 7 QTCOMMERCIALCHART_BEGIN_NAMESPACE
8 8
9 9 class QTCOMMERCIALCHART_EXPORT QPieModelMapper : public QObject
10 10 {
11 11 Q_OBJECT
12 Q_PROPERTY(int mapValues READ mapValues WRITE setMapValues)
13 Q_PROPERTY(int mapLabels READ mapLabels WRITE setMapLabels)
14 Q_PROPERTY(int first READ first WRITE setFirst)
15 Q_PROPERTY(int count READ count WRITE setCount)
16 Q_PROPERTY(Qt::Orientation orientation READ orientation WRITE setOrientation)
17 Q_ENUMS(Qt::Orientation)
18
12 19 public:
13 20 explicit QPieModelMapper(QObject *parent = 0);
14
21
15 22 int first() const;
16 23 void setFirst(int first);
17 24
18 25 int count() const;
19 26 void setCount(int count);
20 27
21 28 Qt::Orientation orientation() const;
22 29 void setOrientation(Qt::Orientation orientation);
23 30
24 31 int mapValues() const;
25 32 void setMapValues(int mapValues);
26 33
27 34 int mapLabels() const;
28 35 void setMapLabels(int mapLabels);
29 36
30 37 void reset();
31 38
32 39 Q_SIGNALS:
33 40 void updated();
34 41
35 42 private:
36 43 int m_first;
37 44 int m_count;
38 45 Qt::Orientation m_orientation;
39 46 int m_mapValues;
40 47 int m_mapLabels;
41 48
42 49 };
43 50
44 51 QTCOMMERCIALCHART_END_NAMESPACE
45 52
46 53 #endif // QPIEMODELMAPPER_H
@@ -1,90 +1,92
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 PIESERIES_H
22 22 #define PIESERIES_H
23 23
24 24 #include <qabstractseries.h>
25 25
26 26 QTCOMMERCIALCHART_BEGIN_NAMESPACE
27 27 class QPieSeriesPrivate;
28 28 class QPieSlice;
29 29 class QPieModelMapper;
30 30
31 31 class QTCOMMERCIALCHART_EXPORT QPieSeries : public QAbstractSeries
32 32 {
33 33 Q_OBJECT
34 34 Q_PROPERTY(qreal horizontalPosition READ horizontalPosition WRITE setHorizontalPosition)
35 35 Q_PROPERTY(qreal verticalPosition READ verticalPosition WRITE setVerticalPosition)
36 36 Q_PROPERTY(qreal size READ pieSize WRITE setPieSize)
37 37 Q_PROPERTY(qreal startAngle READ pieStartAngle WRITE setPieStartAngle)
38 38 Q_PROPERTY(qreal endAngle READ pieEndAngle WRITE setPieEndAngle)
39 Q_PROPERTY(int count READ count)
40 Q_PROPERTY(QPieModelMapper *modelMapper READ modelMapper)
39 41
40 42 public:
41 43 explicit QPieSeries(QObject *parent = 0);
42 44 virtual ~QPieSeries();
43 45
44 46 QAbstractSeries::SeriesType type() const;
45 47
46 48 bool append(QPieSlice* slice);
47 49 bool append(QList<QPieSlice*> slices);
48 50 QPieSeries& operator << (QPieSlice* slice);
49 51 QPieSlice* append(qreal value, QString name);
50 52 bool insert(int index, QPieSlice* slice);
51 53 bool remove(QPieSlice* slice);
52 54 void clear();
53 55
54 56 QList<QPieSlice*> slices() const;
55 57 int count() const;
56 58 bool isEmpty() const;
57 59
58 60 qreal sum() const;
59 61
60 62 void setHorizontalPosition(qreal relativePosition);
61 63 qreal horizontalPosition() const;
62 64 void setVerticalPosition(qreal relativePosition);
63 65 qreal verticalPosition() const;
64 66
65 67 void setPieSize(qreal relativeSize);
66 68 qreal pieSize() const;
67 69
68 70 void setPieStartAngle(qreal startAngle);
69 71 qreal pieStartAngle() const;
70 72 void setPieEndAngle(qreal endAngle);
71 73 qreal pieEndAngle() const;
72 74
73 75 void setLabelsVisible(bool visible = true);
74 76
75 77 void setModel(QAbstractItemModel* model);
76 78 void setModelMapper(QPieModelMapper *mapper);
77 79 QPieModelMapper* modelMapper() const;
78 80
79 81 Q_SIGNALS:
80 82 void clicked(QPieSlice* slice);
81 83 void hovered(QPieSlice* slice, bool state);
82 84
83 85 private:
84 86 Q_DECLARE_PRIVATE(QPieSeries)
85 87 Q_DISABLE_COPY(QPieSeries)
86 88 };
87 89
88 90 QTCOMMERCIALCHART_END_NAMESPACE
89 91
90 92 #endif // PIESERIES_H
@@ -1,47 +1,52
1 1 #ifndef QXYMODELMAPPER_H
2 2 #define QXYMODELMAPPER_H
3 3
4 4 #include "qchartglobal.h"
5 5 #include <QObject>
6 #include <Qt>
7 6
8 7 QTCOMMERCIALCHART_BEGIN_NAMESPACE
9 8
10 9 class QTCOMMERCIALCHART_EXPORT QXYModelMapper : public QObject
11 10 {
12 11 Q_OBJECT
12 Q_PROPERTY(int mapX READ mapX WRITE setMapX)
13 Q_PROPERTY(int mapY READ mapY WRITE setMapY)
14 Q_PROPERTY(int first READ first WRITE setFirst)
15 Q_PROPERTY(int count READ count WRITE setCount)
16 Q_PROPERTY(Qt::Orientation orientation READ orientation WRITE setOrientation)
17 Q_ENUMS(Qt::Orientation)
13 18
14 19 public:
15 20 explicit QXYModelMapper(QObject *parent = 0);
16 21
17 22 int first() const;
18 23 void setFirst(int first);
19 24
20 25 int count() const;
21 26 void setCount(int count);
22 27
23 28 Qt::Orientation orientation() const;
24 29 void setOrientation(Qt::Orientation orientation);
25 30
26 31 int mapX() const;
27 32 void setMapX(int mapX);
28 33
29 34 int mapY() const;
30 35 void setMapY(int mapY);
31 36
32 37 void reset();
33 38
34 39 Q_SIGNALS:
35 40 void updated();
36 41
37 42 private:
38 43 int m_first;
39 44 int m_count;
40 45 Qt::Orientation m_orientation;
41 46 int m_mapX;
42 47 int m_mapY;
43 48 };
44 49
45 50 QTCOMMERCIALCHART_END_NAMESPACE
46 51
47 52 #endif // QXYMODELMAPPER_H
@@ -1,84 +1,86
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 QXYSERIES_H
22 22 #define QXYSERIES_H
23 23
24 24 #include <qchartglobal.h>
25 25 #include <qabstractseries.h>
26 26 #include <QPen>
27 27 #include <QBrush>
28 28
29 29 class QModelIndex;
30 30
31 31 QTCOMMERCIALCHART_BEGIN_NAMESPACE
32 32
33 33 class QXYSeriesPrivate;
34 34 class QXYModelMapper;
35 35
36 36 class QTCOMMERCIALCHART_EXPORT QXYSeries : public QAbstractSeries
37 37 {
38 38 Q_OBJECT
39 Q_PROPERTY(QXYModelMapper *modelMapper READ modelMapper)
40
39 41 protected:
40 42 explicit QXYSeries(QXYSeriesPrivate &d,QObject *parent = 0);
41 43 ~QXYSeries();
42 44
43 45 public:
44 46 void append(qreal x, qreal y);
45 47 void append(const QPointF &point);
46 48 void append(const QList<QPointF> &points);
47 49 void replace(qreal oldX,qreal oldY,qreal newX,qreal newY);
48 50 void replace(const QPointF &oldPoint,const QPointF &newPoint);
49 51 void remove(qreal x, qreal y);
50 52 void remove(const QPointF &point);
51 53 void removeAll();
52 54
53 55 int count() const;
54 56 QList<QPointF> points() const;
55 57
56 58 QXYSeries& operator << (const QPointF &point);
57 59 QXYSeries& operator << (const QList<QPointF> &points);
58 60
59 61 void setPen(const QPen &pen);
60 62 QPen pen() const;
61 63
62 64 void setBrush(const QBrush &brush);
63 65 QBrush brush() const;
64 66
65 67 void setPointsVisible(bool visible = true);
66 68 bool pointsVisible() const;
67 69
68 70 void setModel(QAbstractItemModel *model);
69 71 virtual void setModelMapper(QXYModelMapper *mapper);
70 72 QXYModelMapper* modelMapper() const;
71 73
72 74 Q_SIGNALS:
73 75 void clicked(const QPointF &point);
74 76
75 77 private:
76 78 Q_DECLARE_PRIVATE(QXYSeries);
77 79 Q_DISABLE_COPY(QXYSeries);
78 80 friend class XYLegendMarker;
79 81 friend class XYChartItem;
80 82 };
81 83
82 84 QTCOMMERCIALCHART_END_NAMESPACE
83 85
84 86 #endif
General Comments 0
You need to be logged in to leave comments. Login now