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