##// END OF EJS Templates
Bar series to use theme base colors. Pie brush minor fix....
Tero Ahola -
r661:4756f59398b8
parent child
Show More
@@ -4,7 +4,9
4 #include <qchartview.h>
4 #include <qchartview.h>
5 #include <qpieseries.h>
5 #include <qpieseries.h>
6 #include <qpieslice.h>
6 #include <qpieslice.h>
7 #include <qbarseries.h>
7 #include <qpercentbarseries.h>
8 #include <qpercentbarseries.h>
9 #include <qstackedbarseries.h>
8 #include <qbarset.h>
10 #include <qbarset.h>
9 #include <QGridLayout>
11 #include <QGridLayout>
10 #include <QFormLayout>
12 #include <QFormLayout>
@@ -106,7 +108,9 public:
106 // TODO: categories
108 // TODO: categories
107 for (int i(0); i < valueCount; i++)
109 for (int i(0); i < valueCount; i++)
108 categories << QString::number(i);
110 categories << QString::number(i);
109 QPercentBarSeries* series = new QPercentBarSeries(categories, chart);
111 // QBarSeries* series = new QBarSeries(categories, chart);
112 // QPercentBarSeries* series = new QPercentBarSeries(categories, chart);
113 QStackedBarSeries* series = new QStackedBarSeries(categories, chart);
110 for (int i(0); i < m_dataTable.count(); i++) {
114 for (int i(0); i < m_dataTable.count(); i++) {
111 QBarSet *set = new QBarSet("Set" + QString::number(i));
115 QBarSet *set = new QBarSet("Set" + QString::number(i));
112 foreach (Data data, m_dataTable[i])
116 foreach (Data data, m_dataTable[i])
@@ -48,6 +48,7 void BarPresenter::layoutChanged()
48
48
49 // TODO: width settable per bar?
49 // TODO: width settable per bar?
50 bar->resize(mBarWidth, barHeight);
50 bar->resize(mBarWidth, barHeight);
51 bar->setPen(mSeries->barsetAt(set)->pen());
51 bar->setBrush(mSeries->barsetAt(set)->brush());
52 bar->setBrush(mSeries->barsetAt(set)->brush());
52 bar->setPos(xPos, yPos-barHeight);
53 bar->setPos(xPos, yPos-barHeight);
53 itemIndex++;
54 itemIndex++;
@@ -56,6 +56,7 void StackedBarPresenter::layoutChanged()
56 Bar* bar = mBars.at(itemIndex);
56 Bar* bar = mBars.at(itemIndex);
57
57
58 bar->resize(mBarWidth, barHeight);
58 bar->resize(mBarWidth, barHeight);
59 bar->setPen(mSeries->barsetAt(set)->pen());
59 bar->setBrush(mSeries->barsetAt(set)->brush());
60 bar->setBrush(mSeries->barsetAt(set)->brush());
60 bar->setPos(xPos, yPos-barHeight);
61 bar->setPos(xPos, yPos-barHeight);
61 itemIndex++;
62 itemIndex++;
@@ -150,19 +150,32 void ChartTheme::decorate(QBarSeries* series, int index, bool force)
150 QPen pen;
150 QPen pen;
151 QList<QBarSet*> sets = series->barSets();
151 QList<QBarSet*> sets = series->barSets();
152
152
153 for (int i(0); i < sets.count(); i++) {
153 qreal takeAtPos = 0.5;
154 qreal pos = 0.5;
154 qreal step = 0.2;
155 if (sets.count() > 1)
155 if (sets.count() > 1 ) {
156 pos = (qreal) i / (qreal) (sets.count() - 1);
156 step = 1.0 / (qreal) sets.count();
157 if (sets.count() % m_seriesGradients.count())
158 step *= m_seriesGradients.count();
159 else
160 step *= (m_seriesGradients.count() - 1);
161 }
157
162
158 if (brush == sets.at(i)->brush() || force ) {
163 for (int i(0); i < sets.count(); i++) {
159 QColor c = colorAt(m_seriesGradients.at(index % m_seriesGradients.size()), pos);
164 int colorIndex = (index + i) % m_seriesGradients.count();
160 sets.at(i)->setBrush(QBrush(c));
165 if (i > 0 && i % m_seriesGradients.count() == 0) {
166 // There is no dedicated base color for each sets, generate more colors
167 takeAtPos += step;
168 if (takeAtPos == 1.0)
169 takeAtPos += step;
170 takeAtPos -= (int) takeAtPos;
161 }
171 }
172 qDebug() << "pos:" << takeAtPos;
173 if (brush == sets.at(i)->brush() || force )
174 sets.at(i)->setBrush(colorAt(m_seriesGradients.at(colorIndex), takeAtPos));
162
175
163 // Pick label color from the opposite end of the gradient.
176 // Pick label color from the opposite end of the gradient.
164 // 0.3 as a boundary seems to work well.
177 // 0.3 as a boundary seems to work well.
165 if (pos < 0.3)
178 if (takeAtPos < 0.3)
166 sets.at(i)->setFloatingValuePen(colorAt(m_seriesGradients.at(index % m_seriesGradients.size()), 1));
179 sets.at(i)->setFloatingValuePen(colorAt(m_seriesGradients.at(index % m_seriesGradients.size()), 1));
167 else
180 else
168 sets.at(i)->setFloatingValuePen(colorAt(m_seriesGradients.at(index % m_seriesGradients.size()), 0));
181 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)
203 }
216 }
204
217
205 // Get color for a slice from a gradient linearly, beginning from the start of the gradient
218 // Get color for a slice from a gradient linearly, beginning from the start of the gradient
206 qreal pos = (qreal) i / (qreal) series->count();
219 qreal pos = (qreal) (i + 1) / (qreal) series->count();
207 if (brush == series->slices().at(i)->sliceBrush() || force) {
220 if (brush == series->slices().at(i)->sliceBrush() || force) {
208 QColor brushColor = colorAt(m_seriesGradients.at(index % m_seriesGradients.size()), pos);
221 QColor brushColor = colorAt(m_seriesGradients.at(index % m_seriesGradients.size()), pos);
209 series->slices().at(i)->setSliceBrush(brushColor);
222 series->slices().at(i)->setSliceBrush(brushColor);
@@ -67,7 +67,9 QGroupBox *DataSerieDialog::columnCountSelector()
67 layout->addWidget(radio);
67 layout->addWidget(radio);
68 layout->addWidget(new QRadioButton("2"));
68 layout->addWidget(new QRadioButton("2"));
69 layout->addWidget(new QRadioButton("3"));
69 layout->addWidget(new QRadioButton("3"));
70 layout->addWidget(new QRadioButton("4"));
70 layout->addWidget(new QRadioButton("5"));
71 layout->addWidget(new QRadioButton("5"));
72 layout->addWidget(new QRadioButton("8"));
71 layout->addWidget(new QRadioButton("10"));
73 layout->addWidget(new QRadioButton("10"));
72 layout->addWidget(new QRadioButton("100"));
74 layout->addWidget(new QRadioButton("100"));
73
75
@@ -89,6 +91,7 QGroupBox *DataSerieDialog::rowCountSelector()
89 layout->addWidget(new QRadioButton("50"));
91 layout->addWidget(new QRadioButton("50"));
90 layout->addWidget(new QRadioButton("100"));
92 layout->addWidget(new QRadioButton("100"));
91 layout->addWidget(new QRadioButton("10000"));
93 layout->addWidget(new QRadioButton("10000"));
94 layout->addWidget(new QRadioButton("100000"));
92 layout->addWidget(new QRadioButton("1000000"));
95 layout->addWidget(new QRadioButton("1000000"));
93
96
94 QGroupBox *groupBox = new QGroupBox("Row count");
97 QGroupBox *groupBox = new QGroupBox("Row count");
General Comments 0
You need to be logged in to leave comments. Login now