##// END OF EJS Templates
removed warning from chartthemes demo
sauimone -
r1675:592f4e5c298a
parent child
Show More
@@ -1,378 +1,379
1 /****************************************************************************
1 /****************************************************************************
2 **
2 **
3 ** Copyright (C) 2012 Digia Plc
3 ** Copyright (C) 2012 Digia Plc
4 ** All rights reserved.
4 ** All rights reserved.
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 **
6 **
7 ** This file is part of the Qt Commercial Charts Add-on.
7 ** This file is part of the Qt Commercial Charts Add-on.
8 **
8 **
9 ** $QT_BEGIN_LICENSE$
9 ** $QT_BEGIN_LICENSE$
10 ** Licensees holding valid Qt Commercial licenses may use this file in
10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 ** accordance with the Qt Commercial License Agreement provided with the
11 ** accordance with the Qt Commercial License Agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia.
13 ** a written agreement between you and Digia.
14 **
14 **
15 ** If you have questions regarding the use of this file, please use
15 ** If you have questions regarding the use of this file, please use
16 ** contact form at http://qt.digia.com
16 ** contact form at http://qt.digia.com
17 ** $QT_END_LICENSE$
17 ** $QT_END_LICENSE$
18 **
18 **
19 ****************************************************************************/
19 ****************************************************************************/
20
20
21 #include "themewidget.h"
21 #include "themewidget.h"
22
22
23 #include <QChartView>
23 #include <QChartView>
24 #include <QPieSeries>
24 #include <QPieSeries>
25 #include <QPieSlice>
25 #include <QPieSlice>
26 #include <QAbstractBarSeries>
26 #include <QAbstractBarSeries>
27 #include <QPercentBarSeries>
27 #include <QPercentBarSeries>
28 #include <QStackedBarSeries>
28 #include <QStackedBarSeries>
29 #include <QBarSeries>
29 #include <QBarSeries>
30 #include <QBarSet>
30 #include <QBarSet>
31 #include <QLineSeries>
31 #include <QLineSeries>
32 #include <QSplineSeries>
32 #include <QSplineSeries>
33 #include <QScatterSeries>
33 #include <QScatterSeries>
34 #include <QAreaSeries>
34 #include <QAreaSeries>
35 #include <QLegend>
35 #include <QLegend>
36 #include <QGridLayout>
36 #include <QGridLayout>
37 #include <QFormLayout>
37 #include <QFormLayout>
38 #include <QComboBox>
38 #include <QComboBox>
39 #include <QSpinBox>
39 #include <QSpinBox>
40 #include <QCheckBox>
40 #include <QCheckBox>
41 #include <QGroupBox>
41 #include <QGroupBox>
42 #include <QLabel>
42 #include <QLabel>
43 #include <QTime>
43 #include <QTime>
44 #include <QBarCategoriesAxis>
44 #include <QBarCategoriesAxis>
45
45
46 ThemeWidget::ThemeWidget(QWidget* parent) :
46 ThemeWidget::ThemeWidget(QWidget* parent) :
47 QWidget(parent),
47 QWidget(parent),
48 m_listCount(3),
48 m_listCount(3),
49 m_valueMax(10),
49 m_valueMax(10),
50 m_valueCount(7),
50 m_valueCount(7),
51 m_dataTable(generateRandomData(m_listCount,m_valueMax,m_valueCount)),
51 m_dataTable(generateRandomData(m_listCount,m_valueMax,m_valueCount)),
52 m_themeComboBox(createThemeBox()),
52 m_themeComboBox(createThemeBox()),
53 m_antialiasCheckBox(new QCheckBox("Anti-aliasing")),
53 m_antialiasCheckBox(new QCheckBox("Anti-aliasing")),
54 m_animatedComboBox(createAnimationBox()),
54 m_animatedComboBox(createAnimationBox()),
55 m_legendComboBox(createLegendBox())
55 m_legendComboBox(createLegendBox())
56 {
56 {
57 connectSignals();
57 connectSignals();
58 // create layout
58 // create layout
59 QGridLayout* baseLayout = new QGridLayout();
59 QGridLayout* baseLayout = new QGridLayout();
60 QHBoxLayout *settingsLayout = new QHBoxLayout();
60 QHBoxLayout *settingsLayout = new QHBoxLayout();
61 settingsLayout->addWidget(new QLabel("Theme:"));
61 settingsLayout->addWidget(new QLabel("Theme:"));
62 settingsLayout->addWidget(m_themeComboBox);
62 settingsLayout->addWidget(m_themeComboBox);
63 settingsLayout->addWidget(new QLabel("Animation:"));
63 settingsLayout->addWidget(new QLabel("Animation:"));
64 settingsLayout->addWidget(m_animatedComboBox);
64 settingsLayout->addWidget(m_animatedComboBox);
65 settingsLayout->addWidget(new QLabel("Legend:"));
65 settingsLayout->addWidget(new QLabel("Legend:"));
66 settingsLayout->addWidget(m_legendComboBox);
66 settingsLayout->addWidget(m_legendComboBox);
67 settingsLayout->addWidget(m_antialiasCheckBox);
67 settingsLayout->addWidget(m_antialiasCheckBox);
68 settingsLayout->addStretch();
68 settingsLayout->addStretch();
69 baseLayout->addLayout(settingsLayout, 0, 0, 1, 3);
69 baseLayout->addLayout(settingsLayout, 0, 0, 1, 3);
70
70
71 //create charts
71 //create charts
72
72
73 QChartView *chartView;
73 QChartView *chartView;
74
74
75 chartView = new QChartView(createAreaChart());
75 chartView = new QChartView(createAreaChart());
76 baseLayout->addWidget(chartView, 1, 0);
76 baseLayout->addWidget(chartView, 1, 0);
77 m_charts << chartView;
77 m_charts << chartView;
78
78
79 chartView = new QChartView(createBarChart(m_valueCount));
79 chartView = new QChartView(createBarChart(m_valueCount));
80 baseLayout->addWidget(chartView, 1, 1);
80 baseLayout->addWidget(chartView, 1, 1);
81 m_charts << chartView;
81 m_charts << chartView;
82
82
83 chartView = new QChartView(createLineChart());
83 chartView = new QChartView(createLineChart());
84 baseLayout->addWidget(chartView, 1, 2);
84 baseLayout->addWidget(chartView, 1, 2);
85 m_charts << chartView;
85 m_charts << chartView;
86
86
87 chartView = new QChartView(createPieChart());
87 chartView = new QChartView(createPieChart());
88 chartView->setSizePolicy(QSizePolicy::Ignored, QSizePolicy::Ignored); // funny things happen if the pie slice labels no not fit the screen...
88 chartView->setSizePolicy(QSizePolicy::Ignored, QSizePolicy::Ignored); // funny things happen if the pie slice labels no not fit the screen...
89 baseLayout->addWidget(chartView, 2, 0);
89 baseLayout->addWidget(chartView, 2, 0);
90 m_charts << chartView;
90 m_charts << chartView;
91
91
92 chartView = new QChartView(createSplineChart());
92 chartView = new QChartView(createSplineChart());
93 baseLayout->addWidget(chartView, 2, 1);
93 baseLayout->addWidget(chartView, 2, 1);
94 m_charts << chartView;
94 m_charts << chartView;
95
95
96 chartView = new QChartView(createScatterChart());
96 chartView = new QChartView(createScatterChart());
97 baseLayout->addWidget(chartView, 2, 2);
97 baseLayout->addWidget(chartView, 2, 2);
98 m_charts << chartView;
98 m_charts << chartView;
99
99
100 setLayout(baseLayout);
100 setLayout(baseLayout);
101
101
102 // Set defaults
102 // Set defaults
103 m_antialiasCheckBox->setChecked(true);
103 m_antialiasCheckBox->setChecked(true);
104 updateUI();
104 updateUI();
105 }
105 }
106
106
107 ThemeWidget::~ThemeWidget()
107 ThemeWidget::~ThemeWidget()
108 {
108 {
109 }
109 }
110
110
111 void ThemeWidget::connectSignals()
111 void ThemeWidget::connectSignals()
112 {
112 {
113 connect(m_themeComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(updateUI()));
113 connect(m_themeComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(updateUI()));
114 connect(m_antialiasCheckBox, SIGNAL(toggled(bool)), this, SLOT(updateUI()));
114 connect(m_antialiasCheckBox, SIGNAL(toggled(bool)), this, SLOT(updateUI()));
115 connect(m_animatedComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(updateUI()));
115 connect(m_animatedComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(updateUI()));
116 connect(m_legendComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(updateUI()));
116 connect(m_legendComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(updateUI()));
117 }
117 }
118
118
119 DataTable ThemeWidget::generateRandomData(int listCount,int valueMax,int valueCount) const
119 DataTable ThemeWidget::generateRandomData(int listCount,int valueMax,int valueCount) const
120 {
120 {
121 DataTable dataTable;
121 DataTable dataTable;
122
122
123 // set seed for random stuff
123 // set seed for random stuff
124 qsrand(QTime(0, 0, 0).secsTo(QTime::currentTime()));
124 qsrand(QTime(0, 0, 0).secsTo(QTime::currentTime()));
125
125
126 // generate random data
126 // generate random data
127 for (int i(0); i < listCount; i++) {
127 for (int i(0); i < listCount; i++) {
128 DataList dataList;
128 DataList dataList;
129 qreal yValue(0);
129 qreal yValue(0);
130 for (int j(0); j < valueCount; j++) {
130 for (int j(0); j < valueCount; j++) {
131 yValue = yValue + (qreal) (qrand() % valueMax) / (qreal) valueCount;
131 yValue = yValue + (qreal) (qrand() % valueMax) / (qreal) valueCount;
132 QPointF value((j + (qreal) rand() / (qreal) RAND_MAX) * ((qreal) m_valueMax / (qreal) valueCount),
132 QPointF value((j + (qreal) rand() / (qreal) RAND_MAX) * ((qreal) m_valueMax / (qreal) valueCount),
133 yValue);
133 yValue);
134 QString label = "Slice " + QString::number(i) + ":" + QString::number(j);
134 QString label = "Slice " + QString::number(i) + ":" + QString::number(j);
135 dataList << Data(value, label);
135 dataList << Data(value, label);
136 }
136 }
137 dataTable << dataList;
137 dataTable << dataList;
138 }
138 }
139
139
140 return dataTable;
140 return dataTable;
141 }
141 }
142
142
143 QComboBox* ThemeWidget::createThemeBox() const
143 QComboBox* ThemeWidget::createThemeBox() const
144 {
144 {
145 // settings layout
145 // settings layout
146 QComboBox* themeComboBox = new QComboBox();
146 QComboBox* themeComboBox = new QComboBox();
147 themeComboBox->addItem("Light", QChart::ChartThemeLight);
147 themeComboBox->addItem("Light", QChart::ChartThemeLight);
148 themeComboBox->addItem("Blue Cerulean", QChart::ChartThemeBlueCerulean);
148 themeComboBox->addItem("Blue Cerulean", QChart::ChartThemeBlueCerulean);
149 themeComboBox->addItem("Dark", QChart::ChartThemeDark);
149 themeComboBox->addItem("Dark", QChart::ChartThemeDark);
150 themeComboBox->addItem("Brown Sand", QChart::ChartThemeBrownSand);
150 themeComboBox->addItem("Brown Sand", QChart::ChartThemeBrownSand);
151 themeComboBox->addItem("Blue NCS", QChart::ChartThemeBlueNcs);
151 themeComboBox->addItem("Blue NCS", QChart::ChartThemeBlueNcs);
152 themeComboBox->addItem("High Contrast", QChart::ChartThemeHighContrast);
152 themeComboBox->addItem("High Contrast", QChart::ChartThemeHighContrast);
153 themeComboBox->addItem("Blue Icy", QChart::ChartThemeBlueIcy);
153 themeComboBox->addItem("Blue Icy", QChart::ChartThemeBlueIcy);
154 return themeComboBox;
154 return themeComboBox;
155 }
155 }
156
156
157 QComboBox* ThemeWidget::createAnimationBox() const
157 QComboBox* ThemeWidget::createAnimationBox() const
158 {
158 {
159 // settings layout
159 // settings layout
160 QComboBox* animationComboBox = new QComboBox();
160 QComboBox* animationComboBox = new QComboBox();
161 animationComboBox->addItem("No Animations", QChart::NoAnimation);
161 animationComboBox->addItem("No Animations", QChart::NoAnimation);
162 animationComboBox->addItem("GridAxis Animations", QChart::GridAxisAnimations);
162 animationComboBox->addItem("GridAxis Animations", QChart::GridAxisAnimations);
163 animationComboBox->addItem("Series Animations", QChart::SeriesAnimations);
163 animationComboBox->addItem("Series Animations", QChart::SeriesAnimations);
164 animationComboBox->addItem("All Animations", QChart::AllAnimations);
164 animationComboBox->addItem("All Animations", QChart::AllAnimations);
165 return animationComboBox;
165 return animationComboBox;
166 }
166 }
167
167
168 QComboBox* ThemeWidget::createLegendBox() const
168 QComboBox* ThemeWidget::createLegendBox() const
169 {
169 {
170 QComboBox* legendComboBox = new QComboBox();
170 QComboBox* legendComboBox = new QComboBox();
171 legendComboBox->addItem("No Legend ", 0);
171 legendComboBox->addItem("No Legend ", 0);
172 legendComboBox->addItem("Legend Top", Qt::AlignTop);
172 legendComboBox->addItem("Legend Top", Qt::AlignTop);
173 legendComboBox->addItem("Legend Bottom", Qt::AlignBottom);
173 legendComboBox->addItem("Legend Bottom", Qt::AlignBottom);
174 legendComboBox->addItem("Legend Left", Qt::AlignLeft);
174 legendComboBox->addItem("Legend Left", Qt::AlignLeft);
175 legendComboBox->addItem("Legend Right", Qt::AlignRight);
175 legendComboBox->addItem("Legend Right", Qt::AlignRight);
176 return legendComboBox;
176 return legendComboBox;
177 }
177 }
178
178
179 QChart* ThemeWidget::createAreaChart() const
179 QChart* ThemeWidget::createAreaChart() const
180 {
180 {
181 QChart *chart = new QChart();
181 QChart *chart = new QChart();
182 // chart->axisX()->setNiceNumbersEnabled(true);
182 // chart->axisX()->setNiceNumbersEnabled(true);
183 // chart->axisY()->setNiceNumbersEnabled(true);
183 // chart->axisY()->setNiceNumbersEnabled(true);
184 chart->setTitle("Area chart");
184 chart->setTitle("Area chart");
185
185
186 // The lower series initialized to zero values
186 // The lower series initialized to zero values
187 QLineSeries *lowerSeries = 0;
187 QLineSeries *lowerSeries = 0;
188 QString name("Series ");
188 QString name("Series ");
189 int nameIndex = 0;
189 int nameIndex = 0;
190 for (int i(0); i < m_dataTable.count(); i++) {
190 for (int i(0); i < m_dataTable.count(); i++) {
191 QLineSeries *upperSeries = new QLineSeries(chart);
191 QLineSeries *upperSeries = new QLineSeries(chart);
192 for (int j(0); j < m_dataTable[i].count(); j++) {
192 for (int j(0); j < m_dataTable[i].count(); j++) {
193 Data data = m_dataTable[i].at(j);
193 Data data = m_dataTable[i].at(j);
194 if (lowerSeries){
194 if (lowerSeries){
195 const QList<QPointF>& points = lowerSeries->points();
195 const QList<QPointF>& points = lowerSeries->points();
196 upperSeries->append(QPointF(j, points[i].y() + data.first.y()));
196 upperSeries->append(QPointF(j, points[i].y() + data.first.y()));
197 }else
197 }else
198 upperSeries->append(QPointF(j, data.first.y()));
198 upperSeries->append(QPointF(j, data.first.y()));
199 }
199 }
200 QAreaSeries *area = new QAreaSeries(upperSeries, lowerSeries);
200 QAreaSeries *area = new QAreaSeries(upperSeries, lowerSeries);
201 area->setName(name + QString::number(nameIndex));
201 area->setName(name + QString::number(nameIndex));
202 nameIndex++;
202 nameIndex++;
203 chart->addSeries(area);
203 chart->addSeries(area);
204 chart->createDefaultAxes();
204 chart->createDefaultAxes();
205 lowerSeries = upperSeries;
205 lowerSeries = upperSeries;
206 }
206 }
207
207
208 return chart;
208 return chart;
209 }
209 }
210
210
211 QChart* ThemeWidget::createBarChart(int valueCount) const
211 QChart* ThemeWidget::createBarChart(int valueCount) const
212 {
212 {
213 Q_UNUSED(valueCount);
213 QChart* chart = new QChart();
214 QChart* chart = new QChart();
214 //TODO: chart->axisX()->setNiceNumbersEnabled(true);
215 //TODO: chart->axisX()->setNiceNumbersEnabled(true);
215 //TODO: chart->axisY()->setNiceNumbersEnabled(true);
216 //TODO: chart->axisY()->setNiceNumbersEnabled(true);
216 chart->setTitle("Bar chart");
217 chart->setTitle("Bar chart");
217
218
218 QStackedBarSeries* series = new QStackedBarSeries(chart);
219 QStackedBarSeries* series = new QStackedBarSeries(chart);
219 for (int i(0); i < m_dataTable.count(); i++) {
220 for (int i(0); i < m_dataTable.count(); i++) {
220 QBarSet *set = new QBarSet("Bar set " + QString::number(i));
221 QBarSet *set = new QBarSet("Bar set " + QString::number(i));
221 foreach (Data data, m_dataTable[i])
222 foreach (Data data, m_dataTable[i])
222 *set << data.first.y();
223 *set << data.first.y();
223 series->append(set);
224 series->append(set);
224 }
225 }
225 chart->addSeries(series);
226 chart->addSeries(series);
226 chart->createDefaultAxes();
227 chart->createDefaultAxes();
227
228
228 return chart;
229 return chart;
229 }
230 }
230
231
231 QChart* ThemeWidget::createLineChart() const
232 QChart* ThemeWidget::createLineChart() const
232 {
233 {
233 QChart* chart = new QChart();
234 QChart* chart = new QChart();
234 //TODO: chart->axisX()->setNiceNumbersEnabled(true);
235 //TODO: chart->axisX()->setNiceNumbersEnabled(true);
235 //TODO: chart->axisY()->setNiceNumbersEnabled(true);
236 //TODO: chart->axisY()->setNiceNumbersEnabled(true);
236 chart->setTitle("Line chart");
237 chart->setTitle("Line chart");
237
238
238 QString name("Series ");
239 QString name("Series ");
239 int nameIndex = 0;
240 int nameIndex = 0;
240 foreach (DataList list, m_dataTable) {
241 foreach (DataList list, m_dataTable) {
241 QLineSeries *series = new QLineSeries(chart);
242 QLineSeries *series = new QLineSeries(chart);
242 foreach (Data data, list)
243 foreach (Data data, list)
243 series->append(data.first);
244 series->append(data.first);
244 series->setName(name + QString::number(nameIndex));
245 series->setName(name + QString::number(nameIndex));
245 nameIndex++;
246 nameIndex++;
246 chart->addSeries(series);
247 chart->addSeries(series);
247 }
248 }
248 chart->createDefaultAxes();
249 chart->createDefaultAxes();
249
250
250 return chart;
251 return chart;
251 }
252 }
252
253
253 QChart* ThemeWidget::createPieChart() const
254 QChart* ThemeWidget::createPieChart() const
254 {
255 {
255 QChart* chart = new QChart();
256 QChart* chart = new QChart();
256 chart->setTitle("Pie chart");
257 chart->setTitle("Pie chart");
257
258
258 qreal pieSize = 1.0 / m_dataTable.count();
259 qreal pieSize = 1.0 / m_dataTable.count();
259 for (int i = 0; i < m_dataTable.count(); i++) {
260 for (int i = 0; i < m_dataTable.count(); i++) {
260 QPieSeries *series = new QPieSeries(chart);
261 QPieSeries *series = new QPieSeries(chart);
261 foreach (Data data, m_dataTable[i]) {
262 foreach (Data data, m_dataTable[i]) {
262 QPieSlice *slice = series->append(data.second, data.first.y());
263 QPieSlice *slice = series->append(data.second, data.first.y());
263 if (data == m_dataTable[i].first()) {
264 if (data == m_dataTable[i].first()) {
264 slice->setLabelVisible();
265 slice->setLabelVisible();
265 slice->setExploded();
266 slice->setExploded();
266 }
267 }
267 }
268 }
268 qreal hPos = (pieSize / 2) + (i / (qreal) m_dataTable.count());
269 qreal hPos = (pieSize / 2) + (i / (qreal) m_dataTable.count());
269 series->setPieSize(pieSize);
270 series->setPieSize(pieSize);
270 series->setHorizontalPosition(hPos);
271 series->setHorizontalPosition(hPos);
271 series->setVerticalPosition(0.5);
272 series->setVerticalPosition(0.5);
272 chart->addSeries(series);
273 chart->addSeries(series);
273 }
274 }
274
275
275 return chart;
276 return chart;
276 }
277 }
277
278
278 QChart* ThemeWidget::createSplineChart() const
279 QChart* ThemeWidget::createSplineChart() const
279 { // spine chart
280 { // spine chart
280 QChart* chart = new QChart();
281 QChart* chart = new QChart();
281 //TODO: chart->axisX()->setNiceNumbersEnabled(true);
282 //TODO: chart->axisX()->setNiceNumbersEnabled(true);
282 //TODO: chart->axisY()->setNiceNumbersEnabled(true);
283 //TODO: chart->axisY()->setNiceNumbersEnabled(true);
283 chart->setTitle("Spline chart");
284 chart->setTitle("Spline chart");
284 QString name("Series ");
285 QString name("Series ");
285 int nameIndex = 0;
286 int nameIndex = 0;
286 foreach (DataList list, m_dataTable) {
287 foreach (DataList list, m_dataTable) {
287 QSplineSeries *series = new QSplineSeries(chart);
288 QSplineSeries *series = new QSplineSeries(chart);
288 foreach (Data data, list)
289 foreach (Data data, list)
289 series->append(data.first);
290 series->append(data.first);
290 series->setName(name + QString::number(nameIndex));
291 series->setName(name + QString::number(nameIndex));
291 nameIndex++;
292 nameIndex++;
292 chart->addSeries(series);
293 chart->addSeries(series);
293 }
294 }
294 chart->createDefaultAxes();
295 chart->createDefaultAxes();
295 return chart;
296 return chart;
296 }
297 }
297
298
298 QChart* ThemeWidget::createScatterChart() const
299 QChart* ThemeWidget::createScatterChart() const
299 { // scatter chart
300 { // scatter chart
300 QChart* chart = new QChart();
301 QChart* chart = new QChart();
301 //TODO: chart->axisX()->setNiceNumbersEnabled(true);
302 //TODO: chart->axisX()->setNiceNumbersEnabled(true);
302 //TODO: chart->axisY()->setNiceNumbersEnabled(true);
303 //TODO: chart->axisY()->setNiceNumbersEnabled(true);
303 chart->setTitle("Scatter chart");
304 chart->setTitle("Scatter chart");
304 QString name("Series ");
305 QString name("Series ");
305 int nameIndex = 0;
306 int nameIndex = 0;
306 foreach (DataList list, m_dataTable) {
307 foreach (DataList list, m_dataTable) {
307 QScatterSeries *series = new QScatterSeries(chart);
308 QScatterSeries *series = new QScatterSeries(chart);
308 foreach (Data data, list)
309 foreach (Data data, list)
309 series->append(data.first);
310 series->append(data.first);
310 series->setName(name + QString::number(nameIndex));
311 series->setName(name + QString::number(nameIndex));
311 nameIndex++;
312 nameIndex++;
312 chart->addSeries(series);
313 chart->addSeries(series);
313 }
314 }
314 chart->createDefaultAxes();
315 chart->createDefaultAxes();
315 return chart;
316 return chart;
316 }
317 }
317
318
318 void ThemeWidget::updateUI()
319 void ThemeWidget::updateUI()
319 {
320 {
320 QChart::ChartTheme theme = (QChart::ChartTheme) m_themeComboBox->itemData(m_themeComboBox->currentIndex()).toInt();
321 QChart::ChartTheme theme = (QChart::ChartTheme) m_themeComboBox->itemData(m_themeComboBox->currentIndex()).toInt();
321
322
322 if (m_charts.at(0)->chart()->theme() != theme) {
323 if (m_charts.at(0)->chart()->theme() != theme) {
323 foreach (QChartView *chartView, m_charts)
324 foreach (QChartView *chartView, m_charts)
324 chartView->chart()->setTheme(theme);
325 chartView->chart()->setTheme(theme);
325
326
326 QPalette pal = window()->palette();
327 QPalette pal = window()->palette();
327 if (theme == QChart::ChartThemeLight) {
328 if (theme == QChart::ChartThemeLight) {
328 pal.setColor(QPalette::Window, QRgb(0xf0f0f0));
329 pal.setColor(QPalette::Window, QRgb(0xf0f0f0));
329 pal.setColor(QPalette::WindowText, QRgb(0x404044));
330 pal.setColor(QPalette::WindowText, QRgb(0x404044));
330 } else if (theme == QChart::ChartThemeDark) {
331 } else if (theme == QChart::ChartThemeDark) {
331 pal.setColor(QPalette::Window, QRgb(0x121218));
332 pal.setColor(QPalette::Window, QRgb(0x121218));
332 pal.setColor(QPalette::WindowText, QRgb(0xd6d6d6));
333 pal.setColor(QPalette::WindowText, QRgb(0xd6d6d6));
333 } else if (theme == QChart::ChartThemeBlueCerulean) {
334 } else if (theme == QChart::ChartThemeBlueCerulean) {
334 pal.setColor(QPalette::Window, QRgb(0x40434a));
335 pal.setColor(QPalette::Window, QRgb(0x40434a));
335 pal.setColor(QPalette::WindowText, QRgb(0xd6d6d6));
336 pal.setColor(QPalette::WindowText, QRgb(0xd6d6d6));
336 } else if (theme == QChart::ChartThemeBrownSand) {
337 } else if (theme == QChart::ChartThemeBrownSand) {
337 pal.setColor(QPalette::Window, QRgb(0x9e8965));
338 pal.setColor(QPalette::Window, QRgb(0x9e8965));
338 pal.setColor(QPalette::WindowText, QRgb(0x404044));
339 pal.setColor(QPalette::WindowText, QRgb(0x404044));
339 } else if (theme == QChart::ChartThemeBlueNcs) {
340 } else if (theme == QChart::ChartThemeBlueNcs) {
340 pal.setColor(QPalette::Window, QRgb(0x018bba));
341 pal.setColor(QPalette::Window, QRgb(0x018bba));
341 pal.setColor(QPalette::WindowText, QRgb(0x404044));
342 pal.setColor(QPalette::WindowText, QRgb(0x404044));
342 } else if (theme == QChart::ChartThemeHighContrast) {
343 } else if (theme == QChart::ChartThemeHighContrast) {
343 pal.setColor(QPalette::Window, QRgb(0xffab03));
344 pal.setColor(QPalette::Window, QRgb(0xffab03));
344 pal.setColor(QPalette::WindowText, QRgb(0x181818));
345 pal.setColor(QPalette::WindowText, QRgb(0x181818));
345 } else if (theme == QChart::ChartThemeBlueIcy) {
346 } else if (theme == QChart::ChartThemeBlueIcy) {
346 pal.setColor(QPalette::Window, QRgb(0xcee7f0));
347 pal.setColor(QPalette::Window, QRgb(0xcee7f0));
347 pal.setColor(QPalette::WindowText, QRgb(0x404044));
348 pal.setColor(QPalette::WindowText, QRgb(0x404044));
348 } else {
349 } else {
349 pal.setColor(QPalette::Window, QRgb(0xf0f0f0));
350 pal.setColor(QPalette::Window, QRgb(0xf0f0f0));
350 pal.setColor(QPalette::WindowText, QRgb(0x404044));
351 pal.setColor(QPalette::WindowText, QRgb(0x404044));
351 }
352 }
352 window()->setPalette(pal);
353 window()->setPalette(pal);
353 }
354 }
354
355
355 bool checked = m_antialiasCheckBox->isChecked();
356 bool checked = m_antialiasCheckBox->isChecked();
356 foreach (QChartView *chart, m_charts)
357 foreach (QChartView *chart, m_charts)
357 chart->setRenderHint(QPainter::Antialiasing, checked);
358 chart->setRenderHint(QPainter::Antialiasing, checked);
358
359
359 QChart::AnimationOptions options(m_animatedComboBox->itemData(m_animatedComboBox->currentIndex()).toInt());
360 QChart::AnimationOptions options(m_animatedComboBox->itemData(m_animatedComboBox->currentIndex()).toInt());
360 if (m_charts.at(0)->chart()->animationOptions() != options) {
361 if (m_charts.at(0)->chart()->animationOptions() != options) {
361 foreach (QChartView *chartView, m_charts)
362 foreach (QChartView *chartView, m_charts)
362 chartView->chart()->setAnimationOptions(options);
363 chartView->chart()->setAnimationOptions(options);
363 }
364 }
364
365
365 Qt::Alignment alignment(m_legendComboBox->itemData(m_legendComboBox->currentIndex()).toInt());
366 Qt::Alignment alignment(m_legendComboBox->itemData(m_legendComboBox->currentIndex()).toInt());
366
367
367 if (!alignment) {
368 if (!alignment) {
368 foreach (QChartView *chartView, m_charts) {
369 foreach (QChartView *chartView, m_charts) {
369 chartView->chart()->legend()->hide();
370 chartView->chart()->legend()->hide();
370 }
371 }
371 } else {
372 } else {
372 foreach (QChartView *chartView, m_charts) {
373 foreach (QChartView *chartView, m_charts) {
373 chartView->chart()->legend()->setAlignment(alignment);
374 chartView->chart()->legend()->setAlignment(alignment);
374 chartView->chart()->legend()->show();
375 chartView->chart()->legend()->show();
375 }
376 }
376 }
377 }
377 }
378 }
378
379
General Comments 0
You need to be logged in to leave comments. Login now