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