##// END OF EJS Templates
Removed categories support from BarModelMapper
Marek Rosa -
r1354:ab531266047d
parent child
Show More
@@ -196,26 +196,6 void QBarModelMapper::setLastBarSetSection(int lastBarSetSection)
196 196 }
197 197
198 198 /*!
199 Returns which section of the model is used as the data source for the x axis categories.
200 */
201 int QBarModelMapper::categoriesSection() const
202 {
203 Q_D(const QBarModelMapper);
204 return d->m_categoriesSection;
205 }
206
207 /*!
208 Sets the model section that is used as the data source for the x axis categories.
209 Parameter \a categoriesSection specifies the section of the model.
210 */
211 void QBarModelMapper::setCategoriesSection(int categoriesSection)
212 {
213 Q_D(QBarModelMapper);
214 d->m_categoriesSection = categoriesSection;
215 d->initializeBarFromModel();
216 }
217
218 /*!
219 199 Resets the QBarModelMapper to the default state.
220 200 first: 0; count: -1; firstBarSetSection: -1; lastBarSetSection: -1; categoriesSection: -1
221 201 */
@@ -226,7 +206,6 void QBarModelMapper::reset()
226 206 d->m_count = -1;
227 207 d->m_firstBarSetSection = -1;
228 208 d->m_lastBarSetSection = -1;
229 d->m_categoriesSection = -1;
230 209 d->initializeBarFromModel();
231 210 }
232 211
@@ -240,7 +219,6 QBarModelMapperPrivate::QBarModelMapperPrivate(QBarModelMapper *q) :
240 219 m_orientation(Qt::Vertical),
241 220 m_firstBarSetSection(-1),
242 221 m_lastBarSetSection(-1),
243 m_categoriesSection(-1),
244 222 m_seriesSignalsBlock(false),
245 223 m_modelSignalsBlock(false),
246 224 q_ptr(q)
@@ -290,17 +268,6 QModelIndex QBarModelMapperPrivate::barModelIndex(int barSection, int posInBar)
290 268 return m_model->index(barSection, posInBar + m_first);
291 269 }
292 270
293 QModelIndex QBarModelMapperPrivate::categoriesModelIndex(int posInCategories)
294 {
295 if (m_count != -1 && posInCategories >= m_count)
296 return QModelIndex(); // invalid
297
298 if (m_orientation == Qt::Vertical)
299 return m_model->index(posInCategories + m_first, m_categoriesSection);
300 else
301 return m_model->index(m_categoriesSection, posInCategories + m_first);
302 }
303
304 271 void QBarModelMapperPrivate::modelUpdated(QModelIndex topLeft, QModelIndex bottomRight)
305 272 {
306 273 Q_UNUSED(topLeft)
@@ -314,8 +281,6 void QBarModelMapperPrivate::modelUpdated(QModelIndex topLeft, QModelIndex botto
314 281
315 282 blockSeriesSignals();
316 283 QModelIndex index;
317 // QPointF oldPoint;
318 // QPointF newPoint;
319 284 for (int row = topLeft.row(); row <= bottomRight.row(); row++) {
320 285 for (int column = topLeft.column(); column <= bottomRight.column(); column++) {
321 286 index = topLeft.sibling(row, column);
@@ -342,7 +307,7 void QBarModelMapperPrivate::modelRowsAdded(QModelIndex parent, int start, int e
342 307 if (m_orientation == Qt::Vertical)
343 308 // insertData(start, end);
344 309 initializeBarFromModel();
345 else if (start <= m_firstBarSetSection || start <= m_lastBarSetSection || start <= m_categoriesSection) // if the changes affect the map - reinitialize
310 else if (start <= m_firstBarSetSection || start <= m_lastBarSetSection) // if the changes affect the map - reinitialize
346 311 initializeBarFromModel();
347 312 blockSeriesSignals(false);
348 313 }
@@ -358,7 +323,7 void QBarModelMapperPrivate::modelRowsRemoved(QModelIndex parent, int start, int
358 323 if (m_orientation == Qt::Vertical)
359 324 // removeData(start, end);
360 325 initializeBarFromModel();
361 else if (start <= m_firstBarSetSection || start <= m_lastBarSetSection || start <= m_categoriesSection) // if the changes affect the map - reinitialize
326 else if (start <= m_firstBarSetSection || start <= m_lastBarSetSection) // if the changes affect the map - reinitialize
362 327 initializeBarFromModel();
363 328 blockSeriesSignals(false);
364 329 }
@@ -374,7 +339,7 void QBarModelMapperPrivate::modelColumnsAdded(QModelIndex parent, int start, in
374 339 if (m_orientation == Qt::Horizontal)
375 340 // insertData(start, end);
376 341 initializeBarFromModel();
377 else if (start <= m_firstBarSetSection || start <= m_lastBarSetSection || start <= m_categoriesSection) // if the changes affect the map - reinitialize
342 else if (start <= m_firstBarSetSection || start <= m_lastBarSetSection) // if the changes affect the map - reinitialize
378 343 initializeBarFromModel();
379 344 blockSeriesSignals(false);
380 345 }
@@ -390,7 +355,7 void QBarModelMapperPrivate::modelColumnsRemoved(QModelIndex parent, int start,
390 355 if (m_orientation == Qt::Horizontal)
391 356 // removeData(start, end);
392 357 initializeBarFromModel();
393 else if (start <= m_firstBarSetSection || start <= m_lastBarSetSection || start <= m_categoriesSection) // if the changes affect the map - reinitialize
358 else if (start <= m_firstBarSetSection || start <= m_lastBarSetSection) // if the changes affect the map - reinitialize
394 359 initializeBarFromModel();
395 360 blockSeriesSignals(false);
396 361 }
@@ -477,7 +442,6 void QBarModelMapperPrivate::initializeBarFromModel()
477 442 int posInBar = 0;
478 443 QModelIndex barIndex = barModelIndex(i, posInBar);
479 444 QBarSet *barSet = new QBarSet(m_model->headerData(i, Qt::Horizontal).toString());
480 // QModelIndex yIndex = yModelIndex(pointPos);
481 445 while (barIndex.isValid()) {
482 446 barSet->append(m_model->data(barIndex, Qt::DisplayRole).toDouble());
483 447 posInBar++;
@@ -485,18 +449,6 void QBarModelMapperPrivate::initializeBarFromModel()
485 449 }
486 450 m_series->append(barSet);
487 451 }
488
489 if (m_series->chart() && m_categoriesSection != -1) {
490 int posInCategories = 0;
491 QStringList categories;
492 QModelIndex categoriesIndex = categoriesModelIndex(posInCategories);
493 while (categoriesIndex.isValid()) {
494 categories.append(m_model->data(categoriesIndex, Qt::DisplayRole).toString());
495 posInCategories++;
496 categoriesIndex = categoriesModelIndex(posInCategories);
497 }
498 m_series->chart()->axisX()->categories()->insert(categories);
499 }
500 452 blockSeriesSignals(false);
501 453 }
502 454
@@ -46,9 +46,6 protected:
46 46 int lastBarSetSection() const;
47 47 void setLastBarSetSection(int lastBarSetSection);
48 48
49 int categoriesSection() const;
50 void setCategoriesSection(int categoriesSection);
51
52 49 Qt::Orientation orientation() const;
53 50 void setOrientation(Qt::Orientation orientation);
54 51
@@ -35,7 +35,6 public Q_SLOTS:
35 35 private:
36 36 QBarSet* barSet(QModelIndex index);
37 37 QModelIndex barModelIndex(int barSection, int posInBar);
38 QModelIndex categoriesModelIndex(int posInCategories);
39 38 void insertData(int start, int end);
40 39 void removeData(int start, int end);
41 40 void blockModelSignals(bool block = true);
@@ -49,7 +48,6 private:
49 48 Qt::Orientation m_orientation;
50 49 int m_firstBarSetSection;
51 50 int m_lastBarSetSection;
52 int m_categoriesSection;
53 51 bool m_seriesSignalsBlock;
54 52 bool m_modelSignalsBlock;
55 53
@@ -25,13 +25,6 QTCOMMERCIALCHART_BEGIN_NAMESPACE
25 25 */
26 26
27 27 /*!
28 \property QHBarModelMapper::categoriesRow
29 \brief Defines which row of the model is used as the data source for the x axis categories
30
31 Default value is: -1 (invalid mapping)
32 */
33
34 /*!
35 28 Constructs a mapper object which is a child of \a parent.
36 29 */
37 30 QHBarModelMapper::QHBarModelMapper(QObject *parent) :
@@ -60,16 +53,6 void QHBarModelMapper::setLastBarSetRow(int lastBarSetRow)
60 53 return QBarModelMapper::setLastBarSetSection(lastBarSetRow);
61 54 }
62 55
63 int QHBarModelMapper::categoriesRow() const
64 {
65 return QBarModelMapper::categoriesSection();
66 }
67
68 void QHBarModelMapper::setCategoriesRow(int categoriesRow)
69 {
70 return QBarModelMapper::setCategoriesSection(categoriesRow);
71 }
72
73 56 #include "moc_qhbarmodelmapper.cpp"
74 57
75 58 QTCOMMERCIALCHART_END_NAMESPACE
@@ -10,7 +10,6 class QTCOMMERCIALCHART_EXPORT QHBarModelMapper : public QBarModelMapper
10 10 Q_OBJECT
11 11 Q_PROPERTY(int firstBarSetRow READ firstBarSetRow WRITE setFirstBarSetRow)
12 12 Q_PROPERTY(int lastBarSetRow READ lastBarSetRow WRITE setLastBarSetRow)
13 Q_PROPERTY(int categoriesRow READ categoriesRow WRITE setCategoriesRow)
14 13
15 14 public:
16 15 explicit QHBarModelMapper(QObject *parent = 0);
@@ -20,10 +19,6 public:
20 19
21 20 int lastBarSetRow() const;
22 21 void setLastBarSetRow(int lastBarSetRow);
23
24 int categoriesRow() const;
25 void setCategoriesRow(int categoriesRow);
26
27 22 };
28 23
29 24 QTCOMMERCIALCHART_END_NAMESPACE
@@ -25,13 +25,6 QTCOMMERCIALCHART_BEGIN_NAMESPACE
25 25 */
26 26
27 27 /*!
28 \property QVBarModelMapper::categoriesColumn
29 \brief Defines which column of the model is used as the data source for the x axis categories
30
31 Default value is: -1 (invalid mapping)
32 */
33
34 /*!
35 28 Constructs a mapper object which is a child of \a parent.
36 29 */
37 30 QVBarModelMapper::QVBarModelMapper(QObject *parent) :
@@ -60,16 +53,6 void QVBarModelMapper::setLastBarSetColumn(int lastBarSetColumn)
60 53 return QBarModelMapper::setLastBarSetSection(lastBarSetColumn);
61 54 }
62 55
63 int QVBarModelMapper::categoriesColumn() const
64 {
65 return QBarModelMapper::categoriesSection();
66 }
67
68 void QVBarModelMapper::setCategoriesColumn(int categoriesColumn)
69 {
70 return QBarModelMapper::setCategoriesSection(categoriesColumn);
71 }
72
73 56 #include "moc_qvbarmodelmapper.cpp"
74 57
75 58 QTCOMMERCIALCHART_END_NAMESPACE
@@ -10,7 +10,6 class QTCOMMERCIALCHART_EXPORT QVBarModelMapper : public QBarModelMapper
10 10 Q_OBJECT
11 11 Q_PROPERTY(int firstBarSetColumn READ firstBarSetColumn WRITE setFirstBarSetColumn)
12 12 Q_PROPERTY(int lastBarSetColumn READ lastBarSetColumn WRITE setLastBarSetColumn)
13 Q_PROPERTY(int categoriesColumn READ categoriesColumn WRITE setCategoriesColumn)
14 13
15 14 public:
16 15 explicit QVBarModelMapper(QObject *parent = 0);
@@ -20,10 +19,6 public:
20 19
21 20 int lastBarSetColumn() const;
22 21 void setLastBarSetColumn(int lastBarSetColumn);
23
24 int categoriesColumn() const;
25 void setCategoriesColumn(int categoriesColumn);
26
27 22 };
28 23
29 24 QTCOMMERCIALCHART_END_NAMESPACE
@@ -479,16 +479,10 void TableWidget::updateChartType(bool toggle)
479 479 m_chart->setAnimationOptions(QChart::SeriesAnimations);
480 480
481 481 QGroupedBarSeries* barSeries = new QGroupedBarSeries();
482 // barSeries->setCategories(QStringList());
483 // barSeries->setModel(m_model);
484 // barSeries->setModelMappingRange(2, 5);
485 // barSeries->setModelMapping(5, 2, 4, Qt::Vertical);
486
487 482
488 483 int first = 3;
489 484 int count = 6;
490 485 QVBarModelMapper *mapper = new QVBarModelMapper;
491 mapper->setCategoriesColumn(5);
492 486 mapper->setFirstBarSetColumn(2);
493 487 mapper->setLastBarSetColumn(4);
494 488 mapper->setFirst(first);
@@ -498,6 +492,11 void TableWidget::updateChartType(bool toggle)
498 492 // barSeries->setModelMapper(mapper);
499 493 m_chart->addSeries(barSeries);
500 494
495 QStringList categories;
496 categories << "June" << "July" << "August" << "September" << "October" << "November";
497
498 m_chart->axisX()->categories()->insert(categories);
499
501 500 QList<QBarSet*> barsets = barSeries->barSets();
502 501 for (int i = 0; i < barsets.count(); i++) {
503 502 seriesColorHex = "#" + QString::number(barsets.at(i)->brush().color().rgb(), 16).right(6).toUpper();
General Comments 0
You need to be logged in to leave comments. Login now