@@ -65,18 +65,18 void DeclarativeBarSeries::componentComplete() | |||
|
65 | 65 | } |
|
66 | 66 | } |
|
67 | 67 | |
|
68 | void DeclarativeBarSeries::setBarCategories(QStringList categories) | |
|
68 | void DeclarativeBarSeries::setBarCategories(QStringList /*categories*/) | |
|
69 | 69 | { |
|
70 | m_categories = categories; | |
|
71 | if (m_series) { | |
|
72 | // Replace categories of the QBarSeries with the new categories | |
|
73 | for (int i(0); i < m_categories.count(); i++) { | |
|
74 | if (m_series->categories().at(i) != m_categories.at(i)) | |
|
75 | m_series->insertCategory(m_series->categoryCount(), m_categories.at(i)); | |
|
76 | } | |
|
77 | while (m_series->categoryCount() > m_categories.count()) | |
|
78 | m_series->removeCategory(m_series->categoryCount() - 1); | |
|
79 | } | |
|
70 | // m_categories = categories; | |
|
71 | // if (m_series) { | |
|
72 | // // Replace categories of the QBarSeries with the new categories | |
|
73 | // for (int i(0); i < m_categories.count(); i++) { | |
|
74 | // if (m_series->categories().at(i) != m_categories.at(i)) | |
|
75 | // m_series->insertCategory(m_series->categoryCount(), m_categories.at(i)); | |
|
76 | // } | |
|
77 | // while (m_series->categoryCount() > m_categories.count()) | |
|
78 | // m_series->removeCategory(m_series->categoryCount() - 1); | |
|
79 | // } | |
|
80 | 80 | } |
|
81 | 81 | |
|
82 | 82 | QStringList DeclarativeBarSeries::barCategories() |
@@ -170,27 +170,6 void QBarSeries::insertBarSet(int i, QBarSet *set) | |||
|
170 | 170 | } |
|
171 | 171 | |
|
172 | 172 | /*! |
|
173 | Inserts new \a category on the \a i position. | |
|
174 | The category that is currently at this postion is moved to postion i + 1 | |
|
175 | \sa removeCategory() | |
|
176 | */ | |
|
177 | void QBarSeries::insertCategory(int i, QString category) | |
|
178 | { | |
|
179 | Q_D(QBarSeries); | |
|
180 | d->m_internalModel->insertCategory(i, category); | |
|
181 | } | |
|
182 | ||
|
183 | /*! | |
|
184 | Removes the category specified by \a i | |
|
185 | \sa insertCategory() | |
|
186 | */ | |
|
187 | void QBarSeries::removeCategory(int i) | |
|
188 | { | |
|
189 | Q_D(QBarSeries); | |
|
190 | d->m_internalModel->removeCategory(i); | |
|
191 | } | |
|
192 | ||
|
193 | /*! | |
|
194 | 173 | Returns number of sets in series. |
|
195 | 174 | */ |
|
196 | 175 | int QBarSeries::barsetCount() const |
@@ -251,7 +230,7 QBarCategories QBarSeries::categories() const | |||
|
251 | 230 | QBarCategories categories; |
|
252 | 231 | int count = d->m_internalModel->categoryCount(); |
|
253 | 232 | for (int i=1; i <= count; i++) { |
|
254 |
|
|
|
233 | categories.insert(i, d->m_internalModel->categoryName(i - 1)); | |
|
255 | 234 | } |
|
256 | 235 | return categories; |
|
257 | 236 | |
@@ -276,8 +255,6 QBarSeriesPrivate::QBarSeriesPrivate(QBarCategories categories, QBarSeries *q) : | |||
|
276 | 255 | m_mapCategories(-1), |
|
277 | 256 | m_mapBarBottom(-1), |
|
278 | 257 | m_mapBarTop(-1), |
|
279 | m_mapFirst(0), | |
|
280 | m_mapCount(0), | |
|
281 | 258 | m_mapOrientation(Qt::Vertical) |
|
282 | 259 | { |
|
283 | 260 | } |
@@ -341,8 +318,6 bool QBarSeriesPrivate::setModel(QAbstractItemModel *model) | |||
|
341 | 318 | m_mapCategories = -1; |
|
342 | 319 | m_mapBarBottom = -1; |
|
343 | 320 | m_mapBarTop = -1; |
|
344 | m_mapFirst = 0; | |
|
345 | m_mapCount = 0; | |
|
346 | 321 | m_mapOrientation = Qt::Vertical; |
|
347 | 322 | } |
|
348 | 323 | |
@@ -369,51 +344,35 void QBarSeriesPrivate::setModelMapping(int categories, int bottomBoundry, int t | |||
|
369 | 344 | m_mapCategories = categories; |
|
370 | 345 | m_mapBarBottom = bottomBoundry; |
|
371 | 346 | m_mapBarTop = topBoundry; |
|
372 | // m_mapFirst = 1; | |
|
373 | 347 | m_mapOrientation = orientation; |
|
374 | 348 | |
|
375 | 349 | // connect the signals |
|
376 | if (m_mapOrientation == Qt::Vertical) { | |
|
377 | m_mapCount = m_model->rowCount() - m_mapFirst; | |
|
378 | connect(m_model,SIGNAL(dataChanged(QModelIndex,QModelIndex)), | |
|
379 | this, SLOT(modelUpdated(QModelIndex,QModelIndex))); | |
|
380 | connect(m_model,SIGNAL(rowsInserted(QModelIndex,int,int)), | |
|
381 | this, SLOT(modelDataAdded(QModelIndex,int,int))); | |
|
382 | connect(m_model, SIGNAL(rowsRemoved(QModelIndex,int,int)), | |
|
383 | this, SLOT(modelDataRemoved(QModelIndex,int,int))); | |
|
384 | } else { | |
|
385 | m_mapCount = m_model->columnCount() - m_mapFirst; | |
|
386 | connect(m_model,SIGNAL(dataChanged(QModelIndex,QModelIndex)), | |
|
387 | this, SLOT(modelUpdated(QModelIndex,QModelIndex))); | |
|
388 | connect(m_model,SIGNAL(columnsInserted(QModelIndex,int,int)), | |
|
389 | this, SLOT(modelDataAdded(QModelIndex,int,int))); | |
|
390 | connect(m_model, SIGNAL(columnsRemoved(QModelIndex,int,int)), | |
|
391 | this, SLOT(modelDataRemoved(QModelIndex,int,int))); | |
|
392 | } | |
|
350 | connect(m_model,SIGNAL(dataChanged(QModelIndex,QModelIndex)), | |
|
351 | this, SLOT(modelUpdated(QModelIndex,QModelIndex))); | |
|
393 | 352 | |
|
394 | 353 | // create the initial bars |
|
395 | 354 | delete m_internalModel; |
|
396 | 355 | if (m_mapOrientation == Qt::Vertical) { |
|
397 | 356 | QStringList categories; |
|
398 |
for (int k = |
|
|
357 | for (int k = 0; k < m_model->rowCount(); k++) | |
|
399 | 358 | categories << m_model->data(m_model->index(k, m_mapCategories), Qt::DisplayRole).toString(); |
|
400 | 359 | m_internalModel = new BarChartModel(categories, this); |
|
401 | 360 | |
|
402 | 361 | for (int i = m_mapBarBottom; i <= m_mapBarTop; i++) { |
|
403 | 362 | QBarSet* barSet = new QBarSet(QString("Column: %1").arg(i + 1)); |
|
404 |
for(int m = |
|
|
363 | for(int m = 0; m < m_model->rowCount(); m++) | |
|
405 | 364 | *barSet << m_model->data(m_model->index(m, i), Qt::DisplayRole).toDouble(); |
|
406 | 365 | q->appendBarSet(barSet); |
|
407 | 366 | } |
|
408 | 367 | } else { |
|
409 | 368 | QStringList categories; |
|
410 |
for (int k = |
|
|
369 | for (int k = 0; k < m_model->columnCount(); k++) | |
|
411 | 370 | categories << m_model->data(m_model->index(m_mapCategories, k), Qt::DisplayRole).toString(); |
|
412 | 371 | m_internalModel = new BarChartModel(categories, this); |
|
413 | 372 | |
|
414 | 373 | for (int i = m_mapBarBottom; i <= m_mapBarTop; i++) { |
|
415 | 374 | QBarSet* barSet = new QBarSet(QString("Row: %1").arg(i + 1)); |
|
416 |
for(int m = |
|
|
375 | for(int m = 0; m < m_model->columnCount(); m++) | |
|
417 | 376 | *barSet << m_model->data(m_model->index(i, m), Qt::DisplayRole).toDouble(); |
|
418 | 377 | q->appendBarSet(barSet); |
|
419 | 378 | } |
@@ -427,47 +386,15 void QBarSeriesPrivate::modelUpdated(QModelIndex topLeft, QModelIndex bottomRigh | |||
|
427 | 386 | if (m_mapOrientation == Qt::Vertical) |
|
428 | 387 | { |
|
429 | 388 | // model update is relevant to BarSeries if the change was made to the part of the model that was mapped to BarSeries |
|
430 |
if (topLeft.column() >= m_mapBarBottom && topLeft.column() <= m_mapBarTop |
|
|
431 |
barsetAt(topLeft.column() - m_mapBarBottom)->setValue(topLeft.row() |
|
|
389 | if (topLeft.column() >= m_mapBarBottom && topLeft.column() <= m_mapBarTop) | |
|
390 | barsetAt(topLeft.column() - m_mapBarBottom)->setValue(topLeft.row(), m_model->data(topLeft, Qt::DisplayRole).toDouble()); | |
|
432 | 391 | } |
|
433 | 392 | else |
|
434 | 393 | { |
|
435 | 394 | // model update is relevant to BarSeries if the change was made to the part of the model that was mapped to BarSeries |
|
436 |
if (topLeft.row() >= m_mapBarBottom && topLeft.row() <= m_mapBarTop |
|
|
437 |
barsetAt(topLeft.row() - m_mapBarBottom)->setValue(topLeft.column() |
|
|
438 | } | |
|
439 | } | |
|
440 | ||
|
441 | void QBarSeriesPrivate::modelDataAdded(QModelIndex /*parent*/, int start, int /*end*/) | |
|
442 | { | |
|
443 | Q_Q(QBarSeries); | |
|
444 | ||
|
445 | if (m_mapOrientation == Qt::Vertical) { | |
|
446 | q->insertCategory(start - m_mapFirst, QString("Row: %1").arg(start + 1)); | |
|
447 | for (int i = 0; i <= m_mapBarTop - m_mapBarBottom; i++) { | |
|
448 | barsetAt(i)->insertValue(start - m_mapFirst, m_model->data(m_model->index(start, i), Qt::DisplayRole).toDouble()); | |
|
449 | } | |
|
450 | } else { | |
|
451 | q->insertCategory(start - m_mapFirst, QString("Column: %1").arg(start + 1)); | |
|
452 | for (int i = 0; i <= m_mapBarTop - m_mapBarBottom; i++) { | |
|
453 | barsetAt(i)->insertValue(start - m_mapFirst, m_model->data(m_model->index(i, start), Qt::DisplayRole).toDouble()); | |
|
454 | } | |
|
455 | } | |
|
456 | emit restructuredBars(); | |
|
457 | } | |
|
458 | ||
|
459 | void QBarSeriesPrivate::modelDataRemoved(QModelIndex parent, int start, int end) | |
|
460 | { | |
|
461 | Q_Q(QBarSeries); | |
|
462 | Q_UNUSED(parent) | |
|
463 | Q_UNUSED(end) | |
|
464 | ||
|
465 | q->removeCategory(start - m_mapFirst); | |
|
466 | for (int i = 0; i <= m_mapBarTop - m_mapBarBottom; i++) | |
|
467 | { | |
|
468 | barsetAt(i)->removeValue(start - m_mapFirst); | |
|
395 | if (topLeft.row() >= m_mapBarBottom && topLeft.row() <= m_mapBarTop) | |
|
396 | barsetAt(topLeft.row() - m_mapBarBottom)->setValue(topLeft.column(), m_model->data(topLeft, Qt::DisplayRole).toDouble()); | |
|
469 | 397 | } |
|
470 | emit restructuredBars(); | |
|
471 | 398 | } |
|
472 | 399 | |
|
473 | 400 | void QBarSeriesPrivate::barsetChanged() |
@@ -50,8 +50,6 public: | |||
|
50 | 50 | void appendBarSets(QList<QBarSet* > sets); |
|
51 | 51 | void removeBarSets(QList<QBarSet* > sets); |
|
52 | 52 | void insertBarSet(int i, QBarSet *set); |
|
53 | void insertCategory(int i, QString category); | |
|
54 | void removeCategory(int i); | |
|
55 | 53 | int barsetCount() const; |
|
56 | 54 | int categoryCount() const; |
|
57 | 55 | QList<QBarSet*> barSets() const; |
@@ -44,8 +44,6 Q_SIGNALS: | |||
|
44 | 44 | private Q_SLOTS: |
|
45 | 45 | // slots for updating bars when data in model changes |
|
46 | 46 | void modelUpdated(QModelIndex topLeft, QModelIndex bottomRight); |
|
47 | void modelDataAdded(QModelIndex parent, int start, int end); | |
|
48 | void modelDataRemoved(QModelIndex parent, int start, int end); | |
|
49 | 47 | void barsetChanged(); |
|
50 | 48 | |
|
51 | 49 | protected: |
@@ -54,8 +52,6 protected: | |||
|
54 | 52 | int m_mapCategories; |
|
55 | 53 | int m_mapBarBottom; |
|
56 | 54 | int m_mapBarTop; |
|
57 | int m_mapFirst; | |
|
58 | int m_mapCount; | |
|
59 | 55 | Qt::Orientation m_mapOrientation; |
|
60 | 56 | private: |
|
61 | 57 | Q_DECLARE_PUBLIC(QBarSeries) |
@@ -66,13 +66,6 QPointF QSplineSeries::controlPoint(int index) const | |||
|
66 | 66 | return d->m_controlPoints[index]; |
|
67 | 67 | } |
|
68 | 68 | |
|
69 | void QSplineSeries::setModelMappingRange(int first, int count) | |
|
70 | { | |
|
71 | Q_D(QSplineSeries); | |
|
72 | QLineSeries::setModelMappingRange(first, count); | |
|
73 | d->calculateControlPoints(); | |
|
74 | } | |
|
75 | ||
|
76 | 69 | //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
77 | 70 | |
|
78 | 71 | QSplineSeriesPrivate::QSplineSeriesPrivate(QSplineSeries* q):QLineSeriesPrivate(q) |
@@ -186,30 +179,6 void QSplineSeriesPrivate::updateControlPoints() | |||
|
186 | 179 | } |
|
187 | 180 | } |
|
188 | 181 | |
|
189 | /*//! | |
|
190 | \fn bool QSplineSeries::setModel(QAbstractItemModel *model) | |
|
191 | Sets the \a model to be used as a data source | |
|
192 | \sa setModelMapping(), setModelMappingRange() | |
|
193 | */ | |
|
194 | //bool QSplineSeries::setModel(QAbstractItemModel* model) | |
|
195 | //{ | |
|
196 | // QXYSeries::setModel(model); | |
|
197 | //// calculateControlPoints(); | |
|
198 | // return true; | |
|
199 | //} | |
|
200 | ||
|
201 | /*//! | |
|
202 | \fn bool QSplineSeries::setModelMapping(int modelX, int modelY, Qt::Orientation orientation) | |
|
203 | Sets the \a modelX to be used as a data source for x coordinate and \a modelY to be used | |
|
204 | as a data source for y coordinate. The \a orientation parameter specifies whether the data | |
|
205 | is in columns or in rows. | |
|
206 | */ | |
|
207 | //void QSplineSeries::setModelMapping(int modelX, int modelY, Qt::Orientation orientation) | |
|
208 | //{ | |
|
209 | // QLineSeries::setModelMapping(modelX, modelY, orientation); | |
|
210 | //// calculateControlPoints(); | |
|
211 | //} | |
|
212 | ||
|
213 | 182 | /*! |
|
214 | 183 | \fn bool QSplineSeries::setModelMappingRange(int first, int count) |
|
215 | 184 | Allows limiting the model mapping. |
@@ -40,7 +40,6 public: | |||
|
40 | 40 | QAbstractSeries::QSeriesType type() const; |
|
41 | 41 | |
|
42 | 42 | QPointF controlPoint(int index) const; |
|
43 | void setModelMappingRange(int first, int count); | |
|
44 | 43 | |
|
45 | 44 | private: |
|
46 | 45 | Q_DECLARE_PRIVATE(QSplineSeries); |
@@ -76,19 +76,6 QTCOMMERCIALCHART_BEGIN_NAMESPACE | |||
|
76 | 76 | */ |
|
77 | 77 | |
|
78 | 78 | /*! |
|
79 | \fn int QXYSeries::mapFirst() const | |
|
80 | Returns the index of the model's item that is used as a first one for the series. | |
|
81 | \sa mapCount() | |
|
82 | */ | |
|
83 | ||
|
84 | /*! | |
|
85 | \fn int QXYSeries::mapCount() const | |
|
86 | Returns the number of the items that are taken from the model. | |
|
87 | If -1 it means all the items of the model following the first one are used. | |
|
88 | \sa mapFirst() | |
|
89 | */ | |
|
90 | ||
|
91 | /*! | |
|
92 | 79 | \internal |
|
93 | 80 | |
|
94 | 81 | Constructs empty series object which is a child of \a parent. |
@@ -220,10 +207,10 qreal QXYSeries::x(int pos) const | |||
|
220 | 207 | if (d->m_model) { |
|
221 | 208 | if (d->m_mapOrientation == Qt::Vertical) |
|
222 | 209 | // consecutive data is read from model's column |
|
223 |
return d->m_model->data(d->m_model->index(pos |
|
|
210 | return d->m_model->data(d->m_model->index(pos, d->m_mapX), Qt::DisplayRole).toDouble(); | |
|
224 | 211 | else |
|
225 | 212 | // consecutive data is read from model's row |
|
226 |
return d->m_model->data(d->m_model->index(d->m_mapX, pos |
|
|
213 | return d->m_model->data(d->m_model->index(d->m_mapX, pos), Qt::DisplayRole).toDouble(); | |
|
227 | 214 | } else { |
|
228 | 215 | // model is not specified, return the data from series' internal data store |
|
229 | 216 | return d->m_x.at(pos); |
@@ -239,10 +226,10 qreal QXYSeries::y(int pos) const | |||
|
239 | 226 | if (d->m_model) { |
|
240 | 227 | if (d->m_mapOrientation == Qt::Vertical) |
|
241 | 228 | // consecutive data is read from model's column |
|
242 |
return d->m_model->data(d->m_model->index(pos |
|
|
229 | return d->m_model->data(d->m_model->index(pos, d->m_mapY), Qt::DisplayRole).toDouble(); | |
|
243 | 230 | else |
|
244 | 231 | // consecutive data is read from model's row |
|
245 |
return d->m_model->data(d->m_model->index(d->m_mapY, pos |
|
|
232 | return d->m_model->data(d->m_model->index(d->m_mapY, pos), Qt::DisplayRole).toDouble(); | |
|
246 | 233 | } else { |
|
247 | 234 | // model is not specified, return the data from series' internal data store |
|
248 | 235 | return d->m_y.at(pos); |
@@ -260,19 +247,11 int QXYSeries::count() const | |||
|
260 | 247 | |
|
261 | 248 | if (d->m_model) { |
|
262 | 249 | if (d->m_mapOrientation == Qt::Vertical) { |
|
263 |
// data is in a column. Return the number of mapped items |
|
|
264 | // or the number of items that can be mapped | |
|
265 | if (d->m_mapLimited) | |
|
266 | return qMin(d->m_mapCount, qMax(d->m_model->rowCount() - d->m_mapFirst, 0)); | |
|
267 | else | |
|
268 | return qMax(d->m_model->rowCount() - d->m_mapFirst, 0); | |
|
250 | // data is in a column. Return the number of mapped items | |
|
251 | return d->m_model->rowCount(); | |
|
269 | 252 | } else { |
|
270 |
// data is in a row. Return the number of mapped items |
|
|
271 | // or the number of items that can be mapped | |
|
272 | if (d->m_mapLimited) | |
|
273 | return qMin(d->m_mapCount, qMax(d->m_model->columnCount() - d->m_mapFirst, 0)); | |
|
274 | else | |
|
275 | return qMax(d->m_model->columnCount() - d->m_mapFirst, 0); | |
|
253 | // data is in a row. Return the number of mapped items | |
|
254 | return d->m_model->columnCount(); | |
|
276 | 255 | } |
|
277 | 256 | } |
|
278 | 257 | |
@@ -386,145 +365,11 void QXYSeries::modelUpdated(QModelIndex topLeft, QModelIndex bottomRight) | |||
|
386 | 365 | Q_UNUSED(bottomRight) |
|
387 | 366 | Q_D(QXYSeries); |
|
388 | 367 | if (d->m_mapOrientation == Qt::Vertical) { |
|
389 |
if (topLeft. |
|
|
390 |
emit d->pointReplaced(topLeft.row() |
|
|
391 | } else { | |
|
392 | if (topLeft.column() >= d->m_mapFirst && (!d->m_mapLimited || topLeft.column() < d->m_mapFirst + d->m_mapCount)) | |
|
393 | emit d->pointReplaced(topLeft.column() - d->m_mapFirst); | |
|
394 | } | |
|
395 | } | |
|
396 | ||
|
397 | /*! | |
|
398 | \internal | |
|
399 | */ | |
|
400 | void QXYSeries::modelDataAboutToBeAdded(QModelIndex parent, int start, int end) | |
|
401 | { | |
|
402 | Q_UNUSED(parent) | |
|
403 | // Q_UNUSED(end) | |
|
404 | Q_D(QXYSeries); | |
|
405 | if (d->m_mapLimited) { | |
|
406 | if (start >= d->m_mapFirst + d->m_mapCount) { | |
|
407 | // the added data is below mapped area | |
|
408 | // therefore it has no relevance | |
|
409 | return; | |
|
410 | } else { | |
|
411 | // the added data is in the mapped area or before it and update is needed | |
|
412 | ||
|
413 | // check how many mapped items there is currently (before new items are added) | |
|
414 | // if the number of items currently is equal the m_mapCount then some needs to be removed from xychartitem | |
|
415 | // internal storage before new ones can be added | |
|
416 | ||
|
417 | int itemsToRemove = qMin(count() - qMax(start - d->m_mapFirst, 0), end - start + 1); | |
|
418 | if (d->m_mapCount == count()) { | |
|
419 | for (int i = 0; i < itemsToRemove; i++) | |
|
420 | emit d->pointRemoved(qMin(end, count()) - i); | |
|
421 | } | |
|
422 | } | |
|
423 | } else { | |
|
424 | // map is not limited (it includes all the items starting from m_mapFirst till the end of model) | |
|
425 | // nothing to do | |
|
426 | // emit pointAdded(qMax(start - m_mapFirst, 0)); | |
|
427 | } | |
|
428 | } | |
|
429 | ||
|
430 | /*! | |
|
431 | \internal | |
|
432 | */ | |
|
433 | void QXYSeries::modelDataAdded(QModelIndex parent, int start, int end) | |
|
434 | { | |
|
435 | Q_UNUSED(parent) | |
|
436 | // Q_UNUSED(end) | |
|
437 | Q_D(QXYSeries); | |
|
438 | if (d->m_mapLimited) { | |
|
439 | if (start >= d->m_mapFirst + d->m_mapCount) { | |
|
440 | // the added data is below mapped area | |
|
441 | // therefore it has no relevance | |
|
442 | return; | |
|
443 | } else { | |
|
444 | // the added data is in the mapped area or before it | |
|
445 | // update needed | |
|
446 | if (count() > 0) { | |
|
447 | int toBeAdded = qMin(d->m_mapCount - (start - d->m_mapFirst), end - start + 1); | |
|
448 | for (int i = 0; i < toBeAdded; i++) | |
|
449 | if (start + i >= d->m_mapFirst) | |
|
450 | emit d->pointAdded(start + i); | |
|
451 | } | |
|
452 | } | |
|
453 | } else { | |
|
454 | // map is not limited (it included all the items starting from m_mapFirst till the end of model) | |
|
455 | for (int i = 0; i < end - start + 1; i++) | |
|
456 | emit d->pointAdded(start + i); | |
|
457 | } | |
|
458 | } | |
|
459 | ||
|
460 | /*! | |
|
461 | \internal | |
|
462 | */ | |
|
463 | void QXYSeries::modelDataAboutToBeRemoved(QModelIndex parent, int start, int end) | |
|
464 | { | |
|
465 | Q_UNUSED(parent) | |
|
466 | // Q_UNUSED(end) | |
|
467 | Q_D(QXYSeries); | |
|
468 | if (d->m_mapLimited) { | |
|
469 | if (start >= d->m_mapFirst + d->m_mapCount) { | |
|
470 | // the removed data is below mapped area | |
|
471 | // therefore it has no relevance | |
|
472 | return; | |
|
473 | } else { | |
|
474 | // the removed data is in the mapped area or before it | |
|
475 | // update needed | |
|
476 | ||
|
477 | // check how many items need to be removed from the xychartitem storage | |
|
478 | // the number equals the number of items that are removed and that lay before | |
|
479 | // or in the mapped area. Items that lay beyond the map do not count | |
|
480 | // the max is the current number of items in storage (count()) | |
|
481 | int itemsToRemove = qMin(count(), qMin(end, d->m_mapFirst + d->m_mapCount - 1) - start + 1); | |
|
482 | for (int i = 0; i < itemsToRemove; i++) | |
|
483 | emit d->pointRemoved(start); | |
|
484 | } | |
|
485 | } else { | |
|
486 | // map is not limited (it included all the items starting from m_mapFirst till the end of model) | |
|
487 | for (int i = 0; i < end - start + 1; i++) | |
|
488 | emit d->pointRemoved(start); | |
|
489 | } | |
|
490 | } | |
|
491 | ||
|
492 | /*! | |
|
493 | \internal | |
|
494 | */ | |
|
495 | void QXYSeries::modelDataRemoved(QModelIndex parent, int start, int end) | |
|
496 | { | |
|
497 | ||
|
498 | Q_UNUSED(parent) | |
|
499 | Q_UNUSED(end) | |
|
500 | Q_D(QXYSeries); | |
|
501 | // how many items there were before data was removed | |
|
502 | // int oldCount = count() - 1; | |
|
503 | ||
|
504 | if (d->m_mapLimited) { | |
|
505 | if (start >= d->m_mapFirst + d->m_mapCount) { | |
|
506 | // the removed data is below mapped area | |
|
507 | // therefore it has no relevance | |
|
508 | return; | |
|
509 | } else { | |
|
510 | // if the current items count in the whole model is bigger than the index of the last item | |
|
511 | // that was removed than it means there are some extra items available | |
|
512 | ||
|
513 | int removedItemsCount = qMin(count(), qMin(end, d->m_mapFirst + d->m_mapCount - 1) - start + 1); | |
|
514 | int extraItemsAvailable = 0; | |
|
515 | if (d->m_mapOrientation == Qt::Vertical) { | |
|
516 | extraItemsAvailable = qMax(d->m_model->rowCount() + (end - start + 1) - qMax(end + 1, d->m_mapFirst + d->m_mapCount), 0); | |
|
517 | } else { | |
|
518 | extraItemsAvailable = qMax(d->m_model->columnCount() + (end - start + 1) - qMax(end + 1, d->m_mapFirst + d->m_mapCount), 0); | |
|
519 | } | |
|
520 | ||
|
521 | // if there are excess items available (below the mapped area) use them to repopulate mapped area | |
|
522 | int toBeAdded = qMin(extraItemsAvailable, removedItemsCount); | |
|
523 | for (int k = 0; k < toBeAdded; k++) | |
|
524 | emit d->pointAdded(d->m_mapFirst + d->m_mapCount - removedItemsCount + k); | |
|
525 | } | |
|
368 | if (topLeft.column() == d->m_mapX || topLeft.column() == d->m_mapY) | |
|
369 | emit d->pointReplaced(topLeft.row()); | |
|
526 | 370 | } else { |
|
527 | // data was removed from XYSeries interal storage. Nothing more to do | |
|
371 | if (topLeft.row() == d->m_mapX || topLeft.row() == d->m_mapY) | |
|
372 | emit d->pointReplaced(topLeft.column()); | |
|
528 | 373 | } |
|
529 | 374 | } |
|
530 | 375 | |
@@ -541,9 +386,6 bool QXYSeries::setModel(QAbstractItemModel *model) | |||
|
541 | 386 | QObject::disconnect(d->m_model, 0, this, 0); |
|
542 | 387 | d->m_mapX = -1; |
|
543 | 388 | d->m_mapY = -1; |
|
544 | d->m_mapFirst = 0; | |
|
545 | d->m_mapCount = 0; | |
|
546 | d->m_mapLimited = false; | |
|
547 | 389 | d->m_mapOrientation = Qt::Vertical; |
|
548 | 390 | } |
|
549 | 391 | |
@@ -571,63 +413,16 void QXYSeries::setModelMapping(int modelX, int modelY, Qt::Orientation orientat | |||
|
571 | 413 | return; |
|
572 | 414 | d->m_mapX = modelX; |
|
573 | 415 | d->m_mapY = modelY; |
|
574 | d->m_mapFirst = 0; | |
|
575 | 416 | d->m_mapOrientation = orientation; |
|
576 | if (d->m_mapOrientation == Qt::Vertical) { | |
|
577 | connect(d->m_model,SIGNAL(dataChanged(QModelIndex,QModelIndex)), this, SLOT(modelUpdated(QModelIndex,QModelIndex))); | |
|
578 | connect(d->m_model,SIGNAL(rowsAboutToBeInserted(QModelIndex,int,int)), this, SLOT(modelDataAboutToBeAdded(QModelIndex,int,int))); | |
|
579 | connect(d->m_model,SIGNAL(rowsInserted(QModelIndex,int,int)), this, SLOT(modelDataAdded(QModelIndex,int,int))); | |
|
580 | connect(d->m_model, SIGNAL(rowsAboutToBeRemoved(QModelIndex,int,int)), this, SLOT(modelDataAboutToBeRemoved(QModelIndex,int,int))); | |
|
581 | connect(d->m_model, SIGNAL(rowsRemoved(QModelIndex,int,int)), this, SLOT(modelDataRemoved(QModelIndex,int,int))); | |
|
582 | } else { | |
|
583 | connect(d->m_model,SIGNAL(dataChanged(QModelIndex,QModelIndex)), this, SLOT(modelUpdated(QModelIndex,QModelIndex))); | |
|
584 | connect(d->m_model,SIGNAL(columnsAboutToBeInserted(QModelIndex,int,int)), this, SLOT(modelDataAboutToBeAdded(QModelIndex,int,int))); | |
|
585 | connect(d->m_model,SIGNAL(columnsInserted(QModelIndex,int,int)), this, SLOT(modelDataAdded(QModelIndex,int,int))); | |
|
586 | connect(d->m_model, SIGNAL(columnsAboutToBeRemoved(QModelIndex,int,int)), this, SLOT(modelDataAboutToBeRemoved(QModelIndex,int,int))); | |
|
587 | connect(d->m_model, SIGNAL(columnsRemoved(QModelIndex,int,int)), this, SLOT(modelDataRemoved(QModelIndex,int,int))); | |
|
588 | } | |
|
589 | } | |
|
590 | ||
|
591 | /*! | |
|
592 | \fn bool QXYSeries::setModelMappingRange(int first, int count) | |
|
593 | Allows limiting the model mapping. | |
|
594 | Parameter \a first specifies which element of the model should be used as a first one of the series. | |
|
595 | Parameter \a count specifies how many elements should be mapped. If count is not specified (defaults to -1) | |
|
596 | then all the items following \a first item in a model are used. | |
|
597 | \sa setModel(), setModelMapping() | |
|
598 | */ | |
|
599 | void QXYSeries::setModelMappingRange(int first, int count) | |
|
600 | { | |
|
601 | Q_D(QXYSeries); | |
|
602 | d->m_mapFirst = first; | |
|
603 | if (count == 0) { | |
|
604 | d->m_mapLimited = false; | |
|
605 | } else { | |
|
606 | d->m_mapCount = count; | |
|
607 | d->m_mapLimited = true; | |
|
608 | } | |
|
609 | } | |
|
610 | ||
|
611 | int QXYSeries::mapFirst() const | |
|
612 | { | |
|
613 | Q_D(const QXYSeries); | |
|
614 | return d->m_mapFirst; | |
|
615 | } | |
|
616 | ||
|
617 | int QXYSeries::mapCount() const | |
|
618 | { | |
|
619 | Q_D(const QXYSeries); | |
|
620 | return d->m_mapCount; | |
|
417 | connect(d->m_model,SIGNAL(dataChanged(QModelIndex,QModelIndex)), this, SLOT(modelUpdated(QModelIndex,QModelIndex))); | |
|
621 | 418 | } |
|
622 | 419 | |
|
623 | 420 | ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
624 | 421 | |
|
422 | ||
|
625 | 423 | QXYSeriesPrivate::QXYSeriesPrivate(QXYSeries *q) : QAbstractSeriesPrivate(q), |
|
626 | 424 | m_mapX(-1), |
|
627 | 425 | m_mapY(-1), |
|
628 | m_mapFirst(0), | |
|
629 | m_mapCount(0), | |
|
630 | m_mapLimited(false), | |
|
631 | 426 | m_mapOrientation( Qt::Vertical), |
|
632 | 427 | m_pointsVisible(false) |
|
633 | 428 | { |
@@ -68,18 +68,10 public: | |||
|
68 | 68 | bool pointsVisible() const; |
|
69 | 69 | |
|
70 | 70 | bool setModel(QAbstractItemModel *model); |
|
71 | ||
|
72 | 71 | virtual void setModelMapping(int modelX, int modelY, Qt::Orientation orientation = Qt::Vertical); |
|
73 | virtual void setModelMappingRange(int first, int count = 0); | |
|
74 | int mapFirst() const; | |
|
75 | int mapCount() const; | |
|
76 | 72 | |
|
77 | 73 | private Q_SLOTS: |
|
78 | 74 | void modelUpdated(QModelIndex topLeft, QModelIndex bottomRight); |
|
79 | void modelDataAboutToBeAdded(QModelIndex parent, int start, int end); | |
|
80 | void modelDataAdded(QModelIndex parent, int start, int end); | |
|
81 | void modelDataAboutToBeRemoved(QModelIndex parent, int start, int end); | |
|
82 | void modelDataRemoved(QModelIndex parent, int start, int end); | |
|
83 | 75 | |
|
84 | 76 | Q_SIGNALS: |
|
85 | 77 | void clicked(const QPointF &point); |
@@ -61,11 +61,7 protected: | |||
|
61 | 61 | |
|
62 | 62 | int m_mapX; |
|
63 | 63 | int m_mapY; |
|
64 | int m_mapFirst; | |
|
65 | int m_mapCount; | |
|
66 | bool m_mapLimited; | |
|
67 | 64 | Qt::Orientation m_mapOrientation; |
|
68 | int tempItemsRemoved; | |
|
69 | 65 | bool m_pointsVisible; |
|
70 | 66 | |
|
71 | 67 | private: |
@@ -108,44 +108,20 void XYChartItem::handlePointAdded(int index) | |||
|
108 | 108 | { |
|
109 | 109 | QVector<QPointF> points = m_points; |
|
110 | 110 | QPointF point; |
|
111 | if (m_series->model()) { | |
|
112 | point = calculateGeometryPoint(index - m_series->mapFirst()); | |
|
113 | if (index < m_series->mapFirst()) { | |
|
114 |
|
|
|
115 |
|
|
|
116 | } | |
|
117 | else { | |
|
118 | points.insert(index - m_series->mapFirst(), point); | |
|
119 | updateLayout(m_points, points, index - m_series->mapFirst()); | |
|
120 | } | |
|
121 | } | |
|
122 | else { | |
|
123 | // this checks do not work correctly if model is set | |
|
124 | Q_ASSERT(index<m_series->count()); | |
|
125 | Q_ASSERT(index>=0); | |
|
126 | point = calculateGeometryPoint(index); | |
|
127 | points.insert(index, point); | |
|
128 | updateLayout(m_points, points, index); | |
|
129 | } | |
|
111 | Q_ASSERT(index<m_series->count()); | |
|
112 | Q_ASSERT(index>=0); | |
|
113 | point = calculateGeometryPoint(index); | |
|
114 | points.insert(index, point); | |
|
115 | updateLayout(m_points, points, index); | |
|
130 | 116 | update(); |
|
131 | 117 | } |
|
132 | 118 | void XYChartItem::handlePointRemoved(int index) |
|
133 | 119 | { |
|
134 | 120 | QVector<QPointF> points = m_points; |
|
135 | if (m_series->model()) { | |
|
136 | if (index < m_series->mapFirst()) | |
|
137 |
|
|
|
138 | else | |
|
139 | points.remove(index - m_series->mapFirst()); | |
|
140 | updateLayout(m_points, points, index - m_series->mapFirst()); | |
|
141 | } | |
|
142 | else { | |
|
143 | // this checks do not work correctly if model is set | |
|
144 | Q_ASSERT(index<m_series->count() + 1); | |
|
145 | Q_ASSERT(index>=0); | |
|
146 | points.remove(index); | |
|
147 | updateLayout(m_points, points, index); | |
|
148 | } | |
|
121 | Q_ASSERT(index<m_series->count() + 1); | |
|
122 | Q_ASSERT(index>=0); | |
|
123 | points.remove(index); | |
|
124 | updateLayout(m_points, points, index); | |
|
149 | 125 | update(); |
|
150 | 126 | } |
|
151 | 127 |
@@ -166,7 +166,7 void TableWidget::updateChartType(bool toggle) | |||
|
166 | 166 | m_series = new QLineSeries; |
|
167 | 167 | m_series->setModel(m_model); |
|
168 | 168 | m_series->setModelMapping(0,1, Qt::Vertical); |
|
169 | m_series->setModelMappingRange(1, 4); | |
|
169 | // m_series->setModelMappingRange(1, 4); | |
|
170 | 170 | m_chart->addSeries(m_series); |
|
171 | 171 | seriesColorHex = "#" + QString::number(m_series->pen().color().rgb(), 16).right(6).toUpper(); |
|
172 | 172 | m_model->addMapping(seriesColorHex, QRect(0, 1, 2, 4)); |
@@ -183,7 +183,7 void TableWidget::updateChartType(bool toggle) | |||
|
183 | 183 | m_series = new QLineSeries; |
|
184 | 184 | m_series->setModel(m_model); |
|
185 | 185 | m_series->setModelMapping(4,5, Qt::Vertical); |
|
186 | m_series->setModelMappingRange(2, 0); | |
|
186 | // m_series->setModelMappingRange(2, 0); | |
|
187 | 187 | m_chart->addSeries(m_series); |
|
188 | 188 | seriesColorHex = "#" + QString::number(m_series->pen().color().rgb(), 16).right(6).toUpper(); |
|
189 | 189 | m_model->addMapping(seriesColorHex, QRect(4, 2, 2, 1000)); |
@@ -194,7 +194,7 void TableWidget::updateChartType(bool toggle) | |||
|
194 | 194 | m_series = new QSplineSeries; |
|
195 | 195 | m_series->setModel(m_model); |
|
196 | 196 | m_series->setModelMapping(0,1, Qt::Vertical); |
|
197 | m_series->setModelMappingRange(1, 4); | |
|
197 | // m_series->setModelMappingRange(1, 4); | |
|
198 | 198 | // series->setModelMapping(0,1, Qt::Horizontal); |
|
199 | 199 | m_chart->addSeries(m_series); |
|
200 | 200 | seriesColorHex = "#" + QString::number(m_series->pen().color().rgb(), 16).right(6).toUpper(); |
@@ -204,7 +204,7 void TableWidget::updateChartType(bool toggle) | |||
|
204 | 204 | m_series = new QSplineSeries; |
|
205 | 205 | m_series->setModel(m_model); |
|
206 | 206 | m_series->setModelMapping(2,3, Qt::Vertical); |
|
207 | m_series->setModelMappingRange(0, 0); | |
|
207 | // m_series->setModelMappingRange(0, 0); | |
|
208 | 208 | // series->setModelMapping(2,3, Qt::Horizontal); |
|
209 | 209 | m_chart->addSeries(m_series); |
|
210 | 210 | seriesColorHex = "#" + QString::number(m_series->pen().color().rgb(), 16).right(6).toUpper(); |
@@ -214,7 +214,7 void TableWidget::updateChartType(bool toggle) | |||
|
214 | 214 | m_series = new QSplineSeries; |
|
215 | 215 | m_series->setModel(m_model); |
|
216 | 216 | m_series->setModelMapping(4,5, Qt::Vertical); |
|
217 | m_series->setModelMappingRange(2, 0); | |
|
217 | // m_series->setModelMappingRange(2, 0); | |
|
218 | 218 | // series->setModelMapping(4,5, Qt::Horizontal); |
|
219 | 219 | m_chart->addSeries(m_series); |
|
220 | 220 | seriesColorHex = "#" + QString::number(m_series->pen().color().rgb(), 16).right(6).toUpper(); |
@@ -226,7 +226,7 void TableWidget::updateChartType(bool toggle) | |||
|
226 | 226 | m_series = new QScatterSeries; |
|
227 | 227 | m_series->setModel(m_model); |
|
228 | 228 | m_series->setModelMapping(0,1, Qt::Vertical); |
|
229 | m_series->setModelMappingRange(2, 0); | |
|
229 | // m_series->setModelMappingRange(2, 0); | |
|
230 | 230 | // series->setModelMapping(0,1, Qt::Horizontal); |
|
231 | 231 | m_chart->addSeries(m_series); |
|
232 | 232 | |
@@ -237,7 +237,7 void TableWidget::updateChartType(bool toggle) | |||
|
237 | 237 | m_series = new QScatterSeries; |
|
238 | 238 | m_series->setModel(m_model); |
|
239 | 239 | m_series->setModelMapping(2,3, Qt::Vertical); |
|
240 | m_series->setModelMappingRange(1, 6); | |
|
240 | // m_series->setModelMappingRange(1, 6); | |
|
241 | 241 | // series->setModelMapping(2,3, Qt::Horizontal); |
|
242 | 242 | m_chart->addSeries(m_series); |
|
243 | 243 | |
@@ -297,7 +297,7 void TableWidget::updateChartType(bool toggle) | |||
|
297 | 297 | QLineSeries* upperLineSeries = new QLineSeries; |
|
298 | 298 | upperLineSeries->setModel(m_model); |
|
299 | 299 | upperLineSeries->setModelMapping(0, 1, Qt::Vertical); |
|
300 | upperLineSeries->setModelMappingRange(1, 5); | |
|
300 | // upperLineSeries->setModelMappingRange(1, 5); | |
|
301 | 301 | QLineSeries* lowerLineSeries = new QLineSeries; |
|
302 | 302 | lowerLineSeries->setModel(m_model); |
|
303 | 303 | lowerLineSeries->setModelMapping(2, 3, Qt::Vertical); |
General Comments 0
You need to be logged in to leave comments.
Login now