diff --git a/src/barchart/barchartitem.cpp b/src/barchart/barchartitem.cpp index 3784b1b..98acbbd 100644 --- a/src/barchart/barchartitem.cpp +++ b/src/barchart/barchartitem.cpp @@ -93,7 +93,7 @@ void BarChartItem::handleDataStructureChanged() } // TODO: Is this the right place to call it? -// presenter()->chartTheme()->decorate(m_series, presenter()->dataSet()->seriesIndex(m_series)); + presenter()->chartTheme()->decorate(m_series, presenter()->dataSet()->seriesIndex(m_series)); handleLayoutChanged(); } diff --git a/src/barchart/qbarmodelmapper.cpp b/src/barchart/qbarmodelmapper.cpp index 1c39dc5..7ac77e8 100644 --- a/src/barchart/qbarmodelmapper.cpp +++ b/src/barchart/qbarmodelmapper.cpp @@ -262,10 +262,10 @@ QBarSet* QBarModelMapperPrivate::barSet(QModelIndex index) if (m_orientation == Qt::Vertical && index.column() >= m_firstBarSetSection && index.column() <= m_lastBarSetSection) { if (index.row() >= m_first && (m_count == - 1 || index.row() < m_first + m_count)) { -// if (m_model->index(index.row(), m_valuesSection).isValid() && m_model->index(index.row(), m_labelsSection).isValid()) - return m_series->barSets().at(index.column() - m_firstBarSetSection); -// else -// return 0; + // if (m_model->index(index.row(), m_valuesSection).isValid() && m_model->index(index.row(), m_labelsSection).isValid()) + return m_series->barSets().at(index.column() - m_firstBarSetSection); + // else + // return 0; } } else if (m_orientation == Qt::Horizontal && index.row() >= m_firstBarSetSection && index.row() <= m_lastBarSetSection) { if (index.column() >= m_first && (m_count == - 1 || index.column() < m_first + m_count)) @@ -461,13 +461,18 @@ void QBarModelMapperPrivate::initializeBarFromModel() for (int i = m_firstBarSetSection; i <= m_lastBarSetSection; i++) { int posInBar = 0; QModelIndex barIndex = barModelIndex(i, posInBar); - QBarSet *barSet = new QBarSet(m_model->headerData(i, Qt::Horizontal).toString()); - while (barIndex.isValid()) { - barSet->append(m_model->data(barIndex, Qt::DisplayRole).toDouble()); - posInBar++; - barIndex = barModelIndex(i, posInBar); + // check if there is such model index + if (barIndex.isValid()) { + QBarSet *barSet = new QBarSet(m_model->headerData(i, Qt::Horizontal).toString()); + while (barIndex.isValid()) { + barSet->append(m_model->data(barIndex, Qt::DisplayRole).toDouble()); + posInBar++; + barIndex = barModelIndex(i, posInBar); + } + m_series->append(barSet); + } else { + break; } - m_series->append(barSet); } blockSeriesSignals(false); } diff --git a/src/barchart/qbarseries.cpp b/src/barchart/qbarseries.cpp index a168881..ff96959 100644 --- a/src/barchart/qbarseries.cpp +++ b/src/barchart/qbarseries.cpp @@ -178,10 +178,13 @@ bool QBarSeries::remove(QList sets) return success; } +/*! + Removes all of the bar sets from the series +*/ void QBarSeries::clear() { Q_D(QBarSeries); - d->m_barSets.clear(); + d->remove(barSets()); } /*! diff --git a/tests/tablemodelchart/tablewidget.cpp b/tests/tablemodelchart/tablewidget.cpp index 41f051a..b7b10e7 100644 --- a/tests/tablemodelchart/tablewidget.cpp +++ b/tests/tablemodelchart/tablewidget.cpp @@ -50,7 +50,9 @@ TableWidget::TableWidget(QWidget *parent) m_mapper(0), m_model(0), m_pieMapper(0), - m_pieMapper2(0) + m_pieMapper2(0), + m_barSeries(0), + m_barMapper(0) // specialPie(0) { setGeometry(1900, 100, 1000, 600); @@ -476,28 +478,29 @@ void TableWidget::updateChartType(bool toggle) // } else if (m_barRadioButton->isChecked()) { - m_chart->setAnimationOptions(QChart::SeriesAnimations); +// m_chart->setAnimationOptions(QChart::SeriesAnimations); + m_chart->setAnimationOptions(QChart::NoAnimation); - QGroupedBarSeries* barSeries = new QGroupedBarSeries(); + m_barSeries = new QGroupedBarSeries(); int first = 3; int count = 6; - QVBarModelMapper *mapper = new QVBarModelMapper; - mapper->setFirstBarSetColumn(2); - mapper->setLastBarSetColumn(4); - mapper->setFirst(first); - mapper->setCount(count); - mapper->setSeries(barSeries); - mapper->setModel(m_model); + m_barMapper = new QVBarModelMapper; + m_barMapper->setFirstBarSetColumn(2); + m_barMapper->setLastBarSetColumn(4); + m_barMapper->setFirst(first); + m_barMapper->setCount(count); + m_barMapper->setSeries(m_barSeries); + m_barMapper->setModel(m_model); // barSeries->setModelMapper(mapper); - m_chart->addSeries(barSeries); + m_chart->addSeries(m_barSeries); QStringList categories; categories << "June" << "July" << "August" << "September" << "October" << "November"; m_chart->axisX()->categories()->insert(categories); - QList barsets = barSeries->barSets(); + QList barsets = m_barSeries->barSets(); for (int i = 0; i < barsets.count(); i++) { seriesColorHex = "#" + QString::number(barsets.at(i)->brush().color().rgb(), 16).right(6).toUpper(); m_model->addMapping(seriesColorHex, QRect(2 + i, first, 1, barsets.at(i)->count())); @@ -570,13 +573,15 @@ void TableWidget::testPie3() void TableWidget::testXY() { + if (m_barMapper) + m_barMapper->setLastBarSetColumn(m_barMapper->lastBarSetColumn() + 1); // if (m_series->type() != QAbstractSeries::SeriesTypeLine) { // m_series->append(QPointF(150, 75)); // } - if (m_series->count() > 0) { - m_series->remove(m_series->points().last()); - } +// if (m_series->count() > 0) { +// m_series->remove(m_series->points().last()); +// } } TableWidget::~TableWidget() diff --git a/tests/tablemodelchart/tablewidget.h b/tests/tablemodelchart/tablewidget.h index abe7c3d..0a84bc3 100644 --- a/tests/tablemodelchart/tablewidget.h +++ b/tests/tablemodelchart/tablewidget.h @@ -29,6 +29,8 @@ #include #include #include +#include +#include class CustomTableModel; class QTableView; @@ -66,6 +68,7 @@ public: QVXYModelMapper *m_mapper; CustomTableModel* m_model; QTableView* m_tableView; + QRadioButton* m_lineRadioButton; QRadioButton* m_splineRadioButton; QRadioButton* m_scatterRadioButton; @@ -73,10 +76,14 @@ public: QRadioButton* m_areaRadioButton; QRadioButton* m_barRadioButton; QSpinBox* m_linesCountSpinBox; + QVPieModelMapper *m_pieMapper; QPieSeries* m_pieSeries; QVPieModelMapper *m_pieMapper2; QPieSeries* m_pieSeries2; + + QGroupedBarSeries* m_barSeries; + QVBarModelMapper* m_barMapper; // QPieSeries* specialPie; };