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