##// END OF EJS Templates
Test app now adds n data series of different type
Tero Ahola -
r20:1184ba596217
parent child
Show More
@@ -1,24 +1,54
1 #include "dataseriedialog.h"
1 #include "dataseriedialog.h"
2 #include <QDialogButtonBox>
2 #include <QDialogButtonBox>
3 #include <QAbstractButton>
3 #include <QGridLayout>
4 #include <QComboBox>
5 #include <QPushButton>
6 #include <QLabel>
4 #include <QDebug>
7 #include <QDebug>
5
8
6 DataSerieDialog::DataSerieDialog(QWidget *parent) :
9 DataSerieDialog::DataSerieDialog(QWidget *parent) :
7 QDialog(parent)
10 QDialog(parent)
8 {
11 {
9 QDialogButtonBox *addSeriesBox = new QDialogButtonBox(Qt::Vertical, this);
12 // Combo box for selecting the series type
10 addSeriesBox->addButton("Line", QDialogButtonBox::AcceptRole);
13 m_seriesTypeCombo = new QComboBox(this);
11 addSeriesBox->addButton("Area", QDialogButtonBox::AcceptRole);
14 m_seriesTypeCombo->addItem("Line");
12 addSeriesBox->addButton("Bar", QDialogButtonBox::AcceptRole);
15 m_seriesTypeCombo->addItem("Area");
13 addSeriesBox->addButton("Pie", QDialogButtonBox::AcceptRole);
16 m_seriesTypeCombo->addItem("Bar");
14 addSeriesBox->addButton("Scatter", QDialogButtonBox::AcceptRole);
17 m_seriesTypeCombo->addItem("Pie");
15 addSeriesBox->addButton("Spline", QDialogButtonBox::AcceptRole);
18 m_seriesTypeCombo->addItem("Scatter");
16 connect(addSeriesBox, SIGNAL(clicked(QAbstractButton *)), this, SLOT(addSeries(QAbstractButton *)));
19 m_seriesTypeCombo->addItem("Spline");
17 this->setFixedSize(addSeriesBox->sizeHint());
20
21 // Combo box for selecting data for the new series
22 m_testDataCombo = new QComboBox(this);
23 m_testDataCombo->addItem("linear");
24 m_testDataCombo->addItem("SIN");
25 m_testDataCombo->addItem("SIN + random");
26 m_testDataCombo->addItem("TODO From file...");
27 m_testDataCombo->addItem("TODO From URL...");
28
29 QDialogButtonBox *addSeriesBox = new QDialogButtonBox(Qt::Horizontal);
30 QPushButton *b = addSeriesBox->addButton(QDialogButtonBox::Ok);
31 connect(b, SIGNAL(clicked()), this, SLOT(accept()));
32 b = addSeriesBox->addButton(QDialogButtonBox::Cancel);
33 connect(b, SIGNAL(clicked()), this, SLOT(reject()));
34
35 QGridLayout *grid = new QGridLayout();
36 grid->addWidget(new QLabel("Series type:"), 0, 0);
37 grid->addWidget(m_seriesTypeCombo, 0, 1);
38 grid->addWidget(new QLabel("Data:"), 1, 0);
39 grid->addWidget(m_testDataCombo, 1, 1);
40 grid->addWidget(addSeriesBox, 2, 1);
41
42 setLayout(grid);
18 }
43 }
19
44
20 void DataSerieDialog::addSeries(QAbstractButton *button)
45 void DataSerieDialog::accept()
21 {
46 {
22 addSeries(button->text().toAscii());
47 accepted(m_seriesTypeCombo->currentText(), m_testDataCombo->currentText());
23 accept();
48 QDialog::accept();
24 }
49 }
50 //void DataSerieDialog::addSeries(QAbstractButton *button)
51 //{
52 // addSeries(button->text().toAscii());
53 // accept();
54 //}
@@ -3,7 +3,7
3
3
4 #include <QDialog>
4 #include <QDialog>
5
5
6 class QAbstractButton;
6 class QComboBox;
7
7
8 class DataSerieDialog : public QDialog
8 class DataSerieDialog : public QDialog
9 {
9 {
@@ -12,10 +12,14 public:
12 explicit DataSerieDialog(QWidget *parent = 0);
12 explicit DataSerieDialog(QWidget *parent = 0);
13
13
14 signals:
14 signals:
15 void addSeries(QString series);
15 void accepted(QString series, QString data);
16
16
17 public slots:
17 public slots:
18 void addSeries(QAbstractButton *button);
18 void accept();
19
20 private:
21 QComboBox *m_seriesTypeCombo;
22 QComboBox *m_testDataCombo;
19 };
23 };
20
24
21 #endif // DATASERIEDIALOG_H
25 #endif // DATASERIEDIALOG_H
@@ -21,32 +21,10 MainWidget::MainWidget(QWidget *parent) :
21 m_chartWidget = new QChartWidget(this);
21 m_chartWidget = new QChartWidget(this);
22 // m_chartWidget->resize(QSize(200,200));
22 // m_chartWidget->resize(QSize(200,200));
23 // m_chartWidget->setColor(Qt::red);
23 // m_chartWidget->setColor(Qt::red);
24 // Chart type
25 // TODO: How about multiple types?
26 // Should the type be a property of a graph instead of the chart?
27 // QComboBox *chartTypeCombo = new QComboBox(this);
28 // chartTypeCombo->addItem("Line");
29 // chartTypeCombo->addItem("Area");
30 // chartTypeCombo->addItem("Bar");
31 // chartTypeCombo->addItem("Pie");
32 // chartTypeCombo->addItem("Scatter");
33 // chartTypeCombo->addItem("Spline");
34 // connect(chartTypeCombo, SIGNAL(currentIndexChanged(int)),
35 // this, SLOT(chartTypeChanged(int)));
36
24
37 QPushButton *addSeriesButton = new QPushButton("Add series");
25 QPushButton *addSeriesButton = new QPushButton("Add series");
38 connect(addSeriesButton, SIGNAL(clicked()), this, SLOT(addSeries()));
26 connect(addSeriesButton, SIGNAL(clicked()), this, SLOT(addSeries()));
39
27
40 // Test data selector
41 QComboBox *testDataCombo = new QComboBox(this);
42 testDataCombo->addItem("linear");
43 testDataCombo->addItem("SIN");
44 testDataCombo->addItem("SIN + random component");
45 testDataCombo->addItem("TODO From file...");
46 testDataCombo->addItem("TODO From URL...");
47 connect(testDataCombo, SIGNAL(currentIndexChanged(int)),
48 this, SLOT(testDataChanged(int)));
49
50 // Chart background
28 // Chart background
51 QComboBox *backgroundCombo = new QComboBox(this);
29 QComboBox *backgroundCombo = new QComboBox(this);
52 backgroundCombo->addItem("None");
30 backgroundCombo->addItem("None");
@@ -85,10 +63,6 MainWidget::MainWidget(QWidget *parent) :
85 QHBoxLayout *hbox = new QHBoxLayout();
63 QHBoxLayout *hbox = new QHBoxLayout();
86 //grid->addWidget(new QLabel("Add series:"), 0, 0);
64 //grid->addWidget(new QLabel("Add series:"), 0, 0);
87 grid->addWidget(addSeriesButton, 0, 1);
65 grid->addWidget(addSeriesButton, 0, 1);
88 // grid->addWidget(new QLabel("Chart type:"), 0, 0);
89 // grid->addWidget(chartTypeCombo, 0, 1);
90 grid->addWidget(new QLabel("Data:"), 1, 0);
91 grid->addWidget(testDataCombo, 1, 1);
92 grid->addWidget(new QLabel("Background:"), 2, 0);
66 grid->addWidget(new QLabel("Background:"), 2, 0);
93 grid->addWidget(backgroundCombo, 2, 1);
67 grid->addWidget(backgroundCombo, 2, 1);
94 grid->addWidget(m_autoScaleCheck, 3, 0);
68 grid->addWidget(m_autoScaleCheck, 3, 0);
@@ -118,24 +92,43 MainWidget::MainWidget(QWidget *parent) :
118 void MainWidget::addSeries()
92 void MainWidget::addSeries()
119 {
93 {
120 DataSerieDialog dialog(this);
94 DataSerieDialog dialog(this);
121 connect(&dialog, SIGNAL(addSeries(QString)), this, SLOT(addSeries(QString)));
95 connect(&dialog, SIGNAL(accepted(QString, QString)), this, SLOT(addSeries(QString, QString)));
122 dialog.exec();
96 dialog.exec();
123 }
97 }
124
98
125 void MainWidget::addSeries(QString series)
99 void MainWidget::addSeries(QString series, QString data)
126 {
100 {
127 if (series == "Scatter") {
101 qDebug() << "addSeries: " << series << " data: " << data;
128 QXYSeries* series0 = new QXYSeries();
102
103 QXYSeries* series0 = new QXYSeries();
104
105 if (data == "linear") {
106 // TODO
107 } else if (data == "SIN") {
129 series0->setColor(Qt::blue);
108 series0->setColor(Qt::blue);
130 for (int x = 0; x < 100; x++)
109 for (int x = 0; x < 100; x++)
131 series0->add(x, abs(sin(3.14159265358979 / 50 * x) * 100));
110 series0->add(x, abs(sin(3.14159265358979 / 50 * x) * 100));
132 QList<QXYSeries*> dataset;
111 QList<QXYSeries*> dataset;
133 dataset << series0;
112 dataset << series0;
113 } else if (data == "SIN + random") {
114 series0->setColor(Qt::blue);
115 for (qreal x = 0; x < 100; x += 0.1) {
116 series0->add(x + (rand() % 5),
117 abs(sin(3.14159265358979 / 50 * x) * 100) + (rand() % 5));
118 }
119 } else {
120 // TODO: check if data has a valid file name
121 }
122
123 QList<QXYSeries*> dataset;
124 dataset << series0;
125
126 if (series == "Scatter") {
134 m_chartWidget->addDataSeries(QChart::DataSeriesTypeScatter, dataset);
127 m_chartWidget->addDataSeries(QChart::DataSeriesTypeScatter, dataset);
135 //m_chartWidget->addDataSeries(dataset);
128 } else if (series == "Line") {
129 m_chartWidget->addDataSeries(QChart::DataSeriesTypeLine, dataset);
136 } else {
130 } else {
137 // TODO
131 // TODO
138 qDebug() << "addSeries: " << series;
139 }
132 }
140 }
133 }
141
134
@@ -21,7 +21,7 signals:
21 private slots:
21 private slots:
22 void chartTypeChanged(int itemIndex);
22 void chartTypeChanged(int itemIndex);
23 void addSeries();
23 void addSeries();
24 void addSeries(QString series);
24 void addSeries(QString series, QString data);
25 void testDataChanged(int itemIndex);
25 void testDataChanged(int itemIndex);
26 void backgroundChanged(int itemIndex);
26 void backgroundChanged(int itemIndex);
27 void autoScaleChanged(int value);
27 void autoScaleChanged(int value);
General Comments 0
You need to be logged in to leave comments. Login now