|
@@
-1,381
+1,381
|
|
1
|
#include "mainwidget.h"
|
|
1
|
#include "mainwidget.h"
|
|
2
|
#include "dataseriedialog.h"
|
|
2
|
#include "dataseriedialog.h"
|
|
3
|
#include "qchartseries.h"
|
|
3
|
#include "qchartseries.h"
|
|
4
|
#include "qpieseries.h"
|
|
4
|
#include "qpieseries.h"
|
|
5
|
#include <qlinechartseries.h>
|
|
5
|
#include <qlinechartseries.h>
|
|
6
|
#include <barchartseries.h>
|
|
6
|
#include <barchartseries.h>
|
|
7
|
#include <QPushButton>
|
|
7
|
#include <QPushButton>
|
|
8
|
#include <QComboBox>
|
|
8
|
#include <QComboBox>
|
|
9
|
#include <QSpinBox>
|
|
9
|
#include <QSpinBox>
|
|
10
|
#include <QCheckBox>
|
|
10
|
#include <QCheckBox>
|
|
11
|
#include <QGridLayout>
|
|
11
|
#include <QGridLayout>
|
|
12
|
#include <QHBoxLayout>
|
|
12
|
#include <QHBoxLayout>
|
|
13
|
#include <QLabel>
|
|
13
|
#include <QLabel>
|
|
14
|
#include <QSpacerItem>
|
|
14
|
#include <QSpacerItem>
|
|
15
|
#include <QMessageBox>
|
|
15
|
#include <QMessageBox>
|
|
16
|
#include <cmath>
|
|
16
|
#include <cmath>
|
|
17
|
#include <QDebug>
|
|
17
|
#include <QDebug>
|
|
18
|
#include <QStandardItemModel>
|
|
18
|
#include <QStandardItemModel>
|
|
19
|
|
|
19
|
|
|
20
|
|
|
20
|
|
|
21
|
QTCOMMERCIALCHART_USE_NAMESPACE
|
|
21
|
QTCOMMERCIALCHART_USE_NAMESPACE
|
|
22
|
|
|
22
|
|
|
23
|
MainWidget::MainWidget(QWidget *parent) :
|
|
23
|
MainWidget::MainWidget(QWidget *parent) :
|
|
24
|
QWidget(parent)
|
|
24
|
QWidget(parent)
|
|
25
|
{
|
|
25
|
{
|
|
26
|
m_chartWidget = new QChartView(this);
|
|
26
|
m_chartWidget = new QChartView(this);
|
|
27
|
m_chartWidget->setRubberBandPolicy(QChartView::HorizonalRubberBand);
|
|
27
|
m_chartWidget->setRubberBandPolicy(QChartView::HorizonalRubberBand);
|
|
28
|
|
|
28
|
|
|
29
|
// Grid layout for the controls for configuring the chart widget
|
|
29
|
// Grid layout for the controls for configuring the chart widget
|
|
30
|
QGridLayout *grid = new QGridLayout();
|
|
30
|
QGridLayout *grid = new QGridLayout();
|
|
31
|
QPushButton *addSeriesButton = new QPushButton("Add series");
|
|
31
|
QPushButton *addSeriesButton = new QPushButton("Add series");
|
|
32
|
connect(addSeriesButton, SIGNAL(clicked()), this, SLOT(addSeries()));
|
|
32
|
connect(addSeriesButton, SIGNAL(clicked()), this, SLOT(addSeries()));
|
|
33
|
grid->addWidget(addSeriesButton, 0, 1);
|
|
33
|
grid->addWidget(addSeriesButton, 0, 1);
|
|
34
|
initBackroundCombo(grid);
|
|
34
|
initBackroundCombo(grid);
|
|
35
|
initScaleControls(grid);
|
|
35
|
initScaleControls(grid);
|
|
36
|
initThemeCombo(grid);
|
|
36
|
initThemeCombo(grid);
|
|
37
|
QCheckBox *zoomCheckBox = new QCheckBox("Drag'n drop Zoom");
|
|
37
|
QCheckBox *zoomCheckBox = new QCheckBox("Drag'n drop Zoom");
|
|
38
|
connect(zoomCheckBox, SIGNAL(toggled(bool)), m_chartWidget, SLOT(setZoomEnabled(bool)));
|
|
38
|
connect(zoomCheckBox, SIGNAL(toggled(bool)), m_chartWidget, SLOT(setZoomEnabled(bool)));
|
|
39
|
zoomCheckBox->setChecked(true);
|
|
39
|
zoomCheckBox->setChecked(true);
|
|
40
|
grid->addWidget(zoomCheckBox, grid->rowCount(), 0);
|
|
40
|
grid->addWidget(zoomCheckBox, grid->rowCount(), 0);
|
|
41
|
// add row with empty label to make all the other rows static
|
|
41
|
// add row with empty label to make all the other rows static
|
|
42
|
grid->addWidget(new QLabel(""), grid->rowCount(), 0);
|
|
42
|
grid->addWidget(new QLabel(""), grid->rowCount(), 0);
|
|
43
|
grid->setRowStretch(grid->rowCount() - 1, 1);
|
|
43
|
grid->setRowStretch(grid->rowCount() - 1, 1);
|
|
44
|
|
|
44
|
|
|
45
|
// Another grid layout as a main layout
|
|
45
|
// Another grid layout as a main layout
|
|
46
|
QGridLayout *mainLayout = new QGridLayout();
|
|
46
|
QGridLayout *mainLayout = new QGridLayout();
|
|
47
|
mainLayout->addLayout(grid, 0, 0);
|
|
47
|
mainLayout->addLayout(grid, 0, 0);
|
|
48
|
|
|
48
|
|
|
49
|
// Init series type specific controls
|
|
49
|
// Init series type specific controls
|
|
50
|
initPieControls();
|
|
50
|
initPieControls();
|
|
51
|
mainLayout->addLayout(m_pieLayout, 2, 0);
|
|
51
|
mainLayout->addLayout(m_pieLayout, 2, 0);
|
|
52
|
// Scatter series specific settings
|
|
52
|
// Scatter series specific settings
|
|
53
|
// m_scatterLayout = new QGridLayout();
|
|
53
|
// m_scatterLayout = new QGridLayout();
|
|
54
|
// m_scatterLayout->addWidget(new QLabel("scatter"), 0, 0);
|
|
54
|
// m_scatterLayout->addWidget(new QLabel("scatter"), 0, 0);
|
|
55
|
// m_scatterLayout->setEnabled(false);
|
|
55
|
// m_scatterLayout->setEnabled(false);
|
|
56
|
// mainLayout->addLayout(m_scatterLayout, 1, 0);
|
|
56
|
// mainLayout->addLayout(m_scatterLayout, 1, 0);
|
|
57
|
|
|
57
|
|
|
58
|
// Add layouts and the chart widget to the main layout
|
|
58
|
// Add layouts and the chart widget to the main layout
|
|
59
|
mainLayout->addWidget(m_chartWidget, 0, 1, 3, 1);
|
|
59
|
mainLayout->addWidget(m_chartWidget, 0, 1, 3, 1);
|
|
60
|
setLayout(mainLayout);
|
|
60
|
setLayout(mainLayout);
|
|
61
|
|
|
61
|
|
|
62
|
// force an update to test data
|
|
62
|
// force an update to test data
|
|
63
|
testDataChanged(0);
|
|
63
|
testDataChanged(0);
|
|
64
|
}
|
|
64
|
}
|
|
65
|
|
|
65
|
|
|
66
|
// Combo box for selecting the chart's background
|
|
66
|
// Combo box for selecting the chart's background
|
|
67
|
void MainWidget::initBackroundCombo(QGridLayout *grid)
|
|
67
|
void MainWidget::initBackroundCombo(QGridLayout *grid)
|
|
68
|
{
|
|
68
|
{
|
|
69
|
QComboBox *backgroundCombo = new QComboBox(this);
|
|
69
|
QComboBox *backgroundCombo = new QComboBox(this);
|
|
70
|
backgroundCombo->addItem("Color");
|
|
70
|
backgroundCombo->addItem("Color");
|
|
71
|
backgroundCombo->addItem("Gradient");
|
|
71
|
backgroundCombo->addItem("Gradient");
|
|
72
|
backgroundCombo->addItem("Image");
|
|
72
|
backgroundCombo->addItem("Image");
|
|
73
|
connect(backgroundCombo, SIGNAL(currentIndexChanged(int)),
|
|
73
|
connect(backgroundCombo, SIGNAL(currentIndexChanged(int)),
|
|
74
|
this, SLOT(backgroundChanged(int)));
|
|
74
|
this, SLOT(backgroundChanged(int)));
|
|
75
|
|
|
75
|
|
|
76
|
grid->addWidget(new QLabel("Background:"), grid->rowCount(), 0);
|
|
76
|
grid->addWidget(new QLabel("Background:"), grid->rowCount(), 0);
|
|
77
|
grid->addWidget(backgroundCombo, grid->rowCount() - 1, 1);
|
|
77
|
grid->addWidget(backgroundCombo, grid->rowCount() - 1, 1);
|
|
78
|
}
|
|
78
|
}
|
|
79
|
|
|
79
|
|
|
80
|
// Scale related controls (auto-scale vs. manual min-max values)
|
|
80
|
// Scale related controls (auto-scale vs. manual min-max values)
|
|
81
|
void MainWidget::initScaleControls(QGridLayout *grid)
|
|
81
|
void MainWidget::initScaleControls(QGridLayout *grid)
|
|
82
|
{
|
|
82
|
{
|
|
83
|
m_autoScaleCheck = new QCheckBox("Automatic scaling");
|
|
83
|
m_autoScaleCheck = new QCheckBox("Automatic scaling");
|
|
84
|
connect(m_autoScaleCheck, SIGNAL(stateChanged(int)), this, SLOT(autoScaleChanged(int)));
|
|
84
|
connect(m_autoScaleCheck, SIGNAL(stateChanged(int)), this, SLOT(autoScaleChanged(int)));
|
|
85
|
// Allow setting also non-sense values (like -2147483648 and 2147483647)
|
|
85
|
// Allow setting also non-sense values (like -2147483648 and 2147483647)
|
|
86
|
m_xMinSpin = new QSpinBox();
|
|
86
|
m_xMinSpin = new QSpinBox();
|
|
87
|
m_xMinSpin->setMinimum(INT_MIN);
|
|
87
|
m_xMinSpin->setMinimum(INT_MIN);
|
|
88
|
m_xMinSpin->setMaximum(INT_MAX);
|
|
88
|
m_xMinSpin->setMaximum(INT_MAX);
|
|
89
|
m_xMinSpin->setValue(0);
|
|
89
|
m_xMinSpin->setValue(0);
|
|
90
|
connect(m_xMinSpin, SIGNAL(valueChanged(int)), this, SLOT(xMinChanged(int)));
|
|
90
|
connect(m_xMinSpin, SIGNAL(valueChanged(int)), this, SLOT(xMinChanged(int)));
|
|
91
|
m_xMaxSpin = new QSpinBox();
|
|
91
|
m_xMaxSpin = new QSpinBox();
|
|
92
|
m_xMaxSpin->setMinimum(INT_MIN);
|
|
92
|
m_xMaxSpin->setMinimum(INT_MIN);
|
|
93
|
m_xMaxSpin->setMaximum(INT_MAX);
|
|
93
|
m_xMaxSpin->setMaximum(INT_MAX);
|
|
94
|
m_xMaxSpin->setValue(10);
|
|
94
|
m_xMaxSpin->setValue(10);
|
|
95
|
connect(m_xMaxSpin, SIGNAL(valueChanged(int)), this, SLOT(xMaxChanged(int)));
|
|
95
|
connect(m_xMaxSpin, SIGNAL(valueChanged(int)), this, SLOT(xMaxChanged(int)));
|
|
96
|
m_yMinSpin = new QSpinBox();
|
|
96
|
m_yMinSpin = new QSpinBox();
|
|
97
|
m_yMinSpin->setMinimum(INT_MIN);
|
|
97
|
m_yMinSpin->setMinimum(INT_MIN);
|
|
98
|
m_yMinSpin->setMaximum(INT_MAX);
|
|
98
|
m_yMinSpin->setMaximum(INT_MAX);
|
|
99
|
m_yMinSpin->setValue(0);
|
|
99
|
m_yMinSpin->setValue(0);
|
|
100
|
connect(m_yMinSpin, SIGNAL(valueChanged(int)), this, SLOT(yMinChanged(int)));
|
|
100
|
connect(m_yMinSpin, SIGNAL(valueChanged(int)), this, SLOT(yMinChanged(int)));
|
|
101
|
m_yMaxSpin = new QSpinBox();
|
|
101
|
m_yMaxSpin = new QSpinBox();
|
|
102
|
m_yMaxSpin->setMinimum(INT_MIN);
|
|
102
|
m_yMaxSpin->setMinimum(INT_MIN);
|
|
103
|
m_yMaxSpin->setMaximum(INT_MAX);
|
|
103
|
m_yMaxSpin->setMaximum(INT_MAX);
|
|
104
|
m_yMaxSpin->setValue(10);
|
|
104
|
m_yMaxSpin->setValue(10);
|
|
105
|
connect(m_yMaxSpin, SIGNAL(valueChanged(int)), this, SLOT(yMaxChanged(int)));
|
|
105
|
connect(m_yMaxSpin, SIGNAL(valueChanged(int)), this, SLOT(yMaxChanged(int)));
|
|
106
|
|
|
106
|
|
|
107
|
grid->addWidget(m_autoScaleCheck, grid->rowCount(), 0);
|
|
107
|
grid->addWidget(m_autoScaleCheck, grid->rowCount(), 0);
|
|
108
|
grid->addWidget(new QLabel("x min:"), grid->rowCount(), 0);
|
|
108
|
grid->addWidget(new QLabel("x min:"), grid->rowCount(), 0);
|
|
109
|
grid->addWidget(m_xMinSpin, grid->rowCount() - 1, 1);
|
|
109
|
grid->addWidget(m_xMinSpin, grid->rowCount() - 1, 1);
|
|
110
|
grid->addWidget(new QLabel("x max:"), grid->rowCount(), 0);
|
|
110
|
grid->addWidget(new QLabel("x max:"), grid->rowCount(), 0);
|
|
111
|
grid->addWidget(m_xMaxSpin, grid->rowCount() - 1, 1);
|
|
111
|
grid->addWidget(m_xMaxSpin, grid->rowCount() - 1, 1);
|
|
112
|
grid->addWidget(new QLabel("y min:"), grid->rowCount(), 0);
|
|
112
|
grid->addWidget(new QLabel("y min:"), grid->rowCount(), 0);
|
|
113
|
grid->addWidget(m_yMinSpin, grid->rowCount() - 1, 1);
|
|
113
|
grid->addWidget(m_yMinSpin, grid->rowCount() - 1, 1);
|
|
114
|
grid->addWidget(new QLabel("y max:"), grid->rowCount(), 0);
|
|
114
|
grid->addWidget(new QLabel("y max:"), grid->rowCount(), 0);
|
|
115
|
grid->addWidget(m_yMaxSpin, grid->rowCount() - 1, 1);
|
|
115
|
grid->addWidget(m_yMaxSpin, grid->rowCount() - 1, 1);
|
|
116
|
|
|
116
|
|
|
117
|
m_autoScaleCheck->setChecked(true);
|
|
117
|
m_autoScaleCheck->setChecked(true);
|
|
118
|
}
|
|
118
|
}
|
|
119
|
|
|
119
|
|
|
120
|
// Combo box for selecting theme
|
|
120
|
// Combo box for selecting theme
|
|
121
|
void MainWidget::initThemeCombo(QGridLayout *grid)
|
|
121
|
void MainWidget::initThemeCombo(QGridLayout *grid)
|
|
122
|
{
|
|
122
|
{
|
|
123
|
QComboBox *chartTheme = new QComboBox();
|
|
123
|
QComboBox *chartTheme = new QComboBox();
|
|
124
|
chartTheme->addItem("Default");
|
|
124
|
chartTheme->addItem("Default");
|
|
125
|
chartTheme->addItem("Vanilla");
|
|
125
|
chartTheme->addItem("Vanilla");
|
|
126
|
chartTheme->addItem("Icy");
|
|
126
|
chartTheme->addItem("Icy");
|
|
127
|
chartTheme->addItem("Grayscale");
|
|
127
|
chartTheme->addItem("Grayscale");
|
|
128
|
chartTheme->addItem("Scientific");
|
|
128
|
chartTheme->addItem("Scientific");
|
|
129
|
chartTheme->addItem("Unnamed1");
|
|
129
|
chartTheme->addItem("Unnamed1");
|
|
130
|
connect(chartTheme, SIGNAL(currentIndexChanged(int)),
|
|
130
|
connect(chartTheme, SIGNAL(currentIndexChanged(int)),
|
|
131
|
this, SLOT(changeChartTheme(int)));
|
|
131
|
this, SLOT(changeChartTheme(int)));
|
|
132
|
grid->addWidget(new QLabel("Chart theme:"), 8, 0);
|
|
132
|
grid->addWidget(new QLabel("Chart theme:"), 8, 0);
|
|
133
|
grid->addWidget(chartTheme, 8, 1);
|
|
133
|
grid->addWidget(chartTheme, 8, 1);
|
|
134
|
}
|
|
134
|
}
|
|
135
|
|
|
135
|
|
|
136
|
void MainWidget::initPieControls()
|
|
136
|
void MainWidget::initPieControls()
|
|
137
|
{
|
|
137
|
{
|
|
138
|
// Pie series specific settings
|
|
138
|
// Pie series specific settings
|
|
139
|
// Pie size factory
|
|
139
|
// Pie size factory
|
|
140
|
QDoubleSpinBox *pieSizeSpin = new QDoubleSpinBox();
|
|
140
|
QDoubleSpinBox *pieSizeSpin = new QDoubleSpinBox();
|
|
141
|
pieSizeSpin->setMinimum(LONG_MIN);
|
|
141
|
pieSizeSpin->setMinimum(LONG_MIN);
|
|
142
|
pieSizeSpin->setMaximum(LONG_MAX);
|
|
142
|
pieSizeSpin->setMaximum(LONG_MAX);
|
|
143
|
pieSizeSpin->setValue(1.0);
|
|
143
|
pieSizeSpin->setValue(1.0);
|
|
144
|
pieSizeSpin->setSingleStep(0.1);
|
|
144
|
pieSizeSpin->setSingleStep(0.1);
|
|
145
|
connect(pieSizeSpin, SIGNAL(valueChanged(double)), this, SLOT(setPieSizeFactor(double)));
|
|
145
|
connect(pieSizeSpin, SIGNAL(valueChanged(double)), this, SLOT(setPieSizeFactor(double)));
|
|
146
|
// Pie position
|
|
146
|
// Pie position
|
|
147
|
QComboBox *piePosCombo = new QComboBox(this);
|
|
147
|
QComboBox *piePosCombo = new QComboBox(this);
|
|
148
|
piePosCombo->addItem("Maximized");
|
|
148
|
piePosCombo->addItem("Maximized");
|
|
149
|
piePosCombo->addItem("Top left");
|
|
149
|
piePosCombo->addItem("Top left");
|
|
150
|
piePosCombo->addItem("Top right");
|
|
150
|
piePosCombo->addItem("Top right");
|
|
151
|
piePosCombo->addItem("Bottom left");
|
|
151
|
piePosCombo->addItem("Bottom left");
|
|
152
|
piePosCombo->addItem("Bottom right");
|
|
152
|
piePosCombo->addItem("Bottom right");
|
|
153
|
connect(piePosCombo, SIGNAL(currentIndexChanged(int)),
|
|
153
|
connect(piePosCombo, SIGNAL(currentIndexChanged(int)),
|
|
154
|
this, SLOT(setPiePosition(int)));
|
|
154
|
this, SLOT(setPiePosition(int)));
|
|
155
|
m_pieLayout = new QGridLayout();
|
|
155
|
m_pieLayout = new QGridLayout();
|
|
156
|
m_pieLayout->setEnabled(false);
|
|
156
|
m_pieLayout->setEnabled(false);
|
|
157
|
m_pieLayout->addWidget(new QLabel("Pie size factor"), 0, 0);
|
|
157
|
m_pieLayout->addWidget(new QLabel("Pie size factor"), 0, 0);
|
|
158
|
m_pieLayout->addWidget(pieSizeSpin, 0, 1);
|
|
158
|
m_pieLayout->addWidget(pieSizeSpin, 0, 1);
|
|
159
|
m_pieLayout->addWidget(new QLabel("Pie position"), 1, 0);
|
|
159
|
m_pieLayout->addWidget(new QLabel("Pie position"), 1, 0);
|
|
160
|
m_pieLayout->addWidget(piePosCombo, 1, 1);
|
|
160
|
m_pieLayout->addWidget(piePosCombo, 1, 1);
|
|
161
|
}
|
|
161
|
}
|
|
162
|
|
|
162
|
|
|
163
|
void MainWidget::addSeries()
|
|
163
|
void MainWidget::addSeries()
|
|
164
|
{
|
|
164
|
{
|
|
165
|
DataSerieDialog dialog(m_defaultSeriesName, this);
|
|
165
|
DataSerieDialog dialog(m_defaultSeriesName, this);
|
|
166
|
connect(&dialog, SIGNAL(accepted(QString, QString)), this, SLOT(addSeries(QString, QString)));
|
|
166
|
connect(&dialog, SIGNAL(accepted(QString, QString)), this, SLOT(addSeries(QString, QString)));
|
|
167
|
dialog.exec();
|
|
167
|
dialog.exec();
|
|
168
|
}
|
|
168
|
}
|
|
169
|
|
|
169
|
|
|
170
|
void MainWidget::addSeries(QString series, QString data)
|
|
170
|
void MainWidget::addSeries(QString series, QString data)
|
|
171
|
{
|
|
171
|
{
|
|
172
|
qDebug() << "addSeries: " << series << " data: " << data;
|
|
172
|
qDebug() << "addSeries: " << series << " data: " << data;
|
|
173
|
m_defaultSeriesName = series;
|
|
173
|
m_defaultSeriesName = series;
|
|
174
|
|
|
174
|
|
|
175
|
// TODO: a dedicated data class for storing x and y values
|
|
175
|
// TODO: a dedicated data class for storing x and y values
|
|
176
|
QList<qreal> x;
|
|
176
|
QList<qreal> x;
|
|
177
|
QList<qreal> y;
|
|
177
|
QList<qreal> y;
|
|
178
|
|
|
178
|
|
|
179
|
if (data == "linear") {
|
|
179
|
if (data == "linear") {
|
|
180
|
for (int i = 0; i < 20; i++) {
|
|
180
|
for (int i = 0; i < 20; i++) {
|
|
181
|
x.append(i);
|
|
181
|
x.append(i);
|
|
182
|
y.append(i);
|
|
182
|
y.append(i);
|
|
183
|
}
|
|
183
|
}
|
|
184
|
} else if (data == "linear, 1M") {
|
|
184
|
} else if (data == "linear, 1M") {
|
|
185
|
// 1 million data points from 0.0001 to 100
|
|
185
|
// 1 million data points from 0.0001 to 100
|
|
186
|
// TODO: What is the requirement? Should we be able to show this kind of data with
|
|
186
|
// TODO: What is the requirement? Should we be able to show this kind of data with
|
|
187
|
// reasonable performance, or can we expect the application developer to do "data mining"
|
|
187
|
// reasonable performance, or can we expect the application developer to do "data mining"
|
|
188
|
// for us, so that the count of data points given to QtCommercial Chart is always
|
|
188
|
// for us, so that the count of data points given to QtCommercial Chart is always
|
|
189
|
// reasonable?
|
|
189
|
// reasonable?
|
|
190
|
for (qreal i = 0; i < 100; i += 0.0001) {
|
|
190
|
for (qreal i = 0; i < 100; i += 0.0001) {
|
|
191
|
x.append(i);
|
|
191
|
x.append(i);
|
|
192
|
y.append(20);
|
|
192
|
y.append(20);
|
|
193
|
}
|
|
193
|
}
|
|
194
|
} else if (data == "SIN") {
|
|
194
|
} else if (data == "SIN") {
|
|
195
|
for (int i = 0; i < 100; i++) {
|
|
195
|
for (int i = 0; i < 100; i++) {
|
|
196
|
x.append(i);
|
|
196
|
x.append(i);
|
|
197
|
y.append(abs(sin(3.14159265358979 / 50 * i) * 100));
|
|
197
|
y.append(abs(sin(3.14159265358979 / 50 * i) * 100));
|
|
198
|
}
|
|
198
|
}
|
|
199
|
} else if (data == "SIN + random") {
|
|
199
|
} else if (data == "SIN + random") {
|
|
200
|
for (qreal i = 0; i < 100; i += 0.1) {
|
|
200
|
for (qreal i = 0; i < 100; i += 0.1) {
|
|
201
|
x.append(i + (rand() % 5));
|
|
201
|
x.append(i + (rand() % 5));
|
|
202
|
y.append(abs(sin(3.14159265358979 / 50 * i) * 100) + (rand() % 5));
|
|
202
|
y.append(abs(sin(3.14159265358979 / 50 * i) * 100) + (rand() % 5));
|
|
203
|
}
|
|
203
|
}
|
|
204
|
} else {
|
|
204
|
} else {
|
|
205
|
// TODO: check if data has a valid file name
|
|
205
|
// TODO: check if data has a valid file name
|
|
206
|
Q_ASSERT(false);
|
|
206
|
Q_ASSERT(false);
|
|
207
|
}
|
|
207
|
}
|
|
208
|
|
|
208
|
|
|
209
|
// TODO: color of the series
|
|
209
|
// TODO: color of the series
|
|
210
|
QChartSeries *newSeries = 0;
|
|
210
|
QChartSeries *newSeries = 0;
|
|
211
|
if (series == "Scatter") {
|
|
211
|
if (series == "Scatter") {
|
|
212
|
newSeries = m_chartWidget->createSeries(QChartSeries::SeriesTypeScatter);
|
|
212
|
newSeries = m_chartWidget->createSeries(QChartSeries::SeriesTypeScatter);
|
|
213
|
Q_ASSERT(newSeries->setData(x, y));
|
|
213
|
Q_ASSERT(newSeries->setData(x, y));
|
|
214
|
} else if (series == "Pie") {
|
|
214
|
} else if (series == "Pie") {
|
|
215
|
newSeries = m_chartWidget->createSeries(QChartSeries::SeriesTypePie);
|
|
215
|
newSeries = m_chartWidget->createSeries(QChartSeries::SeriesTypePie);
|
|
216
|
Q_ASSERT(newSeries->setData(y));
|
|
216
|
Q_ASSERT(newSeries->setData(y));
|
|
217
|
} else if (series == "Line") {
|
|
217
|
} else if (series == "Line") {
|
|
218
|
// TODO: adding data to an existing line series does not give any visuals for some reason
|
|
218
|
// TODO: adding data to an existing line series does not give any visuals for some reason
|
|
219
|
// newSeries = m_chartWidget->createSeries(QChartSeries::SeriesTypeLine);
|
|
219
|
// newSeries = m_chartWidget->createSeries(QChartSeries::SeriesTypeLine);
|
|
220
|
// QXYChartSeries *lineSeries = static_cast<QXYChartSeries *>(newSeries);
|
|
220
|
// QXYChartSeries *lineSeries = static_cast<QXYChartSeries *>(newSeries);
|
|
221
|
// lineSeries->setColor(Qt::blue);
|
|
221
|
// lineSeries->setColor(Qt::blue);
|
|
222
|
// for (int i(0); i < x.count() && i < y.count(); i++) {
|
|
222
|
// for (int i(0); i < x.count() && i < y.count(); i++) {
|
|
223
|
// lineSeries->add(x.at(i), y.at(i));
|
|
223
|
// lineSeries->add(x.at(i), y.at(i));
|
|
224
|
// }
|
|
224
|
// }
|
|
225
|
//Q_ASSERT(newSeries->setData(x, y));
|
|
225
|
//Q_ASSERT(newSeries->setData(x, y));
|
|
226
|
QLineChartSeries* series0 = QLineChartSeries::create();
|
|
226
|
QLineChartSeries* series0 = QLineChartSeries::create();
|
|
227
|
for (int i(0); i < x.count() && i < y.count(); i++)
|
|
227
|
for (int i(0); i < x.count() && i < y.count(); i++)
|
|
228
|
series0->add(x.at(i), y.at(i));
|
|
228
|
series0->add(x.at(i), y.at(i));
|
|
229
|
m_chartWidget->addSeries(series0);
|
|
229
|
m_chartWidget->addSeries(series0);
|
|
230
|
newSeries = series0;
|
|
230
|
newSeries = series0;
|
|
231
|
} else {
|
|
231
|
} else {
|
|
232
|
// TODO
|
|
232
|
// TODO
|
|
233
|
}
|
|
233
|
}
|
|
234
|
|
|
234
|
|
|
235
|
// BarChart
|
|
235
|
// BarChart
|
|
236
|
if (series == "Bar") {
|
|
236
|
if (series == "Bar") {
|
|
237
|
// This is the another way of creating series. Should we create test cases for both ways, if we support them?
|
|
237
|
// This is the another way of creating series. Should we create test cases for both ways, if we support them?
|
|
238
|
qDebug() << "Bar chart series";
|
|
238
|
qDebug() << "Bar chart series";
|
|
239
|
newSeries = QChartSeries::create(QChartSeries::SeriesTypeBar, this);
|
|
239
|
newSeries = QChartSeries::create(QChartSeries::SeriesTypeBar, this);
|
|
240
|
|
|
240
|
|
|
241
|
// Create some test data to chart
|
|
241
|
// Create some test data to chart
|
|
242
|
QStandardItemModel dataModel(2,10,this);
|
|
242
|
QStandardItemModel dataModel(2,10,this);
|
|
243
|
QModelIndex index;
|
|
243
|
QModelIndex index;
|
|
244
|
index = dataModel.index(0,0);
|
|
244
|
index = dataModel.index(0,0);
|
|
245
|
// Series 1, items 6 to 9 missing.
|
|
245
|
// Series 1, items 6 to 9 missing.
|
|
246
|
dataModel.setData(dataModel.index(0,0),1);
|
|
246
|
dataModel.setData(dataModel.index(0,0),1);
|
|
247
|
dataModel.setData(dataModel.index(0,1),12);
|
|
247
|
dataModel.setData(dataModel.index(0,1),12);
|
|
248
|
dataModel.setData(dataModel.index(0,2),5);
|
|
248
|
dataModel.setData(dataModel.index(0,2),5);
|
|
249
|
dataModel.setData(dataModel.index(0,3),8);
|
|
249
|
dataModel.setData(dataModel.index(0,3),8);
|
|
250
|
dataModel.setData(dataModel.index(0,4),17);
|
|
250
|
dataModel.setData(dataModel.index(0,4),17);
|
|
251
|
dataModel.setData(dataModel.index(0,5),9);
|
|
251
|
dataModel.setData(dataModel.index(0,5),9);
|
|
252
|
|
|
252
|
|
|
253
|
// Series 2, some other items missing
|
|
253
|
// Series 2, some other items missing
|
|
254
|
dataModel.setData(dataModel.index(1,0),5);
|
|
254
|
dataModel.setData(dataModel.index(1,0),5);
|
|
255
|
dataModel.setData(dataModel.index(1,3),4);
|
|
255
|
dataModel.setData(dataModel.index(1,3),4);
|
|
256
|
dataModel.setData(dataModel.index(1,5),7);
|
|
256
|
dataModel.setData(dataModel.index(1,5),7);
|
|
257
|
dataModel.setData(dataModel.index(1,6),8);
|
|
257
|
dataModel.setData(dataModel.index(1,6),8);
|
|
258
|
dataModel.setData(dataModel.index(1,8),9);
|
|
258
|
dataModel.setData(dataModel.index(1,8),9);
|
|
259
|
dataModel.setData(dataModel.index(1,9),9);
|
|
259
|
dataModel.setData(dataModel.index(1,9),9);
|
|
260
|
|
|
260
|
|
|
261
|
newSeries->setData(&dataModel);
|
|
261
|
newSeries->setData(&dataModel);
|
|
262
|
|
|
262
|
|
|
263
|
m_chartWidget->addSeries(newSeries);
|
|
263
|
m_chartWidget->addSeries(newSeries);
|
|
264
|
}
|
|
264
|
}
|
|
265
|
|
|
265
|
|
|
266
|
setCurrentSeries(newSeries);
|
|
266
|
setCurrentSeries(newSeries);
|
|
267
|
}
|
|
267
|
}
|
|
268
|
|
|
268
|
|
|
269
|
void MainWidget::setCurrentSeries(QChartSeries *series)
|
|
269
|
void MainWidget::setCurrentSeries(QChartSeries *series)
|
|
270
|
{
|
|
270
|
{
|
|
271
|
m_currentSeries = series;
|
|
271
|
m_currentSeries = series;
|
|
272
|
switch (m_currentSeries->type()) {
|
|
272
|
switch (m_currentSeries->type()) {
|
|
273
|
case QChartSeries::SeriesTypeLine:
|
|
273
|
case QChartSeries::SeriesTypeLine:
|
|
274
|
break;
|
|
274
|
break;
|
|
275
|
case QChartSeries::SeriesTypeScatter:
|
|
275
|
case QChartSeries::SeriesTypeScatter:
|
|
276
|
break;
|
|
276
|
break;
|
|
277
|
case QChartSeries::SeriesTypePie:
|
|
277
|
case QChartSeries::SeriesTypePie:
|
|
278
|
break;
|
|
278
|
break;
|
|
279
|
case QChartSeries::SeriesTypeBar:
|
|
279
|
case QChartSeries::SeriesTypeBar:
|
|
280
|
qDebug() << "setCurrentSeries (bar)";
|
|
280
|
qDebug() << "setCurrentSeries (bar)";
|
|
281
|
break;
|
|
281
|
break;
|
|
282
|
default:
|
|
282
|
default:
|
|
283
|
Q_ASSERT(false);
|
|
283
|
Q_ASSERT(false);
|
|
284
|
break;
|
|
284
|
break;
|
|
285
|
}
|
|
285
|
}
|
|
286
|
}
|
|
286
|
}
|
|
287
|
|
|
287
|
|
|
288
|
void MainWidget::testDataChanged(int itemIndex)
|
|
288
|
void MainWidget::testDataChanged(int itemIndex)
|
|
289
|
{
|
|
289
|
{
|
|
290
|
qDebug() << "testDataChanged: " << itemIndex;
|
|
290
|
qDebug() << "testDataChanged: " << itemIndex;
|
|
291
|
|
|
291
|
|
|
292
|
// switch (itemIndex) {
|
|
292
|
// switch (itemIndex) {
|
|
293
|
// case 0: {
|
|
293
|
// case 0: {
|
|
294
|
// QList<QChartDataPoint> data;
|
|
294
|
// QList<QChartDataPoint> data;
|
|
295
|
// for (int x = 0; x < 20; x++) {
|
|
295
|
// for (int x = 0; x < 20; x++) {
|
|
296
|
// data.append(QChartDataPoint() << x << x / 2);
|
|
296
|
// data.append(QChartDataPoint() << x << x / 2);
|
|
297
|
// }
|
|
297
|
// }
|
|
298
|
// m_chartWidget->setData(data);
|
|
298
|
// m_chartWidget->setData(data);
|
|
299
|
// break;
|
|
299
|
// break;
|
|
300
|
// }
|
|
300
|
// }
|
|
301
|
// case 1: {
|
|
301
|
// case 1: {
|
|
302
|
// QList<QChartDataPoint> data;
|
|
302
|
// QList<QChartDataPoint> data;
|
|
303
|
// for (int x = 0; x < 100; x++) {
|
|
303
|
// for (int x = 0; x < 100; x++) {
|
|
304
|
// data.append(QChartDataPoint() << x - 200 << 2 * (uint(sin(3.14159/50*x)*80) % 100));
|
|
304
|
// data.append(QChartDataPoint() << x - 200 << 2 * (uint(sin(3.14159/50*x)*80) % 100));
|
|
305
|
// }
|
|
305
|
// }
|
|
306
|
// m_chartWidget->setData(data);
|
|
306
|
// m_chartWidget->setData(data);
|
|
307
|
// break;
|
|
307
|
// break;
|
|
308
|
// }
|
|
308
|
// }
|
|
309
|
// case 2: {
|
|
309
|
// case 2: {
|
|
310
|
// QList<QChartDataPoint> data;
|
|
310
|
// QList<QChartDataPoint> data;
|
|
311
|
// for (int x = 0; x < 1000; x++) {
|
|
311
|
// for (int x = 0; x < 1000; x++) {
|
|
312
|
// data.append(QChartDataPoint() << x - 200 << 2 * (uint(sin(3.14159/50*x)*80) % 100) + (rand() % 100 * 0.2));
|
|
312
|
// data.append(QChartDataPoint() << x - 200 << 2 * (uint(sin(3.14159/50*x)*80) % 100) + (rand() % 100 * 0.2));
|
|
313
|
// data.append(QChartDataPoint() << x - 200 << 2 * (uint(sin(3.14159/50*x)*80) % 100) + (rand() % 100 * 0.2));
|
|
313
|
// data.append(QChartDataPoint() << x - 200 << 2 * (uint(sin(3.14159/50*x)*80) % 100) + (rand() % 100 * 0.2));
|
|
314
|
// data.append(QChartDataPoint() << x - 200 << 2 * (uint(sin(3.14159/50*x)*80) % 100) + (rand() % 100 * 0.2));
|
|
314
|
// data.append(QChartDataPoint() << x - 200 << 2 * (uint(sin(3.14159/50*x)*80) % 100) + (rand() % 100 * 0.2));
|
|
315
|
// }
|
|
315
|
// }
|
|
316
|
// m_chartWidget->setData(data);
|
|
316
|
// m_chartWidget->setData(data);
|
|
317
|
// break;
|
|
317
|
// break;
|
|
318
|
// }
|
|
318
|
// }
|
|
319
|
// default:
|
|
319
|
// default:
|
|
320
|
// break;
|
|
320
|
// break;
|
|
321
|
// }
|
|
321
|
// }
|
|
322
|
}
|
|
322
|
}
|
|
323
|
|
|
323
|
|
|
324
|
void MainWidget::backgroundChanged(int itemIndex)
|
|
324
|
void MainWidget::backgroundChanged(int itemIndex)
|
|
325
|
{
|
|
325
|
{
|
|
326
|
qDebug() << "backgroundChanged: " << itemIndex;
|
|
326
|
qDebug() << "backgroundChanged: " << itemIndex;
|
|
327
|
}
|
|
327
|
}
|
|
328
|
|
|
328
|
|
|
329
|
void MainWidget::autoScaleChanged(int value)
|
|
329
|
void MainWidget::autoScaleChanged(int value)
|
|
330
|
{
|
|
330
|
{
|
|
331
|
if (value) {
|
|
331
|
if (value) {
|
|
332
|
// TODO: enable auto scaling
|
|
332
|
// TODO: enable auto scaling
|
|
333
|
} else {
|
|
333
|
} else {
|
|
334
|
// TODO: set scaling manually (and disable auto scaling)
|
|
334
|
// TODO: set scaling manually (and disable auto scaling)
|
|
335
|
}
|
|
335
|
}
|
|
336
|
|
|
336
|
|
|
337
|
m_xMinSpin->setEnabled(!value);
|
|
337
|
m_xMinSpin->setEnabled(!value);
|
|
338
|
m_xMaxSpin->setEnabled(!value);
|
|
338
|
m_xMaxSpin->setEnabled(!value);
|
|
339
|
m_yMinSpin->setEnabled(!value);
|
|
339
|
m_yMinSpin->setEnabled(!value);
|
|
340
|
m_yMaxSpin->setEnabled(!value);
|
|
340
|
m_yMaxSpin->setEnabled(!value);
|
|
341
|
}
|
|
341
|
}
|
|
342
|
|
|
342
|
|
|
343
|
void MainWidget::xMinChanged(int value)
|
|
343
|
void MainWidget::xMinChanged(int value)
|
|
344
|
{
|
|
344
|
{
|
|
345
|
qDebug() << "xMinChanged: " << value;
|
|
345
|
qDebug() << "xMinChanged: " << value;
|
|
346
|
}
|
|
346
|
}
|
|
347
|
|
|
347
|
|
|
348
|
void MainWidget::xMaxChanged(int value)
|
|
348
|
void MainWidget::xMaxChanged(int value)
|
|
349
|
{
|
|
349
|
{
|
|
350
|
qDebug() << "xMaxChanged: " << value;
|
|
350
|
qDebug() << "xMaxChanged: " << value;
|
|
351
|
}
|
|
351
|
}
|
|
352
|
|
|
352
|
|
|
353
|
void MainWidget::yMinChanged(int value)
|
|
353
|
void MainWidget::yMinChanged(int value)
|
|
354
|
{
|
|
354
|
{
|
|
355
|
qDebug() << "yMinChanged: " << value;
|
|
355
|
qDebug() << "yMinChanged: " << value;
|
|
356
|
}
|
|
356
|
}
|
|
357
|
|
|
357
|
|
|
358
|
void MainWidget::yMaxChanged(int value)
|
|
358
|
void MainWidget::yMaxChanged(int value)
|
|
359
|
{
|
|
359
|
{
|
|
360
|
qDebug() << "yMaxChanged: " << value;
|
|
360
|
qDebug() << "yMaxChanged: " << value;
|
|
361
|
}
|
|
361
|
}
|
|
362
|
|
|
362
|
|
|
363
|
void MainWidget::changeChartTheme(int themeIndex)
|
|
363
|
void MainWidget::changeChartTheme(int themeIndex)
|
|
364
|
{
|
|
364
|
{
|
|
365
|
qDebug() << "changeChartTheme: " << themeIndex;
|
|
365
|
qDebug() << "changeChartTheme: " << themeIndex;
|
|
366
|
m_chartWidget->setTheme((QChart::ChartThemeId) themeIndex);
|
|
366
|
m_chartWidget->setChartTheme((QChart::ChartTheme) themeIndex);
|
|
367
|
}
|
|
367
|
}
|
|
368
|
|
|
368
|
|
|
369
|
void MainWidget::setPieSizeFactor(double size)
|
|
369
|
void MainWidget::setPieSizeFactor(double size)
|
|
370
|
{
|
|
370
|
{
|
|
371
|
QPieSeries *pie = qobject_cast<QPieSeries *>(m_currentSeries);
|
|
371
|
QPieSeries *pie = qobject_cast<QPieSeries *>(m_currentSeries);
|
|
372
|
if (pie)
|
|
372
|
if (pie)
|
|
373
|
pie->setSizeFactor(qreal(size));
|
|
373
|
pie->setSizeFactor(qreal(size));
|
|
374
|
}
|
|
374
|
}
|
|
375
|
|
|
375
|
|
|
376
|
void MainWidget::setPiePosition(int position)
|
|
376
|
void MainWidget::setPiePosition(int position)
|
|
377
|
{
|
|
377
|
{
|
|
378
|
QPieSeries *pie = qobject_cast<QPieSeries *>(m_currentSeries);
|
|
378
|
QPieSeries *pie = qobject_cast<QPieSeries *>(m_currentSeries);
|
|
379
|
if (pie)
|
|
379
|
if (pie)
|
|
380
|
pie->setPosition((QPieSeries::PiePosition) position);
|
|
380
|
pie->setPosition((QPieSeries::PiePosition) position);
|
|
381
|
}
|
|
381
|
}
|