@@ -179,6 +179,21 void QBarModelMapperPrivate::blockSeriesSignals(bool block) | |||
|
179 | 179 | m_seriesSignalsBlock = block; |
|
180 | 180 | } |
|
181 | 181 | |
|
182 | QBarSet* QBarModelMapperPrivate::barSet(QModelIndex index) | |
|
183 | { | |
|
184 | if (!index.isValid()) | |
|
185 | return 0; | |
|
186 | ||
|
187 | if (m_orientation == Qt::Vertical && index.column() >= m_firstBarSection && index.column() <= m_lastBarSection) { | |
|
188 | if (index.row() >= m_first && (m_count == - 1 || index.row() < m_first + m_count)) | |
|
189 | return m_series->barSets().at(index.column() - m_firstBarSection); | |
|
190 | } else if (m_orientation == Qt::Horizontal && index.row() >= m_firstBarSection && index.row() <= m_lastBarSection) { | |
|
191 | if (index.column() >= m_first && (m_count == - 1 || index.column() < m_first + m_count)) | |
|
192 | return m_series->barSets().at(index.row() - m_firstBarSection); | |
|
193 | } | |
|
194 | return 0; // This part of model has not been mapped to any slice | |
|
195 | } | |
|
196 | ||
|
182 | 197 | QModelIndex QBarModelMapperPrivate::barModelIndex(int barSection, int posInBar) |
|
183 | 198 | { |
|
184 | 199 | if (m_count != -1 && posInBar >= m_count) |
@@ -215,43 +230,36 void QBarModelMapperPrivate::modelUpdated(QModelIndex topLeft, QModelIndex botto | |||
|
215 | 230 | if (m_modelSignalsBlock) |
|
216 | 231 | return; |
|
217 | 232 | |
|
218 |
|
|
|
219 |
|
|
|
233 | blockSeriesSignals(); | |
|
234 | QModelIndex index; | |
|
220 | 235 | // QPointF oldPoint; |
|
221 | 236 | // QPointF newPoint; |
|
222 |
|
|
|
223 |
|
|
|
224 |
|
|
|
225 | // if (m_orientation == Qt::Vertical && (index.column() == m_xSection|| index.column() == m_ySection)) { | |
|
226 | // if (index.row() >= m_first && (m_count == - 1 || index.row() < m_first + m_count)) { | |
|
227 | // oldPoint = m_series->points().at(index.row() - m_first); | |
|
228 | // newPoint.setX(m_model->data(m_model->index(index.row(), m_xSection)).toReal()); | |
|
229 | // newPoint.setY(m_model->data(m_model->index(index.row(), m_ySection)).toReal()); | |
|
230 | // } | |
|
231 | // } else if (m_orientation == Qt::Horizontal && (index.row() == m_xSection || index.row() == m_ySection)) { | |
|
232 | // if (index.column() >= m_first && (m_count == - 1 || index.column() < m_first + m_count)) { | |
|
233 | // oldPoint = m_series->points().at(index.column() - m_first); | |
|
234 | // newPoint.setX(m_model->data(m_model->index(m_xSection, index.column())).toReal()); | |
|
235 | // newPoint.setY(m_model->data(m_model->index(m_ySection, index.column())).toReal()); | |
|
236 | // } | |
|
237 | // } else { | |
|
238 | // continue; | |
|
239 | // } | |
|
240 | // m_series->replace(oldPoint, newPoint); | |
|
241 | // } | |
|
242 | // blockSeriesSignals(false); | |
|
243 | // } | |
|
237 | for (int row = topLeft.row(); row <= bottomRight.row(); row++) { | |
|
238 | for (int column = topLeft.column(); column <= bottomRight.column(); column++) { | |
|
239 | index = topLeft.sibling(row, column); | |
|
240 | QBarSet* bar = barSet(index); | |
|
241 | if (bar) { | |
|
242 | if (m_orientation == Qt::Vertical) | |
|
243 | bar->replace(row - m_first, m_model->data(index).toReal()); | |
|
244 | else | |
|
245 | bar->replace(column - m_first, m_model->data(index).toReal()); | |
|
246 | } | |
|
247 | } | |
|
248 | } | |
|
249 | blockSeriesSignals(false); | |
|
244 | 250 | } |
|
245 | 251 | |
|
246 | 252 | void QBarModelMapperPrivate::modelRowsAdded(QModelIndex parent, int start, int end) |
|
247 | 253 | { |
|
248 | 254 | Q_UNUSED(parent); |
|
255 | Q_UNUSED(end) | |
|
249 | 256 | if (m_modelSignalsBlock) |
|
250 | 257 | return; |
|
251 | 258 | |
|
252 | 259 | blockSeriesSignals(); |
|
253 | 260 | if (m_orientation == Qt::Vertical) |
|
254 | insertData(start, end); | |
|
261 | // insertData(start, end); | |
|
262 | initializeBarFromModel(); | |
|
255 | 263 | else if (start <= m_firstBarSection || start <= m_lastBarSection || start <= m_categoriesSection) // if the changes affect the map - reinitialize |
|
256 | 264 | initializeBarFromModel(); |
|
257 | 265 | blockSeriesSignals(false); |
@@ -260,12 +268,14 void QBarModelMapperPrivate::modelRowsAdded(QModelIndex parent, int start, int e | |||
|
260 | 268 | void QBarModelMapperPrivate::modelRowsRemoved(QModelIndex parent, int start, int end) |
|
261 | 269 | { |
|
262 | 270 | Q_UNUSED(parent); |
|
271 | Q_UNUSED(end) | |
|
263 | 272 | if (m_modelSignalsBlock) |
|
264 | 273 | return; |
|
265 | 274 | |
|
266 | 275 | blockSeriesSignals(); |
|
267 | 276 | if (m_orientation == Qt::Vertical) |
|
268 | removeData(start, end); | |
|
277 | // removeData(start, end); | |
|
278 | initializeBarFromModel(); | |
|
269 | 279 | else if (start <= m_firstBarSection || start <= m_lastBarSection || start <= m_categoriesSection) // if the changes affect the map - reinitialize |
|
270 | 280 | initializeBarFromModel(); |
|
271 | 281 | blockSeriesSignals(false); |
@@ -274,12 +284,14 void QBarModelMapperPrivate::modelRowsRemoved(QModelIndex parent, int start, int | |||
|
274 | 284 | void QBarModelMapperPrivate::modelColumnsAdded(QModelIndex parent, int start, int end) |
|
275 | 285 | { |
|
276 | 286 | Q_UNUSED(parent); |
|
287 | Q_UNUSED(end) | |
|
277 | 288 | if (m_modelSignalsBlock) |
|
278 | 289 | return; |
|
279 | 290 | |
|
280 | 291 | blockSeriesSignals(); |
|
281 | 292 | if (m_orientation == Qt::Horizontal) |
|
282 | insertData(start, end); | |
|
293 | // insertData(start, end); | |
|
294 | initializeBarFromModel(); | |
|
283 | 295 | else if (start <= m_firstBarSection || start <= m_lastBarSection || start <= m_categoriesSection) // if the changes affect the map - reinitialize |
|
284 | 296 | initializeBarFromModel(); |
|
285 | 297 | blockSeriesSignals(false); |
@@ -288,12 +300,14 void QBarModelMapperPrivate::modelColumnsAdded(QModelIndex parent, int start, in | |||
|
288 | 300 | void QBarModelMapperPrivate::modelColumnsRemoved(QModelIndex parent, int start, int end) |
|
289 | 301 | { |
|
290 | 302 | Q_UNUSED(parent); |
|
303 | Q_UNUSED(end) | |
|
291 | 304 | if (m_modelSignalsBlock) |
|
292 | 305 | return; |
|
293 | 306 | |
|
294 | 307 | blockSeriesSignals(); |
|
295 | 308 | if (m_orientation == Qt::Horizontal) |
|
296 | removeData(start, end); | |
|
309 | // removeData(start, end); | |
|
310 | initializeBarFromModel(); | |
|
297 | 311 | else if (start <= m_firstBarSection || start <= m_lastBarSection || start <= m_categoriesSection) // if the changes affect the map - reinitialize |
|
298 | 312 | initializeBarFromModel(); |
|
299 | 313 | blockSeriesSignals(false); |
@@ -313,11 +327,13 void QBarModelMapperPrivate::insertData(int start, int end) | |||
|
313 | 327 | addedCount = m_count; |
|
314 | 328 | int first = qMax(start, m_first); |
|
315 | 329 | int last = qMin(first + addedCount - 1, m_orientation == Qt::Vertical ? m_model->rowCount() - 1 : m_model->columnCount() - 1); |
|
316 |
for (int |
|
|
317 | QPointF point; | |
|
318 | point.setX(m_model->data(xModelIndex(i - m_first), Qt::DisplayRole).toDouble()); | |
|
319 |
point.set |
|
|
320 | m_series->insert(i - m_first, point); | |
|
330 | for (int k = 0; k < m_series->barSets().count(); k++) { | |
|
331 | for (int i = first; i <= last; i++) { | |
|
332 | QBar point; | |
|
333 | point.setX(m_model->data(xModelIndex(i - m_first), Qt::DisplayRole).toDouble()); | |
|
334 | point.setY(m_model->data(yModelIndex(i - m_first), Qt::DisplayRole).toDouble()); | |
|
335 | m_series->insert(i - m_first, point); | |
|
336 | } | |
|
321 | 337 | } |
|
322 | 338 | |
|
323 | 339 | // remove excess of slices (abouve m_count) |
@@ -371,7 +387,7 void QBarModelMapperPrivate::initializeBarFromModel() | |||
|
371 | 387 | |
|
372 | 388 | blockSeriesSignals(); |
|
373 | 389 | // clear current content |
|
374 |
|
|
|
390 | m_series->clear(); | |
|
375 | 391 | |
|
376 | 392 | // create the initial bar sets |
|
377 | 393 | for (int i = m_firstBarSection; i <= m_lastBarSection; i++) { |
@@ -9,6 +9,8 class QModelIndex; | |||
|
9 | 9 | |
|
10 | 10 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
11 | 11 | |
|
12 | class QBarSet; | |
|
13 | ||
|
12 | 14 | class QBarModelMapperPrivate : public QObject |
|
13 | 15 | { |
|
14 | 16 | Q_OBJECT |
@@ -31,6 +33,7 public Q_SLOTS: | |||
|
31 | 33 | void initializeBarFromModel(); |
|
32 | 34 | |
|
33 | 35 | private: |
|
36 | QBarSet* barSet(QModelIndex index); | |
|
34 | 37 | QModelIndex barModelIndex(int barSection, int posInBar); |
|
35 | 38 | QModelIndex categoriesModelIndex(int posInCategories); |
|
36 | 39 | void insertData(int start, int end); |
@@ -161,6 +161,13 bool QBarSeries::remove(QList<QBarSet* > sets) | |||
|
161 | 161 | return d->remove(sets); |
|
162 | 162 | } |
|
163 | 163 | |
|
164 | void QBarSeries::clear() | |
|
165 | { | |
|
166 | Q_D(QBarSeries); | |
|
167 | d->m_barSets.clear(); | |
|
168 | d->m_categories.clear(); | |
|
169 | } | |
|
170 | ||
|
164 | 171 | /*! |
|
165 | 172 | Returns number of sets in series. |
|
166 | 173 | */ |
@@ -54,6 +54,7 public: | |||
|
54 | 54 | int categoryCount() const; |
|
55 | 55 | QList<QBarSet*> barSets() const; |
|
56 | 56 | QBarCategories categories() const; |
|
57 | void clear(); | |
|
57 | 58 | |
|
58 | 59 | void setVisible(bool visible = true); |
|
59 | 60 | bool isVisible() const; |
@@ -15,7 +15,7 QXYModelMapper::~QXYModelMapper() | |||
|
15 | 15 | { |
|
16 | 16 | Q_D(QXYModelMapper); |
|
17 | 17 | disconnect(d->m_model, 0, d, 0); |
|
18 | // disconnect(d->m_series, 0, d, 0); | |
|
18 | // disconnect(d->m_series, 0, d, 0); | |
|
19 | 19 | } |
|
20 | 20 | |
|
21 | 21 | QAbstractItemModel* QXYModelMapper::model() const |
@@ -270,8 +270,8 void QXYModelMapperPrivate::modelUpdated(QModelIndex topLeft, QModelIndex bottom | |||
|
270 | 270 | } |
|
271 | 271 | m_series->replace(oldPoint, newPoint); |
|
272 | 272 | } |
|
273 | blockSeriesSignals(false); | |
|
274 | 273 | } |
|
274 | blockSeriesSignals(false); | |
|
275 | 275 | } |
|
276 | 276 | |
|
277 | 277 | void QXYModelMapperPrivate::modelRowsAdded(QModelIndex parent, int start, int end) |
@@ -476,13 +476,13 void TableWidget::updateChartType(bool toggle) | |||
|
476 | 476 | // barSeries->setModelMapping(5, 2, 4, Qt::Vertical); |
|
477 | 477 | |
|
478 | 478 | int first = 3; |
|
479 | int count = 4; | |
|
479 | // int count = 4; | |
|
480 | 480 | QVBarModelMapper *mapper = new QVBarModelMapper; |
|
481 | 481 | mapper->setCategoriesSection(5); |
|
482 | 482 | mapper->setFirstBarSection(2); |
|
483 | 483 | mapper->setLastBarSection(4); |
|
484 | 484 | mapper->setFirst(first); |
|
485 | mapper->setCount(count); | |
|
485 | // mapper->setCount(count); | |
|
486 | 486 | mapper->setSeries(barSeries); |
|
487 | 487 | mapper->setModel(m_model); |
|
488 | 488 | // barSeries->setModelMapper(mapper); |
@@ -490,7 +490,7 void TableWidget::updateChartType(bool toggle) | |||
|
490 | 490 | QList<QBarSet*> barsets = barSeries->barSets(); |
|
491 | 491 | for (int i = 0; i < barsets.count(); i++) { |
|
492 | 492 | seriesColorHex = "#" + QString::number(barsets.at(i)->brush().color().rgb(), 16).right(6).toUpper(); |
|
493 | m_model->addMapping(seriesColorHex, QRect(2 + i, first, 1, count)); | |
|
493 | m_model->addMapping(seriesColorHex, QRect(2 + i, first, 1, barsets.at(i)->count())); | |
|
494 | 494 | } |
|
495 | 495 | } |
|
496 | 496 |
General Comments 0
You need to be logged in to leave comments.
Login now