@@ -1,630 +1,612 | |||||
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 "qbarmodelmapper.h" |
|
21 | #include "qbarmodelmapper.h" | |
22 | #include "qbarmodelmapper_p.h" |
|
22 | #include "qbarmodelmapper_p.h" | |
23 | #include "qbarseries.h" |
|
23 | #include "qbarseries.h" | |
24 | #include "qbarset.h" |
|
24 | #include "qbarset.h" | |
25 | #include "qchart.h" |
|
25 | #include "qchart.h" | |
26 | #include <QAbstractItemModel> |
|
26 | #include <QAbstractItemModel> | |
27 |
|
27 | |||
28 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
28 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
29 |
|
29 | |||
30 | /*! |
|
30 | /*! | |
31 | \class QBarModelMapper |
|
31 | \class QBarModelMapper | |
32 | \brief part of QtCommercial chart API. |
|
32 | \brief part of QtCommercial chart API. | |
33 | \mainclass |
|
33 | \mainclass | |
34 |
|
34 | |||
35 | Model mappers allow you to use QAbstractItemModel derived models as a data source for a chart series. |
|
35 | Model mappers allow you to use QAbstractItemModel derived models as a data source for a chart series. | |
36 | The instance of this class cannot be created directly. QHBarModelMapper of QVBarModelMapper should be used instead. |
|
36 | The instance of this class cannot be created directly. QHBarModelMapper of QVBarModelMapper should be used instead. | |
37 | This class is used to create a connection between QBarSeries and QAbstractItemModel derived model object. |
|
37 | This class is used to create a connection between QBarSeries and QAbstractItemModel derived model object. | |
38 | Model mapper maintains equal size of all the BarSets. |
|
38 | Model mapper maintains equal size of all the BarSets. | |
39 | Adding/removing value from the BarSet causes the the same change in the rest of the BarSets added to the same series. |
|
39 | Adding/removing value from the BarSet causes the the same change in the rest of the BarSets added to the same series. | |
40 | NOTE: used model has to support adding/removing rows/columns and modifying the data of the cells. |
|
40 | NOTE: used model has to support adding/removing rows/columns and modifying the data of the cells. | |
41 | */ |
|
41 | */ | |
42 | /*! |
|
|||
43 | \qmlclass BarModelMapper |
|
|||
44 | Cannot be created by the user. Base for HBarModelMapper and VBarModelMapper. Model mappers allow you to use |
|
|||
45 | QAbstractItemModel derived models as a data source for a chart series. Adding/removing value from the BarSet causes |
|
|||
46 | the the same change in the rest of the BarSets added to the same series. |
|
|||
47 | */ |
|
|||
48 |
|
42 | |||
49 | /*! |
|
43 | /*! | |
50 | \property QBarModelMapper::series |
|
44 | \property QBarModelMapper::series | |
51 | \brief Defines the QPieSeries object that is used by the mapper. |
|
45 | \brief Defines the QPieSeries object that is used by the mapper. | |
52 | All the data in the series is discarded when it is set to the mapper. |
|
46 | All the data in the series is discarded when it is set to the mapper. | |
53 | When new series is specified the old series is disconnected (it preserves its data) |
|
47 | When new series is specified the old series is disconnected (it preserves its data) | |
54 | */ |
|
48 | */ | |
55 | /*! |
|
|||
56 | \qmlproperty BarSeries BarModelMapper::series |
|
|||
57 | Defines the BarSeries based object that is used by the mapper. All the data in the series is |
|
|||
58 | discarded when it is set to the mapper. When new series is specified the old series is |
|
|||
59 | disconnected (it preserves its data). |
|
|||
60 | */ |
|
|||
61 |
|
49 | |||
62 | /*! |
|
50 | /*! | |
63 | \property QBarModelMapper::model |
|
51 | \property QBarModelMapper::model | |
64 | \brief Defines the model that is used by the mapper. |
|
52 | \brief Defines the model that is used by the mapper. | |
65 | */ |
|
53 | */ | |
66 | /*! |
|
|||
67 | \qmlproperty Model BarModelMapper::model |
|
|||
68 | The QAbstractItemModel based model that is used by the mapper. You need to implement the model and expose it to |
|
|||
69 | QML as shown in \l {QML Custom Model} demo application. NOTE: the model has to support adding/removing rows/columns |
|
|||
70 | and modifying the data of the cells. |
|
|||
71 | */ |
|
|||
72 |
|
54 | |||
73 | /*! |
|
55 | /*! | |
74 | \fn void QBarModelMapper::seriesReplaced() |
|
56 | \fn void QBarModelMapper::seriesReplaced() | |
75 | Emitted when the series to which mapper is connected to has changed. |
|
57 | Emitted when the series to which mapper is connected to has changed. | |
76 | */ |
|
58 | */ | |
77 |
|
59 | |||
78 | /*! |
|
60 | /*! | |
79 | \fn void QBarModelMapper::modelReplaced() |
|
61 | \fn void QBarModelMapper::modelReplaced() | |
80 | Emitted when the model to which mapper is connected to has changed. |
|
62 | Emitted when the model to which mapper is connected to has changed. | |
81 | */ |
|
63 | */ | |
82 |
|
64 | |||
83 | /*! |
|
65 | /*! | |
84 | Constructs a mapper object which is a child of \a parent. |
|
66 | Constructs a mapper object which is a child of \a parent. | |
85 | */ |
|
67 | */ | |
86 | QBarModelMapper::QBarModelMapper(QObject *parent) : |
|
68 | QBarModelMapper::QBarModelMapper(QObject *parent) : | |
87 | QObject(parent), |
|
69 | QObject(parent), | |
88 | d_ptr(new QBarModelMapperPrivate(this)) |
|
70 | d_ptr(new QBarModelMapperPrivate(this)) | |
89 | { |
|
71 | { | |
90 | } |
|
72 | } | |
91 |
|
73 | |||
92 | QAbstractItemModel* QBarModelMapper::model() const |
|
74 | QAbstractItemModel* QBarModelMapper::model() const | |
93 | { |
|
75 | { | |
94 | Q_D(const QBarModelMapper); |
|
76 | Q_D(const QBarModelMapper); | |
95 | return d->m_model; |
|
77 | return d->m_model; | |
96 | } |
|
78 | } | |
97 |
|
79 | |||
98 | void QBarModelMapper::setModel(QAbstractItemModel *model) |
|
80 | void QBarModelMapper::setModel(QAbstractItemModel *model) | |
99 | { |
|
81 | { | |
100 | if (model == 0) |
|
82 | if (model == 0) | |
101 | return; |
|
83 | return; | |
102 |
|
84 | |||
103 | Q_D(QBarModelMapper); |
|
85 | Q_D(QBarModelMapper); | |
104 | if (d->m_model) { |
|
86 | if (d->m_model) { | |
105 | disconnect(d->m_model, 0, d, 0); |
|
87 | disconnect(d->m_model, 0, d, 0); | |
106 | } |
|
88 | } | |
107 |
|
89 | |||
108 | d->m_model = model; |
|
90 | d->m_model = model; | |
109 | d->initializeBarFromModel(); |
|
91 | d->initializeBarFromModel(); | |
110 | // connect signals from the model |
|
92 | // connect signals from the model | |
111 | connect(d->m_model, SIGNAL(dataChanged(QModelIndex,QModelIndex)), d, SLOT(modelUpdated(QModelIndex,QModelIndex))); |
|
93 | connect(d->m_model, SIGNAL(dataChanged(QModelIndex,QModelIndex)), d, SLOT(modelUpdated(QModelIndex,QModelIndex))); | |
112 | connect(d->m_model, SIGNAL(headerDataChanged(Qt::Orientation,int,int)), d, SLOT(modelHeaderDataUpdated(Qt::Orientation,int,int))); |
|
94 | connect(d->m_model, SIGNAL(headerDataChanged(Qt::Orientation,int,int)), d, SLOT(modelHeaderDataUpdated(Qt::Orientation,int,int))); | |
113 | connect(d->m_model, SIGNAL(rowsInserted(QModelIndex,int,int)), d, SLOT(modelRowsAdded(QModelIndex,int,int))); |
|
95 | connect(d->m_model, SIGNAL(rowsInserted(QModelIndex,int,int)), d, SLOT(modelRowsAdded(QModelIndex,int,int))); | |
114 | connect(d->m_model, SIGNAL(rowsRemoved(QModelIndex,int,int)), d, SLOT(modelRowsRemoved(QModelIndex,int,int))); |
|
96 | connect(d->m_model, SIGNAL(rowsRemoved(QModelIndex,int,int)), d, SLOT(modelRowsRemoved(QModelIndex,int,int))); | |
115 | connect(d->m_model, SIGNAL(columnsInserted(QModelIndex,int,int)), d, SLOT(modelColumnsAdded(QModelIndex,int,int))); |
|
97 | connect(d->m_model, SIGNAL(columnsInserted(QModelIndex,int,int)), d, SLOT(modelColumnsAdded(QModelIndex,int,int))); | |
116 | connect(d->m_model, SIGNAL(columnsRemoved(QModelIndex,int,int)), d, SLOT(modelColumnsRemoved(QModelIndex,int,int))); |
|
98 | connect(d->m_model, SIGNAL(columnsRemoved(QModelIndex,int,int)), d, SLOT(modelColumnsRemoved(QModelIndex,int,int))); | |
117 |
|
99 | |||
118 | emit modelReplaced(); |
|
100 | emit modelReplaced(); | |
119 | } |
|
101 | } | |
120 |
|
102 | |||
121 | QBarSeries* QBarModelMapper::series() const |
|
103 | QBarSeries* QBarModelMapper::series() const | |
122 | { |
|
104 | { | |
123 | Q_D(const QBarModelMapper); |
|
105 | Q_D(const QBarModelMapper); | |
124 | return d->m_series; |
|
106 | return d->m_series; | |
125 | } |
|
107 | } | |
126 |
|
108 | |||
127 | void QBarModelMapper::setSeries(QBarSeries *series) |
|
109 | void QBarModelMapper::setSeries(QBarSeries *series) | |
128 | { |
|
110 | { | |
129 | Q_D(QBarModelMapper); |
|
111 | Q_D(QBarModelMapper); | |
130 | if (d->m_series) { |
|
112 | if (d->m_series) { | |
131 | disconnect(d->m_series, 0, d, 0); |
|
113 | disconnect(d->m_series, 0, d, 0); | |
132 | } |
|
114 | } | |
133 |
|
115 | |||
134 | if (series == 0) |
|
116 | if (series == 0) | |
135 | return; |
|
117 | return; | |
136 |
|
118 | |||
137 | d->m_series = series; |
|
119 | d->m_series = series; | |
138 | d->initializeBarFromModel(); |
|
120 | d->initializeBarFromModel(); | |
139 | // connect the signals from the series |
|
121 | // connect the signals from the series | |
140 | connect(d->m_series, SIGNAL(barsetsAdded(QList<QBarSet*>)), d, SLOT(barSetsAdded(QList<QBarSet*>))); |
|
122 | connect(d->m_series, SIGNAL(barsetsAdded(QList<QBarSet*>)), d, SLOT(barSetsAdded(QList<QBarSet*>))); | |
141 | connect(d->m_series, SIGNAL(barsetsRemoved(QList<QBarSet*>)), d, SLOT(barSetsRemoved(QList<QBarSet*>))); |
|
123 | connect(d->m_series, SIGNAL(barsetsRemoved(QList<QBarSet*>)), d, SLOT(barSetsRemoved(QList<QBarSet*>))); | |
142 |
|
124 | |||
143 | emit seriesReplaced(); |
|
125 | emit seriesReplaced(); | |
144 | } |
|
126 | } | |
145 |
|
127 | |||
146 | /*! |
|
128 | /*! | |
147 | Returns which row/column of the model contains the first values of the QBarSets in the series. |
|
129 | Returns which row/column of the model contains the first values of the QBarSets in the series. | |
148 | The default value is 0. |
|
130 | The default value is 0. | |
149 | */ |
|
131 | */ | |
150 | int QBarModelMapper::first() const |
|
132 | int QBarModelMapper::first() const | |
151 | { |
|
133 | { | |
152 | Q_D(const QBarModelMapper); |
|
134 | Q_D(const QBarModelMapper); | |
153 | return d->m_first; |
|
135 | return d->m_first; | |
154 | } |
|
136 | } | |
155 |
|
137 | |||
156 | /*! |
|
138 | /*! | |
157 | Sets which row of the model contains the \a first values of the QBarSets in the series. |
|
139 | Sets which row of the model contains the \a first values of the QBarSets in the series. | |
158 | The default value is 0. |
|
140 | The default value is 0. | |
159 | */ |
|
141 | */ | |
160 | void QBarModelMapper::setFirst(int first) |
|
142 | void QBarModelMapper::setFirst(int first) | |
161 | { |
|
143 | { | |
162 | Q_D(QBarModelMapper); |
|
144 | Q_D(QBarModelMapper); | |
163 | d->m_first = qMax(first, 0); |
|
145 | d->m_first = qMax(first, 0); | |
164 | d->initializeBarFromModel(); |
|
146 | d->initializeBarFromModel(); | |
165 | } |
|
147 | } | |
166 |
|
148 | |||
167 | /*! |
|
149 | /*! | |
168 | Returns the number of rows/columns of the model that are mapped as the data for QBarSeries |
|
150 | Returns the number of rows/columns of the model that are mapped as the data for QBarSeries | |
169 | Minimal and default value is: -1 (count limited by the number of rows/columns in the model) |
|
151 | Minimal and default value is: -1 (count limited by the number of rows/columns in the model) | |
170 | */ |
|
152 | */ | |
171 | int QBarModelMapper::count() const |
|
153 | int QBarModelMapper::count() const | |
172 | { |
|
154 | { | |
173 | Q_D(const QBarModelMapper); |
|
155 | Q_D(const QBarModelMapper); | |
174 | return d->m_count; |
|
156 | return d->m_count; | |
175 | } |
|
157 | } | |
176 |
|
158 | |||
177 | /*! |
|
159 | /*! | |
178 | Sets the \a count of rows/columns of the model that are mapped as the data for QBarSeries |
|
160 | Sets the \a count of rows/columns of the model that are mapped as the data for QBarSeries | |
179 | Minimal and default value is: -1 (count limited by the number of rows/columns in the model) |
|
161 | Minimal and default value is: -1 (count limited by the number of rows/columns in the model) | |
180 | */ |
|
162 | */ | |
181 | void QBarModelMapper::setCount(int count) |
|
163 | void QBarModelMapper::setCount(int count) | |
182 | { |
|
164 | { | |
183 | Q_D(QBarModelMapper); |
|
165 | Q_D(QBarModelMapper); | |
184 | d->m_count = qMax(count, -1); |
|
166 | d->m_count = qMax(count, -1); | |
185 | d->initializeBarFromModel(); |
|
167 | d->initializeBarFromModel(); | |
186 | } |
|
168 | } | |
187 |
|
169 | |||
188 | /*! |
|
170 | /*! | |
189 | Returns the orientation that is used when QBarModelMapper accesses the model. |
|
171 | Returns the orientation that is used when QBarModelMapper accesses the model. | |
190 | This mean whether the consecutive values of the bar set are read from row (Qt::Horizontal) |
|
172 | This mean whether the consecutive values of the bar set are read from row (Qt::Horizontal) | |
191 | or from columns (Qt::Vertical) |
|
173 | or from columns (Qt::Vertical) | |
192 | */ |
|
174 | */ | |
193 | Qt::Orientation QBarModelMapper::orientation() const |
|
175 | Qt::Orientation QBarModelMapper::orientation() const | |
194 | { |
|
176 | { | |
195 | Q_D(const QBarModelMapper); |
|
177 | Q_D(const QBarModelMapper); | |
196 | return d->m_orientation; |
|
178 | return d->m_orientation; | |
197 | } |
|
179 | } | |
198 |
|
180 | |||
199 | /*! |
|
181 | /*! | |
200 | Returns the \a orientation that is used when QBarModelMapper accesses the model. |
|
182 | Returns the \a orientation that is used when QBarModelMapper accesses the model. | |
201 | This mean whether the consecutive values of the pie are read from row (Qt::Horizontal) |
|
183 | This mean whether the consecutive values of the pie are read from row (Qt::Horizontal) | |
202 | or from columns (Qt::Vertical) |
|
184 | or from columns (Qt::Vertical) | |
203 | */ |
|
185 | */ | |
204 | void QBarModelMapper::setOrientation(Qt::Orientation orientation) |
|
186 | void QBarModelMapper::setOrientation(Qt::Orientation orientation) | |
205 | { |
|
187 | { | |
206 | Q_D(QBarModelMapper); |
|
188 | Q_D(QBarModelMapper); | |
207 | d->m_orientation = orientation; |
|
189 | d->m_orientation = orientation; | |
208 | d->initializeBarFromModel(); |
|
190 | d->initializeBarFromModel(); | |
209 | } |
|
191 | } | |
210 |
|
192 | |||
211 | /*! |
|
193 | /*! | |
212 | Returns which section of the model is used as the data source for the first bar set |
|
194 | Returns which section of the model is used as the data source for the first bar set | |
213 | */ |
|
195 | */ | |
214 | int QBarModelMapper::firstBarSetSection() const |
|
196 | int QBarModelMapper::firstBarSetSection() const | |
215 | { |
|
197 | { | |
216 | Q_D(const QBarModelMapper); |
|
198 | Q_D(const QBarModelMapper); | |
217 | return d->m_firstBarSetSection; |
|
199 | return d->m_firstBarSetSection; | |
218 | } |
|
200 | } | |
219 |
|
201 | |||
220 | /*! |
|
202 | /*! | |
221 | Sets the model section that is used as the data source for the first bar set |
|
203 | Sets the model section that is used as the data source for the first bar set | |
222 | Parameter \a firstBarSetSection specifies the section of the model. |
|
204 | Parameter \a firstBarSetSection specifies the section of the model. | |
223 | */ |
|
205 | */ | |
224 | void QBarModelMapper::setFirstBarSetSection(int firstBarSetSection) |
|
206 | void QBarModelMapper::setFirstBarSetSection(int firstBarSetSection) | |
225 | { |
|
207 | { | |
226 | Q_D(QBarModelMapper); |
|
208 | Q_D(QBarModelMapper); | |
227 | d->m_firstBarSetSection = qMax(-1, firstBarSetSection); |
|
209 | d->m_firstBarSetSection = qMax(-1, firstBarSetSection); | |
228 | d->initializeBarFromModel(); |
|
210 | d->initializeBarFromModel(); | |
229 | } |
|
211 | } | |
230 |
|
212 | |||
231 | /*! |
|
213 | /*! | |
232 | Returns which section of the model is used as the data source for the last bar set |
|
214 | Returns which section of the model is used as the data source for the last bar set | |
233 | */ |
|
215 | */ | |
234 | int QBarModelMapper::lastBarSetSection() const |
|
216 | int QBarModelMapper::lastBarSetSection() const | |
235 | { |
|
217 | { | |
236 | Q_D(const QBarModelMapper); |
|
218 | Q_D(const QBarModelMapper); | |
237 | return d->m_lastBarSetSection; |
|
219 | return d->m_lastBarSetSection; | |
238 | } |
|
220 | } | |
239 |
|
221 | |||
240 | /*! |
|
222 | /*! | |
241 | Sets the model section that is used as the data source for the last bar set |
|
223 | Sets the model section that is used as the data source for the last bar set | |
242 | Parameter \a lastBarSetSection specifies the section of the model. |
|
224 | Parameter \a lastBarSetSection specifies the section of the model. | |
243 | */ |
|
225 | */ | |
244 | void QBarModelMapper::setLastBarSetSection(int lastBarSetSection) |
|
226 | void QBarModelMapper::setLastBarSetSection(int lastBarSetSection) | |
245 | { |
|
227 | { | |
246 | Q_D(QBarModelMapper); |
|
228 | Q_D(QBarModelMapper); | |
247 | d->m_lastBarSetSection = qMax(-1, lastBarSetSection); |
|
229 | d->m_lastBarSetSection = qMax(-1, lastBarSetSection); | |
248 | d->initializeBarFromModel(); |
|
230 | d->initializeBarFromModel(); | |
249 | } |
|
231 | } | |
250 |
|
232 | |||
251 | /*! |
|
233 | /*! | |
252 | Resets the QBarModelMapper to the default state. |
|
234 | Resets the QBarModelMapper to the default state. | |
253 | first: 0; count: -1; firstBarSetSection: -1; lastBarSetSection: -1; categoriesSection: -1 |
|
235 | first: 0; count: -1; firstBarSetSection: -1; lastBarSetSection: -1; categoriesSection: -1 | |
254 | */ |
|
236 | */ | |
255 | void QBarModelMapper::reset() |
|
237 | void QBarModelMapper::reset() | |
256 | { |
|
238 | { | |
257 | Q_D(QBarModelMapper); |
|
239 | Q_D(QBarModelMapper); | |
258 | d->m_first = 0; |
|
240 | d->m_first = 0; | |
259 | d->m_count = -1; |
|
241 | d->m_count = -1; | |
260 | d->m_firstBarSetSection = -1; |
|
242 | d->m_firstBarSetSection = -1; | |
261 | d->m_lastBarSetSection = -1; |
|
243 | d->m_lastBarSetSection = -1; | |
262 | d->initializeBarFromModel(); |
|
244 | d->initializeBarFromModel(); | |
263 | } |
|
245 | } | |
264 |
|
246 | |||
265 | /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
247 | /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |
266 |
|
248 | |||
267 | QBarModelMapperPrivate::QBarModelMapperPrivate(QBarModelMapper *q) : |
|
249 | QBarModelMapperPrivate::QBarModelMapperPrivate(QBarModelMapper *q) : | |
268 | m_series(0), |
|
250 | m_series(0), | |
269 | m_model(0), |
|
251 | m_model(0), | |
270 | m_first(0), |
|
252 | m_first(0), | |
271 | m_count(-1), |
|
253 | m_count(-1), | |
272 | m_orientation(Qt::Vertical), |
|
254 | m_orientation(Qt::Vertical), | |
273 | m_firstBarSetSection(-1), |
|
255 | m_firstBarSetSection(-1), | |
274 | m_lastBarSetSection(-1), |
|
256 | m_lastBarSetSection(-1), | |
275 | m_seriesSignalsBlock(false), |
|
257 | m_seriesSignalsBlock(false), | |
276 | m_modelSignalsBlock(false), |
|
258 | m_modelSignalsBlock(false), | |
277 | q_ptr(q) |
|
259 | q_ptr(q) | |
278 | { |
|
260 | { | |
279 | } |
|
261 | } | |
280 |
|
262 | |||
281 | void QBarModelMapperPrivate::blockModelSignals(bool block) |
|
263 | void QBarModelMapperPrivate::blockModelSignals(bool block) | |
282 | { |
|
264 | { | |
283 | m_modelSignalsBlock = block; |
|
265 | m_modelSignalsBlock = block; | |
284 | } |
|
266 | } | |
285 |
|
267 | |||
286 | void QBarModelMapperPrivate::blockSeriesSignals(bool block) |
|
268 | void QBarModelMapperPrivate::blockSeriesSignals(bool block) | |
287 | { |
|
269 | { | |
288 | m_seriesSignalsBlock = block; |
|
270 | m_seriesSignalsBlock = block; | |
289 | } |
|
271 | } | |
290 |
|
272 | |||
291 | QBarSet* QBarModelMapperPrivate::barSet(QModelIndex index) |
|
273 | QBarSet* QBarModelMapperPrivate::barSet(QModelIndex index) | |
292 | { |
|
274 | { | |
293 | if (!index.isValid()) |
|
275 | if (!index.isValid()) | |
294 | return 0; |
|
276 | return 0; | |
295 |
|
277 | |||
296 | if (m_orientation == Qt::Vertical && index.column() >= m_firstBarSetSection && index.column() <= m_lastBarSetSection) { |
|
278 | if (m_orientation == Qt::Vertical && index.column() >= m_firstBarSetSection && index.column() <= m_lastBarSetSection) { | |
297 | if (index.row() >= m_first && (m_count == - 1 || index.row() < m_first + m_count)) { |
|
279 | if (index.row() >= m_first && (m_count == - 1 || index.row() < m_first + m_count)) { | |
298 | // if (m_model->index(index.row(), m_valuesSection).isValid() && m_model->index(index.row(), m_labelsSection).isValid()) |
|
280 | // if (m_model->index(index.row(), m_valuesSection).isValid() && m_model->index(index.row(), m_labelsSection).isValid()) | |
299 | return m_series->barSets().at(index.column() - m_firstBarSetSection); |
|
281 | return m_series->barSets().at(index.column() - m_firstBarSetSection); | |
300 | // else |
|
282 | // else | |
301 | // return 0; |
|
283 | // return 0; | |
302 | } |
|
284 | } | |
303 | } else if (m_orientation == Qt::Horizontal && index.row() >= m_firstBarSetSection && index.row() <= m_lastBarSetSection) { |
|
285 | } else if (m_orientation == Qt::Horizontal && index.row() >= m_firstBarSetSection && index.row() <= m_lastBarSetSection) { | |
304 | if (index.column() >= m_first && (m_count == - 1 || index.column() < m_first + m_count)) |
|
286 | if (index.column() >= m_first && (m_count == - 1 || index.column() < m_first + m_count)) | |
305 | return m_series->barSets().at(index.row() - m_firstBarSetSection); |
|
287 | return m_series->barSets().at(index.row() - m_firstBarSetSection); | |
306 | } |
|
288 | } | |
307 | return 0; // This part of model has not been mapped to any slice |
|
289 | return 0; // This part of model has not been mapped to any slice | |
308 | } |
|
290 | } | |
309 |
|
291 | |||
310 | QModelIndex QBarModelMapperPrivate::barModelIndex(int barSection, int posInBar) |
|
292 | QModelIndex QBarModelMapperPrivate::barModelIndex(int barSection, int posInBar) | |
311 | { |
|
293 | { | |
312 | if (m_count != -1 && posInBar >= m_count) |
|
294 | if (m_count != -1 && posInBar >= m_count) | |
313 | return QModelIndex(); // invalid |
|
295 | return QModelIndex(); // invalid | |
314 |
|
296 | |||
315 | if (barSection < m_firstBarSetSection || barSection > m_lastBarSetSection) |
|
297 | if (barSection < m_firstBarSetSection || barSection > m_lastBarSetSection) | |
316 | return QModelIndex(); // invalid |
|
298 | return QModelIndex(); // invalid | |
317 |
|
299 | |||
318 | if (m_orientation == Qt::Vertical) |
|
300 | if (m_orientation == Qt::Vertical) | |
319 | return m_model->index(posInBar + m_first, barSection); |
|
301 | return m_model->index(posInBar + m_first, barSection); | |
320 | else |
|
302 | else | |
321 | return m_model->index(barSection, posInBar + m_first); |
|
303 | return m_model->index(barSection, posInBar + m_first); | |
322 | } |
|
304 | } | |
323 |
|
305 | |||
324 | void QBarModelMapperPrivate::modelUpdated(QModelIndex topLeft, QModelIndex bottomRight) |
|
306 | void QBarModelMapperPrivate::modelUpdated(QModelIndex topLeft, QModelIndex bottomRight) | |
325 | { |
|
307 | { | |
326 | Q_UNUSED(topLeft) |
|
308 | Q_UNUSED(topLeft) | |
327 | Q_UNUSED(bottomRight) |
|
309 | Q_UNUSED(bottomRight) | |
328 |
|
310 | |||
329 | if (m_model == 0 || m_series == 0) |
|
311 | if (m_model == 0 || m_series == 0) | |
330 | return; |
|
312 | return; | |
331 |
|
313 | |||
332 | if (m_modelSignalsBlock) |
|
314 | if (m_modelSignalsBlock) | |
333 | return; |
|
315 | return; | |
334 |
|
316 | |||
335 | blockSeriesSignals(); |
|
317 | blockSeriesSignals(); | |
336 | QModelIndex index; |
|
318 | QModelIndex index; | |
337 | for (int row = topLeft.row(); row <= bottomRight.row(); row++) { |
|
319 | for (int row = topLeft.row(); row <= bottomRight.row(); row++) { | |
338 | for (int column = topLeft.column(); column <= bottomRight.column(); column++) { |
|
320 | for (int column = topLeft.column(); column <= bottomRight.column(); column++) { | |
339 | index = topLeft.sibling(row, column); |
|
321 | index = topLeft.sibling(row, column); | |
340 | QBarSet* bar = barSet(index); |
|
322 | QBarSet* bar = barSet(index); | |
341 | if (bar) { |
|
323 | if (bar) { | |
342 | if (m_orientation == Qt::Vertical) |
|
324 | if (m_orientation == Qt::Vertical) | |
343 | bar->replace(row - m_first, m_model->data(index).toReal()); |
|
325 | bar->replace(row - m_first, m_model->data(index).toReal()); | |
344 | else |
|
326 | else | |
345 | bar->replace(column - m_first, m_model->data(index).toReal()); |
|
327 | bar->replace(column - m_first, m_model->data(index).toReal()); | |
346 | } |
|
328 | } | |
347 | } |
|
329 | } | |
348 | } |
|
330 | } | |
349 | blockSeriesSignals(false); |
|
331 | blockSeriesSignals(false); | |
350 | } |
|
332 | } | |
351 |
|
333 | |||
352 | void QBarModelMapperPrivate::modelHeaderDataUpdated(Qt::Orientation orientation, int first, int last) |
|
334 | void QBarModelMapperPrivate::modelHeaderDataUpdated(Qt::Orientation orientation, int first, int last) | |
353 | { |
|
335 | { | |
354 | if (m_model == 0 || m_series == 0) |
|
336 | if (m_model == 0 || m_series == 0) | |
355 | return; |
|
337 | return; | |
356 |
|
338 | |||
357 | if (m_modelSignalsBlock) |
|
339 | if (m_modelSignalsBlock) | |
358 | return; |
|
340 | return; | |
359 |
|
341 | |||
360 | blockSeriesSignals(); |
|
342 | blockSeriesSignals(); | |
361 | if (orientation != m_orientation) { |
|
343 | if (orientation != m_orientation) { | |
362 | for (int section = first; section <= last; section++) { |
|
344 | for (int section = first; section <= last; section++) { | |
363 | if (section >= m_firstBarSetSection && section <= m_lastBarSetSection) { |
|
345 | if (section >= m_firstBarSetSection && section <= m_lastBarSetSection) { | |
364 | QBarSet* bar = m_series->barSets().at(section - m_firstBarSetSection); |
|
346 | QBarSet* bar = m_series->barSets().at(section - m_firstBarSetSection); | |
365 | if (bar) |
|
347 | if (bar) | |
366 | bar->setLabel(m_model->headerData(section, orientation).toString()); |
|
348 | bar->setLabel(m_model->headerData(section, orientation).toString()); | |
367 | } |
|
349 | } | |
368 | } |
|
350 | } | |
369 | } |
|
351 | } | |
370 | blockSeriesSignals(false); |
|
352 | blockSeriesSignals(false); | |
371 | } |
|
353 | } | |
372 |
|
354 | |||
373 | void QBarModelMapperPrivate::modelRowsAdded(QModelIndex parent, int start, int end) |
|
355 | void QBarModelMapperPrivate::modelRowsAdded(QModelIndex parent, int start, int end) | |
374 | { |
|
356 | { | |
375 | Q_UNUSED(parent); |
|
357 | Q_UNUSED(parent); | |
376 | Q_UNUSED(end) |
|
358 | Q_UNUSED(end) | |
377 | if (m_modelSignalsBlock) |
|
359 | if (m_modelSignalsBlock) | |
378 | return; |
|
360 | return; | |
379 |
|
361 | |||
380 | blockSeriesSignals(); |
|
362 | blockSeriesSignals(); | |
381 | if (m_orientation == Qt::Vertical) |
|
363 | if (m_orientation == Qt::Vertical) | |
382 | // insertData(start, end); |
|
364 | // insertData(start, end); | |
383 | initializeBarFromModel(); |
|
365 | initializeBarFromModel(); | |
384 | else if (start <= m_firstBarSetSection || start <= m_lastBarSetSection) // if the changes affect the map - reinitialize |
|
366 | else if (start <= m_firstBarSetSection || start <= m_lastBarSetSection) // if the changes affect the map - reinitialize | |
385 | initializeBarFromModel(); |
|
367 | initializeBarFromModel(); | |
386 | blockSeriesSignals(false); |
|
368 | blockSeriesSignals(false); | |
387 | } |
|
369 | } | |
388 |
|
370 | |||
389 | void QBarModelMapperPrivate::modelRowsRemoved(QModelIndex parent, int start, int end) |
|
371 | void QBarModelMapperPrivate::modelRowsRemoved(QModelIndex parent, int start, int end) | |
390 | { |
|
372 | { | |
391 | Q_UNUSED(parent); |
|
373 | Q_UNUSED(parent); | |
392 | Q_UNUSED(end) |
|
374 | Q_UNUSED(end) | |
393 | if (m_modelSignalsBlock) |
|
375 | if (m_modelSignalsBlock) | |
394 | return; |
|
376 | return; | |
395 |
|
377 | |||
396 | blockSeriesSignals(); |
|
378 | blockSeriesSignals(); | |
397 | if (m_orientation == Qt::Vertical) |
|
379 | if (m_orientation == Qt::Vertical) | |
398 | // removeData(start, end); |
|
380 | // removeData(start, end); | |
399 | initializeBarFromModel(); |
|
381 | initializeBarFromModel(); | |
400 | else if (start <= m_firstBarSetSection || start <= m_lastBarSetSection) // if the changes affect the map - reinitialize |
|
382 | else if (start <= m_firstBarSetSection || start <= m_lastBarSetSection) // if the changes affect the map - reinitialize | |
401 | initializeBarFromModel(); |
|
383 | initializeBarFromModel(); | |
402 | blockSeriesSignals(false); |
|
384 | blockSeriesSignals(false); | |
403 | } |
|
385 | } | |
404 |
|
386 | |||
405 | void QBarModelMapperPrivate::modelColumnsAdded(QModelIndex parent, int start, int end) |
|
387 | void QBarModelMapperPrivate::modelColumnsAdded(QModelIndex parent, int start, int end) | |
406 | { |
|
388 | { | |
407 | Q_UNUSED(parent); |
|
389 | Q_UNUSED(parent); | |
408 | Q_UNUSED(end) |
|
390 | Q_UNUSED(end) | |
409 | if (m_modelSignalsBlock) |
|
391 | if (m_modelSignalsBlock) | |
410 | return; |
|
392 | return; | |
411 |
|
393 | |||
412 | blockSeriesSignals(); |
|
394 | blockSeriesSignals(); | |
413 | if (m_orientation == Qt::Horizontal) |
|
395 | if (m_orientation == Qt::Horizontal) | |
414 | // insertData(start, end); |
|
396 | // insertData(start, end); | |
415 | initializeBarFromModel(); |
|
397 | initializeBarFromModel(); | |
416 | else if (start <= m_firstBarSetSection || start <= m_lastBarSetSection) // if the changes affect the map - reinitialize |
|
398 | else if (start <= m_firstBarSetSection || start <= m_lastBarSetSection) // if the changes affect the map - reinitialize | |
417 | initializeBarFromModel(); |
|
399 | initializeBarFromModel(); | |
418 | blockSeriesSignals(false); |
|
400 | blockSeriesSignals(false); | |
419 | } |
|
401 | } | |
420 |
|
402 | |||
421 | void QBarModelMapperPrivate::modelColumnsRemoved(QModelIndex parent, int start, int end) |
|
403 | void QBarModelMapperPrivate::modelColumnsRemoved(QModelIndex parent, int start, int end) | |
422 | { |
|
404 | { | |
423 | Q_UNUSED(parent); |
|
405 | Q_UNUSED(parent); | |
424 | Q_UNUSED(end) |
|
406 | Q_UNUSED(end) | |
425 | if (m_modelSignalsBlock) |
|
407 | if (m_modelSignalsBlock) | |
426 | return; |
|
408 | return; | |
427 |
|
409 | |||
428 | blockSeriesSignals(); |
|
410 | blockSeriesSignals(); | |
429 | if (m_orientation == Qt::Horizontal) |
|
411 | if (m_orientation == Qt::Horizontal) | |
430 | // removeData(start, end); |
|
412 | // removeData(start, end); | |
431 | initializeBarFromModel(); |
|
413 | initializeBarFromModel(); | |
432 | else if (start <= m_firstBarSetSection || start <= m_lastBarSetSection) // if the changes affect the map - reinitialize |
|
414 | else if (start <= m_firstBarSetSection || start <= m_lastBarSetSection) // if the changes affect the map - reinitialize | |
433 | initializeBarFromModel(); |
|
415 | initializeBarFromModel(); | |
434 | blockSeriesSignals(false); |
|
416 | blockSeriesSignals(false); | |
435 | } |
|
417 | } | |
436 |
|
418 | |||
437 | void QBarModelMapperPrivate::insertData(int start, int end) |
|
419 | void QBarModelMapperPrivate::insertData(int start, int end) | |
438 | { |
|
420 | { | |
439 | Q_UNUSED(end) |
|
421 | Q_UNUSED(end) | |
440 | Q_UNUSED(start) |
|
422 | Q_UNUSED(start) | |
441 | Q_UNUSED(end) |
|
423 | Q_UNUSED(end) | |
442 | // To be implemented |
|
424 | // To be implemented | |
443 | } |
|
425 | } | |
444 |
|
426 | |||
445 | void QBarModelMapperPrivate::removeData(int start, int end) |
|
427 | void QBarModelMapperPrivate::removeData(int start, int end) | |
446 | { |
|
428 | { | |
447 | Q_UNUSED(end) |
|
429 | Q_UNUSED(end) | |
448 | Q_UNUSED(start) |
|
430 | Q_UNUSED(start) | |
449 | Q_UNUSED(end) |
|
431 | Q_UNUSED(end) | |
450 | // To be implemented |
|
432 | // To be implemented | |
451 | } |
|
433 | } | |
452 |
|
434 | |||
453 | void QBarModelMapperPrivate::barSetsAdded(QList<QBarSet*> sets) |
|
435 | void QBarModelMapperPrivate::barSetsAdded(QList<QBarSet*> sets) | |
454 | { |
|
436 | { | |
455 | if (m_seriesSignalsBlock) |
|
437 | if (m_seriesSignalsBlock) | |
456 | return; |
|
438 | return; | |
457 |
|
439 | |||
458 | if (sets.count() == 0) |
|
440 | if (sets.count() == 0) | |
459 | return; |
|
441 | return; | |
460 |
|
442 | |||
461 | int firstIndex = m_series->barSets().indexOf(sets.at(0)); |
|
443 | int firstIndex = m_series->barSets().indexOf(sets.at(0)); | |
462 | if (firstIndex == -1) |
|
444 | if (firstIndex == -1) | |
463 | return; |
|
445 | return; | |
464 |
|
446 | |||
465 | int maxCount = 0; |
|
447 | int maxCount = 0; | |
466 | for(int i = 0; i < sets.count(); i++) |
|
448 | for(int i = 0; i < sets.count(); i++) | |
467 | if (sets.at(i)->count() > m_count) |
|
449 | if (sets.at(i)->count() > m_count) | |
468 | maxCount = sets.at(i)->count(); |
|
450 | maxCount = sets.at(i)->count(); | |
469 |
|
451 | |||
470 | if (m_count != -1 && m_count < maxCount) |
|
452 | if (m_count != -1 && m_count < maxCount) | |
471 | m_count = maxCount; |
|
453 | m_count = maxCount; | |
472 |
|
454 | |||
473 | m_lastBarSetSection += sets.count(); |
|
455 | m_lastBarSetSection += sets.count(); | |
474 |
|
456 | |||
475 | blockModelSignals(); |
|
457 | blockModelSignals(); | |
476 | int modelCapacity = m_orientation == Qt::Vertical ? m_model->rowCount() - m_first : m_model->columnCount() - m_first; |
|
458 | int modelCapacity = m_orientation == Qt::Vertical ? m_model->rowCount() - m_first : m_model->columnCount() - m_first; | |
477 | if (maxCount > modelCapacity) { |
|
459 | if (maxCount > modelCapacity) { | |
478 | if (m_orientation == Qt::Vertical) |
|
460 | if (m_orientation == Qt::Vertical) | |
479 | m_model->insertRows(m_model->rowCount(), maxCount - modelCapacity); |
|
461 | m_model->insertRows(m_model->rowCount(), maxCount - modelCapacity); | |
480 | else |
|
462 | else | |
481 | m_model->insertColumns(m_model->columnCount(), maxCount - modelCapacity); |
|
463 | m_model->insertColumns(m_model->columnCount(), maxCount - modelCapacity); | |
482 | } |
|
464 | } | |
483 |
|
465 | |||
484 | if (m_orientation == Qt::Vertical) |
|
466 | if (m_orientation == Qt::Vertical) | |
485 | m_model->insertColumns(firstIndex + m_firstBarSetSection, sets.count()); |
|
467 | m_model->insertColumns(firstIndex + m_firstBarSetSection, sets.count()); | |
486 | else |
|
468 | else | |
487 | m_model->insertRows(firstIndex + m_firstBarSetSection, sets.count()); |
|
469 | m_model->insertRows(firstIndex + m_firstBarSetSection, sets.count()); | |
488 |
|
470 | |||
489 |
|
471 | |||
490 | for(int i = firstIndex + m_firstBarSetSection; i < firstIndex + m_firstBarSetSection + sets.count(); i++) { |
|
472 | for(int i = firstIndex + m_firstBarSetSection; i < firstIndex + m_firstBarSetSection + sets.count(); i++) { | |
491 | m_model->setHeaderData(i, m_orientation == Qt::Vertical ? Qt::Horizontal : Qt::Vertical, sets.at(i - firstIndex - m_firstBarSetSection)->label()); |
|
473 | m_model->setHeaderData(i, m_orientation == Qt::Vertical ? Qt::Horizontal : Qt::Vertical, sets.at(i - firstIndex - m_firstBarSetSection)->label()); | |
492 | for (int j = 0; j < sets.at(i - firstIndex - m_firstBarSetSection)->count(); j++) |
|
474 | for (int j = 0; j < sets.at(i - firstIndex - m_firstBarSetSection)->count(); j++) | |
493 | m_model->setData(barModelIndex(i, j), sets.at(i - firstIndex - m_firstBarSetSection)->at(j).y()); |
|
475 | m_model->setData(barModelIndex(i, j), sets.at(i - firstIndex - m_firstBarSetSection)->at(j).y()); | |
494 | } |
|
476 | } | |
495 | blockModelSignals(false); |
|
477 | blockModelSignals(false); | |
496 | initializeBarFromModel(); |
|
478 | initializeBarFromModel(); | |
497 | } |
|
479 | } | |
498 |
|
480 | |||
499 | void QBarModelMapperPrivate::barSetsRemoved(QList<QBarSet*> sets) |
|
481 | void QBarModelMapperPrivate::barSetsRemoved(QList<QBarSet*> sets) | |
500 | { |
|
482 | { | |
501 | if (m_seriesSignalsBlock) |
|
483 | if (m_seriesSignalsBlock) | |
502 | return; |
|
484 | return; | |
503 |
|
485 | |||
504 | if (sets.count() == 0) |
|
486 | if (sets.count() == 0) | |
505 | return; |
|
487 | return; | |
506 |
|
488 | |||
507 | int firstIndex = m_barSets.indexOf(sets.at(0)); |
|
489 | int firstIndex = m_barSets.indexOf(sets.at(0)); | |
508 | if (firstIndex == -1) |
|
490 | if (firstIndex == -1) | |
509 | return; |
|
491 | return; | |
510 |
|
492 | |||
511 | m_lastBarSetSection -= sets.count(); |
|
493 | m_lastBarSetSection -= sets.count(); | |
512 |
|
494 | |||
513 | for (int i = firstIndex + sets.count() - 1; i >= firstIndex; i--) |
|
495 | for (int i = firstIndex + sets.count() - 1; i >= firstIndex; i--) | |
514 | m_barSets.removeAt(i); |
|
496 | m_barSets.removeAt(i); | |
515 |
|
497 | |||
516 | blockModelSignals(); |
|
498 | blockModelSignals(); | |
517 | if (m_orientation == Qt::Vertical) |
|
499 | if (m_orientation == Qt::Vertical) | |
518 | m_model->removeColumns(firstIndex + m_firstBarSetSection, sets.count()); |
|
500 | m_model->removeColumns(firstIndex + m_firstBarSetSection, sets.count()); | |
519 | else |
|
501 | else | |
520 | m_model->removeRows(firstIndex + m_firstBarSetSection, sets.count()); |
|
502 | m_model->removeRows(firstIndex + m_firstBarSetSection, sets.count()); | |
521 | blockModelSignals(false); |
|
503 | blockModelSignals(false); | |
522 | initializeBarFromModel(); |
|
504 | initializeBarFromModel(); | |
523 | } |
|
505 | } | |
524 |
|
506 | |||
525 | void QBarModelMapperPrivate::valuesAdded(int index, int count) |
|
507 | void QBarModelMapperPrivate::valuesAdded(int index, int count) | |
526 | { |
|
508 | { | |
527 | if (m_seriesSignalsBlock) |
|
509 | if (m_seriesSignalsBlock) | |
528 | return; |
|
510 | return; | |
529 |
|
511 | |||
530 | if (m_count != -1) |
|
512 | if (m_count != -1) | |
531 | m_count += count; |
|
513 | m_count += count; | |
532 |
|
514 | |||
533 | int barSetIndex = m_barSets.indexOf(qobject_cast<QBarSet *>(QObject::sender())); |
|
515 | int barSetIndex = m_barSets.indexOf(qobject_cast<QBarSet *>(QObject::sender())); | |
534 |
|
516 | |||
535 | blockModelSignals(); |
|
517 | blockModelSignals(); | |
536 | if (m_orientation == Qt::Vertical) |
|
518 | if (m_orientation == Qt::Vertical) | |
537 | m_model->insertRows(index + m_first, count); |
|
519 | m_model->insertRows(index + m_first, count); | |
538 | else |
|
520 | else | |
539 | m_model->insertColumns(index + m_first, count); |
|
521 | m_model->insertColumns(index + m_first, count); | |
540 |
|
522 | |||
541 | for (int j = index; j < index + count; j++) |
|
523 | for (int j = index; j < index + count; j++) | |
542 | m_model->setData(barModelIndex(barSetIndex + m_firstBarSetSection, j), m_barSets.at(barSetIndex)->at(j).y()); |
|
524 | m_model->setData(barModelIndex(barSetIndex + m_firstBarSetSection, j), m_barSets.at(barSetIndex)->at(j).y()); | |
543 |
|
525 | |||
544 | blockModelSignals(false); |
|
526 | blockModelSignals(false); | |
545 | initializeBarFromModel(); |
|
527 | initializeBarFromModel(); | |
546 | } |
|
528 | } | |
547 |
|
529 | |||
548 | void QBarModelMapperPrivate::valuesRemoved(int index, int count) |
|
530 | void QBarModelMapperPrivate::valuesRemoved(int index, int count) | |
549 | { |
|
531 | { | |
550 | if (m_seriesSignalsBlock) |
|
532 | if (m_seriesSignalsBlock) | |
551 | return; |
|
533 | return; | |
552 |
|
534 | |||
553 | if (m_count != -1) |
|
535 | if (m_count != -1) | |
554 | m_count -= count; |
|
536 | m_count -= count; | |
555 |
|
537 | |||
556 | blockModelSignals(); |
|
538 | blockModelSignals(); | |
557 | if (m_orientation == Qt::Vertical) |
|
539 | if (m_orientation == Qt::Vertical) | |
558 | m_model->removeRows(index + m_first, count); |
|
540 | m_model->removeRows(index + m_first, count); | |
559 | else |
|
541 | else | |
560 | m_model->removeColumns(index + m_first, count); |
|
542 | m_model->removeColumns(index + m_first, count); | |
561 |
|
543 | |||
562 | blockModelSignals(false); |
|
544 | blockModelSignals(false); | |
563 | initializeBarFromModel(); |
|
545 | initializeBarFromModel(); | |
564 | } |
|
546 | } | |
565 |
|
547 | |||
566 | void QBarModelMapperPrivate::barLabelChanged() |
|
548 | void QBarModelMapperPrivate::barLabelChanged() | |
567 | { |
|
549 | { | |
568 | if (m_seriesSignalsBlock) |
|
550 | if (m_seriesSignalsBlock) | |
569 | return; |
|
551 | return; | |
570 |
|
552 | |||
571 | int barSetIndex = m_barSets.indexOf(qobject_cast<QBarSet *>(QObject::sender())); |
|
553 | int barSetIndex = m_barSets.indexOf(qobject_cast<QBarSet *>(QObject::sender())); | |
572 |
|
554 | |||
573 | blockModelSignals(); |
|
555 | blockModelSignals(); | |
574 | m_model->setHeaderData(barSetIndex + m_firstBarSetSection, m_orientation == Qt::Vertical ? Qt::Horizontal : Qt::Vertical, m_barSets.at(barSetIndex)->label()); |
|
556 | m_model->setHeaderData(barSetIndex + m_firstBarSetSection, m_orientation == Qt::Vertical ? Qt::Horizontal : Qt::Vertical, m_barSets.at(barSetIndex)->label()); | |
575 | blockModelSignals(false); |
|
557 | blockModelSignals(false); | |
576 | initializeBarFromModel(); |
|
558 | initializeBarFromModel(); | |
577 | } |
|
559 | } | |
578 |
|
560 | |||
579 | void QBarModelMapperPrivate::barValueChanged(int index) |
|
561 | void QBarModelMapperPrivate::barValueChanged(int index) | |
580 | { |
|
562 | { | |
581 | if (m_seriesSignalsBlock) |
|
563 | if (m_seriesSignalsBlock) | |
582 | return; |
|
564 | return; | |
583 |
|
565 | |||
584 | int barSetIndex = m_barSets.indexOf(qobject_cast<QBarSet *>(QObject::sender())); |
|
566 | int barSetIndex = m_barSets.indexOf(qobject_cast<QBarSet *>(QObject::sender())); | |
585 |
|
567 | |||
586 | blockModelSignals(); |
|
568 | blockModelSignals(); | |
587 | m_model->setData(barModelIndex(barSetIndex + m_firstBarSetSection, index), m_barSets.at(barSetIndex)->at(index).y()); |
|
569 | m_model->setData(barModelIndex(barSetIndex + m_firstBarSetSection, index), m_barSets.at(barSetIndex)->at(index).y()); | |
588 | blockModelSignals(false); |
|
570 | blockModelSignals(false); | |
589 | initializeBarFromModel(); |
|
571 | initializeBarFromModel(); | |
590 | } |
|
572 | } | |
591 |
|
573 | |||
592 | void QBarModelMapperPrivate::initializeBarFromModel() |
|
574 | void QBarModelMapperPrivate::initializeBarFromModel() | |
593 | { |
|
575 | { | |
594 | if (m_model == 0 || m_series == 0) |
|
576 | if (m_model == 0 || m_series == 0) | |
595 | return; |
|
577 | return; | |
596 |
|
578 | |||
597 | blockSeriesSignals(); |
|
579 | blockSeriesSignals(); | |
598 | // clear current content |
|
580 | // clear current content | |
599 | m_series->clear(); |
|
581 | m_series->clear(); | |
600 | m_barSets.clear(); |
|
582 | m_barSets.clear(); | |
601 |
|
583 | |||
602 | // create the initial bar sets |
|
584 | // create the initial bar sets | |
603 | for (int i = m_firstBarSetSection; i <= m_lastBarSetSection; i++) { |
|
585 | for (int i = m_firstBarSetSection; i <= m_lastBarSetSection; i++) { | |
604 | int posInBar = 0; |
|
586 | int posInBar = 0; | |
605 | QModelIndex barIndex = barModelIndex(i, posInBar); |
|
587 | QModelIndex barIndex = barModelIndex(i, posInBar); | |
606 | // check if there is such model index |
|
588 | // check if there is such model index | |
607 | if (barIndex.isValid()) { |
|
589 | if (barIndex.isValid()) { | |
608 | QBarSet *barSet = new QBarSet(m_model->headerData(i, m_orientation == Qt::Vertical ? Qt::Horizontal : Qt::Vertical).toString()); |
|
590 | QBarSet *barSet = new QBarSet(m_model->headerData(i, m_orientation == Qt::Vertical ? Qt::Horizontal : Qt::Vertical).toString()); | |
609 | while (barIndex.isValid()) { |
|
591 | while (barIndex.isValid()) { | |
610 | barSet->append(m_model->data(barIndex, Qt::DisplayRole).toDouble()); |
|
592 | barSet->append(m_model->data(barIndex, Qt::DisplayRole).toDouble()); | |
611 | posInBar++; |
|
593 | posInBar++; | |
612 | barIndex = barModelIndex(i, posInBar); |
|
594 | barIndex = barModelIndex(i, posInBar); | |
613 | } |
|
595 | } | |
614 | connect(barSet, SIGNAL(valuesAdded(int, int)), this, SLOT(valuesAdded(int, int))); |
|
596 | connect(barSet, SIGNAL(valuesAdded(int, int)), this, SLOT(valuesAdded(int, int))); | |
615 | connect(barSet, SIGNAL(valuesRemoved(int, int)), this, SLOT(valuesRemoved(int, int))); |
|
597 | connect(barSet, SIGNAL(valuesRemoved(int, int)), this, SLOT(valuesRemoved(int, int))); | |
616 | connect(barSet, SIGNAL(valueChanged(int)), this, SLOT(barValueChanged(int))); |
|
598 | connect(barSet, SIGNAL(valueChanged(int)), this, SLOT(barValueChanged(int))); | |
617 | connect(barSet, SIGNAL(labelChanged()), this, SLOT(barLabelChanged())); |
|
599 | connect(barSet, SIGNAL(labelChanged()), this, SLOT(barLabelChanged())); | |
618 | m_series->append(barSet); |
|
600 | m_series->append(barSet); | |
619 | m_barSets.append(barSet); |
|
601 | m_barSets.append(barSet); | |
620 | } else { |
|
602 | } else { | |
621 | break; |
|
603 | break; | |
622 | } |
|
604 | } | |
623 | } |
|
605 | } | |
624 | blockSeriesSignals(false); |
|
606 | blockSeriesSignals(false); | |
625 | } |
|
607 | } | |
626 |
|
608 | |||
627 | #include "moc_qbarmodelmapper.cpp" |
|
609 | #include "moc_qbarmodelmapper.cpp" | |
628 | #include "moc_qbarmodelmapper_p.cpp" |
|
610 | #include "moc_qbarmodelmapper_p.cpp" | |
629 |
|
611 | |||
630 | QTCOMMERCIALCHART_END_NAMESPACE |
|
612 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,178 +1,199 | |||||
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 part of QtCommercial chart API. |
|
27 | \brief part of QtCommercial chart API. | |
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 |
|
37 | \qmlclass HBarModelMapper QHBarModelMapper | |
38 | \inherits BarModelMapper |
|
|||
39 | \mainclass |
|
38 | \mainclass | |
40 |
|
39 | |||
41 | HBarModelMapper allows you to use your own QAbstractItemModel derived model with data in rows as a data source |
|
40 | HBarModelMapper allows you to use your own QAbstractItemModel derived model with data in rows as a data source | |
42 | for any bar series. The following QML example would create a bar series with three bar sets (assuming the model has |
|
41 | for any bar series. Adding/removing value from the BarSet causes the the same change in the rest of the BarSets | |
43 | at least four rows). Each bar set would contain data starting from column 1. The name of a set would be defined |
|
42 | added to the same series. The following QML example would create a bar series with three bar sets (assuming the | |
44 | by the vertical header (of the row). |
|
43 | model has at least four rows). Each bar set would contain data starting from column 1. The name of a set would be | |
|
44 | defined by the vertical header (of the row). | |||
45 | \code |
|
45 | \code | |
46 | BarSeries { |
|
46 | BarSeries { | |
47 | HBarModelMapper { |
|
47 | HBarModelMapper { | |
48 | model: myCustomModel |
|
48 | model: myCustomModel // QAbstractItemModel derived implementation | |
49 | firstBarSetRow: 1 |
|
49 | firstBarSetRow: 1 | |
50 | lastBarSetRow: 3 |
|
50 | lastBarSetRow: 3 | |
51 | firstColumn: 1 |
|
51 | firstColumn: 1 | |
52 | } |
|
52 | } | |
53 | } |
|
53 | } | |
54 | \endcode |
|
54 | \endcode | |
55 | */ |
|
55 | */ | |
56 |
|
56 | |||
57 | /*! |
|
57 | /*! | |
|
58 | \qmlproperty BarSeries HBarModelMapper::series | |||
|
59 | Defines the BarSeries based object that is used by the mapper. All the data in the series is discarded when it is | |||
|
60 | set to the mapper. When new series is specified the old series is disconnected (it preserves its data). | |||
|
61 | */ | |||
|
62 | ||||
|
63 | /*! | |||
|
64 | \qmlproperty Model HBarModelMapper::model | |||
|
65 | The QAbstractItemModel based model that is used by the mapper. You need to implement the model and expose it to | |||
|
66 | QML as shown in \l {QML Custom Model} demo application. NOTE: the model has to support adding/removing rows/columns | |||
|
67 | and modifying the data of the cells. | |||
|
68 | */ | |||
|
69 | ||||
|
70 | /*! | |||
58 | \property QHBarModelMapper::firstBarSetRow |
|
71 | \property QHBarModelMapper::firstBarSetRow | |
59 | \brief Defines which column of the model is used as the data source for the first bar set |
|
72 | \brief Defines which column of the model is used as the data source for the first bar set | |
60 |
|
||||
61 | Default value is: -1 (invalid mapping) |
|
73 | Default value is: -1 (invalid mapping) | |
62 | */ |
|
74 | */ | |
|
75 | /*! | |||
|
76 | \qmlproperty int HBarModelMapper::firstBarSetRow | |||
|
77 | Defines which column of the model is used as the data source for the first bar set. The default value is -1 | |||
|
78 | (invalid mapping). | |||
|
79 | */ | |||
63 |
|
80 | |||
64 | /*! |
|
81 | /*! | |
65 | \property QHBarModelMapper::lastBarSetRow |
|
82 | \property QHBarModelMapper::lastBarSetRow | |
66 | \brief Defines which column of the model is used as the data source for the last bar set |
|
83 | \brief Defines which column of the model is used as the data source for the last bar set | |
67 |
|
||||
68 | Default value is: -1 (invalid mapping) |
|
84 | Default value is: -1 (invalid mapping) | |
69 | */ |
|
85 | */ | |
|
86 | /*! | |||
|
87 | \qmlproperty int HBarModelMapper::lastBarSetRow | |||
|
88 | Defines which column of the model is used as the data source for the last bar set. The default value is -1 | |||
|
89 | (invalid mapping). | |||
|
90 | */ | |||
70 |
|
91 | |||
71 | /*! |
|
92 | /*! | |
72 | \property QHBarModelMapper::firstColumn |
|
93 | \property QHBarModelMapper::firstColumn | |
73 | \brief Defines which column of the model contains the first values of the QBarSets in the series. |
|
94 | \brief Defines which column of the model contains the first values of the QBarSets in the series. | |
74 | Minimal and default value is: 0 |
|
95 | Minimal and default value is: 0 | |
75 | */ |
|
96 | */ | |
76 | /*! |
|
97 | /*! | |
77 | \qmlproperty int BarModelMapper::firstColumn |
|
98 | \qmlproperty int HBarModelMapper::firstColumn | |
78 | Defines which column of the model contains the first values of the QBarSets in the series. |
|
99 | Defines which column of the model contains the first values of the QBarSets in the series. | |
79 | The default value is 0. |
|
100 | The default value is 0. | |
80 | */ |
|
101 | */ | |
81 |
|
102 | |||
82 | /*! |
|
103 | /*! | |
83 | \property QHBarModelMapper::columnCount |
|
104 | \property QHBarModelMapper::columnCount | |
84 |
\brief Defines the number of |
|
105 | \brief Defines the number of columns of the model that are mapped as the data for QBarSeries | |
85 |
Minimal and default value is: -1 (count limited by the number of |
|
106 | Minimal and default value is: -1 (count limited by the number of columns in the model) | |
86 | */ |
|
107 | */ | |
87 | /*! |
|
108 | /*! | |
88 | \qmlproperty int BarModelMapper::columnCount |
|
109 | \qmlproperty int HBarModelMapper::columnCount | |
89 |
Defines the number of |
|
110 | Defines the number of columns of the model that are mapped as the data for QBarSeries. The default value is | |
90 |
-1 (count limited by the number of |
|
111 | -1 (count limited by the number of columns in the model) | |
91 | */ |
|
112 | */ | |
92 |
|
113 | |||
93 | /*! |
|
114 | /*! | |
94 | \fn void QHBarModelMapper::firstBarSetRowChanged() |
|
115 | \fn void QHBarModelMapper::firstBarSetRowChanged() | |
95 |
|
116 | |||
96 | Emitted when the firstBarSetRow has changed. |
|
117 | Emitted when the firstBarSetRow has changed. | |
97 | */ |
|
118 | */ | |
98 |
|
119 | |||
99 | /*! |
|
120 | /*! | |
100 | \fn void QHBarModelMapper::lastBarSetRowChanged() |
|
121 | \fn void QHBarModelMapper::lastBarSetRowChanged() | |
101 |
|
122 | |||
102 | Emitted when the lastBarSetRow has changed. |
|
123 | Emitted when the lastBarSetRow has changed. | |
103 | */ |
|
124 | */ | |
104 |
|
125 | |||
105 | /*! |
|
126 | /*! | |
106 | \fn void QHBarModelMapper::firstColumnChanged() |
|
127 | \fn void QHBarModelMapper::firstColumnChanged() | |
107 | Emitted when the firstColumn has changed. |
|
128 | Emitted when the firstColumn has changed. | |
108 | */ |
|
129 | */ | |
109 |
|
130 | |||
110 | /*! |
|
131 | /*! | |
111 | \fn void QHBarModelMapper::columnCountChanged() |
|
132 | \fn void QHBarModelMapper::columnCountChanged() | |
112 | Emitted when the columnCount has changed. |
|
133 | Emitted when the columnCount has changed. | |
113 | */ |
|
134 | */ | |
114 |
|
135 | |||
115 | /*! |
|
136 | /*! | |
116 | Constructs a mapper object which is a child of \a parent. |
|
137 | Constructs a mapper object which is a child of \a parent. | |
117 | */ |
|
138 | */ | |
118 | QHBarModelMapper::QHBarModelMapper(QObject *parent) : |
|
139 | QHBarModelMapper::QHBarModelMapper(QObject *parent) : | |
119 | QBarModelMapper(parent) |
|
140 | QBarModelMapper(parent) | |
120 | { |
|
141 | { | |
121 | QBarModelMapper::setOrientation(Qt::Horizontal); |
|
142 | QBarModelMapper::setOrientation(Qt::Horizontal); | |
122 | } |
|
143 | } | |
123 |
|
144 | |||
124 | int QHBarModelMapper::firstBarSetRow() const |
|
145 | int QHBarModelMapper::firstBarSetRow() const | |
125 | { |
|
146 | { | |
126 | return QBarModelMapper::firstBarSetSection(); |
|
147 | return QBarModelMapper::firstBarSetSection(); | |
127 | } |
|
148 | } | |
128 |
|
149 | |||
129 | void QHBarModelMapper::setFirstBarSetRow(int firstBarSetRow) |
|
150 | void QHBarModelMapper::setFirstBarSetRow(int firstBarSetRow) | |
130 | { |
|
151 | { | |
131 | if (firstBarSetRow != firstBarSetSection()) { |
|
152 | if (firstBarSetRow != firstBarSetSection()) { | |
132 | QBarModelMapper::setFirstBarSetSection(firstBarSetRow); |
|
153 | QBarModelMapper::setFirstBarSetSection(firstBarSetRow); | |
133 | emit firstBarSetRowChanged(); |
|
154 | emit firstBarSetRowChanged(); | |
134 | } |
|
155 | } | |
135 | } |
|
156 | } | |
136 |
|
157 | |||
137 | int QHBarModelMapper::lastBarSetRow() const |
|
158 | int QHBarModelMapper::lastBarSetRow() const | |
138 | { |
|
159 | { | |
139 | return QBarModelMapper::lastBarSetSection(); |
|
160 | return QBarModelMapper::lastBarSetSection(); | |
140 | } |
|
161 | } | |
141 |
|
162 | |||
142 | void QHBarModelMapper::setLastBarSetRow(int lastBarSetRow) |
|
163 | void QHBarModelMapper::setLastBarSetRow(int lastBarSetRow) | |
143 | { |
|
164 | { | |
144 | if (lastBarSetRow != lastBarSetSection()) { |
|
165 | if (lastBarSetRow != lastBarSetSection()) { | |
145 | QBarModelMapper::setLastBarSetSection(lastBarSetRow); |
|
166 | QBarModelMapper::setLastBarSetSection(lastBarSetRow); | |
146 | emit lastBarSetRowChanged(); |
|
167 | emit lastBarSetRowChanged(); | |
147 | } |
|
168 | } | |
148 | } |
|
169 | } | |
149 |
|
170 | |||
150 | int QHBarModelMapper::firstColumn() const |
|
171 | int QHBarModelMapper::firstColumn() const | |
151 | { |
|
172 | { | |
152 | return QBarModelMapper::first(); |
|
173 | return QBarModelMapper::first(); | |
153 | } |
|
174 | } | |
154 |
|
175 | |||
155 | void QHBarModelMapper::setFirstColumn(int firstColumn) |
|
176 | void QHBarModelMapper::setFirstColumn(int firstColumn) | |
156 | { |
|
177 | { | |
157 | if (firstColumn != first()) { |
|
178 | if (firstColumn != first()) { | |
158 | QBarModelMapper::setFirst(firstColumn); |
|
179 | QBarModelMapper::setFirst(firstColumn); | |
159 | emit firstColumnChanged(); |
|
180 | emit firstColumnChanged(); | |
160 | } |
|
181 | } | |
161 | } |
|
182 | } | |
162 |
|
183 | |||
163 | int QHBarModelMapper::columnCount() const |
|
184 | int QHBarModelMapper::columnCount() const | |
164 | { |
|
185 | { | |
165 | return QBarModelMapper::count(); |
|
186 | return QBarModelMapper::count(); | |
166 | } |
|
187 | } | |
167 |
|
188 | |||
168 | void QHBarModelMapper::setColumnCount(int columnCount) |
|
189 | void QHBarModelMapper::setColumnCount(int columnCount) | |
169 | { |
|
190 | { | |
170 | if (columnCount != count()) { |
|
191 | if (columnCount != count()) { | |
171 | QBarModelMapper::setCount(columnCount); |
|
192 | QBarModelMapper::setCount(columnCount); | |
172 | emit firstColumnChanged(); |
|
193 | emit firstColumnChanged(); | |
173 | } |
|
194 | } | |
174 | } |
|
195 | } | |
175 |
|
196 | |||
176 | #include "moc_qhbarmodelmapper.cpp" |
|
197 | #include "moc_qhbarmodelmapper.cpp" | |
177 |
|
198 | |||
178 | QTCOMMERCIALCHART_END_NAMESPACE |
|
199 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,184 +1,197 | |||||
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 part of QtCommercial chart API. |
|
27 | \brief part of QtCommercial chart API. | |
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 | \inherits BarModelMapper |
|
|||
39 | \mainclass |
|
38 | \mainclass | |
40 |
|
39 | |||
41 | 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 | |
42 | for any bar series. The following QML example would create a bar series with three bar sets (assuming the model has |
|
41 | for any bar series. Adding/removing value from the BarSet causes the the same change in the rest of the BarSets | |
43 | at least four columns). Each bar set would contain data starting from row 1. The name of a set would be defined |
|
42 | added to the same series. The following QML example would create a bar series with three bar sets (assuming the | |
44 | by the horizontal header (of the column). |
|
43 | 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). | |||
45 | \code |
|
45 | \code | |
46 | GroupedBarSeries { |
|
46 | GroupedBarSeries { | |
47 | VBarModelMapper { |
|
47 | VBarModelMapper { | |
48 | model: myCustomModel |
|
48 | model: myCustomModel // QAbstractItemModel derived implementation | |
49 | firstBarSetColumn: 1 |
|
49 | firstBarSetColumn: 1 | |
50 | lastBarSetColumn: 3 |
|
50 | lastBarSetColumn: 3 | |
51 | firstRow: 1 |
|
51 | firstRow: 1 | |
52 | } |
|
52 | } | |
53 | } |
|
53 | } | |
54 | \endcode |
|
54 | \endcode | |
55 | */ |
|
55 | */ | |
56 |
|
56 | |||
57 | /*! |
|
57 | /*! | |
|
58 | \qmlproperty BarSeries VBarModelMapper::series | |||
|
59 | Defines the BarSeries based object that is used by the mapper. All the data in the series is discarded when it is | |||
|
60 | set to the mapper. When new series is specified the old series is disconnected (it preserves its data). | |||
|
61 | */ | |||
|
62 | ||||
|
63 | /*! | |||
|
64 | \qmlproperty Model VBarModelMapper::model | |||
|
65 | The QAbstractItemModel based model that is used by the mapper. You need to implement the model and expose it to | |||
|
66 | QML as shown in \l {QML Custom Model} demo application. NOTE: the model has to support adding/removing rows/columns | |||
|
67 | and modifying the data of the cells. | |||
|
68 | */ | |||
|
69 | ||||
|
70 | /*! | |||
58 | \property QVBarModelMapper::firstBarSetColumn |
|
71 | \property QVBarModelMapper::firstBarSetColumn | |
59 | \brief Defines which column of the model is used as the data source for the first bar set |
|
72 | \brief Defines which column of the model is used as the data source for the first bar set | |
60 | Default value is: -1 (invalid mapping) |
|
73 | Default value is: -1 (invalid mapping) | |
61 | */ |
|
74 | */ | |
62 | /*! |
|
75 | /*! | |
63 | \qmlproperty int VBarModelMapper::firstBarSetColumn |
|
76 | \qmlproperty int VBarModelMapper::firstBarSetColumn | |
64 | Defines which column of the model is used as the data source for the first bar set. Default value |
|
77 | Defines which column of the model is used as the data source for the first bar set. Default value | |
65 | is: -1 (invalid mapping). |
|
78 | is: -1 (invalid mapping). | |
66 | */ |
|
79 | */ | |
67 |
|
80 | |||
68 | /*! |
|
81 | /*! | |
69 | \property QVBarModelMapper::lastBarSetColumn |
|
82 | \property QVBarModelMapper::lastBarSetColumn | |
70 | \brief Defines which column of the model is used as the data source for the last bar set |
|
83 | \brief Defines which column of the model is used as the data source for the last bar set | |
71 | Default value is: -1 (invalid mapping) |
|
84 | Default value is: -1 (invalid mapping) | |
72 | */ |
|
85 | */ | |
73 | /*! |
|
86 | /*! | |
74 | \qmlproperty int VBarModelMapper::lastBarSetColumn |
|
87 | \qmlproperty int VBarModelMapper::lastBarSetColumn | |
75 | Defines which column of the model is used as the data source for the last bar set. Default |
|
88 | Defines which column of the model is used as the data source for the last bar set. Default | |
76 | value is: -1 (invalid mapping). |
|
89 | value is: -1 (invalid mapping). | |
77 | */ |
|
90 | */ | |
78 |
|
91 | |||
79 | /*! |
|
92 | /*! | |
80 | \property QVBarModelMapper::firstRow |
|
93 | \property QVBarModelMapper::firstRow | |
81 | \brief Defines which row of the model contains the first values of the QBarSets in the series. |
|
94 | \brief Defines which row of the model contains the first values of the QBarSets in the series. | |
82 | Minimal and default value is: 0 |
|
95 | Minimal and default value is: 0 | |
83 | */ |
|
96 | */ | |
84 | /*! |
|
97 | /*! | |
85 | \qmlproperty int BarModelMapper::firstRow |
|
98 | \qmlproperty int VBarModelMapper::firstRow | |
86 | Defines which row of the model contains the first values of the QBarSets in the series. |
|
99 | Defines which row of the model contains the first values of the QBarSets in the series. | |
87 | The default value is 0. |
|
100 | The default value is 0. | |
88 | */ |
|
101 | */ | |
89 |
|
102 | |||
90 | /*! |
|
103 | /*! | |
91 | \property QVBarModelMapper::rowCount |
|
104 | \property QVBarModelMapper::rowCount | |
92 | \brief Defines the number of rows of the model that are mapped as the data for QBarSeries |
|
105 | \brief Defines the number of rows of the model that are mapped as the data for QBarSeries | |
93 | Minimal and default value is: -1 (count limited by the number of rows in the model) |
|
106 | Minimal and default value is: -1 (count limited by the number of rows in the model) | |
94 | */ |
|
107 | */ | |
95 | /*! |
|
108 | /*! | |
96 | \qmlproperty int BarModelMapper::rowCount |
|
109 | \qmlproperty int VBarModelMapper::rowCount | |
97 | Defines the number of rows of the model that are mapped as the data for QBarSeries. The default value is |
|
110 | Defines the number of rows of the model that are mapped as the data for QBarSeries. The default value is | |
98 | -1 (count limited by the number of rows in the model) |
|
111 | -1 (count limited by the number of rows in the model) | |
99 | */ |
|
112 | */ | |
100 |
|
113 | |||
101 | /*! |
|
114 | /*! | |
102 | \fn void QVBarModelMapper::firstBarSetColumnChanged() |
|
115 | \fn void QVBarModelMapper::firstBarSetColumnChanged() | |
103 | Emitted when the firstBarSetColumn has changed. |
|
116 | Emitted when the firstBarSetColumn has changed. | |
104 | */ |
|
117 | */ | |
105 |
|
118 | |||
106 | /*! |
|
119 | /*! | |
107 | \fn void QVBarModelMapper::lastBarSetColumnChanged() |
|
120 | \fn void QVBarModelMapper::lastBarSetColumnChanged() | |
108 | Emitted when the lastBarSetColumn has changed. |
|
121 | Emitted when the lastBarSetColumn has changed. | |
109 | */ |
|
122 | */ | |
110 |
|
123 | |||
111 | /*! |
|
124 | /*! | |
112 | \fn void QVBarModelMapper::firstRowChanged() |
|
125 | \fn void QVBarModelMapper::firstRowChanged() | |
113 | Emitted when the firstRow has changed. |
|
126 | Emitted when the firstRow has changed. | |
114 | */ |
|
127 | */ | |
115 |
|
128 | |||
116 | /*! |
|
129 | /*! | |
117 | \fn void QVBarModelMapper::rowCountChanged() |
|
130 | \fn void QVBarModelMapper::rowCountChanged() | |
118 | Emitted when the rowCount has changed. |
|
131 | Emitted when the rowCount has changed. | |
119 | */ |
|
132 | */ | |
120 |
|
133 | |||
121 | /*! |
|
134 | /*! | |
122 | Constructs a mapper object which is a child of \a parent. |
|
135 | Constructs a mapper object which is a child of \a parent. | |
123 | */ |
|
136 | */ | |
124 | QVBarModelMapper::QVBarModelMapper(QObject *parent) : |
|
137 | QVBarModelMapper::QVBarModelMapper(QObject *parent) : | |
125 | QBarModelMapper(parent) |
|
138 | QBarModelMapper(parent) | |
126 | { |
|
139 | { | |
127 | QBarModelMapper::setOrientation(Qt::Vertical); |
|
140 | QBarModelMapper::setOrientation(Qt::Vertical); | |
128 | } |
|
141 | } | |
129 |
|
142 | |||
130 | int QVBarModelMapper::firstBarSetColumn() const |
|
143 | int QVBarModelMapper::firstBarSetColumn() const | |
131 | { |
|
144 | { | |
132 | return QBarModelMapper::firstBarSetSection(); |
|
145 | return QBarModelMapper::firstBarSetSection(); | |
133 | } |
|
146 | } | |
134 |
|
147 | |||
135 | void QVBarModelMapper::setFirstBarSetColumn(int firstBarSetColumn) |
|
148 | void QVBarModelMapper::setFirstBarSetColumn(int firstBarSetColumn) | |
136 | { |
|
149 | { | |
137 | if (firstBarSetColumn != firstBarSetSection()) { |
|
150 | if (firstBarSetColumn != firstBarSetSection()) { | |
138 | QBarModelMapper::setFirstBarSetSection(firstBarSetColumn); |
|
151 | QBarModelMapper::setFirstBarSetSection(firstBarSetColumn); | |
139 | emit firstBarSetColumnChanged(); |
|
152 | emit firstBarSetColumnChanged(); | |
140 | } |
|
153 | } | |
141 | } |
|
154 | } | |
142 |
|
155 | |||
143 | int QVBarModelMapper::lastBarSetColumn() const |
|
156 | int QVBarModelMapper::lastBarSetColumn() const | |
144 | { |
|
157 | { | |
145 | return QBarModelMapper::lastBarSetSection(); |
|
158 | return QBarModelMapper::lastBarSetSection(); | |
146 | } |
|
159 | } | |
147 |
|
160 | |||
148 | void QVBarModelMapper::setLastBarSetColumn(int lastBarSetColumn) |
|
161 | void QVBarModelMapper::setLastBarSetColumn(int lastBarSetColumn) | |
149 | { |
|
162 | { | |
150 | if (lastBarSetColumn != lastBarSetSection()) { |
|
163 | if (lastBarSetColumn != lastBarSetSection()) { | |
151 | QBarModelMapper::setLastBarSetSection(lastBarSetColumn); |
|
164 | QBarModelMapper::setLastBarSetSection(lastBarSetColumn); | |
152 | emit lastBarSetColumnChanged(); |
|
165 | emit lastBarSetColumnChanged(); | |
153 | } |
|
166 | } | |
154 | } |
|
167 | } | |
155 |
|
168 | |||
156 | int QVBarModelMapper::firstRow() const |
|
169 | int QVBarModelMapper::firstRow() const | |
157 | { |
|
170 | { | |
158 | return QBarModelMapper::first(); |
|
171 | return QBarModelMapper::first(); | |
159 | } |
|
172 | } | |
160 |
|
173 | |||
161 | void QVBarModelMapper::setFirstRow(int firstRow) |
|
174 | void QVBarModelMapper::setFirstRow(int firstRow) | |
162 | { |
|
175 | { | |
163 | if (firstRow != first()) { |
|
176 | if (firstRow != first()) { | |
164 | QBarModelMapper::setFirst(firstRow); |
|
177 | QBarModelMapper::setFirst(firstRow); | |
165 | emit firstRowChanged(); |
|
178 | emit firstRowChanged(); | |
166 | } |
|
179 | } | |
167 | } |
|
180 | } | |
168 |
|
181 | |||
169 | int QVBarModelMapper::rowCount() const |
|
182 | int QVBarModelMapper::rowCount() const | |
170 | { |
|
183 | { | |
171 | return QBarModelMapper::count(); |
|
184 | return QBarModelMapper::count(); | |
172 | } |
|
185 | } | |
173 |
|
186 | |||
174 | void QVBarModelMapper::setRowCount(int rowCount) |
|
187 | void QVBarModelMapper::setRowCount(int rowCount) | |
175 | { |
|
188 | { | |
176 | if (rowCount != count()) { |
|
189 | if (rowCount != count()) { | |
177 | QBarModelMapper::setCount(rowCount); |
|
190 | QBarModelMapper::setCount(rowCount); | |
178 | emit firstRowChanged(); |
|
191 | emit firstRowChanged(); | |
179 | } |
|
192 | } | |
180 | } |
|
193 | } | |
181 |
|
194 | |||
182 | #include "moc_qvbarmodelmapper.cpp" |
|
195 | #include "moc_qvbarmodelmapper.cpp" | |
183 |
|
196 | |||
184 | QTCOMMERCIALCHART_END_NAMESPACE |
|
197 | QTCOMMERCIALCHART_END_NAMESPACE |
General Comments 0
You need to be logged in to leave comments.
Login now