@@ -0,0 +1,29 | |||||
|
1 | /*! | |||
|
2 | \example demos/qmlcustommodel | |||
|
3 | \title QML Custom Model | |||
|
4 | \subtitle | |||
|
5 | ||||
|
6 | This example shows how to use your own QAbstractItemModel derived data model as a data source for a ChartView. | |||
|
7 | \image demos_qmlcustommodel.png | |||
|
8 | ||||
|
9 | First we create a ChartView: | |||
|
10 | \snippet ../demos/qmlcustommodel/qml/qmlcustommodel/main.qml 1 | |||
|
11 | ||||
|
12 | Then our data model that contains the shares of top-5 car manufacturers in Finland for the last 5 years. The model | |||
|
13 | could be constructed from various sources depending on the use case, but here we use static data for the sake of | |||
|
14 | simplicity. Check customtablemodel.cpp, declarativemodel.cpp and plugin.cpp to see how to make your own | |||
|
15 | QAbstractItemModel accessible on QML. | |||
|
16 | \snippet ../demos/qmlcustommodel/qml/qmlcustommodel/main.qml 2 | |||
|
17 | ||||
|
18 | Then we create several series as children for the same ChartView. First a pie series that illustrates the shares of | |||
|
19 | the car manufacturers in Finland in 2011: | |||
|
20 | \snippet ../demos/qmlcustommodel/qml/qmlcustommodel/main.qml 3 | |||
|
21 | ||||
|
22 | And one line series for each manufacturer presenting the share between 2007-2011, for example this one is for | |||
|
23 | Volkswagen. The series is not visible by default; it is made visible when the user clicks on the Volkswagen slice | |||
|
24 | on the pie series: | |||
|
25 | \snippet ../demos/qmlcustommodel/qml/qmlcustommodel/main.qml 4 | |||
|
26 | ||||
|
27 | And finally a bar series that shows the share for all the other manufacturers between 2007-2011: | |||
|
28 | \snippet ../demos/qmlcustommodel/qml/qmlcustommodel/main.qml 5 | |||
|
29 | */ |
@@ -94,16 +94,4 void DeclarativeTableModel::append(QVariantList values) | |||||
94 | dataChanged(beginIndex, endIndex); |
|
94 | dataChanged(beginIndex, endIndex); | |
95 | } |
|
95 | } | |
96 |
|
96 | |||
97 | //void DeclarativeTableModel::appendPoint(QXYModelMapper *mapper, DeclarativeXyPoint *point) |
|
|||
98 | //{ |
|
|||
99 | // Q_UNUSED(mapper) |
|
|||
100 | // Q_UNUSED(point) |
|
|||
101 | // // TODO: XYModelMapper implementation has change, this code has to be updated. |
|
|||
102 | //// qDebug() << "DeclarativeTableModel::appendPoint:" << point; |
|
|||
103 | //// QVariantList values; |
|
|||
104 | //// values.insert(mapper->mapX(), point->x()); |
|
|||
105 | //// values.insert(mapper->mapY(), point->y()); |
|
|||
106 | //// append(values); |
|
|||
107 | //} |
|
|||
108 |
|
||||
109 | #include "moc_declarativemodel.cpp" |
|
97 | #include "moc_declarativemodel.cpp" |
@@ -49,7 +49,6 class DeclarativeTableModel : public CustomTableModel, public QDeclarativeParser | |||||
49 | public: |
|
49 | public: | |
50 | explicit DeclarativeTableModel(QObject *parent = 0); |
|
50 | explicit DeclarativeTableModel(QObject *parent = 0); | |
51 | QDeclarativeListProperty<QObject> modelChildren(); |
|
51 | QDeclarativeListProperty<QObject> modelChildren(); | |
52 | // void appendPoint(QXYModelMapper *mapper, DeclarativeXyPoint *point); |
|
|||
53 |
|
52 | |||
54 | public: // from QDeclarativeParserStatus |
|
53 | public: // from QDeclarativeParserStatus | |
55 | void classBegin(); |
|
54 | void classBegin(); |
@@ -24,21 +24,23 import QmlCustomModel 1.0 | |||||
24 |
|
24 | |||
25 | Rectangle { |
|
25 | Rectangle { | |
26 | width: parent.width |
|
26 | width: parent.width | |
27 |
height: parent.heigh |
|
27 | height: parent.heigh | |
28 |
|
28 | |||
|
29 | //![1] | |||
29 | ChartView { |
|
30 | ChartView { | |
30 | id: chartView |
|
31 | id: chartView | |
31 | title: "Top-5 car brand shares in Finland" |
|
32 | title: "Top-5 car brand shares in Finland" | |
32 | anchors.fill: parent |
|
33 | anchors.fill: parent | |
33 | theme: ChartView.ChartThemeLight |
|
|||
34 | axisX.max: 10 |
|
34 | axisX.max: 10 | |
35 | axisX.min: 0 |
|
35 | axisX.min: 0 | |
36 | axisY.max: 20 |
|
36 | axisY.max: 20 | |
37 | axisY.min: 0 |
|
37 | axisY.min: 0 | |
38 | animationOptions: ChartView.SeriesAnimations |
|
38 | animationOptions: ChartView.SeriesAnimations | |
39 | axisXLabels: [0, "2007", 1, "2008", 2, "2009", 3, "2010", 4, "2011", 5, "2012"] |
|
39 | axisXLabels: [0, "2007", 1, "2008", 2, "2009", 3, "2010", 4, "2011", 5, "2012"] | |
|
40 | // ... | |||
|
41 | //![1] | |||
40 |
|
42 | |||
41 | // For dynamic data we use a custom data model derived from QAbstractiItemModel |
|
43 | //![2] | |
42 |
|
|
44 | CustomModel { | |
43 | id: customModel |
|
45 | id: customModel | |
44 | CustomModelElement { values: [0, "Manufacturer", 0, 1, 2, 3, 4] } |
|
46 | CustomModelElement { values: [0, "Manufacturer", 0, 1, 2, 3, 4] } | |
@@ -49,7 +51,9 Rectangle { | |||||
49 | CustomModelElement { values: [5, "Volvo", 7.1, 6.7, 6.5, 6.3, 7.0] } |
|
51 | CustomModelElement { values: [5, "Volvo", 7.1, 6.7, 6.5, 6.3, 7.0] } | |
50 | CustomModelElement { values: [6, "Others", 57.7, 54.9, 48.7, 50.5, 51.7] } |
|
52 | CustomModelElement { values: [6, "Others", 57.7, 54.9, 48.7, 50.5, 51.7] } | |
51 | } |
|
53 | } | |
|
54 | //![2] | |||
52 |
|
55 | |||
|
56 | //![5] | |||
53 | BarSeries { |
|
57 | BarSeries { | |
54 | name: "Others" |
|
58 | name: "Others" | |
55 | barMargin: 0 |
|
59 | barMargin: 0 | |
@@ -61,7 +65,9 Rectangle { | |||||
61 | first: 2 |
|
65 | first: 2 | |
62 | } |
|
66 | } | |
63 | } |
|
67 | } | |
|
68 | //![5] | |||
64 |
|
69 | |||
|
70 | //![4] | |||
65 | LineSeries { |
|
71 | LineSeries { | |
66 | name: "Volkswagen" |
|
72 | name: "Volkswagen" | |
67 | visible: false |
|
73 | visible: false | |
@@ -72,6 +78,7 Rectangle { | |||||
72 | first: 2 |
|
78 | first: 2 | |
73 | } |
|
79 | } | |
74 | } |
|
80 | } | |
|
81 | //![4] | |||
75 |
|
82 | |||
76 | LineSeries { |
|
83 | LineSeries { | |
77 | name: "Toyota" |
|
84 | name: "Toyota" | |
@@ -117,6 +124,7 Rectangle { | |||||
117 | } |
|
124 | } | |
118 | } |
|
125 | } | |
119 |
|
126 | |||
|
127 | //![3] | |||
120 | PieSeries { |
|
128 | PieSeries { | |
121 | id: pieSeries |
|
129 | id: pieSeries | |
122 | size: 0.4 |
|
130 | size: 0.4 | |
@@ -134,6 +142,7 Rectangle { | |||||
134 | } |
|
142 | } | |
135 | } |
|
143 | } | |
136 | } |
|
144 | } | |
|
145 | //![3] | |||
137 |
|
146 | |||
138 | VPieModelMapper { |
|
147 | VPieModelMapper { | |
139 | series: pieSeries |
|
148 | series: pieSeries |
@@ -18,6 +18,7 | |||||
18 | <li><a href="demos-dynamicspline.html">Dynamic spline chart</a></li> |
|
18 | <li><a href="demos-dynamicspline.html">Dynamic spline chart</a></li> | |
19 | <li><a href="demos-qmlchart.html">Qml Basic Charts</a></li> |
|
19 | <li><a href="demos-qmlchart.html">Qml Basic Charts</a></li> | |
20 | <li><a href="demos-qmlweather.html">Qml Weather</a></li> |
|
20 | <li><a href="demos-qmlweather.html">Qml Weather</a></li> | |
|
21 | <li><a href="demos-qmlcustommodel.html">Qml Custom Model</a></li> | |||
21 | </ul> |
|
22 | </ul> | |
22 | </td> |
|
23 | </td> | |
23 | </tr> |
|
24 | </tr> |
General Comments 0
You need to be logged in to leave comments.
Login now