##// END OF EJS Templates
Started to refactor the API to allow integrating different plot types
Tero Ahola -
r19:b231f8e5fa43
parent child
Show More
@@ -0,0 +1,53
1 #include "qchartwidget.h"
2 #include "qxyseries.h"
3 #include "xylinechart_p.h"
4 #include <QGraphicsView>
5 #include <QGraphicsScene>
6
7 QCHART_BEGIN_NAMESPACE
8
9 class QChartWidgetPrivate
10 {
11 public:
12 QChartWidgetPrivate(QWidget *parent) : m_view(0), m_scene(0), m_chart(0) {
13 m_scene = new QGraphicsScene();
14 m_view = new QGraphicsView(m_scene, parent);
15 m_view->resize(490, 300);
16 m_view->show();
17 }
18 ~QChartWidgetPrivate() {
19 delete m_view;
20 delete m_scene;
21 }
22
23 QGraphicsView *m_view;
24 QGraphicsScene *m_scene;
25 QChart* m_chart;
26 };
27
28 QChartWidget::QChartWidget(QWidget *parent) :
29 QWidget(parent),
30 d(new QChartWidgetPrivate(this))
31 {
32 setMinimumSize(d->m_view->size());
33 }
34
35 QChartWidget::~QChartWidget()
36 {
37 delete d;
38 }
39
40 void QChartWidget::addDataSeries(
41 QChart::DataSeriesType dataSeriesType,
42 QList<QXYSeries*> dataset)
43 {
44 // TODO: implement management of several data series of different types
45
46 d->m_chart = QChart::createXYLineChart(dataset);
47 d->m_scene->addItem(d->m_chart);
48 d->m_chart->setSize(this->size());
49 }
50
51 #include "moc_qchartwidget.cpp"
52
53 QCHART_END_NAMESPACE
@@ -0,0 +1,36
1 #ifndef QCHARTWIDGET_H
2 #define QCHARTWIDGET_H
3
4 #include "qchartconfig.h"
5 #include "qchart.h"
6 #include <QWidget>
7
8 QCHART_BEGIN_NAMESPACE
9
10 class QXYSeries;
11 class QChartWidgetPrivate;
12
13 class QCHART_EXPORT QChartWidget : public QWidget
14 {
15 Q_OBJECT
16 public:
17 explicit QChartWidget(QWidget *parent = 0);
18 ~QChartWidget();
19 // TODO: replace QXYSeries list with a charts data API
20 // TODO: return QChartDataSeries
21 void addDataSeries(QChart::DataSeriesType dataSeriesType, QList<QXYSeries*> dataset);
22
23 signals:
24
25 public slots:
26
27 private:
28 friend class QChartWidgetPrivate;
29 Q_DISABLE_COPY(QChartWidget)
30 // Q_DECLARE_PRIVATE(QChartWidget)
31 QChartWidgetPrivate * const d;
32 };
33
34 QCHART_END_NAMESPACE
35
36 #endif // QCHARTWIDGET_H
@@ -0,0 +1,24
1 #include "dataseriedialog.h"
2 #include <QDialogButtonBox>
3 #include <QAbstractButton>
4 #include <QDebug>
5
6 DataSerieDialog::DataSerieDialog(QWidget *parent) :
7 QDialog(parent)
8 {
9 QDialogButtonBox *addSeriesBox = new QDialogButtonBox(Qt::Vertical, this);
10 addSeriesBox->addButton("Line", QDialogButtonBox::AcceptRole);
11 addSeriesBox->addButton("Area", QDialogButtonBox::AcceptRole);
12 addSeriesBox->addButton("Bar", QDialogButtonBox::AcceptRole);
13 addSeriesBox->addButton("Pie", QDialogButtonBox::AcceptRole);
14 addSeriesBox->addButton("Scatter", QDialogButtonBox::AcceptRole);
15 addSeriesBox->addButton("Spline", QDialogButtonBox::AcceptRole);
16 connect(addSeriesBox, SIGNAL(clicked(QAbstractButton *)), this, SLOT(addSeries(QAbstractButton *)));
17 this->setFixedSize(addSeriesBox->sizeHint());
18 }
19
20 void DataSerieDialog::addSeries(QAbstractButton *button)
21 {
22 addSeries(button->text().toAscii());
23 accept();
24 }
@@ -0,0 +1,21
1 #ifndef DATASERIEDIALOG_H
2 #define DATASERIEDIALOG_H
3
4 #include <QDialog>
5
6 class QAbstractButton;
7
8 class DataSerieDialog : public QDialog
9 {
10 Q_OBJECT
11 public:
12 explicit DataSerieDialog(QWidget *parent = 0);
13
14 signals:
15 void addSeries(QString series);
16
17 public slots:
18 void addSeries(QAbstractButton *button);
19 };
20
21 #endif // DATASERIEDIALOG_H
1 NO CONTENT: file renamed from src/xylinechart/axis.cpp to src/axis.cpp
1 NO CONTENT: file renamed from src/xylinechart/axis_p.h to src/axis_p.h
@@ -1,30 +1,29
1 1 #include "qchart.h"
2 2 #include "xylinechart_p.h"
3 3
4 4 QCHART_BEGIN_NAMESPACE
5 5
6 6 QChart::QChart(QGraphicsItem* parent):QGraphicsItem(parent),
7 7 m_marginSize(0)
8 8 {
9 9 // setFlags(QGraphicsItem::ItemClipsChildrenToShape);
10 10 }
11 11
12 12 QChart::~QChart(){}
13 13
14 14
15 15 QChart* QChart::createXYLineChart(const QList<QXYSeries*>& dataset)
16 16 {
17
18 17 XYLineChart* chart = new XYLineChart();
19 18 foreach (const QXYSeries* series,dataset) {
20 chart->addXYSeries(series);
19 chart->addXYSeries(series);
21 20 }
22 21 return chart;
23 22 }
24 23
25 24 void QChart::setMargin(int margin)
26 25 {
27 m_marginSize=margin;
26 m_marginSize = margin;
28 27 }
29 28
30 29 QCHART_END_NAMESPACE
@@ -1,31 +1,40
1 1 #ifndef CHART_H
2 2 #define CHART_H
3 3
4 4 #include <qchartconfig.h>
5 5 #include <qxyseries.h>
6 6 #include <QGraphicsItem>
7 7
8 8 QCHART_BEGIN_NAMESPACE
9 9
10 10 class QCHART_EXPORT QChart : public QGraphicsItem
11 11 {
12 public:
13 enum DataSeriesType {
14 DataSeriesTypeLine = 0,
15 DataSeriesTypeArea,
16 DataSeriesTypeBar,
17 DataSeriesTypePie,
18 DataSeriesTypeScatter,
19 DataSeriesTypeSpline
20 };
12 21
13 22 protected:
14 23 QChart(QGraphicsItem* parent =0);
15 24
16 25 public:
17 26 virtual ~QChart();
18 27
19 28 static QChart* createXYLineChart(const QList<QXYSeries*>& dataset);
20 29
21 30 virtual void setSize(const QSizeF& rect)=0;
22 31 void setMargin(int margin);
23 32 int margin() const { return m_marginSize;}
24 33
25 34 private:
26 35 int m_marginSize;
27 36 };
28 37
29 38 QCHART_END_NAMESPACE
30 39
31 40 #endif
@@ -1,44 +1,45
1 1 TARGET = QChart
2 2 TEMPLATE = lib
3 3 QT += core \
4 4 gui
5 5 CONFIG += debug_and_release
6 6 CONFIG(debug, debug|release):TARGET = QChartd
7
7 8 SOURCES += \
8 xylinechart/qchartwidget.cpp \
9 xylinechart/qchart.cpp \
9 xylinechart/qchartgraphicswidget.cpp \
10 10 xylinechart/qxyseries.cpp \
11 xylinechart/axis.cpp \
12 11 xylinechart/xylinechart.cpp \
13 12 xylinechart/xygrid.cpp \
14 xylinechart/xyplotdata.cpp
13 xylinechart/xyplotdata.cpp \
14 qchart.cpp \
15 axis.cpp \
16 qchartwidget.cpp
15 17
16 18 PRIVATE_HEADERS += \
17 19 xylinechart/xylinechart_p.h \
18 xylinechart/axis_p.h \
19 20 xylinechart/xygrid_p.h \
20 xylinechart/xyplotdata_p.h
21
21 xylinechart/xyplotdata_p.h \
22 axis_p.h
22 23 PUBLIC_HEADERS += \
23 xylinechart/qchart.h \
24 24 xylinechart/qxyseries.h \
25 xylinechart/qchartwidget.h \
26 qchartconfig.h
27
25 xylinechart/qchartgraphicswidget.h \
26 qchart.h \
27 qchartwidget.h \
28 qchartconfig.h
28 29 HEADERS += $$PUBLIC_HEADERS
29 30 HEADERS += $$PRIVATE_HEADERS
30 31
31 32 INCLUDEPATH += xylinechart \
32 33 .
33 34
34 35 OBJECTS_DIR = ../build/lib
35 36 MOC_DIR = ../build/lib
36 37 UI_DIR = ../build/lib
37 38 RCC_DIR = ../build/lib
38 39 DEFINES += QCHART_LIBRARY
39 40
40 41 public_headers.path = $$[QT_INSTALL_HEADERS]/QCharts
41 42 public_headers.files = $$PUBLIC_HEADERS
42 43 target.path = $$[QT_INSTALL_LIBS]
43 44 INSTALLS += target \
44 45 public_headers
@@ -1,41 +1,41
1 #include "qchartwidget.h"
1 #include "qchartgraphicswidget.h"
2 2 #include "qchart.h"
3 3
4 4 QCHART_BEGIN_NAMESPACE
5 5
6 6
7 class QChartWidgetPrivate
7 class QChartGraphicsWidgetPrivate
8 8 {
9 9 public:
10 10 QChart* chart;
11 11 //Q_DECLARE_PUBLIC(ChartWidget)
12 QChartWidgetPrivate() {}
12 QChartGraphicsWidgetPrivate() {}
13 13 };
14 14
15 15 ////////////////////////////////////////////////////////////////////////////
16 16
17 QChartWidget::QChartWidget(QGraphicsItem *parent,Qt::WindowFlags wFlags)
17 QChartGraphicsWidget::QChartGraphicsWidget(QGraphicsItem *parent,Qt::WindowFlags wFlags)
18 18 : QGraphicsWidget(parent,wFlags),
19 d_ptr(new QChartWidgetPrivate())
19 d_ptr(new QChartGraphicsWidgetPrivate())
20 20 {
21 21 }
22 22
23 QChartWidget::~QChartWidget()
23 QChartGraphicsWidget::~QChartGraphicsWidget()
24 24 {
25 25 delete d_ptr;
26 26 }
27 27
28 28
29 void QChartWidget::addChart(QChart *chart)
29 void QChartGraphicsWidget::addChart(QChart *chart)
30 30 {
31 31 d_ptr->chart=chart;
32 32 chart->setParentItem(this);
33 33 }
34 34
35 void QChartWidget::setGeometry(const QRectF & rect)
35 void QChartGraphicsWidget::setGeometry(const QRectF & rect)
36 36 {
37 37 d_ptr->chart->setSize(rect.size());
38 38 QGraphicsWidget::setGeometry(rect);
39 39 }
40 40
41 41 QCHART_END_NAMESPACE
@@ -1,34 +1,34
1 #ifndef QCHARTWIDGET_H
2 #define QCHARTWIDGET_H
1 #ifndef QCHARTGRAPHICSWIDGET_H
2 #define QCHARTGRAPHICSWIDGET_H
3 3
4 4 #include <qchartconfig.h>
5 5 #include <QGraphicsWidget>
6 6
7 7 class QGraphicsItem;
8 8
9 9 QCHART_BEGIN_NAMESPACE
10 10
11 11 class QChart;
12 class QChartWidgetPrivate;
12 class QChartGraphicsWidgetPrivate;
13 13
14 class QCHART_EXPORT QChartWidget : public QGraphicsWidget
14 class QCHART_EXPORT QChartGraphicsWidget : public QGraphicsWidget
15 15 {
16 16
17 17 public:
18 explicit QChartWidget(QGraphicsItem *parent = 0,Qt::WindowFlags wFlags = 0);
19 ~QChartWidget();
18 explicit QChartGraphicsWidget(QGraphicsItem *parent = 0,Qt::WindowFlags wFlags = 0);
19 ~QChartGraphicsWidget();
20 20
21 21 QChart* chart() const;
22 22 void addChart(QChart* chart);
23 23
24 24 virtual void setGeometry(const QRectF & rect);
25 25
26 26 private:
27 Q_DISABLE_COPY(QChartWidget)
28 Q_DECLARE_PRIVATE(QChartWidget)
29 QChartWidgetPrivate * const d_ptr;
27 Q_DISABLE_COPY(QChartGraphicsWidget)
28 Q_DECLARE_PRIVATE(QChartGraphicsWidget)
29 QChartGraphicsWidgetPrivate * const d_ptr;
30 30 };
31 31
32 32 QCHART_END_NAMESPACE
33 33
34 34 #endif
@@ -1,59 +1,63
1 1 #include "qxyseries.h"
2 2
3 QCHART_BEGIN_NAMESPACE
4
3 5 QXYSeries::QXYSeries():
4 m_color(Qt::black)
6 m_color(Qt::black)
5 7 {
6 8 }
7 9
8 10 QXYSeries::~QXYSeries()
9 11 {
10 12 }
11 13
12 14
13 15 void QXYSeries::setColor(const QColor& color)
14 16 {
15 17 m_color = color;
16 18 }
17 19
18 20
19 21 void QXYSeries::add(qreal x,qreal y)
20 22 {
21 23 m_x<<x;
22 24 m_y<<y;
23 25 }
24 26
25 27 void QXYSeries::clear()
26 28 {
27 29 m_x.clear();
28 30 m_y.clear();
29 31 }
30 32
31 33 qreal QXYSeries::x(int pos) const
32 34 {
33 35 return m_x.at(pos);
34 36 }
35 37
36 38 qreal QXYSeries::y(int pos) const
37 39 {
38 40 return m_y.at(pos);
39 41 }
40 42
41 43 int QXYSeries::count() const
42 44 {
43 45 Q_ASSERT(m_x.size() == m_y.size());
44 46
45 47 return m_x.size();
46 48
47 49 }
48 50
49 51 QDebug operator<< (QDebug debug, const QXYSeries series)
50 52 {
51 53 Q_ASSERT(series.m_x.size() == series.m_y.size());
52 54
53 55 int size = series.m_x.size();
54 56
55 57 for (int i=0;i<size;i++) {
56 58 debug.nospace() << "(" << series.m_x.at(i) << ','<< series.m_y.at(i) << ") ";
57 59 }
58 60 return debug.space();
59 61 }
62
63 QCHART_END_NAMESPACE
@@ -1,28 +1,33
1 1 #ifndef QXYSERIES_H_
2 2 #define QXYSERIES_H_
3
4 #include "qchartconfig.h"
3 5 #include <QDebug>
4 6 #include <QColor>
5 7
8 QCHART_BEGIN_NAMESPACE
6 9
7 class QXYSeries
10 class QCHART_EXPORT QXYSeries
8 11 {
9 12 public:
10 13 QXYSeries();
11 14 virtual ~QXYSeries();
12 15 void add(qreal x, qreal y);
13 16 void clear();
14 17 void setColor(const QColor& color);
15 18 const QColor& color() const { return m_color;}
16 19 int count() const;
17 20 qreal x(int pos) const;
18 21 qreal y(int pos) const;
19 22 friend QDebug operator<< (QDebug d, const QXYSeries series);
20 23
21 24 private:
22 25 QColor m_color;
23 26 QList<qreal> m_x;
24 27 QList<qreal> m_y;
25 28
26 29 };
27 30
31 QCHART_END_NAMESPACE
32
28 33 #endif
@@ -1,32 +1,33
1 1 TARGET = chartwidgettest
2 2 TEMPLATE = app
3 3
4 4 QT += core gui
5 5 contains(QT_MAJOR_VERSION, 5) {
6 6 QT += widgets
7 7 }
8 8
9 9 CONFIG += charts
10 CHARTS += widget
11 10
12 11 OBJECTS_DIR = tmp
13 12 MOC_DIR = tmp
14 13
15 14 SOURCES += main.cpp \
16 15 mainwidget.cpp \
17 qscatterseries.cpp \
18 qchartwidget.cpp \
19 qseriespointgraphicsitem.cpp
16 # qscatterseries.cpp \
17 # qseriespointgraphicsitem.cpp \
18 dataseriedialog.cpp
20 19
21 20 HEADERS += \
22 21 mainwidget.h \
23 qscatterseries.h \
24 qchartwidget.h \
25 qseriespointgraphicsitem.h
22 # qscatterseries.h \
23 # qseriespointgraphicsitem.h \
24 dataseriedialog.h
25
26
26 27
27 28
28 29
29 30
30 31
31 32
32 33
@@ -1,199 +1,229
1 1 #include "mainwidget.h"
2 #include "qchartwidget.h"
3 //#include <chartwidget.h>
2 #include "dataseriedialog.h"
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 QCHART_USE_NAMESPACE
17
16 18 MainWidget::MainWidget(QWidget *parent) :
17 19 QWidget(parent)
18 20 {
19 21 m_chartWidget = new QChartWidget(this);
20 22 // m_chartWidget->resize(QSize(200,200));
21 23 // m_chartWidget->setColor(Qt::red);
22 24 // Chart type
23 25 // TODO: How about multiple types?
24 26 // Should the type be a property of a graph instead of the chart?
25 QComboBox *chartTypeCombo = new QComboBox(this);
26 chartTypeCombo->addItem("Line");
27 chartTypeCombo->addItem("Area");
28 chartTypeCombo->addItem("Bar");
29 chartTypeCombo->addItem("Pie");
30 chartTypeCombo->addItem("Scatter");
31 chartTypeCombo->addItem("Spline");
32 connect(chartTypeCombo, SIGNAL(currentIndexChanged(int)),
33 this, SLOT(chartTypeChanged(int)));
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
37 QPushButton *addSeriesButton = new QPushButton("Add series");
38 connect(addSeriesButton, SIGNAL(clicked()), this, SLOT(addSeries()));
34 39
35 40 // Test data selector
36 41 QComboBox *testDataCombo = new QComboBox(this);
37 42 testDataCombo->addItem("linear");
38 43 testDataCombo->addItem("SIN");
39 44 testDataCombo->addItem("SIN + random component");
40 45 testDataCombo->addItem("TODO From file...");
41 46 testDataCombo->addItem("TODO From URL...");
42 47 connect(testDataCombo, SIGNAL(currentIndexChanged(int)),
43 48 this, SLOT(testDataChanged(int)));
44 49
45 50 // Chart background
46 51 QComboBox *backgroundCombo = new QComboBox(this);
47 52 backgroundCombo->addItem("None");
48 53 backgroundCombo->addItem("TODO Grid");
49 54 backgroundCombo->addItem("TODO Image");
50 55 connect(backgroundCombo, SIGNAL(currentIndexChanged(int)),
51 56 this, SLOT(backgroundChanged(int)));
52 57
53 58 // Axis
54 59 // TODO: multiple axes?
55 60 m_autoScaleCheck = new QCheckBox("Automatic scaling");
56 61 connect(m_autoScaleCheck, SIGNAL(stateChanged(int)), this, SLOT(autoScaleChanged(int)));
57 62 // Allow setting also non-sense values (like -2147483648 and 2147483647)
58 63 m_xMinSpin = new QSpinBox();
59 64 m_xMinSpin->setMinimum(INT_MIN);
60 65 m_xMinSpin->setMaximum(INT_MAX);
61 66 m_xMinSpin->setValue(0);
62 67 connect(m_xMinSpin, SIGNAL(valueChanged(int)), this, SLOT(xMinChanged(int)));
63 68 m_xMaxSpin = new QSpinBox();
64 69 m_xMaxSpin->setMinimum(INT_MIN);
65 70 m_xMaxSpin->setMaximum(INT_MAX);
66 71 m_xMaxSpin->setValue(10);
67 72 connect(m_xMaxSpin, SIGNAL(valueChanged(int)), this, SLOT(xMaxChanged(int)));
68 73 m_yMinSpin = new QSpinBox();
69 74 m_yMinSpin->setMinimum(INT_MIN);
70 75 m_yMinSpin->setMaximum(INT_MAX);
71 76 m_yMinSpin->setValue(0);
72 77 connect(m_yMinSpin, SIGNAL(valueChanged(int)), this, SLOT(yMinChanged(int)));
73 78 m_yMaxSpin = new QSpinBox();
74 79 m_yMaxSpin->setMinimum(INT_MIN);
75 80 m_yMaxSpin->setMaximum(INT_MAX);
76 81 m_yMaxSpin->setValue(10);
77 82 connect(m_yMaxSpin, SIGNAL(valueChanged(int)), this, SLOT(yMaxChanged(int)));
78 83
79 84 QGridLayout *grid = new QGridLayout();
80 85 QHBoxLayout *hbox = new QHBoxLayout();
81 grid->addWidget(new QLabel("Chart type:"), 0, 0);
82 grid->addWidget(chartTypeCombo, 0, 1);
86 //grid->addWidget(new QLabel("Add series:"), 0, 0);
87 grid->addWidget(addSeriesButton, 0, 1);
88 // grid->addWidget(new QLabel("Chart type:"), 0, 0);
89 // grid->addWidget(chartTypeCombo, 0, 1);
83 90 grid->addWidget(new QLabel("Data:"), 1, 0);
84 91 grid->addWidget(testDataCombo, 1, 1);
85 92 grid->addWidget(new QLabel("Background:"), 2, 0);
86 93 grid->addWidget(backgroundCombo, 2, 1);
87 94 grid->addWidget(m_autoScaleCheck, 3, 0);
88 95 grid->addWidget(new QLabel("x min:"), 4, 0);
89 96 grid->addWidget(m_xMinSpin, 4, 1);
90 97 grid->addWidget(new QLabel("x max:"), 5, 0);
91 98 grid->addWidget(m_xMaxSpin, 5, 1);
92 99 grid->addWidget(new QLabel("y min:"), 6, 0);
93 100 grid->addWidget(m_yMinSpin, 6, 1);
94 101 grid->addWidget(new QLabel("y max:"), 7, 0);
95 102 grid->addWidget(m_yMaxSpin, 7, 1);
96 103 // add row with empty label to make all the other rows static
97 104 grid->addWidget(new QLabel(""), 8, 0);
98 105 grid->setRowStretch(8, 1);
99 106
100 107 hbox->addLayout(grid);
101 108 hbox->addWidget(m_chartWidget);
102 109 hbox->setStretch(1, 1);
103 110
104 111 setLayout(hbox);
105 112
106 113 m_autoScaleCheck->setChecked(true);
107 114 chartTypeChanged(4);
108 115 testDataChanged(0);
109 116 }
110 117
118 void MainWidget::addSeries()
119 {
120 DataSerieDialog dialog(this);
121 connect(&dialog, SIGNAL(addSeries(QString)), this, SLOT(addSeries(QString)));
122 dialog.exec();
123 }
124
125 void MainWidget::addSeries(QString series)
126 {
127 if (series == "Scatter") {
128 QXYSeries* series0 = new QXYSeries();
129 series0->setColor(Qt::blue);
130 for (int x = 0; x < 100; x++)
131 series0->add(x, abs(sin(3.14159265358979 / 50 * x) * 100));
132 QList<QXYSeries*> dataset;
133 dataset << series0;
134 m_chartWidget->addDataSeries(QChart::DataSeriesTypeScatter, dataset);
135 //m_chartWidget->addDataSeries(dataset);
136 } else {
137 // TODO
138 qDebug() << "addSeries: " << series;
139 }
140 }
141
111 142 void MainWidget::chartTypeChanged(int itemIndex)
112 143 {
113 144 // TODO: change chart type
114 145 switch (itemIndex) {
115 146 case 4:
116 m_chartWidget->setType(4);
147 //m_chartWidget->setType(4);
117 148 break;
118 149 default: {
119 m_chartWidget->setType(0);
150 //m_chartWidget->setType(0);
120 151 break;
121 152 }
122 153 }
123 154 }
124 155
125 156 void MainWidget::testDataChanged(int itemIndex)
126 157 {
127 158 qDebug() << "testDataChanged: " << itemIndex;
128 159
129 switch (itemIndex) {
130 case 0: {
131 QList<QChartDataPoint> data;
132 for (int x = 0; x < 20; x++) {
133 data.append(QChartDataPoint() << x << x / 2);
134 }
135 m_chartWidget->setData(data);
136 break;
137 }
138 case 1: {
139 QList<QChartDataPoint> data;
140 for (int x = 0; x < 100; x++) {
141 data.append(QChartDataPoint() << x - 200 << 2 * (uint(sin(3.14159/50*x)*80) % 100));
142 }
143 m_chartWidget->setData(data);
144 break;
145 }
146 case 2: {
147 QList<QChartDataPoint> data;
148 for (int x = 0; x < 1000; x++) {
149 data.append(QChartDataPoint() << x - 200 << 2 * (uint(sin(3.14159/50*x)*80) % 100) + (rand() % 100 * 0.2));
150 data.append(QChartDataPoint() << x - 200 << 2 * (uint(sin(3.14159/50*x)*80) % 100) + (rand() % 100 * 0.2));
151 data.append(QChartDataPoint() << x - 200 << 2 * (uint(sin(3.14159/50*x)*80) % 100) + (rand() % 100 * 0.2));
152 }
153 m_chartWidget->setData(data);
154 break;
155 }
156 default:
157 break;
158 }
159
160 // switch (itemIndex) {
161 // case 0: {
162 // QList<QChartDataPoint> data;
163 // for (int x = 0; x < 20; x++) {
164 // data.append(QChartDataPoint() << x << x / 2);
165 // }
166 // m_chartWidget->setData(data);
167 // break;
168 // }
169 // case 1: {
170 // QList<QChartDataPoint> data;
171 // for (int x = 0; x < 100; x++) {
172 // data.append(QChartDataPoint() << x - 200 << 2 * (uint(sin(3.14159/50*x)*80) % 100));
173 // }
174 // m_chartWidget->setData(data);
175 // break;
176 // }
177 // case 2: {
178 // QList<QChartDataPoint> data;
179 // for (int x = 0; x < 1000; x++) {
180 // data.append(QChartDataPoint() << x - 200 << 2 * (uint(sin(3.14159/50*x)*80) % 100) + (rand() % 100 * 0.2));
181 // data.append(QChartDataPoint() << x - 200 << 2 * (uint(sin(3.14159/50*x)*80) % 100) + (rand() % 100 * 0.2));
182 // data.append(QChartDataPoint() << x - 200 << 2 * (uint(sin(3.14159/50*x)*80) % 100) + (rand() % 100 * 0.2));
183 // }
184 // m_chartWidget->setData(data);
185 // break;
186 // }
187 // default:
188 // break;
189 // }
160 190 }
161 191
162 192 void MainWidget::backgroundChanged(int itemIndex)
163 193 {
164 194 qDebug() << "backgroundChanged: " << itemIndex;
165 195 }
166 196
167 197 void MainWidget::autoScaleChanged(int value)
168 198 {
169 199 if (value) {
170 200 // TODO: enable auto scaling
171 201 } else {
172 202 // TODO: set scaling manually (and disable auto scaling)
173 203 }
174 204
175 205 m_xMinSpin->setEnabled(!value);
176 206 m_xMaxSpin->setEnabled(!value);
177 207 m_yMinSpin->setEnabled(!value);
178 208 m_yMaxSpin->setEnabled(!value);
179 209 }
180 210
181 211 void MainWidget::xMinChanged(int value)
182 212 {
183 213 qDebug() << "xMinChanged: " << value;
184 214 }
185 215
186 216 void MainWidget::xMaxChanged(int value)
187 217 {
188 218 qDebug() << "xMaxChanged: " << value;
189 219 }
190 220
191 221 void MainWidget::yMinChanged(int value)
192 222 {
193 223 qDebug() << "yMinChanged: " << value;
194 224 }
195 225
196 226 void MainWidget::yMaxChanged(int value)
197 227 {
198 228 qDebug() << "yMaxChanged: " << value;
199 229 }
@@ -1,37 +1,42
1 1 #ifndef MAINWIDGET_H
2 2 #define MAINWIDGET_H
3 3
4 #include <qchartconfig.h>
5 #include <qchartwidget.h>
4 6 #include <QWidget>
5 7
6 class QChartWidget;
7 8 class QSpinBox;
8 9 class QCheckBox;
9 10
11 QCHART_USE_NAMESPACE
12
10 13 class MainWidget : public QWidget
11 14 {
12 15 Q_OBJECT
13 16 public:
14 17 explicit MainWidget(QWidget *parent = 0);
15 18
16 19 signals:
17 20
18 21 private slots:
19 22 void chartTypeChanged(int itemIndex);
23 void addSeries();
24 void addSeries(QString series);
20 25 void testDataChanged(int itemIndex);
21 26 void backgroundChanged(int itemIndex);
22 27 void autoScaleChanged(int value);
23 28 void xMinChanged(int value);
24 29 void xMaxChanged(int value);
25 30 void yMinChanged(int value);
26 31 void yMaxChanged(int value);
27 32
28 33 private:
29 34 QChartWidget *m_chartWidget;
30 35 QCheckBox *m_autoScaleCheck;
31 36 QSpinBox *m_xMinSpin;
32 37 QSpinBox *m_xMaxSpin;
33 38 QSpinBox *m_yMinSpin;
34 39 QSpinBox *m_yMaxSpin;
35 40 };
36 41
37 42 #endif // MAINWIDGET_H
1 NO CONTENT: file was removed
1 NO CONTENT: file was removed
General Comments 0
You need to be logged in to leave comments. Login now