##// END OF EJS Templates
Added grouped bar series to chart widget test
Tero Ahola -
r1223:0e5ab3a86184
parent child
Show More
@@ -1,188 +1,189
1 /****************************************************************************
1 /****************************************************************************
2 **
2 **
3 ** Copyright (C) 2012 Digia Plc
3 ** Copyright (C) 2012 Digia Plc
4 ** All rights reserved.
4 ** All rights reserved.
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 **
6 **
7 ** This file is part of the Qt Commercial Charts Add-on.
7 ** This file is part of the Qt Commercial Charts Add-on.
8 **
8 **
9 ** $QT_BEGIN_LICENSE$
9 ** $QT_BEGIN_LICENSE$
10 ** Licensees holding valid Qt Commercial licenses may use this file in
10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 ** accordance with the Qt Commercial License Agreement provided with the
11 ** accordance with the Qt Commercial License Agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia.
13 ** a written agreement between you and Digia.
14 **
14 **
15 ** If you have questions regarding the use of this file, please use
15 ** If you have questions regarding the use of this file, please use
16 ** contact form at http://qt.digia.com
16 ** contact form at http://qt.digia.com
17 ** $QT_END_LICENSE$
17 ** $QT_END_LICENSE$
18 **
18 **
19 ****************************************************************************/
19 ****************************************************************************/
20
20
21 #include "dataseriedialog.h"
21 #include "dataseriedialog.h"
22 #include <QDialogButtonBox>
22 #include <QDialogButtonBox>
23 #include <QGridLayout>
23 #include <QGridLayout>
24 #include <QCheckBox>
24 #include <QCheckBox>
25 #include <QPushButton>
25 #include <QPushButton>
26 #include <QGroupBox>
26 #include <QGroupBox>
27 #include <QRadioButton>
27 #include <QRadioButton>
28 #include <QLabel>
28 #include <QLabel>
29 #include <QDebug>
29 #include <QDebug>
30
30
31 DataSerieDialog::DataSerieDialog(QWidget *parent) :
31 DataSerieDialog::DataSerieDialog(QWidget *parent) :
32 QDialog(parent)
32 QDialog(parent)
33 {
33 {
34 QDialogButtonBox *addSeriesBox = new QDialogButtonBox(Qt::Horizontal);
34 QDialogButtonBox *addSeriesBox = new QDialogButtonBox(Qt::Horizontal);
35 QPushButton *b = addSeriesBox->addButton(QDialogButtonBox::Ok);
35 QPushButton *b = addSeriesBox->addButton(QDialogButtonBox::Ok);
36 connect(b, SIGNAL(clicked()), this, SLOT(accept()));
36 connect(b, SIGNAL(clicked()), this, SLOT(accept()));
37 b = addSeriesBox->addButton(QDialogButtonBox::Cancel);
37 b = addSeriesBox->addButton(QDialogButtonBox::Cancel);
38 connect(b, SIGNAL(clicked()), this, SLOT(reject()));
38 connect(b, SIGNAL(clicked()), this, SLOT(reject()));
39
39
40 QGridLayout *grid = new QGridLayout();
40 QGridLayout *grid = new QGridLayout();
41
41
42 m_seriesTypeSelector = seriesTypeSelector();
42 m_seriesTypeSelector = seriesTypeSelector();
43 m_columnCountSelector = columnCountSelector();
43 m_columnCountSelector = columnCountSelector();
44 m_rowCountSelector = rowCountSelector();
44 m_rowCountSelector = rowCountSelector();
45 m_dataCharacteristicsSelector = dataCharacteristicsSelector();
45 m_dataCharacteristicsSelector = dataCharacteristicsSelector();
46
46
47 grid->addWidget(m_seriesTypeSelector, 0, 0);
47 grid->addWidget(m_seriesTypeSelector, 0, 0);
48 grid->addWidget(m_columnCountSelector, 0, 1);
48 grid->addWidget(m_columnCountSelector, 0, 1);
49 grid->addWidget(m_rowCountSelector, 1, 1);
49 grid->addWidget(m_rowCountSelector, 1, 1);
50 grid->addWidget(m_dataCharacteristicsSelector, 1, 0);
50 grid->addWidget(m_dataCharacteristicsSelector, 1, 0);
51 m_labelsSelector = new QCheckBox("Labels defined");
51 m_labelsSelector = new QCheckBox("Labels defined");
52 m_labelsSelector->setChecked(true);
52 m_labelsSelector->setChecked(true);
53 grid->addWidget(m_labelsSelector, 2, 0);
53 grid->addWidget(m_labelsSelector, 2, 0);
54 grid->addWidget(addSeriesBox, 3, 1);
54 grid->addWidget(addSeriesBox, 3, 1);
55
55
56 setLayout(grid);
56 setLayout(grid);
57 }
57 }
58
58
59 QGroupBox *DataSerieDialog::seriesTypeSelector()
59 QGroupBox *DataSerieDialog::seriesTypeSelector()
60 {
60 {
61 QVBoxLayout *layout = new QVBoxLayout();
61 QVBoxLayout *layout = new QVBoxLayout();
62
62
63 QRadioButton *line = new QRadioButton("Line");
63 QRadioButton *line = new QRadioButton("Line");
64 line->setChecked(true);
64 line->setChecked(true);
65 layout->addWidget(line);
65 layout->addWidget(line);
66 layout->addWidget(new QRadioButton("Area"));
66 layout->addWidget(new QRadioButton("Area"));
67 layout->addWidget(new QRadioButton("Pie"));
67 layout->addWidget(new QRadioButton("Pie"));
68 layout->addWidget(new QRadioButton("Bar"));
68 layout->addWidget(new QRadioButton("Bar"));
69 layout->addWidget(new QRadioButton("Grouped bar"));
69 layout->addWidget(new QRadioButton("Stacked bar"));
70 layout->addWidget(new QRadioButton("Stacked bar"));
70 layout->addWidget(new QRadioButton("Percent bar"));
71 layout->addWidget(new QRadioButton("Percent bar"));
71 layout->addWidget(new QRadioButton("Scatter"));
72 layout->addWidget(new QRadioButton("Scatter"));
72 layout->addWidget(new QRadioButton("Spline"));
73 layout->addWidget(new QRadioButton("Spline"));
73
74
74 QGroupBox *groupBox = new QGroupBox("Series type");
75 QGroupBox *groupBox = new QGroupBox("Series type");
75 groupBox->setLayout(layout);
76 groupBox->setLayout(layout);
76 selectRadio(groupBox, 0);
77 selectRadio(groupBox, 0);
77
78
78 return groupBox;
79 return groupBox;
79 }
80 }
80
81
81 QGroupBox *DataSerieDialog::columnCountSelector()
82 QGroupBox *DataSerieDialog::columnCountSelector()
82 {
83 {
83 QVBoxLayout *layout = new QVBoxLayout();
84 QVBoxLayout *layout = new QVBoxLayout();
84
85
85 QRadioButton *radio = new QRadioButton("1");
86 QRadioButton *radio = new QRadioButton("1");
86 radio->setChecked(true);
87 radio->setChecked(true);
87 layout->addWidget(radio);
88 layout->addWidget(radio);
88 layout->addWidget(new QRadioButton("2"));
89 layout->addWidget(new QRadioButton("2"));
89 layout->addWidget(new QRadioButton("3"));
90 layout->addWidget(new QRadioButton("3"));
90 layout->addWidget(new QRadioButton("4"));
91 layout->addWidget(new QRadioButton("4"));
91 layout->addWidget(new QRadioButton("5"));
92 layout->addWidget(new QRadioButton("5"));
92 layout->addWidget(new QRadioButton("8"));
93 layout->addWidget(new QRadioButton("8"));
93 layout->addWidget(new QRadioButton("10"));
94 layout->addWidget(new QRadioButton("10"));
94 layout->addWidget(new QRadioButton("100"));
95 layout->addWidget(new QRadioButton("100"));
95
96
96 QGroupBox *groupBox = new QGroupBox("Column count");
97 QGroupBox *groupBox = new QGroupBox("Column count");
97 groupBox->setLayout(layout);
98 groupBox->setLayout(layout);
98 selectRadio(groupBox, 0);
99 selectRadio(groupBox, 0);
99
100
100 return groupBox;
101 return groupBox;
101 }
102 }
102
103
103 QGroupBox *DataSerieDialog::rowCountSelector()
104 QGroupBox *DataSerieDialog::rowCountSelector()
104 {
105 {
105 QVBoxLayout *layout = new QVBoxLayout();
106 QVBoxLayout *layout = new QVBoxLayout();
106
107
107 layout->addWidget(new QRadioButton("1"));
108 layout->addWidget(new QRadioButton("1"));
108 QRadioButton *radio = new QRadioButton("10");
109 QRadioButton *radio = new QRadioButton("10");
109 radio->setChecked(true);
110 radio->setChecked(true);
110 layout->addWidget(radio);
111 layout->addWidget(radio);
111 layout->addWidget(new QRadioButton("50"));
112 layout->addWidget(new QRadioButton("50"));
112 layout->addWidget(new QRadioButton("100"));
113 layout->addWidget(new QRadioButton("100"));
113 layout->addWidget(new QRadioButton("10000"));
114 layout->addWidget(new QRadioButton("10000"));
114 layout->addWidget(new QRadioButton("100000"));
115 layout->addWidget(new QRadioButton("100000"));
115 layout->addWidget(new QRadioButton("1000000"));
116 layout->addWidget(new QRadioButton("1000000"));
116
117
117 QGroupBox *groupBox = new QGroupBox("Row count");
118 QGroupBox *groupBox = new QGroupBox("Row count");
118 groupBox->setLayout(layout);
119 groupBox->setLayout(layout);
119 selectRadio(groupBox, 0);
120 selectRadio(groupBox, 0);
120
121
121 return groupBox;
122 return groupBox;
122 }
123 }
123
124
124 QGroupBox *DataSerieDialog::dataCharacteristicsSelector()
125 QGroupBox *DataSerieDialog::dataCharacteristicsSelector()
125 {
126 {
126 QVBoxLayout *layout = new QVBoxLayout();
127 QVBoxLayout *layout = new QVBoxLayout();
127
128
128 layout->addWidget(new QRadioButton("Linear"));
129 layout->addWidget(new QRadioButton("Linear"));
129 layout->addWidget(new QRadioButton("Constant"));
130 layout->addWidget(new QRadioButton("Constant"));
130 layout->addWidget(new QRadioButton("Random"));
131 layout->addWidget(new QRadioButton("Random"));
131 layout->addWidget(new QRadioButton("Sin"));
132 layout->addWidget(new QRadioButton("Sin"));
132 layout->addWidget(new QRadioButton("Sin + random"));
133 layout->addWidget(new QRadioButton("Sin + random"));
133
134
134 QGroupBox *groupBox = new QGroupBox("Data Characteristics");
135 QGroupBox *groupBox = new QGroupBox("Data Characteristics");
135 groupBox->setLayout(layout);
136 groupBox->setLayout(layout);
136 selectRadio(groupBox, 0);
137 selectRadio(groupBox, 0);
137
138
138 return groupBox;
139 return groupBox;
139 }
140 }
140
141
141 void DataSerieDialog::accept()
142 void DataSerieDialog::accept()
142 {
143 {
143 accepted(radioSelection(m_seriesTypeSelector),
144 accepted(radioSelection(m_seriesTypeSelector),
144 radioSelection(m_columnCountSelector).toInt(),
145 radioSelection(m_columnCountSelector).toInt(),
145 radioSelection(m_rowCountSelector).toInt(),
146 radioSelection(m_rowCountSelector).toInt(),
146 radioSelection(m_dataCharacteristicsSelector),
147 radioSelection(m_dataCharacteristicsSelector),
147 m_labelsSelector->isChecked());
148 m_labelsSelector->isChecked());
148 QDialog::accept();
149 QDialog::accept();
149 }
150 }
150
151
151 void DataSerieDialog::selectRadio(QGroupBox *groupBox, int defaultSelection)
152 void DataSerieDialog::selectRadio(QGroupBox *groupBox, int defaultSelection)
152 {
153 {
153 QVBoxLayout *layout = qobject_cast<QVBoxLayout *>(groupBox->layout());
154 QVBoxLayout *layout = qobject_cast<QVBoxLayout *>(groupBox->layout());
154 Q_ASSERT(layout);
155 Q_ASSERT(layout);
155 Q_ASSERT(layout->count());
156 Q_ASSERT(layout->count());
156
157
157 QLayoutItem *item = 0;
158 QLayoutItem *item = 0;
158 if (defaultSelection == -1) {
159 if (defaultSelection == -1) {
159 item = layout->itemAt(0);
160 item = layout->itemAt(0);
160 } else if (layout->count() > defaultSelection) {
161 } else if (layout->count() > defaultSelection) {
161 item = layout->itemAt(defaultSelection);
162 item = layout->itemAt(defaultSelection);
162 }
163 }
163 Q_ASSERT(item);
164 Q_ASSERT(item);
164 QRadioButton *radio = qobject_cast<QRadioButton *>(item->widget());
165 QRadioButton *radio = qobject_cast<QRadioButton *>(item->widget());
165 Q_ASSERT(radio);
166 Q_ASSERT(radio);
166 radio->setChecked(true);
167 radio->setChecked(true);
167 }
168 }
168
169
169 QString DataSerieDialog::radioSelection(QGroupBox *groupBox)
170 QString DataSerieDialog::radioSelection(QGroupBox *groupBox)
170 {
171 {
171 QString selection;
172 QString selection;
172 QVBoxLayout *layout = qobject_cast<QVBoxLayout *>(groupBox->layout());
173 QVBoxLayout *layout = qobject_cast<QVBoxLayout *>(groupBox->layout());
173 Q_ASSERT(layout);
174 Q_ASSERT(layout);
174
175
175 for (int i(0); i < layout->count(); i++) {
176 for (int i(0); i < layout->count(); i++) {
176 QLayoutItem *item = layout->itemAt(i);
177 QLayoutItem *item = layout->itemAt(i);
177 Q_ASSERT(item);
178 Q_ASSERT(item);
178 QRadioButton *radio = qobject_cast<QRadioButton *>(item->widget());
179 QRadioButton *radio = qobject_cast<QRadioButton *>(item->widget());
179 Q_ASSERT(radio);
180 Q_ASSERT(radio);
180 if (radio->isChecked()) {
181 if (radio->isChecked()) {
181 selection = radio->text();
182 selection = radio->text();
182 break;
183 break;
183 }
184 }
184 }
185 }
185
186
186 qDebug() << "radioSelection: " << selection;
187 qDebug() << "radioSelection: " << selection;
187 return selection;
188 return selection;
188 }
189 }
@@ -1,349 +1,354
1 /****************************************************************************
1 /****************************************************************************
2 **
2 **
3 ** Copyright (C) 2012 Digia Plc
3 ** Copyright (C) 2012 Digia Plc
4 ** All rights reserved.
4 ** All rights reserved.
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 **
6 **
7 ** This file is part of the Qt Commercial Charts Add-on.
7 ** This file is part of the Qt Commercial Charts Add-on.
8 **
8 **
9 ** $QT_BEGIN_LICENSE$
9 ** $QT_BEGIN_LICENSE$
10 ** Licensees holding valid Qt Commercial licenses may use this file in
10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 ** accordance with the Qt Commercial License Agreement provided with the
11 ** accordance with the Qt Commercial License Agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia.
13 ** a written agreement between you and Digia.
14 **
14 **
15 ** If you have questions regarding the use of this file, please use
15 ** If you have questions regarding the use of this file, please use
16 ** contact form at http://qt.digia.com
16 ** contact form at http://qt.digia.com
17 ** $QT_END_LICENSE$
17 ** $QT_END_LICENSE$
18 **
18 **
19 ****************************************************************************/
19 ****************************************************************************/
20
20
21 #include "mainwidget.h"
21 #include "mainwidget.h"
22 #include "dataseriedialog.h"
22 #include "dataseriedialog.h"
23 #include "qchartview.h"
23 #include "qchartview.h"
24 #include "qpieseries.h"
24 #include "qpieseries.h"
25 #include "qscatterseries.h"
25 #include "qscatterseries.h"
26 #include "qlineseries.h"
26 #include "qlineseries.h"
27 #include <qareaseries.h>
27 #include <qareaseries.h>
28 #include <qsplineseries.h>
28 #include <qsplineseries.h>
29 #include <qbarset.h>
29 #include <qbarset.h>
30 #include <qbarseries.h>
30 #include <qbarseries.h>
31 #include <qgroupedbarseries.h>
31 #include <qstackedbarseries.h>
32 #include <qstackedbarseries.h>
32 #include <qpercentbarseries.h>
33 #include <qpercentbarseries.h>
33 #include <QPushButton>
34 #include <QPushButton>
34 #include <QComboBox>
35 #include <QComboBox>
35 #include <QSpinBox>
36 #include <QSpinBox>
36 #include <QCheckBox>
37 #include <QCheckBox>
37 #include <QGridLayout>
38 #include <QGridLayout>
38 #include <QHBoxLayout>
39 #include <QHBoxLayout>
39 #include <QLabel>
40 #include <QLabel>
40 #include <QSpacerItem>
41 #include <QSpacerItem>
41 #include <QMessageBox>
42 #include <QMessageBox>
42 #include <cmath>
43 #include <cmath>
43 #include <QDebug>
44 #include <QDebug>
44 #include <QStandardItemModel>
45 #include <QStandardItemModel>
45
46
46
47
47 QTCOMMERCIALCHART_USE_NAMESPACE
48 QTCOMMERCIALCHART_USE_NAMESPACE
48
49
49 MainWidget::MainWidget(QWidget *parent) :
50 MainWidget::MainWidget(QWidget *parent) :
50 QWidget(parent),
51 QWidget(parent),
51 m_addSerieDialog(0),
52 m_addSerieDialog(0),
52 m_chart(0)
53 m_chart(0)
53 {
54 {
54 m_chart = new QChart();
55 m_chart = new QChart();
55
56
56 // Grid layout for the controls for configuring the chart widget
57 // Grid layout for the controls for configuring the chart widget
57 QGridLayout *grid = new QGridLayout();
58 QGridLayout *grid = new QGridLayout();
58 QPushButton *addSeriesButton = new QPushButton("Add series");
59 QPushButton *addSeriesButton = new QPushButton("Add series");
59 connect(addSeriesButton, SIGNAL(clicked()), this, SLOT(addSeries()));
60 connect(addSeriesButton, SIGNAL(clicked()), this, SLOT(addSeries()));
60 grid->addWidget(addSeriesButton, 0, 1);
61 grid->addWidget(addSeriesButton, 0, 1);
61 initBackroundCombo(grid);
62 initBackroundCombo(grid);
62 initScaleControls(grid);
63 initScaleControls(grid);
63 initThemeCombo(grid);
64 initThemeCombo(grid);
64 initCheckboxes(grid);
65 initCheckboxes(grid);
65
66
66 // add row with empty label to make all the other rows static
67 // add row with empty label to make all the other rows static
67 grid->addWidget(new QLabel(""), grid->rowCount(), 0);
68 grid->addWidget(new QLabel(""), grid->rowCount(), 0);
68 grid->setRowStretch(grid->rowCount() - 1, 1);
69 grid->setRowStretch(grid->rowCount() - 1, 1);
69
70
70 // Create chart view with the chart
71 // Create chart view with the chart
71 m_chartView = new QChartView(m_chart, this);
72 m_chartView = new QChartView(m_chart, this);
72 m_chartView->setRubberBand(QChartView::HorizonalRubberBand);
73 m_chartView->setRubberBand(QChartView::HorizonalRubberBand);
73
74
74 // Another grid layout as a main layout
75 // Another grid layout as a main layout
75 QGridLayout *mainLayout = new QGridLayout();
76 QGridLayout *mainLayout = new QGridLayout();
76 mainLayout->addLayout(grid, 0, 0);
77 mainLayout->addLayout(grid, 0, 0);
77 mainLayout->addWidget(m_chartView, 0, 1, 3, 1);
78 mainLayout->addWidget(m_chartView, 0, 1, 3, 1);
78 setLayout(mainLayout);
79 setLayout(mainLayout);
79 }
80 }
80
81
81 // Combo box for selecting the chart's background
82 // Combo box for selecting the chart's background
82 void MainWidget::initBackroundCombo(QGridLayout *grid)
83 void MainWidget::initBackroundCombo(QGridLayout *grid)
83 {
84 {
84 QComboBox *backgroundCombo = new QComboBox(this);
85 QComboBox *backgroundCombo = new QComboBox(this);
85 backgroundCombo->addItem("Color");
86 backgroundCombo->addItem("Color");
86 backgroundCombo->addItem("Gradient");
87 backgroundCombo->addItem("Gradient");
87 backgroundCombo->addItem("Image");
88 backgroundCombo->addItem("Image");
88 connect(backgroundCombo, SIGNAL(currentIndexChanged(int)),
89 connect(backgroundCombo, SIGNAL(currentIndexChanged(int)),
89 this, SLOT(backgroundChanged(int)));
90 this, SLOT(backgroundChanged(int)));
90
91
91 grid->addWidget(new QLabel("Background:"), grid->rowCount(), 0);
92 grid->addWidget(new QLabel("Background:"), grid->rowCount(), 0);
92 grid->addWidget(backgroundCombo, grid->rowCount() - 1, 1);
93 grid->addWidget(backgroundCombo, grid->rowCount() - 1, 1);
93 }
94 }
94
95
95 // Scale related controls (auto-scale vs. manual min-max values)
96 // Scale related controls (auto-scale vs. manual min-max values)
96 void MainWidget::initScaleControls(QGridLayout *grid)
97 void MainWidget::initScaleControls(QGridLayout *grid)
97 {
98 {
98 m_autoScaleCheck = new QCheckBox("Automatic scaling");
99 m_autoScaleCheck = new QCheckBox("Automatic scaling");
99 connect(m_autoScaleCheck, SIGNAL(stateChanged(int)), this, SLOT(autoScaleChanged(int)));
100 connect(m_autoScaleCheck, SIGNAL(stateChanged(int)), this, SLOT(autoScaleChanged(int)));
100 // Allow setting also non-sense values (like -2147483648 and 2147483647)
101 // Allow setting also non-sense values (like -2147483648 and 2147483647)
101 m_xMinSpin = new QSpinBox();
102 m_xMinSpin = new QSpinBox();
102 m_xMinSpin->setMinimum(INT_MIN);
103 m_xMinSpin->setMinimum(INT_MIN);
103 m_xMinSpin->setMaximum(INT_MAX);
104 m_xMinSpin->setMaximum(INT_MAX);
104 m_xMinSpin->setValue(0);
105 m_xMinSpin->setValue(0);
105 connect(m_xMinSpin, SIGNAL(valueChanged(int)), this, SLOT(xMinChanged(int)));
106 connect(m_xMinSpin, SIGNAL(valueChanged(int)), this, SLOT(xMinChanged(int)));
106 m_xMaxSpin = new QSpinBox();
107 m_xMaxSpin = new QSpinBox();
107 m_xMaxSpin->setMinimum(INT_MIN);
108 m_xMaxSpin->setMinimum(INT_MIN);
108 m_xMaxSpin->setMaximum(INT_MAX);
109 m_xMaxSpin->setMaximum(INT_MAX);
109 m_xMaxSpin->setValue(10);
110 m_xMaxSpin->setValue(10);
110 connect(m_xMaxSpin, SIGNAL(valueChanged(int)), this, SLOT(xMaxChanged(int)));
111 connect(m_xMaxSpin, SIGNAL(valueChanged(int)), this, SLOT(xMaxChanged(int)));
111 m_yMinSpin = new QSpinBox();
112 m_yMinSpin = new QSpinBox();
112 m_yMinSpin->setMinimum(INT_MIN);
113 m_yMinSpin->setMinimum(INT_MIN);
113 m_yMinSpin->setMaximum(INT_MAX);
114 m_yMinSpin->setMaximum(INT_MAX);
114 m_yMinSpin->setValue(0);
115 m_yMinSpin->setValue(0);
115 connect(m_yMinSpin, SIGNAL(valueChanged(int)), this, SLOT(yMinChanged(int)));
116 connect(m_yMinSpin, SIGNAL(valueChanged(int)), this, SLOT(yMinChanged(int)));
116 m_yMaxSpin = new QSpinBox();
117 m_yMaxSpin = new QSpinBox();
117 m_yMaxSpin->setMinimum(INT_MIN);
118 m_yMaxSpin->setMinimum(INT_MIN);
118 m_yMaxSpin->setMaximum(INT_MAX);
119 m_yMaxSpin->setMaximum(INT_MAX);
119 m_yMaxSpin->setValue(10);
120 m_yMaxSpin->setValue(10);
120 connect(m_yMaxSpin, SIGNAL(valueChanged(int)), this, SLOT(yMaxChanged(int)));
121 connect(m_yMaxSpin, SIGNAL(valueChanged(int)), this, SLOT(yMaxChanged(int)));
121
122
122 grid->addWidget(m_autoScaleCheck, grid->rowCount(), 0);
123 grid->addWidget(m_autoScaleCheck, grid->rowCount(), 0);
123 grid->addWidget(new QLabel("x min:"), grid->rowCount(), 0);
124 grid->addWidget(new QLabel("x min:"), grid->rowCount(), 0);
124 grid->addWidget(m_xMinSpin, grid->rowCount() - 1, 1);
125 grid->addWidget(m_xMinSpin, grid->rowCount() - 1, 1);
125 grid->addWidget(new QLabel("x max:"), grid->rowCount(), 0);
126 grid->addWidget(new QLabel("x max:"), grid->rowCount(), 0);
126 grid->addWidget(m_xMaxSpin, grid->rowCount() - 1, 1);
127 grid->addWidget(m_xMaxSpin, grid->rowCount() - 1, 1);
127 grid->addWidget(new QLabel("y min:"), grid->rowCount(), 0);
128 grid->addWidget(new QLabel("y min:"), grid->rowCount(), 0);
128 grid->addWidget(m_yMinSpin, grid->rowCount() - 1, 1);
129 grid->addWidget(m_yMinSpin, grid->rowCount() - 1, 1);
129 grid->addWidget(new QLabel("y max:"), grid->rowCount(), 0);
130 grid->addWidget(new QLabel("y max:"), grid->rowCount(), 0);
130 grid->addWidget(m_yMaxSpin, grid->rowCount() - 1, 1);
131 grid->addWidget(m_yMaxSpin, grid->rowCount() - 1, 1);
131
132
132 m_autoScaleCheck->setChecked(true);
133 m_autoScaleCheck->setChecked(true);
133 }
134 }
134
135
135 // Combo box for selecting theme
136 // Combo box for selecting theme
136 void MainWidget::initThemeCombo(QGridLayout *grid)
137 void MainWidget::initThemeCombo(QGridLayout *grid)
137 {
138 {
138 QComboBox *chartTheme = new QComboBox();
139 QComboBox *chartTheme = new QComboBox();
139 chartTheme->addItem("Default");
140 chartTheme->addItem("Default");
140 chartTheme->addItem("Light");
141 chartTheme->addItem("Light");
141 chartTheme->addItem("Blue Cerulean");
142 chartTheme->addItem("Blue Cerulean");
142 chartTheme->addItem("Dark");
143 chartTheme->addItem("Dark");
143 chartTheme->addItem("Brown Sand");
144 chartTheme->addItem("Brown Sand");
144 chartTheme->addItem("Blue NCS");
145 chartTheme->addItem("Blue NCS");
145 chartTheme->addItem("High Contrast");
146 chartTheme->addItem("High Contrast");
146 chartTheme->addItem("Blue Icy");
147 chartTheme->addItem("Blue Icy");
147 connect(chartTheme, SIGNAL(currentIndexChanged(int)),
148 connect(chartTheme, SIGNAL(currentIndexChanged(int)),
148 this, SLOT(changeChartTheme(int)));
149 this, SLOT(changeChartTheme(int)));
149 grid->addWidget(new QLabel("Chart theme:"), 8, 0);
150 grid->addWidget(new QLabel("Chart theme:"), 8, 0);
150 grid->addWidget(chartTheme, 8, 1);
151 grid->addWidget(chartTheme, 8, 1);
151 }
152 }
152
153
153 // Different check boxes for customizing chart
154 // Different check boxes for customizing chart
154 void MainWidget::initCheckboxes(QGridLayout *grid)
155 void MainWidget::initCheckboxes(QGridLayout *grid)
155 {
156 {
156 // TODO: setZoomEnabled slot has been removed from QChartView -> Re-implement zoom on/off
157 // TODO: setZoomEnabled slot has been removed from QChartView -> Re-implement zoom on/off
157 QCheckBox *zoomCheckBox = new QCheckBox("Drag'n drop Zoom");
158 QCheckBox *zoomCheckBox = new QCheckBox("Drag'n drop Zoom");
158 // connect(zoomCheckBox, SIGNAL(toggled(bool)), m_chartView, SLOT(setZoomEnabled(bool)));
159 // connect(zoomCheckBox, SIGNAL(toggled(bool)), m_chartView, SLOT(setZoomEnabled(bool)));
159 zoomCheckBox->setChecked(true);
160 zoomCheckBox->setChecked(true);
160 grid->addWidget(zoomCheckBox, grid->rowCount(), 0);
161 grid->addWidget(zoomCheckBox, grid->rowCount(), 0);
161
162
162 QCheckBox *aliasCheckBox = new QCheckBox("Anti-alias");
163 QCheckBox *aliasCheckBox = new QCheckBox("Anti-alias");
163 connect(aliasCheckBox, SIGNAL(toggled(bool)), this, SLOT(antiAliasToggled(bool)));
164 connect(aliasCheckBox, SIGNAL(toggled(bool)), this, SLOT(antiAliasToggled(bool)));
164 aliasCheckBox->setChecked(false);
165 aliasCheckBox->setChecked(false);
165 grid->addWidget(aliasCheckBox, grid->rowCount(), 0);
166 grid->addWidget(aliasCheckBox, grid->rowCount(), 0);
166 }
167 }
167
168
168 void MainWidget::antiAliasToggled(bool enabled)
169 void MainWidget::antiAliasToggled(bool enabled)
169 {
170 {
170 m_chartView->setRenderHint(QPainter::Antialiasing, enabled);
171 m_chartView->setRenderHint(QPainter::Antialiasing, enabled);
171 }
172 }
172
173
173 void MainWidget::addSeries()
174 void MainWidget::addSeries()
174 {
175 {
175 if (!m_addSerieDialog) {
176 if (!m_addSerieDialog) {
176 m_addSerieDialog = new DataSerieDialog(this);
177 m_addSerieDialog = new DataSerieDialog(this);
177 connect(m_addSerieDialog, SIGNAL(accepted(QString,int,int,QString,bool)),
178 connect(m_addSerieDialog, SIGNAL(accepted(QString,int,int,QString,bool)),
178 this, SLOT(addSeries(QString,int,int,QString,bool)));
179 this, SLOT(addSeries(QString,int,int,QString,bool)));
179 }
180 }
180 m_addSerieDialog->exec();
181 m_addSerieDialog->exec();
181 }
182 }
182
183
183 QList<RealList> MainWidget::generateTestData(int columnCount, int rowCount, QString dataCharacteristics)
184 QList<RealList> MainWidget::generateTestData(int columnCount, int rowCount, QString dataCharacteristics)
184 {
185 {
185 // TODO: dataCharacteristics
186 // TODO: dataCharacteristics
186 QList<RealList> testData;
187 QList<RealList> testData;
187 for (int j(0); j < columnCount; j++) {
188 for (int j(0); j < columnCount; j++) {
188 QList <qreal> newColumn;
189 QList <qreal> newColumn;
189 for (int i(0); i < rowCount; i++) {
190 for (int i(0); i < rowCount; i++) {
190 if (dataCharacteristics == "Sin") {
191 if (dataCharacteristics == "Sin") {
191 newColumn.append(abs(sin(3.14159265358979 / 50 * i) * 100));
192 newColumn.append(abs(sin(3.14159265358979 / 50 * i) * 100));
192 } else if (dataCharacteristics == "Sin + random") {
193 } else if (dataCharacteristics == "Sin + random") {
193 newColumn.append(abs(sin(3.14159265358979 / 50 * i) * 100) + (rand() % 5));
194 newColumn.append(abs(sin(3.14159265358979 / 50 * i) * 100) + (rand() % 5));
194 } else if (dataCharacteristics == "Random") {
195 } else if (dataCharacteristics == "Random") {
195 newColumn.append(rand() % 10 + (qreal) rand() / (qreal) RAND_MAX);
196 newColumn.append(rand() % 10 + (qreal) rand() / (qreal) RAND_MAX);
196 } else if (dataCharacteristics == "Linear") {
197 } else if (dataCharacteristics == "Linear") {
197 //newColumn.append(i * (j + 1.0));
198 //newColumn.append(i * (j + 1.0));
198 // TODO: temporary hack to make pie work; prevent zero values:
199 // TODO: temporary hack to make pie work; prevent zero values:
199 newColumn.append(i * (j + 1.0) + 0.1);
200 newColumn.append(i * (j + 1.0) + 0.1);
200 } else { // "constant"
201 } else { // "constant"
201 newColumn.append((j + 1.0));
202 newColumn.append((j + 1.0));
202 }
203 }
203 }
204 }
204 testData.append(newColumn);
205 testData.append(newColumn);
205 }
206 }
206 return testData;
207 return testData;
207 }
208 }
208
209
209 QStringList MainWidget::generateLabels(int count)
210 QStringList MainWidget::generateLabels(int count)
210 {
211 {
211 QStringList result;
212 QStringList result;
212 for (int i(0); i < count; i++)
213 for (int i(0); i < count; i++)
213 result.append("label" + QString::number(i));
214 result.append("label" + QString::number(i));
214 return result;
215 return result;
215 }
216 }
216
217
217 void MainWidget::addSeries(QString seriesName, int columnCount, int rowCount, QString dataCharacteristics, bool labelsEnabled)
218 void MainWidget::addSeries(QString seriesName, int columnCount, int rowCount, QString dataCharacteristics, bool labelsEnabled)
218 {
219 {
219 qDebug() << "addSeries: " << seriesName
220 qDebug() << "addSeries: " << seriesName
220 << " columnCount: " << columnCount
221 << " columnCount: " << columnCount
221 << " rowCount: " << rowCount
222 << " rowCount: " << rowCount
222 << " dataCharacteristics: " << dataCharacteristics
223 << " dataCharacteristics: " << dataCharacteristics
223 << " labels enabled: " << labelsEnabled;
224 << " labels enabled: " << labelsEnabled;
224 m_defaultSeriesName = seriesName;
225 m_defaultSeriesName = seriesName;
225
226
226 QList<RealList> data = generateTestData(columnCount, rowCount, dataCharacteristics);
227 QList<RealList> data = generateTestData(columnCount, rowCount, dataCharacteristics);
227
228
228 // Line series and scatter series use similar data
229 // Line series and scatter series use similar data
229 if (seriesName == "Line") {
230 if (seriesName == "Line") {
230 for (int j(0); j < data.count(); j ++) {
231 for (int j(0); j < data.count(); j ++) {
231 QList<qreal> column = data.at(j);
232 QList<qreal> column = data.at(j);
232 QLineSeries *series = new QLineSeries();
233 QLineSeries *series = new QLineSeries();
233 series->setName("line" + QString::number(j));
234 series->setName("line" + QString::number(j));
234 for (int i(0); i < column.count(); i++)
235 for (int i(0); i < column.count(); i++)
235 series->append(i, column.at(i));
236 series->append(i, column.at(i));
236 m_chart->addSeries(series);
237 m_chart->addSeries(series);
237 }
238 }
238 } else if (seriesName == "Area") {
239 } else if (seriesName == "Area") {
239 // TODO: lower series for the area?
240 // TODO: lower series for the area?
240 for (int j(0); j < data.count(); j ++) {
241 for (int j(0); j < data.count(); j ++) {
241 QList<qreal> column = data.at(j);
242 QList<qreal> column = data.at(j);
242 QLineSeries *lineSeries = new QLineSeries();
243 QLineSeries *lineSeries = new QLineSeries();
243 for (int i(0); i < column.count(); i++)
244 for (int i(0); i < column.count(); i++)
244 lineSeries->append(i, column.at(i));
245 lineSeries->append(i, column.at(i));
245 QAreaSeries *areaSeries = new QAreaSeries(lineSeries);
246 QAreaSeries *areaSeries = new QAreaSeries(lineSeries);
246 areaSeries->setName("area" + QString::number(j));
247 areaSeries->setName("area" + QString::number(j));
247 m_chart->addSeries(areaSeries);
248 m_chart->addSeries(areaSeries);
248 }
249 }
249 } else if (seriesName == "Scatter") {
250 } else if (seriesName == "Scatter") {
250 for (int j(0); j < data.count(); j++) {
251 for (int j(0); j < data.count(); j++) {
251 QList<qreal> column = data.at(j);
252 QList<qreal> column = data.at(j);
252 QScatterSeries *series = new QScatterSeries();
253 QScatterSeries *series = new QScatterSeries();
253 series->setName("scatter" + QString::number(j));
254 series->setName("scatter" + QString::number(j));
254 for (int i(0); i < column.count(); i++)
255 for (int i(0); i < column.count(); i++)
255 series->append(i, column.at(i));
256 series->append(i, column.at(i));
256 m_chart->addSeries(series);
257 m_chart->addSeries(series);
257 }
258 }
258 } else if (seriesName == "Pie") {
259 } else if (seriesName == "Pie") {
259 QStringList labels = generateLabels(rowCount);
260 QStringList labels = generateLabels(rowCount);
260 for (int j(0); j < data.count(); j++) {
261 for (int j(0); j < data.count(); j++) {
261 QPieSeries *series = new QPieSeries();
262 QPieSeries *series = new QPieSeries();
262 QList<qreal> column = data.at(j);
263 QList<qreal> column = data.at(j);
263 for (int i(0); i < column.count(); i++)
264 for (int i(0); i < column.count(); i++)
264 series->append(labels.at(i), column.at(i));
265 series->append(labels.at(i), column.at(i));
265 m_chart->addSeries(series);
266 m_chart->addSeries(series);
266 }
267 }
267 } else if (seriesName == "Bar"
268 } else if (seriesName == "Bar"
269 || seriesName == "Grouped bar"
268 || seriesName == "Stacked bar"
270 || seriesName == "Stacked bar"
269 || seriesName == "Percent bar") {
271 || seriesName == "Percent bar") {
270 QStringList category;
272 QStringList category;
271 QStringList labels = generateLabels(rowCount);
273 QStringList labels = generateLabels(rowCount);
272 foreach(QString label, labels)
274 foreach(QString label, labels)
273 category << label;
275 category << label;
274 QBarSeries* series = 0;
276 QBarSeries* series = 0;
275 if (seriesName == "Bar") {
277 if (seriesName == "Bar") {
276 series = new QBarSeries(this);
278 series = new QBarSeries(this);
277 series->setCategories(category);
279 series->setCategories(category);
280 } else if (seriesName == "Grouped bar") {
281 series = new QGroupedBarSeries(this);
282 series->setCategories(category);
278 } else if (seriesName == "Stacked bar") {
283 } else if (seriesName == "Stacked bar") {
279 series = new QStackedBarSeries(this);
284 series = new QStackedBarSeries(this);
280 series->setCategories(category);
285 series->setCategories(category);
281 } else {
286 } else {
282 series = new QPercentBarSeries(this);
287 series = new QPercentBarSeries(this);
283 series->setCategories(category);
288 series->setCategories(category);
284 }
289 }
285
290
286 for (int j(0); j < data.count(); j++) {
291 for (int j(0); j < data.count(); j++) {
287 QList<qreal> column = data.at(j);
292 QList<qreal> column = data.at(j);
288 QBarSet *set = new QBarSet("set" + QString::number(j));
293 QBarSet *set = new QBarSet("set" + QString::number(j));
289 for (int i(0); i < column.count(); i++)
294 for (int i(0); i < column.count(); i++)
290 *set << column.at(i);
295 *set << column.at(i);
291 series->append(set);
296 series->append(set);
292 }
297 }
293
298
294 m_chart->addSeries(series);
299 m_chart->addSeries(series);
295 } else if (seriesName == "Spline") {
300 } else if (seriesName == "Spline") {
296 for (int j(0); j < data.count(); j ++) {
301 for (int j(0); j < data.count(); j ++) {
297 QList<qreal> column = data.at(j);
302 QList<qreal> column = data.at(j);
298 QSplineSeries *series = new QSplineSeries();
303 QSplineSeries *series = new QSplineSeries();
299 for (int i(0); i < column.count(); i++)
304 for (int i(0); i < column.count(); i++)
300 series->append(i, column.at(i));
305 series->append(i, column.at(i));
301 m_chart->addSeries(series);
306 m_chart->addSeries(series);
302 }
307 }
303 }
308 }
304 }
309 }
305
310
306 void MainWidget::backgroundChanged(int itemIndex)
311 void MainWidget::backgroundChanged(int itemIndex)
307 {
312 {
308 qDebug() << "backgroundChanged: " << itemIndex;
313 qDebug() << "backgroundChanged: " << itemIndex;
309 }
314 }
310
315
311 void MainWidget::autoScaleChanged(int value)
316 void MainWidget::autoScaleChanged(int value)
312 {
317 {
313 if (value) {
318 if (value) {
314 // TODO: enable auto scaling
319 // TODO: enable auto scaling
315 } else {
320 } else {
316 // TODO: set scaling manually (and disable auto scaling)
321 // TODO: set scaling manually (and disable auto scaling)
317 }
322 }
318
323
319 m_xMinSpin->setEnabled(!value);
324 m_xMinSpin->setEnabled(!value);
320 m_xMaxSpin->setEnabled(!value);
325 m_xMaxSpin->setEnabled(!value);
321 m_yMinSpin->setEnabled(!value);
326 m_yMinSpin->setEnabled(!value);
322 m_yMaxSpin->setEnabled(!value);
327 m_yMaxSpin->setEnabled(!value);
323 }
328 }
324
329
325 void MainWidget::xMinChanged(int value)
330 void MainWidget::xMinChanged(int value)
326 {
331 {
327 qDebug() << "xMinChanged: " << value;
332 qDebug() << "xMinChanged: " << value;
328 }
333 }
329
334
330 void MainWidget::xMaxChanged(int value)
335 void MainWidget::xMaxChanged(int value)
331 {
336 {
332 qDebug() << "xMaxChanged: " << value;
337 qDebug() << "xMaxChanged: " << value;
333 }
338 }
334
339
335 void MainWidget::yMinChanged(int value)
340 void MainWidget::yMinChanged(int value)
336 {
341 {
337 qDebug() << "yMinChanged: " << value;
342 qDebug() << "yMinChanged: " << value;
338 }
343 }
339
344
340 void MainWidget::yMaxChanged(int value)
345 void MainWidget::yMaxChanged(int value)
341 {
346 {
342 qDebug() << "yMaxChanged: " << value;
347 qDebug() << "yMaxChanged: " << value;
343 }
348 }
344
349
345 void MainWidget::changeChartTheme(int themeIndex)
350 void MainWidget::changeChartTheme(int themeIndex)
346 {
351 {
347 qDebug() << "changeChartTheme: " << themeIndex;
352 qDebug() << "changeChartTheme: " << themeIndex;
348 m_chart->setTheme((QChart::ChartTheme) themeIndex);
353 m_chart->setTheme((QChart::ChartTheme) themeIndex);
349 }
354 }
General Comments 0
You need to be logged in to leave comments. Login now