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