##// END OF EJS Templates
Added auto scaling option to test app
Tero Ahola -
r6:ac2e8ee32571
parent child
Show More
@@ -1,138 +1,152
1 #include "mainwidget.h"
1 #include "mainwidget.h"
2 #include <chartwidget.h>
2 #include <chartwidget.h>
3 #include <QPushButton>
3 #include <QPushButton>
4 #include <QComboBox>
4 #include <QComboBox>
5 #include <QSpinBox>
5 #include <QSpinBox>
6 #include <QCheckBox>
6 #include <QGridLayout>
7 #include <QGridLayout>
7 #include <QHBoxLayout>
8 #include <QHBoxLayout>
8 #include <QLabel>
9 #include <QLabel>
9 #include <QSpacerItem>
10 #include <QSpacerItem>
10 #include <QMessageBox>
11 #include <QMessageBox>
11 #include <QDebug>
12 #include <QDebug>
12
13
13 MainWidget::MainWidget(QWidget *parent) :
14 MainWidget::MainWidget(QWidget *parent) :
14 QWidget(parent)
15 QWidget(parent)
15 {
16 {
16 m_chartWidget = new ChartWidget(this);
17 m_chartWidget = new ChartWidget(this);
17 m_chartWidget->resize(QSize(200,200));
18 m_chartWidget->resize(QSize(200,200));
18 m_chartWidget->setColor(Qt::red);
19 m_chartWidget->setColor(Qt::red);
19
20
20 // Chart type
21 // Chart type
21 QComboBox *chartTypeCombo = new QComboBox(this);
22 QComboBox *chartTypeCombo = new QComboBox(this);
22 chartTypeCombo->addItem("Line");
23 chartTypeCombo->addItem("Line");
23 chartTypeCombo->addItem("Area");
24 chartTypeCombo->addItem("Area");
24 chartTypeCombo->addItem("Bar");
25 chartTypeCombo->addItem("Bar");
25 chartTypeCombo->addItem("Pie");
26 chartTypeCombo->addItem("Pie");
26 chartTypeCombo->addItem("Scatter");
27 chartTypeCombo->addItem("Scatter");
27 chartTypeCombo->addItem("Spline");
28 chartTypeCombo->addItem("Spline");
28 connect(chartTypeCombo, SIGNAL(currentIndexChanged(int)),
29 connect(chartTypeCombo, SIGNAL(currentIndexChanged(int)),
29 this, SLOT(chartTypeChanged(int)));
30 this, SLOT(chartTypeChanged(int)));
30
31
31 // Test data selector
32 // Test data selector
32 QComboBox *dataCombo = new QComboBox(this);
33 QComboBox *dataCombo = new QComboBox(this);
33 dataCombo->addItem("todo: add test data");
34 dataCombo->addItem("todo: add test data");
34 connect(dataCombo, SIGNAL(currentIndexChanged(QString)),
35 connect(dataCombo, SIGNAL(currentIndexChanged(QString)),
35 this, SLOT(dataChanged(QString)));
36 this, SLOT(dataChanged(QString)));
36
37
37 // Chart background
38 // Chart background
38 QComboBox *backgroundCombo = new QComboBox(this);
39 QComboBox *backgroundCombo = new QComboBox(this);
39 backgroundCombo->addItem("todo: add background types");
40 backgroundCombo->addItem("todo: add background types");
40 connect(backgroundCombo, SIGNAL(currentIndexChanged(int)),
41 connect(backgroundCombo, SIGNAL(currentIndexChanged(int)),
41 this, SLOT(backgroundChanged(int)));
42 this, SLOT(backgroundChanged(int)));
42
43
43 // Axis
44 // Axis
45 QCheckBox *autoScaleCheck = new QCheckBox("Automatic scaling");
46 connect(autoScaleCheck, SIGNAL(stateChanged(int)), this, SLOT(autoScaleChanged(int)));
44 // Allow setting also non-sense values (like -2147483648 and 2147483647)
47 // Allow setting also non-sense values (like -2147483648 and 2147483647)
45 QSpinBox *xMinSpin = new QSpinBox();
48 m_xMinSpin = new QSpinBox();
46 xMinSpin->setMinimum(INT_MIN);
49 m_xMinSpin->setMinimum(INT_MIN);
47 xMinSpin->setMaximum(INT_MAX);
50 m_xMinSpin->setMaximum(INT_MAX);
48 xMinSpin->setValue(0);
51 m_xMinSpin->setValue(0);
49 connect(xMinSpin, SIGNAL(valueChanged(int)), this, SLOT(xMinChanged(int)));
52 connect(m_xMinSpin, SIGNAL(valueChanged(int)), this, SLOT(xMinChanged(int)));
50 QSpinBox *xMaxSpin = new QSpinBox();
53 m_xMaxSpin = new QSpinBox();
51 xMaxSpin->setMinimum(INT_MIN);
54 m_xMaxSpin->setMinimum(INT_MIN);
52 xMaxSpin->setMaximum(INT_MAX);
55 m_xMaxSpin->setMaximum(INT_MAX);
53 xMaxSpin->setValue(10);
56 m_xMaxSpin->setValue(10);
54 connect(xMaxSpin, SIGNAL(valueChanged(int)), this, SLOT(xMaxChanged(int)));
57 connect(m_xMaxSpin, SIGNAL(valueChanged(int)), this, SLOT(xMaxChanged(int)));
55 QSpinBox *yMinSpin = new QSpinBox();
58 m_yMinSpin = new QSpinBox();
56 yMinSpin->setMinimum(INT_MIN);
59 m_yMinSpin->setMinimum(INT_MIN);
57 yMinSpin->setMaximum(INT_MAX);
60 m_yMinSpin->setMaximum(INT_MAX);
58 yMinSpin->setValue(0);
61 m_yMinSpin->setValue(0);
59 connect(yMinSpin, SIGNAL(valueChanged(int)), this, SLOT(yMinChanged(int)));
62 connect(m_yMinSpin, SIGNAL(valueChanged(int)), this, SLOT(yMinChanged(int)));
60 QSpinBox *yMaxSpin = new QSpinBox();
63 m_yMaxSpin = new QSpinBox();
61 yMaxSpin->setMinimum(INT_MIN);
64 m_yMaxSpin->setMinimum(INT_MIN);
62 yMaxSpin->setMaximum(INT_MAX);
65 m_yMaxSpin->setMaximum(INT_MAX);
63 yMaxSpin->setValue(10);
66 m_yMaxSpin->setValue(10);
64 connect(yMaxSpin, SIGNAL(valueChanged(int)), this, SLOT(yMaxChanged(int)));
67 connect(m_yMaxSpin, SIGNAL(valueChanged(int)), this, SLOT(yMaxChanged(int)));
65
68
66 QGridLayout *grid = new QGridLayout();
69 QGridLayout *grid = new QGridLayout();
67 QHBoxLayout *hbox = new QHBoxLayout();
70 QHBoxLayout *hbox = new QHBoxLayout();
68 grid->addWidget(new QLabel("Chart type:"), 0, 0);
71 grid->addWidget(new QLabel("Chart type:"), 0, 0);
69 grid->addWidget(chartTypeCombo, 0, 1);
72 grid->addWidget(chartTypeCombo, 0, 1);
70 grid->addWidget(new QLabel("Data:"), 1, 0);
73 grid->addWidget(new QLabel("Data:"), 1, 0);
71 grid->addWidget(dataCombo, 1, 1);
74 grid->addWidget(dataCombo, 1, 1);
72 grid->addWidget(new QLabel("Background:"), 2, 0);
75 grid->addWidget(new QLabel("Background:"), 2, 0);
73 grid->addWidget(backgroundCombo, 2, 1);
76 grid->addWidget(backgroundCombo, 2, 1);
74 grid->addWidget(new QLabel("x min:"), 3, 0);
77 grid->addWidget(autoScaleCheck, 3, 0);
75 grid->addWidget(xMinSpin, 3, 1);
78 grid->addWidget(new QLabel("x min:"), 4, 0);
76 grid->addWidget(new QLabel("x max:"), 4, 0);
79 grid->addWidget(m_xMinSpin, 4, 1);
77 grid->addWidget(xMaxSpin, 4, 1);
80 grid->addWidget(new QLabel("x max:"), 5, 0);
78 grid->addWidget(new QLabel("y min:"), 5, 0);
81 grid->addWidget(m_xMaxSpin, 5, 1);
79 grid->addWidget(yMinSpin, 5, 1);
82 grid->addWidget(new QLabel("y min:"), 6, 0);
80 grid->addWidget(new QLabel("y max:"), 6, 0);
83 grid->addWidget(m_yMinSpin, 6, 1);
81 grid->addWidget(yMaxSpin, 6, 1);
84 grid->addWidget(new QLabel("y max:"), 7, 0);
85 grid->addWidget(m_yMaxSpin, 7, 1);
82 // add row with empty label to make all the other rows static
86 // add row with empty label to make all the other rows static
83 grid->addWidget(new QLabel(""), 7, 0);
87 grid->addWidget(new QLabel(""), 8, 0);
84 grid->setRowStretch(7, 1);
88 grid->setRowStretch(8, 1);
85
89
86 hbox->addLayout(grid);
90 hbox->addLayout(grid);
87 hbox->addWidget(m_chartWidget);
91 hbox->addWidget(m_chartWidget);
88 hbox->setStretch(1, 1);
92 hbox->setStretch(1, 1);
89
93
90 setLayout(hbox);
94 setLayout(hbox);
95
96 // Setting auto scale affects min/max value spin boxes, so it needs to be done after they have
97 // been constructed
98 autoScaleCheck->setChecked(true);
91 }
99 }
92
100
93 void MainWidget::chartTypeChanged(int itemIndex)
101 void MainWidget::chartTypeChanged(int itemIndex)
94 {
102 {
95 qDebug() << "chartTypeChanged: " << itemIndex;
103 qDebug() << "chartTypeChanged: " << itemIndex;
96
104 QMessageBox msg;
97 switch (itemIndex) {
105 msg.setText("TODO: API for setting chart type");
98 // case 0:
106 msg.exec();
99 // m_chartWidget->setType(ChartWidget::TypeLine);
100 // break;
101 default:
102 // TODO: api for setting chart type?
103 QMessageBox msg;
104 msg.setText("TODO: API for setting chart type");
105 msg.exec();
106 break;
107 }
108 }
107 }
109
108
110 void MainWidget::dataChanged(QString itemText)
109 void MainWidget::dataChanged(QString itemText)
111 {
110 {
112 qDebug() << "dataChanged: " << itemText;
111 qDebug() << "dataChanged: " << itemText;
113 }
112 }
114
113
115 void MainWidget::backgroundChanged(int itemIndex)
114 void MainWidget::backgroundChanged(int itemIndex)
116 {
115 {
117 qDebug() << "backgroundChanged: " << itemIndex;
116 qDebug() << "backgroundChanged: " << itemIndex;
118 }
117 }
119
118
119 void MainWidget::autoScaleChanged(int value)
120 {
121 if (this->isVisible()) {
122 QMessageBox msg;
123 msg.setText("TODO: APIs for using either auto scaling or explicit values");
124 msg.exec();
125 }
126
127 // TODO: get initial spin box axis values from charts widget
128 m_xMinSpin->setEnabled(value == Qt::Unchecked);
129 m_xMaxSpin->setEnabled(value == Qt::Unchecked);
130 m_yMinSpin->setEnabled(value == Qt::Unchecked);
131 m_yMaxSpin->setEnabled(value == Qt::Unchecked);
132 }
133
120 void MainWidget::xMinChanged(int value)
134 void MainWidget::xMinChanged(int value)
121 {
135 {
122 qDebug() << "xMinChanged: " << value;
136 qDebug() << "xMinChanged: " << value;
123 }
137 }
124
138
125 void MainWidget::xMaxChanged(int value)
139 void MainWidget::xMaxChanged(int value)
126 {
140 {
127 qDebug() << "xMaxChanged: " << value;
141 qDebug() << "xMaxChanged: " << value;
128 }
142 }
129
143
130 void MainWidget::yMinChanged(int value)
144 void MainWidget::yMinChanged(int value)
131 {
145 {
132 qDebug() << "yMinChanged: " << value;
146 qDebug() << "yMinChanged: " << value;
133 }
147 }
134
148
135 void MainWidget::yMaxChanged(int value)
149 void MainWidget::yMaxChanged(int value)
136 {
150 {
137 qDebug() << "yMaxChanged: " << value;
151 qDebug() << "yMaxChanged: " << value;
138 }
152 }
@@ -1,29 +1,35
1 #ifndef MAINWIDGET_H
1 #ifndef MAINWIDGET_H
2 #define MAINWIDGET_H
2 #define MAINWIDGET_H
3
3
4 #include <QWidget>
4 #include <QWidget>
5
5
6 class ChartWidget;
6 class ChartWidget;
7 class QSpinBox;
7
8
8 class MainWidget : public QWidget
9 class MainWidget : public QWidget
9 {
10 {
10 Q_OBJECT
11 Q_OBJECT
11 public:
12 public:
12 explicit MainWidget(QWidget *parent = 0);
13 explicit MainWidget(QWidget *parent = 0);
13
14
14 signals:
15 signals:
15
16
16 private slots:
17 private slots:
17 void chartTypeChanged(int itemIndex);
18 void chartTypeChanged(int itemIndex);
18 void dataChanged(QString itemText);
19 void dataChanged(QString itemText);
19 void backgroundChanged(int itemIndex);
20 void backgroundChanged(int itemIndex);
21 void autoScaleChanged(int value);
20 void xMinChanged(int value);
22 void xMinChanged(int value);
21 void xMaxChanged(int value);
23 void xMaxChanged(int value);
22 void yMinChanged(int value);
24 void yMinChanged(int value);
23 void yMaxChanged(int value);
25 void yMaxChanged(int value);
24
26
25 private:
27 private:
26 ChartWidget *m_chartWidget;
28 ChartWidget *m_chartWidget;
29 QSpinBox *m_xMinSpin;
30 QSpinBox *m_xMaxSpin;
31 QSpinBox *m_yMinSpin;
32 QSpinBox *m_yMaxSpin;
27 };
33 };
28
34
29 #endif // MAINWIDGET_H
35 #endif // MAINWIDGET_H
General Comments 0
You need to be logged in to leave comments. Login now