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