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