##// END OF EJS Templates
Documenting QChartSeries continues
Tero Ahola -
r310:a8ed8052414f
parent child
Show More
@@ -1,94 +1,73
1 #include "declarativeseries.h"
1 #include "declarativeseries.h"
2 #include "declarativechart.h"
2 #include "declarativechart.h"
3 #include <qscatterseries.h>
3 #include <qscatterseries.h>
4 #include <qlinechartseries.h>
4 #include <qlinechartseries.h>
5 #include <qpieseries.h>
5 #include <qpieseries.h>
6 #include <cmath>
6 #include <cmath>
7 #include <QDebug>
7 #include <QDebug>
8
8
9 QTCOMMERCIALCHART_BEGIN_NAMESPACE
9 QTCOMMERCIALCHART_BEGIN_NAMESPACE
10
10
11 DeclarativeSeries::DeclarativeSeries(QDeclarativeItem *parent) :
11 DeclarativeSeries::DeclarativeSeries(QDeclarativeItem *parent) :
12 QDeclarativeItem(parent),
12 QDeclarativeItem(parent),
13 m_seriesType(SeriesTypeInvalid), // TODO: default type?
13 m_seriesType(SeriesTypeInvalid), // TODO: default type?
14 m_chart(0),
14 m_chart(0),
15 m_series(0)
15 m_series(0)
16 {
16 {
17 setFlag(QGraphicsItem::ItemHasNoContents, false);
17 setFlag(QGraphicsItem::ItemHasNoContents, false);
18 connect(this, SIGNAL(parentChanged()),
18 connect(this, SIGNAL(parentChanged()),
19 this, SLOT(setParentForSeries()));
19 this, SLOT(setParentForSeries()));
20 }
20 }
21
21
22 void DeclarativeSeries::setSeriesType(SeriesType type)
22 void DeclarativeSeries::setSeriesType(SeriesType type)
23 {
23 {
24 if (!m_series || type != m_seriesType) {
24 if (!m_series || type != m_seriesType) {
25 m_seriesType = type;
25 m_seriesType = type;
26 initSeries();
26 initSeries();
27 } else {
27 } else {
28 m_seriesType = type;
28 m_seriesType = type;
29 }
29 }
30 }
30 }
31
31
32 void DeclarativeSeries::setParentForSeries()
32 void DeclarativeSeries::setParentForSeries()
33 {
33 {
34 if (!m_series)
34 if (!m_series)
35 initSeries();
35 initSeries();
36 else if (m_series->type() != m_seriesType)
36 else if (m_series->type() != m_seriesType)
37 initSeries();
37 initSeries();
38 }
38 }
39
39
40 void DeclarativeSeries::initSeries()
40 void DeclarativeSeries::initSeries()
41 {
41 {
42 DeclarativeChart *declarativeChart = qobject_cast<DeclarativeChart *>(parent());
42 DeclarativeChart *declarativeChart = qobject_cast<DeclarativeChart *>(parent());
43
43
44 if (declarativeChart && m_seriesType != SeriesTypeInvalid) {
44 if (declarativeChart && m_seriesType != SeriesTypeInvalid) {
45 delete m_series;
45 delete m_series;
46 m_series = 0;
46 m_series = 0;
47
47
48 QChart *chart = qobject_cast<QChart *>(declarativeChart->m_chart);
48 QChart *chart = qobject_cast<QChart *>(declarativeChart->m_chart);
49 qDebug() << "creating series for chart: " << chart;
49 qDebug() << "creating series for chart: " << chart;
50 Q_ASSERT(chart);
50 Q_ASSERT(chart);
51
51
52 switch (m_seriesType) {
52 switch (m_seriesType) {
53 case SeriesTypeLine: {
54 m_series = new QLineChartSeries(this);
55 for (qreal i(0.0); i < 100.0; i += 1.0)
56 ((QLineChartSeries *)m_series)->add(i, i);
57 chart->addSeries(m_series);
58 break;
59 }
60 case SeriesTypeBar:
61 // fallthrough; bar and scatter use the same test data
62 case SeriesTypeScatter: {
63 m_series = new QScatterSeries();
64 chart->addSeries(m_series);
65 QScatterSeries *scatter = qobject_cast<QScatterSeries *>(m_series);
66 Q_ASSERT(scatter);
67 for (qreal i = 0; i < 100; i += 0.1)
68 scatter->addData(QPointF(i + (rand() % 5),
69 abs(sin(3.14159265358979 / 50 * i) * 100) + (rand() % 5)));
70 break;
71 }
72 case SeriesTypeStackedBar:
73 break;
74 case SeriesTypePercentBar:
75 break;
76 case SeriesTypePie: {
53 case SeriesTypePie: {
77 m_series = new QPieSeries();
54 QPieSeries *pieSeries = new QPieSeries();
78 chart->addSeries(m_series);
55 chart->addSeries(pieSeries);
79 QList<qreal> data;
56 QList<qreal> data;
80 data << 1.0;
57 data << 1.0;
81 data << 12.0;
58 data << 12.0;
82 data << 4.0;
59 data << 4.0;
83 Q_ASSERT(m_series->setData(data));
60 Q_ASSERT(pieSeries->setData(data));
61 m_series = pieSeries;
84 break;
62 break;
85 }
63 }
86 default:
64 default:
65 Q_ASSERT(false);
87 break;
66 break;
88 }
67 }
89 }
68 }
90 }
69 }
91
70
92 #include "moc_declarativeseries.cpp"
71 #include "moc_declarativeseries.cpp"
93
72
94 QTCOMMERCIALCHART_END_NAMESPACE
73 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,50 +1,50
1 #ifndef DECLARATIVESERIES_H
1 #ifndef DECLARATIVESERIES_H
2 #define DECLARATIVESERIES_H
2 #define DECLARATIVESERIES_H
3
3
4 #include <QDeclarativeItem>
4 #include <QDeclarativeItem>
5 #include <qchart.h>
5 #include <qchart.h>
6 #include <qchartseries.h>
6 #include <qchartseries.h>
7
7
8 QTCOMMERCIALCHART_BEGIN_NAMESPACE
8 QTCOMMERCIALCHART_BEGIN_NAMESPACE
9
9
10 class DeclarativeSeries : public QDeclarativeItem
10 class DeclarativeSeries : public QDeclarativeItem
11 {
11 {
12 Q_OBJECT
12 Q_OBJECT
13 Q_ENUMS(SeriesType)
13 Q_ENUMS(SeriesType)
14 Q_PROPERTY(SeriesType seriesType READ seriesType WRITE setSeriesType)
14 Q_PROPERTY(SeriesType seriesType READ seriesType WRITE setSeriesType)
15
15
16 public:
16 public:
17 // TODO: how to re-use the existing enum from QChart?
17 // TODO: how to re-use the existing enum from QChart?
18 enum SeriesType {
18 enum SeriesType {
19 SeriesTypeInvalid = QChartSeries::SeriesTypeInvalid,
19 SeriesTypeInvalid = -1,
20 SeriesTypeLine,
20 SeriesTypeLine = QChartSeries::SeriesTypeLine,
21 // SeriesTypeArea,
21 // SeriesTypeArea,
22 SeriesTypeBar,
22 SeriesTypeBar,
23 SeriesTypeStackedBar,
23 SeriesTypeStackedBar,
24 SeriesTypePercentBar,
24 SeriesTypePercentBar,
25 SeriesTypePie,
25 SeriesTypePie,
26 SeriesTypeScatter
26 SeriesTypeScatter
27 // SeriesTypeSpline
27 // SeriesTypeSpline
28 };
28 };
29
29
30 explicit DeclarativeSeries(QDeclarativeItem *parent = 0);
30 explicit DeclarativeSeries(QDeclarativeItem *parent = 0);
31
31
32 signals:
32 signals:
33
33
34 public slots:
34 public slots:
35 void setParentForSeries();
35 void setParentForSeries();
36
36
37 public:
37 public:
38 void setSeriesType(SeriesType type);
38 void setSeriesType(SeriesType type);
39 SeriesType seriesType() { return m_seriesType; }
39 SeriesType seriesType() { return m_seriesType; }
40
40
41 private:
41 private:
42 void initSeries();
42 void initSeries();
43 SeriesType m_seriesType;
43 SeriesType m_seriesType;
44 QChart *m_chart;
44 QChart *m_chart;
45 QChartSeries *m_series;
45 QChartSeries *m_series;
46 };
46 };
47
47
48 QTCOMMERCIALCHART_END_NAMESPACE
48 QTCOMMERCIALCHART_END_NAMESPACE
49
49
50 #endif // DECLARATIVESERIES_H
50 #endif // DECLARATIVESERIES_H
@@ -1,49 +1,52
1 #include "qchartseries.h"
1 #include "qchartseries.h"
2
2
3 /*!
3 /*!
4 \class QChartSeries
4 \class QChartSeries
5 \brief Base class for all QtCommercial Chart series.
5 \brief Base class for all QtCommercial Chart series.
6 \mainclass
6 \mainclass
7
8 Usually you use the series type specific inherited classes instead of the base class.
9 \sa QScatterSeries
7 */
10 */
8
11
9 /*!
12 /*!
10 \enum QChartSeries::QChartSeriesType
13 \enum QChartSeries::QChartSeriesType
11
14
12 The type of the series object.
15 The type of the series object.
13
16
14 \value SeriesTypeLine
17 \value SeriesTypeLine
15 \value SeriesTypeArea
18 \value SeriesTypeArea
16 \value SeriesTypeBar
19 \value SeriesTypeBar
17 \value SeriesTypeStackedBar
20 \value SeriesTypeStackedBar
18 \value SeriesTypePercentBar
21 \value SeriesTypePercentBar
19 \value SeriesTypePie
22 \value SeriesTypePie
20 \value SeriesTypeScatter
23 \value SeriesTypeScatter
21 \value SeriesTypeSpline
24 \value SeriesTypeSpline
22 */
25 */
23
26
24 /*!
27 /*!
25 \fn QChartSeries::QChartSeries(QObject *parent)
28 \fn QChartSeries::QChartSeries(QObject *parent)
26 \brief Constructs ChartSeries object with \a parent.
29 \brief Constructs ChartSeries object with \a parent.
27 */
30 */
28
31
29 /*!
32 /*!
30 \fn QChartSeries::~QChartSeries()
33 \fn QChartSeries::~QChartSeries()
31 \brief Virtual destructor for the chart series.
34 \brief Virtual destructor for the chart series.
32 */
35 */
33
36
34 /*!
37 /*!
35 \fn QChartSeriesType QChartSeries::type() const
38 \fn QChartSeriesType QChartSeries::type() const
36 \brief The type of the series.
39 \brief The type of the series.
37 */
40 */
38
41
39 /*!
42 /*!
40 \fn bool QChartSeries::setModel(QAbstractItemModel *model)
43 \fn bool QChartSeries::setModel(QAbstractItemModel *model)
41 \brief Use the \a model to provide data for the series. The model overrides possible user data
44 \brief Use the \a model to provide data for the series. The model overrides possible user data
42 set with QChartSeries type specific data setters. For example if you call both
45 set with QChartSeries type specific data setters. For example if you call both
43 QScatterSeries::addData() and QScatterSeries::setModel, only the data provided by the model is
46 QScatterSeries::addData() and QScatterSeries::setModel, only the data provided by the model is
44 used by the series. Returns true if the model is valid for the series.
47 used by the series. Returns true if the model is valid for the series.
45 */
48 */
46
49
47 QTCOMMERCIALCHART_BEGIN_NAMESPACE
50 QTCOMMERCIALCHART_BEGIN_NAMESPACE
48 #include "moc_qchartseries.cpp"
51 #include "moc_qchartseries.cpp"
49 QTCOMMERCIALCHART_END_NAMESPACE
52 QTCOMMERCIALCHART_END_NAMESPACE
General Comments 0
You need to be logged in to leave comments. Login now