##// END OF EJS Templates
Removed all the unfinished model functionality from XYSeries and BarSeries
Marek Rosa -
r990:2f31b8379e5f
parent child
Show More
@@ -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;
70 // m_categories = categories;
71 if (m_series) {
71 // if (m_series) {
72 // Replace categories of the QBarSeries with the new categories
72 // // Replace categories of the QBarSeries with the new categories
73 for (int i(0); i < m_categories.count(); i++) {
73 // for (int i(0); i < m_categories.count(); i++) {
74 if (m_series->categories().at(i) != m_categories.at(i))
74 // if (m_series->categories().at(i) != m_categories.at(i))
75 m_series->insertCategory(m_series->categoryCount(), m_categories.at(i));
75 // m_series->insertCategory(m_series->categoryCount(), m_categories.at(i));
76 }
76 // }
77 while (m_series->categoryCount() > m_categories.count())
77 // while (m_series->categoryCount() > m_categories.count())
78 m_series->removeCategory(m_series->categoryCount() - 1);
78 // m_series->removeCategory(m_series->categoryCount() - 1);
79 }
79 // }
80 }
80 }
81
81
82 QStringList DeclarativeBarSeries::barCategories()
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 Returns number of sets in series.
173 Returns number of sets in series.
195 */
174 */
196 int QBarSeries::barsetCount() const
175 int QBarSeries::barsetCount() const
@@ -251,7 +230,7 QBarCategories QBarSeries::categories() const
251 QBarCategories categories;
230 QBarCategories categories;
252 int count = d->m_internalModel->categoryCount();
231 int count = d->m_internalModel->categoryCount();
253 for (int i=1; i <= count; i++) {
232 for (int i=1; i <= count; i++) {
254 categories.insert(i, d->m_internalModel->categoryName(i - 1));
233 categories.insert(i, d->m_internalModel->categoryName(i - 1));
255 }
234 }
256 return categories;
235 return categories;
257
236
@@ -276,8 +255,6 QBarSeriesPrivate::QBarSeriesPrivate(QBarCategories categories, QBarSeries *q) :
276 m_mapCategories(-1),
255 m_mapCategories(-1),
277 m_mapBarBottom(-1),
256 m_mapBarBottom(-1),
278 m_mapBarTop(-1),
257 m_mapBarTop(-1),
279 m_mapFirst(0),
280 m_mapCount(0),
281 m_mapOrientation(Qt::Vertical)
258 m_mapOrientation(Qt::Vertical)
282 {
259 {
283 }
260 }
@@ -341,8 +318,6 bool QBarSeriesPrivate::setModel(QAbstractItemModel *model)
341 m_mapCategories = -1;
318 m_mapCategories = -1;
342 m_mapBarBottom = -1;
319 m_mapBarBottom = -1;
343 m_mapBarTop = -1;
320 m_mapBarTop = -1;
344 m_mapFirst = 0;
345 m_mapCount = 0;
346 m_mapOrientation = Qt::Vertical;
321 m_mapOrientation = Qt::Vertical;
347 }
322 }
348
323
@@ -369,51 +344,35 void QBarSeriesPrivate::setModelMapping(int categories, int bottomBoundry, int t
369 m_mapCategories = categories;
344 m_mapCategories = categories;
370 m_mapBarBottom = bottomBoundry;
345 m_mapBarBottom = bottomBoundry;
371 m_mapBarTop = topBoundry;
346 m_mapBarTop = topBoundry;
372 // m_mapFirst = 1;
373 m_mapOrientation = orientation;
347 m_mapOrientation = orientation;
374
348
375 // connect the signals
349 // connect the signals
376 if (m_mapOrientation == Qt::Vertical) {
350 connect(m_model,SIGNAL(dataChanged(QModelIndex,QModelIndex)),
377 m_mapCount = m_model->rowCount() - m_mapFirst;
351 this, SLOT(modelUpdated(QModelIndex,QModelIndex)));
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 }
393
352
394 // create the initial bars
353 // create the initial bars
395 delete m_internalModel;
354 delete m_internalModel;
396 if (m_mapOrientation == Qt::Vertical) {
355 if (m_mapOrientation == Qt::Vertical) {
397 QStringList categories;
356 QStringList categories;
398 for (int k = m_mapFirst; k < m_mapFirst + m_mapCount; k++)
357 for (int k = 0; k < m_model->rowCount(); k++)
399 categories << m_model->data(m_model->index(k, m_mapCategories), Qt::DisplayRole).toString();
358 categories << m_model->data(m_model->index(k, m_mapCategories), Qt::DisplayRole).toString();
400 m_internalModel = new BarChartModel(categories, this);
359 m_internalModel = new BarChartModel(categories, this);
401
360
402 for (int i = m_mapBarBottom; i <= m_mapBarTop; i++) {
361 for (int i = m_mapBarBottom; i <= m_mapBarTop; i++) {
403 QBarSet* barSet = new QBarSet(QString("Column: %1").arg(i + 1));
362 QBarSet* barSet = new QBarSet(QString("Column: %1").arg(i + 1));
404 for(int m = m_mapFirst; m < m_mapFirst + m_mapCount; m++)
363 for(int m = 0; m < m_model->rowCount(); m++)
405 *barSet << m_model->data(m_model->index(m, i), Qt::DisplayRole).toDouble();
364 *barSet << m_model->data(m_model->index(m, i), Qt::DisplayRole).toDouble();
406 q->appendBarSet(barSet);
365 q->appendBarSet(barSet);
407 }
366 }
408 } else {
367 } else {
409 QStringList categories;
368 QStringList categories;
410 for (int k = m_mapFirst; k < m_mapFirst + m_mapCount; k++)
369 for (int k = 0; k < m_model->columnCount(); k++)
411 categories << m_model->data(m_model->index(m_mapCategories, k), Qt::DisplayRole).toString();
370 categories << m_model->data(m_model->index(m_mapCategories, k), Qt::DisplayRole).toString();
412 m_internalModel = new BarChartModel(categories, this);
371 m_internalModel = new BarChartModel(categories, this);
413
372
414 for (int i = m_mapBarBottom; i <= m_mapBarTop; i++) {
373 for (int i = m_mapBarBottom; i <= m_mapBarTop; i++) {
415 QBarSet* barSet = new QBarSet(QString("Row: %1").arg(i + 1));
374 QBarSet* barSet = new QBarSet(QString("Row: %1").arg(i + 1));
416 for(int m = m_mapFirst; m < m_mapFirst + m_mapCount; m++)
375 for(int m = 0; m < m_model->columnCount(); m++)
417 *barSet << m_model->data(m_model->index(i, m), Qt::DisplayRole).toDouble();
376 *barSet << m_model->data(m_model->index(i, m), Qt::DisplayRole).toDouble();
418 q->appendBarSet(barSet);
377 q->appendBarSet(barSet);
419 }
378 }
@@ -427,47 +386,15 void QBarSeriesPrivate::modelUpdated(QModelIndex topLeft, QModelIndex bottomRigh
427 if (m_mapOrientation == Qt::Vertical)
386 if (m_mapOrientation == Qt::Vertical)
428 {
387 {
429 // model update is relevant to BarSeries if the change was made to the part of the model that was mapped to BarSeries
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 && topLeft.row() >= m_mapFirst && topLeft.row() < m_mapFirst + m_mapCount)
389 if (topLeft.column() >= m_mapBarBottom && topLeft.column() <= m_mapBarTop)
431 barsetAt(topLeft.column() - m_mapBarBottom)->setValue(topLeft.row() - m_mapFirst, m_model->data(topLeft, Qt::DisplayRole).toDouble());
390 barsetAt(topLeft.column() - m_mapBarBottom)->setValue(topLeft.row(), m_model->data(topLeft, Qt::DisplayRole).toDouble());
432 }
391 }
433 else
392 else
434 {
393 {
435 // model update is relevant to BarSeries if the change was made to the part of the model that was mapped to BarSeries
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 && topLeft.column() >= m_mapFirst && topLeft.column() < m_mapFirst + m_mapCount)
395 if (topLeft.row() >= m_mapBarBottom && topLeft.row() <= m_mapBarTop)
437 barsetAt(topLeft.row() - m_mapBarBottom)->setValue(topLeft.column() - m_mapFirst, m_model->data(topLeft, Qt::DisplayRole).toDouble());
396 barsetAt(topLeft.row() - m_mapBarBottom)->setValue(topLeft.column(), m_model->data(topLeft, Qt::DisplayRole).toDouble());
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);
469 }
397 }
470 emit restructuredBars();
471 }
398 }
472
399
473 void QBarSeriesPrivate::barsetChanged()
400 void QBarSeriesPrivate::barsetChanged()
@@ -50,8 +50,6 public:
50 void appendBarSets(QList<QBarSet* > sets);
50 void appendBarSets(QList<QBarSet* > sets);
51 void removeBarSets(QList<QBarSet* > sets);
51 void removeBarSets(QList<QBarSet* > sets);
52 void insertBarSet(int i, QBarSet *set);
52 void insertBarSet(int i, QBarSet *set);
53 void insertCategory(int i, QString category);
54 void removeCategory(int i);
55 int barsetCount() const;
53 int barsetCount() const;
56 int categoryCount() const;
54 int categoryCount() const;
57 QList<QBarSet*> barSets() const;
55 QList<QBarSet*> barSets() const;
@@ -44,8 +44,6 Q_SIGNALS:
44 private Q_SLOTS:
44 private Q_SLOTS:
45 // slots for updating bars when data in model changes
45 // slots for updating bars when data in model changes
46 void modelUpdated(QModelIndex topLeft, QModelIndex bottomRight);
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 void barsetChanged();
47 void barsetChanged();
50
48
51 protected:
49 protected:
@@ -54,8 +52,6 protected:
54 int m_mapCategories;
52 int m_mapCategories;
55 int m_mapBarBottom;
53 int m_mapBarBottom;
56 int m_mapBarTop;
54 int m_mapBarTop;
57 int m_mapFirst;
58 int m_mapCount;
59 Qt::Orientation m_mapOrientation;
55 Qt::Orientation m_mapOrientation;
60 private:
56 private:
61 Q_DECLARE_PUBLIC(QBarSeries)
57 Q_DECLARE_PUBLIC(QBarSeries)
@@ -66,13 +66,6 QPointF QSplineSeries::controlPoint(int index) const
66 return d->m_controlPoints[index];
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 QSplineSeriesPrivate::QSplineSeriesPrivate(QSplineSeries* q):QLineSeriesPrivate(q)
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 \fn bool QSplineSeries::setModelMappingRange(int first, int count)
183 \fn bool QSplineSeries::setModelMappingRange(int first, int count)
215 Allows limiting the model mapping.
184 Allows limiting the model mapping.
@@ -40,7 +40,6 public:
40 QAbstractSeries::QSeriesType type() const;
40 QAbstractSeries::QSeriesType type() const;
41
41
42 QPointF controlPoint(int index) const;
42 QPointF controlPoint(int index) const;
43 void setModelMappingRange(int first, int count);
44
43
45 private:
44 private:
46 Q_DECLARE_PRIVATE(QSplineSeries);
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 \internal
79 \internal
93
80
94 Constructs empty series object which is a child of \a parent.
81 Constructs empty series object which is a child of \a parent.
@@ -220,10 +207,10 qreal QXYSeries::x(int pos) const
220 if (d->m_model) {
207 if (d->m_model) {
221 if (d->m_mapOrientation == Qt::Vertical)
208 if (d->m_mapOrientation == Qt::Vertical)
222 // consecutive data is read from model's column
209 // consecutive data is read from model's column
223 return d->m_model->data(d->m_model->index(pos + d->m_mapFirst, d->m_mapX), Qt::DisplayRole).toDouble();
210 return d->m_model->data(d->m_model->index(pos, d->m_mapX), Qt::DisplayRole).toDouble();
224 else
211 else
225 // consecutive data is read from model's row
212 // consecutive data is read from model's row
226 return d->m_model->data(d->m_model->index(d->m_mapX, pos + d->m_mapFirst), Qt::DisplayRole).toDouble();
213 return d->m_model->data(d->m_model->index(d->m_mapX, pos), Qt::DisplayRole).toDouble();
227 } else {
214 } else {
228 // model is not specified, return the data from series' internal data store
215 // model is not specified, return the data from series' internal data store
229 return d->m_x.at(pos);
216 return d->m_x.at(pos);
@@ -239,10 +226,10 qreal QXYSeries::y(int pos) const
239 if (d->m_model) {
226 if (d->m_model) {
240 if (d->m_mapOrientation == Qt::Vertical)
227 if (d->m_mapOrientation == Qt::Vertical)
241 // consecutive data is read from model's column
228 // consecutive data is read from model's column
242 return d->m_model->data(d->m_model->index(pos + d->m_mapFirst, d->m_mapY), Qt::DisplayRole).toDouble();
229 return d->m_model->data(d->m_model->index(pos, d->m_mapY), Qt::DisplayRole).toDouble();
243 else
230 else
244 // consecutive data is read from model's row
231 // consecutive data is read from model's row
245 return d->m_model->data(d->m_model->index(d->m_mapY, pos + d->m_mapFirst), Qt::DisplayRole).toDouble();
232 return d->m_model->data(d->m_model->index(d->m_mapY, pos), Qt::DisplayRole).toDouble();
246 } else {
233 } else {
247 // model is not specified, return the data from series' internal data store
234 // model is not specified, return the data from series' internal data store
248 return d->m_y.at(pos);
235 return d->m_y.at(pos);
@@ -260,19 +247,11 int QXYSeries::count() const
260
247
261 if (d->m_model) {
248 if (d->m_model) {
262 if (d->m_mapOrientation == Qt::Vertical) {
249 if (d->m_mapOrientation == Qt::Vertical) {
263 // data is in a column. Return the number of mapped items if the model's column have enough items
250 // data is in a column. Return the number of mapped items
264 // or the number of items that can be mapped
251 return d->m_model->rowCount();
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);
269 } else {
252 } else {
270 // data is in a row. Return the number of mapped items if the model's row have enough items
253 // data is in a row. Return the number of mapped items
271 // or the number of items that can be mapped
254 return d->m_model->columnCount();
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);
276 }
255 }
277 }
256 }
278
257
@@ -386,145 +365,11 void QXYSeries::modelUpdated(QModelIndex topLeft, QModelIndex bottomRight)
386 Q_UNUSED(bottomRight)
365 Q_UNUSED(bottomRight)
387 Q_D(QXYSeries);
366 Q_D(QXYSeries);
388 if (d->m_mapOrientation == Qt::Vertical) {
367 if (d->m_mapOrientation == Qt::Vertical) {
389 if (topLeft.row() >= d->m_mapFirst && (!d->m_mapLimited || topLeft.row() < d->m_mapFirst + d->m_mapCount))
368 if (topLeft.column() == d->m_mapX || topLeft.column() == d->m_mapY)
390 emit d->pointReplaced(topLeft.row() - d->m_mapFirst);
369 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 }
526 } else {
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 QObject::disconnect(d->m_model, 0, this, 0);
386 QObject::disconnect(d->m_model, 0, this, 0);
542 d->m_mapX = -1;
387 d->m_mapX = -1;
543 d->m_mapY = -1;
388 d->m_mapY = -1;
544 d->m_mapFirst = 0;
545 d->m_mapCount = 0;
546 d->m_mapLimited = false;
547 d->m_mapOrientation = Qt::Vertical;
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 return;
413 return;
572 d->m_mapX = modelX;
414 d->m_mapX = modelX;
573 d->m_mapY = modelY;
415 d->m_mapY = modelY;
574 d->m_mapFirst = 0;
575 d->m_mapOrientation = orientation;
416 d->m_mapOrientation = orientation;
576 if (d->m_mapOrientation == Qt::Vertical) {
417 connect(d->m_model,SIGNAL(dataChanged(QModelIndex,QModelIndex)), this, SLOT(modelUpdated(QModelIndex,QModelIndex)));
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;
621 }
418 }
622
419
623 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
420 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
624
421
422
625 QXYSeriesPrivate::QXYSeriesPrivate(QXYSeries *q) : QAbstractSeriesPrivate(q),
423 QXYSeriesPrivate::QXYSeriesPrivate(QXYSeries *q) : QAbstractSeriesPrivate(q),
626 m_mapX(-1),
424 m_mapX(-1),
627 m_mapY(-1),
425 m_mapY(-1),
628 m_mapFirst(0),
629 m_mapCount(0),
630 m_mapLimited(false),
631 m_mapOrientation( Qt::Vertical),
426 m_mapOrientation( Qt::Vertical),
632 m_pointsVisible(false)
427 m_pointsVisible(false)
633 {
428 {
@@ -68,18 +68,10 public:
68 bool pointsVisible() const;
68 bool pointsVisible() const;
69
69
70 bool setModel(QAbstractItemModel *model);
70 bool setModel(QAbstractItemModel *model);
71
72 virtual void setModelMapping(int modelX, int modelY, Qt::Orientation orientation = Qt::Vertical);
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 private Q_SLOTS:
73 private Q_SLOTS:
78 void modelUpdated(QModelIndex topLeft, QModelIndex bottomRight);
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 Q_SIGNALS:
76 Q_SIGNALS:
85 void clicked(const QPointF &point);
77 void clicked(const QPointF &point);
@@ -61,11 +61,7 protected:
61
61
62 int m_mapX;
62 int m_mapX;
63 int m_mapY;
63 int m_mapY;
64 int m_mapFirst;
65 int m_mapCount;
66 bool m_mapLimited;
67 Qt::Orientation m_mapOrientation;
64 Qt::Orientation m_mapOrientation;
68 int tempItemsRemoved;
69 bool m_pointsVisible;
65 bool m_pointsVisible;
70
66
71 private:
67 private:
@@ -108,44 +108,20 void XYChartItem::handlePointAdded(int index)
108 {
108 {
109 QVector<QPointF> points = m_points;
109 QVector<QPointF> points = m_points;
110 QPointF point;
110 QPointF point;
111 if (m_series->model()) {
111 Q_ASSERT(index<m_series->count());
112 point = calculateGeometryPoint(index - m_series->mapFirst());
112 Q_ASSERT(index>=0);
113 if (index < m_series->mapFirst()) {
113 point = calculateGeometryPoint(index);
114 points.insert(0, point);
114 points.insert(index, point);
115 updateLayout(m_points, points, 0);
115 updateLayout(m_points, points, index);
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 }
130 update();
116 update();
131 }
117 }
132 void XYChartItem::handlePointRemoved(int index)
118 void XYChartItem::handlePointRemoved(int index)
133 {
119 {
134 QVector<QPointF> points = m_points;
120 QVector<QPointF> points = m_points;
135 if (m_series->model()) {
121 Q_ASSERT(index<m_series->count() + 1);
136 if (index < m_series->mapFirst())
122 Q_ASSERT(index>=0);
137 points.remove(0);
123 points.remove(index);
138 else
124 updateLayout(m_points, points, index);
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 }
149 update();
125 update();
150 }
126 }
151
127
@@ -166,7 +166,7 void TableWidget::updateChartType(bool toggle)
166 m_series = new QLineSeries;
166 m_series = new QLineSeries;
167 m_series->setModel(m_model);
167 m_series->setModel(m_model);
168 m_series->setModelMapping(0,1, Qt::Vertical);
168 m_series->setModelMapping(0,1, Qt::Vertical);
169 m_series->setModelMappingRange(1, 4);
169 // m_series->setModelMappingRange(1, 4);
170 m_chart->addSeries(m_series);
170 m_chart->addSeries(m_series);
171 seriesColorHex = "#" + QString::number(m_series->pen().color().rgb(), 16).right(6).toUpper();
171 seriesColorHex = "#" + QString::number(m_series->pen().color().rgb(), 16).right(6).toUpper();
172 m_model->addMapping(seriesColorHex, QRect(0, 1, 2, 4));
172 m_model->addMapping(seriesColorHex, QRect(0, 1, 2, 4));
@@ -183,7 +183,7 void TableWidget::updateChartType(bool toggle)
183 m_series = new QLineSeries;
183 m_series = new QLineSeries;
184 m_series->setModel(m_model);
184 m_series->setModel(m_model);
185 m_series->setModelMapping(4,5, Qt::Vertical);
185 m_series->setModelMapping(4,5, Qt::Vertical);
186 m_series->setModelMappingRange(2, 0);
186 // m_series->setModelMappingRange(2, 0);
187 m_chart->addSeries(m_series);
187 m_chart->addSeries(m_series);
188 seriesColorHex = "#" + QString::number(m_series->pen().color().rgb(), 16).right(6).toUpper();
188 seriesColorHex = "#" + QString::number(m_series->pen().color().rgb(), 16).right(6).toUpper();
189 m_model->addMapping(seriesColorHex, QRect(4, 2, 2, 1000));
189 m_model->addMapping(seriesColorHex, QRect(4, 2, 2, 1000));
@@ -194,7 +194,7 void TableWidget::updateChartType(bool toggle)
194 m_series = new QSplineSeries;
194 m_series = new QSplineSeries;
195 m_series->setModel(m_model);
195 m_series->setModel(m_model);
196 m_series->setModelMapping(0,1, Qt::Vertical);
196 m_series->setModelMapping(0,1, Qt::Vertical);
197 m_series->setModelMappingRange(1, 4);
197 // m_series->setModelMappingRange(1, 4);
198 // series->setModelMapping(0,1, Qt::Horizontal);
198 // series->setModelMapping(0,1, Qt::Horizontal);
199 m_chart->addSeries(m_series);
199 m_chart->addSeries(m_series);
200 seriesColorHex = "#" + QString::number(m_series->pen().color().rgb(), 16).right(6).toUpper();
200 seriesColorHex = "#" + QString::number(m_series->pen().color().rgb(), 16).right(6).toUpper();
@@ -204,7 +204,7 void TableWidget::updateChartType(bool toggle)
204 m_series = new QSplineSeries;
204 m_series = new QSplineSeries;
205 m_series->setModel(m_model);
205 m_series->setModel(m_model);
206 m_series->setModelMapping(2,3, Qt::Vertical);
206 m_series->setModelMapping(2,3, Qt::Vertical);
207 m_series->setModelMappingRange(0, 0);
207 // m_series->setModelMappingRange(0, 0);
208 // series->setModelMapping(2,3, Qt::Horizontal);
208 // series->setModelMapping(2,3, Qt::Horizontal);
209 m_chart->addSeries(m_series);
209 m_chart->addSeries(m_series);
210 seriesColorHex = "#" + QString::number(m_series->pen().color().rgb(), 16).right(6).toUpper();
210 seriesColorHex = "#" + QString::number(m_series->pen().color().rgb(), 16).right(6).toUpper();
@@ -214,7 +214,7 void TableWidget::updateChartType(bool toggle)
214 m_series = new QSplineSeries;
214 m_series = new QSplineSeries;
215 m_series->setModel(m_model);
215 m_series->setModel(m_model);
216 m_series->setModelMapping(4,5, Qt::Vertical);
216 m_series->setModelMapping(4,5, Qt::Vertical);
217 m_series->setModelMappingRange(2, 0);
217 // m_series->setModelMappingRange(2, 0);
218 // series->setModelMapping(4,5, Qt::Horizontal);
218 // series->setModelMapping(4,5, Qt::Horizontal);
219 m_chart->addSeries(m_series);
219 m_chart->addSeries(m_series);
220 seriesColorHex = "#" + QString::number(m_series->pen().color().rgb(), 16).right(6).toUpper();
220 seriesColorHex = "#" + QString::number(m_series->pen().color().rgb(), 16).right(6).toUpper();
@@ -226,7 +226,7 void TableWidget::updateChartType(bool toggle)
226 m_series = new QScatterSeries;
226 m_series = new QScatterSeries;
227 m_series->setModel(m_model);
227 m_series->setModel(m_model);
228 m_series->setModelMapping(0,1, Qt::Vertical);
228 m_series->setModelMapping(0,1, Qt::Vertical);
229 m_series->setModelMappingRange(2, 0);
229 // m_series->setModelMappingRange(2, 0);
230 // series->setModelMapping(0,1, Qt::Horizontal);
230 // series->setModelMapping(0,1, Qt::Horizontal);
231 m_chart->addSeries(m_series);
231 m_chart->addSeries(m_series);
232
232
@@ -237,7 +237,7 void TableWidget::updateChartType(bool toggle)
237 m_series = new QScatterSeries;
237 m_series = new QScatterSeries;
238 m_series->setModel(m_model);
238 m_series->setModel(m_model);
239 m_series->setModelMapping(2,3, Qt::Vertical);
239 m_series->setModelMapping(2,3, Qt::Vertical);
240 m_series->setModelMappingRange(1, 6);
240 // m_series->setModelMappingRange(1, 6);
241 // series->setModelMapping(2,3, Qt::Horizontal);
241 // series->setModelMapping(2,3, Qt::Horizontal);
242 m_chart->addSeries(m_series);
242 m_chart->addSeries(m_series);
243
243
@@ -297,7 +297,7 void TableWidget::updateChartType(bool toggle)
297 QLineSeries* upperLineSeries = new QLineSeries;
297 QLineSeries* upperLineSeries = new QLineSeries;
298 upperLineSeries->setModel(m_model);
298 upperLineSeries->setModel(m_model);
299 upperLineSeries->setModelMapping(0, 1, Qt::Vertical);
299 upperLineSeries->setModelMapping(0, 1, Qt::Vertical);
300 upperLineSeries->setModelMappingRange(1, 5);
300 // upperLineSeries->setModelMappingRange(1, 5);
301 QLineSeries* lowerLineSeries = new QLineSeries;
301 QLineSeries* lowerLineSeries = new QLineSeries;
302 lowerLineSeries->setModel(m_model);
302 lowerLineSeries->setModel(m_model);
303 lowerLineSeries->setModelMapping(2, 3, Qt::Vertical);
303 lowerLineSeries->setModelMapping(2, 3, Qt::Vertical);
General Comments 0
You need to be logged in to leave comments. Login now