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