##// 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 Resets the QBarModelMapper to the default state.
199 Resets the QBarModelMapper to the default state.
220 first: 0; count: -1; firstBarSetSection: -1; lastBarSetSection: -1; categoriesSection: -1
200 first: 0; count: -1; firstBarSetSection: -1; lastBarSetSection: -1; categoriesSection: -1
221 */
201 */
@@ -226,7 +206,6 void QBarModelMapper::reset()
226 d->m_count = -1;
206 d->m_count = -1;
227 d->m_firstBarSetSection = -1;
207 d->m_firstBarSetSection = -1;
228 d->m_lastBarSetSection = -1;
208 d->m_lastBarSetSection = -1;
229 d->m_categoriesSection = -1;
230 d->initializeBarFromModel();
209 d->initializeBarFromModel();
231 }
210 }
232
211
@@ -240,7 +219,6 QBarModelMapperPrivate::QBarModelMapperPrivate(QBarModelMapper *q) :
240 m_orientation(Qt::Vertical),
219 m_orientation(Qt::Vertical),
241 m_firstBarSetSection(-1),
220 m_firstBarSetSection(-1),
242 m_lastBarSetSection(-1),
221 m_lastBarSetSection(-1),
243 m_categoriesSection(-1),
244 m_seriesSignalsBlock(false),
222 m_seriesSignalsBlock(false),
245 m_modelSignalsBlock(false),
223 m_modelSignalsBlock(false),
246 q_ptr(q)
224 q_ptr(q)
@@ -290,17 +268,6 QModelIndex QBarModelMapperPrivate::barModelIndex(int barSection, int posInBar)
290 return m_model->index(barSection, posInBar + m_first);
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 void QBarModelMapperPrivate::modelUpdated(QModelIndex topLeft, QModelIndex bottomRight)
271 void QBarModelMapperPrivate::modelUpdated(QModelIndex topLeft, QModelIndex bottomRight)
305 {
272 {
306 Q_UNUSED(topLeft)
273 Q_UNUSED(topLeft)
@@ -314,8 +281,6 void QBarModelMapperPrivate::modelUpdated(QModelIndex topLeft, QModelIndex botto
314
281
315 blockSeriesSignals();
282 blockSeriesSignals();
316 QModelIndex index;
283 QModelIndex index;
317 // QPointF oldPoint;
318 // QPointF newPoint;
319 for (int row = topLeft.row(); row <= bottomRight.row(); row++) {
284 for (int row = topLeft.row(); row <= bottomRight.row(); row++) {
320 for (int column = topLeft.column(); column <= bottomRight.column(); column++) {
285 for (int column = topLeft.column(); column <= bottomRight.column(); column++) {
321 index = topLeft.sibling(row, column);
286 index = topLeft.sibling(row, column);
@@ -342,7 +307,7 void QBarModelMapperPrivate::modelRowsAdded(QModelIndex parent, int start, int e
342 if (m_orientation == Qt::Vertical)
307 if (m_orientation == Qt::Vertical)
343 // insertData(start, end);
308 // insertData(start, end);
344 initializeBarFromModel();
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 initializeBarFromModel();
311 initializeBarFromModel();
347 blockSeriesSignals(false);
312 blockSeriesSignals(false);
348 }
313 }
@@ -358,7 +323,7 void QBarModelMapperPrivate::modelRowsRemoved(QModelIndex parent, int start, int
358 if (m_orientation == Qt::Vertical)
323 if (m_orientation == Qt::Vertical)
359 // removeData(start, end);
324 // removeData(start, end);
360 initializeBarFromModel();
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 initializeBarFromModel();
327 initializeBarFromModel();
363 blockSeriesSignals(false);
328 blockSeriesSignals(false);
364 }
329 }
@@ -374,7 +339,7 void QBarModelMapperPrivate::modelColumnsAdded(QModelIndex parent, int start, in
374 if (m_orientation == Qt::Horizontal)
339 if (m_orientation == Qt::Horizontal)
375 // insertData(start, end);
340 // insertData(start, end);
376 initializeBarFromModel();
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 initializeBarFromModel();
343 initializeBarFromModel();
379 blockSeriesSignals(false);
344 blockSeriesSignals(false);
380 }
345 }
@@ -390,7 +355,7 void QBarModelMapperPrivate::modelColumnsRemoved(QModelIndex parent, int start,
390 if (m_orientation == Qt::Horizontal)
355 if (m_orientation == Qt::Horizontal)
391 // removeData(start, end);
356 // removeData(start, end);
392 initializeBarFromModel();
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 initializeBarFromModel();
359 initializeBarFromModel();
395 blockSeriesSignals(false);
360 blockSeriesSignals(false);
396 }
361 }
@@ -477,7 +442,6 void QBarModelMapperPrivate::initializeBarFromModel()
477 int posInBar = 0;
442 int posInBar = 0;
478 QModelIndex barIndex = barModelIndex(i, posInBar);
443 QModelIndex barIndex = barModelIndex(i, posInBar);
479 QBarSet *barSet = new QBarSet(m_model->headerData(i, Qt::Horizontal).toString());
444 QBarSet *barSet = new QBarSet(m_model->headerData(i, Qt::Horizontal).toString());
480 // QModelIndex yIndex = yModelIndex(pointPos);
481 while (barIndex.isValid()) {
445 while (barIndex.isValid()) {
482 barSet->append(m_model->data(barIndex, Qt::DisplayRole).toDouble());
446 barSet->append(m_model->data(barIndex, Qt::DisplayRole).toDouble());
483 posInBar++;
447 posInBar++;
@@ -485,18 +449,6 void QBarModelMapperPrivate::initializeBarFromModel()
485 }
449 }
486 m_series->append(barSet);
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 blockSeriesSignals(false);
452 blockSeriesSignals(false);
501 }
453 }
502
454
@@ -46,9 +46,6 protected:
46 int lastBarSetSection() const;
46 int lastBarSetSection() const;
47 void setLastBarSetSection(int lastBarSetSection);
47 void setLastBarSetSection(int lastBarSetSection);
48
48
49 int categoriesSection() const;
50 void setCategoriesSection(int categoriesSection);
51
52 Qt::Orientation orientation() const;
49 Qt::Orientation orientation() const;
53 void setOrientation(Qt::Orientation orientation);
50 void setOrientation(Qt::Orientation orientation);
54
51
@@ -35,7 +35,6 public Q_SLOTS:
35 private:
35 private:
36 QBarSet* barSet(QModelIndex index);
36 QBarSet* barSet(QModelIndex index);
37 QModelIndex barModelIndex(int barSection, int posInBar);
37 QModelIndex barModelIndex(int barSection, int posInBar);
38 QModelIndex categoriesModelIndex(int posInCategories);
39 void insertData(int start, int end);
38 void insertData(int start, int end);
40 void removeData(int start, int end);
39 void removeData(int start, int end);
41 void blockModelSignals(bool block = true);
40 void blockModelSignals(bool block = true);
@@ -49,7 +48,6 private:
49 Qt::Orientation m_orientation;
48 Qt::Orientation m_orientation;
50 int m_firstBarSetSection;
49 int m_firstBarSetSection;
51 int m_lastBarSetSection;
50 int m_lastBarSetSection;
52 int m_categoriesSection;
53 bool m_seriesSignalsBlock;
51 bool m_seriesSignalsBlock;
54 bool m_modelSignalsBlock;
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 Constructs a mapper object which is a child of \a parent.
28 Constructs a mapper object which is a child of \a parent.
36 */
29 */
37 QHBarModelMapper::QHBarModelMapper(QObject *parent) :
30 QHBarModelMapper::QHBarModelMapper(QObject *parent) :
@@ -60,16 +53,6 void QHBarModelMapper::setLastBarSetRow(int lastBarSetRow)
60 return QBarModelMapper::setLastBarSetSection(lastBarSetRow);
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 #include "moc_qhbarmodelmapper.cpp"
56 #include "moc_qhbarmodelmapper.cpp"
74
57
75 QTCOMMERCIALCHART_END_NAMESPACE
58 QTCOMMERCIALCHART_END_NAMESPACE
@@ -10,7 +10,6 class QTCOMMERCIALCHART_EXPORT QHBarModelMapper : public QBarModelMapper
10 Q_OBJECT
10 Q_OBJECT
11 Q_PROPERTY(int firstBarSetRow READ firstBarSetRow WRITE setFirstBarSetRow)
11 Q_PROPERTY(int firstBarSetRow READ firstBarSetRow WRITE setFirstBarSetRow)
12 Q_PROPERTY(int lastBarSetRow READ lastBarSetRow WRITE setLastBarSetRow)
12 Q_PROPERTY(int lastBarSetRow READ lastBarSetRow WRITE setLastBarSetRow)
13 Q_PROPERTY(int categoriesRow READ categoriesRow WRITE setCategoriesRow)
14
13
15 public:
14 public:
16 explicit QHBarModelMapper(QObject *parent = 0);
15 explicit QHBarModelMapper(QObject *parent = 0);
@@ -20,10 +19,6 public:
20
19
21 int lastBarSetRow() const;
20 int lastBarSetRow() const;
22 void setLastBarSetRow(int lastBarSetRow);
21 void setLastBarSetRow(int lastBarSetRow);
23
24 int categoriesRow() const;
25 void setCategoriesRow(int categoriesRow);
26
27 };
22 };
28
23
29 QTCOMMERCIALCHART_END_NAMESPACE
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 Constructs a mapper object which is a child of \a parent.
28 Constructs a mapper object which is a child of \a parent.
36 */
29 */
37 QVBarModelMapper::QVBarModelMapper(QObject *parent) :
30 QVBarModelMapper::QVBarModelMapper(QObject *parent) :
@@ -60,16 +53,6 void QVBarModelMapper::setLastBarSetColumn(int lastBarSetColumn)
60 return QBarModelMapper::setLastBarSetSection(lastBarSetColumn);
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 #include "moc_qvbarmodelmapper.cpp"
56 #include "moc_qvbarmodelmapper.cpp"
74
57
75 QTCOMMERCIALCHART_END_NAMESPACE
58 QTCOMMERCIALCHART_END_NAMESPACE
@@ -10,7 +10,6 class QTCOMMERCIALCHART_EXPORT QVBarModelMapper : public QBarModelMapper
10 Q_OBJECT
10 Q_OBJECT
11 Q_PROPERTY(int firstBarSetColumn READ firstBarSetColumn WRITE setFirstBarSetColumn)
11 Q_PROPERTY(int firstBarSetColumn READ firstBarSetColumn WRITE setFirstBarSetColumn)
12 Q_PROPERTY(int lastBarSetColumn READ lastBarSetColumn WRITE setLastBarSetColumn)
12 Q_PROPERTY(int lastBarSetColumn READ lastBarSetColumn WRITE setLastBarSetColumn)
13 Q_PROPERTY(int categoriesColumn READ categoriesColumn WRITE setCategoriesColumn)
14
13
15 public:
14 public:
16 explicit QVBarModelMapper(QObject *parent = 0);
15 explicit QVBarModelMapper(QObject *parent = 0);
@@ -20,10 +19,6 public:
20
19
21 int lastBarSetColumn() const;
20 int lastBarSetColumn() const;
22 void setLastBarSetColumn(int lastBarSetColumn);
21 void setLastBarSetColumn(int lastBarSetColumn);
23
24 int categoriesColumn() const;
25 void setCategoriesColumn(int categoriesColumn);
26
27 };
22 };
28
23
29 QTCOMMERCIALCHART_END_NAMESPACE
24 QTCOMMERCIALCHART_END_NAMESPACE
@@ -479,16 +479,10 void TableWidget::updateChartType(bool toggle)
479 m_chart->setAnimationOptions(QChart::SeriesAnimations);
479 m_chart->setAnimationOptions(QChart::SeriesAnimations);
480
480
481 QGroupedBarSeries* barSeries = new QGroupedBarSeries();
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 int first = 3;
483 int first = 3;
489 int count = 6;
484 int count = 6;
490 QVBarModelMapper *mapper = new QVBarModelMapper;
485 QVBarModelMapper *mapper = new QVBarModelMapper;
491 mapper->setCategoriesColumn(5);
492 mapper->setFirstBarSetColumn(2);
486 mapper->setFirstBarSetColumn(2);
493 mapper->setLastBarSetColumn(4);
487 mapper->setLastBarSetColumn(4);
494 mapper->setFirst(first);
488 mapper->setFirst(first);
@@ -498,6 +492,11 void TableWidget::updateChartType(bool toggle)
498 // barSeries->setModelMapper(mapper);
492 // barSeries->setModelMapper(mapper);
499 m_chart->addSeries(barSeries);
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 QList<QBarSet*> barsets = barSeries->barSets();
500 QList<QBarSet*> barsets = barSeries->barSets();
502 for (int i = 0; i < barsets.count(); i++) {
501 for (int i = 0; i < barsets.count(); i++) {
503 seriesColorHex = "#" + QString::number(barsets.at(i)->brush().color().rgb(), 16).right(6).toUpper();
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