@@ -1,374 +1,374 | |||||
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 | connectSignals(); |
|
55 | connectSignals(); | |
56 | // create layout |
|
56 | // create layout | |
57 | QGridLayout* baseLayout = new QGridLayout(); |
|
57 | QGridLayout* baseLayout = new QGridLayout(); | |
58 | QHBoxLayout *settingsLayout = new QHBoxLayout(); |
|
58 | QHBoxLayout *settingsLayout = new QHBoxLayout(); | |
59 | settingsLayout->addWidget(new QLabel("Theme:")); |
|
59 | settingsLayout->addWidget(new QLabel("Theme:")); | |
60 | settingsLayout->addWidget(m_themeComboBox); |
|
60 | settingsLayout->addWidget(m_themeComboBox); | |
61 | settingsLayout->addWidget(new QLabel("Animation:")); |
|
61 | settingsLayout->addWidget(new QLabel("Animation:")); | |
62 | settingsLayout->addWidget(m_animatedComboBox); |
|
62 | settingsLayout->addWidget(m_animatedComboBox); | |
63 | settingsLayout->addWidget(new QLabel("Legend:")); |
|
63 | settingsLayout->addWidget(new QLabel("Legend:")); | |
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 | updateUI(); |
|
102 | updateUI(); | |
103 | } |
|
103 | } | |
104 |
|
104 | |||
105 | ThemeWidget::~ThemeWidget() |
|
105 | ThemeWidget::~ThemeWidget() | |
106 | { |
|
106 | { | |
107 | } |
|
107 | } | |
108 |
|
108 | |||
109 | void ThemeWidget::connectSignals() |
|
109 | void ThemeWidget::connectSignals() | |
110 | { |
|
110 | { | |
111 | connect(m_themeComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(updateUI())); |
|
111 | connect(m_themeComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(updateUI())); | |
112 | connect(m_antialiasCheckBox, SIGNAL(toggled(bool)), this, SLOT(updateUI())); |
|
112 | connect(m_antialiasCheckBox, SIGNAL(toggled(bool)), this, SLOT(updateUI())); | |
113 | connect(m_animatedComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(updateUI())); |
|
113 | connect(m_animatedComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(updateUI())); | |
114 | connect(m_legendComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(updateUI())); |
|
114 | connect(m_legendComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(updateUI())); | |
115 | } |
|
115 | } | |
116 |
|
116 | |||
117 | DataTable ThemeWidget::generateRandomData(int listCount,int valueMax,int valueCount) const |
|
117 | DataTable ThemeWidget::generateRandomData(int listCount,int valueMax,int valueCount) const | |
118 | { |
|
118 | { | |
119 | DataTable dataTable; |
|
119 | DataTable dataTable; | |
120 |
|
120 | |||
121 | // set seed for random stuff |
|
121 | // set seed for random stuff | |
122 | qsrand(QTime(0, 0, 0).secsTo(QTime::currentTime())); |
|
122 | qsrand(QTime(0, 0, 0).secsTo(QTime::currentTime())); | |
123 |
|
123 | |||
124 | // generate random data |
|
124 | // generate random data | |
125 | for (int i(0); i < listCount; i++) { |
|
125 | for (int i(0); i < listCount; i++) { | |
126 | DataList dataList; |
|
126 | DataList dataList; | |
127 | qreal yValue(0); |
|
127 | qreal yValue(0); | |
128 | for (int j(0); j < valueCount; j++) { |
|
128 | for (int j(0); j < valueCount; j++) { | |
129 | yValue = yValue + (qreal) (qrand() % valueMax) / (qreal) valueCount; |
|
129 | yValue = yValue + (qreal) (qrand() % valueMax) / (qreal) valueCount; | |
130 | QPointF value((j + (qreal) rand() / (qreal) RAND_MAX) * ((qreal) m_valueMax / (qreal) valueCount), |
|
130 | QPointF value((j + (qreal) rand() / (qreal) RAND_MAX) * ((qreal) m_valueMax / (qreal) valueCount), | |
131 | yValue); |
|
131 | yValue); | |
132 |
QString label = " |
|
132 | QString label = "Slice " + QString::number(i) + ":" + QString::number(j); | |
133 | dataList << Data(value, label); |
|
133 | dataList << Data(value, label); | |
134 | } |
|
134 | } | |
135 | dataTable << dataList; |
|
135 | dataTable << dataList; | |
136 | } |
|
136 | } | |
137 |
|
137 | |||
138 | return dataTable; |
|
138 | return dataTable; | |
139 | } |
|
139 | } | |
140 |
|
140 | |||
141 | QComboBox* ThemeWidget::createThemeBox() const |
|
141 | QComboBox* ThemeWidget::createThemeBox() const | |
142 | { |
|
142 | { | |
143 | // settings layout |
|
143 | // settings layout | |
144 | QComboBox* themeComboBox = new QComboBox(); |
|
144 | QComboBox* themeComboBox = new QComboBox(); | |
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("No Legend ", 0); |
|
169 | legendComboBox->addItem("No Legend ", 0); | |
170 | legendComboBox->addItem("Legend Top", QLegend::AlignmentTop); |
|
170 | legendComboBox->addItem("Legend Top", QLegend::AlignmentTop); | |
171 | legendComboBox->addItem("Legend Bottom", QLegend::AlignmentBottom); |
|
171 | legendComboBox->addItem("Legend Bottom", QLegend::AlignmentBottom); | |
172 | legendComboBox->addItem("Legend Left", QLegend::AlignmentLeft); |
|
172 | legendComboBox->addItem("Legend Left", QLegend::AlignmentLeft); | |
173 | legendComboBox->addItem("Legend Right", QLegend::AlignmentRight); |
|
173 | legendComboBox->addItem("Legend Right", QLegend::AlignmentRight); | |
174 | return legendComboBox; |
|
174 | return legendComboBox; | |
175 | } |
|
175 | } | |
176 |
|
176 | |||
177 | QChart* ThemeWidget::createAreaChart() const |
|
177 | QChart* ThemeWidget::createAreaChart() const | |
178 | { |
|
178 | { | |
179 | // area chart |
|
179 | // area chart | |
180 | QChart *chart = new QChart(); |
|
180 | QChart *chart = new QChart(); | |
181 | chart->axisX()->setNiceNumbers(true); |
|
181 | chart->axisX()->setNiceNumbers(true); | |
182 | chart->axisY()->setNiceNumbers(true); |
|
182 | chart->axisY()->setNiceNumbers(true); | |
183 | chart->setTitle("Area chart"); |
|
183 | chart->setTitle("Area chart"); | |
184 | QString name("Series "); |
|
184 | QString name("Series "); | |
185 | int nameIndex = 0; |
|
185 | int nameIndex = 0; | |
186 |
|
186 | |||
187 | // The lower series initialized to zero values |
|
187 | // The lower series initialized to zero values | |
188 | QLineSeries *lowerSeries = 0; |
|
188 | QLineSeries *lowerSeries = 0; | |
189 | for (int i(0); i < m_dataTable.count(); i++) { |
|
189 | for (int i(0); i < m_dataTable.count(); i++) { | |
190 | QLineSeries *upperSeries = new QLineSeries(chart); |
|
190 | QLineSeries *upperSeries = new QLineSeries(chart); | |
191 | for (int j(0); j < m_dataTable[i].count(); j++) { |
|
191 | for (int j(0); j < m_dataTable[i].count(); j++) { | |
192 | Data data = m_dataTable[i].at(j); |
|
192 | Data data = m_dataTable[i].at(j); | |
193 | if (lowerSeries) |
|
193 | if (lowerSeries) | |
194 | upperSeries->append(QPointF(j, lowerSeries->y(i) + data.first.y())); |
|
194 | upperSeries->append(QPointF(j, lowerSeries->y(i) + data.first.y())); | |
195 | else |
|
195 | else | |
196 | upperSeries->append(QPointF(j, data.first.y())); |
|
196 | upperSeries->append(QPointF(j, data.first.y())); | |
197 | } |
|
197 | } | |
198 | QAreaSeries *area = new QAreaSeries(upperSeries, lowerSeries); |
|
198 | QAreaSeries *area = new QAreaSeries(upperSeries, lowerSeries); | |
199 | area->setName(name + QString::number(nameIndex)); |
|
199 | area->setName(name + QString::number(nameIndex)); | |
200 | nameIndex++; |
|
200 | nameIndex++; | |
201 | chart->addSeries(area); |
|
201 | chart->addSeries(area); | |
202 | lowerSeries = upperSeries; |
|
202 | lowerSeries = upperSeries; | |
203 | } |
|
203 | } | |
204 | return chart; |
|
204 | return chart; | |
205 | } |
|
205 | } | |
206 |
|
206 | |||
207 | QChart* ThemeWidget::createBarChart(int valueCount) const |
|
207 | QChart* ThemeWidget::createBarChart(int valueCount) const | |
208 | { |
|
208 | { | |
209 | // bar chart |
|
209 | // bar chart | |
210 | QChart* chart = new QChart(); |
|
210 | QChart* chart = new QChart(); | |
211 | chart->axisX()->setNiceNumbers(true); |
|
211 | chart->axisX()->setNiceNumbers(true); | |
212 | chart->axisY()->setNiceNumbers(true); |
|
212 | chart->axisY()->setNiceNumbers(true); | |
213 | chart->setTitle("Bar chart"); |
|
213 | chart->setTitle("Bar chart"); | |
214 | QBarCategories categories; |
|
214 | QBarCategories categories; | |
215 | // TODO: categories |
|
215 | // TODO: categories | |
216 | for (int i(0); i < valueCount; i++) |
|
216 | for (int i(0); i < valueCount; i++) | |
217 | categories << QString::number(i); |
|
217 | categories << QString::number(i); | |
218 | // QBarSeries* series = new QBarSeries(categories, chart); |
|
218 | // QBarSeries* series = new QBarSeries(categories, chart); | |
219 | // QPercentBarSeries* series = new QPercentBarSeries(categories, chart); |
|
219 | // QPercentBarSeries* series = new QPercentBarSeries(categories, chart); | |
220 | QStackedBarSeries* series = new QStackedBarSeries(categories, chart); |
|
220 | QStackedBarSeries* series = new QStackedBarSeries(categories, chart); | |
221 | for (int i(0); i < m_dataTable.count(); i++) { |
|
221 | for (int i(0); i < m_dataTable.count(); i++) { | |
222 |
QBarSet *set = new QBarSet(" |
|
222 | QBarSet *set = new QBarSet("Bar set " + QString::number(i)); | |
223 | foreach (Data data, m_dataTable[i]) |
|
223 | foreach (Data data, m_dataTable[i]) | |
224 | *set << data.first.y(); |
|
224 | *set << data.first.y(); | |
225 | series->appendBarSet(set); |
|
225 | series->appendBarSet(set); | |
226 | } |
|
226 | } | |
227 | chart->addSeries(series); |
|
227 | chart->addSeries(series); | |
228 | return chart; |
|
228 | return chart; | |
229 | } |
|
229 | } | |
230 |
|
230 | |||
231 | QChart* ThemeWidget::createLineChart() const |
|
231 | QChart* ThemeWidget::createLineChart() const | |
232 | { |
|
232 | { | |
233 | // line chart |
|
233 | // line chart | |
234 | QChart* chart = new QChart(); |
|
234 | QChart* chart = new QChart(); | |
235 | chart->axisX()->setNiceNumbers(true); |
|
235 | chart->axisX()->setNiceNumbers(true); | |
236 | chart->axisY()->setNiceNumbers(true); |
|
236 | chart->axisY()->setNiceNumbers(true); | |
237 | chart->setTitle("Line chart"); |
|
237 | chart->setTitle("Line chart"); | |
238 | QString name("Series "); |
|
238 | QString name("Series "); | |
239 | int nameIndex = 0; |
|
239 | int nameIndex = 0; | |
240 | foreach (DataList list, m_dataTable) { |
|
240 | foreach (DataList list, m_dataTable) { | |
241 | QLineSeries *series = new QLineSeries(chart); |
|
241 | QLineSeries *series = new QLineSeries(chart); | |
242 | foreach (Data data, list) |
|
242 | foreach (Data data, list) | |
243 | series->append(data.first); |
|
243 | series->append(data.first); | |
244 | series->setName(name + QString::number(nameIndex)); |
|
244 | series->setName(name + QString::number(nameIndex)); | |
245 | nameIndex++; |
|
245 | nameIndex++; | |
246 | chart->addSeries(series); |
|
246 | chart->addSeries(series); | |
247 | } |
|
247 | } | |
248 | return chart; |
|
248 | return chart; | |
249 | } |
|
249 | } | |
250 |
|
250 | |||
251 | QChart* ThemeWidget::createPieChart() const |
|
251 | QChart* ThemeWidget::createPieChart() const | |
252 | { |
|
252 | { | |
253 | // pie chart |
|
253 | // pie chart | |
254 | QChart* chart = new QChart(); |
|
254 | QChart* chart = new QChart(); | |
255 | chart->setTitle("Pie chart"); |
|
255 | chart->setTitle("Pie chart"); | |
256 | qreal pieSize = 1.0 / m_dataTable.count(); |
|
256 | qreal pieSize = 1.0 / m_dataTable.count(); | |
257 | for (int i = 0; i < m_dataTable.count(); i++) { |
|
257 | for (int i = 0; i < m_dataTable.count(); i++) { | |
258 | QPieSeries *series = new QPieSeries(chart); |
|
258 | QPieSeries *series = new QPieSeries(chart); | |
259 | foreach (Data data, m_dataTable[i]) { |
|
259 | foreach (Data data, m_dataTable[i]) { | |
260 | QPieSlice *slice = series->append(data.first.y(), data.second); |
|
260 | QPieSlice *slice = series->append(data.first.y(), data.second); | |
261 | if (data == m_dataTable[i].first()) { |
|
261 | if (data == m_dataTable[i].first()) { | |
262 | slice->setLabelVisible(); |
|
262 | slice->setLabelVisible(); | |
263 | slice->setExploded(); |
|
263 | slice->setExploded(); | |
264 | } |
|
264 | } | |
265 | } |
|
265 | } | |
266 | qreal hPos = (pieSize / 2) + (i / (qreal) m_dataTable.count()); |
|
266 | qreal hPos = (pieSize / 2) + (i / (qreal) m_dataTable.count()); | |
267 | series->setPieSize(pieSize); |
|
267 | series->setPieSize(pieSize); | |
268 | series->setHorizontalPosition(hPos); |
|
268 | series->setHorizontalPosition(hPos); | |
269 | series->setVerticalPosition(0.5); |
|
269 | series->setVerticalPosition(0.5); | |
270 | chart->addSeries(series); |
|
270 | chart->addSeries(series); | |
271 | } |
|
271 | } | |
272 |
|
272 | |||
273 | return chart; |
|
273 | return chart; | |
274 | } |
|
274 | } | |
275 |
|
275 | |||
276 | QChart* ThemeWidget::createSplineChart() const |
|
276 | QChart* ThemeWidget::createSplineChart() const | |
277 | { // spine chart |
|
277 | { // spine chart | |
278 | QChart* chart = new QChart(); |
|
278 | QChart* chart = new QChart(); | |
279 | chart->axisX()->setNiceNumbers(true); |
|
279 | chart->axisX()->setNiceNumbers(true); | |
280 | chart->axisY()->setNiceNumbers(true); |
|
280 | chart->axisY()->setNiceNumbers(true); | |
281 | chart->setTitle("Spline chart"); |
|
281 | chart->setTitle("Spline chart"); | |
282 | QString name("Series "); |
|
282 | QString name("Series "); | |
283 | int nameIndex = 0; |
|
283 | int nameIndex = 0; | |
284 | foreach (DataList list, m_dataTable) { |
|
284 | foreach (DataList list, m_dataTable) { | |
285 | QSplineSeries *series = new QSplineSeries(chart); |
|
285 | QSplineSeries *series = new QSplineSeries(chart); | |
286 | foreach (Data data, list) |
|
286 | foreach (Data data, list) | |
287 | series->append(data.first); |
|
287 | series->append(data.first); | |
288 | series->setName(name + QString::number(nameIndex)); |
|
288 | series->setName(name + QString::number(nameIndex)); | |
289 | nameIndex++; |
|
289 | nameIndex++; | |
290 | chart->addSeries(series); |
|
290 | chart->addSeries(series); | |
291 | } |
|
291 | } | |
292 | return chart; |
|
292 | return chart; | |
293 | } |
|
293 | } | |
294 |
|
294 | |||
295 | QChart* ThemeWidget::createScatterChart() const |
|
295 | QChart* ThemeWidget::createScatterChart() const | |
296 | { // scatter chart |
|
296 | { // scatter chart | |
297 | QChart* chart = new QChart(); |
|
297 | QChart* chart = new QChart(); | |
298 | chart->axisX()->setNiceNumbers(true); |
|
298 | chart->axisX()->setNiceNumbers(true); | |
299 | chart->axisY()->setNiceNumbers(true); |
|
299 | chart->axisY()->setNiceNumbers(true); | |
300 | chart->setTitle("Scatter chart"); |
|
300 | chart->setTitle("Scatter chart"); | |
301 | QString name("Series "); |
|
301 | QString name("Series "); | |
302 | int nameIndex = 0; |
|
302 | int nameIndex = 0; | |
303 | foreach (DataList list, m_dataTable) { |
|
303 | foreach (DataList list, m_dataTable) { | |
304 | QScatterSeries *series = new QScatterSeries(chart); |
|
304 | QScatterSeries *series = new QScatterSeries(chart); | |
305 | foreach (Data data, list) |
|
305 | foreach (Data data, list) | |
306 | series->append(data.first); |
|
306 | series->append(data.first); | |
307 | series->setName(name + QString::number(nameIndex)); |
|
307 | series->setName(name + QString::number(nameIndex)); | |
308 | nameIndex++; |
|
308 | nameIndex++; | |
309 | chart->addSeries(series); |
|
309 | chart->addSeries(series); | |
310 | } |
|
310 | } | |
311 | return chart; |
|
311 | return chart; | |
312 | } |
|
312 | } | |
313 |
|
313 | |||
314 | void ThemeWidget::updateUI() |
|
314 | void ThemeWidget::updateUI() | |
315 | { |
|
315 | { | |
316 | QChart::ChartTheme theme = (QChart::ChartTheme) m_themeComboBox->itemData(m_themeComboBox->currentIndex()).toInt(); |
|
316 | QChart::ChartTheme theme = (QChart::ChartTheme) m_themeComboBox->itemData(m_themeComboBox->currentIndex()).toInt(); | |
317 |
|
317 | |||
318 | if (m_charts.at(0)->chart()->theme() != theme) { |
|
318 | if (m_charts.at(0)->chart()->theme() != theme) { | |
319 | foreach (QChartView *chartView, m_charts) |
|
319 | foreach (QChartView *chartView, m_charts) | |
320 | chartView->chart()->setTheme(theme); |
|
320 | chartView->chart()->setTheme(theme); | |
321 |
|
321 | |||
322 | QPalette pal = window()->palette(); |
|
322 | QPalette pal = window()->palette(); | |
323 | if (theme == QChart::ChartThemeLight) { |
|
323 | if (theme == QChart::ChartThemeLight) { | |
324 | pal.setColor(QPalette::Window, QRgb(0xf0f0f0)); |
|
324 | pal.setColor(QPalette::Window, QRgb(0xf0f0f0)); | |
325 | pal.setColor(QPalette::WindowText, QRgb(0x404044)); |
|
325 | pal.setColor(QPalette::WindowText, QRgb(0x404044)); | |
326 | } else if (theme == QChart::ChartThemeDark) { |
|
326 | } else if (theme == QChart::ChartThemeDark) { | |
327 | pal.setColor(QPalette::Window, QRgb(0x121218)); |
|
327 | pal.setColor(QPalette::Window, QRgb(0x121218)); | |
328 | pal.setColor(QPalette::WindowText, QRgb(0xd6d6d6)); |
|
328 | pal.setColor(QPalette::WindowText, QRgb(0xd6d6d6)); | |
329 | } else if (theme == QChart::ChartThemeBlueCerulean) { |
|
329 | } else if (theme == QChart::ChartThemeBlueCerulean) { | |
330 | pal.setColor(QPalette::Window, QRgb(0x40434a)); |
|
330 | pal.setColor(QPalette::Window, QRgb(0x40434a)); | |
331 | pal.setColor(QPalette::WindowText, QRgb(0xd6d6d6)); |
|
331 | pal.setColor(QPalette::WindowText, QRgb(0xd6d6d6)); | |
332 | } else if (theme == QChart::ChartThemeBrownSand) { |
|
332 | } else if (theme == QChart::ChartThemeBrownSand) { | |
333 | pal.setColor(QPalette::Window, QRgb(0x9e8965)); |
|
333 | pal.setColor(QPalette::Window, QRgb(0x9e8965)); | |
334 | pal.setColor(QPalette::WindowText, QRgb(0x404044)); |
|
334 | pal.setColor(QPalette::WindowText, QRgb(0x404044)); | |
335 | } else if (theme == QChart::ChartThemeBlueNcs) { |
|
335 | } else if (theme == QChart::ChartThemeBlueNcs) { | |
336 | pal.setColor(QPalette::Window, QRgb(0x018bba)); |
|
336 | pal.setColor(QPalette::Window, QRgb(0x018bba)); | |
337 | pal.setColor(QPalette::WindowText, QRgb(0x404044)); |
|
337 | pal.setColor(QPalette::WindowText, QRgb(0x404044)); | |
338 | } else if (theme == QChart::ChartThemeHighContrast) { |
|
338 | } else if (theme == QChart::ChartThemeHighContrast) { | |
339 | pal.setColor(QPalette::Window, QRgb(0xffab03)); |
|
339 | pal.setColor(QPalette::Window, QRgb(0xffab03)); | |
340 | pal.setColor(QPalette::WindowText, QRgb(0x181818)); |
|
340 | pal.setColor(QPalette::WindowText, QRgb(0x181818)); | |
341 | } else if (theme == QChart::ChartThemeBlueIcy) { |
|
341 | } else if (theme == QChart::ChartThemeBlueIcy) { | |
342 | pal.setColor(QPalette::Window, QRgb(0xcee7f0)); |
|
342 | pal.setColor(QPalette::Window, QRgb(0xcee7f0)); | |
343 | pal.setColor(QPalette::WindowText, QRgb(0x404044)); |
|
343 | pal.setColor(QPalette::WindowText, QRgb(0x404044)); | |
344 | } else { |
|
344 | } else { | |
345 | pal.setColor(QPalette::Window, QRgb(0xf0f0f0)); |
|
345 | pal.setColor(QPalette::Window, QRgb(0xf0f0f0)); | |
346 | pal.setColor(QPalette::WindowText, QRgb(0x404044)); |
|
346 | pal.setColor(QPalette::WindowText, QRgb(0x404044)); | |
347 | } |
|
347 | } | |
348 | window()->setPalette(pal); |
|
348 | window()->setPalette(pal); | |
349 | } |
|
349 | } | |
350 |
|
350 | |||
351 | bool checked = m_antialiasCheckBox->isChecked(); |
|
351 | bool checked = m_antialiasCheckBox->isChecked(); | |
352 | foreach (QChartView *chart, m_charts) |
|
352 | foreach (QChartView *chart, m_charts) | |
353 | chart->setRenderHint(QPainter::Antialiasing, checked); |
|
353 | chart->setRenderHint(QPainter::Antialiasing, checked); | |
354 |
|
354 | |||
355 | QChart::AnimationOptions options(m_animatedComboBox->itemData(m_animatedComboBox->currentIndex()).toInt()); |
|
355 | QChart::AnimationOptions options(m_animatedComboBox->itemData(m_animatedComboBox->currentIndex()).toInt()); | |
356 | if (m_charts.at(0)->chart()->animationOptions() != options) { |
|
356 | if (m_charts.at(0)->chart()->animationOptions() != options) { | |
357 | foreach (QChartView *chartView, m_charts) |
|
357 | foreach (QChartView *chartView, m_charts) | |
358 | chartView->chart()->setAnimationOptions(options); |
|
358 | chartView->chart()->setAnimationOptions(options); | |
359 | } |
|
359 | } | |
360 |
|
360 | |||
361 | QLegend::Alignments alignment(m_legendComboBox->itemData(m_legendComboBox->currentIndex()).toInt()); |
|
361 | QLegend::Alignments alignment(m_legendComboBox->itemData(m_legendComboBox->currentIndex()).toInt()); | |
362 |
|
362 | |||
363 | if (!alignment) { |
|
363 | if (!alignment) { | |
364 | foreach (QChartView *chartView, m_charts) { |
|
364 | foreach (QChartView *chartView, m_charts) { | |
365 | chartView->chart()->legend()->hide(); |
|
365 | chartView->chart()->legend()->hide(); | |
366 | } |
|
366 | } | |
367 | } |
|
367 | } | |
368 | else |
|
368 | else | |
369 | foreach (QChartView *chartView, m_charts) { |
|
369 | foreach (QChartView *chartView, m_charts) { | |
370 | chartView->chart()->legend()->setAlignment(alignment); |
|
370 | chartView->chart()->legend()->setAlignment(alignment); | |
371 | chartView->chart()->legend()->show(); |
|
371 | chartView->chart()->legend()->show(); | |
372 | } |
|
372 | } | |
373 | } |
|
373 | } | |
374 |
|
374 |
General Comments 0
You need to be logged in to leave comments.
Login now