##// END OF EJS Templates
Cleaning up ChartModel impl before moving it into a demo app
Tero Ahola -
r1190:f9f8ff23359b
parent child
Show More
@@ -1,142 +1,142
1 1 /****************************************************************************
2 2 **
3 3 ** Copyright (C) 2012 Digia Plc
4 4 ** All rights reserved.
5 5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 6 **
7 7 ** This file is part of the Qt Commercial Charts Add-on.
8 8 **
9 9 ** $QT_BEGIN_LICENSE$
10 10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 11 ** accordance with the Qt Commercial License Agreement provided with the
12 12 ** Software or, alternatively, in accordance with the terms contained in
13 13 ** a written agreement between you and Digia.
14 14 **
15 15 ** If you have questions regarding the use of this file, please use
16 16 ** contact form at http://qt.digia.com
17 17 ** $QT_END_LICENSE$
18 18 **
19 19 ****************************************************************************/
20 20
21 21 import QtQuick 1.0
22 22 import QtCommercial.Chart 1.0
23 23
24 24 Rectangle {
25 25 anchors.fill: parent
26 26 property int __explodedIndex: -1
27 27
28 28 ChartView {
29 29 id: chart
30 30 title: "Top-5 car brand shares in Finland"
31 31 anchors.top: parent.top
32 32 anchors.bottom: button.top
33 33 anchors.left: parent.left
34 34 anchors.right: parent.right
35 35 theme: ChartView.ChartThemeLight
36 36 legend: ChartView.LegendBottom
37 37 animationOptions: ChartView.SeriesAnimations
38 38
39 39 // If you have static data, you can simply use the PieSlice API
40 40 PieSeries {
41 41 id: pieSeries
42 42 PieSlice { id: volkswagenSlice; label: "Volkswagen"; value: 13.5 }
43 43 PieSlice { label: "Toyota"; value: 10.9 }
44 44 PieSlice { label: "Ford"; value: 8.6 }
45 45 PieSlice { label: "Skoda"; value: 8.2 }
46 46 PieSlice { label: "Volvo"; value: 6.8 }
47 47 }
48 48
49 49 // TODO: move ChartModel API into a demo application instead of making it a public API
50 50 // // For dynamic data you can use the ChartModel API.
51 51 // ChartModel {
52 52 // id: chartModel
53 // ChartModelRow { values: ["Volkswagen", 13.5] }
54 // ChartModelRow { values: ["Toyota", 10.9] }
55 // ChartModelRow { values: ["Ford", 8.6] }
56 // ChartModelRow { values: ["Skoda", 8.2] }
57 // ChartModelRow { values: ["Volvo", 6.8] }
53 // ChartModelElement { values: ["Volkswagen", 13.5] }
54 // ChartModelElement { values: ["Toyota", 10.9] }
55 // ChartModelElement { values: ["Ford", 8.6] }
56 // ChartModelElement { values: ["Skoda", 8.2] }
57 // ChartModelElement { values: ["Volvo", 6.8] }
58 58 // }
59 59 // // In this case you need to define how the data maps to pie slices with the ModelMapper API of the pie series.
60 60 // PieSeries {
61 61 // id: pieSeries
62 62 // model: chartModel
63 63 // modelMapper.mapLabels: 0
64 64 // modelMapper.mapValues: 1
65 65 // modelMapper.first: 0
66 66 // modelMapper.count: -1 // "Undefined" = -1 by default
67 67 // modelMapper.orientation: PieModelMapper.Vertical
68 68 // }
69 69
70 70 // TODO: you could also append to your model, for example:
71 71 // pieSeries.model.append(["Others", 52.0]);
72 72 }
73 73
74 74 Component.onCompleted: {
75 75 volkswagenSlice.exploded = true;
76 76 // You can also add slices dynamically
77 77 var newSlice = pieSeries.append("Others", 52.0);
78 78 }
79 79
80 80 Timer {
81 81 repeat: true
82 82 interval: 2000
83 83 running: true
84 84 onTriggered: {
85 85 // Set all slices as not exploded
86 86 for (var i = 0; i < pieSeries.count; i++)
87 87 pieSeries.at(i).exploded = false;
88 88
89 89 // Explode one of the slices
90 90 __explodedIndex = (__explodedIndex + 1) % pieSeries.count;
91 91 pieSeries.at(__explodedIndex).exploded = true;
92 92
93 93 // TODO: implement for convenience
94 94 // pieSeries.find("Ford").exploded = true;
95 95 // pieSeries.removeAll("Ford")
96 96 }
97 97 }
98 98
99 99 Rectangle {
100 100 id: button
101 101 anchors.bottom: parent.bottom
102 102 anchors.bottomMargin: 10
103 103 anchors.horizontalCenter: parent.horizontalCenter
104 104 height: 40
105 105 width: 100
106 106 color: "orange"
107 107 radius: 5
108 108 Text {
109 109 id: buttonText
110 110 anchors.centerIn: parent
111 111 text: "Hide others"
112 112 }
113 113 MouseArea {
114 114 anchors.fill: parent
115 115 onClicked: {
116 116 if (buttonText.text == "Show others") {
117 117 pieSeries.modelMapper.count = -1;
118 118 buttonText.text = "Hide others";
119 119 } else {
120 120 pieSeries.modelMapper.count = 5;
121 121 buttonText.text = "Show others";
122 122 }
123 123 }
124 124 }
125 125 }
126 126
127 127 // TODO: show how to use data from a list model in a chart view
128 128 // i.e. copy the data into a chart model
129 129 // ListModel {
130 130 // id: listModel
131 131 // ListElement {
132 132 // label: "Volkswagen"
133 133 // value: 13.5
134 134 // }
135 135 // ListElement {
136 136 // label: "Toyota"
137 137 // value: 10.9
138 138 // }
139 139 // // and so on...
140 140 // }
141 141
142 142 }
@@ -1,62 +1,62
1 1 /****************************************************************************
2 2 **
3 3 ** Copyright (C) 2012 Digia Plc
4 4 ** All rights reserved.
5 5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 6 **
7 7 ** This file is part of the Qt Commercial Charts Add-on.
8 8 **
9 9 ** $QT_BEGIN_LICENSE$
10 10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 11 ** accordance with the Qt Commercial License Agreement provided with the
12 12 ** Software or, alternatively, in accordance with the terms contained in
13 13 ** a written agreement between you and Digia.
14 14 **
15 15 ** If you have questions regarding the use of this file, please use
16 16 ** contact form at http://qt.digia.com
17 17 ** $QT_END_LICENSE$
18 18 **
19 19 ****************************************************************************/
20 20
21 21 import QtQuick 1.0
22 22 import QtCommercial.Chart 1.0
23 23
24 24 Rectangle {
25 25 anchors.fill: parent
26 26
27 27 ChartView {
28 28 title: "Line&Spline"
29 29 anchors.fill: parent
30 30 theme: ChartView.ChartThemeBrownSand
31 31 animationOptions: ChartView.NoAnimation
32 32
33 33 LineSeries {
34 34 name: "Line"
35 35 model: chartModel
36 36 modelMapper.mapX: 0
37 37 modelMapper.mapY: 1
38 38 modelMapper.first: 0
39 39 modelMapper.count: -1
40 40 modelMapper.orientation: XYModelMapper.Vertical
41 41 }
42 42
43 43 SplineSeries {
44 44 name: "Spline"
45 45 model: chartModel
46 46 modelMapper.mapX: 0
47 47 modelMapper.mapY: 2
48 48 }
49 49 }
50 50
51 51 ChartModel {
52 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] }
53 ChartModelElement { values: [0.0, 0.0, 0.3] }
54 ChartModelElement { values: [1.1, 2.1, 3.2] }
55 ChartModelElement { values: [1.9, 3.3, 2.4] }
56 ChartModelElement { values: [2.1, 2.1, 2.1] }
57 ChartModelElement { values: [2.9, 4.9, 2.6] }
58 ChartModelElement { values: [3.4, 3.0, 2.3] }
59 ChartModelElement { values: [4.1, 3.3, 3.1] }
60 60 }
61 61
62 62 }
@@ -1,78 +1,78
1 1 /****************************************************************************
2 2 **
3 3 ** Copyright (C) 2012 Digia Plc
4 4 ** All rights reserved.
5 5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 6 **
7 7 ** This file is part of the Qt Commercial Charts Add-on.
8 8 **
9 9 ** $QT_BEGIN_LICENSE$
10 10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 11 ** accordance with the Qt Commercial License Agreement provided with the
12 12 ** Software or, alternatively, in accordance with the terms contained in
13 13 ** a written agreement between you and Digia.
14 14 **
15 15 ** If you have questions regarding the use of this file, please use
16 16 ** contact form at http://qt.digia.com
17 17 ** $QT_END_LICENSE$
18 18 **
19 19 ****************************************************************************/
20 20
21 21 import QtQuick 1.0
22 22 import QtCommercial.Chart 1.0
23 23
24 24 Rectangle {
25 25 anchors.fill: parent
26 26
27 27 ChartView {
28 28 title: "NHL All-Star Team Players"
29 29 anchors.fill: parent
30 30 theme: ChartView.ChartThemeHighContrast
31 31 axisXLabels: ["0", "2000", "1", "2001", "2", "2002", "3", "2003", "4", "2004", "5", "2005",
32 32 "6", "2006", "7", "2007", "8", "2008", "9", "2009", "10", "2010", "11", "2011"]
33 33
34 34 AreaSeries {
35 35 name: "Russian"
36 36 upperModel: chartModel
37 37 upperModelMapper.mapX: 0
38 38 upperModelMapper.mapY: 2
39 39 lowerModel: chartModel
40 40 lowerModelMapper.mapX: 0
41 41 lowerModelMapper.mapY: 1
42 42 }
43 43 AreaSeries {
44 44 name: "Swedish"
45 45 upperModel: chartModel
46 46 upperModelMapper.mapX: 0
47 47 upperModelMapper.mapY: 3
48 48 lowerModel: chartModel
49 49 lowerModelMapper.mapX: 0
50 50 lowerModelMapper.mapY: 1
51 51 }
52 52 AreaSeries {
53 53 name: "Finnish"
54 54 upperModel: chartModel
55 55 upperModelMapper.mapX: 0
56 56 upperModelMapper.mapY: 4
57 57 lowerModel: chartModel
58 58 lowerModelMapper.mapX: 0
59 59 lowerModelMapper.mapY: 1
60 60 }
61 61 }
62 62
63 63 ChartModel {
64 64 id: chartModel
65 ChartModelRow { values: [0, 0, 1, 1, 0] }
66 ChartModelRow { values: [1, 0, 1, 1, 0] }
67 ChartModelRow { values: [2, 0, 1, 3, 0] }
68 ChartModelRow { values: [3, 0, 1, 3, 0] }
69 ChartModelRow { values: [4, 0, 1, 2, 0] }
70 ChartModelRow { values: [5, 0, 0, 0, 0] }
71 ChartModelRow { values: [6, 0, 1, 2, 1] }
72 ChartModelRow { values: [7, 0, 1, 1, 0] }
73 ChartModelRow { values: [8, 0, 4, 2, 0] }
74 ChartModelRow { values: [9, 0, 3, 1, 0] }
75 ChartModelRow { values: [10, 0, 2, 3, 0] }
76 ChartModelRow { values: [11, 0, 1, 3, 1] }
65 ChartModelElement { values: [0, 0, 1, 1, 0] }
66 ChartModelElement { values: [1, 0, 1, 1, 0] }
67 ChartModelElement { values: [2, 0, 1, 3, 0] }
68 ChartModelElement { values: [3, 0, 1, 3, 0] }
69 ChartModelElement { values: [4, 0, 1, 2, 0] }
70 ChartModelElement { values: [5, 0, 0, 0, 0] }
71 ChartModelElement { values: [6, 0, 1, 2, 1] }
72 ChartModelElement { values: [7, 0, 1, 1, 0] }
73 ChartModelElement { values: [8, 0, 4, 2, 0] }
74 ChartModelElement { values: [9, 0, 3, 1, 0] }
75 ChartModelElement { values: [10, 0, 2, 3, 0] }
76 ChartModelElement { values: [11, 0, 1, 3, 1] }
77 77 }
78 78 }
@@ -1,78 +1,77
1 1 /****************************************************************************
2 2 **
3 3 ** Copyright (C) 2012 Digia Plc
4 4 ** All rights reserved.
5 5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 6 **
7 7 ** This file is part of the Qt Commercial Charts Add-on.
8 8 **
9 9 ** $QT_BEGIN_LICENSE$
10 10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 11 ** accordance with the Qt Commercial License Agreement provided with the
12 12 ** Software or, alternatively, in accordance with the terms contained in
13 13 ** a written agreement between you and Digia.
14 14 **
15 15 ** If you have questions regarding the use of this file, please use
16 16 ** contact form at http://qt.digia.com
17 17 ** $QT_END_LICENSE$
18 18 **
19 19 ****************************************************************************/
20 20
21 21 import QtQuick 1.0
22 22 import QtCommercial.Chart 1.0
23 23
24 24 Rectangle {
25 25 anchors.fill: parent
26 26
27 27 ChartView {
28 28 title: "Bar series"
29 29 anchors.fill: parent
30 30 theme: ChartView.ChartThemeLight
31 31 legend: ChartView.LegendBottom
32 32 // axisXLabels: ["0", "2008", "1", "2009", "2", "2010", "3", "2012"]
33 33 axisX.max: 10
34 34
35 35 BarSeries {
36 36 barCategories: [ "2008", "2009", "2010", "2011", "2012" ]
37 37 model: barModel
38 38 }
39 39
40
41 40 // // TODO: optional syntax with ChartModel base model API
42 41 // BarSeries {
43 42 // model: chartModel
44 43 // modelMapping: BarSeriesMapping {
45 44 // // Giving "undefined" x mapping value means that the indexes are used as x-values
46 45 // setIndexes: [BarSeriesMapping.Undefined, 0,
47 46 // BarSeriesMapping.Undefined, 1,
48 47 // BarSeriesMapping.Undefined, 2] // defaults to []
49 48 //// setValues: [
50 49 //// BarSetMapping {x: BarSetMapping.Undefined; y: 0},
51 50 //// BarSetMapping {x: BarSetMapping.Undefined; y: 1},
52 51 //// BarSetMapping {x: BarSetMapping.Undefined; y: 2}
53 52 //// ]
54 53 // orientation: BarSeriesMapping.Vertical // defaults to Vertical
55 54 // startIndex: 0 // defaults to 0
56 55 // count: BarSeriesMapping.Undefined // defaults to "Undefined"
57 56 // }
58 57 // }
59 58 }
60 59
61 60 // ChartModel {
62 61 // id: chartModel
63 62 // }
64 63
65 64 BarModel {
66 65 id: barModel
67 66 BarSet { name: "Bob"; values: [2, 2, 3, 4, 5, 6] }
68 BarSet { name: "Bub"; values: [5, 1, 2, 4, 1, 7] }
69 BarSet { name: "Bib"; values: [3, 5, 8, 13, 5, 8] }
67 BarSet { name: "Susan"; values: [5, 1, 2, 4, 1, 7] }
68 BarSet { name: "James"; values: [3, 5, 8, 13, 5, 8] }
70 69 }
71 70
72 71 // TODO
73 72 // Component.onCompleted: {
74 73 // bobBars.append(1.2);
75 74 // bobBars.append(1.5);
76 75 // bobBars.append([1.5, 1.4, 1.9]);
77 76 // }
78 77 }
@@ -1,168 +1,132
1 1 /****************************************************************************
2 2 **
3 3 ** Copyright (C) 2012 Digia Plc
4 4 ** All rights reserved.
5 5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 6 **
7 7 ** This file is part of the Qt Commercial Charts Add-on.
8 8 **
9 9 ** $QT_BEGIN_LICENSE$
10 10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 11 ** accordance with the Qt Commercial License Agreement provided with the
12 12 ** Software or, alternatively, in accordance with the terms contained in
13 13 ** a written agreement between you and Digia.
14 14 **
15 15 ** If you have questions regarding the use of this file, please use
16 16 ** contact form at http://qt.digia.com
17 17 ** $QT_END_LICENSE$
18 18 **
19 19 ****************************************************************************/
20 20
21 21 #include "declarativemodel.h"
22 22 #include <qdeclarativelist.h>
23 23 #include <QDebug>
24 24
25 25 QTCOMMERCIALCHART_BEGIN_NAMESPACE
26 26
27 27
28 28 ////////////// Table model row ///////////////////
29 29
30 DeclarativeTableModelRow::DeclarativeTableModelRow(QObject *parent)
30 DeclarativeTableModelElement::DeclarativeTableModelElement(QObject *parent)
31 31 : QObject(parent)
32 32 {
33 33 }
34 34
35 QVariantList DeclarativeTableModelRow::values()
35 QVariantList DeclarativeTableModelElement::values()
36 36 {
37 37 return m_values;
38 38 }
39 39
40 void DeclarativeTableModelRow::setValues(QVariantList values)
40 void DeclarativeTableModelElement::setValues(QVariantList values)
41 41 {
42 42 m_values = values;
43 43 }
44 44
45 45 ////////////// Table model ///////////////////
46 46
47 47 DeclarativeTableModel::DeclarativeTableModel(QObject *parent) :
48 48 ChartTableModel(parent)
49 49 {
50 50 }
51 51
52 52 void DeclarativeTableModel::classBegin()
53 53 {
54 54 }
55 55
56 56 void DeclarativeTableModel::componentComplete()
57 57 {
58 58 foreach (QObject *child, children()) {
59 if (qobject_cast<DeclarativeTableModelRow *>(child)) {
60 append(qobject_cast<DeclarativeTableModelRow *>(child)->values());
59 if (qobject_cast<DeclarativeTableModelElement *>(child)) {
60 append(qobject_cast<DeclarativeTableModelElement *>(child)->values());
61 61 }
62 62 }
63 63 }
64 64
65 65 QDeclarativeListProperty<QObject> DeclarativeTableModel::modelChildren()
66 66 {
67 67 return QDeclarativeListProperty<QObject>(this, 0, &DeclarativeTableModel::appendModelChild);
68 68 }
69 69
70 70 void DeclarativeTableModel::appendModelChild(QDeclarativeListProperty<QObject> *list,
71 71 QObject *child)
72 72 {
73 73 // childs are added in componentComplete instead
74 74 Q_UNUSED(list)
75 75 Q_UNUSED(child)
76 76 }
77 77
78 78 void DeclarativeTableModel::append(QVariantList values)
79 79 {
80 80 // qDebug() << "DeclarativeTableModel::append:" << values;
81 81
82 82 while (columnCount() < values.count())
83 83 insertColumn(columnCount());
84 84
85 85 insertRow(rowCount());
86 86
87 87 QModelIndex beginIndex = QModelIndex();
88 88 QModelIndex endIndex = QModelIndex();
89 89 for (int i(0); i < values.count(); i++) {
90 90 QModelIndex modelIndex = createIndex(rowCount() - 1, i);
91 91 if (i == 0)
92 92 beginIndex = modelIndex;
93 93 if (i == (values.count() - 1))
94 94 endIndex = modelIndex;
95 95 setData(modelIndex, values.at(i));
96 96 }
97 97 dataChanged(beginIndex, endIndex);
98 98 }
99 99
100 100 void DeclarativeTableModel::appendPoint(QXYModelMapper *mapper, DeclarativeXyPoint *point)
101 101 {
102 qDebug() << "DeclarativeTableModel::appendPoint:" << point;
102 // qDebug() << "DeclarativeTableModel::appendPoint:" << point;
103 103 QVariantList values;
104 104 values.insert(mapper->mapX(), point->x());
105 105 values.insert(mapper->mapY(), point->y());
106 106 append(values);
107 107 }
108 108
109 //void DeclarativeTableModel::appendPoints(QVariantList points)
110 //{
111 // qreal x = 0.0;
112 // for (int i(0); i < points.count(); i++) {
113 // if (i % 2) {
114 // bool ok(false);
115 // qreal y = points.at(i).toReal(&ok);
116 // if (ok) {
117 // DeclarativeXyPoint *point= new DeclarativeXyPoint();
118 // point->setX(x);
119 // point->setY(y);
120 // appendPoint(point);
121 // } else {
122 // qWarning() << "Illegal y value";
123 // }
124 // } else {
125 // bool ok(false);
126 // x = points.at(i).toReal(&ok);
127 // if (!ok) {
128 // qWarning() << "Illegal x value";
129 // }
130 // }
131 // }
132 //}
133
134 //void DeclarativeTableModel::appendPoint(DeclarativeXyPoint* point)
135 //{
136 //// qDebug() << "DeclarativeTableModel::append:" << point->x() << " " << point->y();
137 // insertRow(rowCount());
138 // QModelIndex xModelIndex = createIndex(rowCount() - 1, 0);
139 // QModelIndex yModelIndex = createIndex(rowCount() - 1, 1);
140 // setData(xModelIndex, point->x());
141 // setData(yModelIndex, point->y());
142 // dataChanged(xModelIndex, yModelIndex);
143 //}
144
145 109 ////////////// Bar model ///////////////////////
146 110
147 111 DeclarativeBarModel::DeclarativeBarModel(QObject *parent) :
148 112 DeclarativeTableModel(parent)
149 113 {
150 114 }
151 115
152 116 void DeclarativeBarModel::append(QBarSet* barSet)
153 117 {
154 118 insertColumn(columnCount());
155 119 for (int i(0); i < barSet->count(); i++) {
156 120 if (rowCount() < (i + 1))
157 121 insertRow(rowCount());
158 122 setData(createIndex(i, columnCount() - 1), barSet->at(i));
159 123 // insertRow(rowCount());
160 124 // setData(createIndex(rowCount() - 1, 0), );
161 125 // setData(createIndex(rowCount() - 1, 1), barSet->at(i));
162 126 }
163 127 // TODO: setModelMapping(0, 1, columnCount(), Qt::Vertical);
164 128 }
165 129
166 130 #include "moc_declarativemodel.cpp"
167 131
168 132 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,84 +1,84
1 1 /****************************************************************************
2 2 **
3 3 ** Copyright (C) 2012 Digia Plc
4 4 ** All rights reserved.
5 5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 6 **
7 7 ** This file is part of the Qt Commercial Charts Add-on.
8 8 **
9 9 ** $QT_BEGIN_LICENSE$
10 10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 11 ** accordance with the Qt Commercial License Agreement provided with the
12 12 ** Software or, alternatively, in accordance with the terms contained in
13 13 ** a written agreement between you and Digia.
14 14 **
15 15 ** If you have questions regarding the use of this file, please use
16 16 ** contact form at http://qt.digia.com
17 17 ** $QT_END_LICENSE$
18 18 **
19 19 ****************************************************************************/
20 20
21 21 #ifndef DECLARATIVEMODEL_H
22 22 #define DECLARATIVEMODEL_H
23 23
24 24 #include "qchartglobal.h"
25 25 #include "declarativexypoint.h"
26 26 #include <QPieSlice>
27 27 #include "../src/charttablemodel.h" // TODO
28 28 #include <QBarSet>
29 29 #include <QXYModelMapper>
30 30 #include <QDeclarativeListProperty>
31 31 #include <QVariant>
32 32 #include <QDeclarativeParserStatus>
33 33
34 34 QTCOMMERCIALCHART_BEGIN_NAMESPACE
35 35
36 class DeclarativeTableModelRow : public QObject
36 class DeclarativeTableModelElement : public QObject
37 37 {
38 38 Q_OBJECT
39 39 Q_PROPERTY(QVariantList values READ values WRITE setValues)
40 40
41 41 public:
42 explicit DeclarativeTableModelRow(QObject *parent = 0);
42 explicit DeclarativeTableModelElement(QObject *parent = 0);
43 43 QVariantList values();
44 44 void setValues(QVariantList values);
45 45 private:
46 46 QVariantList m_values;
47 47 };
48 48
49 49 class DeclarativeTableModel : public ChartTableModel, public QDeclarativeParserStatus
50 50 {
51 51 Q_OBJECT
52 52 Q_INTERFACES(QDeclarativeParserStatus)
53 53 Q_PROPERTY(QDeclarativeListProperty<QObject> modelChildren READ modelChildren)
54 54 Q_CLASSINFO("DefaultProperty", "modelChildren")
55 55
56 56 public:
57 57 explicit DeclarativeTableModel(QObject *parent = 0);
58 58 QDeclarativeListProperty<QObject> modelChildren();
59 59 void appendPoint(QXYModelMapper *mapper, DeclarativeXyPoint *point);
60 60
61 61 public: // from QDeclarativeParserStatus
62 62 void classBegin();
63 63 void componentComplete();
64 64
65 65 public Q_SLOTS:
66 66 void append(QVariantList slices);
67 67 static void appendModelChild(QDeclarativeListProperty<QObject> *list,
68 68 QObject *element);
69 69 };
70 70
71 71 class DeclarativeBarModel : public DeclarativeTableModel
72 72 {
73 73 Q_OBJECT
74 74
75 75 public:
76 76 explicit DeclarativeBarModel(QObject *parent = 0);
77 77
78 78 public Q_SLOTS:
79 79 void append(QBarSet* barSet);
80 80 };
81 81
82 82 QTCOMMERCIALCHART_END_NAMESPACE
83 83
84 84 #endif // DECLARATIVEMODEL_H
@@ -1,79 +1,79
1 1 /****************************************************************************
2 2 **
3 3 ** Copyright (C) 2012 Digia Plc
4 4 ** All rights reserved.
5 5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 6 **
7 7 ** This file is part of the Qt Commercial Charts Add-on.
8 8 **
9 9 ** $QT_BEGIN_LICENSE$
10 10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 11 ** accordance with the Qt Commercial License Agreement provided with the
12 12 ** Software or, alternatively, in accordance with the terms contained in
13 13 ** a written agreement between you and Digia.
14 14 **
15 15 ** If you have questions regarding the use of this file, please use
16 16 ** contact form at http://qt.digia.com
17 17 ** $QT_END_LICENSE$
18 18 **
19 19 ****************************************************************************/
20 20
21 21 #include <QtDeclarative/qdeclarativeextensionplugin.h>
22 22 #include <QtDeclarative/qdeclarative.h>
23 23 #include "qchart.h"
24 24 #include "qaxiscategories.h"
25 25 #include "declarativechart.h"
26 26 #include "declarativexypoint.h"
27 27 #include "declarativelineseries.h"
28 28 #include "declarativesplineseries.h"
29 29 #include "declarativeareaseries.h"
30 30 #include "declarativescatterseries.h"
31 31 #include "declarativebarseries.h"
32 32 #include "declarativepieseries.h"
33 33 #include "declarativemodel.h"
34 34 #include <QPieModelMapper>
35 35 #include <QXYModelMapper>
36 36
37 37 QTCOMMERCIALCHART_BEGIN_NAMESPACE
38 38
39 39 class ChartQmlPlugin : public QDeclarativeExtensionPlugin
40 40 {
41 41 Q_OBJECT
42 42 public:
43 43 virtual void registerTypes(const char *uri)
44 44 {
45 45 Q_ASSERT(QLatin1String(uri) == QLatin1String("QtCommercial.Chart"));
46 46
47 47 qmlRegisterType<DeclarativeChart>(uri, 1, 0, "ChartView");
48 48 qmlRegisterUncreatableType<QAxis>(uri, 1, 0, "Axis",
49 49 QLatin1String("Trying to create uncreatable: Axis."));
50 50 //qmlRegisterType<DeclarativeAxisCategory>(uri, 1, 0, "AxisCategory");
51 51 qmlRegisterType<DeclarativeXyPoint>(uri, 1, 0, "XyPoint");
52 52 qmlRegisterType<DeclarativeScatterSeries>(uri, 1, 0, "ScatterSeries");
53 53 qmlRegisterType<DeclarativeLineSeries>(uri, 1, 0, "LineSeries");
54 54 qmlRegisterType<DeclarativeSplineSeries>(uri, 1, 0, "SplineSeries");
55 55 qmlRegisterType<DeclarativeAreaSeries>(uri, 1, 0, "AreaSeries");
56 56 qmlRegisterType<DeclarativeBarSeries>(uri, 1, 0, "BarSeries");
57 57 qmlRegisterType<DeclarativePieSeries>(uri, 1, 0, "PieSeries");
58 58 qmlRegisterType<QPieSlice>(uri, 1, 0, "PieSlice");
59 59 qmlRegisterType<DeclarativeTableModel>(uri, 1, 0, "ChartModel");
60 qmlRegisterType<DeclarativeTableModelRow>(uri, 1, 0, "ChartModelRow");
60 qmlRegisterType<DeclarativeTableModelElement>(uri, 1, 0, "ChartModelElement");
61 61 //qmlRegisterType<DeclarativePieMapping>(uri, 1, 0, "PieMapping");
62 62 //qmlRegisterType<QPieModelMapper>(uri, 1, 0, "PieModelMapper");
63 63 qmlRegisterUncreatableType<QPieModelMapper>(uri, 1, 0, "PieModelMapper",
64 64 QLatin1String("Trying to create uncreatable: PieModelMapper."));
65 65 qmlRegisterUncreatableType<QXYModelMapper>(uri, 1, 0, "XYModelMapper",
66 66 QLatin1String("Trying to create uncreatable: PieModelMapper."));
67 67
68 68 qmlRegisterType<DeclarativeBarModel>(uri, 1, 0, "BarModel");
69 69 qmlRegisterType<DeclarativeBarSet>(uri, 1, 0, "BarSet");
70 70 }
71 71 };
72 72
73 73 #include "plugin.moc"
74 74
75 75 QTCOMMERCIALCHART_END_NAMESPACE
76 76
77 77 QTCOMMERCIALCHART_USE_NAMESPACE
78 78
79 79 Q_EXPORT_PLUGIN2(qtcommercialchartqml, QT_PREPEND_NAMESPACE(ChartQmlPlugin))
General Comments 0
You need to be logged in to leave comments. Login now