@@ -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,14 +1,21 | |||||
1 | #include "barchartseries.h" |
|
1 | #include "barchartseries.h" | |
2 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
2 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
3 |
|
3 | |||
4 |
BarChartSeries::BarChartSeries( |
|
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); | |
@@ -23,6 +30,8 int BarChartSeries::min() | |||||
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++) { |
@@ -10,14 +10,19 QTCOMMERCIALCHART_BEGIN_NAMESPACE | |||||
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( |
|
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(); |
@@ -8,7 +8,8 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, | |
@@ -26,7 +27,8 public: | |||||
26 | virtual ~QChartSeries(){}; |
|
27 | virtual ~QChartSeries(){}; | |
27 |
|
28 | |||
28 | // Factory method |
|
29 | // Factory method | |
29 |
static QChartSeries* create(QObject* parent = 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 |
@@ -25,7 +25,8 SOURCES += \ | |||||
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 \ |
@@ -10,6 +10,8 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: |
@@ -3,6 +3,7 | |||||
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> | |
@@ -165,6 +166,22 void MainWidget::addSeries(QString series, QString data) | |||||
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 |
General Comments 0
You need to be logged in to leave comments.
Login now