From 4756f59398b83f1a9a781ec06d2d42f0b8462503 2012-03-20 11:02:01 From: Tero Ahola Date: 2012-03-20 11:02:01 Subject: [PATCH] Bar series to use theme base colors. Pie brush minor fix. Also fixed pen of bar series and stacked bar series. --- diff --git a/demos/chartthemes/main.cpp b/demos/chartthemes/main.cpp index 645b884..6739818 100644 --- a/demos/chartthemes/main.cpp +++ b/demos/chartthemes/main.cpp @@ -4,7 +4,9 @@ #include #include #include +#include #include +#include #include #include #include @@ -106,7 +108,9 @@ public: // TODO: categories for (int i(0); i < valueCount; i++) categories << QString::number(i); - QPercentBarSeries* series = new QPercentBarSeries(categories, chart); +// QBarSeries* series = new QBarSeries(categories, chart); +// QPercentBarSeries* series = new QPercentBarSeries(categories, chart); + QStackedBarSeries* series = new QStackedBarSeries(categories, chart); for (int i(0); i < m_dataTable.count(); i++) { QBarSet *set = new QBarSet("Set" + QString::number(i)); foreach (Data data, m_dataTable[i]) diff --git a/src/barchart/barpresenter.cpp b/src/barchart/barpresenter.cpp index 661a332..340b4ae 100644 --- a/src/barchart/barpresenter.cpp +++ b/src/barchart/barpresenter.cpp @@ -48,6 +48,7 @@ void BarPresenter::layoutChanged() // TODO: width settable per bar? bar->resize(mBarWidth, barHeight); + bar->setPen(mSeries->barsetAt(set)->pen()); bar->setBrush(mSeries->barsetAt(set)->brush()); bar->setPos(xPos, yPos-barHeight); itemIndex++; diff --git a/src/barchart/stackedbarpresenter.cpp b/src/barchart/stackedbarpresenter.cpp index 47f99b0..f498146 100644 --- a/src/barchart/stackedbarpresenter.cpp +++ b/src/barchart/stackedbarpresenter.cpp @@ -56,6 +56,7 @@ void StackedBarPresenter::layoutChanged() Bar* bar = mBars.at(itemIndex); bar->resize(mBarWidth, barHeight); + bar->setPen(mSeries->barsetAt(set)->pen()); bar->setBrush(mSeries->barsetAt(set)->brush()); bar->setPos(xPos, yPos-barHeight); itemIndex++; diff --git a/src/charttheme.cpp b/src/charttheme.cpp index fce80a2..a99eb07 100644 --- a/src/charttheme.cpp +++ b/src/charttheme.cpp @@ -150,19 +150,32 @@ void ChartTheme::decorate(QBarSeries* series, int index, bool force) QPen pen; QList sets = series->barSets(); - for (int i(0); i < sets.count(); i++) { - qreal pos = 0.5; - if (sets.count() > 1) - pos = (qreal) i / (qreal) (sets.count() - 1); + qreal takeAtPos = 0.5; + qreal step = 0.2; + if (sets.count() > 1 ) { + step = 1.0 / (qreal) sets.count(); + if (sets.count() % m_seriesGradients.count()) + step *= m_seriesGradients.count(); + else + step *= (m_seriesGradients.count() - 1); + } - if (brush == sets.at(i)->brush() || force ) { - QColor c = colorAt(m_seriesGradients.at(index % m_seriesGradients.size()), pos); - sets.at(i)->setBrush(QBrush(c)); + for (int i(0); i < sets.count(); i++) { + int colorIndex = (index + i) % m_seriesGradients.count(); + if (i > 0 && i % m_seriesGradients.count() == 0) { + // There is no dedicated base color for each sets, generate more colors + takeAtPos += step; + if (takeAtPos == 1.0) + takeAtPos += step; + takeAtPos -= (int) takeAtPos; } + qDebug() << "pos:" << takeAtPos; + if (brush == sets.at(i)->brush() || force ) + sets.at(i)->setBrush(colorAt(m_seriesGradients.at(colorIndex), takeAtPos)); // Pick label color from the opposite end of the gradient. // 0.3 as a boundary seems to work well. - if (pos < 0.3) + if (takeAtPos < 0.3) sets.at(i)->setFloatingValuePen(colorAt(m_seriesGradients.at(index % m_seriesGradients.size()), 1)); else sets.at(i)->setFloatingValuePen(colorAt(m_seriesGradients.at(index % m_seriesGradients.size()), 0)); @@ -203,7 +216,7 @@ void ChartTheme::decorate(QPieSeries* series, int index, bool force) } // Get color for a slice from a gradient linearly, beginning from the start of the gradient - qreal pos = (qreal) i / (qreal) series->count(); + qreal pos = (qreal) (i + 1) / (qreal) series->count(); if (brush == series->slices().at(i)->sliceBrush() || force) { QColor brushColor = colorAt(m_seriesGradients.at(index % m_seriesGradients.size()), pos); series->slices().at(i)->setSliceBrush(brushColor); diff --git a/test/chartwidgettest/dataseriedialog.cpp b/test/chartwidgettest/dataseriedialog.cpp index 4d2f2eb..9a8cdab 100644 --- a/test/chartwidgettest/dataseriedialog.cpp +++ b/test/chartwidgettest/dataseriedialog.cpp @@ -67,7 +67,9 @@ QGroupBox *DataSerieDialog::columnCountSelector() layout->addWidget(radio); layout->addWidget(new QRadioButton("2")); layout->addWidget(new QRadioButton("3")); + layout->addWidget(new QRadioButton("4")); layout->addWidget(new QRadioButton("5")); + layout->addWidget(new QRadioButton("8")); layout->addWidget(new QRadioButton("10")); layout->addWidget(new QRadioButton("100")); @@ -89,6 +91,7 @@ QGroupBox *DataSerieDialog::rowCountSelector() layout->addWidget(new QRadioButton("50")); layout->addWidget(new QRadioButton("100")); layout->addWidget(new QRadioButton("10000")); + layout->addWidget(new QRadioButton("100000")); layout->addWidget(new QRadioButton("1000000")); QGroupBox *groupBox = new QGroupBox("Row count");