##// END OF EJS Templates
Refactored QML example to multiple views
Tero Ahola -
r887:1270a0b0cca2
parent child
Show More
@@ -0,0 +1,74
1 /****************************************************************************
2 **
3 ** Copyright (C) 2012 Digia Plc
4 ** All rights reserved.
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 **
7 ** This file is part of the Qt Commercial Charts Add-on.
8 **
9 ** $QT_BEGIN_LICENSE$
10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 ** accordance with the Qt Commercial License Agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia.
14 **
15 ** If you have questions regarding the use of this file, please use
16 ** contact form at http://qt.digia.com
17 ** $QT_END_LICENSE$
18 **
19 ****************************************************************************/
20
21 import QtQuick 1.0
22 import QtCommercial.Chart 1.0
23
24 Rectangle {
25 width: parent.width
26 height: parent.height
27
28 // Another option for QML data api:
29 // ListModel {
30 // id: listModelForPie
31 // // PieDataElement
32 // ListElement {
33 // label: "Apple"
34 // value: 4.3
35 // }
36 // ListElement {
37 // label: "Blackberry"
38 // value: 15.1
39 // }
40 // }
41
42 Component.onCompleted: {
43 // console.log("model:" + myModel.item(0));
44 // myModel.insert(1, {"time":1.4; "speed":41.1 });
45 // scatter.appendData();
46 // chart1.theme = Chart.ThemeHighContrast;
47 // chart2.theme = Chart.ThemeHighContrast;
48 }
49
50 Chart {
51 id: chart1
52 anchors.fill: parent
53 theme: Chart.ChartThemeDark
54
55 BarSeries {
56 barCategories: [ "2008", "2009", "2010", "2011", "2012" ]
57 // TBD: data
58 }
59
60 PieSeries {
61 horizontalPosition: 0.2
62 verticalPosition: 0.3
63 size: 0.4
64 endAngle: 0.52 * 360 // The share of "others" is 52%
65 slices: [
66 PieSlice { label: "Volkswagen"; value: 13.5 },
67 PieSlice { label: "Toyota"; value: 10.9 },
68 PieSlice { label: "Ford"; value: 8.6 },
69 PieSlice { label: "Skoda"; value: 8.2 },
70 PieSlice { label: "Volvo"; value: 6.8 }
71 ]
72 }
73 }
74 }
@@ -0,0 +1,51
1 /****************************************************************************
2 **
3 ** Copyright (C) 2012 Digia Plc
4 ** All rights reserved.
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 **
7 ** This file is part of the Qt Commercial Charts Add-on.
8 **
9 ** $QT_BEGIN_LICENSE$
10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 ** accordance with the Qt Commercial License Agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia.
14 **
15 ** If you have questions regarding the use of this file, please use
16 ** contact form at http://qt.digia.com
17 ** $QT_END_LICENSE$
18 **
19 ****************************************************************************/
20
21 import QtQuick 1.0
22 import QtCommercial.Chart 1.0
23
24 Rectangle {
25 anchors.fill: parent
26
27 Chart {
28 anchors.fill: parent
29 theme: Chart.ChartThemeBrownSand
30
31 LineSeries {
32 name: "Line"
33 points: [
34 XyPoint { x: 0.0; y: 0.0 },
35 XyPoint { x: 1.1; y: 2.1 },
36 XyPoint { x: 2.9; y: 4.9 },
37 XyPoint { x: 3.2; y: 3.0 }
38 ]
39 }
40
41 SplineSeries {
42 name: "Spline"
43 points: [
44 XyPoint { x: 0.0; y: 0.3 },
45 XyPoint { x: 1.1; y: 3.2 },
46 XyPoint { x: 2.17; y: 2.15 },
47 XyPoint { x: 4.17; y: 3.15 }
48 ]
49 }
50 }
51 }
@@ -0,0 +1,70
1 /****************************************************************************
2 **
3 ** Copyright (C) 2012 Digia Plc
4 ** All rights reserved.
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 **
7 ** This file is part of the Qt Commercial Charts Add-on.
8 **
9 ** $QT_BEGIN_LICENSE$
10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 ** accordance with the Qt Commercial License Agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia.
14 **
15 ** If you have questions regarding the use of this file, please use
16 ** contact form at http://qt.digia.com
17 ** $QT_END_LICENSE$
18 **
19 ****************************************************************************/
20
21 import QtQuick 1.0
22 import QtCommercial.Chart 1.0
23
24 Rectangle {
25 anchors.fill: parent
26
27 Chart {
28 anchors.fill: parent
29 theme: Chart.ChartThemeHighContrast
30
31 AreaSeries {
32 name: "Area"
33 points: [
34 XyPoint { x: 0.0; y: 1.1 },
35 XyPoint { x: 2.5; y: 3.6 },
36 XyPoint { x: 3.57; y: 2.55 }
37 ]
38 lowerPoints: [
39 XyPoint { x: 0.0; y: 0.0 },
40 XyPoint { x: 2.5; y: 0.0 },
41 XyPoint { x: 3.57; y: 0.0 }
42 ]
43 }
44
45 ScatterSeries {
46 name: "Scatter1"
47 points: [
48 XyPoint { x: 1.5; y: 1.5 },
49 XyPoint { x: 1.5; y: 1.6 },
50 XyPoint { x: 1.57; y: 1.55 }
51 ]
52 }
53 ScatterSeries {
54 name: "Scatter2"
55 points: [
56 XyPoint { x: 2.0; y: 2.0 },
57 XyPoint { x: 2.0; y: 2.1 },
58 XyPoint { x: 2.07; y: 2.05 }
59 ]
60 }
61 ScatterSeries {
62 name: "Scatter3"
63 points: [
64 XyPoint { x: 2.6; y: 2.6 },
65 XyPoint { x: 2.6; y: 2.7 },
66 XyPoint { x: 2.67; y: 2.65 }
67 ]
68 }
69 }
70 }
@@ -261,7 +261,8 void TableWidget::updateChartType(bool toggle)
261 pieSeries->setModelMapping(0,0, Qt::Vertical);
261 pieSeries->setModelMapping(0,0, Qt::Vertical);
262 pieSeries->setLabelsVisible(true);
262 pieSeries->setLabelsVisible(true);
263 pieSeries->setPieSize(0.4);
263 pieSeries->setPieSize(0.4);
264 pieSeries->setPiePosition(0.2, 0.35);
264 pieSeries->setHorizontalPosition(0.2);
265 pieSeries->setVerticalPosition(0.35);
265
266
266 m_chart->addSeries(pieSeries);
267 m_chart->addSeries(pieSeries);
267 seriesColorHex = "#" + QString::number(pieSeries->slices().at(pieSeries->slices().count()/2)->brush().color().rgb(), 16).right(6).toUpper();
268 seriesColorHex = "#" + QString::number(pieSeries->slices().at(pieSeries->slices().count()/2)->brush().color().rgb(), 16).right(6).toUpper();
@@ -273,7 +274,8 void TableWidget::updateChartType(bool toggle)
273 pieSeries->setModelMapping(1,1, Qt::Vertical);
274 pieSeries->setModelMapping(1,1, Qt::Vertical);
274 pieSeries->setLabelsVisible(true);
275 pieSeries->setLabelsVisible(true);
275 pieSeries->setPieSize(0.4);
276 pieSeries->setPieSize(0.4);
276 pieSeries->setPiePosition(0.8, 0.35);
277 pieSeries->setHorizontalPosition(0.8);
278 pieSeries->setVerticalPosition(0.35);
277 m_chart->addSeries(pieSeries);
279 m_chart->addSeries(pieSeries);
278 seriesColorHex = "#" + QString::number(pieSeries->slices().at(pieSeries->slices().count()/2)->brush().color().rgb(), 16).right(6).toUpper();
280 seriesColorHex = "#" + QString::number(pieSeries->slices().at(pieSeries->slices().count()/2)->brush().color().rgb(), 16).right(6).toUpper();
279 m_model->addMapping(seriesColorHex, QRect(1, 0, 1, 1000));
281 m_model->addMapping(seriesColorHex, QRect(1, 0, 1, 1000));
@@ -284,7 +286,8 void TableWidget::updateChartType(bool toggle)
284 pieSeries->setModelMapping(2,2, Qt::Vertical);
286 pieSeries->setModelMapping(2,2, Qt::Vertical);
285 pieSeries->setLabelsVisible(true);
287 pieSeries->setLabelsVisible(true);
286 pieSeries->setPieSize(0.4);
288 pieSeries->setPieSize(0.4);
287 pieSeries->setPiePosition(0.5, 0.65);
289 pieSeries->setHorizontalPosition(0.5);
290 pieSeries->setVerticalPosition(0.65);
288 m_chart->addSeries(pieSeries);
291 m_chart->addSeries(pieSeries);
289 seriesColorHex = "#" + QString::number(pieSeries->slices().at(pieSeries->slices().count()/2)->brush().color().rgb(), 16).right(6).toUpper();
292 seriesColorHex = "#" + QString::number(pieSeries->slices().at(pieSeries->slices().count()/2)->brush().color().rgb(), 16).right(6).toUpper();
290 m_model->addMapping(seriesColorHex, QRect(2, 0, 1, 1000));
293 m_model->addMapping(seriesColorHex, QRect(2, 0, 1, 1000));
@@ -23,7 +23,7 import QtQuick 1.0
23 Item {
23 Item {
24 id: container
24 id: container
25 width: 400
25 width: 400
26 height: 500
26 height: 300
27 Component.onCompleted: {
27 Component.onCompleted: {
28 var co = Qt.createComponent("main.qml")
28 var co = Qt.createComponent("main.qml")
29 if (co.status == Component.Ready) {
29 if (co.status == Component.Ready) {
@@ -24,124 +24,31 import QtCommercial.Chart 1.0
24 Rectangle {
24 Rectangle {
25 width: parent.width
25 width: parent.width
26 height: parent.height
26 height: parent.height
27
27 property int __viewNumber: 0
28 // Another option for QML data api:
28
29 // ListModel {
29 Timer {
30 // id: listModelForPie
30 id: timer
31 // // PieDataElement
31 running: true
32 // ListElement {
32 repeat: true
33 // label: "Apple"
33 interval: 5000
34 // value: 4.3
34 triggeredOnStart: true
35 // }
35 onTriggered: {
36 // ListElement {
36 loader.source = "View" + (__viewNumber % 3 + 1) + ".qml";
37 // label: "Blackberry"
37 __viewNumber++;
38 // value: 15.1
39 // }
40 // }
41
42 Component.onCompleted: {
43 // console.log("model:" + myModel.item(0));
44 // myModel.insert(1, {"time":1.4; "speed":41.1 });
45 // scatter.appendData();
46 // chart1.theme = Chart.ThemeHighContrast;
47 // chart2.theme = Chart.ThemeHighContrast;
48 }
49
50
51 Chart {
52 id: chart1
53 anchors.top: parent.top
54 anchors.left: parent.left
55 anchors.right: parent.right
56 height: parent.height / 2
57 theme: Chart.ChartThemeDark
58
59 BarSeries {
60 barCategories: [ "2008", "2009", "2010", "2011", "2012" ]
61 // TBD: data
62 }
63
64 PieSeries {
65 horizontalPosition: 0.2
66 verticalPosition: 0.3
67 size: 0.4
68 endAngle: 0.52 * 360 // The share of "others" is 52%
69 slices: [
70 PieSlice { label: "Volkswagen"; value: 13.5 },
71 PieSlice { label: "Toyota"; value: 10.9 },
72 PieSlice { label: "Ford"; value: 8.6 },
73 PieSlice { label: "Skoda"; value: 8.2 },
74 PieSlice { label: "Volvo"; value: 6.8 }
75 ]
76 }
38 }
77 }
39 }
78
40
41 Loader {
42 id: loader
43 anchors.fill: parent
44 }
79
45
80 Chart {
46 MouseArea {
81 id: chart2
47 anchors.fill: parent
82 anchors.top: chart1.bottom
48 onClicked: {
83 anchors.bottom: parent.bottom
49 timer.restart();
84 anchors.left: parent.left
50 loader.source = "View" + (__viewNumber % 3 + 1) + ".qml";
85 anchors.right: parent.right
51 __viewNumber++;
86 theme: Chart.ChartThemeBrownSand
87
88 LineSeries {
89 name: "Line"
90 points: [
91 XyPoint { x: 0.0; y: 0.0 },
92 XyPoint { x: 1.1; y: 2.1 },
93 XyPoint { x: 2.9; y: 4.9 },
94 XyPoint { x: 3.2; y: 3.0 }
95 ]
96 }
97
98 SplineSeries {
99 name: "Spline"
100 points: [
101 XyPoint { x: 0.0; y: 0.3 },
102 XyPoint { x: 1.1; y: 3.2 },
103 XyPoint { x: 2.17; y: 2.15 },
104 XyPoint { x: 4.17; y: 3.15 }
105 ]
106 }
107
108 AreaSeries {
109 name: "Area"
110 points: [
111 XyPoint { x: 0.0; y: 1.1 },
112 XyPoint { x: 2.5; y: 3.6 },
113 XyPoint { x: 3.57; y: 2.55 }
114 ]
115 lowerPoints: [
116 XyPoint { x: 0.0; y: 0.0 },
117 XyPoint { x: 2.5; y: 0.0 },
118 XyPoint { x: 3.57; y: 0.0 }
119 ]
120 }
121
122 ScatterSeries {
123 name: "Scatter1"
124 points: [
125 XyPoint { x: 1.5; y: 1.5 },
126 XyPoint { x: 1.5; y: 1.6 },
127 XyPoint { x: 1.57; y: 1.55 }
128 ]
129 }
130 ScatterSeries {
131 name: "Scatter2"
132 points: [
133 XyPoint { x: 2.0; y: 2.0 },
134 XyPoint { x: 2.0; y: 2.1 },
135 XyPoint { x: 2.07; y: 2.05 }
136 ]
137 }
138 ScatterSeries {
139 name: "Scatter3"
140 points: [
141 XyPoint { x: 2.6; y: 2.6 },
142 XyPoint { x: 2.6; y: 2.7 },
143 XyPoint { x: 2.67; y: 2.65 }
144 ]
145 }
52 }
146 }
53 }
147 }
54 }
@@ -2,5 +2,8
2 <qresource prefix="/">
2 <qresource prefix="/">
3 <file>qml/qmlchart/loader.qml</file>
3 <file>qml/qmlchart/loader.qml</file>
4 <file>qml/qmlchart/main.qml</file>
4 <file>qml/qmlchart/main.qml</file>
5 <file>qml/qmlchart/View1.qml</file>
6 <file>qml/qmlchart/View2.qml</file>
7 <file>qml/qmlchart/View3.qml</file>
5 </qresource>
8 </qresource>
6 </RCC>
9 </RCC>
General Comments 0
You need to be logged in to leave comments. Login now