@@ -0,0 +1,138 | |||||
|
1 | #include "mainwidget.h" | |||
|
2 | #include <chartwidget.h> | |||
|
3 | #include <QPushButton> | |||
|
4 | #include <QComboBox> | |||
|
5 | #include <QSpinBox> | |||
|
6 | #include <QGridLayout> | |||
|
7 | #include <QHBoxLayout> | |||
|
8 | #include <QLabel> | |||
|
9 | #include <QSpacerItem> | |||
|
10 | #include <QMessageBox> | |||
|
11 | #include <QDebug> | |||
|
12 | ||||
|
13 | MainWidget::MainWidget(QWidget *parent) : | |||
|
14 | QWidget(parent) | |||
|
15 | { | |||
|
16 | m_chartWidget = new ChartWidget(this); | |||
|
17 | m_chartWidget->resize(QSize(200,200)); | |||
|
18 | m_chartWidget->setColor(Qt::red); | |||
|
19 | ||||
|
20 | // Chart type | |||
|
21 | QComboBox *chartTypeCombo = new QComboBox(this); | |||
|
22 | chartTypeCombo->addItem("Line"); | |||
|
23 | chartTypeCombo->addItem("Area"); | |||
|
24 | chartTypeCombo->addItem("Bar"); | |||
|
25 | chartTypeCombo->addItem("Pie"); | |||
|
26 | chartTypeCombo->addItem("Scatter"); | |||
|
27 | chartTypeCombo->addItem("Spline"); | |||
|
28 | connect(chartTypeCombo, SIGNAL(currentIndexChanged(int)), | |||
|
29 | this, SLOT(chartTypeChanged(int))); | |||
|
30 | ||||
|
31 | // Test data selector | |||
|
32 | QComboBox *dataCombo = new QComboBox(this); | |||
|
33 | dataCombo->addItem("todo: add test data"); | |||
|
34 | connect(dataCombo, SIGNAL(currentIndexChanged(QString)), | |||
|
35 | this, SLOT(dataChanged(QString))); | |||
|
36 | ||||
|
37 | // Chart background | |||
|
38 | QComboBox *backgroundCombo = new QComboBox(this); | |||
|
39 | backgroundCombo->addItem("todo: add background types"); | |||
|
40 | connect(backgroundCombo, SIGNAL(currentIndexChanged(int)), | |||
|
41 | this, SLOT(backgroundChanged(int))); | |||
|
42 | ||||
|
43 | // Axis | |||
|
44 | // Allow setting also non-sense values (like -2147483648 and 2147483647) | |||
|
45 | QSpinBox *xMinSpin = new QSpinBox(); | |||
|
46 | xMinSpin->setMinimum(INT_MIN); | |||
|
47 | xMinSpin->setMaximum(INT_MAX); | |||
|
48 | xMinSpin->setValue(0); | |||
|
49 | connect(xMinSpin, SIGNAL(valueChanged(int)), this, SLOT(xMinChanged(int))); | |||
|
50 | QSpinBox *xMaxSpin = new QSpinBox(); | |||
|
51 | xMaxSpin->setMinimum(INT_MIN); | |||
|
52 | xMaxSpin->setMaximum(INT_MAX); | |||
|
53 | xMaxSpin->setValue(10); | |||
|
54 | connect(xMaxSpin, SIGNAL(valueChanged(int)), this, SLOT(xMaxChanged(int))); | |||
|
55 | QSpinBox *yMinSpin = new QSpinBox(); | |||
|
56 | yMinSpin->setMinimum(INT_MIN); | |||
|
57 | yMinSpin->setMaximum(INT_MAX); | |||
|
58 | yMinSpin->setValue(0); | |||
|
59 | connect(yMinSpin, SIGNAL(valueChanged(int)), this, SLOT(yMinChanged(int))); | |||
|
60 | QSpinBox *yMaxSpin = new QSpinBox(); | |||
|
61 | yMaxSpin->setMinimum(INT_MIN); | |||
|
62 | yMaxSpin->setMaximum(INT_MAX); | |||
|
63 | yMaxSpin->setValue(10); | |||
|
64 | connect(yMaxSpin, SIGNAL(valueChanged(int)), this, SLOT(yMaxChanged(int))); | |||
|
65 | ||||
|
66 | QGridLayout *grid = new QGridLayout(); | |||
|
67 | QHBoxLayout *hbox = new QHBoxLayout(); | |||
|
68 | grid->addWidget(new QLabel("Chart type:"), 0, 0); | |||
|
69 | grid->addWidget(chartTypeCombo, 0, 1); | |||
|
70 | grid->addWidget(new QLabel("Data:"), 1, 0); | |||
|
71 | grid->addWidget(dataCombo, 1, 1); | |||
|
72 | grid->addWidget(new QLabel("Background:"), 2, 0); | |||
|
73 | grid->addWidget(backgroundCombo, 2, 1); | |||
|
74 | grid->addWidget(new QLabel("x min:"), 3, 0); | |||
|
75 | grid->addWidget(xMinSpin, 3, 1); | |||
|
76 | grid->addWidget(new QLabel("x max:"), 4, 0); | |||
|
77 | grid->addWidget(xMaxSpin, 4, 1); | |||
|
78 | grid->addWidget(new QLabel("y min:"), 5, 0); | |||
|
79 | grid->addWidget(yMinSpin, 5, 1); | |||
|
80 | grid->addWidget(new QLabel("y max:"), 6, 0); | |||
|
81 | grid->addWidget(yMaxSpin, 6, 1); | |||
|
82 | // add row with empty label to make all the other rows static | |||
|
83 | grid->addWidget(new QLabel(""), 7, 0); | |||
|
84 | grid->setRowStretch(7, 1); | |||
|
85 | ||||
|
86 | hbox->addLayout(grid); | |||
|
87 | hbox->addWidget(m_chartWidget); | |||
|
88 | hbox->setStretch(1, 1); | |||
|
89 | ||||
|
90 | setLayout(hbox); | |||
|
91 | } | |||
|
92 | ||||
|
93 | void MainWidget::chartTypeChanged(int itemIndex) | |||
|
94 | { | |||
|
95 | qDebug() << "chartTypeChanged: " << itemIndex; | |||
|
96 | ||||
|
97 | switch (itemIndex) { | |||
|
98 | // case 0: | |||
|
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 | } | |||
|
109 | ||||
|
110 | void MainWidget::dataChanged(QString itemText) | |||
|
111 | { | |||
|
112 | qDebug() << "dataChanged: " << itemText; | |||
|
113 | } | |||
|
114 | ||||
|
115 | void MainWidget::backgroundChanged(int itemIndex) | |||
|
116 | { | |||
|
117 | qDebug() << "backgroundChanged: " << itemIndex; | |||
|
118 | } | |||
|
119 | ||||
|
120 | void MainWidget::xMinChanged(int value) | |||
|
121 | { | |||
|
122 | qDebug() << "xMinChanged: " << value; | |||
|
123 | } | |||
|
124 | ||||
|
125 | void MainWidget::xMaxChanged(int value) | |||
|
126 | { | |||
|
127 | qDebug() << "xMaxChanged: " << value; | |||
|
128 | } | |||
|
129 | ||||
|
130 | void MainWidget::yMinChanged(int value) | |||
|
131 | { | |||
|
132 | qDebug() << "yMinChanged: " << value; | |||
|
133 | } | |||
|
134 | ||||
|
135 | void MainWidget::yMaxChanged(int value) | |||
|
136 | { | |||
|
137 | qDebug() << "yMaxChanged: " << value; | |||
|
138 | } |
@@ -0,0 +1,29 | |||||
|
1 | #ifndef MAINWIDGET_H | |||
|
2 | #define MAINWIDGET_H | |||
|
3 | ||||
|
4 | #include <QWidget> | |||
|
5 | ||||
|
6 | class ChartWidget; | |||
|
7 | ||||
|
8 | class MainWidget : public QWidget | |||
|
9 | { | |||
|
10 | Q_OBJECT | |||
|
11 | public: | |||
|
12 | explicit MainWidget(QWidget *parent = 0); | |||
|
13 | ||||
|
14 | signals: | |||
|
15 | ||||
|
16 | private slots: | |||
|
17 | void chartTypeChanged(int itemIndex); | |||
|
18 | void dataChanged(QString itemText); | |||
|
19 | void backgroundChanged(int itemIndex); | |||
|
20 | void xMinChanged(int value); | |||
|
21 | void xMaxChanged(int value); | |||
|
22 | void yMinChanged(int value); | |||
|
23 | void yMaxChanged(int value); | |||
|
24 | ||||
|
25 | private: | |||
|
26 | ChartWidget *m_chartWidget; | |||
|
27 | }; | |||
|
28 | ||||
|
29 | #endif // MAINWIDGET_H |
@@ -12,5 +12,11 CHARTS += widget | |||||
12 | OBJECTS_DIR = tmp |
|
12 | OBJECTS_DIR = tmp | |
13 | MOC_DIR = tmp |
|
13 | MOC_DIR = tmp | |
14 |
|
14 | |||
15 | SOURCES += main.cpp |
|
15 | SOURCES += main.cpp \ | |
|
16 | mainwidget.cpp | |||
|
17 | ||||
|
18 | HEADERS += \ | |||
|
19 | mainwidget.h | |||
|
20 | ||||
|
21 | ||||
16 |
|
22 |
@@ -4,15 +4,13 | |||||
4 | #else |
|
4 | #else | |
5 | #include <QtWidgets/QApplication> |
|
5 | #include <QtWidgets/QApplication> | |
6 | #endif |
|
6 | #endif | |
7 |
#include |
|
7 | #include "mainwidget.h" | |
8 |
|
8 | |||
9 | int main(int argc, char *argv[]) |
|
9 | int main(int argc, char *argv[]) | |
10 | { |
|
10 | { | |
11 | QApplication a(argc, argv); |
|
11 | QApplication a(argc, argv); | |
12 |
|
12 | |||
13 |
|
|
13 | MainWidget w; | |
14 | w.resize(QSize(200,200)); |
|
|||
15 | w.setColor(Qt::red); |
|
|||
16 | w.show(); |
|
14 | w.show(); | |
17 |
|
15 | |||
18 | return a.exec(); |
|
16 | return a.exec(); |
General Comments 0
You need to be logged in to leave comments.
Login now