From 63ded67c2d2b031613930d2c83a3f3fb21d3eada 2012-04-12 11:46:32 From: Marek Rosa Date: 2012-04-12 11:46:32 Subject: [PATCH] For BarChart labels for legend are now taken from model's headerData (row or column) --- diff --git a/src/barchart/qbarseries.cpp b/src/barchart/qbarseries.cpp index 08eea91..2802ddc 100644 --- a/src/barchart/qbarseries.cpp +++ b/src/barchart/qbarseries.cpp @@ -224,7 +224,6 @@ void QBarSeries::setLabelsVisible(bool visible) QBarSeriesPrivate::QBarSeriesPrivate(QBarCategories categories, QBarSeries *q) : QAbstractSeriesPrivate(q), m_categories(categories), - m_model(0), m_mapCategories(-1), m_mapBarBottom(-1), m_mapBarTop(-1), @@ -394,7 +393,7 @@ void QBarSeriesPrivate::setModelMapping(int categories, int bottomBoundry, int t } for (int i = m_mapBarBottom; i <= m_mapBarTop; i++) { - QBarSet* barSet = new QBarSet(QString("Column: %1").arg(i + 1)); + QBarSet* barSet = new QBarSet(m_model->headerData(i, Qt::Horizontal, Qt::DisplayRole).toString()); for(int m = 0; m < m_model->rowCount(); m++) *barSet << m_model->data(m_model->index(m, i), Qt::DisplayRole).toDouble(); q->appendBarSet(barSet); @@ -405,7 +404,7 @@ void QBarSeriesPrivate::setModelMapping(int categories, int bottomBoundry, int t } for (int i = m_mapBarBottom; i <= m_mapBarTop; i++) { - QBarSet* barSet = new QBarSet(QString("Row: %1").arg(i + 1)); + QBarSet* barSet = new QBarSet(m_model->headerData(i, Qt::Vertical, Qt::DisplayRole).toString()); for(int m = 0; m < m_model->columnCount(); m++) *barSet << m_model->data(m_model->index(i, m), Qt::DisplayRole).toDouble(); q->appendBarSet(barSet); diff --git a/src/barchart/qbarseries_p.h b/src/barchart/qbarseries_p.h index c480773..a658c6b 100644 --- a/src/barchart/qbarseries_p.h +++ b/src/barchart/qbarseries_p.h @@ -48,7 +48,6 @@ protected: QList m_barSets; QBarCategories m_categories; - QAbstractItemModel* m_model; int m_mapCategories; int m_mapBarBottom; int m_mapBarTop; diff --git a/test/tablemodelchart/tablewidget.cpp b/test/tablemodelchart/tablewidget.cpp index 28f6e5a..1aa9b11 100644 --- a/test/tablemodelchart/tablewidget.cpp +++ b/test/tablemodelchart/tablewidget.cpp @@ -51,6 +51,7 @@ TableWidget::TableWidget(QWidget *parent) // tableView->setMinimumSize(340, 480); // tableView->setItemDelegate(new QStyledItemDelegate); m_chart = new QChart; + m_chart->legend()->setVisible(true); m_chartView = new QChartView(m_chart); m_chartView->setRenderHint(QPainter::Antialiasing); m_chartView->setMinimumSize(640, 480); @@ -139,7 +140,9 @@ void TableWidget::updateChartType(bool toggle) // this if is needed, so that the function is only called once. // For the radioButton that was enabled. if (toggle) { - m_chart->removeAllSeries(); + m_chart->removeAllSeries(); + m_chart->axisX()->setNiceNumbersEnabled(false); + m_chart->axisY()->setNiceNumbersEnabled(false); // renable axes of the chart (pie hides them) // x axis @@ -321,8 +324,10 @@ void TableWidget::updateChartType(bool toggle) } - m_chart->axisX()->setRange(0, 500); + if (!m_barRadioButton->isChecked()) + m_chart->axisX()->setRange(0, 500); m_chart->axisY()->setRange(0, 120); + m_chart->legend()->setVisible(true); // repaint table view colors m_tableView->repaint();