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