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