##// END OF EJS Templates
Fixes to BarSeries and BarModelMapper
Marek Rosa -
r1356:2dd60111aef3
parent child
Show More
@@ -93,7 +93,7 void BarChartItem::handleDataStructureChanged()
93 }
93 }
94
94
95 // TODO: Is this the right place to call it?
95 // TODO: Is this the right place to call it?
96 // presenter()->chartTheme()->decorate(m_series, presenter()->dataSet()->seriesIndex(m_series));
96 presenter()->chartTheme()->decorate(m_series, presenter()->dataSet()->seriesIndex(m_series));
97 handleLayoutChanged();
97 handleLayoutChanged();
98 }
98 }
99
99
@@ -461,6 +461,8 void QBarModelMapperPrivate::initializeBarFromModel()
461 for (int i = m_firstBarSetSection; i <= m_lastBarSetSection; i++) {
461 for (int i = m_firstBarSetSection; i <= m_lastBarSetSection; i++) {
462 int posInBar = 0;
462 int posInBar = 0;
463 QModelIndex barIndex = barModelIndex(i, posInBar);
463 QModelIndex barIndex = barModelIndex(i, posInBar);
464 // check if there is such model index
465 if (barIndex.isValid()) {
464 QBarSet *barSet = new QBarSet(m_model->headerData(i, Qt::Horizontal).toString());
466 QBarSet *barSet = new QBarSet(m_model->headerData(i, Qt::Horizontal).toString());
465 while (barIndex.isValid()) {
467 while (barIndex.isValid()) {
466 barSet->append(m_model->data(barIndex, Qt::DisplayRole).toDouble());
468 barSet->append(m_model->data(barIndex, Qt::DisplayRole).toDouble());
@@ -468,6 +470,9 void QBarModelMapperPrivate::initializeBarFromModel()
468 barIndex = barModelIndex(i, posInBar);
470 barIndex = barModelIndex(i, posInBar);
469 }
471 }
470 m_series->append(barSet);
472 m_series->append(barSet);
473 } else {
474 break;
475 }
471 }
476 }
472 blockSeriesSignals(false);
477 blockSeriesSignals(false);
473 }
478 }
@@ -178,10 +178,13 bool QBarSeries::remove(QList<QBarSet* > sets)
178 return success;
178 return success;
179 }
179 }
180
180
181 /*!
182 Removes all of the bar sets from the series
183 */
181 void QBarSeries::clear()
184 void QBarSeries::clear()
182 {
185 {
183 Q_D(QBarSeries);
186 Q_D(QBarSeries);
184 d->m_barSets.clear();
187 d->remove(barSets());
185 }
188 }
186
189
187 /*!
190 /*!
@@ -50,7 +50,9 TableWidget::TableWidget(QWidget *parent)
50 m_mapper(0),
50 m_mapper(0),
51 m_model(0),
51 m_model(0),
52 m_pieMapper(0),
52 m_pieMapper(0),
53 m_pieMapper2(0)
53 m_pieMapper2(0),
54 m_barSeries(0),
55 m_barMapper(0)
54 // specialPie(0)
56 // specialPie(0)
55 {
57 {
56 setGeometry(1900, 100, 1000, 600);
58 setGeometry(1900, 100, 1000, 600);
@@ -476,28 +478,29 void TableWidget::updateChartType(bool toggle)
476 // }
478 // }
477 else if (m_barRadioButton->isChecked())
479 else if (m_barRadioButton->isChecked())
478 {
480 {
479 m_chart->setAnimationOptions(QChart::SeriesAnimations);
481 // m_chart->setAnimationOptions(QChart::SeriesAnimations);
482 m_chart->setAnimationOptions(QChart::NoAnimation);
480
483
481 QGroupedBarSeries* barSeries = new QGroupedBarSeries();
484 m_barSeries = new QGroupedBarSeries();
482
485
483 int first = 3;
486 int first = 3;
484 int count = 6;
487 int count = 6;
485 QVBarModelMapper *mapper = new QVBarModelMapper;
488 m_barMapper = new QVBarModelMapper;
486 mapper->setFirstBarSetColumn(2);
489 m_barMapper->setFirstBarSetColumn(2);
487 mapper->setLastBarSetColumn(4);
490 m_barMapper->setLastBarSetColumn(4);
488 mapper->setFirst(first);
491 m_barMapper->setFirst(first);
489 mapper->setCount(count);
492 m_barMapper->setCount(count);
490 mapper->setSeries(barSeries);
493 m_barMapper->setSeries(m_barSeries);
491 mapper->setModel(m_model);
494 m_barMapper->setModel(m_model);
492 // barSeries->setModelMapper(mapper);
495 // barSeries->setModelMapper(mapper);
493 m_chart->addSeries(barSeries);
496 m_chart->addSeries(m_barSeries);
494
497
495 QStringList categories;
498 QStringList categories;
496 categories << "June" << "July" << "August" << "September" << "October" << "November";
499 categories << "June" << "July" << "August" << "September" << "October" << "November";
497
500
498 m_chart->axisX()->categories()->insert(categories);
501 m_chart->axisX()->categories()->insert(categories);
499
502
500 QList<QBarSet*> barsets = barSeries->barSets();
503 QList<QBarSet*> barsets = m_barSeries->barSets();
501 for (int i = 0; i < barsets.count(); i++) {
504 for (int i = 0; i < barsets.count(); i++) {
502 seriesColorHex = "#" + QString::number(barsets.at(i)->brush().color().rgb(), 16).right(6).toUpper();
505 seriesColorHex = "#" + QString::number(barsets.at(i)->brush().color().rgb(), 16).right(6).toUpper();
503 m_model->addMapping(seriesColorHex, QRect(2 + i, first, 1, barsets.at(i)->count()));
506 m_model->addMapping(seriesColorHex, QRect(2 + i, first, 1, barsets.at(i)->count()));
@@ -570,13 +573,15 void TableWidget::testPie3()
570
573
571 void TableWidget::testXY()
574 void TableWidget::testXY()
572 {
575 {
576 if (m_barMapper)
577 m_barMapper->setLastBarSetColumn(m_barMapper->lastBarSetColumn() + 1);
573 // if (m_series->type() != QAbstractSeries::SeriesTypeLine) {
578 // if (m_series->type() != QAbstractSeries::SeriesTypeLine) {
574 // m_series->append(QPointF(150, 75));
579 // m_series->append(QPointF(150, 75));
575 // }
580 // }
576
581
577 if (m_series->count() > 0) {
582 // if (m_series->count() > 0) {
578 m_series->remove(m_series->points().last());
583 // m_series->remove(m_series->points().last());
579 }
584 // }
580 }
585 }
581
586
582 TableWidget::~TableWidget()
587 TableWidget::~TableWidget()
@@ -29,6 +29,8
29 #include <QVPieModelMapper>
29 #include <QVPieModelMapper>
30 #include <QVXYModelMapper>
30 #include <QVXYModelMapper>
31 #include <QHXYModelMapper>
31 #include <QHXYModelMapper>
32 #include <QGroupedBarSeries>
33 #include <QVBarModelMapper>
32
34
33 class CustomTableModel;
35 class CustomTableModel;
34 class QTableView;
36 class QTableView;
@@ -66,6 +68,7 public:
66 QVXYModelMapper *m_mapper;
68 QVXYModelMapper *m_mapper;
67 CustomTableModel* m_model;
69 CustomTableModel* m_model;
68 QTableView* m_tableView;
70 QTableView* m_tableView;
71
69 QRadioButton* m_lineRadioButton;
72 QRadioButton* m_lineRadioButton;
70 QRadioButton* m_splineRadioButton;
73 QRadioButton* m_splineRadioButton;
71 QRadioButton* m_scatterRadioButton;
74 QRadioButton* m_scatterRadioButton;
@@ -73,10 +76,14 public:
73 QRadioButton* m_areaRadioButton;
76 QRadioButton* m_areaRadioButton;
74 QRadioButton* m_barRadioButton;
77 QRadioButton* m_barRadioButton;
75 QSpinBox* m_linesCountSpinBox;
78 QSpinBox* m_linesCountSpinBox;
79
76 QVPieModelMapper *m_pieMapper;
80 QVPieModelMapper *m_pieMapper;
77 QPieSeries* m_pieSeries;
81 QPieSeries* m_pieSeries;
78 QVPieModelMapper *m_pieMapper2;
82 QVPieModelMapper *m_pieMapper2;
79 QPieSeries* m_pieSeries2;
83 QPieSeries* m_pieSeries2;
84
85 QGroupedBarSeries* m_barSeries;
86 QVBarModelMapper* m_barMapper;
80 // QPieSeries* specialPie;
87 // QPieSeries* specialPie;
81 };
88 };
82
89
General Comments 0
You need to be logged in to leave comments. Login now