##// END OF EJS Templates
Fix compilation with GCC 6...
Marc Mutz -
r2872:9c63b5bda170
parent child
Show More
@@ -1,380 +1,380
1 /******************************************************************************
1 /******************************************************************************
2 **
2 **
3 ** Copyright (C) 2015 The Qt Company Ltd.
3 ** Copyright (C) 2015 The Qt Company Ltd.
4 ** Contact: http://www.qt.io/licensing/
4 ** Contact: http://www.qt.io/licensing/
5 **
5 **
6 ** This file is part of the Qt Charts module.
6 ** This file is part of the Qt Charts module.
7 **
7 **
8 ** $QT_BEGIN_LICENSE:COMM$
8 ** $QT_BEGIN_LICENSE:COMM$
9 **
9 **
10 ** Commercial License Usage
10 ** Commercial License Usage
11 ** Licensees holding valid commercial Qt licenses may use this file in
11 ** Licensees holding valid commercial Qt licenses may use this file in
12 ** accordance with the commercial license agreement provided with the
12 ** accordance with the commercial license agreement provided with the
13 ** Software or, alternatively, in accordance with the terms contained in
13 ** Software or, alternatively, in accordance with the terms contained in
14 ** a written agreement between you and The Qt Company. For licensing terms
14 ** a written agreement between you and The Qt Company. For licensing terms
15 ** and conditions see http://www.qt.io/terms-conditions. For further
15 ** and conditions see http://www.qt.io/terms-conditions. For further
16 ** information use the contact form at http://www.qt.io/contact-us.
16 ** information use the contact form at http://www.qt.io/contact-us.
17 **
17 **
18 ** $QT_END_LICENSE$
18 ** $QT_END_LICENSE$
19 **
19 **
20 ******************************************************************************/
20 ******************************************************************************/
21
21
22 #include "mainwidget.h"
22 #include "mainwidget.h"
23 #include "dataseriedialog.h"
23 #include "dataseriedialog.h"
24 #include <QtCharts/QChartView>
24 #include <QtCharts/QChartView>
25 #include <QtCharts/QPieSeries>
25 #include <QtCharts/QPieSeries>
26 #include <QtCharts/QScatterSeries>
26 #include <QtCharts/QScatterSeries>
27 #include <QtCharts/QLineSeries>
27 #include <QtCharts/QLineSeries>
28 #include <QtCharts/QAreaSeries>
28 #include <QtCharts/QAreaSeries>
29 #include <QtCharts/QSplineSeries>
29 #include <QtCharts/QSplineSeries>
30 #include <QtCharts/QBarSet>
30 #include <QtCharts/QBarSet>
31 #include <QtCharts/QBarSeries>
31 #include <QtCharts/QBarSeries>
32 #include <QtCharts/QStackedBarSeries>
32 #include <QtCharts/QStackedBarSeries>
33 #include <QtCharts/QPercentBarSeries>
33 #include <QtCharts/QPercentBarSeries>
34 #include <QtWidgets/QPushButton>
34 #include <QtWidgets/QPushButton>
35 #include <QtWidgets/QComboBox>
35 #include <QtWidgets/QComboBox>
36 #include <QtWidgets/QSpinBox>
36 #include <QtWidgets/QSpinBox>
37 #include <QtWidgets/QCheckBox>
37 #include <QtWidgets/QCheckBox>
38 #include <QtWidgets/QGridLayout>
38 #include <QtWidgets/QGridLayout>
39 #include <QtWidgets/QHBoxLayout>
39 #include <QtWidgets/QHBoxLayout>
40 #include <QtWidgets/QLabel>
40 #include <QtWidgets/QLabel>
41 #include <QtWidgets/QSpacerItem>
41 #include <QtWidgets/QSpacerItem>
42 #include <QtWidgets/QMessageBox>
42 #include <QtWidgets/QMessageBox>
43 #include <cmath>
43 #include <cmath>
44 #include <QtCore/QDebug>
44 #include <QtCore/QDebug>
45 #include <QtGui/QStandardItemModel>
45 #include <QtGui/QStandardItemModel>
46 #include <QtCharts/QBarCategoryAxis>
46 #include <QtCharts/QBarCategoryAxis>
47 #include <QtWidgets/QOpenGLWidget>
47 #include <QtWidgets/QOpenGLWidget>
48
48
49 QT_CHARTS_USE_NAMESPACE
49 QT_CHARTS_USE_NAMESPACE
50
50
51 MainWidget::MainWidget(QWidget *parent) :
51 MainWidget::MainWidget(QWidget *parent) :
52 QWidget(parent),
52 QWidget(parent),
53 m_addSerieDialog(0),
53 m_addSerieDialog(0),
54 m_chart(0)
54 m_chart(0)
55 {
55 {
56 m_chart = new QChart();
56 m_chart = new QChart();
57
57
58 // Grid layout for the controls for configuring the chart widget
58 // Grid layout for the controls for configuring the chart widget
59 QGridLayout *grid = new QGridLayout();
59 QGridLayout *grid = new QGridLayout();
60 QPushButton *addSeriesButton = new QPushButton("Add series");
60 QPushButton *addSeriesButton = new QPushButton("Add series");
61 connect(addSeriesButton, SIGNAL(clicked()), this, SLOT(addSeries()));
61 connect(addSeriesButton, SIGNAL(clicked()), this, SLOT(addSeries()));
62 grid->addWidget(addSeriesButton, 0, 1);
62 grid->addWidget(addSeriesButton, 0, 1);
63 initBackroundCombo(grid);
63 initBackroundCombo(grid);
64 initScaleControls(grid);
64 initScaleControls(grid);
65 initThemeCombo(grid);
65 initThemeCombo(grid);
66 initCheckboxes(grid);
66 initCheckboxes(grid);
67
67
68 // add row with empty label to make all the other rows static
68 // add row with empty label to make all the other rows static
69 grid->addWidget(new QLabel(""), grid->rowCount(), 0);
69 grid->addWidget(new QLabel(""), grid->rowCount(), 0);
70 grid->setRowStretch(grid->rowCount() - 1, 1);
70 grid->setRowStretch(grid->rowCount() - 1, 1);
71
71
72 // Create chart view with the chart
72 // Create chart view with the chart
73 m_chartView = new QChartView(m_chart, this);
73 m_chartView = new QChartView(m_chart, this);
74 m_chartView->setRubberBand(QChartView::HorizontalRubberBand);
74 m_chartView->setRubberBand(QChartView::HorizontalRubberBand);
75
75
76 // Another grid layout as a main layout
76 // Another grid layout as a main layout
77 QGridLayout *mainLayout = new QGridLayout();
77 QGridLayout *mainLayout = new QGridLayout();
78 mainLayout->addLayout(grid, 0, 0);
78 mainLayout->addLayout(grid, 0, 0);
79 mainLayout->addWidget(m_chartView, 0, 1, 3, 1);
79 mainLayout->addWidget(m_chartView, 0, 1, 3, 1);
80 setLayout(mainLayout);
80 setLayout(mainLayout);
81 }
81 }
82
82
83 // Combo box for selecting the chart's background
83 // Combo box for selecting the chart's background
84 void MainWidget::initBackroundCombo(QGridLayout *grid)
84 void MainWidget::initBackroundCombo(QGridLayout *grid)
85 {
85 {
86 QComboBox *backgroundCombo = new QComboBox(this);
86 QComboBox *backgroundCombo = new QComboBox(this);
87 backgroundCombo->addItem("Color");
87 backgroundCombo->addItem("Color");
88 backgroundCombo->addItem("Gradient");
88 backgroundCombo->addItem("Gradient");
89 backgroundCombo->addItem("Image");
89 backgroundCombo->addItem("Image");
90 connect(backgroundCombo, SIGNAL(currentIndexChanged(int)),
90 connect(backgroundCombo, SIGNAL(currentIndexChanged(int)),
91 this, SLOT(backgroundChanged(int)));
91 this, SLOT(backgroundChanged(int)));
92
92
93 grid->addWidget(new QLabel("Background:"), grid->rowCount(), 0);
93 grid->addWidget(new QLabel("Background:"), grid->rowCount(), 0);
94 grid->addWidget(backgroundCombo, grid->rowCount() - 1, 1);
94 grid->addWidget(backgroundCombo, grid->rowCount() - 1, 1);
95 }
95 }
96
96
97 // Scale related controls (auto-scale vs. manual min-max values)
97 // Scale related controls (auto-scale vs. manual min-max values)
98 void MainWidget::initScaleControls(QGridLayout *grid)
98 void MainWidget::initScaleControls(QGridLayout *grid)
99 {
99 {
100 m_autoScaleCheck = new QCheckBox("Automatic scaling");
100 m_autoScaleCheck = new QCheckBox("Automatic scaling");
101 connect(m_autoScaleCheck, SIGNAL(stateChanged(int)), this, SLOT(autoScaleChanged(int)));
101 connect(m_autoScaleCheck, SIGNAL(stateChanged(int)), this, SLOT(autoScaleChanged(int)));
102 // Allow setting also non-sense values (like -2147483648 and 2147483647)
102 // Allow setting also non-sense values (like -2147483648 and 2147483647)
103 m_xMinSpin = new QSpinBox();
103 m_xMinSpin = new QSpinBox();
104 m_xMinSpin->setMinimum(INT_MIN);
104 m_xMinSpin->setMinimum(INT_MIN);
105 m_xMinSpin->setMaximum(INT_MAX);
105 m_xMinSpin->setMaximum(INT_MAX);
106 m_xMinSpin->setValue(0);
106 m_xMinSpin->setValue(0);
107 connect(m_xMinSpin, SIGNAL(valueChanged(int)), this, SLOT(xMinChanged(int)));
107 connect(m_xMinSpin, SIGNAL(valueChanged(int)), this, SLOT(xMinChanged(int)));
108 m_xMaxSpin = new QSpinBox();
108 m_xMaxSpin = new QSpinBox();
109 m_xMaxSpin->setMinimum(INT_MIN);
109 m_xMaxSpin->setMinimum(INT_MIN);
110 m_xMaxSpin->setMaximum(INT_MAX);
110 m_xMaxSpin->setMaximum(INT_MAX);
111 m_xMaxSpin->setValue(10);
111 m_xMaxSpin->setValue(10);
112 connect(m_xMaxSpin, SIGNAL(valueChanged(int)), this, SLOT(xMaxChanged(int)));
112 connect(m_xMaxSpin, SIGNAL(valueChanged(int)), this, SLOT(xMaxChanged(int)));
113 m_yMinSpin = new QSpinBox();
113 m_yMinSpin = new QSpinBox();
114 m_yMinSpin->setMinimum(INT_MIN);
114 m_yMinSpin->setMinimum(INT_MIN);
115 m_yMinSpin->setMaximum(INT_MAX);
115 m_yMinSpin->setMaximum(INT_MAX);
116 m_yMinSpin->setValue(0);
116 m_yMinSpin->setValue(0);
117 connect(m_yMinSpin, SIGNAL(valueChanged(int)), this, SLOT(yMinChanged(int)));
117 connect(m_yMinSpin, SIGNAL(valueChanged(int)), this, SLOT(yMinChanged(int)));
118 m_yMaxSpin = new QSpinBox();
118 m_yMaxSpin = new QSpinBox();
119 m_yMaxSpin->setMinimum(INT_MIN);
119 m_yMaxSpin->setMinimum(INT_MIN);
120 m_yMaxSpin->setMaximum(INT_MAX);
120 m_yMaxSpin->setMaximum(INT_MAX);
121 m_yMaxSpin->setValue(10);
121 m_yMaxSpin->setValue(10);
122 connect(m_yMaxSpin, SIGNAL(valueChanged(int)), this, SLOT(yMaxChanged(int)));
122 connect(m_yMaxSpin, SIGNAL(valueChanged(int)), this, SLOT(yMaxChanged(int)));
123
123
124 grid->addWidget(m_autoScaleCheck, grid->rowCount(), 0);
124 grid->addWidget(m_autoScaleCheck, grid->rowCount(), 0);
125 grid->addWidget(new QLabel("x min:"), grid->rowCount(), 0);
125 grid->addWidget(new QLabel("x min:"), grid->rowCount(), 0);
126 grid->addWidget(m_xMinSpin, grid->rowCount() - 1, 1);
126 grid->addWidget(m_xMinSpin, grid->rowCount() - 1, 1);
127 grid->addWidget(new QLabel("x max:"), grid->rowCount(), 0);
127 grid->addWidget(new QLabel("x max:"), grid->rowCount(), 0);
128 grid->addWidget(m_xMaxSpin, grid->rowCount() - 1, 1);
128 grid->addWidget(m_xMaxSpin, grid->rowCount() - 1, 1);
129 grid->addWidget(new QLabel("y min:"), grid->rowCount(), 0);
129 grid->addWidget(new QLabel("y min:"), grid->rowCount(), 0);
130 grid->addWidget(m_yMinSpin, grid->rowCount() - 1, 1);
130 grid->addWidget(m_yMinSpin, grid->rowCount() - 1, 1);
131 grid->addWidget(new QLabel("y max:"), grid->rowCount(), 0);
131 grid->addWidget(new QLabel("y max:"), grid->rowCount(), 0);
132 grid->addWidget(m_yMaxSpin, grid->rowCount() - 1, 1);
132 grid->addWidget(m_yMaxSpin, grid->rowCount() - 1, 1);
133
133
134 m_autoScaleCheck->setChecked(true);
134 m_autoScaleCheck->setChecked(true);
135 }
135 }
136
136
137 // Combo box for selecting theme
137 // Combo box for selecting theme
138 void MainWidget::initThemeCombo(QGridLayout *grid)
138 void MainWidget::initThemeCombo(QGridLayout *grid)
139 {
139 {
140 QComboBox *chartTheme = new QComboBox();
140 QComboBox *chartTheme = new QComboBox();
141 chartTheme->addItem("Default");
141 chartTheme->addItem("Default");
142 chartTheme->addItem("Light");
142 chartTheme->addItem("Light");
143 chartTheme->addItem("Blue Cerulean");
143 chartTheme->addItem("Blue Cerulean");
144 chartTheme->addItem("Dark");
144 chartTheme->addItem("Dark");
145 chartTheme->addItem("Brown Sand");
145 chartTheme->addItem("Brown Sand");
146 chartTheme->addItem("Blue NCS");
146 chartTheme->addItem("Blue NCS");
147 chartTheme->addItem("High Contrast");
147 chartTheme->addItem("High Contrast");
148 chartTheme->addItem("Blue Icy");
148 chartTheme->addItem("Blue Icy");
149 chartTheme->addItem("Qt");
149 chartTheme->addItem("Qt");
150 connect(chartTheme, SIGNAL(currentIndexChanged(int)),
150 connect(chartTheme, SIGNAL(currentIndexChanged(int)),
151 this, SLOT(changeChartTheme(int)));
151 this, SLOT(changeChartTheme(int)));
152 grid->addWidget(new QLabel("Chart theme:"), 8, 0);
152 grid->addWidget(new QLabel("Chart theme:"), 8, 0);
153 grid->addWidget(chartTheme, 8, 1);
153 grid->addWidget(chartTheme, 8, 1);
154 }
154 }
155
155
156 // Different check boxes for customizing chart
156 // Different check boxes for customizing chart
157 void MainWidget::initCheckboxes(QGridLayout *grid)
157 void MainWidget::initCheckboxes(QGridLayout *grid)
158 {
158 {
159 // TODO: setZoomEnabled slot has been removed from QChartView -> Re-implement zoom on/off
159 // TODO: setZoomEnabled slot has been removed from QChartView -> Re-implement zoom on/off
160 QCheckBox *zoomCheckBox = new QCheckBox("Drag'n drop Zoom");
160 QCheckBox *zoomCheckBox = new QCheckBox("Drag'n drop Zoom");
161 // connect(zoomCheckBox, SIGNAL(toggled(bool)), m_chartView, SLOT(setZoomEnabled(bool)));
161 // connect(zoomCheckBox, SIGNAL(toggled(bool)), m_chartView, SLOT(setZoomEnabled(bool)));
162 zoomCheckBox->setChecked(true);
162 zoomCheckBox->setChecked(true);
163 grid->addWidget(zoomCheckBox, grid->rowCount(), 0);
163 grid->addWidget(zoomCheckBox, grid->rowCount(), 0);
164
164
165 QCheckBox *aliasCheckBox = new QCheckBox("Anti-alias");
165 QCheckBox *aliasCheckBox = new QCheckBox("Anti-alias");
166 connect(aliasCheckBox, SIGNAL(toggled(bool)), this, SLOT(antiAliasToggled(bool)));
166 connect(aliasCheckBox, SIGNAL(toggled(bool)), this, SLOT(antiAliasToggled(bool)));
167 aliasCheckBox->setChecked(false);
167 aliasCheckBox->setChecked(false);
168 grid->addWidget(aliasCheckBox, grid->rowCount(), 0);
168 grid->addWidget(aliasCheckBox, grid->rowCount(), 0);
169
169
170 QCheckBox *openGLCheckBox = new QCheckBox("Use QOpenGLWidget");
170 QCheckBox *openGLCheckBox = new QCheckBox("Use QOpenGLWidget");
171 connect(openGLCheckBox, SIGNAL(toggled(bool)), this, SLOT(openGLToggled(bool)));
171 connect(openGLCheckBox, SIGNAL(toggled(bool)), this, SLOT(openGLToggled(bool)));
172 openGLCheckBox->setChecked(false);
172 openGLCheckBox->setChecked(false);
173 grid->addWidget(openGLCheckBox, grid->rowCount(), 0);
173 grid->addWidget(openGLCheckBox, grid->rowCount(), 0);
174 }
174 }
175
175
176 void MainWidget::antiAliasToggled(bool enabled)
176 void MainWidget::antiAliasToggled(bool enabled)
177 {
177 {
178 m_chartView->setRenderHint(QPainter::Antialiasing, enabled);
178 m_chartView->setRenderHint(QPainter::Antialiasing, enabled);
179 }
179 }
180
180
181 void MainWidget::openGLToggled(bool enabled)
181 void MainWidget::openGLToggled(bool enabled)
182 {
182 {
183 if (enabled) {
183 if (enabled) {
184 QSurfaceFormat f = QSurfaceFormat::defaultFormat();
184 QSurfaceFormat f = QSurfaceFormat::defaultFormat();
185 f.setSamples(4);
185 f.setSamples(4);
186 QSurfaceFormat::setDefaultFormat(f);
186 QSurfaceFormat::setDefaultFormat(f);
187 QOpenGLWidget *g = new QOpenGLWidget();
187 QOpenGLWidget *g = new QOpenGLWidget();
188 m_chartView->setViewport(g);
188 m_chartView->setViewport(g);
189 } else {
189 } else {
190 m_chartView->setViewport(0);
190 m_chartView->setViewport(0);
191 }
191 }
192 }
192 }
193
193
194 void MainWidget::addSeries()
194 void MainWidget::addSeries()
195 {
195 {
196 if (!m_addSerieDialog) {
196 if (!m_addSerieDialog) {
197 m_addSerieDialog = new DataSerieDialog(this);
197 m_addSerieDialog = new DataSerieDialog(this);
198 connect(m_addSerieDialog, SIGNAL(accepted(QString,int,int,QString,bool)),
198 connect(m_addSerieDialog, SIGNAL(accepted(QString,int,int,QString,bool)),
199 this, SLOT(addSeries(QString,int,int,QString,bool)));
199 this, SLOT(addSeries(QString,int,int,QString,bool)));
200 }
200 }
201 m_addSerieDialog->exec();
201 m_addSerieDialog->exec();
202 }
202 }
203
203
204 QList<RealList> MainWidget::generateTestData(int columnCount, int rowCount, QString dataCharacteristics)
204 QList<RealList> MainWidget::generateTestData(int columnCount, int rowCount, QString dataCharacteristics)
205 {
205 {
206 QList<RealList> testData;
206 QList<RealList> testData;
207 for (int j(0); j < columnCount; j++) {
207 for (int j(0); j < columnCount; j++) {
208 QList <qreal> newColumn;
208 QList <qreal> newColumn;
209 for (int i(0); i < rowCount; i++) {
209 for (int i(0); i < rowCount; i++) {
210 if (dataCharacteristics == "Sin") {
210 if (dataCharacteristics == "Sin") {
211 newColumn.append(abs(sin(3.14159265358979 / 50 * i) * 100));
211 newColumn.append(std::abs(sin(3.14159265358979 / 50 * i) * 100));
212 } else if (dataCharacteristics == "Sin + random") {
212 } else if (dataCharacteristics == "Sin + random") {
213 newColumn.append(abs(sin(3.14159265358979 / 50 * i) * 100) + (rand() % 5));
213 newColumn.append(std::abs(sin(3.14159265358979 / 50 * i) * 100) + (rand() % 5));
214 } else if (dataCharacteristics == "Random") {
214 } else if (dataCharacteristics == "Random") {
215 newColumn.append(rand() % 10 + (qreal) rand() / (qreal) RAND_MAX);
215 newColumn.append(rand() % 10 + (qreal) rand() / (qreal) RAND_MAX);
216 } else if (dataCharacteristics == "Linear") {
216 } else if (dataCharacteristics == "Linear") {
217 //newColumn.append(i * (j + 1.0));
217 //newColumn.append(i * (j + 1.0));
218 // TODO: temporary hack to make pie work; prevent zero values:
218 // TODO: temporary hack to make pie work; prevent zero values:
219 newColumn.append(i * (j + 1.0) + 0.1);
219 newColumn.append(i * (j + 1.0) + 0.1);
220 } else { // "constant"
220 } else { // "constant"
221 newColumn.append((j + 1.0));
221 newColumn.append((j + 1.0));
222 }
222 }
223 }
223 }
224 testData.append(newColumn);
224 testData.append(newColumn);
225 }
225 }
226 return testData;
226 return testData;
227 }
227 }
228
228
229 QStringList MainWidget::generateLabels(int count)
229 QStringList MainWidget::generateLabels(int count)
230 {
230 {
231 QStringList result;
231 QStringList result;
232 for (int i(0); i < count; i++)
232 for (int i(0); i < count; i++)
233 result.append("label" + QString::number(i));
233 result.append("label" + QString::number(i));
234 return result;
234 return result;
235 }
235 }
236
236
237 void MainWidget::addSeries(QString seriesName, int columnCount, int rowCount, QString dataCharacteristics, bool labelsEnabled)
237 void MainWidget::addSeries(QString seriesName, int columnCount, int rowCount, QString dataCharacteristics, bool labelsEnabled)
238 {
238 {
239 qDebug() << "addSeries: " << seriesName
239 qDebug() << "addSeries: " << seriesName
240 << " columnCount: " << columnCount
240 << " columnCount: " << columnCount
241 << " rowCount: " << rowCount
241 << " rowCount: " << rowCount
242 << " dataCharacteristics: " << dataCharacteristics
242 << " dataCharacteristics: " << dataCharacteristics
243 << " labels enabled: " << labelsEnabled;
243 << " labels enabled: " << labelsEnabled;
244 m_defaultSeriesName = seriesName;
244 m_defaultSeriesName = seriesName;
245
245
246 QList<RealList> data = generateTestData(columnCount, rowCount, dataCharacteristics);
246 QList<RealList> data = generateTestData(columnCount, rowCount, dataCharacteristics);
247
247
248 // Line series and scatter series use similar data
248 // Line series and scatter series use similar data
249 if (seriesName == "Line") {
249 if (seriesName == "Line") {
250 for (int j(0); j < data.count(); j ++) {
250 for (int j(0); j < data.count(); j ++) {
251 QList<qreal> column = data.at(j);
251 QList<qreal> column = data.at(j);
252 QLineSeries *series = new QLineSeries();
252 QLineSeries *series = new QLineSeries();
253 series->setName("line" + QString::number(j));
253 series->setName("line" + QString::number(j));
254 for (int i(0); i < column.count(); i++)
254 for (int i(0); i < column.count(); i++)
255 series->append(i, column.at(i));
255 series->append(i, column.at(i));
256 m_chart->addSeries(series);
256 m_chart->addSeries(series);
257 }
257 }
258 } else if (seriesName == "Area") {
258 } else if (seriesName == "Area") {
259 // TODO: lower series for the area?
259 // TODO: lower series for the area?
260 for (int j(0); j < data.count(); j ++) {
260 for (int j(0); j < data.count(); j ++) {
261 QList<qreal> column = data.at(j);
261 QList<qreal> column = data.at(j);
262 QLineSeries *lineSeries = new QLineSeries();
262 QLineSeries *lineSeries = new QLineSeries();
263 for (int i(0); i < column.count(); i++)
263 for (int i(0); i < column.count(); i++)
264 lineSeries->append(i, column.at(i));
264 lineSeries->append(i, column.at(i));
265 QAreaSeries *areaSeries = new QAreaSeries(lineSeries);
265 QAreaSeries *areaSeries = new QAreaSeries(lineSeries);
266 areaSeries->setName("area" + QString::number(j));
266 areaSeries->setName("area" + QString::number(j));
267 m_chart->addSeries(areaSeries);
267 m_chart->addSeries(areaSeries);
268 }
268 }
269 } else if (seriesName == "Scatter") {
269 } else if (seriesName == "Scatter") {
270 for (int j(0); j < data.count(); j++) {
270 for (int j(0); j < data.count(); j++) {
271 QList<qreal> column = data.at(j);
271 QList<qreal> column = data.at(j);
272 QScatterSeries *series = new QScatterSeries();
272 QScatterSeries *series = new QScatterSeries();
273 series->setName("scatter" + QString::number(j));
273 series->setName("scatter" + QString::number(j));
274 for (int i(0); i < column.count(); i++)
274 for (int i(0); i < column.count(); i++)
275 series->append(i, column.at(i));
275 series->append(i, column.at(i));
276 m_chart->addSeries(series);
276 m_chart->addSeries(series);
277 }
277 }
278 } else if (seriesName == "Pie") {
278 } else if (seriesName == "Pie") {
279 QStringList labels = generateLabels(rowCount);
279 QStringList labels = generateLabels(rowCount);
280 for (int j(0); j < data.count(); j++) {
280 for (int j(0); j < data.count(); j++) {
281 QPieSeries *series = new QPieSeries();
281 QPieSeries *series = new QPieSeries();
282 QList<qreal> column = data.at(j);
282 QList<qreal> column = data.at(j);
283 for (int i(0); i < column.count(); i++)
283 for (int i(0); i < column.count(); i++)
284 series->append(labels.at(i), column.at(i));
284 series->append(labels.at(i), column.at(i));
285 m_chart->addSeries(series);
285 m_chart->addSeries(series);
286 }
286 }
287 } else if (seriesName == "Bar"
287 } else if (seriesName == "Bar"
288 || seriesName == "Stacked bar"
288 || seriesName == "Stacked bar"
289 || seriesName == "Percent bar") {
289 || seriesName == "Percent bar") {
290 QStringList category;
290 QStringList category;
291 QStringList labels = generateLabels(rowCount);
291 QStringList labels = generateLabels(rowCount);
292 foreach (QString label, labels)
292 foreach (QString label, labels)
293 category << label;
293 category << label;
294 QAbstractBarSeries* series = 0;
294 QAbstractBarSeries* series = 0;
295 if (seriesName == "Bar") {
295 if (seriesName == "Bar") {
296 series = new QBarSeries(this);
296 series = new QBarSeries(this);
297 QBarCategoryAxis* axis = new QBarCategoryAxis();
297 QBarCategoryAxis* axis = new QBarCategoryAxis();
298 axis->append(category);
298 axis->append(category);
299 m_chart->setAxisX(axis,series);
299 m_chart->setAxisX(axis,series);
300 } else if (seriesName == "Stacked bar") {
300 } else if (seriesName == "Stacked bar") {
301 series = new QStackedBarSeries(this);
301 series = new QStackedBarSeries(this);
302 QBarCategoryAxis* axis = new QBarCategoryAxis();
302 QBarCategoryAxis* axis = new QBarCategoryAxis();
303 axis->append(category);
303 axis->append(category);
304 m_chart->setAxisX(axis,series);
304 m_chart->setAxisX(axis,series);
305 } else {
305 } else {
306 series = new QPercentBarSeries(this);
306 series = new QPercentBarSeries(this);
307 QBarCategoryAxis* axis = new QBarCategoryAxis();
307 QBarCategoryAxis* axis = new QBarCategoryAxis();
308 axis->append(category);
308 axis->append(category);
309 m_chart->setAxisX(axis,series);
309 m_chart->setAxisX(axis,series);
310 }
310 }
311
311
312 for (int j(0); j < data.count(); j++) {
312 for (int j(0); j < data.count(); j++) {
313 QList<qreal> column = data.at(j);
313 QList<qreal> column = data.at(j);
314 QBarSet *set = new QBarSet("set" + QString::number(j));
314 QBarSet *set = new QBarSet("set" + QString::number(j));
315 for (int i(0); i < column.count(); i++)
315 for (int i(0); i < column.count(); i++)
316 *set << column.at(i);
316 *set << column.at(i);
317 series->append(set);
317 series->append(set);
318 }
318 }
319
319
320 m_chart->addSeries(series);
320 m_chart->addSeries(series);
321 } else if (seriesName == "Spline") {
321 } else if (seriesName == "Spline") {
322 for (int j(0); j < data.count(); j ++) {
322 for (int j(0); j < data.count(); j ++) {
323 QList<qreal> column = data.at(j);
323 QList<qreal> column = data.at(j);
324 QSplineSeries *series = new QSplineSeries();
324 QSplineSeries *series = new QSplineSeries();
325 series->setName("spline" + QString::number(j));
325 series->setName("spline" + QString::number(j));
326 for (int i(0); i < column.count(); i++)
326 for (int i(0); i < column.count(); i++)
327 series->append(i, column.at(i));
327 series->append(i, column.at(i));
328 m_chart->addSeries(series);
328 m_chart->addSeries(series);
329 }
329 }
330 }
330 }
331 m_chart->createDefaultAxes();
331 m_chart->createDefaultAxes();
332 }
332 }
333
333
334 void MainWidget::backgroundChanged(int itemIndex)
334 void MainWidget::backgroundChanged(int itemIndex)
335 {
335 {
336 qDebug() << "backgroundChanged: " << itemIndex;
336 qDebug() << "backgroundChanged: " << itemIndex;
337 }
337 }
338
338
339 void MainWidget::autoScaleChanged(int value)
339 void MainWidget::autoScaleChanged(int value)
340 {
340 {
341 if (value) {
341 if (value) {
342 // TODO: enable auto scaling
342 // TODO: enable auto scaling
343 } else {
343 } else {
344 // TODO: set scaling manually (and disable auto scaling)
344 // TODO: set scaling manually (and disable auto scaling)
345 }
345 }
346
346
347 m_xMinSpin->setEnabled(!value);
347 m_xMinSpin->setEnabled(!value);
348 m_xMaxSpin->setEnabled(!value);
348 m_xMaxSpin->setEnabled(!value);
349 m_yMinSpin->setEnabled(!value);
349 m_yMinSpin->setEnabled(!value);
350 m_yMaxSpin->setEnabled(!value);
350 m_yMaxSpin->setEnabled(!value);
351 }
351 }
352
352
353 void MainWidget::xMinChanged(int value)
353 void MainWidget::xMinChanged(int value)
354 {
354 {
355 qDebug() << "xMinChanged: " << value;
355 qDebug() << "xMinChanged: " << value;
356 }
356 }
357
357
358 void MainWidget::xMaxChanged(int value)
358 void MainWidget::xMaxChanged(int value)
359 {
359 {
360 qDebug() << "xMaxChanged: " << value;
360 qDebug() << "xMaxChanged: " << value;
361 }
361 }
362
362
363 void MainWidget::yMinChanged(int value)
363 void MainWidget::yMinChanged(int value)
364 {
364 {
365 qDebug() << "yMinChanged: " << value;
365 qDebug() << "yMinChanged: " << value;
366 }
366 }
367
367
368 void MainWidget::yMaxChanged(int value)
368 void MainWidget::yMaxChanged(int value)
369 {
369 {
370 qDebug() << "yMaxChanged: " << value;
370 qDebug() << "yMaxChanged: " << value;
371 }
371 }
372
372
373 void MainWidget::changeChartTheme(int themeIndex)
373 void MainWidget::changeChartTheme(int themeIndex)
374 {
374 {
375 qDebug() << "changeChartTheme: " << themeIndex;
375 qDebug() << "changeChartTheme: " << themeIndex;
376 if (themeIndex == 0)
376 if (themeIndex == 0)
377 m_chart->setTheme(QChart::ChartThemeLight);
377 m_chart->setTheme(QChart::ChartThemeLight);
378 else
378 else
379 m_chart->setTheme((QChart::ChartTheme) (themeIndex - 1));
379 m_chart->setTheme((QChart::ChartTheme) (themeIndex - 1));
380 }
380 }
General Comments 0
You need to be logged in to leave comments. Login now