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