##// END OF EJS Templates
QML model mapper documentation for pie and xy
Tero Ahola -
r1516:267764825d23
parent child
Show More
@@ -1,248 +1,249
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 "qhbarmodelmapper.h"
21 #include "qhbarmodelmapper.h"
22
22
23 QTCOMMERCIALCHART_BEGIN_NAMESPACE
23 QTCOMMERCIALCHART_BEGIN_NAMESPACE
24
24
25 /*!
25 /*!
26 \class QHBarModelMapper
26 \class QHBarModelMapper
27 \brief Horizontal model mapper for bar series
27 \brief Horizontal model mapper for bar series
28 \mainclass
28 \mainclass
29
29
30 Model mappers allow you to use QAbstractItemModel derived models as a data source for a chart series.
30 Model mappers allow you to use QAbstractItemModel derived models as a data source for a chart series.
31 Horizontal model mapper is used to create a connection between QBarSeries and QAbstractItemModel derived model object.
31 Horizontal model mapper is used to create a connection between QBarSeries and QAbstractItemModel derived model object.
32 Model mapper maintains equal size of all the BarSets.
32 Model mapper maintains equal size of all the BarSets.
33 Adding/removing value from the BarSet causes the the same change in the rest of the BarSets added to the same series.
33 Adding/removing value from the BarSet causes the the same change in the rest of the BarSets added to the same series.
34 NOTE: used model has to support adding/removing rows/columns and modifying the data of the cells.
34 NOTE: used model has to support adding/removing rows/columns and modifying the data of the cells.
35 */
35 */
36 /*!
36 /*!
37 \qmlclass HBarModelMapper QHBarModelMapper
37 \qmlclass HBarModelMapper QHBarModelMapper
38 \mainclass
39
38
40 HBarModelMapper allows you to use your own QAbstractItemModel derived model with data in rows as a data source
39 HBarModelMapper allows you to use your own QAbstractItemModel derived model with data in rows as a data source
41 for any bar series. Adding/removing value from the BarSet causes the the same change in the rest of the BarSets
40 for any bar series. It is possible to use both QAbstractItemModel and bar series data API to manipulate data.
42 added to the same series. The following QML example would create a bar series with three bar sets (assuming the
41 HBarModelMapper keeps the series and the model in sync.
43 model has at least four rows). Each bar set would contain data starting from column 1. The name of a set would be
42
44 defined by the vertical header (of the row).
43 The following QML example would create a bar series with three bar sets (assuming the model has
44 at least four rows). Each bar set would contain data starting from column 1. The name of a set would be defined by
45 the vertical header (of the row).
45 \code
46 \code
46 BarSeries {
47 BarSeries {
47 HBarModelMapper {
48 HBarModelMapper {
48 model: myCustomModel // QAbstractItemModel derived implementation
49 model: myCustomModel // QAbstractItemModel derived implementation
49 firstBarSetRow: 1
50 firstBarSetRow: 1
50 lastBarSetRow: 3
51 lastBarSetRow: 3
51 firstColumn: 1
52 firstColumn: 1
52 }
53 }
53 }
54 }
54 \endcode
55 \endcode
55 */
56 */
56
57
57 /*!
58 /*!
58 \property QHBarModelMapper::series
59 \property QHBarModelMapper::series
59 \brief Defines the QPieSeries object that is used by the mapper.
60 \brief Defines the QPieSeries object that is used by the mapper.
60
61
61 All the data in the series is discarded when it is set to the mapper.
62 All the data in the series is discarded when it is set to the mapper.
62 When new series is specified the old series is disconnected (it preserves its data)
63 When new series is specified the old series is disconnected (it preserves its data)
63 */
64 */
64 /*!
65 /*!
65 \qmlproperty BarSeries HBarModelMapper::series
66 \qmlproperty BarSeries HBarModelMapper::series
66 Defines the BarSeries based object that is used by the mapper. All the data in the series is discarded when it is
67 Defines the BarSeries based object that is used by the mapper. All the data in the series is discarded when it is
67 set to the mapper. When new series is specified the old series is disconnected (it preserves its data).
68 set to the mapper. When new series is specified the old series is disconnected (it preserves its data).
68 */
69 */
69
70
70 /*!
71 /*!
71 \property QHBarModelMapper::model
72 \property QHBarModelMapper::model
72 \brief Defines the model that is used by the mapper.
73 \brief Defines the model that is used by the mapper.
73 */
74 */
74 /*!
75 /*!
75 \qmlproperty Model HBarModelMapper::model
76 \qmlproperty SomeModel HBarModelMapper::model
76 The QAbstractItemModel based model that is used by the mapper. You need to implement the model and expose it to
77 The QAbstractItemModel based model that is used by the mapper. You need to implement the model and expose it to
77 QML as shown in \l {QML Custom Model} demo application. NOTE: the model has to support adding/removing rows/columns
78 QML as shown in \l {QML Custom Model} demo application. NOTE: the model has to support adding/removing rows/columns
78 and modifying the data of the cells.
79 and modifying the data of the cells.
79 */
80 */
80
81
81 /*!
82 /*!
82 \property QHBarModelMapper::firstBarSetRow
83 \property QHBarModelMapper::firstBarSetRow
83 \brief Defines which column of the model is used as the data source for the first bar set
84 \brief Defines which column of the model is used as the data source for the first bar set
84 Default value is: -1 (invalid mapping)
85 Default value is: -1 (invalid mapping)
85 */
86 */
86 /*!
87 /*!
87 \qmlproperty int HBarModelMapper::firstBarSetRow
88 \qmlproperty int HBarModelMapper::firstBarSetRow
88 Defines which column of the model is used as the data source for the first bar set. The default value is -1
89 Defines which column of the model is used as the data source for the first bar set. The default value is -1
89 (invalid mapping).
90 (invalid mapping).
90 */
91 */
91
92
92 /*!
93 /*!
93 \property QHBarModelMapper::lastBarSetRow
94 \property QHBarModelMapper::lastBarSetRow
94 \brief Defines which column of the model is used as the data source for the last bar set
95 \brief Defines which column of the model is used as the data source for the last bar set
95 Default value is: -1 (invalid mapping)
96 Default value is: -1 (invalid mapping)
96 */
97 */
97 /*!
98 /*!
98 \qmlproperty int HBarModelMapper::lastBarSetRow
99 \qmlproperty int HBarModelMapper::lastBarSetRow
99 Defines which column of the model is used as the data source for the last bar set. The default value is -1
100 Defines which column of the model is used as the data source for the last bar set. The default value is -1
100 (invalid mapping).
101 (invalid mapping).
101 */
102 */
102
103
103 /*!
104 /*!
104 \property QHBarModelMapper::firstColumn
105 \property QHBarModelMapper::firstColumn
105 \brief Defines which column of the model contains the first values of the QBarSets in the series.
106 \brief Defines which column of the model contains the first values of the QBarSets in the series.
106 Minimal and default value is: 0
107 Minimal and default value is: 0
107 */
108 */
108 /*!
109 /*!
109 \qmlproperty int HBarModelMapper::firstColumn
110 \qmlproperty int HBarModelMapper::firstColumn
110 Defines which column of the model contains the first values of the QBarSets in the series.
111 Defines which column of the model contains the first values of the QBarSets in the series.
111 The default value is 0.
112 The default value is 0.
112 */
113 */
113
114
114 /*!
115 /*!
115 \property QHBarModelMapper::columnCount
116 \property QHBarModelMapper::columnCount
116 \brief Defines the number of columns of the model that are mapped as the data for QBarSeries
117 \brief Defines the number of columns of the model that are mapped as the data for QBarSeries
117 Minimal and default value is: -1 (count limited by the number of columns in the model)
118 Minimal and default value is: -1 (count limited by the number of columns in the model)
118 */
119 */
119 /*!
120 /*!
120 \qmlproperty int HBarModelMapper::columnCount
121 \qmlproperty int HBarModelMapper::columnCount
121 Defines the number of columns of the model that are mapped as the data for QBarSeries. The default value is
122 Defines the number of columns of the model that are mapped as the data for QBarSeries. The default value is
122 -1 (count limited by the number of columns in the model)
123 -1 (count limited by the number of columns in the model)
123 */
124 */
124
125
125 /*!
126 /*!
126 \fn void QHBarModelMapper::seriesReplaced()
127 \fn void QHBarModelMapper::seriesReplaced()
127
128
128 Emitted when the series to which mapper is connected to has changed.
129 Emitted when the series to which mapper is connected to has changed.
129 */
130 */
130
131
131 /*!
132 /*!
132 \fn void QHBarModelMapper::modelReplaced()
133 \fn void QHBarModelMapper::modelReplaced()
133
134
134 Emitted when the model to which mapper is connected to has changed.
135 Emitted when the model to which mapper is connected to has changed.
135 */
136 */
136
137
137 /*!
138 /*!
138 \fn void QHBarModelMapper::firstBarSetRowChanged()
139 \fn void QHBarModelMapper::firstBarSetRowChanged()
139
140
140 Emitted when the firstBarSetRow has changed.
141 Emitted when the firstBarSetRow has changed.
141 */
142 */
142
143
143 /*!
144 /*!
144 \fn void QHBarModelMapper::lastBarSetRowChanged()
145 \fn void QHBarModelMapper::lastBarSetRowChanged()
145
146
146 Emitted when the lastBarSetRow has changed.
147 Emitted when the lastBarSetRow has changed.
147 */
148 */
148
149
149 /*!
150 /*!
150 \fn void QHBarModelMapper::firstColumnChanged()
151 \fn void QHBarModelMapper::firstColumnChanged()
151 Emitted when the firstColumn has changed.
152 Emitted when the firstColumn has changed.
152 */
153 */
153
154
154 /*!
155 /*!
155 \fn void QHBarModelMapper::columnCountChanged()
156 \fn void QHBarModelMapper::columnCountChanged()
156 Emitted when the columnCount has changed.
157 Emitted when the columnCount has changed.
157 */
158 */
158
159
159 /*!
160 /*!
160 Constructs a mapper object which is a child of \a parent.
161 Constructs a mapper object which is a child of \a parent.
161 */
162 */
162 QHBarModelMapper::QHBarModelMapper(QObject *parent) :
163 QHBarModelMapper::QHBarModelMapper(QObject *parent) :
163 QBarModelMapper(parent)
164 QBarModelMapper(parent)
164 {
165 {
165 QBarModelMapper::setOrientation(Qt::Horizontal);
166 QBarModelMapper::setOrientation(Qt::Horizontal);
166 }
167 }
167
168
168 QAbstractItemModel* QHBarModelMapper::model() const
169 QAbstractItemModel* QHBarModelMapper::model() const
169 {
170 {
170 return QBarModelMapper::model();
171 return QBarModelMapper::model();
171 }
172 }
172
173
173 void QHBarModelMapper::setModel(QAbstractItemModel *model)
174 void QHBarModelMapper::setModel(QAbstractItemModel *model)
174 {
175 {
175 if (model != QBarModelMapper::model()) {
176 if (model != QBarModelMapper::model()) {
176 QBarModelMapper::setModel(model);
177 QBarModelMapper::setModel(model);
177 emit modelReplaced();
178 emit modelReplaced();
178 }
179 }
179 }
180 }
180
181
181 QBarSeries* QHBarModelMapper::series() const
182 QBarSeries* QHBarModelMapper::series() const
182 {
183 {
183 return QBarModelMapper::series();
184 return QBarModelMapper::series();
184 }
185 }
185
186
186 void QHBarModelMapper::setSeries(QBarSeries *series)
187 void QHBarModelMapper::setSeries(QBarSeries *series)
187 {
188 {
188 if (series != QBarModelMapper::series()) {
189 if (series != QBarModelMapper::series()) {
189 QBarModelMapper::setSeries(series);
190 QBarModelMapper::setSeries(series);
190 emit seriesReplaced();
191 emit seriesReplaced();
191 }
192 }
192 }
193 }
193
194
194 int QHBarModelMapper::firstBarSetRow() const
195 int QHBarModelMapper::firstBarSetRow() const
195 {
196 {
196 return QBarModelMapper::firstBarSetSection();
197 return QBarModelMapper::firstBarSetSection();
197 }
198 }
198
199
199 void QHBarModelMapper::setFirstBarSetRow(int firstBarSetRow)
200 void QHBarModelMapper::setFirstBarSetRow(int firstBarSetRow)
200 {
201 {
201 if (firstBarSetRow != firstBarSetSection()) {
202 if (firstBarSetRow != firstBarSetSection()) {
202 QBarModelMapper::setFirstBarSetSection(firstBarSetRow);
203 QBarModelMapper::setFirstBarSetSection(firstBarSetRow);
203 emit firstBarSetRowChanged();
204 emit firstBarSetRowChanged();
204 }
205 }
205 }
206 }
206
207
207 int QHBarModelMapper::lastBarSetRow() const
208 int QHBarModelMapper::lastBarSetRow() const
208 {
209 {
209 return QBarModelMapper::lastBarSetSection();
210 return QBarModelMapper::lastBarSetSection();
210 }
211 }
211
212
212 void QHBarModelMapper::setLastBarSetRow(int lastBarSetRow)
213 void QHBarModelMapper::setLastBarSetRow(int lastBarSetRow)
213 {
214 {
214 if (lastBarSetRow != lastBarSetSection()) {
215 if (lastBarSetRow != lastBarSetSection()) {
215 QBarModelMapper::setLastBarSetSection(lastBarSetRow);
216 QBarModelMapper::setLastBarSetSection(lastBarSetRow);
216 emit lastBarSetRowChanged();
217 emit lastBarSetRowChanged();
217 }
218 }
218 }
219 }
219
220
220 int QHBarModelMapper::firstColumn() const
221 int QHBarModelMapper::firstColumn() const
221 {
222 {
222 return QBarModelMapper::first();
223 return QBarModelMapper::first();
223 }
224 }
224
225
225 void QHBarModelMapper::setFirstColumn(int firstColumn)
226 void QHBarModelMapper::setFirstColumn(int firstColumn)
226 {
227 {
227 if (firstColumn != first()) {
228 if (firstColumn != first()) {
228 QBarModelMapper::setFirst(firstColumn);
229 QBarModelMapper::setFirst(firstColumn);
229 emit firstColumnChanged();
230 emit firstColumnChanged();
230 }
231 }
231 }
232 }
232
233
233 int QHBarModelMapper::columnCount() const
234 int QHBarModelMapper::columnCount() const
234 {
235 {
235 return QBarModelMapper::count();
236 return QBarModelMapper::count();
236 }
237 }
237
238
238 void QHBarModelMapper::setColumnCount(int columnCount)
239 void QHBarModelMapper::setColumnCount(int columnCount)
239 {
240 {
240 if (columnCount != count()) {
241 if (columnCount != count()) {
241 QBarModelMapper::setCount(columnCount);
242 QBarModelMapper::setCount(columnCount);
242 emit firstColumnChanged();
243 emit firstColumnChanged();
243 }
244 }
244 }
245 }
245
246
246 #include "moc_qhbarmodelmapper.cpp"
247 #include "moc_qhbarmodelmapper.cpp"
247
248
248 QTCOMMERCIALCHART_END_NAMESPACE
249 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,246 +1,248
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 "qvbarmodelmapper.h"
21 #include "qvbarmodelmapper.h"
22
22
23 QTCOMMERCIALCHART_BEGIN_NAMESPACE
23 QTCOMMERCIALCHART_BEGIN_NAMESPACE
24
24
25 /*!
25 /*!
26 \class QVBarModelMapper
26 \class QVBarModelMapper
27 \brief Vertical model mapper for bar series
27 \brief Vertical model mapper for bar series
28 \mainclass
28 \mainclass
29
29
30 Model mappers allow you to use QAbstractItemModel derived models as a data source for a chart series.
30 Model mappers allow you to use QAbstractItemModel derived models as a data source for a chart series.
31 Vertical model mapper is used to create a connection between QBarSeries and QAbstractItemModel derived model object.
31 Vertical model mapper is used to create a connection between QBarSeries and QAbstractItemModel derived model object.
32 Model mapper maintains equal size of all the BarSets.
32 Model mapper maintains equal size of all the BarSets.
33 Adding/removing value from the BarSet causes the the same change in the rest of the BarSets added to the same series.
33 Adding/removing value from the BarSet causes the the same change in the rest of the BarSets added to the same series.
34 NOTE: used model has to support adding/removing rows/columns and modifying the data of the cells.
34 NOTE: used model has to support adding/removing rows/columns and modifying the data of the cells.
35 */
35 */
36 /*!
36 /*!
37 \qmlclass VBarModelMapper
37 \qmlclass VBarModelMapper
38 \mainclass
38 \mainclass
39
39
40 VBarModelMapper allows you to use your own QAbstractItemModel derived model with data in columns as a data source
40 VBarModelMapper allows you to use your own QAbstractItemModel derived model with data in columns as a data source
41 for any bar series. Adding/removing value from the BarSet causes the the same change in the rest of the BarSets
41 for any bar series. It is possible to use both QAbstractItemModel and bar series data API to manipulate data.
42 added to the same series. The following QML example would create a bar series with three bar sets (assuming the
42 VBarModelMapper keeps the series and the model in sync.
43
44 The following QML example would create a bar series with three bar sets (assuming the
43 model has at least four columns). Each bar set would contain data starting from row 1. The name of a set would be
45 model has at least four columns). Each bar set would contain data starting from row 1. The name of a set would be
44 defined by the horizontal header (of the column).
46 defined by the horizontal header (of the column).
45 \code
47 \code
46 GroupedBarSeries {
48 GroupedBarSeries {
47 VBarModelMapper {
49 VBarModelMapper {
48 model: myCustomModel // QAbstractItemModel derived implementation
50 model: myCustomModel // QAbstractItemModel derived implementation
49 firstBarSetColumn: 1
51 firstBarSetColumn: 1
50 lastBarSetColumn: 3
52 lastBarSetColumn: 3
51 firstRow: 1
53 firstRow: 1
52 }
54 }
53 }
55 }
54 \endcode
56 \endcode
55 */
57 */
56
58
57 /*!
59 /*!
58 \property QVBarModelMapper::series
60 \property QVBarModelMapper::series
59 \brief Defines the QPieSeries object that is used by the mapper.
61 \brief Defines the QPieSeries object that is used by the mapper.
60
62
61 All the data in the series is discarded when it is set to the mapper.
63 All the data in the series is discarded when it is set to the mapper.
62 When new series is specified the old series is disconnected (it preserves its data)
64 When new series is specified the old series is disconnected (it preserves its data)
63 */
65 */
64 /*!
66 /*!
65 \qmlproperty BarSeries VBarModelMapper::series
67 \qmlproperty BarSeries VBarModelMapper::series
66 Defines the BarSeries based object that is used by the mapper. All the data in the series is discarded when it is
68 Defines the BarSeries based object that is used by the mapper. All the data in the series is discarded when it is
67 set to the mapper. When new series is specified the old series is disconnected (it preserves its data).
69 set to the mapper. When new series is specified the old series is disconnected (it preserves its data).
68 */
70 */
69
71
70 /*!
72 /*!
71 \property QVBarModelMapper::model
73 \property QVBarModelMapper::model
72 \brief Defines the model that is used by the mapper.
74 \brief Defines the model that is used by the mapper.
73 */
75 */
74 /*!
76 /*!
75 \qmlproperty Model VBarModelMapper::model
77 \qmlproperty SomeModel VBarModelMapper::model
76 The QAbstractItemModel based model that is used by the mapper. You need to implement the model and expose it to
78 The QAbstractItemModel based model that is used by the mapper. You need to implement the model and expose it to
77 QML as shown in \l {QML Custom Model} demo application. NOTE: the model has to support adding/removing rows/columns
79 QML as shown in \l {QML Custom Model} demo application. NOTE: the model has to support adding/removing rows/columns
78 and modifying the data of the cells.
80 and modifying the data of the cells.
79 */
81 */
80
82
81 /*!
83 /*!
82 \property QVBarModelMapper::firstBarSetColumn
84 \property QVBarModelMapper::firstBarSetColumn
83 \brief Defines which column of the model is used as the data source for the first bar set
85 \brief Defines which column of the model is used as the data source for the first bar set
84 Default value is: -1 (invalid mapping)
86 Default value is: -1 (invalid mapping)
85 */
87 */
86 /*!
88 /*!
87 \qmlproperty int VBarModelMapper::firstBarSetColumn
89 \qmlproperty int VBarModelMapper::firstBarSetColumn
88 Defines which column of the model is used as the data source for the first bar set. Default value
90 Defines which column of the model is used as the data source for the first bar set. Default value
89 is: -1 (invalid mapping).
91 is: -1 (invalid mapping).
90 */
92 */
91
93
92 /*!
94 /*!
93 \property QVBarModelMapper::lastBarSetColumn
95 \property QVBarModelMapper::lastBarSetColumn
94 \brief Defines which column of the model is used as the data source for the last bar set
96 \brief Defines which column of the model is used as the data source for the last bar set
95 Default value is: -1 (invalid mapping)
97 Default value is: -1 (invalid mapping)
96 */
98 */
97 /*!
99 /*!
98 \qmlproperty int VBarModelMapper::lastBarSetColumn
100 \qmlproperty int VBarModelMapper::lastBarSetColumn
99 Defines which column of the model is used as the data source for the last bar set. Default
101 Defines which column of the model is used as the data source for the last bar set. Default
100 value is: -1 (invalid mapping).
102 value is: -1 (invalid mapping).
101 */
103 */
102
104
103 /*!
105 /*!
104 \property QVBarModelMapper::firstRow
106 \property QVBarModelMapper::firstRow
105 \brief Defines which row of the model contains the first values of the QBarSets in the series.
107 \brief Defines which row of the model contains the first values of the QBarSets in the series.
106 Minimal and default value is: 0
108 Minimal and default value is: 0
107 */
109 */
108 /*!
110 /*!
109 \qmlproperty int VBarModelMapper::firstRow
111 \qmlproperty int VBarModelMapper::firstRow
110 Defines which row of the model contains the first values of the QBarSets in the series.
112 Defines which row of the model contains the first values of the QBarSets in the series.
111 The default value is 0.
113 The default value is 0.
112 */
114 */
113
115
114 /*!
116 /*!
115 \property QVBarModelMapper::rowCount
117 \property QVBarModelMapper::rowCount
116 \brief Defines the number of rows of the model that are mapped as the data for QBarSeries
118 \brief Defines the number of rows of the model that are mapped as the data for QBarSeries
117 Minimal and default value is: -1 (count limited by the number of rows in the model)
119 Minimal and default value is: -1 (count limited by the number of rows in the model)
118 */
120 */
119 /*!
121 /*!
120 \qmlproperty int VBarModelMapper::rowCount
122 \qmlproperty int VBarModelMapper::rowCount
121 Defines the number of rows of the model that are mapped as the data for QBarSeries. The default value is
123 Defines the number of rows of the model that are mapped as the data for QBarSeries. The default value is
122 -1 (count limited by the number of rows in the model)
124 -1 (count limited by the number of rows in the model)
123 */
125 */
124
126
125 /*!
127 /*!
126 \fn void QVBarModelMapper::seriesReplaced()
128 \fn void QVBarModelMapper::seriesReplaced()
127
129
128 Emitted when the series to which mapper is connected to has changed.
130 Emitted when the series to which mapper is connected to has changed.
129 */
131 */
130
132
131 /*!
133 /*!
132 \fn void QVBarModelMapper::modelReplaced()
134 \fn void QVBarModelMapper::modelReplaced()
133
135
134 Emitted when the model to which mapper is connected to has changed.
136 Emitted when the model to which mapper is connected to has changed.
135 */
137 */
136
138
137 /*!
139 /*!
138 \fn void QVBarModelMapper::firstBarSetColumnChanged()
140 \fn void QVBarModelMapper::firstBarSetColumnChanged()
139 Emitted when the firstBarSetColumn has changed.
141 Emitted when the firstBarSetColumn has changed.
140 */
142 */
141
143
142 /*!
144 /*!
143 \fn void QVBarModelMapper::lastBarSetColumnChanged()
145 \fn void QVBarModelMapper::lastBarSetColumnChanged()
144 Emitted when the lastBarSetColumn has changed.
146 Emitted when the lastBarSetColumn has changed.
145 */
147 */
146
148
147 /*!
149 /*!
148 \fn void QVBarModelMapper::firstRowChanged()
150 \fn void QVBarModelMapper::firstRowChanged()
149 Emitted when the firstRow has changed.
151 Emitted when the firstRow has changed.
150 */
152 */
151
153
152 /*!
154 /*!
153 \fn void QVBarModelMapper::rowCountChanged()
155 \fn void QVBarModelMapper::rowCountChanged()
154 Emitted when the rowCount has changed.
156 Emitted when the rowCount has changed.
155 */
157 */
156
158
157 /*!
159 /*!
158 Constructs a mapper object which is a child of \a parent.
160 Constructs a mapper object which is a child of \a parent.
159 */
161 */
160 QVBarModelMapper::QVBarModelMapper(QObject *parent) :
162 QVBarModelMapper::QVBarModelMapper(QObject *parent) :
161 QBarModelMapper(parent)
163 QBarModelMapper(parent)
162 {
164 {
163 QBarModelMapper::setOrientation(Qt::Vertical);
165 QBarModelMapper::setOrientation(Qt::Vertical);
164 }
166 }
165
167
166 QAbstractItemModel* QVBarModelMapper::model() const
168 QAbstractItemModel* QVBarModelMapper::model() const
167 {
169 {
168 return QBarModelMapper::model();
170 return QBarModelMapper::model();
169 }
171 }
170
172
171 void QVBarModelMapper::setModel(QAbstractItemModel *model)
173 void QVBarModelMapper::setModel(QAbstractItemModel *model)
172 {
174 {
173 if (model != QBarModelMapper::model()) {
175 if (model != QBarModelMapper::model()) {
174 QBarModelMapper::setModel(model);
176 QBarModelMapper::setModel(model);
175 emit modelReplaced();
177 emit modelReplaced();
176 }
178 }
177 }
179 }
178
180
179 QBarSeries* QVBarModelMapper::series() const
181 QBarSeries* QVBarModelMapper::series() const
180 {
182 {
181 return QBarModelMapper::series();
183 return QBarModelMapper::series();
182 }
184 }
183
185
184 void QVBarModelMapper::setSeries(QBarSeries *series)
186 void QVBarModelMapper::setSeries(QBarSeries *series)
185 {
187 {
186 if (series != QBarModelMapper::series()) {
188 if (series != QBarModelMapper::series()) {
187 QBarModelMapper::setSeries(series);
189 QBarModelMapper::setSeries(series);
188 emit seriesReplaced();
190 emit seriesReplaced();
189 }
191 }
190 }
192 }
191
193
192 int QVBarModelMapper::firstBarSetColumn() const
194 int QVBarModelMapper::firstBarSetColumn() const
193 {
195 {
194 return QBarModelMapper::firstBarSetSection();
196 return QBarModelMapper::firstBarSetSection();
195 }
197 }
196
198
197 void QVBarModelMapper::setFirstBarSetColumn(int firstBarSetColumn)
199 void QVBarModelMapper::setFirstBarSetColumn(int firstBarSetColumn)
198 {
200 {
199 if (firstBarSetColumn != firstBarSetSection()) {
201 if (firstBarSetColumn != firstBarSetSection()) {
200 QBarModelMapper::setFirstBarSetSection(firstBarSetColumn);
202 QBarModelMapper::setFirstBarSetSection(firstBarSetColumn);
201 emit firstBarSetColumnChanged();
203 emit firstBarSetColumnChanged();
202 }
204 }
203 }
205 }
204
206
205 int QVBarModelMapper::lastBarSetColumn() const
207 int QVBarModelMapper::lastBarSetColumn() const
206 {
208 {
207 return QBarModelMapper::lastBarSetSection();
209 return QBarModelMapper::lastBarSetSection();
208 }
210 }
209
211
210 void QVBarModelMapper::setLastBarSetColumn(int lastBarSetColumn)
212 void QVBarModelMapper::setLastBarSetColumn(int lastBarSetColumn)
211 {
213 {
212 if (lastBarSetColumn != lastBarSetSection()) {
214 if (lastBarSetColumn != lastBarSetSection()) {
213 QBarModelMapper::setLastBarSetSection(lastBarSetColumn);
215 QBarModelMapper::setLastBarSetSection(lastBarSetColumn);
214 emit lastBarSetColumnChanged();
216 emit lastBarSetColumnChanged();
215 }
217 }
216 }
218 }
217
219
218 int QVBarModelMapper::firstRow() const
220 int QVBarModelMapper::firstRow() const
219 {
221 {
220 return QBarModelMapper::first();
222 return QBarModelMapper::first();
221 }
223 }
222
224
223 void QVBarModelMapper::setFirstRow(int firstRow)
225 void QVBarModelMapper::setFirstRow(int firstRow)
224 {
226 {
225 if (firstRow != first()) {
227 if (firstRow != first()) {
226 QBarModelMapper::setFirst(firstRow);
228 QBarModelMapper::setFirst(firstRow);
227 emit firstRowChanged();
229 emit firstRowChanged();
228 }
230 }
229 }
231 }
230
232
231 int QVBarModelMapper::rowCount() const
233 int QVBarModelMapper::rowCount() const
232 {
234 {
233 return QBarModelMapper::count();
235 return QBarModelMapper::count();
234 }
236 }
235
237
236 void QVBarModelMapper::setRowCount(int rowCount)
238 void QVBarModelMapper::setRowCount(int rowCount)
237 {
239 {
238 if (rowCount != count()) {
240 if (rowCount != count()) {
239 QBarModelMapper::setCount(rowCount);
241 QBarModelMapper::setCount(rowCount);
240 emit firstRowChanged();
242 emit firstRowChanged();
241 }
243 }
242 }
244 }
243
245
244 #include "moc_qvbarmodelmapper.cpp"
246 #include "moc_qvbarmodelmapper.cpp"
245
247
246 QTCOMMERCIALCHART_END_NAMESPACE
248 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,221 +1,257
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 "qhpiemodelmapper.h"
21 #include "qhpiemodelmapper.h"
22
22
23 QTCOMMERCIALCHART_BEGIN_NAMESPACE
23 QTCOMMERCIALCHART_BEGIN_NAMESPACE
24
24
25 /*!
25 /*!
26 \class QHPieModelMapper
26 \class QHPieModelMapper
27 \mainclass
27 \mainclass
28
28
29 Model mappers allow you to use QAbstractItemModel derived models as a data source for a chart series.
29 Model mappers allow you to use QAbstractItemModel derived models as a data source for a chart series.
30 Horizontal model mapper is used to create a connection between QPieSeries and QAbstractItemModel derived model object that keeps the consecutive pie slices data in rows.
30 Horizontal model mapper is used to create a connection between QPieSeries and QAbstractItemModel derived model object that keeps the consecutive pie slices data in rows.
31 It is possible to use both QAbstractItemModel and QPieSeries model API. QHPieModelMapper makes sure that Pie and the model are kept in sync.
31 It is possible to use both QAbstractItemModel and QPieSeries model API. QHPieModelMapper makes sure that Pie and the model are kept in sync.
32 NOTE: used model has to support adding/removing rows/columns and modifying the data of the cells.
32 NOTE: used model has to support adding/removing rows/columns and modifying the data of the cells.
33 */
33 */
34 /*!
35 \qmlclass HPieModelMapper QHPieModelMapper
36
37 HPieModelMapper allows you to use your own QAbstractItemModel derived model with data in rows as a data source
38 for a pie series. It is possible to use both QAbstractItemModel and PieSeries data API to manipulate data.
39 HPieModelMapper keeps the Pie and the model in sync.
40
41 The following QML example would create a pie series with four slices (assuming the model has
42 at least five columns). Each slice would contain a label from row 1 and a value from row 2.
43 \code
44 HPieModelMapper {
45 series: pieSeries
46 model: customModel
47 labelsRow: 1
48 valuesRow: 2
49 firstColumn: 1
50 columnCount: 4
51 }
52 \endcode
53 */
34
54
35 /*!
55 /*!
36 \property QHPieModelMapper::series
56 \property QHPieModelMapper::series
37 \brief Defines the QPieSeries object that is used by the mapper.
57 \brief Defines the QPieSeries object that is used by the mapper.
38
58
39 All the data in the series is discarded when it is set to the mapper.
59 All the data in the series is discarded when it is set to the mapper.
40 When new series is specified the old series is disconnected (it preserves its data)
60 When new series is specified the old series is disconnected (it preserves its data)
41 */
61 */
62 /*!
63 \qmlproperty PieSeries HPieModelMapper::series
64 Defines the PieSeries object that is used by the mapper. If you define the mapper element as a child for a
65 PieSeries, leave this property undefined. All the data in the series is discarded when it is set to the mapper.
66 When new series is specified the old series is disconnected (it preserves its data).
67 */
42
68
43 /*!
69 /*!
44 \property QHPieModelMapper::model
70 \property QHPieModelMapper::model
45 \brief Defines the model that is used by the mapper.
71 \brief Defines the model that is used by the mapper.
46 */
72 */
73 /*!
74 \qmlproperty SomeModel HPieModelMapper::model
75 The QAbstractItemModel based model that is used by the mapper. You need to implement the model and expose it to
76 QML as shown in \l {QML Custom Model} demo application. NOTE: the model has to support adding/removing rows/columns
77 and modifying the data of the cells.
78 */
47
79
48 /*!
80 /*!
49 \property QHPieModelMapper::valuesRow
81 \property QHPieModelMapper::valuesRow
50 \brief Defines which row of the model is kept in sync with the values of the pie's slices
82 \brief Defines which row of the model is kept in sync with the values of the pie's slices
51
52 Default value is: -1 (invalid mapping)
83 Default value is: -1 (invalid mapping)
53 */
84 */
85 /*!
86 \qmlproperty int HPieModelMapper::valuesRow
87 Defines which row of the model is kept in sync with the values of the pie's slices. Default value is: -1 (invalid
88 mapping).
89 */
54
90
55 /*!
91 /*!
56 \property QHPieModelMapper::labelsRow
92 \property QHPieModelMapper::labelsRow
57 \brief Defines which row of the model is kept in sync with the labels of the pie's slices
93 \brief Defines which row of the model is kept in sync with the labels of the pie's slices
58
94 Default value is: -1 (invalid mapping)
95 */
96 /*!
97 \qmlproperty int HPieModelMapper::labelsRow
98 Defines which row of the model is kept in sync with the labels of the pie's slices
59 Default value is: -1 (invalid mapping)
99 Default value is: -1 (invalid mapping)
60 */
100 */
61
101
62 /*!
102 /*!
63 \property QHPieModelMapper::firstColumn
103 \property QHPieModelMapper::firstColumn
64 \brief Defines which column of the model contains the first slice value.
104 \brief Defines which column of the model contains the first slice value.
65 Minimal and default value is: 0
105 Minimal and default value is: 0
66 */
106 */
67 /*!
107 /*!
68 \qmlproperty int QHPieModelMapper::firstColumn
108 \qmlproperty int HPieModelMapper::firstColumn
69 Defines which column of the model contains the first slice value.
109 Defines which column of the model contains the first slice value.
70 The default value is 0.
110 The default value is 0.
71 */
111 */
72
112
73 /*!
113 /*!
74 \property QHPieModelMapper::columnCount
114 \property QHPieModelMapper::columnCount
75 \brief Defines the number of columns of the model that are mapped as the data for QPieSeries
115 \brief Defines the number of columns of the model that are mapped as the data for QPieSeries
76 Minimal and default value is: -1 (count limited by the number of columns in the model)
116 Minimal and default value is: -1 (count limited by the number of columns in the model)
77 */
117 */
78 /*!
118 /*!
79 \qmlproperty int QHPieModelMapper::columnCount
119 \qmlproperty int HPieModelMapper::columnCount
80 Defines the number of columns of the model that are mapped as the data for QPieSeries. The default value is
120 Defines the number of columns of the model that are mapped as the data for QPieSeries. The default value is
81 -1 (count limited by the number of columns in the model)
121 -1 (count limited by the number of columns in the model)
82 */
122 */
83
123
84 /*!
124 /*!
85 \fn void QHPieModelMapper::seriesReplaced()
125 \fn void QHPieModelMapper::seriesReplaced()
86
87 Emitted when the series to which mapper is connected to has changed.
126 Emitted when the series to which mapper is connected to has changed.
88 */
127 */
89
128
90 /*!
129 /*!
91 \fn void QHPieModelMapper::modelReplaced()
130 \fn void QHPieModelMapper::modelReplaced()
92
93 Emitted when the model to which mapper is connected to has changed.
131 Emitted when the model to which mapper is connected to has changed.
94 */
132 */
95
133
96 /*!
134 /*!
97 \fn void QHPieModelMapper::valuesRowChanged()
135 \fn void QHPieModelMapper::valuesRowChanged()
98
99 Emitted when the valuesRow has changed.
136 Emitted when the valuesRow has changed.
100 */
137 */
101
138
102 /*!
139 /*!
103 \fn void QHPieModelMapper::labelsRowChanged()
140 \fn void QHPieModelMapper::labelsRowChanged()
104
105 Emitted when the labelsRow has changed.
141 Emitted when the labelsRow has changed.
106 */
142 */
107
143
108 /*!
144 /*!
109 \fn void QHPieModelMapper::firstColumnChanged()
145 \fn void QHPieModelMapper::firstColumnChanged()
110 Emitted when the firstColumn has changed.
146 Emitted when the firstColumn has changed.
111 */
147 */
112
148
113 /*!
149 /*!
114 \fn void QHPieModelMapper::columnCountChanged()
150 \fn void QHPieModelMapper::columnCountChanged()
115 Emitted when the columnCount has changed.
151 Emitted when the columnCount has changed.
116 */
152 */
117
153
118 /*!
154 /*!
119 Constructs a mapper object which is a child of \a parent.
155 Constructs a mapper object which is a child of \a parent.
120 */
156 */
121 QHPieModelMapper::QHPieModelMapper(QObject *parent) :
157 QHPieModelMapper::QHPieModelMapper(QObject *parent) :
122 QPieModelMapper(parent)
158 QPieModelMapper(parent)
123 {
159 {
124 setOrientation(Qt::Horizontal);
160 setOrientation(Qt::Horizontal);
125 }
161 }
126
162
127 QAbstractItemModel* QHPieModelMapper::model() const
163 QAbstractItemModel* QHPieModelMapper::model() const
128 {
164 {
129 return QPieModelMapper::model();
165 return QPieModelMapper::model();
130 }
166 }
131
167
132 void QHPieModelMapper::setModel(QAbstractItemModel *model)
168 void QHPieModelMapper::setModel(QAbstractItemModel *model)
133 {
169 {
134 if (model != QPieModelMapper::model()) {
170 if (model != QPieModelMapper::model()) {
135 QPieModelMapper::setModel(model);
171 QPieModelMapper::setModel(model);
136 emit modelReplaced();
172 emit modelReplaced();
137 }
173 }
138 }
174 }
139
175
140 QPieSeries* QHPieModelMapper::series() const
176 QPieSeries* QHPieModelMapper::series() const
141 {
177 {
142 return QPieModelMapper::series();
178 return QPieModelMapper::series();
143 }
179 }
144
180
145 void QHPieModelMapper::setSeries(QPieSeries *series)
181 void QHPieModelMapper::setSeries(QPieSeries *series)
146 {
182 {
147 if (series != QPieModelMapper::series()) {
183 if (series != QPieModelMapper::series()) {
148 QPieModelMapper::setSeries(series);
184 QPieModelMapper::setSeries(series);
149 emit seriesReplaced();
185 emit seriesReplaced();
150 }
186 }
151 }
187 }
152
188
153 /*!
189 /*!
154 Returns which row of the model is kept in sync with the values of the pie's slices
190 Returns which row of the model is kept in sync with the values of the pie's slices
155 */
191 */
156 int QHPieModelMapper::valuesRow() const
192 int QHPieModelMapper::valuesRow() const
157 {
193 {
158 return valuesSection();
194 return valuesSection();
159 }
195 }
160
196
161 /*!
197 /*!
162 Sets the model row that is kept in sync with the pie slices values.
198 Sets the model row that is kept in sync with the pie slices values.
163 Parameter \a valuesRow specifies the row of the model.
199 Parameter \a valuesRow specifies the row of the model.
164 */
200 */
165 void QHPieModelMapper::setValuesRow(int valuesRow)
201 void QHPieModelMapper::setValuesRow(int valuesRow)
166 {
202 {
167 if (valuesRow != valuesSection()) {
203 if (valuesRow != valuesSection()) {
168 setValuesSection(valuesRow);
204 setValuesSection(valuesRow);
169 emit valuesRowChanged();
205 emit valuesRowChanged();
170 }
206 }
171 }
207 }
172
208
173 /*!
209 /*!
174 Returns which row of the model is kept in sync with the labels of the pie's slices
210 Returns which row of the model is kept in sync with the labels of the pie's slices
175 */
211 */
176 int QHPieModelMapper::labelsRow() const
212 int QHPieModelMapper::labelsRow() const
177 {
213 {
178 return labelsSection();
214 return labelsSection();
179 }
215 }
180
216
181 /*!
217 /*!
182 Sets the model row that is kept in sync with the pie's slices labels.
218 Sets the model row that is kept in sync with the pie's slices labels.
183 Parameter \a labelsRow specifies the row of the model.
219 Parameter \a labelsRow specifies the row of the model.
184 */
220 */
185 void QHPieModelMapper::setLabelsRow(int labelsRow)
221 void QHPieModelMapper::setLabelsRow(int labelsRow)
186 {
222 {
187 if (labelsRow != labelsSection()) {
223 if (labelsRow != labelsSection()) {
188 setLabelsSection(labelsRow);
224 setLabelsSection(labelsRow);
189 emit labelsRowChanged();
225 emit labelsRowChanged();
190 }
226 }
191 }
227 }
192
228
193 int QHPieModelMapper::firstColumn() const
229 int QHPieModelMapper::firstColumn() const
194 {
230 {
195 return first();
231 return first();
196 }
232 }
197
233
198 void QHPieModelMapper::setFirstColumn(int firstColumn)
234 void QHPieModelMapper::setFirstColumn(int firstColumn)
199 {
235 {
200 if (firstColumn != first()) {
236 if (firstColumn != first()) {
201 setFirst(firstColumn);
237 setFirst(firstColumn);
202 emit firstColumnChanged();
238 emit firstColumnChanged();
203 }
239 }
204 }
240 }
205
241
206 int QHPieModelMapper::columnCount() const
242 int QHPieModelMapper::columnCount() const
207 {
243 {
208 return count();
244 return count();
209 }
245 }
210
246
211 void QHPieModelMapper::setColumnCount(int columnCount)
247 void QHPieModelMapper::setColumnCount(int columnCount)
212 {
248 {
213 if (columnCount != count()) {
249 if (columnCount != count()) {
214 setCount(columnCount);
250 setCount(columnCount);
215 emit firstColumnChanged();
251 emit firstColumnChanged();
216 }
252 }
217 }
253 }
218
254
219 #include "moc_qhpiemodelmapper.cpp"
255 #include "moc_qhpiemodelmapper.cpp"
220
256
221 QTCOMMERCIALCHART_END_NAMESPACE
257 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,221 +1,260
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 "qvpiemodelmapper.h"
21 #include "qvpiemodelmapper.h"
22
22
23 QTCOMMERCIALCHART_BEGIN_NAMESPACE
23 QTCOMMERCIALCHART_BEGIN_NAMESPACE
24
24
25 /*!
25 /*!
26 \class QVPieModelMapper
26 \class QVPieModelMapper
27 \mainclass
27 \mainclass
28
28
29 Model mappers allow you to use QAbstractItemModel derived models as a data source for a chart series.
29 Model mappers allow you to use QAbstractItemModel derived models as a data source for a chart series.
30 Vertical model mapper is used to create a connection between QPieSeries and QAbstractItemModel derived model object that keeps the consecutive pie slices data in columns.
30 Vertical model mapper is used to create a connection between QPieSeries and QAbstractItemModel derived model object that keeps the consecutive pie slices data in columns.
31 It is possible to use both QAbstractItemModel and QPieSeries model API. QVPieModelMapper makes sure that Pie and the model are kept in sync.
31 It is possible to use both QAbstractItemModel and QPieSeries model API. QVPieModelMapper makes sure that Pie and the model are kept in sync.
32 NOTE: used model has to support adding/removing rows/columns and modifying the data of the cells.
32 NOTE: used model has to support adding/removing rows/columns and modifying the data of the cells.
33 */
33 */
34 /*!
35 \qmlclass VPieModelMapper QVPieModelMapper
36
37 VPieModelMapper allows you to use your own QAbstractItemModel derived model with data in columns as a data source
38 for a pie series. It is possible to use both QAbstractItemModel and PieSeries data API to manipulate data.
39 VPieModelMapper keeps the Pie and the model in sync.
40
41 The following QML example would create a pie series with four slices (assuming the model has at least five rows).
42 Each slice would contain a label from column 1 and a value from column 2.
43 \code
44 VPieModelMapper {
45 series: pieSeries
46 model: customModel
47 labelsColumn: 1
48 valuesColumn: 2
49 firstRow: 1
50 rowCount: 4
51 }
52 \endcode
53 */
34
54
35 /*!
55 /*!
36 \property QVPieModelMapper::series
56 \property QVPieModelMapper::series
37 \brief Defines the QPieSeries object that is used by the mapper.
57 \brief Defines the QPieSeries object that is used by the mapper.
38
39 All the data in the series is discarded when it is set to the mapper.
58 All the data in the series is discarded when it is set to the mapper.
40 When new series is specified the old series is disconnected (it preserves its data)
59 When new series is specified the old series is disconnected (it preserves its data)
41 */
60 */
61 /*!
62 \qmlproperty PieSeries VPieModelMapper::series
63 Defines the PieSeries object that is used by the mapper. If you define the mapper element as a child for a
64 PieSeries, leave this property undefined. All the data in the series is discarded when it is set to the mapper.
65 When new series is specified the old series is disconnected (it preserves its data).
66 */
42
67
43 /*!
68 /*!
44 \property QVPieModelMapper::model
69 \property QVPieModelMapper::model
45 \brief Defines the model that is used by the mapper.
70 \brief Defines the model that is used by the mapper.
46 */
71 */
72 /*!
73 \qmlproperty SomeModel VPieModelMapper::model
74 The QAbstractItemModel based model that is used by the mapper. You need to implement the model and expose it to
75 QML as shown in \l {QML Custom Model} demo application. NOTE: the model has to support adding/removing rows/columns
76 and modifying the data of the cells.
77 */
47
78
48 /*!
79 /*!
49 \property QVPieModelMapper::valuesColumn
80 \property QVPieModelMapper::valuesColumn
50 \brief Defines which column of the model is kept in sync with the values of the pie's slices
81 \brief Defines which column of the model is kept in sync with the values of the pie's slices
51
52 Default value is: -1 (invalid mapping)
82 Default value is: -1 (invalid mapping)
53 */
83 */
84 /*!
85 \qmlproperty int VPieModelMapper::valuesColumn
86 Defines which column of the model is kept in sync with the values of the pie's slices. Default value is -1 (invalid
87 mapping).
88 */
54
89
55 /*!
90 /*!
56 \property QVPieModelMapper::labelsColumn
91 \property QVPieModelMapper::labelsColumn
57 \brief Defines which column of the model is kept in sync with the labels of the pie's slices
92 \brief Defines which column of the model is kept in sync with the labels of the pie's slices
58
59 Default value is: -1 (invalid mapping)
93 Default value is: -1 (invalid mapping)
60 */
94 */
95 /*!
96 \qmlproperty int VPieModelMapper::labelsColumn
97 Defines which column of the model is kept in sync with the labels of the pie's slices. Default value is -1 (invalid
98 mapping).
99 */
61
100
62 /*!
101 /*!
63 \property QVPieModelMapper::firstRow
102 \property QVPieModelMapper::firstRow
64 \brief Defines which row of the model contains the first slice value.
103 \brief Defines which row of the model contains the first slice value.
65 Minimal and default value is: 0
104 Minimal and default value is: 0
66 */
105 */
67 /*!
106 /*!
68 \qmlproperty int QVPieModelMapper::firstRow
107 \qmlproperty int VPieModelMapper::firstRow
69 Defines which row of the model contains the first slice value.
108 Defines which row of the model contains the first slice value.
70 The default value is 0.
109 The default value is 0.
71 */
110 */
72
111
73 /*!
112 /*!
74 \property QVPieModelMapper::rowCount
113 \property QVPieModelMapper::rowCount
75 \brief Defines the number of rows of the model that are mapped as the data for QPieSeries
114 \brief Defines the number of rows of the model that are mapped as the data for QPieSeries
76 Minimal and default value is: -1 (count limited by the number of rows in the model)
115 Minimal and default value is: -1 (count limited by the number of rows in the model)
77 */
116 */
78 /*!
117 /*!
79 \qmlproperty int QVPieModelMapper::columnCount
118 \qmlproperty int VPieModelMapper::columnCount
80 Defines the number of rows of the model that are mapped as the data for QPieSeries. The default value is
119 Defines the number of rows of the model that are mapped as the data for QPieSeries. The default value is
81 -1 (count limited by the number of rows in the model)
120 -1 (count limited by the number of rows in the model)
82 */
121 */
83
122
84 /*!
123 /*!
85 \fn void QVPieModelMapper::seriesReplaced()
124 \fn void QVPieModelMapper::seriesReplaced()
86
125
87 Emitted when the series to which mapper is connected to has changed.
126 Emitted when the series to which mapper is connected to has changed.
88 */
127 */
89
128
90 /*!
129 /*!
91 \fn void QVPieModelMapper::modelReplaced()
130 \fn void QVPieModelMapper::modelReplaced()
92
131
93 Emitted when the model to which mapper is connected to has changed.
132 Emitted when the model to which mapper is connected to has changed.
94 */
133 */
95
134
96 /*!
135 /*!
97 \fn void QVPieModelMapper::valuesColumnChanged()
136 \fn void QVPieModelMapper::valuesColumnChanged()
98
137
99 Emitted when the valuesColumn has changed.
138 Emitted when the valuesColumn has changed.
100 */
139 */
101
140
102 /*!
141 /*!
103 \fn void QVPieModelMapper::labelsColumnChanged()
142 \fn void QVPieModelMapper::labelsColumnChanged()
104
143
105 Emitted when the labelsColumn has changed.
144 Emitted when the labelsColumn has changed.
106 */
145 */
107
146
108 /*!
147 /*!
109 \fn void QVPieModelMapper::firstRowChanged()
148 \fn void QVPieModelMapper::firstRowChanged()
110 Emitted when the firstRow has changed.
149 Emitted when the firstRow has changed.
111 */
150 */
112
151
113 /*!
152 /*!
114 \fn void QVPieModelMapper::rowCountChanged()
153 \fn void QVPieModelMapper::rowCountChanged()
115 Emitted when the rowCount has changed.
154 Emitted when the rowCount has changed.
116 */
155 */
117
156
118 /*!
157 /*!
119 Constructs a mapper object which is a child of \a parent.
158 Constructs a mapper object which is a child of \a parent.
120 */
159 */
121 QVPieModelMapper::QVPieModelMapper(QObject *parent) :
160 QVPieModelMapper::QVPieModelMapper(QObject *parent) :
122 QPieModelMapper(parent)
161 QPieModelMapper(parent)
123 {
162 {
124 QPieModelMapper::setOrientation(Qt::Vertical);
163 QPieModelMapper::setOrientation(Qt::Vertical);
125 }
164 }
126
165
127 QAbstractItemModel* QVPieModelMapper::model() const
166 QAbstractItemModel* QVPieModelMapper::model() const
128 {
167 {
129 return QPieModelMapper::model();
168 return QPieModelMapper::model();
130 }
169 }
131
170
132 void QVPieModelMapper::setModel(QAbstractItemModel *model)
171 void QVPieModelMapper::setModel(QAbstractItemModel *model)
133 {
172 {
134 if (model != QPieModelMapper::model()) {
173 if (model != QPieModelMapper::model()) {
135 QPieModelMapper::setModel(model);
174 QPieModelMapper::setModel(model);
136 emit modelReplaced();
175 emit modelReplaced();
137 }
176 }
138 }
177 }
139
178
140 QPieSeries* QVPieModelMapper::series() const
179 QPieSeries* QVPieModelMapper::series() const
141 {
180 {
142 return QPieModelMapper::series();
181 return QPieModelMapper::series();
143 }
182 }
144
183
145 void QVPieModelMapper::setSeries(QPieSeries *series)
184 void QVPieModelMapper::setSeries(QPieSeries *series)
146 {
185 {
147 if (series != QPieModelMapper::series()) {
186 if (series != QPieModelMapper::series()) {
148 QPieModelMapper::setSeries(series);
187 QPieModelMapper::setSeries(series);
149 emit seriesReplaced();
188 emit seriesReplaced();
150 }
189 }
151 }
190 }
152
191
153 /*!
192 /*!
154 Returns which column of the model is kept in sync with the values of the pie's slices
193 Returns which column of the model is kept in sync with the values of the pie's slices
155 */
194 */
156 int QVPieModelMapper::valuesColumn() const
195 int QVPieModelMapper::valuesColumn() const
157 {
196 {
158 return QPieModelMapper::valuesSection();
197 return QPieModelMapper::valuesSection();
159 }
198 }
160
199
161 /*!
200 /*!
162 Sets the model column that is kept in sync with the pie slices values.
201 Sets the model column that is kept in sync with the pie slices values.
163 Parameter \a valuesColumn specifies the row of the model.
202 Parameter \a valuesColumn specifies the row of the model.
164 */
203 */
165 void QVPieModelMapper::setValuesColumn(int valuesColumn)
204 void QVPieModelMapper::setValuesColumn(int valuesColumn)
166 {
205 {
167 if (valuesColumn != valuesSection()) {
206 if (valuesColumn != valuesSection()) {
168 QPieModelMapper::setValuesSection(valuesColumn);
207 QPieModelMapper::setValuesSection(valuesColumn);
169 emit valuesColumnChanged();
208 emit valuesColumnChanged();
170 }
209 }
171 }
210 }
172
211
173 /*!
212 /*!
174 Returns which column of the model is kept in sync with the labels of the pie's slices
213 Returns which column of the model is kept in sync with the labels of the pie's slices
175 */
214 */
176 int QVPieModelMapper::labelsColumn() const
215 int QVPieModelMapper::labelsColumn() const
177 {
216 {
178 return QPieModelMapper::labelsSection();
217 return QPieModelMapper::labelsSection();
179 }
218 }
180
219
181 /*!
220 /*!
182 Sets the model column that is kept in sync with the pie's slices labels.
221 Sets the model column that is kept in sync with the pie's slices labels.
183 Parameter \a labelsColumn specifies the row of the model.
222 Parameter \a labelsColumn specifies the row of the model.
184 */
223 */
185 void QVPieModelMapper::setLabelsColumn(int labelsColumn)
224 void QVPieModelMapper::setLabelsColumn(int labelsColumn)
186 {
225 {
187 if (labelsColumn != labelsSection()) {
226 if (labelsColumn != labelsSection()) {
188 QPieModelMapper::setLabelsSection(labelsColumn);
227 QPieModelMapper::setLabelsSection(labelsColumn);
189 emit labelsColumnChanged();
228 emit labelsColumnChanged();
190 }
229 }
191 }
230 }
192
231
193 int QVPieModelMapper::firstRow() const
232 int QVPieModelMapper::firstRow() const
194 {
233 {
195 return first();
234 return first();
196 }
235 }
197
236
198 void QVPieModelMapper::setFirstRow(int firstRow)
237 void QVPieModelMapper::setFirstRow(int firstRow)
199 {
238 {
200 if (firstRow != first()) {
239 if (firstRow != first()) {
201 setFirst(firstRow);
240 setFirst(firstRow);
202 emit firstRowChanged();
241 emit firstRowChanged();
203 }
242 }
204 }
243 }
205
244
206 int QVPieModelMapper::rowCount() const
245 int QVPieModelMapper::rowCount() const
207 {
246 {
208 return count();
247 return count();
209 }
248 }
210
249
211 void QVPieModelMapper::setRowCount(int rowCount)
250 void QVPieModelMapper::setRowCount(int rowCount)
212 {
251 {
213 if (rowCount != count()) {
252 if (rowCount != count()) {
214 setCount(rowCount);
253 setCount(rowCount);
215 emit firstRowChanged();
254 emit firstRowChanged();
216 }
255 }
217 }
256 }
218
257
219 #include "moc_qvpiemodelmapper.cpp"
258 #include "moc_qvpiemodelmapper.cpp"
220
259
221 QTCOMMERCIALCHART_END_NAMESPACE
260 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,206 +1,232
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 "qhxymodelmapper.h"
21 #include "qhxymodelmapper.h"
22
22
23 QTCOMMERCIALCHART_BEGIN_NAMESPACE
23 QTCOMMERCIALCHART_BEGIN_NAMESPACE
24
24
25 /*!
25 /*!
26 \class QHXYModelMapper
26 \class QHXYModelMapper
27 \mainclass
27 \mainclass
28
28
29 Model mappers allow you to use QAbstractItemModel derived models as a data source for a chart series.
29 Model mappers allow you to use QAbstractItemModel derived models as a data source for a chart series.
30 Horizontal model mapper is used to create a connection between QXYSeries and QAbstractItemModel derived model object.
30 Horizontal model mapper is used to create a connection between QXYSeries and QAbstractItemModel derived model object.
31 It is possible to use both QAbstractItemModel and QXYSeries model API. QXYModelMapper makes sure that QXYSeries and the model are kept in sync.
31 It is possible to use both QAbstractItemModel and QXYSeries model API. QXYModelMapper makes sure that QXYSeries and the model are kept in sync.
32 NOTE: used model has to support adding/removing rows/columns and modifying the data of the cells.
32 NOTE: used model has to support adding/removing rows/columns and modifying the data of the cells.
33 */
33 */
34 /*!
35 \qmlclass HXYModelMapper QHXYModelMapper
36
37 HXYModelMapper allows you to use your own QAbstractItemModel derived model with data in rows as a data source
38 for XYSeries based series. It is possible to use both QAbstractItemModel and XYSeries data API to manipulate data.
39 HXYModelMapper keeps the series and the model in sync.
40 */
34
41
35 /*!
42 /*!
36 \property QHXYModelMapper::series
43 \property QHXYModelMapper::series
37 \brief Defines the QXYSeries object that is used by the mapper.
44 \brief Defines the QXYSeries object that is used by the mapper.
38
39 All the data in the series is discarded when it is set to the mapper.
45 All the data in the series is discarded when it is set to the mapper.
40 When new series is specified the old series is disconnected (it preserves its data)
46 When new series is specified the old series is disconnected (it preserves its data)
41 */
47 */
48 /*!
49 \qmlproperty XYSeries HXYModelMapper::series
50 Defines the QXYSeries object that is used by the mapper. All the data in the series is discarded when it is set to
51 the mapper. When new series is specified the old series is disconnected (it preserves its data).
52 */
42
53
43 /*!
54 /*!
44 \property QHXYModelMapper::model
55 \property QHXYModelMapper::model
45 \brief Defines the model that is used by the mapper.
56 \brief Defines the model that is used by the mapper.
46 */
57 */
58 /*!
59 \qmlproperty SomeModel HXYModelMapper::model
60 The QAbstractItemModel based model that is used by the mapper. You need to implement the model and expose it to
61 QML as shown in \l {QML Custom Model} demo application. NOTE: the model has to support adding/removing rows/columns
62 and modifying the data of the cells.
63 */
47
64
48 /*!
65 /*!
49 \property QHXYModelMapper::xRow
66 \property QHXYModelMapper::xRow
50 \brief Defines which row of the model is kept in sync with the x values of the QXYSeries
67 \brief Defines which row of the model is kept in sync with the x values of the QXYSeries
51 Default value is: -1 (invalid mapping)
68 Default value is: -1 (invalid mapping)
52 */
69 */
70 /*!
71 \qmlproperty int HXYModelMapper::xRow
72 Defines which row of the model is kept in sync with the x values of the QXYSeries. Default value is -1 (invalid
73 mapping).
74 */
53
75
54 /*!
76 /*!
55 \property QHXYModelMapper::yRow
77 \property QHXYModelMapper::yRow
56 \brief Defines which row of the model is kept in sync with the y values of the QXYSeries
78 \brief Defines which row of the model is kept in sync with the y values of the QXYSeries
57
58 Default value is: -1 (invalid mapping)
79 Default value is: -1 (invalid mapping)
59 */
80 */
81 /*!
82 \qmlproperty int HXYModelMapper::yRow
83 Defines which row of the model is kept in sync with the y values of the QXYSeries. Default value is -1
84 (invalid mapping).
85 */
60
86
61 /*!
87 /*!
62 \property QHXYModelMapper::firstColumn
88 \property QHXYModelMapper::firstColumn
63 \brief Defines which column of the model contains the data for the first point of the series.
89 \brief Defines which column of the model contains the data for the first point of the series.
64 Minimal and default value is: 0
90 Minimal and default value is: 0
65 */
91 */
66 /*!
92 /*!
67 \qmlproperty int QHXYModelMapper::firstColumn
93 \qmlproperty int HXYModelMapper::firstColumn
68 Defines which column of the model contains the data for the first point of the series.
94 Defines which column of the model contains the data for the first point of the series.
69 The default value is 0.
95 The default value is 0.
70 */
96 */
71
97
72 /*!
98 /*!
73 \property QHXYModelMapper::columnCount
99 \property QHXYModelMapper::columnCount
74 \brief Defines the number of columns of the model that are mapped as the data for series
100 \brief Defines the number of columns of the model that are mapped as the data for series
75 Minimal and default value is: -1 (count limited by the number of columns in the model)
101 Minimal and default value is: -1 (count limited by the number of columns in the model)
76 */
102 */
77 /*!
103 /*!
78 \qmlproperty int QHXYModelMapper::columnCount
104 \qmlproperty int HXYModelMapper::columnCount
79 Defines the number of columns of the model that are mapped as the data for series. The default value is
105 Defines the number of columns of the model that are mapped as the data for series. The default value is
80 -1 (count limited by the number of columns in the model)
106 -1 (count limited by the number of columns in the model)
81 */
107 */
82
108
83 /*!
109 /*!
84 \fn void QHXYModelMapper::seriesReplaced()
110 \fn void QHXYModelMapper::seriesReplaced()
85
111
86 Emitted when the series to which mapper is connected to has changed.
112 Emitted when the series to which mapper is connected to has changed.
87 */
113 */
88
114
89 /*!
115 /*!
90 \fn void QHXYModelMapper::modelReplaced()
116 \fn void QHXYModelMapper::modelReplaced()
91
117
92 Emitted when the model to which mapper is connected to has changed.
118 Emitted when the model to which mapper is connected to has changed.
93 */
119 */
94
120
95 /*!
121 /*!
96 \fn void QHXYModelMapper::xRowChanged()
122 \fn void QHXYModelMapper::xRowChanged()
97
123
98 Emitted when the xRow has changed.
124 Emitted when the xRow has changed.
99 */
125 */
100
126
101 /*!
127 /*!
102 \fn void QHXYModelMapper::yRowChanged()
128 \fn void QHXYModelMapper::yRowChanged()
103
129
104 Emitted when the yRow has changed.
130 Emitted when the yRow has changed.
105 */
131 */
106
132
107 /*!
133 /*!
108 \fn void QHXYModelMapper::firstColumnChanged()
134 \fn void QHXYModelMapper::firstColumnChanged()
109 Emitted when the firstColumn has changed.
135 Emitted when the firstColumn has changed.
110 */
136 */
111
137
112 /*!
138 /*!
113 \fn void QHXYModelMapper::columnCountChanged()
139 \fn void QHXYModelMapper::columnCountChanged()
114 Emitted when the columnCount has changed.
140 Emitted when the columnCount has changed.
115 */
141 */
116
142
117 /*!
143 /*!
118 Constructs a mapper object which is a child of \a parent.
144 Constructs a mapper object which is a child of \a parent.
119 */
145 */
120 QHXYModelMapper::QHXYModelMapper(QObject *parent) :
146 QHXYModelMapper::QHXYModelMapper(QObject *parent) :
121 QXYModelMapper(parent)
147 QXYModelMapper(parent)
122 {
148 {
123 QXYModelMapper::setOrientation(Qt::Horizontal);
149 QXYModelMapper::setOrientation(Qt::Horizontal);
124 }
150 }
125
151
126 QAbstractItemModel* QHXYModelMapper::model() const
152 QAbstractItemModel* QHXYModelMapper::model() const
127 {
153 {
128 return QXYModelMapper::model();
154 return QXYModelMapper::model();
129 }
155 }
130
156
131 void QHXYModelMapper::setModel(QAbstractItemModel *model)
157 void QHXYModelMapper::setModel(QAbstractItemModel *model)
132 {
158 {
133 if (model != QXYModelMapper::model()) {
159 if (model != QXYModelMapper::model()) {
134 QXYModelMapper::setModel(model);
160 QXYModelMapper::setModel(model);
135 emit modelReplaced();
161 emit modelReplaced();
136 }
162 }
137 }
163 }
138
164
139 QXYSeries* QHXYModelMapper::series() const
165 QXYSeries* QHXYModelMapper::series() const
140 {
166 {
141 return QXYModelMapper::series();
167 return QXYModelMapper::series();
142 }
168 }
143
169
144 void QHXYModelMapper::setSeries(QXYSeries *series)
170 void QHXYModelMapper::setSeries(QXYSeries *series)
145 {
171 {
146 if (series != QXYModelMapper::series()) {
172 if (series != QXYModelMapper::series()) {
147 QXYModelMapper::setSeries(series);
173 QXYModelMapper::setSeries(series);
148 emit seriesReplaced();
174 emit seriesReplaced();
149 }
175 }
150 }
176 }
151
177
152 int QHXYModelMapper::xRow() const
178 int QHXYModelMapper::xRow() const
153 {
179 {
154 return QXYModelMapper::xSection();
180 return QXYModelMapper::xSection();
155 }
181 }
156
182
157 void QHXYModelMapper::setXRow(int xRow)
183 void QHXYModelMapper::setXRow(int xRow)
158 {
184 {
159 if (xRow != xSection()) {
185 if (xRow != xSection()) {
160 return QXYModelMapper::setXSection(xRow);
186 return QXYModelMapper::setXSection(xRow);
161 emit xRowChanged();
187 emit xRowChanged();
162 }
188 }
163 }
189 }
164
190
165 int QHXYModelMapper::yRow() const
191 int QHXYModelMapper::yRow() const
166 {
192 {
167 return QXYModelMapper::ySection();
193 return QXYModelMapper::ySection();
168 }
194 }
169
195
170 void QHXYModelMapper::setYRow(int yRow)
196 void QHXYModelMapper::setYRow(int yRow)
171 {
197 {
172 if (yRow != ySection()) {
198 if (yRow != ySection()) {
173 return QXYModelMapper::setYSection(yRow);
199 return QXYModelMapper::setYSection(yRow);
174 emit yRowChanged();
200 emit yRowChanged();
175 }
201 }
176 }
202 }
177
203
178 int QHXYModelMapper::firstColumn() const
204 int QHXYModelMapper::firstColumn() const
179 {
205 {
180 return first();
206 return first();
181 }
207 }
182
208
183 void QHXYModelMapper::setFirstColumn(int firstColumn)
209 void QHXYModelMapper::setFirstColumn(int firstColumn)
184 {
210 {
185 if (firstColumn != first()) {
211 if (firstColumn != first()) {
186 setFirst(firstColumn);
212 setFirst(firstColumn);
187 emit firstColumnChanged();
213 emit firstColumnChanged();
188 }
214 }
189 }
215 }
190
216
191 int QHXYModelMapper::columnCount() const
217 int QHXYModelMapper::columnCount() const
192 {
218 {
193 return count();
219 return count();
194 }
220 }
195
221
196 void QHXYModelMapper::setColumnCount(int columnCount)
222 void QHXYModelMapper::setColumnCount(int columnCount)
197 {
223 {
198 if (columnCount != count()) {
224 if (columnCount != count()) {
199 setCount(columnCount);
225 setCount(columnCount);
200 emit firstColumnChanged();
226 emit firstColumnChanged();
201 }
227 }
202 }
228 }
203
229
204 #include "moc_qhxymodelmapper.cpp"
230 #include "moc_qhxymodelmapper.cpp"
205
231
206 QTCOMMERCIALCHART_END_NAMESPACE
232 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,207 +1,232
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 "qvxymodelmapper.h"
21 #include "qvxymodelmapper.h"
22
22
23 QTCOMMERCIALCHART_BEGIN_NAMESPACE
23 QTCOMMERCIALCHART_BEGIN_NAMESPACE
24
24
25 /*!
25 /*!
26 \class QVXYModelMapper
26 \class QVXYModelMapper
27 \mainclass
27 \mainclass
28
28
29 Model mappers allow you to use QAbstractItemModel derived models as a data source for a chart series.
29 Model mappers allow you to use QAbstractItemModel derived models as a data source for a chart series.
30 Vertical model mapper is used to create a connection between QXYSeries and QAbstractItemModel derived model object.
30 Vertical model mapper is used to create a connection between QXYSeries and QAbstractItemModel derived model object.
31 It is possible to use both QAbstractItemModel and QXYSeries model API. QXYModelMapper makes sure that QXYSeries and the model are kept in sync.
31 It is possible to use both QAbstractItemModel and QXYSeries model API. QXYModelMapper makes sure that QXYSeries and the model are kept in sync.
32 NOTE: used model has to support adding/removing rows/columns and modifying the data of the cells.
32 NOTE: used model has to support adding/removing rows/columns and modifying the data of the cells.
33 */
33 */
34 /*!
35 \qmlclass VXYModelMapper QHXYModelMapper
36
37 VXYModelMapper allows you to use your own QAbstractItemModel derived model with data in columns as a data source
38 for XYSeries based series. It is possible to use both QAbstractItemModel and XYSeries data API to manipulate data.
39 VYModelMapper keeps the series and the model in sync.
40 */
34
41
35 /*!
42 /*!
36 \property QVXYModelMapper::series
43 \property QVXYModelMapper::series
37 \brief Defines the QXYSeries object that is used by the mapper.
44 \brief Defines the QXYSeries object that is used by the mapper.
38
39 All the data in the series is discarded when it is set to the mapper.
45 All the data in the series is discarded when it is set to the mapper.
40 When new series is specified the old series is disconnected (it preserves its data)
46 When new series is specified the old series is disconnected (it preserves its data)
41 */
47 */
48 /*!
49 \qmlproperty XYSeries VXYModelMapper::series
50 Defines the QXYSeries object that is used by the mapper. All the data in the series is discarded when it is set to
51 the mapper. When new series is specified the old series is disconnected (it preserves its data).
52 */
42
53
43 /*!
54 /*!
44 \property QVXYModelMapper::model
55 \property QVXYModelMapper::model
45 \brief Defines the model that is used by the mapper.
56 \brief Defines the model that is used by the mapper.
46 */
57 */
58 /*!
59 \qmlproperty SomeModel VXYModelMapper::model
60 The QAbstractItemModel based model that is used by the mapper. You need to implement the model and expose it to
61 QML as shown in \l {QML Custom Model} demo application. NOTE: the model has to support adding/removing rows/columns
62 and modifying the data of the cells.
63 */
47
64
48 /*!
65 /*!
49 \property QVXYModelMapper::xColumn
66 \property QVXYModelMapper::xColumn
50 \brief Defines which column of the model is kept in sync with the x values of QXYSeries
67 \brief Defines which column of the model is kept in sync with the x values of QXYSeries
51
52 Default value is: -1 (invalid mapping)
68 Default value is: -1 (invalid mapping)
53 */
69 */
70 /*!
71 \qmlproperty int VXYModelMapper::xColumn
72 Defines which column of the model is kept in sync with the x values of XYSeries. Default value is -1 (invalid
73 mapping).
74 */
54
75
55 /*!
76 /*!
56 \property QVXYModelMapper::yColumn
77 \property QVXYModelMapper::yColumn
57 \brief Defines which column of the model is kept in sync with the y values of QXYSeries
78 \brief Defines which column of the model is kept in sync with the y values of QXYSeries
58
59 Default value is: -1 (invalid mapping)
79 Default value is: -1 (invalid mapping)
60 */
80 */
81 /*!
82 \qmlproperty int VXYModelMapper::yColumn
83 Defines which column of the model is kept in sync with the y values of QXYSeries. Default value is -1 (invalid
84 mapping).
85 */
61
86
62 /*!
87 /*!
63 \property QVXYModelMapper::firstRow
88 \property QVXYModelMapper::firstRow
64 \brief Defines which row of the model contains the data for the first point of the series.
89 \brief Defines which row of the model contains the data for the first point of the series.
65 Minimal and default value is: 0
90 Minimal and default value is: 0
66 */
91 */
67 /*!
92 /*!
68 \qmlproperty int QVXYModelMapper::firstRow
93 \qmlproperty int VXYModelMapper::firstRow
69 Defines which row of the model contains the data for the first point of the series.
94 Defines which row of the model contains the data for the first point of the series.
70 The default value is 0.
95 The default value is 0.
71 */
96 */
72
97
73 /*!
98 /*!
74 \property QVXYModelMapper::rowCount
99 \property QVXYModelMapper::rowCount
75 \brief Defines the number of rows of the model that are mapped as the data for series
100 \brief Defines the number of rows of the model that are mapped as the data for series
76 Minimal and default value is: -1 (count limited by the number of rows in the model)
101 Minimal and default value is: -1 (count limited by the number of rows in the model)
77 */
102 */
78 /*!
103 /*!
79 \qmlproperty int QVXYModelMapper::columnCount
104 \qmlproperty int VXYModelMapper::columnCount
80 Defines the number of rows of the model that are mapped as the data for series. The default value is
105 Defines the number of rows of the model that are mapped as the data for series. The default value is
81 -1 (count limited by the number of rows in the model)
106 -1 (count limited by the number of rows in the model).
82 */
107 */
83
108
84 /*!
109 /*!
85 \fn void QVXYModelMapper::seriesReplaced()
110 \fn void QVXYModelMapper::seriesReplaced()
86
111
87 Emitted when the series to which mapper is connected to has changed.
112 Emitted when the series to which mapper is connected to has changed.
88 */
113 */
89
114
90 /*!
115 /*!
91 \fn void QVXYModelMapper::modelReplaced()
116 \fn void QVXYModelMapper::modelReplaced()
92
117
93 Emitted when the model to which mapper is connected to has changed.
118 Emitted when the model to which mapper is connected to has changed.
94 */
119 */
95
120
96 /*!
121 /*!
97 \fn void QVXYModelMapper::xColumnChanged()
122 \fn void QVXYModelMapper::xColumnChanged()
98
123
99 Emitted when the xColumn has changed.
124 Emitted when the xColumn has changed.
100 */
125 */
101
126
102 /*!
127 /*!
103 \fn void QVXYModelMapper::yColumnChanged()
128 \fn void QVXYModelMapper::yColumnChanged()
104
129
105 Emitted when the yColumn has changed.
130 Emitted when the yColumn has changed.
106 */
131 */
107
132
108 /*!
133 /*!
109 \fn void QVXYModelMapper::firstRowChanged()
134 \fn void QVXYModelMapper::firstRowChanged()
110 Emitted when the firstRow has changed.
135 Emitted when the firstRow has changed.
111 */
136 */
112
137
113 /*!
138 /*!
114 \fn void QVXYModelMapper::rowCountChanged()
139 \fn void QVXYModelMapper::rowCountChanged()
115 Emitted when the rowCount has changed.
140 Emitted when the rowCount has changed.
116 */
141 */
117
142
118 /*!
143 /*!
119 Constructs a mapper object which is a child of \a parent.
144 Constructs a mapper object which is a child of \a parent.
120 */
145 */
121 QVXYModelMapper::QVXYModelMapper(QObject *parent) :
146 QVXYModelMapper::QVXYModelMapper(QObject *parent) :
122 QXYModelMapper(parent)
147 QXYModelMapper(parent)
123 {
148 {
124 QXYModelMapper::setOrientation(Qt::Vertical);
149 QXYModelMapper::setOrientation(Qt::Vertical);
125 }
150 }
126
151
127 QAbstractItemModel* QVXYModelMapper::model() const
152 QAbstractItemModel* QVXYModelMapper::model() const
128 {
153 {
129 return QXYModelMapper::model();
154 return QXYModelMapper::model();
130 }
155 }
131
156
132 void QVXYModelMapper::setModel(QAbstractItemModel *model)
157 void QVXYModelMapper::setModel(QAbstractItemModel *model)
133 {
158 {
134 if (model != QXYModelMapper::model()) {
159 if (model != QXYModelMapper::model()) {
135 QXYModelMapper::setModel(model);
160 QXYModelMapper::setModel(model);
136 emit modelReplaced();
161 emit modelReplaced();
137 }
162 }
138 }
163 }
139
164
140 QXYSeries* QVXYModelMapper::series() const
165 QXYSeries* QVXYModelMapper::series() const
141 {
166 {
142 return QXYModelMapper::series();
167 return QXYModelMapper::series();
143 }
168 }
144
169
145 void QVXYModelMapper::setSeries(QXYSeries *series)
170 void QVXYModelMapper::setSeries(QXYSeries *series)
146 {
171 {
147 if (series != QXYModelMapper::series()) {
172 if (series != QXYModelMapper::series()) {
148 QXYModelMapper::setSeries(series);
173 QXYModelMapper::setSeries(series);
149 emit seriesReplaced();
174 emit seriesReplaced();
150 }
175 }
151 }
176 }
152
177
153 int QVXYModelMapper::xColumn() const
178 int QVXYModelMapper::xColumn() const
154 {
179 {
155 return QXYModelMapper::xSection();
180 return QXYModelMapper::xSection();
156 }
181 }
157
182
158 void QVXYModelMapper::setXColumn(int xColumn)
183 void QVXYModelMapper::setXColumn(int xColumn)
159 {
184 {
160 if (xColumn != xSection()) {
185 if (xColumn != xSection()) {
161 return QXYModelMapper::setXSection(xColumn);
186 return QXYModelMapper::setXSection(xColumn);
162 emit xColumnChanged();
187 emit xColumnChanged();
163 }
188 }
164 }
189 }
165
190
166 int QVXYModelMapper::yColumn() const
191 int QVXYModelMapper::yColumn() const
167 {
192 {
168 return QXYModelMapper::ySection();
193 return QXYModelMapper::ySection();
169 }
194 }
170
195
171 void QVXYModelMapper::setYColumn(int yColumn)
196 void QVXYModelMapper::setYColumn(int yColumn)
172 {
197 {
173 if (yColumn != ySection()) {
198 if (yColumn != ySection()) {
174 return QXYModelMapper::setYSection(yColumn);
199 return QXYModelMapper::setYSection(yColumn);
175 emit yColumnChanged();
200 emit yColumnChanged();
176 }
201 }
177 }
202 }
178
203
179 int QVXYModelMapper::firstRow() const
204 int QVXYModelMapper::firstRow() const
180 {
205 {
181 return first();
206 return first();
182 }
207 }
183
208
184 void QVXYModelMapper::setFirstRow(int firstRow)
209 void QVXYModelMapper::setFirstRow(int firstRow)
185 {
210 {
186 if (firstRow != first()) {
211 if (firstRow != first()) {
187 setFirst(firstRow);
212 setFirst(firstRow);
188 emit firstRowChanged();
213 emit firstRowChanged();
189 }
214 }
190 }
215 }
191
216
192 int QVXYModelMapper::rowCount() const
217 int QVXYModelMapper::rowCount() const
193 {
218 {
194 return count();
219 return count();
195 }
220 }
196
221
197 void QVXYModelMapper::setRowCount(int rowCount)
222 void QVXYModelMapper::setRowCount(int rowCount)
198 {
223 {
199 if (rowCount != count()) {
224 if (rowCount != count()) {
200 setCount(rowCount);
225 setCount(rowCount);
201 emit firstRowChanged();
226 emit firstRowChanged();
202 }
227 }
203 }
228 }
204
229
205 #include "moc_qvxymodelmapper.cpp"
230 #include "moc_qvxymodelmapper.cpp"
206
231
207 QTCOMMERCIALCHART_END_NAMESPACE
232 QTCOMMERCIALCHART_END_NAMESPACE
General Comments 0
You need to be logged in to leave comments. Login now