##// END OF EJS Templates
The test app now preserves series type selection
Tero Ahola -
r26:aa0e09b6abc0
parent child
Show More
@@ -1,54 +1,61
1 1 #include "dataseriedialog.h"
2 2 #include <QDialogButtonBox>
3 3 #include <QGridLayout>
4 4 #include <QComboBox>
5 5 #include <QPushButton>
6 6 #include <QLabel>
7 7 #include <QDebug>
8 8
9 DataSerieDialog::DataSerieDialog(QWidget *parent) :
9 DataSerieDialog::DataSerieDialog(QString defaultType, QWidget *parent) :
10 10 QDialog(parent)
11 11 {
12 12 // Combo box for selecting the series type
13 13 m_seriesTypeCombo = new QComboBox(this);
14 14 m_seriesTypeCombo->addItem("Line");
15 15 m_seriesTypeCombo->addItem("Area");
16 16 m_seriesTypeCombo->addItem("Bar");
17 17 m_seriesTypeCombo->addItem("Pie");
18 18 m_seriesTypeCombo->addItem("Scatter");
19 19 m_seriesTypeCombo->addItem("Spline");
20 20
21 // Allow pre-selection of a series type
22 if (defaultType != "") {
23 int index = m_seriesTypeCombo->findText(defaultType);
24 if (index > 0)
25 m_seriesTypeCombo->setCurrentIndex(index);
26 }
27
21 28 // Combo box for selecting data for the new series
22 29 m_testDataCombo = new QComboBox(this);
23 30 m_testDataCombo->addItem("linear");
24 31 m_testDataCombo->addItem("SIN");
25 32 m_testDataCombo->addItem("SIN + random");
26 33 m_testDataCombo->addItem("TODO From file...");
27 34 m_testDataCombo->addItem("TODO From URL...");
28 35
29 36 QDialogButtonBox *addSeriesBox = new QDialogButtonBox(Qt::Horizontal);
30 37 QPushButton *b = addSeriesBox->addButton(QDialogButtonBox::Ok);
31 38 connect(b, SIGNAL(clicked()), this, SLOT(accept()));
32 39 b = addSeriesBox->addButton(QDialogButtonBox::Cancel);
33 40 connect(b, SIGNAL(clicked()), this, SLOT(reject()));
34 41
35 42 QGridLayout *grid = new QGridLayout();
36 43 grid->addWidget(new QLabel("Series type:"), 0, 0);
37 44 grid->addWidget(m_seriesTypeCombo, 0, 1);
38 45 grid->addWidget(new QLabel("Data:"), 1, 0);
39 46 grid->addWidget(m_testDataCombo, 1, 1);
40 47 grid->addWidget(addSeriesBox, 2, 1);
41 48
42 49 setLayout(grid);
43 50 }
44 51
45 52 void DataSerieDialog::accept()
46 53 {
47 54 accepted(m_seriesTypeCombo->currentText(), m_testDataCombo->currentText());
48 55 QDialog::accept();
49 56 }
50 57 //void DataSerieDialog::addSeries(QAbstractButton *button)
51 58 //{
52 59 // addSeries(button->text().toAscii());
53 60 // accept();
54 61 //}
@@ -1,25 +1,25
1 1 #ifndef DATASERIEDIALOG_H
2 2 #define DATASERIEDIALOG_H
3 3
4 4 #include <QDialog>
5 5
6 6 class QComboBox;
7 7
8 8 class DataSerieDialog : public QDialog
9 9 {
10 10 Q_OBJECT
11 11 public:
12 explicit DataSerieDialog(QWidget *parent = 0);
12 explicit DataSerieDialog(QString defaultType, QWidget *parent = 0);
13 13
14 14 signals:
15 15 void accepted(QString series, QString data);
16 16
17 17 public slots:
18 18 void accept();
19 19
20 20 private:
21 21 QComboBox *m_seriesTypeCombo;
22 22 QComboBox *m_testDataCombo;
23 23 };
24 24
25 25 #endif // DATASERIEDIALOG_H
@@ -1,222 +1,223
1 1 #include "mainwidget.h"
2 2 #include "dataseriedialog.h"
3 3 #include <qxyseries.h>
4 4 #include <QPushButton>
5 5 #include <QComboBox>
6 6 #include <QSpinBox>
7 7 #include <QCheckBox>
8 8 #include <QGridLayout>
9 9 #include <QHBoxLayout>
10 10 #include <QLabel>
11 11 #include <QSpacerItem>
12 12 #include <QMessageBox>
13 13 #include <cmath>
14 14 #include <QDebug>
15 15
16 16 QCHART_USE_NAMESPACE
17 17
18 18 MainWidget::MainWidget(QWidget *parent) :
19 19 QWidget(parent)
20 20 {
21 21 m_chartWidget = new QChartWidget(this);
22 22 // m_chartWidget->resize(QSize(200,200));
23 23 // m_chartWidget->setColor(Qt::red);
24 24
25 25 QPushButton *addSeriesButton = new QPushButton("Add series");
26 26 connect(addSeriesButton, SIGNAL(clicked()), this, SLOT(addSeries()));
27 27
28 28 // Chart background
29 29 QComboBox *backgroundCombo = new QComboBox(this);
30 30 backgroundCombo->addItem("None");
31 31 backgroundCombo->addItem("TODO Grid");
32 32 backgroundCombo->addItem("TODO Image");
33 33 connect(backgroundCombo, SIGNAL(currentIndexChanged(int)),
34 34 this, SLOT(backgroundChanged(int)));
35 35
36 36 // Axis
37 37 // TODO: multiple axes?
38 38 m_autoScaleCheck = new QCheckBox("Automatic scaling");
39 39 connect(m_autoScaleCheck, SIGNAL(stateChanged(int)), this, SLOT(autoScaleChanged(int)));
40 40 // Allow setting also non-sense values (like -2147483648 and 2147483647)
41 41 m_xMinSpin = new QSpinBox();
42 42 m_xMinSpin->setMinimum(INT_MIN);
43 43 m_xMinSpin->setMaximum(INT_MAX);
44 44 m_xMinSpin->setValue(0);
45 45 connect(m_xMinSpin, SIGNAL(valueChanged(int)), this, SLOT(xMinChanged(int)));
46 46 m_xMaxSpin = new QSpinBox();
47 47 m_xMaxSpin->setMinimum(INT_MIN);
48 48 m_xMaxSpin->setMaximum(INT_MAX);
49 49 m_xMaxSpin->setValue(10);
50 50 connect(m_xMaxSpin, SIGNAL(valueChanged(int)), this, SLOT(xMaxChanged(int)));
51 51 m_yMinSpin = new QSpinBox();
52 52 m_yMinSpin->setMinimum(INT_MIN);
53 53 m_yMinSpin->setMaximum(INT_MAX);
54 54 m_yMinSpin->setValue(0);
55 55 connect(m_yMinSpin, SIGNAL(valueChanged(int)), this, SLOT(yMinChanged(int)));
56 56 m_yMaxSpin = new QSpinBox();
57 57 m_yMaxSpin->setMinimum(INT_MIN);
58 58 m_yMaxSpin->setMaximum(INT_MAX);
59 59 m_yMaxSpin->setValue(10);
60 60 connect(m_yMaxSpin, SIGNAL(valueChanged(int)), this, SLOT(yMaxChanged(int)));
61 61
62 62 QGridLayout *grid = new QGridLayout();
63 63 QHBoxLayout *hbox = new QHBoxLayout();
64 64 //grid->addWidget(new QLabel("Add series:"), 0, 0);
65 65 grid->addWidget(addSeriesButton, 0, 1);
66 66 grid->addWidget(new QLabel("Background:"), 2, 0);
67 67 grid->addWidget(backgroundCombo, 2, 1);
68 68 grid->addWidget(m_autoScaleCheck, 3, 0);
69 69 grid->addWidget(new QLabel("x min:"), 4, 0);
70 70 grid->addWidget(m_xMinSpin, 4, 1);
71 71 grid->addWidget(new QLabel("x max:"), 5, 0);
72 72 grid->addWidget(m_xMaxSpin, 5, 1);
73 73 grid->addWidget(new QLabel("y min:"), 6, 0);
74 74 grid->addWidget(m_yMinSpin, 6, 1);
75 75 grid->addWidget(new QLabel("y max:"), 7, 0);
76 76 grid->addWidget(m_yMaxSpin, 7, 1);
77 77 // add row with empty label to make all the other rows static
78 78 grid->addWidget(new QLabel(""), 8, 0);
79 79 grid->setRowStretch(8, 1);
80 80
81 81 hbox->addLayout(grid);
82 82 hbox->addWidget(m_chartWidget);
83 83 hbox->setStretch(1, 1);
84 84
85 85 setLayout(hbox);
86 86
87 87 m_autoScaleCheck->setChecked(true);
88 88 chartTypeChanged(4);
89 89 testDataChanged(0);
90 90 }
91 91
92 92 void MainWidget::addSeries()
93 93 {
94 DataSerieDialog dialog(this);
94 DataSerieDialog dialog(m_defaultSeries, this);
95 95 connect(&dialog, SIGNAL(accepted(QString, QString)), this, SLOT(addSeries(QString, QString)));
96 96 dialog.exec();
97 97 }
98 98
99 99 void MainWidget::addSeries(QString series, QString data)
100 100 {
101 101 qDebug() << "addSeries: " << series << " data: " << data;
102 m_defaultSeries = series;
102 103
103 104 QXYChartSeries* series0 = new QXYChartSeries();
104 105
105 106 if (data == "linear") {
106 107 // TODO
107 108 } else if (data == "SIN") {
108 109 series0->setColor(Qt::blue);
109 110 for (int x = 0; x < 100; x++)
110 111 series0->add(x, abs(sin(3.14159265358979 / 50 * x) * 100));
111 112 QList<QXYChartSeries*> dataset;
112 113 dataset << series0;
113 114 } else if (data == "SIN + random") {
114 115 series0->setColor(Qt::blue);
115 116 for (qreal x = 0; x < 100; x += 0.1) {
116 117 series0->add(x + (rand() % 5),
117 118 abs(sin(3.14159265358979 / 50 * x) * 100) + (rand() % 5));
118 119 }
119 120 } else {
120 121 // TODO: check if data has a valid file name
121 122 }
122 123
123 124 QList<QXYChartSeries*> dataset;
124 125 dataset << series0;
125 126
126 127 if (series == "Scatter") {
127 128 m_chartWidget->addDataSeries(QChart::DataSeriesTypeScatter, dataset);
128 129 } else if (series == "Line") {
129 130 m_chartWidget->addDataSeries(QChart::DataSeriesTypeLine, dataset);
130 131 } else {
131 132 // TODO
132 133 }
133 134 }
134 135
135 136 void MainWidget::chartTypeChanged(int itemIndex)
136 137 {
137 138 // TODO: change chart type
138 139 switch (itemIndex) {
139 140 case 4:
140 141 //m_chartWidget->setType(4);
141 142 break;
142 143 default: {
143 144 //m_chartWidget->setType(0);
144 145 break;
145 146 }
146 147 }
147 148 }
148 149
149 150 void MainWidget::testDataChanged(int itemIndex)
150 151 {
151 152 qDebug() << "testDataChanged: " << itemIndex;
152 153
153 154 // switch (itemIndex) {
154 155 // case 0: {
155 156 // QList<QChartDataPoint> data;
156 157 // for (int x = 0; x < 20; x++) {
157 158 // data.append(QChartDataPoint() << x << x / 2);
158 159 // }
159 160 // m_chartWidget->setData(data);
160 161 // break;
161 162 // }
162 163 // case 1: {
163 164 // QList<QChartDataPoint> data;
164 165 // for (int x = 0; x < 100; x++) {
165 166 // data.append(QChartDataPoint() << x - 200 << 2 * (uint(sin(3.14159/50*x)*80) % 100));
166 167 // }
167 168 // m_chartWidget->setData(data);
168 169 // break;
169 170 // }
170 171 // case 2: {
171 172 // QList<QChartDataPoint> data;
172 173 // for (int x = 0; x < 1000; x++) {
173 174 // data.append(QChartDataPoint() << x - 200 << 2 * (uint(sin(3.14159/50*x)*80) % 100) + (rand() % 100 * 0.2));
174 175 // data.append(QChartDataPoint() << x - 200 << 2 * (uint(sin(3.14159/50*x)*80) % 100) + (rand() % 100 * 0.2));
175 176 // data.append(QChartDataPoint() << x - 200 << 2 * (uint(sin(3.14159/50*x)*80) % 100) + (rand() % 100 * 0.2));
176 177 // }
177 178 // m_chartWidget->setData(data);
178 179 // break;
179 180 // }
180 181 // default:
181 182 // break;
182 183 // }
183 184 }
184 185
185 186 void MainWidget::backgroundChanged(int itemIndex)
186 187 {
187 188 qDebug() << "backgroundChanged: " << itemIndex;
188 189 }
189 190
190 191 void MainWidget::autoScaleChanged(int value)
191 192 {
192 193 if (value) {
193 194 // TODO: enable auto scaling
194 195 } else {
195 196 // TODO: set scaling manually (and disable auto scaling)
196 197 }
197 198
198 199 m_xMinSpin->setEnabled(!value);
199 200 m_xMaxSpin->setEnabled(!value);
200 201 m_yMinSpin->setEnabled(!value);
201 202 m_yMaxSpin->setEnabled(!value);
202 203 }
203 204
204 205 void MainWidget::xMinChanged(int value)
205 206 {
206 207 qDebug() << "xMinChanged: " << value;
207 208 }
208 209
209 210 void MainWidget::xMaxChanged(int value)
210 211 {
211 212 qDebug() << "xMaxChanged: " << value;
212 213 }
213 214
214 215 void MainWidget::yMinChanged(int value)
215 216 {
216 217 qDebug() << "yMinChanged: " << value;
217 218 }
218 219
219 220 void MainWidget::yMaxChanged(int value)
220 221 {
221 222 qDebug() << "yMaxChanged: " << value;
222 223 }
@@ -1,42 +1,43
1 1 #ifndef MAINWIDGET_H
2 2 #define MAINWIDGET_H
3 3
4 4 #include <qchartconfig.h>
5 5 #include <qchartwidget.h>
6 6 #include <QWidget>
7 7
8 8 class QSpinBox;
9 9 class QCheckBox;
10 10
11 11 QCHART_USE_NAMESPACE
12 12
13 13 class MainWidget : public QWidget
14 14 {
15 15 Q_OBJECT
16 16 public:
17 17 explicit MainWidget(QWidget *parent = 0);
18 18
19 19 signals:
20 20
21 21 private slots:
22 22 void chartTypeChanged(int itemIndex);
23 23 void addSeries();
24 24 void addSeries(QString series, QString data);
25 25 void testDataChanged(int itemIndex);
26 26 void backgroundChanged(int itemIndex);
27 27 void autoScaleChanged(int value);
28 28 void xMinChanged(int value);
29 29 void xMaxChanged(int value);
30 30 void yMinChanged(int value);
31 31 void yMaxChanged(int value);
32 32
33 33 private:
34 34 QChartWidget *m_chartWidget;
35 35 QCheckBox *m_autoScaleCheck;
36 36 QSpinBox *m_xMinSpin;
37 37 QSpinBox *m_xMaxSpin;
38 38 QSpinBox *m_yMinSpin;
39 39 QSpinBox *m_yMaxSpin;
40 QString m_defaultSeries;
40 41 };
41 42
42 43 #endif // MAINWIDGET_H
General Comments 0
You need to be logged in to leave comments. Login now