##// END OF EJS Templates
Refactored series creation.
sauimone -
r62:d89198258a93
parent child
Show More
@@ -0,0 +1,32
1 #include "qchartglobal.h"
2 #include "qchartseries.h"
3
4 #include "barchartseries.h"
5 #include "qxychartseries.h"
6
7 QTCOMMERCIALCHART_BEGIN_NAMESPACE
8
9 QChartSeries* QChartSeries::create(QChartSeriesType type, QObject* parent)
10 {
11 // TODO: Other types
12 switch (type) {
13 case QChartSeries::SeriesTypeLine: {
14 QXYChartSeries* s = QXYChartSeries::create(parent); // TODO: do we need create method for derived implementations?
15 return s;
16 }
17 case QChartSeries::SeriesTypePie: {
18 return 0;
19 }
20 case QChartSeries::SeriesTypeScatter: {
21 return 0;
22 }
23 case QChartSeries::SeriesTypeBar: {
24 BarChartSeries* s = new BarChartSeries(parent);
25 return s;
26 }
27 default:
28 return 0;
29 }
30 }
31
32 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,46 +1,55
1 #include "barchartseries.h"
1 #include "barchartseries.h"
2 QTCOMMERCIALCHART_BEGIN_NAMESPACE
2 QTCOMMERCIALCHART_BEGIN_NAMESPACE
3
3
4 BarChartSeries::BarChartSeries(QList<int> data, QObject *parent)
4 BarChartSeries::BarChartSeries(QObject *parent)
5 : QChartSeries(parent)
5 : QChartSeries(parent)
6 , mData(data)
7 {
6 {
8 }
7 }
9
8
9 bool BarChartSeries::setData(QList<int> data)
10 {
11 mData = data;
12 return true;
13 }
14
10 int BarChartSeries::min()
15 int BarChartSeries::min()
11 {
16 {
17 Q_ASSERT(mData.count() > 0);
18
12 // TODO: make min and max members and update them when data changes.
19 // TODO: make min and max members and update them when data changes.
13 // This is slower since they are checked every time, even if data is same since previous call.
20 // This is slower since they are checked every time, even if data is same since previous call.
14 int min = mData.at(0);
21 int min = mData.at(0);
15
22
16 for (int i=0; i <mData.count(); i++) {
23 for (int i=0; i <mData.count(); i++) {
17 if (mData.at(i) < min) {
24 if (mData.at(i) < min) {
18 min = mData.at(i);
25 min = mData.at(i);
19 }
26 }
20 }
27 }
21 return min;
28 return min;
22 }
29 }
23
30
24 int BarChartSeries::max()
31 int BarChartSeries::max()
25 {
32 {
33 Q_ASSERT(mData.count() > 0);
34
26 int max = mData.at(0);
35 int max = mData.at(0);
27
36
28 for (int i=0; i <mData.count(); i++) {
37 for (int i=0; i <mData.count(); i++) {
29 if (mData.at(i) > max) {
38 if (mData.at(i) > max) {
30 max = mData.at(i);
39 max = mData.at(i);
31 }
40 }
32 }
41 }
33 return max;
42 return max;
34 }
43 }
35
44
36 int BarChartSeries::count()
45 int BarChartSeries::count()
37 {
46 {
38 return mData.count();
47 return mData.count();
39 }
48 }
40
49
41 int BarChartSeries::valueAt(int i)
50 int BarChartSeries::valueAt(int i)
42 {
51 {
43 return mData.at(i);
52 return mData.at(i);
44 }
53 }
45
54
46 QTCOMMERCIALCHART_END_NAMESPACE
55 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,34 +1,39
1 #ifndef BARCHARTSERIES_H
1 #ifndef BARCHARTSERIES_H
2 #define BARCHARTSERIES_H
2 #define BARCHARTSERIES_H
3
3
4 #include <QList>
4 #include <QList>
5 #include "qchartseries.h"
5 #include "qchartseries.h"
6 #include "qchartglobal.h"
6 #include "qchartglobal.h"
7
7
8 QTCOMMERCIALCHART_BEGIN_NAMESPACE
8 QTCOMMERCIALCHART_BEGIN_NAMESPACE
9
9
10 // Container for series
10 // Container for series
11 class QTCOMMERCIALCHART_EXPORT BarChartSeries : public QChartSeries
11 class QTCOMMERCIALCHART_EXPORT BarChartSeries : public QChartSeries
12 {
12 {
13
13 // TODO:
14 // Q_OBJECT
14 public:
15 public:
15 BarChartSeries(QList<int> data, QObject* parent=0);
16 BarChartSeries(QObject* parent=0);
16
17
17 // from QChartSeries
18 // from QChartSeries
18 static QChartSeries* create(QObject* parent = 0 );
19 virtual QChartSeriesType type() const { return QChartSeries::SeriesTypeBar; }
19 virtual QChartSeriesType type() const { return QChartSeries::SeriesTypeBar; }
20
20
21 virtual bool setData(QList<int> data);
22 virtual bool setData(QList<qreal> data) {return false;}
23 virtual bool setData(QList<qreal> x, QList<qreal> y) {return false;}
24
25
21 // Methods to find out minimum and maximum values of data
26 // Methods to find out minimum and maximum values of data
22 int min();
27 int min();
23 int max();
28 int max();
24 int count();
29 int count();
25 int valueAt(int i);
30 int valueAt(int i);
26
31
27 private:
32 private:
28
33
29 QList<int> mData;
34 QList<int> mData;
30 };
35 };
31
36
32 QTCOMMERCIALCHART_END_NAMESPACE
37 QTCOMMERCIALCHART_END_NAMESPACE
33
38
34 #endif // BARCHARTSERIES_H
39 #endif // BARCHARTSERIES_H
@@ -1,41 +1,43
1 #ifndef QCHARTSERIES_H
1 #ifndef QCHARTSERIES_H
2 #define QCHARTSERIES_H
2 #define QCHARTSERIES_H
3
3
4 #include "qchartglobal.h"
4 #include "qchartglobal.h"
5 #include <QObject>
5 #include <QObject>
6
6
7 QTCOMMERCIALCHART_BEGIN_NAMESPACE
7 QTCOMMERCIALCHART_BEGIN_NAMESPACE
8
8
9 class QTCOMMERCIALCHART_EXPORT QChartSeries : public QObject
9 class QTCOMMERCIALCHART_EXPORT QChartSeries : public QObject
10 {
10 {
11
11 //TODO:
12 //Q_OBJECT
12 public:
13 public:
13 enum QChartSeriesType {
14 enum QChartSeriesType {
14 SeriesTypeLine = 0,
15 SeriesTypeLine = 0,
15 // SeriesTypeArea,
16 // SeriesTypeArea,
16 SeriesTypeBar,
17 SeriesTypeBar,
17 SeriesTypePie,
18 SeriesTypePie,
18 SeriesTypeScatter
19 SeriesTypeScatter
19 // SeriesTypeSpline
20 // SeriesTypeSpline
20 };
21 };
21
22
22 protected:
23 protected:
23 QChartSeries(QObject *parent = 0):QObject(parent){};
24 QChartSeries(QObject *parent = 0):QObject(parent){};
24
25
25 public:
26 public:
26 virtual ~QChartSeries(){};
27 virtual ~QChartSeries(){};
27
28
28 // Factory method
29 // Factory method
29 static QChartSeries* create(QObject* parent = 0 ){ return 0;}
30 static QChartSeries* create(QChartSeriesType type, QObject* parent = 0 );
31
30 // Pure virtual
32 // Pure virtual
31 virtual QChartSeriesType type() const = 0;
33 virtual QChartSeriesType type() const = 0;
32
34
33 virtual bool setData(QList<int> data) { return false; }
35 virtual bool setData(QList<int> data) { return false; }
34 virtual bool setData(QList<qreal> data) { return false; }
36 virtual bool setData(QList<qreal> data) { return false; }
35 virtual bool setData(QList<qreal> x, QList<qreal> y){ return false; }
37 virtual bool setData(QList<qreal> x, QList<qreal> y){ return false; }
36 };
38 };
37
39
38 QTCOMMERCIALCHART_END_NAMESPACE
40 QTCOMMERCIALCHART_END_NAMESPACE
39
41
40 #endif
42 #endif
41
43
@@ -1,89 +1,90
1 !include( ../common.pri ) {
1 !include( ../common.pri ) {
2 error( Couldn't find the common.pri file! )
2 error( Couldn't find the common.pri file! )
3 }
3 }
4
4
5 TARGET = QtCommercialChart
5 TARGET = QtCommercialChart
6 DESTDIR = $$CHART_BUILD_LIB_DIR
6 DESTDIR = $$CHART_BUILD_LIB_DIR
7 TEMPLATE = lib
7 TEMPLATE = lib
8 QT += core \
8 QT += core \
9 gui
9 gui
10
10
11 CONFIG += debug_and_release
11 CONFIG += debug_and_release
12 CONFIG(debug, debug|release):TARGET = QtCommercialChartd
12 CONFIG(debug, debug|release):TARGET = QtCommercialChartd
13
13
14 SOURCES += \
14 SOURCES += \
15 barchart/barchartseries.cpp \
15 barchart/barchartseries.cpp \
16 barchart/bargroup.cpp \
16 barchart/bargroup.cpp \
17 barchart/bar.cpp \
17 barchart/bar.cpp \
18 xylinechart/qxychartseries.cpp \
18 xylinechart/qxychartseries.cpp \
19 xylinechart/xylinechartitem.cpp \
19 xylinechart/xylinechartitem.cpp \
20 xylinechart/xygrid.cpp \
20 xylinechart/xygrid.cpp \
21 xylinechart/xyplotdomain.cpp \
21 xylinechart/xyplotdomain.cpp \
22 qscatterseries.cpp \
22 qscatterseries.cpp \
23 qpieseries.cpp \
23 qpieseries.cpp \
24 qchart.cpp \
24 qchart.cpp \
25 axis.cpp \
25 axis.cpp \
26 qchartwidget.cpp \
26 qchartwidget.cpp \
27 pieslice.cpp \
27 pieslice.cpp \
28 qchartview.cpp
28 qchartview.cpp \
29 qchartseries.cpp
29
30
30 PRIVATE_HEADERS += \
31 PRIVATE_HEADERS += \
31 xylinechart/xylinechartitem_p.h \
32 xylinechart/xylinechartitem_p.h \
32 xylinechart/xyplotdomain_p.h \
33 xylinechart/xyplotdomain_p.h \
33 xylinechart/xygrid_p.h \
34 xylinechart/xygrid_p.h \
34 qscatterseries_p.h \
35 qscatterseries_p.h \
35 pieslice.h \
36 pieslice.h \
36 axis_p.h
37 axis_p.h
37
38
38 PUBLIC_HEADERS += \
39 PUBLIC_HEADERS += \
39 qchartseries.h \
40 qchartseries.h \
40 qscatterseries.h \
41 qscatterseries.h \
41 qpieseries.h \
42 qpieseries.h \
42 qchart.h \
43 qchart.h \
43 qchartwidget.h \
44 qchartwidget.h \
44 qchartglobal.h \
45 qchartglobal.h \
45 xylinechart/qxychartseries.h \
46 xylinechart/qxychartseries.h \
46 barchart/barchartseries.h \
47 barchart/barchartseries.h \
47 barchart/bargroup.h \
48 barchart/bargroup.h \
48 qchartview.h
49 qchartview.h
49
50
50 HEADERS += $$PUBLIC_HEADERS
51 HEADERS += $$PUBLIC_HEADERS
51 HEADERS += $$PRIVATE_HEADERS
52 HEADERS += $$PRIVATE_HEADERS
52
53
53 INCLUDEPATH += xylinechart \
54 INCLUDEPATH += xylinechart \
54 barchart \
55 barchart \
55 .
56 .
56
57
57 OBJECTS_DIR = $$CHART_BUILD_DIR/lib
58 OBJECTS_DIR = $$CHART_BUILD_DIR/lib
58 MOC_DIR = $$CHART_BUILD_DIR/lib
59 MOC_DIR = $$CHART_BUILD_DIR/lib
59 UI_DIR = $$CHART_BUILD_DIR/lib
60 UI_DIR = $$CHART_BUILD_DIR/lib
60 RCC_DIR = $$CHART_BUILD_DIR/lib
61 RCC_DIR = $$CHART_BUILD_DIR/lib
61
62
62
63
63 DEFINES += QTCOMMERCIALCHART_LIBRARY
64 DEFINES += QTCOMMERCIALCHART_LIBRARY
64
65
65 public_headers.path = $$[QT_INSTALL_HEADERS]/QtCommercialChart
66 public_headers.path = $$[QT_INSTALL_HEADERS]/QtCommercialChart
66 public_headers.files = $$PUBLIC_HEADERS
67 public_headers.files = $$PUBLIC_HEADERS
67 target.path = $$[QT_INSTALL_LIBS]
68 target.path = $$[QT_INSTALL_LIBS]
68 INSTALLS += target \
69 INSTALLS += target \
69 public_headers
70 public_headers
70
71
71
72
72 install_build_headers.name = bild_headers
73 install_build_headers.name = bild_headers
73 install_build_headers.output = $$CHART_BUILD_HEADER_DIR/${QMAKE_FILE_BASE}.h
74 install_build_headers.output = $$CHART_BUILD_HEADER_DIR/${QMAKE_FILE_BASE}.h
74 install_build_headers.input = PUBLIC_HEADERS
75 install_build_headers.input = PUBLIC_HEADERS
75 install_build_headers.commands = $$QMAKE_COPY ${QMAKE_FILE_NAME} $$CHART_BUILD_HEADER_DIR
76 install_build_headers.commands = $$QMAKE_COPY ${QMAKE_FILE_NAME} $$CHART_BUILD_HEADER_DIR
76 install_build_headers.CONFIG += target_predeps no_link
77 install_build_headers.CONFIG += target_predeps no_link
77 QMAKE_EXTRA_COMPILERS += install_build_headers
78 QMAKE_EXTRA_COMPILERS += install_build_headers
78
79
79 chartversion.target = qchartversion_p.h
80 chartversion.target = qchartversion_p.h
80 chartversion.commands = @echo "build_time" > $$chartversion.target;
81 chartversion.commands = @echo "build_time" > $$chartversion.target;
81 chartversion.depends = $$HEADERS $$SOURCES
82 chartversion.depends = $$HEADERS $$SOURCES
82 PRE_TARGETDEPS += qchartversion_p.h
83 PRE_TARGETDEPS += qchartversion_p.h
83 QMAKE_CLEAN+= qchartversion_p.h
84 QMAKE_CLEAN+= qchartversion_p.h
84 QMAKE_EXTRA_TARGETS += chartversion
85 QMAKE_EXTRA_TARGETS += chartversion
85
86
86 unix:QMAKE_DISTCLEAN += -r $$CHART_BUILD_HEADER_DIR $$CHART_BUILD_LIB_DIR
87 unix:QMAKE_DISTCLEAN += -r $$CHART_BUILD_HEADER_DIR $$CHART_BUILD_LIB_DIR
87 win32:QMAKE_DISTCLEAN += /Q $$CHART_BUILD_HEADER_DIR $$CHART_BUILD_LIB_DIR
88 win32:QMAKE_DISTCLEAN += /Q $$CHART_BUILD_HEADER_DIR $$CHART_BUILD_LIB_DIR
88
89
89
90
@@ -1,40 +1,42
1 #ifndef QXYSERIES_H_
1 #ifndef QXYSERIES_H_
2 #define QXYSERIES_H_
2 #define QXYSERIES_H_
3
3
4 #include "qchartglobal.h"
4 #include "qchartglobal.h"
5 #include "qchartseries.h"
5 #include "qchartseries.h"
6 #include <QDebug>
6 #include <QDebug>
7 #include <QColor>
7 #include <QColor>
8
8
9 QTCOMMERCIALCHART_BEGIN_NAMESPACE
9 QTCOMMERCIALCHART_BEGIN_NAMESPACE
10
10
11 class QTCOMMERCIALCHART_EXPORT QXYChartSeries : public QChartSeries
11 class QTCOMMERCIALCHART_EXPORT QXYChartSeries : public QChartSeries
12 {
12 {
13 //TODO:
14 // Q_OBJECT
13 private:
15 private:
14 QXYChartSeries(QObject* parent=0);
16 QXYChartSeries(QObject* parent=0);
15 public:
17 public:
16 virtual ~QXYChartSeries();
18 virtual ~QXYChartSeries();
17
19
18 //implemented from QChartSeries
20 //implemented from QChartSeries
19 static QXYChartSeries* create(QObject* parent=0);
21 static QXYChartSeries* create(QObject* parent=0);
20 virtual QChartSeriesType type() const { return QChartSeries::SeriesTypeLine;}
22 virtual QChartSeriesType type() const { return QChartSeries::SeriesTypeLine;}
21
23
22 void add(qreal x, qreal y);
24 void add(qreal x, qreal y);
23 void clear();
25 void clear();
24 void setColor(const QColor& color);
26 void setColor(const QColor& color);
25 const QColor& color() const { return m_color;}
27 const QColor& color() const { return m_color;}
26 int count() const;
28 int count() const;
27 qreal x(int pos) const;
29 qreal x(int pos) const;
28 qreal y(int pos) const;
30 qreal y(int pos) const;
29 friend QDebug operator<< (QDebug d, const QXYChartSeries series);
31 friend QDebug operator<< (QDebug d, const QXYChartSeries series);
30
32
31 private:
33 private:
32 QColor m_color;
34 QColor m_color;
33 QList<qreal> m_x;
35 QList<qreal> m_x;
34 QList<qreal> m_y;
36 QList<qreal> m_y;
35
37
36 };
38 };
37
39
38 QTCOMMERCIALCHART_END_NAMESPACE
40 QTCOMMERCIALCHART_END_NAMESPACE
39
41
40 #endif
42 #endif
@@ -1,267 +1,284
1 #include "mainwidget.h"
1 #include "mainwidget.h"
2 #include "dataseriedialog.h"
2 #include "dataseriedialog.h"
3 #include "qchartseries.h"
3 #include "qchartseries.h"
4 #include "qpieseries.h"
4 #include "qpieseries.h"
5 #include <qxychartseries.h>
5 #include <qxychartseries.h>
6 #include <barchartseries.h>
6 #include <QPushButton>
7 #include <QPushButton>
7 #include <QComboBox>
8 #include <QComboBox>
8 #include <QSpinBox>
9 #include <QSpinBox>
9 #include <QCheckBox>
10 #include <QCheckBox>
10 #include <QGridLayout>
11 #include <QGridLayout>
11 #include <QHBoxLayout>
12 #include <QHBoxLayout>
12 #include <QLabel>
13 #include <QLabel>
13 #include <QSpacerItem>
14 #include <QSpacerItem>
14 #include <QMessageBox>
15 #include <QMessageBox>
15 #include <cmath>
16 #include <cmath>
16 #include <QDebug>
17 #include <QDebug>
17
18
18 QTCOMMERCIALCHART_USE_NAMESPACE
19 QTCOMMERCIALCHART_USE_NAMESPACE
19
20
20 MainWidget::MainWidget(QWidget *parent) :
21 MainWidget::MainWidget(QWidget *parent) :
21 QWidget(parent)
22 QWidget(parent)
22 {
23 {
23 QPushButton *addSeriesButton = new QPushButton("Add series");
24 QPushButton *addSeriesButton = new QPushButton("Add series");
24 connect(addSeriesButton, SIGNAL(clicked()), this, SLOT(addSeries()));
25 connect(addSeriesButton, SIGNAL(clicked()), this, SLOT(addSeries()));
25
26
26 // Chart background
27 // Chart background
27 QComboBox *backgroundCombo = new QComboBox(this);
28 QComboBox *backgroundCombo = new QComboBox(this);
28 backgroundCombo->addItem("None");
29 backgroundCombo->addItem("None");
29 backgroundCombo->addItem("TODO Grid");
30 backgroundCombo->addItem("TODO Grid");
30 backgroundCombo->addItem("TODO Image");
31 backgroundCombo->addItem("TODO Image");
31 connect(backgroundCombo, SIGNAL(currentIndexChanged(int)),
32 connect(backgroundCombo, SIGNAL(currentIndexChanged(int)),
32 this, SLOT(backgroundChanged(int)));
33 this, SLOT(backgroundChanged(int)));
33
34
34 // Axis
35 // Axis
35 // TODO: multiple axes?
36 // TODO: multiple axes?
36 m_autoScaleCheck = new QCheckBox("Automatic scaling");
37 m_autoScaleCheck = new QCheckBox("Automatic scaling");
37 connect(m_autoScaleCheck, SIGNAL(stateChanged(int)), this, SLOT(autoScaleChanged(int)));
38 connect(m_autoScaleCheck, SIGNAL(stateChanged(int)), this, SLOT(autoScaleChanged(int)));
38 // Allow setting also non-sense values (like -2147483648 and 2147483647)
39 // Allow setting also non-sense values (like -2147483648 and 2147483647)
39 m_xMinSpin = new QSpinBox();
40 m_xMinSpin = new QSpinBox();
40 m_xMinSpin->setMinimum(INT_MIN);
41 m_xMinSpin->setMinimum(INT_MIN);
41 m_xMinSpin->setMaximum(INT_MAX);
42 m_xMinSpin->setMaximum(INT_MAX);
42 m_xMinSpin->setValue(0);
43 m_xMinSpin->setValue(0);
43 connect(m_xMinSpin, SIGNAL(valueChanged(int)), this, SLOT(xMinChanged(int)));
44 connect(m_xMinSpin, SIGNAL(valueChanged(int)), this, SLOT(xMinChanged(int)));
44 m_xMaxSpin = new QSpinBox();
45 m_xMaxSpin = new QSpinBox();
45 m_xMaxSpin->setMinimum(INT_MIN);
46 m_xMaxSpin->setMinimum(INT_MIN);
46 m_xMaxSpin->setMaximum(INT_MAX);
47 m_xMaxSpin->setMaximum(INT_MAX);
47 m_xMaxSpin->setValue(10);
48 m_xMaxSpin->setValue(10);
48 connect(m_xMaxSpin, SIGNAL(valueChanged(int)), this, SLOT(xMaxChanged(int)));
49 connect(m_xMaxSpin, SIGNAL(valueChanged(int)), this, SLOT(xMaxChanged(int)));
49 m_yMinSpin = new QSpinBox();
50 m_yMinSpin = new QSpinBox();
50 m_yMinSpin->setMinimum(INT_MIN);
51 m_yMinSpin->setMinimum(INT_MIN);
51 m_yMinSpin->setMaximum(INT_MAX);
52 m_yMinSpin->setMaximum(INT_MAX);
52 m_yMinSpin->setValue(0);
53 m_yMinSpin->setValue(0);
53 connect(m_yMinSpin, SIGNAL(valueChanged(int)), this, SLOT(yMinChanged(int)));
54 connect(m_yMinSpin, SIGNAL(valueChanged(int)), this, SLOT(yMinChanged(int)));
54 m_yMaxSpin = new QSpinBox();
55 m_yMaxSpin = new QSpinBox();
55 m_yMaxSpin->setMinimum(INT_MIN);
56 m_yMaxSpin->setMinimum(INT_MIN);
56 m_yMaxSpin->setMaximum(INT_MAX);
57 m_yMaxSpin->setMaximum(INT_MAX);
57 m_yMaxSpin->setValue(10);
58 m_yMaxSpin->setValue(10);
58 connect(m_yMaxSpin, SIGNAL(valueChanged(int)), this, SLOT(yMaxChanged(int)));
59 connect(m_yMaxSpin, SIGNAL(valueChanged(int)), this, SLOT(yMaxChanged(int)));
59
60
60 QGridLayout *grid = new QGridLayout();
61 QGridLayout *grid = new QGridLayout();
61 QGridLayout *mainLayout = new QGridLayout();
62 QGridLayout *mainLayout = new QGridLayout();
62 //grid->addWidget(new QLabel("Add series:"), 0, 0);
63 //grid->addWidget(new QLabel("Add series:"), 0, 0);
63 grid->addWidget(addSeriesButton, 0, 1);
64 grid->addWidget(addSeriesButton, 0, 1);
64 grid->addWidget(new QLabel("Background:"), 2, 0);
65 grid->addWidget(new QLabel("Background:"), 2, 0);
65 grid->addWidget(backgroundCombo, 2, 1);
66 grid->addWidget(backgroundCombo, 2, 1);
66 grid->addWidget(m_autoScaleCheck, 3, 0);
67 grid->addWidget(m_autoScaleCheck, 3, 0);
67 grid->addWidget(new QLabel("x min:"), 4, 0);
68 grid->addWidget(new QLabel("x min:"), 4, 0);
68 grid->addWidget(m_xMinSpin, 4, 1);
69 grid->addWidget(m_xMinSpin, 4, 1);
69 grid->addWidget(new QLabel("x max:"), 5, 0);
70 grid->addWidget(new QLabel("x max:"), 5, 0);
70 grid->addWidget(m_xMaxSpin, 5, 1);
71 grid->addWidget(m_xMaxSpin, 5, 1);
71 grid->addWidget(new QLabel("y min:"), 6, 0);
72 grid->addWidget(new QLabel("y min:"), 6, 0);
72 grid->addWidget(m_yMinSpin, 6, 1);
73 grid->addWidget(m_yMinSpin, 6, 1);
73 grid->addWidget(new QLabel("y max:"), 7, 0);
74 grid->addWidget(new QLabel("y max:"), 7, 0);
74 grid->addWidget(m_yMaxSpin, 7, 1);
75 grid->addWidget(m_yMaxSpin, 7, 1);
75 // add row with empty label to make all the other rows static
76 // add row with empty label to make all the other rows static
76 grid->addWidget(new QLabel(""), 8, 0);
77 grid->addWidget(new QLabel(""), 8, 0);
77 grid->setRowStretch(8, 1);
78 grid->setRowStretch(8, 1);
78
79
79 mainLayout->addLayout(grid, 0, 0);
80 mainLayout->addLayout(grid, 0, 0);
80
81
81 // Scatter specific settings
82 // Scatter specific settings
82 m_scatterLayout = new QGridLayout();
83 m_scatterLayout = new QGridLayout();
83 m_scatterLayout->addWidget(new QLabel("scatter"), 0, 0);
84 m_scatterLayout->addWidget(new QLabel("scatter"), 0, 0);
84 m_scatterLayout->setEnabled(false);
85 m_scatterLayout->setEnabled(false);
85
86
86 // Pie specific settings
87 // Pie specific settings
87 m_pieLayout = new QGridLayout();
88 m_pieLayout = new QGridLayout();
88 m_pieLayout->addWidget(new QLabel("Pie size factor"), 0, 0);
89 m_pieLayout->addWidget(new QLabel("Pie size factor"), 0, 0);
89 QDoubleSpinBox *pieSizeSpin = new QDoubleSpinBox();
90 QDoubleSpinBox *pieSizeSpin = new QDoubleSpinBox();
90 pieSizeSpin->setMinimum(LONG_MIN);
91 pieSizeSpin->setMinimum(LONG_MIN);
91 pieSizeSpin->setMaximum(LONG_MAX);
92 pieSizeSpin->setMaximum(LONG_MAX);
92 pieSizeSpin->setValue(1.0);
93 pieSizeSpin->setValue(1.0);
93 pieSizeSpin->setSingleStep(0.1);
94 pieSizeSpin->setSingleStep(0.1);
94 connect(pieSizeSpin, SIGNAL(valueChanged(double)), this, SLOT(setPieSizeFactor(double)));
95 connect(pieSizeSpin, SIGNAL(valueChanged(double)), this, SLOT(setPieSizeFactor(double)));
95 m_pieLayout->setEnabled(false);
96 m_pieLayout->setEnabled(false);
96 m_pieLayout->addWidget(pieSizeSpin, 0, 1);
97 m_pieLayout->addWidget(pieSizeSpin, 0, 1);
97
98
98 mainLayout->addLayout(m_scatterLayout, 1, 0);
99 mainLayout->addLayout(m_scatterLayout, 1, 0);
99 mainLayout->addLayout(m_pieLayout, 2, 0);
100 mainLayout->addLayout(m_pieLayout, 2, 0);
100
101
101 m_chartWidget = new QChartWidget(this);
102 m_chartWidget = new QChartWidget(this);
102 //m_chartWidget->setColor(Qt::red);
103 //m_chartWidget->setColor(Qt::red);
103 mainLayout->addWidget(m_chartWidget, 0, 1, 3, 1);
104 mainLayout->addWidget(m_chartWidget, 0, 1, 3, 1);
104 // hbox->setStretch(1, 1);
105 // hbox->setStretch(1, 1);
105
106
106 setLayout(mainLayout);
107 setLayout(mainLayout);
107
108
108 m_autoScaleCheck->setChecked(true);
109 m_autoScaleCheck->setChecked(true);
109 testDataChanged(0);
110 testDataChanged(0);
110 }
111 }
111
112
112 void MainWidget::addSeries()
113 void MainWidget::addSeries()
113 {
114 {
114 DataSerieDialog dialog(m_defaultSeriesName, this);
115 DataSerieDialog dialog(m_defaultSeriesName, this);
115 connect(&dialog, SIGNAL(accepted(QString, QString)), this, SLOT(addSeries(QString, QString)));
116 connect(&dialog, SIGNAL(accepted(QString, QString)), this, SLOT(addSeries(QString, QString)));
116 dialog.exec();
117 dialog.exec();
117 }
118 }
118
119
119 void MainWidget::addSeries(QString series, QString data)
120 void MainWidget::addSeries(QString series, QString data)
120 {
121 {
121 qDebug() << "addSeries: " << series << " data: " << data;
122 qDebug() << "addSeries: " << series << " data: " << data;
122 m_defaultSeriesName = series;
123 m_defaultSeriesName = series;
123
124
124 // TODO: a dedicated data class for storing x and y values
125 // TODO: a dedicated data class for storing x and y values
125 QList<qreal> x;
126 QList<qreal> x;
126 QList<qreal> y;
127 QList<qreal> y;
127
128
128 if (data == "linear") {
129 if (data == "linear") {
129 for (int i = 0; i < 20; i++) {
130 for (int i = 0; i < 20; i++) {
130 x.append(i);
131 x.append(i);
131 y.append(i);
132 y.append(i);
132 }
133 }
133 } else if (data == "linear, 1M") {
134 } else if (data == "linear, 1M") {
134 for (int i = 0; i < 10000; i++) {
135 for (int i = 0; i < 10000; i++) {
135 x.append(i);
136 x.append(i);
136 y.append(20);
137 y.append(20);
137 }
138 }
138 } else if (data == "SIN") {
139 } else if (data == "SIN") {
139 for (int i = 0; i < 100; i++) {
140 for (int i = 0; i < 100; i++) {
140 x.append(i);
141 x.append(i);
141 y.append(abs(sin(3.14159265358979 / 50 * i) * 100));
142 y.append(abs(sin(3.14159265358979 / 50 * i) * 100));
142 }
143 }
143 } else if (data == "SIN + random") {
144 } else if (data == "SIN + random") {
144 for (qreal i = 0; i < 100; i += 0.1) {
145 for (qreal i = 0; i < 100; i += 0.1) {
145 x.append(i + (rand() % 5));
146 x.append(i + (rand() % 5));
146 y.append(abs(sin(3.14159265358979 / 50 * i) * 100) + (rand() % 5));
147 y.append(abs(sin(3.14159265358979 / 50 * i) * 100) + (rand() % 5));
147 }
148 }
148 } else {
149 } else {
149 // TODO: check if data has a valid file name
150 // TODO: check if data has a valid file name
150 Q_ASSERT(false);
151 Q_ASSERT(false);
151 }
152 }
152
153
153 // TODO: color of the series
154 // TODO: color of the series
154 QChartSeries *newSeries = 0;
155 QChartSeries *newSeries = 0;
155 if (series == "Scatter") {
156 if (series == "Scatter") {
156 newSeries = m_chartWidget->createSeries(QChartSeries::SeriesTypeScatter);
157 newSeries = m_chartWidget->createSeries(QChartSeries::SeriesTypeScatter);
157 Q_ASSERT(newSeries->setData(x, y));
158 Q_ASSERT(newSeries->setData(x, y));
158 } else if (series == "Pie") {
159 } else if (series == "Pie") {
159 newSeries = m_chartWidget->createSeries(QChartSeries::SeriesTypePie);
160 newSeries = m_chartWidget->createSeries(QChartSeries::SeriesTypePie);
160 Q_ASSERT(newSeries->setData(y));
161 Q_ASSERT(newSeries->setData(y));
161 } else if (series == "Line") {
162 } else if (series == "Line") {
162 newSeries = m_chartWidget->createSeries(QChartSeries::SeriesTypePie);
163 newSeries = m_chartWidget->createSeries(QChartSeries::SeriesTypePie);
163 Q_ASSERT(newSeries->setData(x, y));
164 Q_ASSERT(newSeries->setData(x, y));
164 } else {
165 } else {
165 // TODO
166 // TODO
166 }
167 }
167
168
169 // BarChart
170 if (series == "Bar") {
171 qDebug() << "Bar chart series";
172 QChartSeries* barSeries = QChartSeries::create(QChartSeries::SeriesTypeBar, this);
173 QList<int> barData;
174 barData << 1;
175 barData << 12;
176 barData << 5;
177 barData << 8;
178 barData << 17;
179 barData << 9;
180 barSeries->setData(barData);
181 m_chartWidget->addSeries(barSeries);
182
183 }
184
168 setCurrentSeries(newSeries);
185 setCurrentSeries(newSeries);
169 }
186 }
170
187
171 void MainWidget::setCurrentSeries(QChartSeries *series)
188 void MainWidget::setCurrentSeries(QChartSeries *series)
172 {
189 {
173 m_currentSeries = series;
190 m_currentSeries = series;
174 switch (m_currentSeries->type()) {
191 switch (m_currentSeries->type()) {
175 case QChartSeries::SeriesTypeLine:
192 case QChartSeries::SeriesTypeLine:
176 break;
193 break;
177 case QChartSeries::SeriesTypeScatter:
194 case QChartSeries::SeriesTypeScatter:
178 break;
195 break;
179 case QChartSeries::SeriesTypePie:
196 case QChartSeries::SeriesTypePie:
180 break;
197 break;
181 default:
198 default:
182 Q_ASSERT(false);
199 Q_ASSERT(false);
183 break;
200 break;
184 }
201 }
185 }
202 }
186
203
187 void MainWidget::testDataChanged(int itemIndex)
204 void MainWidget::testDataChanged(int itemIndex)
188 {
205 {
189 qDebug() << "testDataChanged: " << itemIndex;
206 qDebug() << "testDataChanged: " << itemIndex;
190
207
191 // switch (itemIndex) {
208 // switch (itemIndex) {
192 // case 0: {
209 // case 0: {
193 // QList<QChartDataPoint> data;
210 // QList<QChartDataPoint> data;
194 // for (int x = 0; x < 20; x++) {
211 // for (int x = 0; x < 20; x++) {
195 // data.append(QChartDataPoint() << x << x / 2);
212 // data.append(QChartDataPoint() << x << x / 2);
196 // }
213 // }
197 // m_chartWidget->setData(data);
214 // m_chartWidget->setData(data);
198 // break;
215 // break;
199 // }
216 // }
200 // case 1: {
217 // case 1: {
201 // QList<QChartDataPoint> data;
218 // QList<QChartDataPoint> data;
202 // for (int x = 0; x < 100; x++) {
219 // for (int x = 0; x < 100; x++) {
203 // data.append(QChartDataPoint() << x - 200 << 2 * (uint(sin(3.14159/50*x)*80) % 100));
220 // data.append(QChartDataPoint() << x - 200 << 2 * (uint(sin(3.14159/50*x)*80) % 100));
204 // }
221 // }
205 // m_chartWidget->setData(data);
222 // m_chartWidget->setData(data);
206 // break;
223 // break;
207 // }
224 // }
208 // case 2: {
225 // case 2: {
209 // QList<QChartDataPoint> data;
226 // QList<QChartDataPoint> data;
210 // for (int x = 0; x < 1000; x++) {
227 // for (int x = 0; x < 1000; x++) {
211 // data.append(QChartDataPoint() << x - 200 << 2 * (uint(sin(3.14159/50*x)*80) % 100) + (rand() % 100 * 0.2));
228 // data.append(QChartDataPoint() << x - 200 << 2 * (uint(sin(3.14159/50*x)*80) % 100) + (rand() % 100 * 0.2));
212 // data.append(QChartDataPoint() << x - 200 << 2 * (uint(sin(3.14159/50*x)*80) % 100) + (rand() % 100 * 0.2));
229 // data.append(QChartDataPoint() << x - 200 << 2 * (uint(sin(3.14159/50*x)*80) % 100) + (rand() % 100 * 0.2));
213 // data.append(QChartDataPoint() << x - 200 << 2 * (uint(sin(3.14159/50*x)*80) % 100) + (rand() % 100 * 0.2));
230 // data.append(QChartDataPoint() << x - 200 << 2 * (uint(sin(3.14159/50*x)*80) % 100) + (rand() % 100 * 0.2));
214 // }
231 // }
215 // m_chartWidget->setData(data);
232 // m_chartWidget->setData(data);
216 // break;
233 // break;
217 // }
234 // }
218 // default:
235 // default:
219 // break;
236 // break;
220 // }
237 // }
221 }
238 }
222
239
223 void MainWidget::backgroundChanged(int itemIndex)
240 void MainWidget::backgroundChanged(int itemIndex)
224 {
241 {
225 qDebug() << "backgroundChanged: " << itemIndex;
242 qDebug() << "backgroundChanged: " << itemIndex;
226 }
243 }
227
244
228 void MainWidget::autoScaleChanged(int value)
245 void MainWidget::autoScaleChanged(int value)
229 {
246 {
230 if (value) {
247 if (value) {
231 // TODO: enable auto scaling
248 // TODO: enable auto scaling
232 } else {
249 } else {
233 // TODO: set scaling manually (and disable auto scaling)
250 // TODO: set scaling manually (and disable auto scaling)
234 }
251 }
235
252
236 m_xMinSpin->setEnabled(!value);
253 m_xMinSpin->setEnabled(!value);
237 m_xMaxSpin->setEnabled(!value);
254 m_xMaxSpin->setEnabled(!value);
238 m_yMinSpin->setEnabled(!value);
255 m_yMinSpin->setEnabled(!value);
239 m_yMaxSpin->setEnabled(!value);
256 m_yMaxSpin->setEnabled(!value);
240 }
257 }
241
258
242 void MainWidget::xMinChanged(int value)
259 void MainWidget::xMinChanged(int value)
243 {
260 {
244 qDebug() << "xMinChanged: " << value;
261 qDebug() << "xMinChanged: " << value;
245 }
262 }
246
263
247 void MainWidget::xMaxChanged(int value)
264 void MainWidget::xMaxChanged(int value)
248 {
265 {
249 qDebug() << "xMaxChanged: " << value;
266 qDebug() << "xMaxChanged: " << value;
250 }
267 }
251
268
252 void MainWidget::yMinChanged(int value)
269 void MainWidget::yMinChanged(int value)
253 {
270 {
254 qDebug() << "yMinChanged: " << value;
271 qDebug() << "yMinChanged: " << value;
255 }
272 }
256
273
257 void MainWidget::yMaxChanged(int value)
274 void MainWidget::yMaxChanged(int value)
258 {
275 {
259 qDebug() << "yMaxChanged: " << value;
276 qDebug() << "yMaxChanged: " << value;
260 }
277 }
261
278
262 void MainWidget::setPieSizeFactor(double size)
279 void MainWidget::setPieSizeFactor(double size)
263 {
280 {
264 QPieSeries *pie = qobject_cast<QPieSeries *>(m_currentSeries);
281 QPieSeries *pie = qobject_cast<QPieSeries *>(m_currentSeries);
265 Q_ASSERT(pie);
282 Q_ASSERT(pie);
266 pie->setSizeFactor(qreal(size));
283 pie->setSizeFactor(qreal(size));
267 }
284 }
General Comments 0
You need to be logged in to leave comments. Login now