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