##// END OF EJS Templates
Updated mapper classes descriptions
Marek Rosa -
r1397:95d60d3807f4
parent child
Show More
@@ -1,450 +1,451
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 The instance of this class cannot be created directly. QHBarModelMapper of QVBarModelMapper should be used instead. This class is used to create a connection between QBarSeries and QAbstractItemModel derived model object.
36 The instance of this class cannot be created directly. QHBarModelMapper of QVBarModelMapper should be used instead. This class is used to create a connection between QBarSeries and QAbstractItemModel derived model object.
36 Curently it is NOT possible to use both QAbstractItemModel and QBarSeries model API.
37 Curently it is NOT possible to use both QAbstractItemModel and QBarSeries model API.
37 When the series is set to the mapper the QBarSeries and QBarSet API that affect the data (append, setValue, remove) should not be used.
38 When the series is set to the mapper the QBarSeries and QBarSet API that affect the data (append, setValue, remove) should not be used.
38 The model and the QBarSeries won't be kept in sync. Model API should be used to insert,remove,modify BarSets.
39 The model and the QBarSeries won't be kept in sync. Model API should be used to insert,remove,modify BarSets.
39 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.
40 */
41 */
41
42
42 /*!
43 /*!
43 \property QBarModelMapper::series
44 \property QBarModelMapper::series
44 \brief Defines the QPieSeries object that is used by the mapper.
45 \brief Defines the QPieSeries object that is used by the mapper.
45
46
46 All the data in the series is discarded when it is set to the mapper.
47 All the data in the series is discarded when it is set to the mapper.
47 When new series is specified the old series is disconnected (it preserves its data)
48 When new series is specified the old series is disconnected (it preserves its data)
48 */
49 */
49
50
50 /*!
51 /*!
51 \property QBarModelMapper::model
52 \property QBarModelMapper::model
52 \brief Defines the model that is used by the mapper.
53 \brief Defines the model that is used by the mapper.
53 */
54 */
54
55
55 /*!
56 /*!
56 \property QBarModelMapper::first
57 \property QBarModelMapper::first
57 \brief Defines which item of the model's row/column should be mapped as the value of the first QBarSet in the series.
58 \brief Defines which item of the model's row/column should be mapped as the value of the first QBarSet in the series.
58
59
59 Minimal and default value is: 0
60 Minimal and default value is: 0
60 */
61 */
61
62
62 /*!
63 /*!
63 \property QBarModelMapper::count
64 \property QBarModelMapper::count
64 \brief Defines the number of rows/columns of the model that are mapped as the data for QBarSeries
65 \brief Defines the number of rows/columns of the model that are mapped as the data for QBarSeries
65
66
66 Minimal and default value is: -1 (count limited by the number of rows/columns in the model)
67 Minimal and default value is: -1 (count limited by the number of rows/columns in the model)
67 */
68 */
68
69
69 /*!
70 /*!
70 Constructs a mapper object which is a child of \a parent.
71 Constructs a mapper object which is a child of \a parent.
71 */
72 */
72 QBarModelMapper::QBarModelMapper(QObject *parent) :
73 QBarModelMapper::QBarModelMapper(QObject *parent) :
73 QObject(parent),
74 QObject(parent),
74 d_ptr(new QBarModelMapperPrivate(this))
75 d_ptr(new QBarModelMapperPrivate(this))
75 {
76 {
76 }
77 }
77
78
78 QAbstractItemModel* QBarModelMapper::model() const
79 QAbstractItemModel* QBarModelMapper::model() const
79 {
80 {
80 Q_D(const QBarModelMapper);
81 Q_D(const QBarModelMapper);
81 return d->m_model;
82 return d->m_model;
82 }
83 }
83
84
84 void QBarModelMapper::setModel(QAbstractItemModel *model)
85 void QBarModelMapper::setModel(QAbstractItemModel *model)
85 {
86 {
86 if (model == 0)
87 if (model == 0)
87 return;
88 return;
88
89
89 Q_D(QBarModelMapper);
90 Q_D(QBarModelMapper);
90 if (d->m_model) {
91 if (d->m_model) {
91 disconnect(d->m_model, 0, d, 0);
92 disconnect(d->m_model, 0, d, 0);
92 }
93 }
93
94
94 d->m_model = model;
95 d->m_model = model;
95 d->initializeBarFromModel();
96 d->initializeBarFromModel();
96 // connect signals from the model
97 // connect signals from the model
97 connect(d->m_model, SIGNAL(dataChanged(QModelIndex,QModelIndex)), d, SLOT(modelUpdated(QModelIndex,QModelIndex)));
98 connect(d->m_model, SIGNAL(dataChanged(QModelIndex,QModelIndex)), d, SLOT(modelUpdated(QModelIndex,QModelIndex)));
98 connect(d->m_model, SIGNAL(headerDataChanged(Qt::Orientation,int,int)), d, SLOT(modelHeaderDataUpdated(Qt::Orientation,int,int)));
99 connect(d->m_model, SIGNAL(headerDataChanged(Qt::Orientation,int,int)), d, SLOT(modelHeaderDataUpdated(Qt::Orientation,int,int)));
99 connect(d->m_model, SIGNAL(rowsInserted(QModelIndex,int,int)), d, SLOT(modelRowsAdded(QModelIndex,int,int)));
100 connect(d->m_model, SIGNAL(rowsInserted(QModelIndex,int,int)), d, SLOT(modelRowsAdded(QModelIndex,int,int)));
100 connect(d->m_model, SIGNAL(rowsRemoved(QModelIndex,int,int)), d, SLOT(modelRowsRemoved(QModelIndex,int,int)));
101 connect(d->m_model, SIGNAL(rowsRemoved(QModelIndex,int,int)), d, SLOT(modelRowsRemoved(QModelIndex,int,int)));
101 connect(d->m_model, SIGNAL(columnsInserted(QModelIndex,int,int)), d, SLOT(modelColumnsAdded(QModelIndex,int,int)));
102 connect(d->m_model, SIGNAL(columnsInserted(QModelIndex,int,int)), d, SLOT(modelColumnsAdded(QModelIndex,int,int)));
102 connect(d->m_model, SIGNAL(columnsRemoved(QModelIndex,int,int)), d, SLOT(modelColumnsRemoved(QModelIndex,int,int)));
103 connect(d->m_model, SIGNAL(columnsRemoved(QModelIndex,int,int)), d, SLOT(modelColumnsRemoved(QModelIndex,int,int)));
103 }
104 }
104
105
105 QBarSeries* QBarModelMapper::series() const
106 QBarSeries* QBarModelMapper::series() const
106 {
107 {
107 Q_D(const QBarModelMapper);
108 Q_D(const QBarModelMapper);
108 return d->m_series;
109 return d->m_series;
109 }
110 }
110
111
111 void QBarModelMapper::setSeries(QBarSeries *series)
112 void QBarModelMapper::setSeries(QBarSeries *series)
112 {
113 {
113 Q_D(QBarModelMapper);
114 Q_D(QBarModelMapper);
114 if (d->m_series) {
115 if (d->m_series) {
115 disconnect(d->m_series, 0, d, 0);
116 disconnect(d->m_series, 0, d, 0);
116 }
117 }
117
118
118 if (series == 0)
119 if (series == 0)
119 return;
120 return;
120
121
121 d->m_series = series;
122 d->m_series = series;
122 d->initializeBarFromModel();
123 d->initializeBarFromModel();
123 // connect the signals from the series
124 // connect the signals from the series
124 // TODO: TO be implemented
125 // TODO: TO be implemented
125 }
126 }
126
127
127 int QBarModelMapper::first() const
128 int QBarModelMapper::first() const
128 {
129 {
129 Q_D(const QBarModelMapper);
130 Q_D(const QBarModelMapper);
130 return d->m_first;
131 return d->m_first;
131 }
132 }
132
133
133 void QBarModelMapper::setFirst(int first)
134 void QBarModelMapper::setFirst(int first)
134 {
135 {
135 Q_D(QBarModelMapper);
136 Q_D(QBarModelMapper);
136 d->m_first = qMax(first, 0);
137 d->m_first = qMax(first, 0);
137 d->initializeBarFromModel();
138 d->initializeBarFromModel();
138 }
139 }
139
140
140 int QBarModelMapper::count() const
141 int QBarModelMapper::count() const
141 {
142 {
142 Q_D(const QBarModelMapper);
143 Q_D(const QBarModelMapper);
143 return d->m_count;
144 return d->m_count;
144 }
145 }
145
146
146 void QBarModelMapper::setCount(int count)
147 void QBarModelMapper::setCount(int count)
147 {
148 {
148 Q_D(QBarModelMapper);
149 Q_D(QBarModelMapper);
149 d->m_count = qMax(count, -1);
150 d->m_count = qMax(count, -1);
150 d->initializeBarFromModel();
151 d->initializeBarFromModel();
151 }
152 }
152
153
153 /*!
154 /*!
154 Returns the orientation that is used when QBarModelMapper accesses the model.
155 Returns the orientation that is used when QBarModelMapper accesses the model.
155 This mean whether the consecutive values of the bar set are read from row (Qt::Horizontal)
156 This mean whether the consecutive values of the bar set are read from row (Qt::Horizontal)
156 or from columns (Qt::Vertical)
157 or from columns (Qt::Vertical)
157 */
158 */
158 Qt::Orientation QBarModelMapper::orientation() const
159 Qt::Orientation QBarModelMapper::orientation() const
159 {
160 {
160 Q_D(const QBarModelMapper);
161 Q_D(const QBarModelMapper);
161 return d->m_orientation;
162 return d->m_orientation;
162 }
163 }
163
164
164 /*!
165 /*!
165 Returns the \a orientation that is used when QBarModelMapper accesses the model.
166 Returns the \a orientation that is used when QBarModelMapper accesses the model.
166 This mean whether the consecutive values of the pie are read from row (Qt::Horizontal)
167 This mean whether the consecutive values of the pie are read from row (Qt::Horizontal)
167 or from columns (Qt::Vertical)
168 or from columns (Qt::Vertical)
168 */
169 */
169 void QBarModelMapper::setOrientation(Qt::Orientation orientation)
170 void QBarModelMapper::setOrientation(Qt::Orientation orientation)
170 {
171 {
171 Q_D(QBarModelMapper);
172 Q_D(QBarModelMapper);
172 d->m_orientation = orientation;
173 d->m_orientation = orientation;
173 d->initializeBarFromModel();
174 d->initializeBarFromModel();
174 }
175 }
175
176
176 /*!
177 /*!
177 Returns which section of the model is used as the data source for the first bar set
178 Returns which section of the model is used as the data source for the first bar set
178 */
179 */
179 int QBarModelMapper::firstBarSetSection() const
180 int QBarModelMapper::firstBarSetSection() const
180 {
181 {
181 Q_D(const QBarModelMapper);
182 Q_D(const QBarModelMapper);
182 return d->m_firstBarSetSection;
183 return d->m_firstBarSetSection;
183 }
184 }
184
185
185 /*!
186 /*!
186 Sets the model section that is used as the data source for the first bar set
187 Sets the model section that is used as the data source for the first bar set
187 Parameter \a firstBarSetSection specifies the section of the model.
188 Parameter \a firstBarSetSection specifies the section of the model.
188 */
189 */
189 void QBarModelMapper::setFirstBarSetSection(int firstBarSetSection)
190 void QBarModelMapper::setFirstBarSetSection(int firstBarSetSection)
190 {
191 {
191 Q_D(QBarModelMapper);
192 Q_D(QBarModelMapper);
192 d->m_firstBarSetSection = qMax(-1, firstBarSetSection);
193 d->m_firstBarSetSection = qMax(-1, firstBarSetSection);
193 d->initializeBarFromModel();
194 d->initializeBarFromModel();
194 }
195 }
195
196
196 /*!
197 /*!
197 Returns which section of the model is used as the data source for the last bar set
198 Returns which section of the model is used as the data source for the last bar set
198 */
199 */
199 int QBarModelMapper::lastBarSetSection() const
200 int QBarModelMapper::lastBarSetSection() const
200 {
201 {
201 Q_D(const QBarModelMapper);
202 Q_D(const QBarModelMapper);
202 return d->m_lastBarSetSection;
203 return d->m_lastBarSetSection;
203 }
204 }
204
205
205 /*!
206 /*!
206 Sets the model section that is used as the data source for the last bar set
207 Sets the model section that is used as the data source for the last bar set
207 Parameter \a lastBarSetSection specifies the section of the model.
208 Parameter \a lastBarSetSection specifies the section of the model.
208 */
209 */
209 void QBarModelMapper::setLastBarSetSection(int lastBarSetSection)
210 void QBarModelMapper::setLastBarSetSection(int lastBarSetSection)
210 {
211 {
211 Q_D(QBarModelMapper);
212 Q_D(QBarModelMapper);
212 d->m_lastBarSetSection = qMax(-1, lastBarSetSection);
213 d->m_lastBarSetSection = qMax(-1, lastBarSetSection);
213 d->initializeBarFromModel();
214 d->initializeBarFromModel();
214 }
215 }
215
216
216 /*!
217 /*!
217 Resets the QBarModelMapper to the default state.
218 Resets the QBarModelMapper to the default state.
218 first: 0; count: -1; firstBarSetSection: -1; lastBarSetSection: -1; categoriesSection: -1
219 first: 0; count: -1; firstBarSetSection: -1; lastBarSetSection: -1; categoriesSection: -1
219 */
220 */
220 void QBarModelMapper::reset()
221 void QBarModelMapper::reset()
221 {
222 {
222 Q_D(QBarModelMapper);
223 Q_D(QBarModelMapper);
223 d->m_first = 0;
224 d->m_first = 0;
224 d->m_count = -1;
225 d->m_count = -1;
225 d->m_firstBarSetSection = -1;
226 d->m_firstBarSetSection = -1;
226 d->m_lastBarSetSection = -1;
227 d->m_lastBarSetSection = -1;
227 d->initializeBarFromModel();
228 d->initializeBarFromModel();
228 }
229 }
229
230
230 ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
231 ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
231
232
232 QBarModelMapperPrivate::QBarModelMapperPrivate(QBarModelMapper *q) :
233 QBarModelMapperPrivate::QBarModelMapperPrivate(QBarModelMapper *q) :
233 m_series(0),
234 m_series(0),
234 m_model(0),
235 m_model(0),
235 m_first(0),
236 m_first(0),
236 m_count(-1),
237 m_count(-1),
237 m_orientation(Qt::Vertical),
238 m_orientation(Qt::Vertical),
238 m_firstBarSetSection(-1),
239 m_firstBarSetSection(-1),
239 m_lastBarSetSection(-1),
240 m_lastBarSetSection(-1),
240 m_seriesSignalsBlock(false),
241 m_seriesSignalsBlock(false),
241 m_modelSignalsBlock(false),
242 m_modelSignalsBlock(false),
242 q_ptr(q)
243 q_ptr(q)
243 {
244 {
244 }
245 }
245
246
246 void QBarModelMapperPrivate::blockModelSignals(bool block)
247 void QBarModelMapperPrivate::blockModelSignals(bool block)
247 {
248 {
248 m_modelSignalsBlock = block;
249 m_modelSignalsBlock = block;
249 }
250 }
250
251
251 void QBarModelMapperPrivate::blockSeriesSignals(bool block)
252 void QBarModelMapperPrivate::blockSeriesSignals(bool block)
252 {
253 {
253 m_seriesSignalsBlock = block;
254 m_seriesSignalsBlock = block;
254 }
255 }
255
256
256 QBarSet* QBarModelMapperPrivate::barSet(QModelIndex index)
257 QBarSet* QBarModelMapperPrivate::barSet(QModelIndex index)
257 {
258 {
258 if (!index.isValid())
259 if (!index.isValid())
259 return 0;
260 return 0;
260
261
261 if (m_orientation == Qt::Vertical && index.column() >= m_firstBarSetSection && index.column() <= m_lastBarSetSection) {
262 if (m_orientation == Qt::Vertical && index.column() >= m_firstBarSetSection && index.column() <= m_lastBarSetSection) {
262 if (index.row() >= m_first && (m_count == - 1 || index.row() < m_first + m_count)) {
263 if (index.row() >= m_first && (m_count == - 1 || index.row() < m_first + m_count)) {
263 // if (m_model->index(index.row(), m_valuesSection).isValid() && m_model->index(index.row(), m_labelsSection).isValid())
264 // if (m_model->index(index.row(), m_valuesSection).isValid() && m_model->index(index.row(), m_labelsSection).isValid())
264 return m_series->barSets().at(index.column() - m_firstBarSetSection);
265 return m_series->barSets().at(index.column() - m_firstBarSetSection);
265 // else
266 // else
266 // return 0;
267 // return 0;
267 }
268 }
268 } else if (m_orientation == Qt::Horizontal && index.row() >= m_firstBarSetSection && index.row() <= m_lastBarSetSection) {
269 } else if (m_orientation == Qt::Horizontal && index.row() >= m_firstBarSetSection && index.row() <= m_lastBarSetSection) {
269 if (index.column() >= m_first && (m_count == - 1 || index.column() < m_first + m_count))
270 if (index.column() >= m_first && (m_count == - 1 || index.column() < m_first + m_count))
270 return m_series->barSets().at(index.row() - m_firstBarSetSection);
271 return m_series->barSets().at(index.row() - m_firstBarSetSection);
271 }
272 }
272 return 0; // This part of model has not been mapped to any slice
273 return 0; // This part of model has not been mapped to any slice
273 }
274 }
274
275
275 QModelIndex QBarModelMapperPrivate::barModelIndex(int barSection, int posInBar)
276 QModelIndex QBarModelMapperPrivate::barModelIndex(int barSection, int posInBar)
276 {
277 {
277 if (m_count != -1 && posInBar >= m_count)
278 if (m_count != -1 && posInBar >= m_count)
278 return QModelIndex(); // invalid
279 return QModelIndex(); // invalid
279
280
280 if (barSection < m_firstBarSetSection || barSection > m_lastBarSetSection)
281 if (barSection < m_firstBarSetSection || barSection > m_lastBarSetSection)
281 return QModelIndex(); // invalid
282 return QModelIndex(); // invalid
282
283
283 if (m_orientation == Qt::Vertical)
284 if (m_orientation == Qt::Vertical)
284 return m_model->index(posInBar + m_first, barSection);
285 return m_model->index(posInBar + m_first, barSection);
285 else
286 else
286 return m_model->index(barSection, posInBar + m_first);
287 return m_model->index(barSection, posInBar + m_first);
287 }
288 }
288
289
289 void QBarModelMapperPrivate::modelUpdated(QModelIndex topLeft, QModelIndex bottomRight)
290 void QBarModelMapperPrivate::modelUpdated(QModelIndex topLeft, QModelIndex bottomRight)
290 {
291 {
291 Q_UNUSED(topLeft)
292 Q_UNUSED(topLeft)
292 Q_UNUSED(bottomRight)
293 Q_UNUSED(bottomRight)
293
294
294 if (m_model == 0 || m_series == 0)
295 if (m_model == 0 || m_series == 0)
295 return;
296 return;
296
297
297 if (m_modelSignalsBlock)
298 if (m_modelSignalsBlock)
298 return;
299 return;
299
300
300 blockSeriesSignals();
301 blockSeriesSignals();
301 QModelIndex index;
302 QModelIndex index;
302 for (int row = topLeft.row(); row <= bottomRight.row(); row++) {
303 for (int row = topLeft.row(); row <= bottomRight.row(); row++) {
303 for (int column = topLeft.column(); column <= bottomRight.column(); column++) {
304 for (int column = topLeft.column(); column <= bottomRight.column(); column++) {
304 index = topLeft.sibling(row, column);
305 index = topLeft.sibling(row, column);
305 QBarSet* bar = barSet(index);
306 QBarSet* bar = barSet(index);
306 if (bar) {
307 if (bar) {
307 if (m_orientation == Qt::Vertical)
308 if (m_orientation == Qt::Vertical)
308 bar->replace(row - m_first, m_model->data(index).toReal());
309 bar->replace(row - m_first, m_model->data(index).toReal());
309 else
310 else
310 bar->replace(column - m_first, m_model->data(index).toReal());
311 bar->replace(column - m_first, m_model->data(index).toReal());
311 }
312 }
312 }
313 }
313 }
314 }
314 blockSeriesSignals(false);
315 blockSeriesSignals(false);
315 }
316 }
316
317
317 void QBarModelMapperPrivate::modelHeaderDataUpdated(Qt::Orientation orientation, int first, int last)
318 void QBarModelMapperPrivate::modelHeaderDataUpdated(Qt::Orientation orientation, int first, int last)
318 {
319 {
319 if (m_model == 0 || m_series == 0)
320 if (m_model == 0 || m_series == 0)
320 return;
321 return;
321
322
322 if (m_modelSignalsBlock)
323 if (m_modelSignalsBlock)
323 return;
324 return;
324
325
325 blockSeriesSignals();
326 blockSeriesSignals();
326 if (orientation != m_orientation) {
327 if (orientation != m_orientation) {
327 for (int section = first; section <= last; section++) {
328 for (int section = first; section <= last; section++) {
328 if (section >= m_firstBarSetSection && section <= m_lastBarSetSection) {
329 if (section >= m_firstBarSetSection && section <= m_lastBarSetSection) {
329 QBarSet* bar = m_series->barSets().at(section - m_firstBarSetSection);
330 QBarSet* bar = m_series->barSets().at(section - m_firstBarSetSection);
330 if (bar)
331 if (bar)
331 bar->setName(m_model->headerData(section, orientation).toString());
332 bar->setName(m_model->headerData(section, orientation).toString());
332 }
333 }
333 }
334 }
334 }
335 }
335 blockSeriesSignals(false);
336 blockSeriesSignals(false);
336 }
337 }
337
338
338 void QBarModelMapperPrivate::modelRowsAdded(QModelIndex parent, int start, int end)
339 void QBarModelMapperPrivate::modelRowsAdded(QModelIndex parent, int start, int end)
339 {
340 {
340 Q_UNUSED(parent);
341 Q_UNUSED(parent);
341 Q_UNUSED(end)
342 Q_UNUSED(end)
342 if (m_modelSignalsBlock)
343 if (m_modelSignalsBlock)
343 return;
344 return;
344
345
345 blockSeriesSignals();
346 blockSeriesSignals();
346 if (m_orientation == Qt::Vertical)
347 if (m_orientation == Qt::Vertical)
347 // insertData(start, end);
348 // insertData(start, end);
348 initializeBarFromModel();
349 initializeBarFromModel();
349 else if (start <= m_firstBarSetSection || start <= m_lastBarSetSection) // if the changes affect the map - reinitialize
350 else if (start <= m_firstBarSetSection || start <= m_lastBarSetSection) // if the changes affect the map - reinitialize
350 initializeBarFromModel();
351 initializeBarFromModel();
351 blockSeriesSignals(false);
352 blockSeriesSignals(false);
352 }
353 }
353
354
354 void QBarModelMapperPrivate::modelRowsRemoved(QModelIndex parent, int start, int end)
355 void QBarModelMapperPrivate::modelRowsRemoved(QModelIndex parent, int start, int end)
355 {
356 {
356 Q_UNUSED(parent);
357 Q_UNUSED(parent);
357 Q_UNUSED(end)
358 Q_UNUSED(end)
358 if (m_modelSignalsBlock)
359 if (m_modelSignalsBlock)
359 return;
360 return;
360
361
361 blockSeriesSignals();
362 blockSeriesSignals();
362 if (m_orientation == Qt::Vertical)
363 if (m_orientation == Qt::Vertical)
363 // removeData(start, end);
364 // removeData(start, end);
364 initializeBarFromModel();
365 initializeBarFromModel();
365 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
366 initializeBarFromModel();
367 initializeBarFromModel();
367 blockSeriesSignals(false);
368 blockSeriesSignals(false);
368 }
369 }
369
370
370 void QBarModelMapperPrivate::modelColumnsAdded(QModelIndex parent, int start, int end)
371 void QBarModelMapperPrivate::modelColumnsAdded(QModelIndex parent, int start, int end)
371 {
372 {
372 Q_UNUSED(parent);
373 Q_UNUSED(parent);
373 Q_UNUSED(end)
374 Q_UNUSED(end)
374 if (m_modelSignalsBlock)
375 if (m_modelSignalsBlock)
375 return;
376 return;
376
377
377 blockSeriesSignals();
378 blockSeriesSignals();
378 if (m_orientation == Qt::Horizontal)
379 if (m_orientation == Qt::Horizontal)
379 // insertData(start, end);
380 // insertData(start, end);
380 initializeBarFromModel();
381 initializeBarFromModel();
381 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
382 initializeBarFromModel();
383 initializeBarFromModel();
383 blockSeriesSignals(false);
384 blockSeriesSignals(false);
384 }
385 }
385
386
386 void QBarModelMapperPrivate::modelColumnsRemoved(QModelIndex parent, int start, int end)
387 void QBarModelMapperPrivate::modelColumnsRemoved(QModelIndex parent, int start, int end)
387 {
388 {
388 Q_UNUSED(parent);
389 Q_UNUSED(parent);
389 Q_UNUSED(end)
390 Q_UNUSED(end)
390 if (m_modelSignalsBlock)
391 if (m_modelSignalsBlock)
391 return;
392 return;
392
393
393 blockSeriesSignals();
394 blockSeriesSignals();
394 if (m_orientation == Qt::Horizontal)
395 if (m_orientation == Qt::Horizontal)
395 // removeData(start, end);
396 // removeData(start, end);
396 initializeBarFromModel();
397 initializeBarFromModel();
397 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
398 initializeBarFromModel();
399 initializeBarFromModel();
399 blockSeriesSignals(false);
400 blockSeriesSignals(false);
400 }
401 }
401
402
402 void QBarModelMapperPrivate::insertData(int start, int end)
403 void QBarModelMapperPrivate::insertData(int start, int end)
403 {
404 {
404 Q_UNUSED(end)
405 Q_UNUSED(end)
405 Q_UNUSED(start)
406 Q_UNUSED(start)
406 Q_UNUSED(end)
407 Q_UNUSED(end)
407 // To be implemented
408 // To be implemented
408 }
409 }
409
410
410 void QBarModelMapperPrivate::removeData(int start, int end)
411 void QBarModelMapperPrivate::removeData(int start, int end)
411 {
412 {
412 Q_UNUSED(end)
413 Q_UNUSED(end)
413 Q_UNUSED(start)
414 Q_UNUSED(start)
414 Q_UNUSED(end)
415 Q_UNUSED(end)
415 // To be implemented
416 // To be implemented
416 }
417 }
417
418
418 void QBarModelMapperPrivate::initializeBarFromModel()
419 void QBarModelMapperPrivate::initializeBarFromModel()
419 {
420 {
420 if (m_model == 0 || m_series == 0)
421 if (m_model == 0 || m_series == 0)
421 return;
422 return;
422
423
423 blockSeriesSignals();
424 blockSeriesSignals();
424 // clear current content
425 // clear current content
425 m_series->clear();
426 m_series->clear();
426
427
427 // create the initial bar sets
428 // create the initial bar sets
428 for (int i = m_firstBarSetSection; i <= m_lastBarSetSection; i++) {
429 for (int i = m_firstBarSetSection; i <= m_lastBarSetSection; i++) {
429 int posInBar = 0;
430 int posInBar = 0;
430 QModelIndex barIndex = barModelIndex(i, posInBar);
431 QModelIndex barIndex = barModelIndex(i, posInBar);
431 // check if there is such model index
432 // check if there is such model index
432 if (barIndex.isValid()) {
433 if (barIndex.isValid()) {
433 QBarSet *barSet = new QBarSet(m_model->headerData(i, m_orientation == Qt::Vertical ? Qt::Horizontal : Qt::Vertical).toString());
434 QBarSet *barSet = new QBarSet(m_model->headerData(i, m_orientation == Qt::Vertical ? Qt::Horizontal : Qt::Vertical).toString());
434 while (barIndex.isValid()) {
435 while (barIndex.isValid()) {
435 barSet->append(m_model->data(barIndex, Qt::DisplayRole).toDouble());
436 barSet->append(m_model->data(barIndex, Qt::DisplayRole).toDouble());
436 posInBar++;
437 posInBar++;
437 barIndex = barModelIndex(i, posInBar);
438 barIndex = barModelIndex(i, posInBar);
438 }
439 }
439 m_series->append(barSet);
440 m_series->append(barSet);
440 } else {
441 } else {
441 break;
442 break;
442 }
443 }
443 }
444 }
444 blockSeriesSignals(false);
445 blockSeriesSignals(false);
445 }
446 }
446
447
447 #include "moc_qbarmodelmapper.cpp"
448 #include "moc_qbarmodelmapper.cpp"
448 #include "moc_qbarmodelmapper_p.cpp"
449 #include "moc_qbarmodelmapper_p.cpp"
449
450
450 QTCOMMERCIALCHART_END_NAMESPACE
451 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,82 +1,83
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 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.
31 Curently it is NOT possible to use both QAbstractItemModel and QBarSeries model API.
32 Curently it is NOT possible to use both QAbstractItemModel and QBarSeries model API.
32 When the series is set to the mapper the QBarSeries and QBarSet API that affect the data (append, setValue, remove) should not be used.
33 When the series is set to the mapper the QBarSeries and QBarSet API that affect the data (append, setValue, remove) should not be used.
33 The model and the QBarSeries won't be kept in sync. Model API should be used to insert,remove,modify BarSets.
34 The model and the QBarSeries won't be kept in sync. Model API should be used to insert,remove,modify BarSets.
34 NOTE: used model has to support adding/removing rows/columns and modifying the data of the cells.
35 NOTE: used model has to support adding/removing rows/columns and modifying the data of the cells.
35 */
36 */
36
37
37 /*!
38 /*!
38 \property QHBarModelMapper::firstBarSetRow
39 \property QHBarModelMapper::firstBarSetRow
39 \brief Defines which column of the model is used as the data source for the first bar set
40 \brief Defines which column of the model is used as the data source for the first bar set
40
41
41 Default value is: -1 (invalid mapping)
42 Default value is: -1 (invalid mapping)
42 */
43 */
43
44
44 /*!
45 /*!
45 \property QHBarModelMapper::lastBarSetRow
46 \property QHBarModelMapper::lastBarSetRow
46 \brief Defines which column of the model is used as the data source for the last bar set
47 \brief Defines which column of the model is used as the data source for the last bar set
47
48
48 Default value is: -1 (invalid mapping)
49 Default value is: -1 (invalid mapping)
49 */
50 */
50
51
51 /*!
52 /*!
52 Constructs a mapper object which is a child of \a parent.
53 Constructs a mapper object which is a child of \a parent.
53 */
54 */
54 QHBarModelMapper::QHBarModelMapper(QObject *parent) :
55 QHBarModelMapper::QHBarModelMapper(QObject *parent) :
55 QBarModelMapper(parent)
56 QBarModelMapper(parent)
56 {
57 {
57 QBarModelMapper::setOrientation(Qt::Horizontal);
58 QBarModelMapper::setOrientation(Qt::Horizontal);
58 }
59 }
59
60
60 int QHBarModelMapper::firstBarSetRow() const
61 int QHBarModelMapper::firstBarSetRow() const
61 {
62 {
62 return QBarModelMapper::firstBarSetSection();
63 return QBarModelMapper::firstBarSetSection();
63 }
64 }
64
65
65 void QHBarModelMapper::setFirstBarSetRow(int firstBarSetRow)
66 void QHBarModelMapper::setFirstBarSetRow(int firstBarSetRow)
66 {
67 {
67 return QBarModelMapper::setFirstBarSetSection(firstBarSetRow);
68 return QBarModelMapper::setFirstBarSetSection(firstBarSetRow);
68 }
69 }
69
70
70 int QHBarModelMapper::lastBarSetRow() const
71 int QHBarModelMapper::lastBarSetRow() const
71 {
72 {
72 return QBarModelMapper::lastBarSetSection();
73 return QBarModelMapper::lastBarSetSection();
73 }
74 }
74
75
75 void QHBarModelMapper::setLastBarSetRow(int lastBarSetRow)
76 void QHBarModelMapper::setLastBarSetRow(int lastBarSetRow)
76 {
77 {
77 return QBarModelMapper::setLastBarSetSection(lastBarSetRow);
78 return QBarModelMapper::setLastBarSetSection(lastBarSetRow);
78 }
79 }
79
80
80 #include "moc_qhbarmodelmapper.cpp"
81 #include "moc_qhbarmodelmapper.cpp"
81
82
82 QTCOMMERCIALCHART_END_NAMESPACE
83 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,82 +1,83
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 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.
31 Curently it is NOT possible to use both QAbstractItemModel and QBarSeries model API.
32 Curently it is NOT possible to use both QAbstractItemModel and QBarSeries model API.
32 When the series is set to the mapper the QBarSeries and QBarSet API that affect the data (append, setValue, remove) should not be used.
33 When the series is set to the mapper the QBarSeries and QBarSet API that affect the data (append, setValue, remove) should not be used.
33 The model and the QBarSeries won't be kept in sync. Model API should be used to insert,remove,modify BarSets.
34 The model and the QBarSeries won't be kept in sync. Model API should be used to insert,remove,modify BarSets.
34 NOTE: used model has to support adding/removing rows/columns and modifying the data of the cells.
35 NOTE: used model has to support adding/removing rows/columns and modifying the data of the cells.
35 */
36 */
36
37
37 /*!
38 /*!
38 \property QVBarModelMapper::firstBarSetColumn
39 \property QVBarModelMapper::firstBarSetColumn
39 \brief Defines which column of the model is used as the data source for the first bar set
40 \brief Defines which column of the model is used as the data source for the first bar set
40
41
41 Default value is: -1 (invalid mapping)
42 Default value is: -1 (invalid mapping)
42 */
43 */
43
44
44 /*!
45 /*!
45 \property QVBarModelMapper::lastBarSetColumn
46 \property QVBarModelMapper::lastBarSetColumn
46 \brief Defines which column of the model is used as the data source for the last bar set
47 \brief Defines which column of the model is used as the data source for the last bar set
47
48
48 Default value is: -1 (invalid mapping)
49 Default value is: -1 (invalid mapping)
49 */
50 */
50
51
51 /*!
52 /*!
52 Constructs a mapper object which is a child of \a parent.
53 Constructs a mapper object which is a child of \a parent.
53 */
54 */
54 QVBarModelMapper::QVBarModelMapper(QObject *parent) :
55 QVBarModelMapper::QVBarModelMapper(QObject *parent) :
55 QBarModelMapper(parent)
56 QBarModelMapper(parent)
56 {
57 {
57 QBarModelMapper::setOrientation(Qt::Vertical);
58 QBarModelMapper::setOrientation(Qt::Vertical);
58 }
59 }
59
60
60 int QVBarModelMapper::firstBarSetColumn() const
61 int QVBarModelMapper::firstBarSetColumn() const
61 {
62 {
62 return QBarModelMapper::firstBarSetSection();
63 return QBarModelMapper::firstBarSetSection();
63 }
64 }
64
65
65 void QVBarModelMapper::setFirstBarSetColumn(int firstBarSetColumn)
66 void QVBarModelMapper::setFirstBarSetColumn(int firstBarSetColumn)
66 {
67 {
67 return QBarModelMapper::setFirstBarSetSection(firstBarSetColumn);
68 return QBarModelMapper::setFirstBarSetSection(firstBarSetColumn);
68 }
69 }
69
70
70 int QVBarModelMapper::lastBarSetColumn() const
71 int QVBarModelMapper::lastBarSetColumn() const
71 {
72 {
72 return QBarModelMapper::lastBarSetSection();
73 return QBarModelMapper::lastBarSetSection();
73 }
74 }
74
75
75 void QVBarModelMapper::setLastBarSetColumn(int lastBarSetColumn)
76 void QVBarModelMapper::setLastBarSetColumn(int lastBarSetColumn)
76 {
77 {
77 return QBarModelMapper::setLastBarSetSection(lastBarSetColumn);
78 return QBarModelMapper::setLastBarSetSection(lastBarSetColumn);
78 }
79 }
79
80
80 #include "moc_qvbarmodelmapper.cpp"
81 #include "moc_qvbarmodelmapper.cpp"
81
82
82 QTCOMMERCIALCHART_END_NAMESPACE
83 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,94 +1,95
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 \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 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 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.
32 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.
33 NOTE: used model has to support adding/removing rows/columns and modifying the data of the cells.
33 */
34 */
34
35
35 /*!
36 /*!
36 \property QHPieModelMapper::valuesRow
37 \property QHPieModelMapper::valuesRow
37 \brief Defines which row of the model is kept in sync with the values of the pie's slices
38 \brief Defines which row of the model is kept in sync with the values of the pie's slices
38
39
39 Default value is: -1 (invalid mapping)
40 Default value is: -1 (invalid mapping)
40 */
41 */
41
42
42 /*!
43 /*!
43 \property QHPieModelMapper::labelsRow
44 \property QHPieModelMapper::labelsRow
44 \brief Defines which row of the model is kept in sync with the labels of the pie's slices
45 \brief Defines which row of the model is kept in sync with the labels of the pie's slices
45
46
46 Default value is: -1 (invalid mapping)
47 Default value is: -1 (invalid mapping)
47 */
48 */
48
49
49 /*!
50 /*!
50 Constructs a mapper object which is a child of \a parent.
51 Constructs a mapper object which is a child of \a parent.
51 */
52 */
52 QHPieModelMapper::QHPieModelMapper(QObject *parent) :
53 QHPieModelMapper::QHPieModelMapper(QObject *parent) :
53 QPieModelMapper(parent)
54 QPieModelMapper(parent)
54 {
55 {
55 QPieModelMapper::setOrientation(Qt::Horizontal);
56 QPieModelMapper::setOrientation(Qt::Horizontal);
56 }
57 }
57
58
58 /*!
59 /*!
59 Returns which row of the model is kept in sync with the values of the pie's slices
60 Returns which row of the model is kept in sync with the values of the pie's slices
60 */
61 */
61 int QHPieModelMapper::valuesRow() const
62 int QHPieModelMapper::valuesRow() const
62 {
63 {
63 return QPieModelMapper::valuesSection();
64 return QPieModelMapper::valuesSection();
64 }
65 }
65
66
66 /*!
67 /*!
67 Sets the model row that is kept in sync with the pie slices values.
68 Sets the model row that is kept in sync with the pie slices values.
68 Parameter \a valuesRow specifies the row of the model.
69 Parameter \a valuesRow specifies the row of the model.
69 */
70 */
70 void QHPieModelMapper::setValuesRow(int valuesRow)
71 void QHPieModelMapper::setValuesRow(int valuesRow)
71 {
72 {
72 QPieModelMapper::setValuesSection(valuesRow);
73 QPieModelMapper::setValuesSection(valuesRow);
73 }
74 }
74
75
75 /*!
76 /*!
76 Returns which row of the model is kept in sync with the labels of the pie's slices
77 Returns which row of the model is kept in sync with the labels of the pie's slices
77 */
78 */
78 int QHPieModelMapper::labelsRow() const
79 int QHPieModelMapper::labelsRow() const
79 {
80 {
80 return QPieModelMapper::labelsSection();
81 return QPieModelMapper::labelsSection();
81 }
82 }
82
83
83 /*!
84 /*!
84 Sets the model row that is kept in sync with the pie's slices labels.
85 Sets the model row that is kept in sync with the pie's slices labels.
85 Parameter \a labelsRow specifies the row of the model.
86 Parameter \a labelsRow specifies the row of the model.
86 */
87 */
87 void QHPieModelMapper::setLabelsRow(int labelsRow)
88 void QHPieModelMapper::setLabelsRow(int labelsRow)
88 {
89 {
89 QPieModelMapper::setLabelsSection(labelsRow);
90 QPieModelMapper::setLabelsSection(labelsRow);
90 }
91 }
91
92
92 #include "moc_qhpiemodelmapper.cpp"
93 #include "moc_qhpiemodelmapper.cpp"
93
94
94 QTCOMMERCIALCHART_END_NAMESPACE
95 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,595 +1,596
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 "qpiemodelmapper_p.h"
21 #include "qpiemodelmapper_p.h"
22 #include "qpiemodelmapper.h"
22 #include "qpiemodelmapper.h"
23 #include "qpieseries.h"
23 #include "qpieseries.h"
24 #include "qpieslice.h"
24 #include "qpieslice.h"
25 #include <QAbstractItemModel>
25 #include <QAbstractItemModel>
26
26
27 QTCOMMERCIALCHART_BEGIN_NAMESPACE
27 QTCOMMERCIALCHART_BEGIN_NAMESPACE
28
28
29 /*!
29 /*!
30 \class QPieModelMapper
30 \class QPieModelMapper
31 \brief part of QtCommercial chart API.
31 \brief part of QtCommercial chart API.
32 \mainclass
32 \mainclass
33
33
34 Model mappers allow you to use QAbstractItemModel derived models as a data source for a chart series.
34 The instance of this class cannot be created directly. QHPieModelMapper of QVPieModelMapper should be used instead. This class is used to create a connection between QPieSeries and QAbstractItemModel derived model object.
35 The instance of this class cannot be created directly. QHPieModelMapper of QVPieModelMapper should be used instead. This class is used to create a connection between QPieSeries and QAbstractItemModel derived model object.
35 It is possible to use both QAbstractItemModel and QPieSeries model API. QPieModelMapper makes sure that Pie and the model are kept in sync.
36 It is possible to use both QAbstractItemModel and QPieSeries model API. QPieModelMapper makes sure that Pie and the model are kept in sync.
36 NOTE: used model has to support adding/removing rows/columns and modifying the data of the cells.
37 NOTE: used model has to support adding/removing rows/columns and modifying the data of the cells.
37 */
38 */
38
39
39 /*!
40 /*!
40 \property QPieModelMapper::series
41 \property QPieModelMapper::series
41 \brief Defines the QPieSeries object that is used by the mapper.
42 \brief Defines the QPieSeries object that is used by the mapper.
42
43
43 All the data in the series is discarded when it is set to the mapper.
44 All the data in the series is discarded when it is set to the mapper.
44 When new series is specified the old series is disconnected (it preserves its data)
45 When new series is specified the old series is disconnected (it preserves its data)
45 */
46 */
46
47
47 /*!
48 /*!
48 \property QPieModelMapper::model
49 \property QPieModelMapper::model
49 \brief Defines the model that is used by the mapper.
50 \brief Defines the model that is used by the mapper.
50 */
51 */
51
52
52 /*!
53 /*!
53 \property QPieModelMapper::first
54 \property QPieModelMapper::first
54 \brief Defines which item of the model's row/column should be mapped as the value/label of the first slice of the pie
55 \brief Defines which item of the model's row/column should be mapped as the value/label of the first slice of the pie
55
56
56 Minimal and default value is: 0
57 Minimal and default value is: 0
57 */
58 */
58
59
59 /*!
60 /*!
60 \property QPieModelMapper::count
61 \property QPieModelMapper::count
61 \brief Defines the number of rows/columns of the model that are mapped as the data for the pie.
62 \brief Defines the number of rows/columns of the model that are mapped as the data for the pie.
62
63
63 Minimal and default value is: -1 (count limited by the number of rows/columns in the model)
64 Minimal and default value is: -1 (count limited by the number of rows/columns in the model)
64 */
65 */
65
66
66 /*!
67 /*!
67 Constructs a mapper object which is a child of \a parent.
68 Constructs a mapper object which is a child of \a parent.
68 */
69 */
69 QPieModelMapper::QPieModelMapper(QObject *parent) :
70 QPieModelMapper::QPieModelMapper(QObject *parent) :
70 QObject(parent),
71 QObject(parent),
71 d_ptr(new QPieModelMapperPrivate(this))
72 d_ptr(new QPieModelMapperPrivate(this))
72 {
73 {
73 }
74 }
74
75
75 QAbstractItemModel* QPieModelMapper::model() const
76 QAbstractItemModel* QPieModelMapper::model() const
76 {
77 {
77 Q_D(const QPieModelMapper);
78 Q_D(const QPieModelMapper);
78 return d->m_model;
79 return d->m_model;
79 }
80 }
80
81
81 void QPieModelMapper::setModel(QAbstractItemModel *model)
82 void QPieModelMapper::setModel(QAbstractItemModel *model)
82 {
83 {
83 if (model == 0)
84 if (model == 0)
84 return;
85 return;
85
86
86 Q_D(QPieModelMapper);
87 Q_D(QPieModelMapper);
87 if (d->m_model) {
88 if (d->m_model) {
88 disconnect(d->m_model, 0, d, 0);
89 disconnect(d->m_model, 0, d, 0);
89 }
90 }
90
91
91 d->m_model = model;
92 d->m_model = model;
92 d->initializePieFromModel();
93 d->initializePieFromModel();
93 // connect signals from the model
94 // connect signals from the model
94 connect(d->m_model, SIGNAL(dataChanged(QModelIndex,QModelIndex)), d, SLOT(modelUpdated(QModelIndex,QModelIndex)));
95 connect(d->m_model, SIGNAL(dataChanged(QModelIndex,QModelIndex)), d, SLOT(modelUpdated(QModelIndex,QModelIndex)));
95 connect(d->m_model, SIGNAL(rowsInserted(QModelIndex,int,int)), d, SLOT(modelRowsAdded(QModelIndex,int,int)));
96 connect(d->m_model, SIGNAL(rowsInserted(QModelIndex,int,int)), d, SLOT(modelRowsAdded(QModelIndex,int,int)));
96 connect(d->m_model, SIGNAL(rowsRemoved(QModelIndex,int,int)), d, SLOT(modelRowsRemoved(QModelIndex,int,int)));
97 connect(d->m_model, SIGNAL(rowsRemoved(QModelIndex,int,int)), d, SLOT(modelRowsRemoved(QModelIndex,int,int)));
97 connect(d->m_model, SIGNAL(columnsInserted(QModelIndex,int,int)), d, SLOT(modelColumnsAdded(QModelIndex,int,int)));
98 connect(d->m_model, SIGNAL(columnsInserted(QModelIndex,int,int)), d, SLOT(modelColumnsAdded(QModelIndex,int,int)));
98 connect(d->m_model, SIGNAL(columnsRemoved(QModelIndex,int,int)), d, SLOT(modelColumnsRemoved(QModelIndex,int,int)));
99 connect(d->m_model, SIGNAL(columnsRemoved(QModelIndex,int,int)), d, SLOT(modelColumnsRemoved(QModelIndex,int,int)));
99 }
100 }
100
101
101 QPieSeries* QPieModelMapper::series() const
102 QPieSeries* QPieModelMapper::series() const
102 {
103 {
103 Q_D(const QPieModelMapper);
104 Q_D(const QPieModelMapper);
104 return d->m_series;
105 return d->m_series;
105 }
106 }
106
107
107 void QPieModelMapper::setSeries(QPieSeries *series)
108 void QPieModelMapper::setSeries(QPieSeries *series)
108 {
109 {
109 Q_D(QPieModelMapper);
110 Q_D(QPieModelMapper);
110 if (d->m_series) {
111 if (d->m_series) {
111 disconnect(d->m_series, 0, d, 0);
112 disconnect(d->m_series, 0, d, 0);
112 }
113 }
113
114
114 if (series == 0)
115 if (series == 0)
115 return;
116 return;
116
117
117 d->m_series = series;
118 d->m_series = series;
118 d->initializePieFromModel();
119 d->initializePieFromModel();
119 // connect the signals from the series
120 // connect the signals from the series
120 connect(d->m_series, SIGNAL(added(QList<QPieSlice*>)), d, SLOT(slicesAdded(QList<QPieSlice*>)));
121 connect(d->m_series, SIGNAL(added(QList<QPieSlice*>)), d, SLOT(slicesAdded(QList<QPieSlice*>)));
121 connect(d->m_series, SIGNAL(removed(QList<QPieSlice*>)), d, SLOT(slicesRemoved(QList<QPieSlice*>)));
122 connect(d->m_series, SIGNAL(removed(QList<QPieSlice*>)), d, SLOT(slicesRemoved(QList<QPieSlice*>)));
122 }
123 }
123
124
124 int QPieModelMapper::first() const
125 int QPieModelMapper::first() const
125 {
126 {
126 Q_D(const QPieModelMapper);
127 Q_D(const QPieModelMapper);
127 return d->m_first;
128 return d->m_first;
128 }
129 }
129
130
130 void QPieModelMapper::setFirst(int first)
131 void QPieModelMapper::setFirst(int first)
131 {
132 {
132 Q_D(QPieModelMapper);
133 Q_D(QPieModelMapper);
133 d->m_first = qMax(first, 0);
134 d->m_first = qMax(first, 0);
134 d->initializePieFromModel();
135 d->initializePieFromModel();
135 }
136 }
136
137
137 int QPieModelMapper::count() const
138 int QPieModelMapper::count() const
138 {
139 {
139 Q_D(const QPieModelMapper);
140 Q_D(const QPieModelMapper);
140 return d->m_count;
141 return d->m_count;
141 }
142 }
142
143
143 void QPieModelMapper::setCount(int count)
144 void QPieModelMapper::setCount(int count)
144 {
145 {
145 Q_D(QPieModelMapper);
146 Q_D(QPieModelMapper);
146 d->m_count = qMax(count, -1);
147 d->m_count = qMax(count, -1);
147 d->initializePieFromModel();
148 d->initializePieFromModel();
148 }
149 }
149
150
150 /*!
151 /*!
151 Returns the orientation that is used when QPieModelMapper accesses the model.
152 Returns the orientation that is used when QPieModelMapper accesses the model.
152 This mean whether the consecutive values/labels of the pie are read from row (Qt::Horizontal)
153 This mean whether the consecutive values/labels of the pie are read from row (Qt::Horizontal)
153 or from columns (Qt::Vertical)
154 or from columns (Qt::Vertical)
154 */
155 */
155 Qt::Orientation QPieModelMapper::orientation() const
156 Qt::Orientation QPieModelMapper::orientation() const
156 {
157 {
157 Q_D(const QPieModelMapper);
158 Q_D(const QPieModelMapper);
158 return d->m_orientation;
159 return d->m_orientation;
159 }
160 }
160
161
161 /*!
162 /*!
162 Returns the \a orientation that is used when QPieModelMapper accesses the model.
163 Returns the \a orientation that is used when QPieModelMapper accesses the model.
163 This mean whether the consecutive values/labels of the pie are read from row (Qt::Horizontal)
164 This mean whether the consecutive values/labels of the pie are read from row (Qt::Horizontal)
164 or from columns (Qt::Vertical)
165 or from columns (Qt::Vertical)
165 */
166 */
166 void QPieModelMapper::setOrientation(Qt::Orientation orientation)
167 void QPieModelMapper::setOrientation(Qt::Orientation orientation)
167 {
168 {
168 Q_D(QPieModelMapper);
169 Q_D(QPieModelMapper);
169 d->m_orientation = orientation;
170 d->m_orientation = orientation;
170 d->initializePieFromModel();
171 d->initializePieFromModel();
171 }
172 }
172
173
173 /*!
174 /*!
174 Returns which section of the model is kept in sync with the values of the pie's slices
175 Returns which section of the model is kept in sync with the values of the pie's slices
175 */
176 */
176 int QPieModelMapper::valuesSection() const
177 int QPieModelMapper::valuesSection() const
177 {
178 {
178 Q_D(const QPieModelMapper);
179 Q_D(const QPieModelMapper);
179 return d->m_valuesSection;
180 return d->m_valuesSection;
180 }
181 }
181
182
182 /*!
183 /*!
183 Sets the model section that is kept in sync with the pie slices values.
184 Sets the model section that is kept in sync with the pie slices values.
184 Parameter \a valuesSection specifies the section of the model.
185 Parameter \a valuesSection specifies the section of the model.
185 */
186 */
186 void QPieModelMapper::setValuesSection(int valuesSection)
187 void QPieModelMapper::setValuesSection(int valuesSection)
187 {
188 {
188 Q_D(QPieModelMapper);
189 Q_D(QPieModelMapper);
189 d->m_valuesSection = qMax(-1, valuesSection);
190 d->m_valuesSection = qMax(-1, valuesSection);
190 d->initializePieFromModel();
191 d->initializePieFromModel();
191 }
192 }
192
193
193 /*!
194 /*!
194 Returns which section of the model is kept in sync with the labels of the pie's slices
195 Returns which section of the model is kept in sync with the labels of the pie's slices
195 */
196 */
196 int QPieModelMapper::labelsSection() const
197 int QPieModelMapper::labelsSection() const
197 {
198 {
198 Q_D(const QPieModelMapper);
199 Q_D(const QPieModelMapper);
199 return d->m_labelsSection;
200 return d->m_labelsSection;
200 }
201 }
201
202
202 /*!
203 /*!
203 Sets the model section that is kept in sync with the pie slices labels.
204 Sets the model section that is kept in sync with the pie slices labels.
204 Parameter \a labelsSection specifies the section of the model.
205 Parameter \a labelsSection specifies the section of the model.
205 */
206 */
206 void QPieModelMapper::setLabelsSection(int labelsSection)
207 void QPieModelMapper::setLabelsSection(int labelsSection)
207 {
208 {
208 Q_D(QPieModelMapper);
209 Q_D(QPieModelMapper);
209 d->m_labelsSection = qMax(-1, labelsSection);
210 d->m_labelsSection = qMax(-1, labelsSection);
210 d->initializePieFromModel();
211 d->initializePieFromModel();
211 }
212 }
212
213
213 /*!
214 /*!
214 Resets the QPieModelMapper to the default state.
215 Resets the QPieModelMapper to the default state.
215 first: 0; count: -1; valuesSection: -1; labelsSection: -1;
216 first: 0; count: -1; valuesSection: -1; labelsSection: -1;
216 */
217 */
217 void QPieModelMapper::reset()
218 void QPieModelMapper::reset()
218 {
219 {
219 Q_D(QPieModelMapper);
220 Q_D(QPieModelMapper);
220 d->m_first = 0;
221 d->m_first = 0;
221 d->m_count = -1;
222 d->m_count = -1;
222 d->m_valuesSection = -1;
223 d->m_valuesSection = -1;
223 d->m_labelsSection = -1;
224 d->m_labelsSection = -1;
224 }
225 }
225
226
226 ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
227 ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
227
228
228 QPieModelMapperPrivate::QPieModelMapperPrivate(QPieModelMapper *q) :
229 QPieModelMapperPrivate::QPieModelMapperPrivate(QPieModelMapper *q) :
229 m_series(0),
230 m_series(0),
230 m_model(0),
231 m_model(0),
231 m_first(0),
232 m_first(0),
232 m_count(-1),
233 m_count(-1),
233 m_orientation(Qt::Vertical),
234 m_orientation(Qt::Vertical),
234 m_valuesSection(-1),
235 m_valuesSection(-1),
235 m_labelsSection(-1),
236 m_labelsSection(-1),
236 m_seriesSignalsBlock(false),
237 m_seriesSignalsBlock(false),
237 m_modelSignalsBlock(false),
238 m_modelSignalsBlock(false),
238 q_ptr(q)
239 q_ptr(q)
239 {
240 {
240 }
241 }
241
242
242 void QPieModelMapperPrivate::blockModelSignals(bool block)
243 void QPieModelMapperPrivate::blockModelSignals(bool block)
243 {
244 {
244 m_modelSignalsBlock = block;
245 m_modelSignalsBlock = block;
245 }
246 }
246
247
247 void QPieModelMapperPrivate::blockSeriesSignals(bool block)
248 void QPieModelMapperPrivate::blockSeriesSignals(bool block)
248 {
249 {
249 m_seriesSignalsBlock = block;
250 m_seriesSignalsBlock = block;
250 }
251 }
251
252
252
253
253 QPieSlice* QPieModelMapperPrivate::pieSlice(QModelIndex index) const
254 QPieSlice* QPieModelMapperPrivate::pieSlice(QModelIndex index) const
254 {
255 {
255 if (!index.isValid())
256 if (!index.isValid())
256 return 0; // index is invalid
257 return 0; // index is invalid
257
258
258 if (m_orientation == Qt::Vertical && (index.column() == m_valuesSection || index.column() == m_labelsSection)) {
259 if (m_orientation == Qt::Vertical && (index.column() == m_valuesSection || index.column() == m_labelsSection)) {
259 if (index.row() >= m_first && (m_count == - 1 || index.row() < m_first + m_count)) {
260 if (index.row() >= m_first && (m_count == - 1 || index.row() < m_first + m_count)) {
260 if (m_model->index(index.row(), m_valuesSection).isValid() && m_model->index(index.row(), m_labelsSection).isValid())
261 if (m_model->index(index.row(), m_valuesSection).isValid() && m_model->index(index.row(), m_labelsSection).isValid())
261 return m_series->slices().at(index.row() - m_first);
262 return m_series->slices().at(index.row() - m_first);
262 else
263 else
263 return 0;
264 return 0;
264 }
265 }
265 } else if (m_orientation == Qt::Horizontal && (index.row() == m_valuesSection || index.row() == m_labelsSection)) {
266 } else if (m_orientation == Qt::Horizontal && (index.row() == m_valuesSection || index.row() == m_labelsSection)) {
266 if (index.column() >= m_first && (m_count == - 1 || index.column() < m_first + m_count)) {
267 if (index.column() >= m_first && (m_count == - 1 || index.column() < m_first + m_count)) {
267 if (m_model->index(m_valuesSection, index.column()).isValid() && m_model->index(m_labelsSection, index.column()).isValid())
268 if (m_model->index(m_valuesSection, index.column()).isValid() && m_model->index(m_labelsSection, index.column()).isValid())
268 return m_series->slices().at(index.column() - m_first);
269 return m_series->slices().at(index.column() - m_first);
269 else
270 else
270 return 0;
271 return 0;
271 }
272 }
272 }
273 }
273 return 0; // This part of model has not been mapped to any slice
274 return 0; // This part of model has not been mapped to any slice
274 }
275 }
275
276
276 QModelIndex QPieModelMapperPrivate::valueModelIndex(int slicePos)
277 QModelIndex QPieModelMapperPrivate::valueModelIndex(int slicePos)
277 {
278 {
278 if (m_count != -1 && slicePos >= m_count)
279 if (m_count != -1 && slicePos >= m_count)
279 return QModelIndex(); // invalid
280 return QModelIndex(); // invalid
280
281
281 if (m_orientation == Qt::Vertical)
282 if (m_orientation == Qt::Vertical)
282 return m_model->index(slicePos + m_first, m_valuesSection);
283 return m_model->index(slicePos + m_first, m_valuesSection);
283 else
284 else
284 return m_model->index(m_valuesSection, slicePos + m_first);
285 return m_model->index(m_valuesSection, slicePos + m_first);
285 }
286 }
286
287
287 QModelIndex QPieModelMapperPrivate::labelModelIndex(int slicePos)
288 QModelIndex QPieModelMapperPrivate::labelModelIndex(int slicePos)
288 {
289 {
289 if (m_count != -1 && slicePos >= m_count)
290 if (m_count != -1 && slicePos >= m_count)
290 return QModelIndex(); // invalid
291 return QModelIndex(); // invalid
291
292
292 if (m_orientation == Qt::Vertical)
293 if (m_orientation == Qt::Vertical)
293 return m_model->index(slicePos + m_first, m_labelsSection);
294 return m_model->index(slicePos + m_first, m_labelsSection);
294 else
295 else
295 return m_model->index(m_labelsSection, slicePos + m_first);
296 return m_model->index(m_labelsSection, slicePos + m_first);
296 }
297 }
297
298
298 bool QPieModelMapperPrivate::isLabelIndex(QModelIndex index) const
299 bool QPieModelMapperPrivate::isLabelIndex(QModelIndex index) const
299 {
300 {
300 if (m_orientation == Qt::Vertical && index.column() == m_labelsSection)
301 if (m_orientation == Qt::Vertical && index.column() == m_labelsSection)
301 return true;
302 return true;
302 else if (m_orientation == Qt::Horizontal && index.row() == m_labelsSection)
303 else if (m_orientation == Qt::Horizontal && index.row() == m_labelsSection)
303 return true;
304 return true;
304
305
305 return false;
306 return false;
306 }
307 }
307
308
308 bool QPieModelMapperPrivate::isValueIndex(QModelIndex index) const
309 bool QPieModelMapperPrivate::isValueIndex(QModelIndex index) const
309 {
310 {
310 if (m_orientation == Qt::Vertical && index.column() == m_valuesSection)
311 if (m_orientation == Qt::Vertical && index.column() == m_valuesSection)
311 return true;
312 return true;
312 else if (m_orientation == Qt::Horizontal && index.row() == m_valuesSection)
313 else if (m_orientation == Qt::Horizontal && index.row() == m_valuesSection)
313 return true;
314 return true;
314
315
315 return false;
316 return false;
316 }
317 }
317
318
318 void QPieModelMapperPrivate::slicesAdded(QList<QPieSlice*> slices)
319 void QPieModelMapperPrivate::slicesAdded(QList<QPieSlice*> slices)
319 {
320 {
320 if (m_seriesSignalsBlock)
321 if (m_seriesSignalsBlock)
321 return;
322 return;
322
323
323 if (slices.count() == 0)
324 if (slices.count() == 0)
324 return;
325 return;
325
326
326 int firstIndex = m_series->slices().indexOf(slices.at(0));
327 int firstIndex = m_series->slices().indexOf(slices.at(0));
327 if (firstIndex == -1)
328 if (firstIndex == -1)
328 return;
329 return;
329
330
330 if (m_count != -1)
331 if (m_count != -1)
331 m_count += slices.count();
332 m_count += slices.count();
332
333
333 for (int i = firstIndex; i < firstIndex + slices.count(); i++) {
334 for (int i = firstIndex; i < firstIndex + slices.count(); i++) {
334 m_slices.insert(i, slices.at(i - firstIndex));
335 m_slices.insert(i, slices.at(i - firstIndex));
335 connect(slices.at(i - firstIndex), SIGNAL(labelChanged()), this, SLOT(sliceLabelChanged()));
336 connect(slices.at(i - firstIndex), SIGNAL(labelChanged()), this, SLOT(sliceLabelChanged()));
336 connect(slices.at(i - firstIndex), SIGNAL(valueChanged()), this, SLOT(sliceValueChanged()));
337 connect(slices.at(i - firstIndex), SIGNAL(valueChanged()), this, SLOT(sliceValueChanged()));
337 }
338 }
338
339
339 blockModelSignals();
340 blockModelSignals();
340 if (m_orientation == Qt::Vertical)
341 if (m_orientation == Qt::Vertical)
341 m_model->insertRows(firstIndex + m_first, slices.count());
342 m_model->insertRows(firstIndex + m_first, slices.count());
342 else
343 else
343 m_model->insertColumns(firstIndex + m_first, slices.count());
344 m_model->insertColumns(firstIndex + m_first, slices.count());
344
345
345 for(int i = firstIndex; i < firstIndex + slices.count(); i++) {
346 for(int i = firstIndex; i < firstIndex + slices.count(); i++) {
346 m_model->setData(valueModelIndex(i), slices.at(i - firstIndex)->value());
347 m_model->setData(valueModelIndex(i), slices.at(i - firstIndex)->value());
347 m_model->setData(labelModelIndex(i), slices.at(i - firstIndex)->label());
348 m_model->setData(labelModelIndex(i), slices.at(i - firstIndex)->label());
348 }
349 }
349 blockModelSignals(false);
350 blockModelSignals(false);
350 }
351 }
351
352
352 void QPieModelMapperPrivate::slicesRemoved(QList<QPieSlice*> slices)
353 void QPieModelMapperPrivate::slicesRemoved(QList<QPieSlice*> slices)
353 {
354 {
354 if (m_seriesSignalsBlock)
355 if (m_seriesSignalsBlock)
355 return;
356 return;
356
357
357 if (slices.count() == 0)
358 if (slices.count() == 0)
358 return;
359 return;
359
360
360 int firstIndex = m_slices.indexOf(slices.at(0));
361 int firstIndex = m_slices.indexOf(slices.at(0));
361 if (firstIndex == -1)
362 if (firstIndex == -1)
362 return;
363 return;
363
364
364 if (m_count != -1)
365 if (m_count != -1)
365 m_count -= slices.count();
366 m_count -= slices.count();
366
367
367 for (int i = firstIndex + slices.count() - 1; i >= firstIndex; i--)
368 for (int i = firstIndex + slices.count() - 1; i >= firstIndex; i--)
368 m_slices.removeAt(i);
369 m_slices.removeAt(i);
369
370
370 blockModelSignals();
371 blockModelSignals();
371 if (m_orientation == Qt::Vertical)
372 if (m_orientation == Qt::Vertical)
372 m_model->removeRows(firstIndex + m_first, slices.count());
373 m_model->removeRows(firstIndex + m_first, slices.count());
373 else
374 else
374 m_model->removeColumns(firstIndex + m_first, slices.count());
375 m_model->removeColumns(firstIndex + m_first, slices.count());
375 blockModelSignals(false);
376 blockModelSignals(false);
376 }
377 }
377
378
378 void QPieModelMapperPrivate::sliceLabelChanged()
379 void QPieModelMapperPrivate::sliceLabelChanged()
379 {
380 {
380 if (m_seriesSignalsBlock)
381 if (m_seriesSignalsBlock)
381 return;
382 return;
382
383
383 blockModelSignals();
384 blockModelSignals();
384 QPieSlice *slice = qobject_cast<QPieSlice *>(QObject::sender());
385 QPieSlice *slice = qobject_cast<QPieSlice *>(QObject::sender());
385 m_model->setData(labelModelIndex(m_series->slices().indexOf(slice)), slice->label());
386 m_model->setData(labelModelIndex(m_series->slices().indexOf(slice)), slice->label());
386 blockModelSignals(false);
387 blockModelSignals(false);
387 }
388 }
388
389
389 void QPieModelMapperPrivate::sliceValueChanged()
390 void QPieModelMapperPrivate::sliceValueChanged()
390 {
391 {
391 if (m_seriesSignalsBlock)
392 if (m_seriesSignalsBlock)
392 return;
393 return;
393
394
394 blockModelSignals();
395 blockModelSignals();
395 QPieSlice *slice = qobject_cast<QPieSlice *>(QObject::sender());
396 QPieSlice *slice = qobject_cast<QPieSlice *>(QObject::sender());
396 m_model->setData(valueModelIndex(m_series->slices().indexOf(slice)), slice->value());
397 m_model->setData(valueModelIndex(m_series->slices().indexOf(slice)), slice->value());
397 blockModelSignals(false);
398 blockModelSignals(false);
398 }
399 }
399
400
400 void QPieModelMapperPrivate::modelUpdated(QModelIndex topLeft, QModelIndex bottomRight)
401 void QPieModelMapperPrivate::modelUpdated(QModelIndex topLeft, QModelIndex bottomRight)
401 {
402 {
402 if (m_model == 0 || m_series == 0)
403 if (m_model == 0 || m_series == 0)
403 return;
404 return;
404
405
405 if (m_modelSignalsBlock)
406 if (m_modelSignalsBlock)
406 return;
407 return;
407
408
408 blockSeriesSignals();
409 blockSeriesSignals();
409 QModelIndex index;
410 QModelIndex index;
410 QPieSlice *slice;
411 QPieSlice *slice;
411 for (int row = topLeft.row(); row <= bottomRight.row(); row++) {
412 for (int row = topLeft.row(); row <= bottomRight.row(); row++) {
412 for (int column = topLeft.column(); column <= bottomRight.column(); column++) {
413 for (int column = topLeft.column(); column <= bottomRight.column(); column++) {
413 index = topLeft.sibling(row, column);
414 index = topLeft.sibling(row, column);
414 slice = pieSlice(index);
415 slice = pieSlice(index);
415 if (slice) {
416 if (slice) {
416 if (isValueIndex(index))
417 if (isValueIndex(index))
417 slice->setValue(m_model->data(index, Qt::DisplayRole).toReal());
418 slice->setValue(m_model->data(index, Qt::DisplayRole).toReal());
418 if (isLabelIndex(index))
419 if (isLabelIndex(index))
419 slice->setLabel(m_model->data(index, Qt::DisplayRole).toString());
420 slice->setLabel(m_model->data(index, Qt::DisplayRole).toString());
420 }
421 }
421 }
422 }
422 }
423 }
423 blockSeriesSignals(false);
424 blockSeriesSignals(false);
424 }
425 }
425
426
426
427
427 void QPieModelMapperPrivate::modelRowsAdded(QModelIndex parent, int start, int end)
428 void QPieModelMapperPrivate::modelRowsAdded(QModelIndex parent, int start, int end)
428 {
429 {
429 Q_UNUSED(parent);
430 Q_UNUSED(parent);
430 if (m_modelSignalsBlock)
431 if (m_modelSignalsBlock)
431 return;
432 return;
432
433
433 blockSeriesSignals();
434 blockSeriesSignals();
434 if (m_orientation == Qt::Vertical)
435 if (m_orientation == Qt::Vertical)
435 insertData(start, end);
436 insertData(start, end);
436 else if (start <= m_valuesSection || start <= m_labelsSection) // if the changes affect the map - reinitialize the pie
437 else if (start <= m_valuesSection || start <= m_labelsSection) // if the changes affect the map - reinitialize the pie
437 initializePieFromModel();
438 initializePieFromModel();
438 blockSeriesSignals(false);
439 blockSeriesSignals(false);
439 }
440 }
440
441
441 void QPieModelMapperPrivate::modelRowsRemoved(QModelIndex parent, int start, int end)
442 void QPieModelMapperPrivate::modelRowsRemoved(QModelIndex parent, int start, int end)
442 {
443 {
443 Q_UNUSED(parent);
444 Q_UNUSED(parent);
444 if (m_modelSignalsBlock)
445 if (m_modelSignalsBlock)
445 return;
446 return;
446
447
447 blockSeriesSignals();
448 blockSeriesSignals();
448 if (m_orientation == Qt::Vertical)
449 if (m_orientation == Qt::Vertical)
449 removeData(start, end);
450 removeData(start, end);
450 else if (start <= m_valuesSection || start <= m_labelsSection) // if the changes affect the map - reinitialize the pie
451 else if (start <= m_valuesSection || start <= m_labelsSection) // if the changes affect the map - reinitialize the pie
451 initializePieFromModel();
452 initializePieFromModel();
452 blockSeriesSignals(false);
453 blockSeriesSignals(false);
453 }
454 }
454
455
455 void QPieModelMapperPrivate::modelColumnsAdded(QModelIndex parent, int start, int end)
456 void QPieModelMapperPrivate::modelColumnsAdded(QModelIndex parent, int start, int end)
456 {
457 {
457 Q_UNUSED(parent);
458 Q_UNUSED(parent);
458 if (m_modelSignalsBlock)
459 if (m_modelSignalsBlock)
459 return;
460 return;
460
461
461 blockSeriesSignals();
462 blockSeriesSignals();
462 if (m_orientation == Qt::Horizontal)
463 if (m_orientation == Qt::Horizontal)
463 insertData(start, end);
464 insertData(start, end);
464 else if (start <= m_valuesSection || start <= m_labelsSection) // if the changes affect the map - reinitialize the pie
465 else if (start <= m_valuesSection || start <= m_labelsSection) // if the changes affect the map - reinitialize the pie
465 initializePieFromModel();
466 initializePieFromModel();
466 blockSeriesSignals(false);
467 blockSeriesSignals(false);
467 }
468 }
468
469
469 void QPieModelMapperPrivate::modelColumnsRemoved(QModelIndex parent, int start, int end)
470 void QPieModelMapperPrivate::modelColumnsRemoved(QModelIndex parent, int start, int end)
470 {
471 {
471 Q_UNUSED(parent);
472 Q_UNUSED(parent);
472 if (m_modelSignalsBlock)
473 if (m_modelSignalsBlock)
473 return;
474 return;
474
475
475 blockSeriesSignals();
476 blockSeriesSignals();
476 if (m_orientation == Qt::Horizontal)
477 if (m_orientation == Qt::Horizontal)
477 removeData(start, end);
478 removeData(start, end);
478 else if (start <= m_valuesSection || start <= m_labelsSection) // if the changes affect the map - reinitialize the pie
479 else if (start <= m_valuesSection || start <= m_labelsSection) // if the changes affect the map - reinitialize the pie
479 initializePieFromModel();
480 initializePieFromModel();
480 blockSeriesSignals(false);
481 blockSeriesSignals(false);
481 }
482 }
482
483
483 void QPieModelMapperPrivate::insertData(int start, int end)
484 void QPieModelMapperPrivate::insertData(int start, int end)
484 {
485 {
485 if (m_model == 0 || m_series == 0)
486 if (m_model == 0 || m_series == 0)
486 return;
487 return;
487
488
488 if (m_count != -1 && start >= m_first + m_count) {
489 if (m_count != -1 && start >= m_first + m_count) {
489 return;
490 return;
490 } else {
491 } else {
491 int addedCount = end - start + 1;
492 int addedCount = end - start + 1;
492 if (m_count != -1 && addedCount > m_count)
493 if (m_count != -1 && addedCount > m_count)
493 addedCount = m_count;
494 addedCount = m_count;
494 int first = qMax(start, m_first);
495 int first = qMax(start, m_first);
495 int last = qMin(first + addedCount - 1, m_orientation == Qt::Vertical ? m_model->rowCount() - 1 : m_model->columnCount() - 1);
496 int last = qMin(first + addedCount - 1, m_orientation == Qt::Vertical ? m_model->rowCount() - 1 : m_model->columnCount() - 1);
496 for (int i = first; i <= last; i++) {
497 for (int i = first; i <= last; i++) {
497 QModelIndex valueIndex = valueModelIndex(i - m_first);
498 QModelIndex valueIndex = valueModelIndex(i - m_first);
498 QModelIndex labelIndex = labelModelIndex(i - m_first);
499 QModelIndex labelIndex = labelModelIndex(i - m_first);
499 if (valueIndex.isValid() && labelIndex.isValid()) {
500 if (valueIndex.isValid() && labelIndex.isValid()) {
500 QPieSlice *slice = new QPieSlice;
501 QPieSlice *slice = new QPieSlice;
501 slice->setValue(m_model->data(valueIndex, Qt::DisplayRole).toDouble());
502 slice->setValue(m_model->data(valueIndex, Qt::DisplayRole).toDouble());
502 slice->setLabel(m_model->data(labelIndex, Qt::DisplayRole).toString());
503 slice->setLabel(m_model->data(labelIndex, Qt::DisplayRole).toString());
503 slice->setLabelVisible();
504 slice->setLabelVisible();
504 connect(slice, SIGNAL(labelChanged()), this, SLOT(sliceLabelChanged()));
505 connect(slice, SIGNAL(labelChanged()), this, SLOT(sliceLabelChanged()));
505 connect(slice, SIGNAL(valueChanged()), this, SLOT(sliceValueChanged()));
506 connect(slice, SIGNAL(valueChanged()), this, SLOT(sliceValueChanged()));
506 m_series->insert(i - m_first, slice);
507 m_series->insert(i - m_first, slice);
507 m_slices.insert(i - m_first, slice);
508 m_slices.insert(i - m_first, slice);
508 }
509 }
509 }
510 }
510
511
511 // remove excess of slices (abouve m_count)
512 // remove excess of slices (abouve m_count)
512 if (m_count != -1 && m_series->slices().size() > m_count)
513 if (m_count != -1 && m_series->slices().size() > m_count)
513 for (int i = m_series->slices().size() - 1; i >= m_count; i--) {
514 for (int i = m_series->slices().size() - 1; i >= m_count; i--) {
514 m_series->remove(m_series->slices().at(i));
515 m_series->remove(m_series->slices().at(i));
515 m_slices.removeAt(i);
516 m_slices.removeAt(i);
516 }
517 }
517 }
518 }
518 }
519 }
519
520
520 void QPieModelMapperPrivate::removeData(int start, int end)
521 void QPieModelMapperPrivate::removeData(int start, int end)
521 {
522 {
522 if (m_model == 0 || m_series == 0)
523 if (m_model == 0 || m_series == 0)
523 return;
524 return;
524
525
525 int removedCount = end - start + 1;
526 int removedCount = end - start + 1;
526 if (m_count != -1 && start >= m_first + m_count) {
527 if (m_count != -1 && start >= m_first + m_count) {
527 return;
528 return;
528 } else {
529 } else {
529 int toRemove = qMin(m_series->slices().size(), removedCount); // first find how many items can actually be removed
530 int toRemove = qMin(m_series->slices().size(), removedCount); // first find how many items can actually be removed
530 int first = qMax(start, m_first); // get the index of the first item that will be removed.
531 int first = qMax(start, m_first); // get the index of the first item that will be removed.
531 int last = qMin(first + toRemove - 1, m_series->slices().size() + m_first - 1); // get the index of the last item that will be removed.
532 int last = qMin(first + toRemove - 1, m_series->slices().size() + m_first - 1); // get the index of the last item that will be removed.
532 for (int i = last; i >= first; i--) {
533 for (int i = last; i >= first; i--) {
533 m_series->remove(m_series->slices().at(i - m_first));
534 m_series->remove(m_series->slices().at(i - m_first));
534 m_slices.removeAt(i - m_first);
535 m_slices.removeAt(i - m_first);
535 }
536 }
536
537
537 if (m_count != -1) {
538 if (m_count != -1) {
538 int itemsAvailable; // check how many are available to be added
539 int itemsAvailable; // check how many are available to be added
539 if (m_orientation == Qt::Vertical)
540 if (m_orientation == Qt::Vertical)
540 itemsAvailable = m_model->rowCount() - m_first - m_series->slices().size();
541 itemsAvailable = m_model->rowCount() - m_first - m_series->slices().size();
541 else
542 else
542 itemsAvailable = m_model->columnCount() - m_first - m_series->slices().size();
543 itemsAvailable = m_model->columnCount() - m_first - m_series->slices().size();
543 int toBeAdded = qMin(itemsAvailable, m_count - m_series->slices().size()); // add not more items than there is space left to be filled.
544 int toBeAdded = qMin(itemsAvailable, m_count - m_series->slices().size()); // add not more items than there is space left to be filled.
544 int currentSize = m_series->slices().size();
545 int currentSize = m_series->slices().size();
545 if (toBeAdded > 0)
546 if (toBeAdded > 0)
546 for (int i = m_series->slices().size(); i < currentSize + toBeAdded; i++) {
547 for (int i = m_series->slices().size(); i < currentSize + toBeAdded; i++) {
547 QModelIndex valueIndex = valueModelIndex(i - m_first);
548 QModelIndex valueIndex = valueModelIndex(i - m_first);
548 QModelIndex labelIndex = labelModelIndex(i - m_first);
549 QModelIndex labelIndex = labelModelIndex(i - m_first);
549 if (valueIndex.isValid() && labelIndex.isValid()) {
550 if (valueIndex.isValid() && labelIndex.isValid()) {
550 QPieSlice *slice = new QPieSlice;
551 QPieSlice *slice = new QPieSlice;
551 slice->setValue(m_model->data(valueIndex, Qt::DisplayRole).toDouble());
552 slice->setValue(m_model->data(valueIndex, Qt::DisplayRole).toDouble());
552 slice->setLabel(m_model->data(labelIndex, Qt::DisplayRole).toString());
553 slice->setLabel(m_model->data(labelIndex, Qt::DisplayRole).toString());
553 slice->setLabelVisible();
554 slice->setLabelVisible();
554 m_series->insert(i, slice);
555 m_series->insert(i, slice);
555 m_slices.insert(i, slice);
556 m_slices.insert(i, slice);
556 }
557 }
557 }
558 }
558 }
559 }
559 }
560 }
560 }
561 }
561
562
562 void QPieModelMapperPrivate::initializePieFromModel()
563 void QPieModelMapperPrivate::initializePieFromModel()
563 {
564 {
564 if (m_model == 0 || m_series == 0)
565 if (m_model == 0 || m_series == 0)
565 return;
566 return;
566
567
567 blockSeriesSignals();
568 blockSeriesSignals();
568 // clear current content
569 // clear current content
569 m_series->clear();
570 m_series->clear();
570 m_slices.clear();
571 m_slices.clear();
571
572
572 // create the initial slices set
573 // create the initial slices set
573 int slicePos = 0;
574 int slicePos = 0;
574 QModelIndex valueIndex = valueModelIndex(slicePos);
575 QModelIndex valueIndex = valueModelIndex(slicePos);
575 QModelIndex labelIndex = labelModelIndex(slicePos);
576 QModelIndex labelIndex = labelModelIndex(slicePos);
576 while (valueIndex.isValid() && labelIndex.isValid()) {
577 while (valueIndex.isValid() && labelIndex.isValid()) {
577 QPieSlice *slice = new QPieSlice;
578 QPieSlice *slice = new QPieSlice;
578 slice->setLabel(m_model->data(labelIndex, Qt::DisplayRole).toString());
579 slice->setLabel(m_model->data(labelIndex, Qt::DisplayRole).toString());
579 slice->setValue(m_model->data(valueIndex, Qt::DisplayRole).toDouble());
580 slice->setValue(m_model->data(valueIndex, Qt::DisplayRole).toDouble());
580 connect(slice, SIGNAL(labelChanged()), this, SLOT(sliceLabelChanged()));
581 connect(slice, SIGNAL(labelChanged()), this, SLOT(sliceLabelChanged()));
581 connect(slice, SIGNAL(valueChanged()), this, SLOT(sliceValueChanged()));
582 connect(slice, SIGNAL(valueChanged()), this, SLOT(sliceValueChanged()));
582 m_series->append(slice);
583 m_series->append(slice);
583 m_slices.append(slice);
584 m_slices.append(slice);
584 slicePos++;
585 slicePos++;
585 valueIndex = valueModelIndex(slicePos);
586 valueIndex = valueModelIndex(slicePos);
586 labelIndex = labelModelIndex(slicePos);
587 labelIndex = labelModelIndex(slicePos);
587 }
588 }
588 m_series->setLabelsVisible(true);
589 m_series->setLabelsVisible(true);
589 blockSeriesSignals(false);
590 blockSeriesSignals(false);
590 }
591 }
591
592
592 #include "moc_qpiemodelmapper_p.cpp"
593 #include "moc_qpiemodelmapper_p.cpp"
593 #include "moc_qpiemodelmapper.cpp"
594 #include "moc_qpiemodelmapper.cpp"
594
595
595 QTCOMMERCIALCHART_END_NAMESPACE
596 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,94 +1,95
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 \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 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 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.
32 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.
33 NOTE: used model has to support adding/removing rows/columns and modifying the data of the cells.
33 */
34 */
34
35
35 /*!
36 /*!
36 \property QVPieModelMapper::valuesColumn
37 \property QVPieModelMapper::valuesColumn
37 \brief Defines which column of the model is kept in sync with the values of the pie's slices
38 \brief Defines which column of the model is kept in sync with the values of the pie's slices
38
39
39 Default value is: -1 (invalid mapping)
40 Default value is: -1 (invalid mapping)
40 */
41 */
41
42
42 /*!
43 /*!
43 \property QVPieModelMapper::labelsColumn
44 \property QVPieModelMapper::labelsColumn
44 \brief Defines which column of the model is kept in sync with the labels of the pie's slices
45 \brief Defines which column of the model is kept in sync with the labels of the pie's slices
45
46
46 Default value is: -1 (invalid mapping)
47 Default value is: -1 (invalid mapping)
47 */
48 */
48
49
49 /*!
50 /*!
50 Constructs a mapper object which is a child of \a parent.
51 Constructs a mapper object which is a child of \a parent.
51 */
52 */
52 QVPieModelMapper::QVPieModelMapper(QObject *parent) :
53 QVPieModelMapper::QVPieModelMapper(QObject *parent) :
53 QPieModelMapper(parent)
54 QPieModelMapper(parent)
54 {
55 {
55 QPieModelMapper::setOrientation(Qt::Vertical);
56 QPieModelMapper::setOrientation(Qt::Vertical);
56 }
57 }
57
58
58 /*!
59 /*!
59 Returns which column of the model is kept in sync with the values of the pie's slices
60 Returns which column of the model is kept in sync with the values of the pie's slices
60 */
61 */
61 int QVPieModelMapper::valuesColumn() const
62 int QVPieModelMapper::valuesColumn() const
62 {
63 {
63 return QPieModelMapper::valuesSection();
64 return QPieModelMapper::valuesSection();
64 }
65 }
65
66
66 /*!
67 /*!
67 Sets the model column that is kept in sync with the pie slices values.
68 Sets the model column that is kept in sync with the pie slices values.
68 Parameter \a valuesColumn specifies the row of the model.
69 Parameter \a valuesColumn specifies the row of the model.
69 */
70 */
70 void QVPieModelMapper::setValuesColumn(int valuesColumn)
71 void QVPieModelMapper::setValuesColumn(int valuesColumn)
71 {
72 {
72 QPieModelMapper::setValuesSection(valuesColumn);
73 QPieModelMapper::setValuesSection(valuesColumn);
73 }
74 }
74
75
75 /*!
76 /*!
76 Returns which column of the model is kept in sync with the labels of the pie's slices
77 Returns which column of the model is kept in sync with the labels of the pie's slices
77 */
78 */
78 int QVPieModelMapper::labelsColumn() const
79 int QVPieModelMapper::labelsColumn() const
79 {
80 {
80 return QPieModelMapper::labelsSection();
81 return QPieModelMapper::labelsSection();
81 }
82 }
82
83
83 /*!
84 /*!
84 Sets the model column that is kept in sync with the pie's slices labels.
85 Sets the model column that is kept in sync with the pie's slices labels.
85 Parameter \a labelsColumn specifies the row of the model.
86 Parameter \a labelsColumn specifies the row of the model.
86 */
87 */
87 void QVPieModelMapper::setLabelsColumn(int labelsColumn)
88 void QVPieModelMapper::setLabelsColumn(int labelsColumn)
88 {
89 {
89 QPieModelMapper::setLabelsSection(labelsColumn);
90 QPieModelMapper::setLabelsSection(labelsColumn);
90 }
91 }
91
92
92 #include "moc_qvpiemodelmapper.cpp"
93 #include "moc_qvpiemodelmapper.cpp"
93
94
94 QTCOMMERCIALCHART_END_NAMESPACE
95 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,79 +1,80
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 \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 Horizontal model mapper is used to create a connection between QXYSeries and QAbstractItemModel derived model object.
31 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.
32 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.
33 NOTE: used model has to support adding/removing rows/columns and modifying the data of the cells.
33 */
34 */
34
35
35 /*!
36 /*!
36 \property QHXYModelMapper::xRow
37 \property QHXYModelMapper::xRow
37 \brief Defines which row of the model is kept in sync with the x values of the QXYSeries
38 \brief Defines which row of the model is kept in sync with the x values of the QXYSeries
38 Default value is: -1 (invalid mapping)
39 Default value is: -1 (invalid mapping)
39 */
40 */
40
41
41 /*!
42 /*!
42 \property QHXYModelMapper::yRow
43 \property QHXYModelMapper::yRow
43 \brief Defines which row of the model is kept in sync with the y values of the QXYSeries
44 \brief Defines which row of the model is kept in sync with the y values of the QXYSeries
44
45
45 Default value is: -1 (invalid mapping)
46 Default value is: -1 (invalid mapping)
46 */
47 */
47
48
48 /*!
49 /*!
49 Constructs a mapper object which is a child of \a parent.
50 Constructs a mapper object which is a child of \a parent.
50 */
51 */
51 QHXYModelMapper::QHXYModelMapper(QObject *parent) :
52 QHXYModelMapper::QHXYModelMapper(QObject *parent) :
52 QXYModelMapper(parent)
53 QXYModelMapper(parent)
53 {
54 {
54 QXYModelMapper::setOrientation(Qt::Horizontal);
55 QXYModelMapper::setOrientation(Qt::Horizontal);
55 }
56 }
56
57
57 int QHXYModelMapper::xRow() const
58 int QHXYModelMapper::xRow() const
58 {
59 {
59 return QXYModelMapper::xSection();
60 return QXYModelMapper::xSection();
60 }
61 }
61
62
62 void QHXYModelMapper::setXRow(int xRow)
63 void QHXYModelMapper::setXRow(int xRow)
63 {
64 {
64 return QXYModelMapper::setXSection(xRow);
65 return QXYModelMapper::setXSection(xRow);
65 }
66 }
66
67
67 int QHXYModelMapper::yRow() const
68 int QHXYModelMapper::yRow() const
68 {
69 {
69 return QXYModelMapper::ySection();
70 return QXYModelMapper::ySection();
70 }
71 }
71
72
72 void QHXYModelMapper::setYRow(int yRow)
73 void QHXYModelMapper::setYRow(int yRow)
73 {
74 {
74 return QXYModelMapper::setYSection(yRow);
75 return QXYModelMapper::setYSection(yRow);
75 }
76 }
76
77
77 #include "moc_qhxymodelmapper.cpp"
78 #include "moc_qhxymodelmapper.cpp"
78
79
79 QTCOMMERCIALCHART_END_NAMESPACE
80 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,80 +1,81
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 \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 Vertical model mapper is used to create a connection between QXYSeries and QAbstractItemModel derived model object.
31 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.
32 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.
33 NOTE: used model has to support adding/removing rows/columns and modifying the data of the cells.
33 */
34 */
34
35
35 /*!
36 /*!
36 \property QVXYModelMapper::xColumn
37 \property QVXYModelMapper::xColumn
37 \brief Defines which column of the model is kept in sync with the x values of QXYSeries
38 \brief Defines which column of the model is kept in sync with the x values of QXYSeries
38
39
39 Default value is: -1 (invalid mapping)
40 Default value is: -1 (invalid mapping)
40 */
41 */
41
42
42 /*!
43 /*!
43 \property QVXYModelMapper::yColumn
44 \property QVXYModelMapper::yColumn
44 \brief Defines which column of the model is kept in sync with the y values of QXYSeries
45 \brief Defines which column of the model is kept in sync with the y values of QXYSeries
45
46
46 Default value is: -1 (invalid mapping)
47 Default value is: -1 (invalid mapping)
47 */
48 */
48
49
49 /*!
50 /*!
50 Constructs a mapper object which is a child of \a parent.
51 Constructs a mapper object which is a child of \a parent.
51 */
52 */
52 QVXYModelMapper::QVXYModelMapper(QObject *parent) :
53 QVXYModelMapper::QVXYModelMapper(QObject *parent) :
53 QXYModelMapper(parent)
54 QXYModelMapper(parent)
54 {
55 {
55 QXYModelMapper::setOrientation(Qt::Vertical);
56 QXYModelMapper::setOrientation(Qt::Vertical);
56 }
57 }
57
58
58 int QVXYModelMapper::xColumn() const
59 int QVXYModelMapper::xColumn() const
59 {
60 {
60 return QXYModelMapper::xSection();
61 return QXYModelMapper::xSection();
61 }
62 }
62
63
63 void QVXYModelMapper::setXColumn(int xColumn)
64 void QVXYModelMapper::setXColumn(int xColumn)
64 {
65 {
65 return QXYModelMapper::setXSection(xColumn);
66 return QXYModelMapper::setXSection(xColumn);
66 }
67 }
67
68
68 int QVXYModelMapper::yColumn() const
69 int QVXYModelMapper::yColumn() const
69 {
70 {
70 return QXYModelMapper::ySection();
71 return QXYModelMapper::ySection();
71 }
72 }
72
73
73 void QVXYModelMapper::setYColumn(int yColumn)
74 void QVXYModelMapper::setYColumn(int yColumn)
74 {
75 {
75 return QXYModelMapper::setYSection(yColumn);
76 return QXYModelMapper::setYSection(yColumn);
76 }
77 }
77
78
78 #include "moc_qvxymodelmapper.cpp"
79 #include "moc_qvxymodelmapper.cpp"
79
80
80 QTCOMMERCIALCHART_END_NAMESPACE
81 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,521 +1,522
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 "qxymodelmapper.h"
21 #include "qxymodelmapper.h"
22 #include "qxymodelmapper_p.h"
22 #include "qxymodelmapper_p.h"
23 #include "qxyseries.h"
23 #include "qxyseries.h"
24 #include <QAbstractItemModel>
24 #include <QAbstractItemModel>
25
25
26 QTCOMMERCIALCHART_BEGIN_NAMESPACE
26 QTCOMMERCIALCHART_BEGIN_NAMESPACE
27
27
28 /*!
28 /*!
29 \class QXYModelMapper
29 \class QXYModelMapper
30 \brief part of QtCommercial chart API.
30 \brief part of QtCommercial chart API.
31 \mainclass
31 \mainclass
32
32
33 Model mappers allow you to use QAbstractItemModel derived models as a data source for a chart series.
33 The instance of this class cannot be created directly. QHXYModelMapper of QVXYModelMapper should be used instead. This class is used to create a connection between QXYSeries and QAbstractItemModel derived model object.
34 The instance of this class cannot be created directly. QHXYModelMapper of QVXYModelMapper should be used instead. This class is used to create a connection between QXYSeries and QAbstractItemModel derived model object.
34 It is possible to use both QAbstractItemModel and QXYSeries model API. QXYModelMapper makes sure that QXYSeries and the model are kept in sync.
35 It is possible to use both QAbstractItemModel and QXYSeries model API. QXYModelMapper makes sure that QXYSeries and the model are kept in sync.
35 NOTE: used model has to support adding/removing rows/columns and modifying the data of the cells.
36 NOTE: used model has to support adding/removing rows/columns and modifying the data of the cells.
36 */
37 */
37
38
38 /*!
39 /*!
39 \property QXYModelMapper::series
40 \property QXYModelMapper::series
40 \brief Defines the QPieSeries object that is used by the mapper.
41 \brief Defines the QPieSeries object that is used by the mapper.
41
42
42 All the data in the series is discarded when it is set to the mapper.
43 All the data in the series is discarded when it is set to the mapper.
43 When new series is specified the old series is disconnected (it preserves its data)
44 When new series is specified the old series is disconnected (it preserves its data)
44 */
45 */
45
46
46 /*!
47 /*!
47 \property QXYModelMapper::model
48 \property QXYModelMapper::model
48 \brief Defines the model that is used by the mapper.
49 \brief Defines the model that is used by the mapper.
49 */
50 */
50
51
51 /*!
52 /*!
52 \property QXYModelMapper::first
53 \property QXYModelMapper::first
53 \brief Defines which item of the model's row/column should be mapped as the first x/y pair
54 \brief Defines which item of the model's row/column should be mapped as the first x/y pair
54
55
55 Minimal and default value is: 0
56 Minimal and default value is: 0
56 */
57 */
57
58
58 /*!
59 /*!
59 \property QXYModelMapper::count
60 \property QXYModelMapper::count
60 \brief Defines the number of rows/columns of the model that are mapped as the data for QXYSeries
61 \brief Defines the number of rows/columns of the model that are mapped as the data for QXYSeries
61
62
62 Minimal and default value is: -1 (count limited by the number of rows/columns in the model)
63 Minimal and default value is: -1 (count limited by the number of rows/columns in the model)
63 */
64 */
64
65
65 /*!
66 /*!
66 Constructs a mapper object which is a child of \a parent.
67 Constructs a mapper object which is a child of \a parent.
67 */
68 */
68 QXYModelMapper::QXYModelMapper(QObject *parent):
69 QXYModelMapper::QXYModelMapper(QObject *parent):
69 QObject(parent),
70 QObject(parent),
70 d_ptr(new QXYModelMapperPrivate(this))
71 d_ptr(new QXYModelMapperPrivate(this))
71 {
72 {
72 }
73 }
73
74
74 QAbstractItemModel* QXYModelMapper::model() const
75 QAbstractItemModel* QXYModelMapper::model() const
75 {
76 {
76 Q_D(const QXYModelMapper);
77 Q_D(const QXYModelMapper);
77 return d->m_model;
78 return d->m_model;
78 }
79 }
79
80
80 void QXYModelMapper::setModel(QAbstractItemModel *model)
81 void QXYModelMapper::setModel(QAbstractItemModel *model)
81 {
82 {
82 if (model == 0)
83 if (model == 0)
83 return;
84 return;
84
85
85 Q_D(QXYModelMapper);
86 Q_D(QXYModelMapper);
86 if (d->m_model) {
87 if (d->m_model) {
87 disconnect(d->m_model, 0, d, 0);
88 disconnect(d->m_model, 0, d, 0);
88 }
89 }
89
90
90 d->m_model = model;
91 d->m_model = model;
91 d->initializeXYFromModel();
92 d->initializeXYFromModel();
92 // connect signals from the model
93 // connect signals from the model
93 connect(d->m_model, SIGNAL(dataChanged(QModelIndex,QModelIndex)), d, SLOT(modelUpdated(QModelIndex,QModelIndex)));
94 connect(d->m_model, SIGNAL(dataChanged(QModelIndex,QModelIndex)), d, SLOT(modelUpdated(QModelIndex,QModelIndex)));
94 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)));
95 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)));
96 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)));
97 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)));
98 }
99 }
99
100
100 QXYSeries* QXYModelMapper::series() const
101 QXYSeries* QXYModelMapper::series() const
101 {
102 {
102 Q_D(const QXYModelMapper);
103 Q_D(const QXYModelMapper);
103 return d->m_series;
104 return d->m_series;
104 }
105 }
105
106
106 void QXYModelMapper::setSeries(QXYSeries *series)
107 void QXYModelMapper::setSeries(QXYSeries *series)
107 {
108 {
108 Q_D(QXYModelMapper);
109 Q_D(QXYModelMapper);
109 if (d->m_series) {
110 if (d->m_series) {
110 disconnect(d->m_series, 0, d, 0);
111 disconnect(d->m_series, 0, d, 0);
111 }
112 }
112
113
113 if (series == 0)
114 if (series == 0)
114 return;
115 return;
115
116
116 d->m_series = series;
117 d->m_series = series;
117 d->initializeXYFromModel();
118 d->initializeXYFromModel();
118 // connect the signals from the series
119 // connect the signals from the series
119 connect(d->m_series, SIGNAL(pointAdded(int)), d, SLOT(handlePointAdded(int)));
120 connect(d->m_series, SIGNAL(pointAdded(int)), d, SLOT(handlePointAdded(int)));
120 connect(d->m_series, SIGNAL(pointRemoved(int)), d, SLOT(handlePointRemoved(int)));
121 connect(d->m_series, SIGNAL(pointRemoved(int)), d, SLOT(handlePointRemoved(int)));
121 connect(d->m_series, SIGNAL(pointReplaced(int)), d, SLOT(handlePointReplaced(int)));
122 connect(d->m_series, SIGNAL(pointReplaced(int)), d, SLOT(handlePointReplaced(int)));
122 }
123 }
123
124
124 int QXYModelMapper::first() const
125 int QXYModelMapper::first() const
125 {
126 {
126 Q_D(const QXYModelMapper);
127 Q_D(const QXYModelMapper);
127 return d->m_first;
128 return d->m_first;
128 }
129 }
129
130
130 void QXYModelMapper::setFirst(int first)
131 void QXYModelMapper::setFirst(int first)
131 {
132 {
132 Q_D(QXYModelMapper);
133 Q_D(QXYModelMapper);
133 d->m_first = qMax(first, 0);
134 d->m_first = qMax(first, 0);
134 d->initializeXYFromModel();
135 d->initializeXYFromModel();
135 }
136 }
136
137
137 int QXYModelMapper::count() const
138 int QXYModelMapper::count() const
138 {
139 {
139 Q_D(const QXYModelMapper);
140 Q_D(const QXYModelMapper);
140 return d->m_count;
141 return d->m_count;
141 }
142 }
142
143
143 void QXYModelMapper::setCount(int count)
144 void QXYModelMapper::setCount(int count)
144 {
145 {
145 Q_D(QXYModelMapper);
146 Q_D(QXYModelMapper);
146 d->m_count = qMax(count, -1);
147 d->m_count = qMax(count, -1);
147 d->initializeXYFromModel();
148 d->initializeXYFromModel();
148 }
149 }
149
150
150 /*!
151 /*!
151 Returns the orientation that is used when QXYModelMapper accesses the model.
152 Returns the orientation that is used when QXYModelMapper accesses the model.
152 This mean whether the consecutive x/y values of the QXYSeries are read from rows (Qt::Horizontal)
153 This mean whether the consecutive x/y values of the QXYSeries are read from rows (Qt::Horizontal)
153 or from columns (Qt::Vertical)
154 or from columns (Qt::Vertical)
154 */
155 */
155 Qt::Orientation QXYModelMapper::orientation() const
156 Qt::Orientation QXYModelMapper::orientation() const
156 {
157 {
157 Q_D(const QXYModelMapper);
158 Q_D(const QXYModelMapper);
158 return d->m_orientation;
159 return d->m_orientation;
159 }
160 }
160
161
161 /*!
162 /*!
162 Returns the \a orientation that is used when QXYModelMapper accesses the model.
163 Returns the \a orientation that is used when QXYModelMapper accesses the model.
163 This mean whether the consecutive x/y values of the QXYSeries are read from rows (Qt::Horizontal)
164 This mean whether the consecutive x/y values of the QXYSeries are read from rows (Qt::Horizontal)
164 or from columns (Qt::Vertical)
165 or from columns (Qt::Vertical)
165 */
166 */
166 void QXYModelMapper::setOrientation(Qt::Orientation orientation)
167 void QXYModelMapper::setOrientation(Qt::Orientation orientation)
167 {
168 {
168 Q_D(QXYModelMapper);
169 Q_D(QXYModelMapper);
169 d->m_orientation = orientation;
170 d->m_orientation = orientation;
170 d->initializeXYFromModel();
171 d->initializeXYFromModel();
171 }
172 }
172
173
173 /*!
174 /*!
174 Returns which section of the model is kept in sync with the x values of the QXYSeries
175 Returns which section of the model is kept in sync with the x values of the QXYSeries
175 */
176 */
176 int QXYModelMapper::xSection() const
177 int QXYModelMapper::xSection() const
177 {
178 {
178 Q_D(const QXYModelMapper);
179 Q_D(const QXYModelMapper);
179 return d->m_xSection;
180 return d->m_xSection;
180 }
181 }
181
182
182 /*!
183 /*!
183 Sets the model section that is kept in sync with the x values of the QXYSeries.
184 Sets the model section that is kept in sync with the x values of the QXYSeries.
184 Parameter \a xSection specifies the section of the model.
185 Parameter \a xSection specifies the section of the model.
185 */
186 */
186 void QXYModelMapper::setXSection(int xSection)
187 void QXYModelMapper::setXSection(int xSection)
187 {
188 {
188 Q_D(QXYModelMapper);
189 Q_D(QXYModelMapper);
189 d->m_xSection = qMax(-1, xSection);
190 d->m_xSection = qMax(-1, xSection);
190 d->initializeXYFromModel();
191 d->initializeXYFromModel();
191 }
192 }
192
193
193 /*!
194 /*!
194 Returns which section of the model is kept in sync with the y values of the QXYSeries
195 Returns which section of the model is kept in sync with the y values of the QXYSeries
195 */
196 */
196 int QXYModelMapper::ySection() const
197 int QXYModelMapper::ySection() const
197 {
198 {
198 Q_D(const QXYModelMapper);
199 Q_D(const QXYModelMapper);
199 return d->m_ySection;
200 return d->m_ySection;
200 }
201 }
201
202
202 /*!
203 /*!
203 Sets the model section that is kept in sync with the y values of the QXYSeries.
204 Sets the model section that is kept in sync with the y values of the QXYSeries.
204 Parameter \a ySection specifies the section of the model.
205 Parameter \a ySection specifies the section of the model.
205 */
206 */
206 void QXYModelMapper::setYSection(int ySection)
207 void QXYModelMapper::setYSection(int ySection)
207 {
208 {
208 Q_D(QXYModelMapper);
209 Q_D(QXYModelMapper);
209 d->m_ySection = qMax(-1, ySection);
210 d->m_ySection = qMax(-1, ySection);
210 d->initializeXYFromModel();
211 d->initializeXYFromModel();
211 }
212 }
212
213
213 /*!
214 /*!
214 Resets the QXYModelMapper to the default state.
215 Resets the QXYModelMapper to the default state.
215 first: 0; count: -1; xSection: -1; ySection: -1;
216 first: 0; count: -1; xSection: -1; ySection: -1;
216 */
217 */
217 void QXYModelMapper::reset()
218 void QXYModelMapper::reset()
218 {
219 {
219 Q_D(QXYModelMapper);
220 Q_D(QXYModelMapper);
220 d->m_first = 0;
221 d->m_first = 0;
221 d->m_count = -1;
222 d->m_count = -1;
222 d->m_orientation = Qt::Vertical;
223 d->m_orientation = Qt::Vertical;
223 d->m_xSection = -1;
224 d->m_xSection = -1;
224 d->m_ySection = -1;
225 d->m_ySection = -1;
225 d->initializeXYFromModel();
226 d->initializeXYFromModel();
226 }
227 }
227
228
228 ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
229 ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
229
230
230 QXYModelMapperPrivate::QXYModelMapperPrivate(QXYModelMapper *q) :
231 QXYModelMapperPrivate::QXYModelMapperPrivate(QXYModelMapper *q) :
231 m_series(0),
232 m_series(0),
232 m_model(0),
233 m_model(0),
233 m_first(0),
234 m_first(0),
234 m_count(-1),
235 m_count(-1),
235 m_orientation(Qt::Vertical),
236 m_orientation(Qt::Vertical),
236 m_xSection(-1),
237 m_xSection(-1),
237 m_ySection(-1),
238 m_ySection(-1),
238 m_seriesSignalsBlock(false),
239 m_seriesSignalsBlock(false),
239 m_modelSignalsBlock(false),
240 m_modelSignalsBlock(false),
240 q_ptr(q)
241 q_ptr(q)
241 {
242 {
242 }
243 }
243
244
244 void QXYModelMapperPrivate::blockModelSignals(bool block)
245 void QXYModelMapperPrivate::blockModelSignals(bool block)
245 {
246 {
246 m_modelSignalsBlock = block;
247 m_modelSignalsBlock = block;
247 }
248 }
248
249
249 void QXYModelMapperPrivate::blockSeriesSignals(bool block)
250 void QXYModelMapperPrivate::blockSeriesSignals(bool block)
250 {
251 {
251 m_seriesSignalsBlock = block;
252 m_seriesSignalsBlock = block;
252 }
253 }
253
254
254 QModelIndex QXYModelMapperPrivate::xModelIndex(int xPos)
255 QModelIndex QXYModelMapperPrivate::xModelIndex(int xPos)
255 {
256 {
256 if (m_count != -1 && xPos >= m_count)
257 if (m_count != -1 && xPos >= m_count)
257 return QModelIndex(); // invalid
258 return QModelIndex(); // invalid
258
259
259 if (m_orientation == Qt::Vertical)
260 if (m_orientation == Qt::Vertical)
260 return m_model->index(xPos + m_first, m_xSection);
261 return m_model->index(xPos + m_first, m_xSection);
261 else
262 else
262 return m_model->index(m_xSection, xPos + m_first);
263 return m_model->index(m_xSection, xPos + m_first);
263 }
264 }
264
265
265 QModelIndex QXYModelMapperPrivate::yModelIndex(int yPos)
266 QModelIndex QXYModelMapperPrivate::yModelIndex(int yPos)
266 {
267 {
267 if (m_count != -1 && yPos >= m_count)
268 if (m_count != -1 && yPos >= m_count)
268 return QModelIndex(); // invalid
269 return QModelIndex(); // invalid
269
270
270 if (m_orientation == Qt::Vertical)
271 if (m_orientation == Qt::Vertical)
271 return m_model->index(yPos + m_first, m_ySection);
272 return m_model->index(yPos + m_first, m_ySection);
272 else
273 else
273 return m_model->index(m_ySection, yPos + m_first);
274 return m_model->index(m_ySection, yPos + m_first);
274 }
275 }
275
276
276 void QXYModelMapperPrivate::handlePointAdded(int pointPos)
277 void QXYModelMapperPrivate::handlePointAdded(int pointPos)
277 {
278 {
278 if (m_seriesSignalsBlock)
279 if (m_seriesSignalsBlock)
279 return;
280 return;
280
281
281 if (m_count != -1)
282 if (m_count != -1)
282 m_count += 1;
283 m_count += 1;
283
284
284 blockModelSignals();
285 blockModelSignals();
285 if (m_orientation == Qt::Vertical)
286 if (m_orientation == Qt::Vertical)
286 m_model->insertRows(pointPos + m_first, 1);
287 m_model->insertRows(pointPos + m_first, 1);
287 else
288 else
288 m_model->insertColumns(pointPos + m_first, 1);
289 m_model->insertColumns(pointPos + m_first, 1);
289
290
290 m_model->setData(xModelIndex(pointPos), m_series->points().at(pointPos).x());
291 m_model->setData(xModelIndex(pointPos), m_series->points().at(pointPos).x());
291 m_model->setData(yModelIndex(pointPos), m_series->points().at(pointPos).y());
292 m_model->setData(yModelIndex(pointPos), m_series->points().at(pointPos).y());
292 blockModelSignals(false);
293 blockModelSignals(false);
293 }
294 }
294
295
295 void QXYModelMapperPrivate::handlePointRemoved(int pointPos)
296 void QXYModelMapperPrivate::handlePointRemoved(int pointPos)
296 {
297 {
297 if (m_seriesSignalsBlock)
298 if (m_seriesSignalsBlock)
298 return;
299 return;
299
300
300 if (m_count != -1)
301 if (m_count != -1)
301 m_count -= 1;
302 m_count -= 1;
302
303
303 blockModelSignals();
304 blockModelSignals();
304 if (m_orientation == Qt::Vertical)
305 if (m_orientation == Qt::Vertical)
305 m_model->removeRow(pointPos + m_first);
306 m_model->removeRow(pointPos + m_first);
306 else
307 else
307 m_model->removeColumn(pointPos + m_first);
308 m_model->removeColumn(pointPos + m_first);
308 blockModelSignals(false);
309 blockModelSignals(false);
309 }
310 }
310
311
311 void QXYModelMapperPrivate::handlePointReplaced(int pointPos)
312 void QXYModelMapperPrivate::handlePointReplaced(int pointPos)
312 {
313 {
313 if (m_seriesSignalsBlock)
314 if (m_seriesSignalsBlock)
314 return;
315 return;
315
316
316 blockModelSignals();
317 blockModelSignals();
317 m_model->setData(xModelIndex(pointPos), m_series->points().at(pointPos).x());
318 m_model->setData(xModelIndex(pointPos), m_series->points().at(pointPos).x());
318 m_model->setData(yModelIndex(pointPos), m_series->points().at(pointPos).y());
319 m_model->setData(yModelIndex(pointPos), m_series->points().at(pointPos).y());
319 blockModelSignals(false);
320 blockModelSignals(false);
320 }
321 }
321
322
322 void QXYModelMapperPrivate::modelUpdated(QModelIndex topLeft, QModelIndex bottomRight)
323 void QXYModelMapperPrivate::modelUpdated(QModelIndex topLeft, QModelIndex bottomRight)
323 {
324 {
324 if (m_model == 0 || m_series == 0)
325 if (m_model == 0 || m_series == 0)
325 return;
326 return;
326
327
327 if (m_modelSignalsBlock)
328 if (m_modelSignalsBlock)
328 return;
329 return;
329
330
330 blockSeriesSignals();
331 blockSeriesSignals();
331 QModelIndex index;
332 QModelIndex index;
332 QPointF oldPoint;
333 QPointF oldPoint;
333 QPointF newPoint;
334 QPointF newPoint;
334 for (int row = topLeft.row(); row <= bottomRight.row(); row++) {
335 for (int row = topLeft.row(); row <= bottomRight.row(); row++) {
335 for (int column = topLeft.column(); column <= bottomRight.column(); column++) {
336 for (int column = topLeft.column(); column <= bottomRight.column(); column++) {
336 index = topLeft.sibling(row, column);
337 index = topLeft.sibling(row, column);
337 if (m_orientation == Qt::Vertical && (index.column() == m_xSection || index.column() == m_ySection)) {
338 if (m_orientation == Qt::Vertical && (index.column() == m_xSection || index.column() == m_ySection)) {
338 if (index.row() >= m_first && (m_count == - 1 || index.row() < m_first + m_count)) {
339 if (index.row() >= m_first && (m_count == - 1 || index.row() < m_first + m_count)) {
339 QModelIndex xIndex = xModelIndex(index.row() - m_first);
340 QModelIndex xIndex = xModelIndex(index.row() - m_first);
340 QModelIndex yIndex = yModelIndex(index.row() - m_first);
341 QModelIndex yIndex = yModelIndex(index.row() - m_first);
341 if (xIndex.isValid() && yIndex.isValid()) {
342 if (xIndex.isValid() && yIndex.isValid()) {
342 oldPoint = m_series->points().at(index.row() - m_first);
343 oldPoint = m_series->points().at(index.row() - m_first);
343 newPoint.setX(m_model->data(xIndex).toReal());
344 newPoint.setX(m_model->data(xIndex).toReal());
344 newPoint.setY(m_model->data(yIndex).toReal());
345 newPoint.setY(m_model->data(yIndex).toReal());
345 }
346 }
346 }
347 }
347 } else if (m_orientation == Qt::Horizontal && (index.row() == m_xSection || index.row() == m_ySection)) {
348 } else if (m_orientation == Qt::Horizontal && (index.row() == m_xSection || index.row() == m_ySection)) {
348 if (index.column() >= m_first && (m_count == - 1 || index.column() < m_first + m_count)) {
349 if (index.column() >= m_first && (m_count == - 1 || index.column() < m_first + m_count)) {
349 QModelIndex xIndex = xModelIndex(index.column() - m_first);
350 QModelIndex xIndex = xModelIndex(index.column() - m_first);
350 QModelIndex yIndex = yModelIndex(index.column() - m_first);
351 QModelIndex yIndex = yModelIndex(index.column() - m_first);
351 if (xIndex.isValid() && yIndex.isValid()) {
352 if (xIndex.isValid() && yIndex.isValid()) {
352 oldPoint = m_series->points().at(index.column() - m_first);
353 oldPoint = m_series->points().at(index.column() - m_first);
353 newPoint.setX(m_model->data(xIndex).toReal());
354 newPoint.setX(m_model->data(xIndex).toReal());
354 newPoint.setY(m_model->data(yIndex).toReal());
355 newPoint.setY(m_model->data(yIndex).toReal());
355 }
356 }
356 }
357 }
357 } else {
358 } else {
358 continue;
359 continue;
359 }
360 }
360 m_series->replace(oldPoint, newPoint);
361 m_series->replace(oldPoint, newPoint);
361 }
362 }
362 }
363 }
363 blockSeriesSignals(false);
364 blockSeriesSignals(false);
364 }
365 }
365
366
366 void QXYModelMapperPrivate::modelRowsAdded(QModelIndex parent, int start, int end)
367 void QXYModelMapperPrivate::modelRowsAdded(QModelIndex parent, int start, int end)
367 {
368 {
368 Q_UNUSED(parent);
369 Q_UNUSED(parent);
369 if (m_modelSignalsBlock)
370 if (m_modelSignalsBlock)
370 return;
371 return;
371
372
372 blockSeriesSignals();
373 blockSeriesSignals();
373 if (m_orientation == Qt::Vertical)
374 if (m_orientation == Qt::Vertical)
374 insertData(start, end);
375 insertData(start, end);
375 else if (start <= m_xSection || start <= m_ySection) // if the changes affect the map - reinitialize the xy
376 else if (start <= m_xSection || start <= m_ySection) // if the changes affect the map - reinitialize the xy
376 initializeXYFromModel();
377 initializeXYFromModel();
377 blockSeriesSignals(false);
378 blockSeriesSignals(false);
378 }
379 }
379
380
380 void QXYModelMapperPrivate::modelRowsRemoved(QModelIndex parent, int start, int end)
381 void QXYModelMapperPrivate::modelRowsRemoved(QModelIndex parent, int start, int end)
381 {
382 {
382 Q_UNUSED(parent);
383 Q_UNUSED(parent);
383 if (m_modelSignalsBlock)
384 if (m_modelSignalsBlock)
384 return;
385 return;
385
386
386 blockSeriesSignals();
387 blockSeriesSignals();
387 if (m_orientation == Qt::Vertical)
388 if (m_orientation == Qt::Vertical)
388 removeData(start, end);
389 removeData(start, end);
389 else if (start <= m_xSection || start <= m_ySection) // if the changes affect the map - reinitialize the xy
390 else if (start <= m_xSection || start <= m_ySection) // if the changes affect the map - reinitialize the xy
390 initializeXYFromModel();
391 initializeXYFromModel();
391 blockSeriesSignals(false);
392 blockSeriesSignals(false);
392 }
393 }
393
394
394 void QXYModelMapperPrivate::modelColumnsAdded(QModelIndex parent, int start, int end)
395 void QXYModelMapperPrivate::modelColumnsAdded(QModelIndex parent, int start, int end)
395 {
396 {
396 Q_UNUSED(parent);
397 Q_UNUSED(parent);
397 if (m_modelSignalsBlock)
398 if (m_modelSignalsBlock)
398 return;
399 return;
399
400
400 blockSeriesSignals();
401 blockSeriesSignals();
401 if (m_orientation == Qt::Horizontal)
402 if (m_orientation == Qt::Horizontal)
402 insertData(start, end);
403 insertData(start, end);
403 else if (start <= m_xSection || start <= m_ySection) // if the changes affect the map - reinitialize the xy
404 else if (start <= m_xSection || start <= m_ySection) // if the changes affect the map - reinitialize the xy
404 initializeXYFromModel();
405 initializeXYFromModel();
405 blockSeriesSignals(false);
406 blockSeriesSignals(false);
406 }
407 }
407
408
408 void QXYModelMapperPrivate::modelColumnsRemoved(QModelIndex parent, int start, int end)
409 void QXYModelMapperPrivate::modelColumnsRemoved(QModelIndex parent, int start, int end)
409 {
410 {
410 Q_UNUSED(parent);
411 Q_UNUSED(parent);
411 if (m_modelSignalsBlock)
412 if (m_modelSignalsBlock)
412 return;
413 return;
413
414
414 blockSeriesSignals();
415 blockSeriesSignals();
415 if (m_orientation == Qt::Horizontal)
416 if (m_orientation == Qt::Horizontal)
416 removeData(start, end);
417 removeData(start, end);
417 else if (start <= m_xSection || start <= m_ySection) // if the changes affect the map - reinitialize the xy
418 else if (start <= m_xSection || start <= m_ySection) // if the changes affect the map - reinitialize the xy
418 initializeXYFromModel();
419 initializeXYFromModel();
419 blockSeriesSignals(false);
420 blockSeriesSignals(false);
420 }
421 }
421
422
422 void QXYModelMapperPrivate::insertData(int start, int end)
423 void QXYModelMapperPrivate::insertData(int start, int end)
423 {
424 {
424 if (m_model == 0 || m_series == 0)
425 if (m_model == 0 || m_series == 0)
425 return;
426 return;
426
427
427 if (m_count != -1 && start >= m_first + m_count) {
428 if (m_count != -1 && start >= m_first + m_count) {
428 return;
429 return;
429 } else {
430 } else {
430 int addedCount = end - start + 1;
431 int addedCount = end - start + 1;
431 if (m_count != -1 && addedCount > m_count)
432 if (m_count != -1 && addedCount > m_count)
432 addedCount = m_count;
433 addedCount = m_count;
433 int first = qMax(start, m_first);
434 int first = qMax(start, m_first);
434 int last = qMin(first + addedCount - 1, m_orientation == Qt::Vertical ? m_model->rowCount() - 1 : m_model->columnCount() - 1);
435 int last = qMin(first + addedCount - 1, m_orientation == Qt::Vertical ? m_model->rowCount() - 1 : m_model->columnCount() - 1);
435 for (int i = first; i <= last; i++) {
436 for (int i = first; i <= last; i++) {
436 QPointF point;
437 QPointF point;
437 QModelIndex xIndex = xModelIndex(i - m_first);
438 QModelIndex xIndex = xModelIndex(i - m_first);
438 QModelIndex yIndex = yModelIndex(i - m_first);
439 QModelIndex yIndex = yModelIndex(i - m_first);
439 if (xIndex.isValid() && yIndex.isValid()) {
440 if (xIndex.isValid() && yIndex.isValid()) {
440 point.setX(m_model->data(xIndex, Qt::DisplayRole).toDouble());
441 point.setX(m_model->data(xIndex, Qt::DisplayRole).toDouble());
441 point.setY(m_model->data(yIndex, Qt::DisplayRole).toDouble());
442 point.setY(m_model->data(yIndex, Qt::DisplayRole).toDouble());
442 m_series->insert(i - m_first, point);
443 m_series->insert(i - m_first, point);
443 }
444 }
444 }
445 }
445
446
446 // remove excess of slices (abouve m_count)
447 // remove excess of slices (abouve m_count)
447 if (m_count != -1 && m_series->points().size() > m_count)
448 if (m_count != -1 && m_series->points().size() > m_count)
448 for (int i = m_series->points().size() - 1; i >= m_count; i--) {
449 for (int i = m_series->points().size() - 1; i >= m_count; i--) {
449 m_series->remove(m_series->points().at(i));
450 m_series->remove(m_series->points().at(i));
450 }
451 }
451 }
452 }
452 }
453 }
453
454
454 void QXYModelMapperPrivate::removeData(int start, int end)
455 void QXYModelMapperPrivate::removeData(int start, int end)
455 {
456 {
456 if (m_model == 0 || m_series == 0)
457 if (m_model == 0 || m_series == 0)
457 return;
458 return;
458
459
459 int removedCount = end - start + 1;
460 int removedCount = end - start + 1;
460 if (m_count != -1 && start >= m_first + m_count) {
461 if (m_count != -1 && start >= m_first + m_count) {
461 return;
462 return;
462 } else {
463 } else {
463 int toRemove = qMin(m_series->count(), removedCount); // first find how many items can actually be removed
464 int toRemove = qMin(m_series->count(), removedCount); // first find how many items can actually be removed
464 int first = qMax(start, m_first); // get the index of the first item that will be removed.
465 int first = qMax(start, m_first); // get the index of the first item that will be removed.
465 int last = qMin(first + toRemove - 1, m_series->count() + m_first - 1); // get the index of the last item that will be removed.
466 int last = qMin(first + toRemove - 1, m_series->count() + m_first - 1); // get the index of the last item that will be removed.
466 for (int i = last; i >= first; i--) {
467 for (int i = last; i >= first; i--) {
467 m_series->remove(m_series->points().at(i - m_first));
468 m_series->remove(m_series->points().at(i - m_first));
468 }
469 }
469
470
470 if (m_count != -1) {
471 if (m_count != -1) {
471 int itemsAvailable; // check how many are available to be added
472 int itemsAvailable; // check how many are available to be added
472 if (m_orientation == Qt::Vertical)
473 if (m_orientation == Qt::Vertical)
473 itemsAvailable = m_model->rowCount() - m_first - m_series->count();
474 itemsAvailable = m_model->rowCount() - m_first - m_series->count();
474 else
475 else
475 itemsAvailable = m_model->columnCount() - m_first - m_series->count();
476 itemsAvailable = m_model->columnCount() - m_first - m_series->count();
476 int toBeAdded = qMin(itemsAvailable, m_count - m_series->count()); // add not more items than there is space left to be filled.
477 int toBeAdded = qMin(itemsAvailable, m_count - m_series->count()); // add not more items than there is space left to be filled.
477 int currentSize = m_series->count();
478 int currentSize = m_series->count();
478 if (toBeAdded > 0)
479 if (toBeAdded > 0)
479 for (int i = m_series->count(); i < currentSize + toBeAdded; i++) {
480 for (int i = m_series->count(); i < currentSize + toBeAdded; i++) {
480 QPointF point;
481 QPointF point;
481 QModelIndex xIndex = xModelIndex(i);
482 QModelIndex xIndex = xModelIndex(i);
482 QModelIndex yIndex = yModelIndex(i);
483 QModelIndex yIndex = yModelIndex(i);
483 if (xIndex.isValid() && yIndex.isValid()) {
484 if (xIndex.isValid() && yIndex.isValid()) {
484 point.setX(m_model->data(xIndex, Qt::DisplayRole).toDouble());
485 point.setX(m_model->data(xIndex, Qt::DisplayRole).toDouble());
485 point.setY(m_model->data(yIndex, Qt::DisplayRole).toDouble());
486 point.setY(m_model->data(yIndex, Qt::DisplayRole).toDouble());
486 m_series->insert(i, point);
487 m_series->insert(i, point);
487 }
488 }
488 }
489 }
489 }
490 }
490 }
491 }
491 }
492 }
492
493
493 void QXYModelMapperPrivate::initializeXYFromModel()
494 void QXYModelMapperPrivate::initializeXYFromModel()
494 {
495 {
495 if (m_model == 0 || m_series == 0)
496 if (m_model == 0 || m_series == 0)
496 return;
497 return;
497
498
498 blockSeriesSignals();
499 blockSeriesSignals();
499 // clear current content
500 // clear current content
500 m_series->clear();
501 m_series->clear();
501
502
502 // create the initial slices set
503 // create the initial slices set
503 int pointPos = 0;
504 int pointPos = 0;
504 QModelIndex xIndex = xModelIndex(pointPos);
505 QModelIndex xIndex = xModelIndex(pointPos);
505 QModelIndex yIndex = yModelIndex(pointPos);
506 QModelIndex yIndex = yModelIndex(pointPos);
506 while (xIndex.isValid() && yIndex.isValid()) {
507 while (xIndex.isValid() && yIndex.isValid()) {
507 QPointF point;
508 QPointF point;
508 point.setX(m_model->data(xIndex, Qt::DisplayRole).toDouble());
509 point.setX(m_model->data(xIndex, Qt::DisplayRole).toDouble());
509 point.setY(m_model->data(yIndex, Qt::DisplayRole).toDouble());
510 point.setY(m_model->data(yIndex, Qt::DisplayRole).toDouble());
510 m_series->append(point);
511 m_series->append(point);
511 pointPos++;
512 pointPos++;
512 xIndex = xModelIndex(pointPos);
513 xIndex = xModelIndex(pointPos);
513 yIndex = yModelIndex(pointPos);
514 yIndex = yModelIndex(pointPos);
514 }
515 }
515 blockSeriesSignals(false);
516 blockSeriesSignals(false);
516 }
517 }
517
518
518 #include "moc_qxymodelmapper.cpp"
519 #include "moc_qxymodelmapper.cpp"
519 #include "moc_qxymodelmapper_p.cpp"
520 #include "moc_qxymodelmapper_p.cpp"
520
521
521 QTCOMMERCIALCHART_END_NAMESPACE
522 QTCOMMERCIALCHART_END_NAMESPACE
General Comments 0
You need to be logged in to leave comments. Login now