##// END OF EJS Templates
Pie pen now uses gradient start color
Tero Ahola -
r510:abde8123ae71
parent child
Show More
@@ -1,331 +1,332
1 #include "charttheme_p.h"
1 #include "charttheme_p.h"
2 #include "qchart.h"
2 #include "qchart.h"
3 #include "qchartaxis.h"
3 #include "qchartaxis.h"
4 #include <QTime>
4 #include <QTime>
5
5
6 //series
6 //series
7 #include "qbarset.h"
7 #include "qbarset.h"
8 #include "qbarseries.h"
8 #include "qbarseries.h"
9 #include "qstackedbarseries.h"
9 #include "qstackedbarseries.h"
10 #include "qpercentbarseries.h"
10 #include "qpercentbarseries.h"
11 #include "qlineseries.h"
11 #include "qlineseries.h"
12 #include "qareaseries.h"
12 #include "qareaseries.h"
13 #include "qscatterseries.h"
13 #include "qscatterseries.h"
14 #include "qpieseries.h"
14 #include "qpieseries.h"
15 #include "qpieslice.h"
15 #include "qpieslice.h"
16 #include "qsplineseries.h"
16 #include "qsplineseries.h"
17
17
18 //items
18 //items
19 #include "axisitem_p.h"
19 #include "axisitem_p.h"
20 #include "barpresenter_p.h"
20 #include "barpresenter_p.h"
21 #include "stackedbarpresenter_p.h"
21 #include "stackedbarpresenter_p.h"
22 #include "percentbarpresenter_p.h"
22 #include "percentbarpresenter_p.h"
23 #include "linechartitem_p.h"
23 #include "linechartitem_p.h"
24 #include "areachartitem_p.h"
24 #include "areachartitem_p.h"
25 #include "scatterchartitem_p.h"
25 #include "scatterchartitem_p.h"
26 #include "piepresenter_p.h"
26 #include "piepresenter_p.h"
27 #include "splinechartitem_p.h"
27 #include "splinechartitem_p.h"
28
28
29 //themes
29 //themes
30 #include "chartthemedefault_p.h"
30 #include "chartthemedefault_p.h"
31 #include "chartthemevanilla_p.h"
31 #include "chartthemevanilla_p.h"
32 #include "chartthemeicy_p.h"
32 #include "chartthemeicy_p.h"
33 #include "chartthemegrayscale_p.h"
33 #include "chartthemegrayscale_p.h"
34 #include "chartthemescientific_p.h"
34 #include "chartthemescientific_p.h"
35
35
36
36
37 QTCOMMERCIALCHART_BEGIN_NAMESPACE
37 QTCOMMERCIALCHART_BEGIN_NAMESPACE
38
38
39 ChartTheme::ChartTheme(QChart::ChartTheme id)
39 ChartTheme::ChartTheme(QChart::ChartTheme id)
40 {
40 {
41 m_id = id;
41 m_id = id;
42 qsrand(QTime(0,0,0).secsTo(QTime::currentTime()));
42 qsrand(QTime(0,0,0).secsTo(QTime::currentTime()));
43 }
43 }
44
44
45
45
46 ChartTheme* ChartTheme::createTheme(QChart::ChartTheme theme)
46 ChartTheme* ChartTheme::createTheme(QChart::ChartTheme theme)
47 {
47 {
48 switch(theme) {
48 switch(theme) {
49 case QChart::ChartThemeVanilla:
49 case QChart::ChartThemeVanilla:
50 return new ChartThemeVanilla();
50 return new ChartThemeVanilla();
51 case QChart::ChartThemeIcy:
51 case QChart::ChartThemeIcy:
52 return new ChartThemeIcy();
52 return new ChartThemeIcy();
53 case QChart::ChartThemeGrayscale:
53 case QChart::ChartThemeGrayscale:
54 return new ChartThemeGrayscale();
54 return new ChartThemeGrayscale();
55 case QChart::ChartThemeScientific:
55 case QChart::ChartThemeScientific:
56 return new ChartThemeScientific();
56 return new ChartThemeScientific();
57 default:
57 default:
58 return new ChartThemeDefault();
58 return new ChartThemeDefault();
59 }
59 }
60 }
60 }
61
61
62 void ChartTheme::decorate(QChart* chart)
62 void ChartTheme::decorate(QChart* chart)
63 {
63 {
64 chart->setChartBackgroundBrush(m_backgroundGradient);
64 chart->setChartBackgroundBrush(m_backgroundGradient);
65 }
65 }
66 //TODO helper to by removed later
66 //TODO helper to by removed later
67 void ChartTheme::decorate(ChartItem* item, QSeries* series,int count)
67 void ChartTheme::decorate(ChartItem* item, QSeries* series,int count)
68 {
68 {
69 switch(series->type())
69 switch(series->type())
70 {
70 {
71 case QSeries::SeriesTypeLine: {
71 case QSeries::SeriesTypeLine: {
72 QLineSeries* s = static_cast<QLineSeries*>(series);
72 QLineSeries* s = static_cast<QLineSeries*>(series);
73 LineChartItem* i = static_cast<LineChartItem*>(item);
73 LineChartItem* i = static_cast<LineChartItem*>(item);
74 decorate(i,s,count);
74 decorate(i,s,count);
75 break;
75 break;
76 }
76 }
77 case QSeries::SeriesTypeArea: {
77 case QSeries::SeriesTypeArea: {
78 QAreaSeries* s = static_cast<QAreaSeries*>(series);
78 QAreaSeries* s = static_cast<QAreaSeries*>(series);
79 AreaChartItem* i = static_cast<AreaChartItem*>(item);
79 AreaChartItem* i = static_cast<AreaChartItem*>(item);
80 decorate(i,s,count);
80 decorate(i,s,count);
81 break;
81 break;
82 }
82 }
83 case QSeries::SeriesTypeBar: {
83 case QSeries::SeriesTypeBar: {
84 QBarSeries* b = static_cast<QBarSeries*>(series);
84 QBarSeries* b = static_cast<QBarSeries*>(series);
85 BarPresenter* i = static_cast<BarPresenter*>(item);
85 BarPresenter* i = static_cast<BarPresenter*>(item);
86 decorate(i,b,count);
86 decorate(i,b,count);
87 break;
87 break;
88 }
88 }
89 case QSeries::SeriesTypeStackedBar: {
89 case QSeries::SeriesTypeStackedBar: {
90 QStackedBarSeries* s = static_cast<QStackedBarSeries*>(series);
90 QStackedBarSeries* s = static_cast<QStackedBarSeries*>(series);
91 StackedBarPresenter* i = static_cast<StackedBarPresenter*>(item);
91 StackedBarPresenter* i = static_cast<StackedBarPresenter*>(item);
92 decorate(i,s,count);
92 decorate(i,s,count);
93 break;
93 break;
94 }
94 }
95 case QSeries::SeriesTypePercentBar: {
95 case QSeries::SeriesTypePercentBar: {
96 QPercentBarSeries* s = static_cast<QPercentBarSeries*>(series);
96 QPercentBarSeries* s = static_cast<QPercentBarSeries*>(series);
97 PercentBarPresenter* i = static_cast<PercentBarPresenter*>(item);
97 PercentBarPresenter* i = static_cast<PercentBarPresenter*>(item);
98 decorate(i,s,count);
98 decorate(i,s,count);
99 break;
99 break;
100 }
100 }
101 case QSeries::SeriesTypeScatter: {
101 case QSeries::SeriesTypeScatter: {
102 QScatterSeries* s = qobject_cast<QScatterSeries*>(series);
102 QScatterSeries* s = qobject_cast<QScatterSeries*>(series);
103 Q_ASSERT(s);
103 Q_ASSERT(s);
104 ScatterChartItem* i = static_cast<ScatterChartItem*>(item);
104 ScatterChartItem* i = static_cast<ScatterChartItem*>(item);
105 Q_ASSERT(i);
105 Q_ASSERT(i);
106 decorate(i, s, count);
106 decorate(i, s, count);
107 break;
107 break;
108 }
108 }
109 case QSeries::SeriesTypePie: {
109 case QSeries::SeriesTypePie: {
110 QPieSeries* s = static_cast<QPieSeries*>(series);
110 QPieSeries* s = static_cast<QPieSeries*>(series);
111 PiePresenter* i = static_cast<PiePresenter*>(item);
111 PiePresenter* i = static_cast<PiePresenter*>(item);
112 decorate(i,s,count);
112 decorate(i,s,count);
113 break;
113 break;
114 }
114 }
115 default:
115 default:
116 qDebug()<<"Wrong item to be decorated by theme";
116 qDebug()<<"Wrong item to be decorated by theme";
117 break;
117 break;
118 }
118 }
119
119
120 }
120 }
121
121
122 void ChartTheme::decorate(AreaChartItem* item, QAreaSeries* series,int count)
122 void ChartTheme::decorate(AreaChartItem* item, QAreaSeries* series,int count)
123 {
123 {
124 QPen pen;
124 QPen pen;
125 QBrush brush;
125 QBrush brush;
126
126
127 if(pen != series->pen()){
127 if(pen != series->pen()){
128 item->setPen(series->pen());
128 item->setPen(series->pen());
129 }else{
129 }else{
130 pen.setColor(m_seriesColors.at(count%m_seriesColors.size()));
130 pen.setColor(m_seriesColors.at(count%m_seriesColors.size()));
131 pen.setWidthF(2);
131 pen.setWidthF(2);
132 item->setPen(pen);
132 item->setPen(pen);
133 }
133 }
134
134
135 if(brush != series->brush()){
135 if(brush != series->brush()){
136 item->setBrush(series->brush());
136 item->setBrush(series->brush());
137 }else{
137 }else{
138 QBrush brush(m_seriesColors.at(count%m_seriesColors.size()));
138 QBrush brush(m_seriesColors.at(count%m_seriesColors.size()));
139 item->setBrush(brush);
139 item->setBrush(brush);
140 }
140 }
141 }
141 }
142
142
143
143
144 void ChartTheme::decorate(LineChartItem* item, QLineSeries* series,int count)
144 void ChartTheme::decorate(LineChartItem* item, QLineSeries* series,int count)
145 {
145 {
146 QPen pen;
146 QPen pen;
147 if(pen != series->pen()){
147 if(pen != series->pen()){
148 item->setLinePen(series->pen());
148 item->setLinePen(series->pen());
149 return;
149 return;
150 }
150 }
151 pen.setColor(m_seriesColors.at(count%m_seriesColors.size()));
151 pen.setColor(m_seriesColors.at(count%m_seriesColors.size()));
152 pen.setWidthF(2);
152 pen.setWidthF(2);
153 item->setLinePen(pen);
153 item->setLinePen(pen);
154 }
154 }
155
155
156 void ChartTheme::decorate(BarPresenter* item, QBarSeries* series,int count)
156 void ChartTheme::decorate(BarPresenter* item, QBarSeries* series,int count)
157 {
157 {
158 QList<QBarSet*> sets = series->barSets();
158 QList<QBarSet*> sets = series->barSets();
159 for (int i=0; i<sets.count(); i++) {
159 for (int i=0; i<sets.count(); i++) {
160 qreal pos = (qreal) i / (qreal) sets.count();
160 qreal pos = (qreal) i / (qreal) sets.count();
161 QColor c = colorAt(m_seriesGradients.at(count % m_seriesGradients.size()), pos);
161 QColor c = colorAt(m_seriesGradients.at(count % m_seriesGradients.size()), pos);
162 sets.at(i)->setBrush(QBrush(c));
162 sets.at(i)->setBrush(QBrush(c));
163 }
163 }
164 }
164 }
165
165
166 void ChartTheme::decorate(StackedBarPresenter* item, QStackedBarSeries* series,int count)
166 void ChartTheme::decorate(StackedBarPresenter* item, QStackedBarSeries* series,int count)
167 {
167 {
168 QList<QBarSet*> sets = series->barSets();
168 QList<QBarSet*> sets = series->barSets();
169 for (int i=0; i<sets.count(); i++) {
169 for (int i=0; i<sets.count(); i++) {
170 qreal pos = (qreal) i / (qreal) sets.count();
170 qreal pos = (qreal) i / (qreal) sets.count();
171 QColor c = colorAt(m_seriesGradients.at(count % m_seriesGradients.size()), pos);
171 QColor c = colorAt(m_seriesGradients.at(count % m_seriesGradients.size()), pos);
172 sets.at(i)->setBrush(QBrush(c));
172 sets.at(i)->setBrush(QBrush(c));
173 }
173 }
174 }
174 }
175
175
176 void ChartTheme::decorate(PercentBarPresenter* item, QPercentBarSeries* series,int count)
176 void ChartTheme::decorate(PercentBarPresenter* item, QPercentBarSeries* series,int count)
177 {
177 {
178 QList<QBarSet*> sets = series->barSets();
178 QList<QBarSet*> sets = series->barSets();
179 for (int i=0; i<sets.count(); i++) {
179 for (int i=0; i<sets.count(); i++) {
180 qreal pos = (qreal) i / (qreal) sets.count();
180 qreal pos = (qreal) i / (qreal) sets.count();
181 QColor c = colorAt(m_seriesGradients.at(count % m_seriesGradients.size()), pos);
181 QColor c = colorAt(m_seriesGradients.at(count % m_seriesGradients.size()), pos);
182 sets.at(i)->setBrush(QBrush(c));
182 sets.at(i)->setBrush(QBrush(c));
183 }
183 }
184 }
184 }
185
185
186 void ChartTheme::decorate(ScatterChartItem* item, QScatterSeries* series, int count)
186 void ChartTheme::decorate(ScatterChartItem* item, QScatterSeries* series, int count)
187 {
187 {
188 Q_ASSERT(item);
188 Q_ASSERT(item);
189 Q_ASSERT(series);
189 Q_ASSERT(series);
190
190
191 QColor color = m_seriesColors.at(count % m_seriesColors.size());
191 QColor color = m_seriesColors.at(count % m_seriesColors.size());
192 // TODO: define alpha in the theme? or in the series?
192 // TODO: define alpha in the theme? or in the series?
193 //color.setAlpha(120);
193 //color.setAlpha(120);
194
194
195 QBrush brush(color, Qt::SolidPattern);
195 QBrush brush(color, Qt::SolidPattern);
196 item->setBrush(Qt::blue);
196 item->setBrush(Qt::blue);
197
197
198 QPen pen(brush, 3);
198 QPen pen(brush, 3);
199 pen.setColor(color);
199 pen.setColor(color);
200 item->setPen(pen);
200 item->setPen(pen);
201 }
201 }
202
202
203 void ChartTheme::decorate(PiePresenter* item, QPieSeries* series, int count)
203 void ChartTheme::decorate(PiePresenter* item, QPieSeries* series, int count)
204 {
204 {
205 // Get color for a slice from a gradient linearly, beginning from the start of the gradient
205 // Get color for a slice from a gradient linearly, beginning from the start of the gradient
206 for (int i(0); i < series->slices().count(); i++) {
206 for (int i(0); i < series->slices().count(); i++) {
207 qreal pos = (qreal) i / (qreal) series->count();
207 qreal pos = (qreal) i / (qreal) series->count();
208 QColor c = colorAt(m_seriesGradients.at(count % m_seriesGradients.size()), pos);
208 QColor penColor = colorAt(m_seriesGradients.at(count % m_seriesGradients.size()), 0.1);
209 series->slices().at(i)->setSlicePen(c);
209 series->slices().at(i)->setSlicePen(penColor);
210 series->slices().at(i)->setSliceBrush(c);
210 QColor brushColor = colorAt(m_seriesGradients.at(count % m_seriesGradients.size()), pos);
211 series->slices().at(i)->setSliceBrush(brushColor);
211 }
212 }
212 }
213 }
213
214
214
215
215 void ChartTheme::decorate(QChartAxis* axis, AxisItem* item)
216 void ChartTheme::decorate(QChartAxis* axis, AxisItem* item)
216 {
217 {
217 //TODO: dummy defults for now
218 //TODO: dummy defults for now
218 axis->setLabelsBrush(Qt::black);
219 axis->setLabelsBrush(Qt::black);
219 axis->setLabelsPen(Qt::NoPen);
220 axis->setLabelsPen(Qt::NoPen);
220 axis->setShadesPen(Qt::NoPen);
221 axis->setShadesPen(Qt::NoPen);
221 axis->setShadesOpacity(0.5);
222 axis->setShadesOpacity(0.5);
222 }
223 }
223
224
224 void ChartTheme::decorate(SplineChartItem* item, QSplineSeries* series, int count)
225 void ChartTheme::decorate(SplineChartItem* item, QSplineSeries* series, int count)
225 {
226 {
226 Q_ASSERT(item);
227 Q_ASSERT(item);
227 Q_ASSERT(series);
228 Q_ASSERT(series);
228
229
229 QPen pen;
230 QPen pen;
230
231
231 if(pen != series->pen()){
232 if(pen != series->pen()){
232 item->setLinePen(series->pen());
233 item->setLinePen(series->pen());
233 }else{
234 }else{
234 pen.setColor(m_seriesColors.at(count%m_seriesColors.size()));
235 pen.setColor(m_seriesColors.at(count%m_seriesColors.size()));
235 pen.setWidthF(series->pen().widthF());
236 pen.setWidthF(series->pen().widthF());
236 item->setLinePen(series->pen());
237 item->setLinePen(series->pen());
237 }
238 }
238
239
239 // QColor color = m_seriesColors.at(count % m_seriesColors.size());
240 // QColor color = m_seriesColors.at(count % m_seriesColors.size());
240 // TODO: define alpha in the theme? or in the series?
241 // TODO: define alpha in the theme? or in the series?
241 //color.setAlpha(120);
242 //color.setAlpha(120);
242
243
243 // QBrush brush(color, Qt::SolidPattern);
244 // QBrush brush(color, Qt::SolidPattern);
244 // presenter->m_markerBrush = brush;
245 // presenter->m_markerBrush = brush;
245
246
246 // QPen pen(brush, 3);
247 // QPen pen(brush, 3);
247 // pen.setColor(color);
248 // pen.setColor(color);
248 // presenter->m_markerPen = pen;
249 // presenter->m_markerPen = pen;
249 }
250 }
250
251
251 void ChartTheme::generateSeriesGradients()
252 void ChartTheme::generateSeriesGradients()
252 {
253 {
253 // Generate gradients in HSV color space
254 // Generate gradients in HSV color space
254 foreach (QColor color, m_seriesColors) {
255 foreach (QColor color, m_seriesColors) {
255 QLinearGradient g;
256 QLinearGradient g;
256 qreal h = color.hsvHueF();
257 qreal h = color.hsvHueF();
257 qreal s = color.hsvSaturationF();
258 qreal s = color.hsvSaturationF();
258
259
259 // TODO: tune the algorithm to give nice results with most base colors defined in
260 // TODO: tune the algorithm to give nice results with most base colors defined in
260 // most themes. The rest of the gradients we can define manually in theme specific
261 // most themes. The rest of the gradients we can define manually in theme specific
261 // implementation.
262 // implementation.
262 QColor start = color;
263 QColor start = color;
263 start.setHsvF(h, 0.05, 0.95);
264 start.setHsvF(h, 0.05, 0.95);
264 g.setColorAt(0.0, start);
265 g.setColorAt(0.0, start);
265
266
266 g.setColorAt(0.5, color);
267 g.setColorAt(0.5, color);
267
268
268 QColor end = color;
269 QColor end = color;
269 end.setHsvF(h, s, 0.25);
270 end.setHsvF(h, s, 0.25);
270 g.setColorAt(1.0, end);
271 g.setColorAt(1.0, end);
271
272
272 m_seriesGradients << g;
273 m_seriesGradients << g;
273 }
274 }
274 }
275 }
275
276
276
277
277 QColor ChartTheme::colorAt(const QColor &start, const QColor &end, qreal pos)
278 QColor ChartTheme::colorAt(const QColor &start, const QColor &end, qreal pos)
278 {
279 {
279 Q_ASSERT(pos >=0.0 && pos <= 1.0);
280 Q_ASSERT(pos >=0.0 && pos <= 1.0);
280 qreal r = start.redF() + ((end.redF() - start.redF()) * pos);
281 qreal r = start.redF() + ((end.redF() - start.redF()) * pos);
281 qreal g = start.greenF() + ((end.greenF() - start.greenF()) * pos);
282 qreal g = start.greenF() + ((end.greenF() - start.greenF()) * pos);
282 qreal b = start.blueF() + ((end.blueF() - start.blueF()) * pos);
283 qreal b = start.blueF() + ((end.blueF() - start.blueF()) * pos);
283 QColor c;
284 QColor c;
284 c.setRgbF(r, g, b);
285 c.setRgbF(r, g, b);
285 return c;
286 return c;
286 }
287 }
287
288
288 QColor ChartTheme::colorAt(const QGradient &gradient, qreal pos)
289 QColor ChartTheme::colorAt(const QGradient &gradient, qreal pos)
289 {
290 {
290 Q_ASSERT(pos >=0 && pos <= 1.0);
291 Q_ASSERT(pos >=0 && pos <= 1.0);
291
292
292 // another possibility:
293 // another possibility:
293 // http://stackoverflow.com/questions/3306786/get-intermediate-color-from-a-gradient
294 // http://stackoverflow.com/questions/3306786/get-intermediate-color-from-a-gradient
294
295
295 QGradientStops stops = gradient.stops();
296 QGradientStops stops = gradient.stops();
296 int count = stops.count();
297 int count = stops.count();
297
298
298 // find previous stop relative to position
299 // find previous stop relative to position
299 QGradientStop prev = stops.first();
300 QGradientStop prev = stops.first();
300 for (int i=0; i<count; i++) {
301 for (int i=0; i<count; i++) {
301 QGradientStop stop = stops.at(i);
302 QGradientStop stop = stops.at(i);
302 if (pos > stop.first)
303 if (pos > stop.first)
303 prev = stop;
304 prev = stop;
304
305
305 // given position is actually a stop position?
306 // given position is actually a stop position?
306 if (pos == stop.first) {
307 if (pos == stop.first) {
307 //qDebug() << "stop color" << pos;
308 //qDebug() << "stop color" << pos;
308 return stop.second;
309 return stop.second;
309 }
310 }
310 }
311 }
311
312
312 // find next stop relative to position
313 // find next stop relative to position
313 QGradientStop next = stops.last();
314 QGradientStop next = stops.last();
314 for (int i=count-1; i>=0; i--) {
315 for (int i=count-1; i>=0; i--) {
315 QGradientStop stop = stops.at(i);
316 QGradientStop stop = stops.at(i);
316 if (pos < stop.first)
317 if (pos < stop.first)
317 next = stop;
318 next = stop;
318 }
319 }
319
320
320 //qDebug() << "prev" << prev.first << "pos" << pos << "next" << next.first;
321 //qDebug() << "prev" << prev.first << "pos" << pos << "next" << next.first;
321
322
322 qreal range = next.first - prev.first;
323 qreal range = next.first - prev.first;
323 qreal posDelta = pos - prev.first;
324 qreal posDelta = pos - prev.first;
324 qreal relativePos = posDelta / range;
325 qreal relativePos = posDelta / range;
325
326
326 //qDebug() << "range" << range << "posDelta" << posDelta << "relativePos" << relativePos;
327 //qDebug() << "range" << range << "posDelta" << posDelta << "relativePos" << relativePos;
327
328
328 return colorAt(prev.second, next.second, relativePos);
329 return colorAt(prev.second, next.second, relativePos);
329 }
330 }
330
331
331 QTCOMMERCIALCHART_END_NAMESPACE
332 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,369 +1,369
1 #include "mainwidget.h"
1 #include "mainwidget.h"
2 #include "dataseriedialog.h"
2 #include "dataseriedialog.h"
3 #include <qpieseries.h>
3 #include <qpieseries.h>
4 #include <qscatterseries.h>
4 #include <qscatterseries.h>
5 #include <qlineseries.h>
5 #include <qlineseries.h>
6 #include <qareaseries.h>
6 #include <qareaseries.h>
7 #include <qsplineseries.h>
7 #include <qsplineseries.h>
8 #include <qbarset.h>
8 #include <qbarset.h>
9 #include <qbarseries.h>
9 #include <qbarseries.h>
10 #include <qstackedbarseries.h>
10 #include <qstackedbarseries.h>
11 #include <qpercentbarseries.h>
11 #include <qpercentbarseries.h>
12 #include <QPushButton>
12 #include <QPushButton>
13 #include <QComboBox>
13 #include <QComboBox>
14 #include <QSpinBox>
14 #include <QSpinBox>
15 #include <QCheckBox>
15 #include <QCheckBox>
16 #include <QGridLayout>
16 #include <QGridLayout>
17 #include <QHBoxLayout>
17 #include <QHBoxLayout>
18 #include <QLabel>
18 #include <QLabel>
19 #include <QSpacerItem>
19 #include <QSpacerItem>
20 #include <QMessageBox>
20 #include <QMessageBox>
21 #include <cmath>
21 #include <cmath>
22 #include <QDebug>
22 #include <QDebug>
23 #include <QStandardItemModel>
23 #include <QStandardItemModel>
24
24
25
25
26 QTCOMMERCIALCHART_USE_NAMESPACE
26 QTCOMMERCIALCHART_USE_NAMESPACE
27
27
28 MainWidget::MainWidget(QWidget *parent) :
28 MainWidget::MainWidget(QWidget *parent) :
29 QWidget(parent),
29 QWidget(parent),
30 m_addSerieDialog(0),
30 m_addSerieDialog(0),
31 m_chartView(0)
31 m_chartView(0)
32 {
32 {
33 m_chartView = new QChartView(this);
33 m_chartView = new QChartView(this);
34 m_chartView->setRubberBandPolicy(QChartView::HorizonalRubberBand);
34 m_chartView->setRubberBandPolicy(QChartView::HorizonalRubberBand);
35
35
36 // Grid layout for the controls for configuring the chart widget
36 // Grid layout for the controls for configuring the chart widget
37 QGridLayout *grid = new QGridLayout();
37 QGridLayout *grid = new QGridLayout();
38 QPushButton *addSeriesButton = new QPushButton("Add series");
38 QPushButton *addSeriesButton = new QPushButton("Add series");
39 connect(addSeriesButton, SIGNAL(clicked()), this, SLOT(addSeries()));
39 connect(addSeriesButton, SIGNAL(clicked()), this, SLOT(addSeries()));
40 grid->addWidget(addSeriesButton, 0, 1);
40 grid->addWidget(addSeriesButton, 0, 1);
41 initBackroundCombo(grid);
41 initBackroundCombo(grid);
42 initScaleControls(grid);
42 initScaleControls(grid);
43 initThemeCombo(grid);
43 initThemeCombo(grid);
44 initCheckboxes(grid);
44 initCheckboxes(grid);
45
45
46 // add row with empty label to make all the other rows static
46 // add row with empty label to make all the other rows static
47 grid->addWidget(new QLabel(""), grid->rowCount(), 0);
47 grid->addWidget(new QLabel(""), grid->rowCount(), 0);
48 grid->setRowStretch(grid->rowCount() - 1, 1);
48 grid->setRowStretch(grid->rowCount() - 1, 1);
49
49
50 // Another grid layout as a main layout
50 // Another grid layout as a main layout
51 QGridLayout *mainLayout = new QGridLayout();
51 QGridLayout *mainLayout = new QGridLayout();
52 mainLayout->addLayout(grid, 0, 0);
52 mainLayout->addLayout(grid, 0, 0);
53
53
54 // Add layouts and the chart widget to the main layout
54 // Add layouts and the chart widget to the main layout
55 mainLayout->addWidget(m_chartView, 0, 1, 3, 1);
55 mainLayout->addWidget(m_chartView, 0, 1, 3, 1);
56 setLayout(mainLayout);
56 setLayout(mainLayout);
57 }
57 }
58
58
59 // Combo box for selecting the chart's background
59 // Combo box for selecting the chart's background
60 void MainWidget::initBackroundCombo(QGridLayout *grid)
60 void MainWidget::initBackroundCombo(QGridLayout *grid)
61 {
61 {
62 QComboBox *backgroundCombo = new QComboBox(this);
62 QComboBox *backgroundCombo = new QComboBox(this);
63 backgroundCombo->addItem("Color");
63 backgroundCombo->addItem("Color");
64 backgroundCombo->addItem("Gradient");
64 backgroundCombo->addItem("Gradient");
65 backgroundCombo->addItem("Image");
65 backgroundCombo->addItem("Image");
66 connect(backgroundCombo, SIGNAL(currentIndexChanged(int)),
66 connect(backgroundCombo, SIGNAL(currentIndexChanged(int)),
67 this, SLOT(backgroundChanged(int)));
67 this, SLOT(backgroundChanged(int)));
68
68
69 grid->addWidget(new QLabel("Background:"), grid->rowCount(), 0);
69 grid->addWidget(new QLabel("Background:"), grid->rowCount(), 0);
70 grid->addWidget(backgroundCombo, grid->rowCount() - 1, 1);
70 grid->addWidget(backgroundCombo, grid->rowCount() - 1, 1);
71 }
71 }
72
72
73 // Scale related controls (auto-scale vs. manual min-max values)
73 // Scale related controls (auto-scale vs. manual min-max values)
74 void MainWidget::initScaleControls(QGridLayout *grid)
74 void MainWidget::initScaleControls(QGridLayout *grid)
75 {
75 {
76 m_autoScaleCheck = new QCheckBox("Automatic scaling");
76 m_autoScaleCheck = new QCheckBox("Automatic scaling");
77 connect(m_autoScaleCheck, SIGNAL(stateChanged(int)), this, SLOT(autoScaleChanged(int)));
77 connect(m_autoScaleCheck, SIGNAL(stateChanged(int)), this, SLOT(autoScaleChanged(int)));
78 // Allow setting also non-sense values (like -2147483648 and 2147483647)
78 // Allow setting also non-sense values (like -2147483648 and 2147483647)
79 m_xMinSpin = new QSpinBox();
79 m_xMinSpin = new QSpinBox();
80 m_xMinSpin->setMinimum(INT_MIN);
80 m_xMinSpin->setMinimum(INT_MIN);
81 m_xMinSpin->setMaximum(INT_MAX);
81 m_xMinSpin->setMaximum(INT_MAX);
82 m_xMinSpin->setValue(0);
82 m_xMinSpin->setValue(0);
83 connect(m_xMinSpin, SIGNAL(valueChanged(int)), this, SLOT(xMinChanged(int)));
83 connect(m_xMinSpin, SIGNAL(valueChanged(int)), this, SLOT(xMinChanged(int)));
84 m_xMaxSpin = new QSpinBox();
84 m_xMaxSpin = new QSpinBox();
85 m_xMaxSpin->setMinimum(INT_MIN);
85 m_xMaxSpin->setMinimum(INT_MIN);
86 m_xMaxSpin->setMaximum(INT_MAX);
86 m_xMaxSpin->setMaximum(INT_MAX);
87 m_xMaxSpin->setValue(10);
87 m_xMaxSpin->setValue(10);
88 connect(m_xMaxSpin, SIGNAL(valueChanged(int)), this, SLOT(xMaxChanged(int)));
88 connect(m_xMaxSpin, SIGNAL(valueChanged(int)), this, SLOT(xMaxChanged(int)));
89 m_yMinSpin = new QSpinBox();
89 m_yMinSpin = new QSpinBox();
90 m_yMinSpin->setMinimum(INT_MIN);
90 m_yMinSpin->setMinimum(INT_MIN);
91 m_yMinSpin->setMaximum(INT_MAX);
91 m_yMinSpin->setMaximum(INT_MAX);
92 m_yMinSpin->setValue(0);
92 m_yMinSpin->setValue(0);
93 connect(m_yMinSpin, SIGNAL(valueChanged(int)), this, SLOT(yMinChanged(int)));
93 connect(m_yMinSpin, SIGNAL(valueChanged(int)), this, SLOT(yMinChanged(int)));
94 m_yMaxSpin = new QSpinBox();
94 m_yMaxSpin = new QSpinBox();
95 m_yMaxSpin->setMinimum(INT_MIN);
95 m_yMaxSpin->setMinimum(INT_MIN);
96 m_yMaxSpin->setMaximum(INT_MAX);
96 m_yMaxSpin->setMaximum(INT_MAX);
97 m_yMaxSpin->setValue(10);
97 m_yMaxSpin->setValue(10);
98 connect(m_yMaxSpin, SIGNAL(valueChanged(int)), this, SLOT(yMaxChanged(int)));
98 connect(m_yMaxSpin, SIGNAL(valueChanged(int)), this, SLOT(yMaxChanged(int)));
99
99
100 grid->addWidget(m_autoScaleCheck, grid->rowCount(), 0);
100 grid->addWidget(m_autoScaleCheck, grid->rowCount(), 0);
101 grid->addWidget(new QLabel("x min:"), grid->rowCount(), 0);
101 grid->addWidget(new QLabel("x min:"), grid->rowCount(), 0);
102 grid->addWidget(m_xMinSpin, grid->rowCount() - 1, 1);
102 grid->addWidget(m_xMinSpin, grid->rowCount() - 1, 1);
103 grid->addWidget(new QLabel("x max:"), grid->rowCount(), 0);
103 grid->addWidget(new QLabel("x max:"), grid->rowCount(), 0);
104 grid->addWidget(m_xMaxSpin, grid->rowCount() - 1, 1);
104 grid->addWidget(m_xMaxSpin, grid->rowCount() - 1, 1);
105 grid->addWidget(new QLabel("y min:"), grid->rowCount(), 0);
105 grid->addWidget(new QLabel("y min:"), grid->rowCount(), 0);
106 grid->addWidget(m_yMinSpin, grid->rowCount() - 1, 1);
106 grid->addWidget(m_yMinSpin, grid->rowCount() - 1, 1);
107 grid->addWidget(new QLabel("y max:"), grid->rowCount(), 0);
107 grid->addWidget(new QLabel("y max:"), grid->rowCount(), 0);
108 grid->addWidget(m_yMaxSpin, grid->rowCount() - 1, 1);
108 grid->addWidget(m_yMaxSpin, grid->rowCount() - 1, 1);
109
109
110 m_autoScaleCheck->setChecked(true);
110 m_autoScaleCheck->setChecked(true);
111 }
111 }
112
112
113 // Combo box for selecting theme
113 // Combo box for selecting theme
114 void MainWidget::initThemeCombo(QGridLayout *grid)
114 void MainWidget::initThemeCombo(QGridLayout *grid)
115 {
115 {
116 QComboBox *chartTheme = new QComboBox();
116 QComboBox *chartTheme = new QComboBox();
117 chartTheme->addItem("Default");
117 chartTheme->addItem("Default");
118 chartTheme->addItem("Vanilla");
118 chartTheme->addItem("Vanilla");
119 chartTheme->addItem("Icy");
119 chartTheme->addItem("Icy");
120 chartTheme->addItem("Grayscale");
120 chartTheme->addItem("Grayscale");
121 chartTheme->addItem("Scientific");
121 chartTheme->addItem("Scientific");
122 chartTheme->addItem("Unnamed1");
122 chartTheme->addItem("Unnamed1");
123 connect(chartTheme, SIGNAL(currentIndexChanged(int)),
123 connect(chartTheme, SIGNAL(currentIndexChanged(int)),
124 this, SLOT(changeChartTheme(int)));
124 this, SLOT(changeChartTheme(int)));
125 grid->addWidget(new QLabel("Chart theme:"), 8, 0);
125 grid->addWidget(new QLabel("Chart theme:"), 8, 0);
126 grid->addWidget(chartTheme, 8, 1);
126 grid->addWidget(chartTheme, 8, 1);
127 }
127 }
128
128
129 // Different check boxes for customizing chart
129 // Different check boxes for customizing chart
130 void MainWidget::initCheckboxes(QGridLayout *grid)
130 void MainWidget::initCheckboxes(QGridLayout *grid)
131 {
131 {
132 // TODO: setZoomEnabled slot has been removed from QChartView -> Re-implement zoom on/off
132 // TODO: setZoomEnabled slot has been removed from QChartView -> Re-implement zoom on/off
133 QCheckBox *zoomCheckBox = new QCheckBox("Drag'n drop Zoom");
133 QCheckBox *zoomCheckBox = new QCheckBox("Drag'n drop Zoom");
134 connect(zoomCheckBox, SIGNAL(toggled(bool)), m_chartView, SLOT(setZoomEnabled(bool)));
134 connect(zoomCheckBox, SIGNAL(toggled(bool)), m_chartView, SLOT(setZoomEnabled(bool)));
135 zoomCheckBox->setChecked(true);
135 zoomCheckBox->setChecked(true);
136 grid->addWidget(zoomCheckBox, grid->rowCount(), 0);
136 grid->addWidget(zoomCheckBox, grid->rowCount(), 0);
137
137
138 QCheckBox *aliasCheckBox = new QCheckBox("Anti-alias");
138 QCheckBox *aliasCheckBox = new QCheckBox("Anti-alias");
139 connect(aliasCheckBox, SIGNAL(toggled(bool)), this, SLOT(antiAliasToggled(bool)));
139 connect(aliasCheckBox, SIGNAL(toggled(bool)), this, SLOT(antiAliasToggled(bool)));
140 aliasCheckBox->setChecked(false);
140 aliasCheckBox->setChecked(false);
141 grid->addWidget(aliasCheckBox, grid->rowCount(), 0);
141 grid->addWidget(aliasCheckBox, grid->rowCount(), 0);
142 }
142 }
143
143
144 void MainWidget::antiAliasToggled(bool enabled)
144 void MainWidget::antiAliasToggled(bool enabled)
145 {
145 {
146 m_chartView->setRenderHint(QPainter::Antialiasing, enabled);
146 m_chartView->setRenderHint(QPainter::Antialiasing, enabled);
147 }
147 }
148
148
149 void MainWidget::addSeries()
149 void MainWidget::addSeries()
150 {
150 {
151 if (!m_addSerieDialog) {
151 if (!m_addSerieDialog) {
152 m_addSerieDialog = new DataSerieDialog(this);
152 m_addSerieDialog = new DataSerieDialog(this);
153 connect(m_addSerieDialog, SIGNAL(accepted(QString, int, int, QString, bool)),
153 connect(m_addSerieDialog, SIGNAL(accepted(QString, int, int, QString, bool)),
154 this, SLOT(addSeries(QString, int, int, QString, bool)));
154 this, SLOT(addSeries(QString, int, int, QString, bool)));
155 }
155 }
156 m_addSerieDialog->exec();
156 m_addSerieDialog->exec();
157 }
157 }
158
158
159 QList<RealList> MainWidget::generateTestData(int columnCount, int rowCount, QString dataCharacteristics)
159 QList<RealList> MainWidget::generateTestData(int columnCount, int rowCount, QString dataCharacteristics)
160 {
160 {
161 // TODO: dataCharacteristics
161 // TODO: dataCharacteristics
162 QList<RealList> testData;
162 QList<RealList> testData;
163 for (int j(0); j < columnCount; j++) {
163 for (int j(0); j < columnCount; j++) {
164 QList <qreal> newColumn;
164 QList <qreal> newColumn;
165 for (int i(0); i < rowCount; i++) {
165 for (int i(0); i < rowCount; i++) {
166 if (dataCharacteristics == "Sin") {
166 if (dataCharacteristics == "Sin") {
167 newColumn.append(abs(sin(3.14159265358979 / 50 * i) * 100));
167 newColumn.append(abs(sin(3.14159265358979 / 50 * i) * 100));
168 } else if (dataCharacteristics == "Sin + random") {
168 } else if (dataCharacteristics == "Sin + random") {
169 newColumn.append(abs(sin(3.14159265358979 / 50 * i) * 100) + (rand() % 5));
169 newColumn.append(abs(sin(3.14159265358979 / 50 * i) * 100) + (rand() % 5));
170 } else if (dataCharacteristics == "Random") {
170 } else if (dataCharacteristics == "Random") {
171 newColumn.append(rand() % 5);
171 newColumn.append(rand() % 10 + (qreal) rand() / (qreal) RAND_MAX);
172 } else if (dataCharacteristics == "Linear") {
172 } else if (dataCharacteristics == "Linear") {
173 //newColumn.append(i * (j + 1.0));
173 //newColumn.append(i * (j + 1.0));
174 // TODO: temporary hack to make pie work; prevent zero values:
174 // TODO: temporary hack to make pie work; prevent zero values:
175 newColumn.append(i * (j + 1.0) + 0.1);
175 newColumn.append(i * (j + 1.0) + 0.1);
176 } else { // "constant"
176 } else { // "constant"
177 newColumn.append((j + 1.0));
177 newColumn.append((j + 1.0));
178 }
178 }
179 }
179 }
180 testData.append(newColumn);
180 testData.append(newColumn);
181 }
181 }
182 return testData;
182 return testData;
183 }
183 }
184
184
185 QStringList MainWidget::generateLabels(int count)
185 QStringList MainWidget::generateLabels(int count)
186 {
186 {
187 QStringList result;
187 QStringList result;
188 for (int i(0); i < count; i++)
188 for (int i(0); i < count; i++)
189 result.append("label" + QString::number(i));
189 result.append("label" + QString::number(i));
190 return result;
190 return result;
191 }
191 }
192
192
193 void MainWidget::addSeries(QString seriesName, int columnCount, int rowCount, QString dataCharacteristics, bool labelsEnabled)
193 void MainWidget::addSeries(QString seriesName, int columnCount, int rowCount, QString dataCharacteristics, bool labelsEnabled)
194 {
194 {
195 qDebug() << "addSeries: " << seriesName
195 qDebug() << "addSeries: " << seriesName
196 << " columnCount: " << columnCount
196 << " columnCount: " << columnCount
197 << " rowCount: " << rowCount
197 << " rowCount: " << rowCount
198 << " dataCharacteristics: " << dataCharacteristics
198 << " dataCharacteristics: " << dataCharacteristics
199 << " labels enabled: " << labelsEnabled;
199 << " labels enabled: " << labelsEnabled;
200 m_defaultSeriesName = seriesName;
200 m_defaultSeriesName = seriesName;
201
201
202 QList<RealList> data = generateTestData(columnCount, rowCount, dataCharacteristics);
202 QList<RealList> data = generateTestData(columnCount, rowCount, dataCharacteristics);
203
203
204 // Line series and scatter series use similar data
204 // Line series and scatter series use similar data
205 if (seriesName == "Line") {
205 if (seriesName == "Line") {
206 for (int j(0); j < data.count(); j ++) {
206 for (int j(0); j < data.count(); j ++) {
207 QList<qreal> column = data.at(j);
207 QList<qreal> column = data.at(j);
208 QLineSeries *series = new QLineSeries();
208 QLineSeries *series = new QLineSeries();
209 for (int i(0); i < column.count(); i++) {
209 for (int i(0); i < column.count(); i++) {
210 series->add(i, column.at(i));
210 series->add(i, column.at(i));
211 }
211 }
212 m_chartView->addSeries(series);
212 m_chartView->addSeries(series);
213 setCurrentSeries(series);
213 setCurrentSeries(series);
214 }
214 }
215 } if (seriesName == "Area") {
215 } if (seriesName == "Area") {
216 // TODO: lower series for the area?
216 // TODO: lower series for the area?
217 for (int j(0); j < data.count(); j ++) {
217 for (int j(0); j < data.count(); j ++) {
218 QList<qreal> column = data.at(j);
218 QList<qreal> column = data.at(j);
219 QLineSeries *lineSeries = new QLineSeries();
219 QLineSeries *lineSeries = new QLineSeries();
220 for (int i(0); i < column.count(); i++) {
220 for (int i(0); i < column.count(); i++) {
221 lineSeries->add(i, column.at(i));
221 lineSeries->add(i, column.at(i));
222 }
222 }
223 QAreaSeries *areaSeries = new QAreaSeries(lineSeries);
223 QAreaSeries *areaSeries = new QAreaSeries(lineSeries);
224 m_chartView->addSeries(areaSeries);
224 m_chartView->addSeries(areaSeries);
225 setCurrentSeries(areaSeries);
225 setCurrentSeries(areaSeries);
226 }
226 }
227 } else if (seriesName == "Scatter") {
227 } else if (seriesName == "Scatter") {
228 for (int j(0); j < data.count(); j++) {
228 for (int j(0); j < data.count(); j++) {
229 QList<qreal> column = data.at(j);
229 QList<qreal> column = data.at(j);
230 QScatterSeries *series = new QScatterSeries();
230 QScatterSeries *series = new QScatterSeries();
231 for (int i(0); i < column.count(); i++) {
231 for (int i(0); i < column.count(); i++) {
232 (*series) << QPointF(i, column.at(i));
232 (*series) << QPointF(i, column.at(i));
233 }
233 }
234 m_chartView->addSeries(series);
234 m_chartView->addSeries(series);
235 setCurrentSeries(series);
235 setCurrentSeries(series);
236 }
236 }
237 } else if (seriesName == "Pie") {
237 } else if (seriesName == "Pie") {
238 QStringList labels = generateLabels(rowCount);
238 QStringList labels = generateLabels(rowCount);
239 for (int j(0); j < data.count(); j++) {
239 for (int j(0); j < data.count(); j++) {
240 QPieSeries *series = new QPieSeries();
240 QPieSeries *series = new QPieSeries();
241 QList<qreal> column = data.at(j);
241 QList<qreal> column = data.at(j);
242 for (int i(0); i < column.count(); i++) {
242 for (int i(0); i < column.count(); i++) {
243 series->add(column.at(i), labels.at(i));
243 series->add(column.at(i), labels.at(i));
244 }
244 }
245 m_chartView->addSeries(series);
245 m_chartView->addSeries(series);
246 setCurrentSeries(series);
246 setCurrentSeries(series);
247 }
247 }
248 } else if (seriesName == "Bar"
248 } else if (seriesName == "Bar"
249 || seriesName == "Stacked bar"
249 || seriesName == "Stacked bar"
250 || seriesName == "Percent bar") {
250 || seriesName == "Percent bar") {
251 QStringList category;
251 QStringList category;
252 QStringList labels = generateLabels(rowCount);
252 QStringList labels = generateLabels(rowCount);
253 foreach(QString label, labels)
253 foreach(QString label, labels)
254 category << label;
254 category << label;
255 QBarSeries* series = 0;
255 QBarSeries* series = 0;
256 if (seriesName == "Bar")
256 if (seriesName == "Bar")
257 series = new QBarSeries(category, this);
257 series = new QBarSeries(category, this);
258 else if (seriesName == "Stacked bar")
258 else if (seriesName == "Stacked bar")
259 series = new QStackedBarSeries(category, this);
259 series = new QStackedBarSeries(category, this);
260 else
260 else
261 series = new QPercentBarSeries(category, this);
261 series = new QPercentBarSeries(category, this);
262
262
263 for (int j(0); j < data.count(); j++) {
263 for (int j(0); j < data.count(); j++) {
264 QList<qreal> column = data.at(j);
264 QList<qreal> column = data.at(j);
265 QBarSet *set = new QBarSet("set" + QString::number(j));
265 QBarSet *set = new QBarSet("set" + QString::number(j));
266 for (int i(0); i < column.count(); i++) {
266 for (int i(0); i < column.count(); i++) {
267 *set << column.at(i);
267 *set << column.at(i);
268 }
268 }
269 series->addBarSet(set);
269 series->addBarSet(set);
270 }
270 }
271
271
272 // TODO: new implementation of setFloatingValuesEnabled with signals
272 // TODO: new implementation of setFloatingValuesEnabled with signals
273 //series->setFloatingValuesEnabled(true);
273 //series->setFloatingValuesEnabled(true);
274 series->setToolTipEnabled(true);
274 series->setToolTipEnabled(true);
275 series->setSeparatorsVisible(false);
275 series->setSeparatorsVisible(false);
276 m_chartView->addSeries(series);
276 m_chartView->addSeries(series);
277 setCurrentSeries(series);
277 setCurrentSeries(series);
278 } else if (seriesName == "Spline") {
278 } else if (seriesName == "Spline") {
279 for (int j(0); j < data.count(); j ++) {
279 for (int j(0); j < data.count(); j ++) {
280 QList<qreal> column = data.at(j);
280 QList<qreal> column = data.at(j);
281 QSplineSeries *series = new QSplineSeries();
281 QSplineSeries *series = new QSplineSeries();
282 for (int i(0); i < column.count(); i++) {
282 for (int i(0); i < column.count(); i++) {
283 series->add(i, column.at(i));
283 series->add(i, column.at(i));
284 }
284 }
285 m_chartView->addSeries(series);
285 m_chartView->addSeries(series);
286 setCurrentSeries(series);
286 setCurrentSeries(series);
287 }
287 }
288
288
289 // TODO: area
289 // TODO: area
290 }
290 }
291 }
291 }
292
292
293 void MainWidget::setCurrentSeries(QSeries *series)
293 void MainWidget::setCurrentSeries(QSeries *series)
294 {
294 {
295 if (series) {
295 if (series) {
296 m_currentSeries = series;
296 m_currentSeries = series;
297 switch (m_currentSeries->type()) {
297 switch (m_currentSeries->type()) {
298 case QSeries::SeriesTypeLine:
298 case QSeries::SeriesTypeLine:
299 break;
299 break;
300 case QSeries::SeriesTypeScatter:
300 case QSeries::SeriesTypeScatter:
301 break;
301 break;
302 case QSeries::SeriesTypePie:
302 case QSeries::SeriesTypePie:
303 break;
303 break;
304 case QSeries::SeriesTypeBar:
304 case QSeries::SeriesTypeBar:
305 qDebug() << "setCurrentSeries (bar)";
305 qDebug() << "setCurrentSeries (bar)";
306 break;
306 break;
307 case QSeries::SeriesTypeStackedBar:
307 case QSeries::SeriesTypeStackedBar:
308 qDebug() << "setCurrentSeries (Stackedbar)";
308 qDebug() << "setCurrentSeries (Stackedbar)";
309 break;
309 break;
310 case QSeries::SeriesTypePercentBar:
310 case QSeries::SeriesTypePercentBar:
311 qDebug() << "setCurrentSeries (Percentbar)";
311 qDebug() << "setCurrentSeries (Percentbar)";
312 break;
312 break;
313 case QSeries::SeriesTypeSpline:
313 case QSeries::SeriesTypeSpline:
314 break;
314 break;
315 default:
315 default:
316 Q_ASSERT(false);
316 Q_ASSERT(false);
317 break;
317 break;
318 }
318 }
319 }
319 }
320 }
320 }
321
321
322 void MainWidget::backgroundChanged(int itemIndex)
322 void MainWidget::backgroundChanged(int itemIndex)
323 {
323 {
324 qDebug() << "backgroundChanged: " << itemIndex;
324 qDebug() << "backgroundChanged: " << itemIndex;
325 }
325 }
326
326
327 void MainWidget::autoScaleChanged(int value)
327 void MainWidget::autoScaleChanged(int value)
328 {
328 {
329 if (value) {
329 if (value) {
330 // TODO: enable auto scaling
330 // TODO: enable auto scaling
331 } else {
331 } else {
332 // TODO: set scaling manually (and disable auto scaling)
332 // TODO: set scaling manually (and disable auto scaling)
333 }
333 }
334
334
335 m_xMinSpin->setEnabled(!value);
335 m_xMinSpin->setEnabled(!value);
336 m_xMaxSpin->setEnabled(!value);
336 m_xMaxSpin->setEnabled(!value);
337 m_yMinSpin->setEnabled(!value);
337 m_yMinSpin->setEnabled(!value);
338 m_yMaxSpin->setEnabled(!value);
338 m_yMaxSpin->setEnabled(!value);
339 }
339 }
340
340
341 void MainWidget::xMinChanged(int value)
341 void MainWidget::xMinChanged(int value)
342 {
342 {
343 qDebug() << "xMinChanged: " << value;
343 qDebug() << "xMinChanged: " << value;
344 }
344 }
345
345
346 void MainWidget::xMaxChanged(int value)
346 void MainWidget::xMaxChanged(int value)
347 {
347 {
348 qDebug() << "xMaxChanged: " << value;
348 qDebug() << "xMaxChanged: " << value;
349 }
349 }
350
350
351 void MainWidget::yMinChanged(int value)
351 void MainWidget::yMinChanged(int value)
352 {
352 {
353 qDebug() << "yMinChanged: " << value;
353 qDebug() << "yMinChanged: " << value;
354 }
354 }
355
355
356 void MainWidget::yMaxChanged(int value)
356 void MainWidget::yMaxChanged(int value)
357 {
357 {
358 qDebug() << "yMaxChanged: " << value;
358 qDebug() << "yMaxChanged: " << value;
359 }
359 }
360
360
361 void MainWidget::changeChartTheme(int themeIndex)
361 void MainWidget::changeChartTheme(int themeIndex)
362 {
362 {
363 qDebug() << "changeChartTheme: " << themeIndex;
363 qDebug() << "changeChartTheme: " << themeIndex;
364 m_chartView->setChartTheme((QChart::ChartTheme) themeIndex);
364 m_chartView->setChartTheme((QChart::ChartTheme) themeIndex);
365 //TODO: remove this hack. This is just to make it so that theme change is seen immediately.
365 //TODO: remove this hack. This is just to make it so that theme change is seen immediately.
366 QSize s = size();
366 QSize s = size();
367 s.setWidth(s.width()+1);
367 s.setWidth(s.width()+1);
368 resize(s);
368 resize(s);
369 }
369 }
General Comments 0
You need to be logged in to leave comments. Login now