##// END OF EJS Templates
Spline to QML API
Tero Ahola -
r732:4aded284df80
parent child
Show More
@@ -0,0 +1,23
1 #ifndef DECLARATIVESPLINESERIES_H
2 #define DECLARATIVESPLINESERIES_H
3
4 #include "qchartglobal.h"
5 #include "declarativexyseries.h"
6 #include <QDeclarativeItem>
7
8 QTCOMMERCIALCHART_BEGIN_NAMESPACE
9
10 class DeclarativeSplineSeries : public DeclarativeXySeries
11 {
12 Q_OBJECT
13
14 public:
15 explicit DeclarativeSplineSeries(QDeclarativeItem *parent = 0) :
16 DeclarativeXySeries(QSeries::SeriesTypeSpline, parent) {}
17 };
18
19 #include "moc_declarativesplineseries.cpp"
20
21 QTCOMMERCIALCHART_END_NAMESPACE
22
23 #endif // DECLARATIVESPLINESERIES_H
@@ -0,0 +1,85
1 #include "DeclarativeXySeries.h"
2 #include "declarativechart.h"
3 #include "qchart.h"
4 #include "qxyseries.h"
5 #include "qareaseries.h"
6 #include "qsplineseries.h"
7 #include "qscatterseries.h"
8
9 QTCOMMERCIALCHART_BEGIN_NAMESPACE
10
11 DeclarativeXySeries::DeclarativeXySeries(QSeries::QSeriesType type, QDeclarativeItem *parent) :
12 QDeclarativeItem(parent),
13 m_seriesType(type),
14 m_chart(0),
15 m_series(0)
16 {
17 setFlag(QGraphicsItem::ItemHasNoContents, false);
18 }
19
20 DeclarativeXySeries::~DeclarativeXySeries()
21 {
22 }
23
24 void DeclarativeXySeries::componentComplete()
25 {
26 Q_ASSERT(!m_series);
27 DeclarativeChart *declarativeChart = qobject_cast<DeclarativeChart *>(parent());
28
29 if (declarativeChart) {
30 m_chart = qobject_cast<QChart *>(declarativeChart->m_chart);
31 Q_ASSERT(m_chart);
32
33 switch (m_seriesType) {
34 case QSeries::SeriesTypeLine:
35 qDebug() << "creating line series for chart: " << m_chart;
36 m_series = new QLineSeries();
37 break;
38 case QSeries::SeriesTypeArea:
39 qDebug() << "TODO: creating area series for chart: " << m_chart;
40 // m_series = new QAreaSeries();
41 break;
42 case QSeries::SeriesTypeSpline:
43 qDebug() << "creating spline series for chart: " << m_chart;
44 m_series = new QSplineSeries();
45 break;
46 case QSeries::SeriesTypeScatter:
47 qDebug() << "creating scatter series for chart: " << m_chart;
48 m_series = new QScatterSeries();
49 break;
50 default:
51 Q_ASSERT(false);
52 }
53
54 for (int i(0); i < m_points.count(); i++) {
55 DeclarativeXyPoint *element = m_points.at(i);
56 m_series->add(element->x(), element->y());
57 }
58 m_chart->addSeries(m_series);
59 }
60 }
61
62 QDeclarativeListProperty<DeclarativeXyPoint> DeclarativeXySeries::points()
63 {
64 return QDeclarativeListProperty<DeclarativeXyPoint>(this, 0, &DeclarativeXySeries::appendPoints);
65 }
66
67 void DeclarativeXySeries::appendPoints(QDeclarativeListProperty<DeclarativeXyPoint> *list,
68 DeclarativeXyPoint *element)
69 {
70 DeclarativeXySeries *series = qobject_cast<DeclarativeXySeries *>(list->object);
71 qDebug() << "appendPoints: " << series;
72 qDebug() << "appendPoints: " << element;
73 qDebug() << "appendPoints: " << element->x();
74 qDebug() << "appendPoints: " << element->y();
75 qDebug() << "appendPoints: " << series->m_series;
76 if (series) {
77 series->m_points.append(element);
78 if (series->m_series)
79 series->m_series->add(element->x(), element->y());
80 }
81 }
82
83 #include "moc_declarativexyseries.cpp"
84
85 QTCOMMERCIALCHART_END_NAMESPACE
@@ -0,0 +1,45
1 #ifndef DECLARATIVE_XY_SERIES_H
2 #define DECLARATIVE_XY_SERIES_H
3
4 #include "qchartglobal.h"
5 #include "declarativexypoint.h"
6 #include "qxyseries.h"
7 #include <QDeclarativeItem>
8
9 QTCOMMERCIALCHART_BEGIN_NAMESPACE
10
11 class QChart;
12
13 class DeclarativeXySeries : public QDeclarativeItem
14 {
15 Q_OBJECT
16 Q_PROPERTY(QDeclarativeListProperty<DeclarativeXyPoint> points READ points)
17
18 public:
19 explicit DeclarativeXySeries(QSeries::QSeriesType type, QDeclarativeItem *parent = 0);
20 ~DeclarativeXySeries();
21
22 public: // from QDeclarativeParserStatus
23 void componentComplete();
24
25 public:
26 QDeclarativeListProperty<DeclarativeXyPoint> points();
27
28 signals:
29
30 public slots:
31 static void appendPoints(QDeclarativeListProperty<DeclarativeXyPoint> *list,
32 DeclarativeXyPoint *element);
33
34 private slots:
35
36 public:
37 QSeries::QSeriesType m_seriesType;
38 QChart *m_chart;
39 QXYSeries *m_series;
40 QList<DeclarativeXyPoint *> m_points;
41 };
42
43 QTCOMMERCIALCHART_END_NAMESPACE
44
45 #endif // DECLARATIVE_XY_SERIES_H
@@ -6,48 +6,8
6 QTCOMMERCIALCHART_BEGIN_NAMESPACE
6 QTCOMMERCIALCHART_BEGIN_NAMESPACE
7
7
8 DeclarativeLineSeries::DeclarativeLineSeries(QDeclarativeItem *parent) :
8 DeclarativeLineSeries::DeclarativeLineSeries(QDeclarativeItem *parent) :
9 QDeclarativeItem(parent)
9 DeclarativeXySeries(QSeries::SeriesTypeLine, parent)
10 {
10 {
11 setFlag(QGraphicsItem::ItemHasNoContents, false);
12 connect(this, SIGNAL(parentChanged()),
13 this, SLOT(setParentForSeries()));
14 }
15
16 void DeclarativeLineSeries::setParentForSeries()
17 {
18 if (!m_series) {
19 DeclarativeChart *declarativeChart = qobject_cast<DeclarativeChart *>(parent());
20
21 if (declarativeChart) {
22 QChart *chart = qobject_cast<QChart *>(declarativeChart->m_chart);
23 qDebug() << "creating line series for chart: " << chart;
24 Q_ASSERT(chart);
25
26 m_series = new QLineSeries();
27 Q_ASSERT(m_series);
28 for (int i(0); i < m_data.count(); i++) {
29 DeclarativeXyPoint *element = m_data.at(i);
30 m_series->add(element->x(), element->y());
31 }
32 chart->addSeries(m_series);
33 }
34 }
35 }
36
37 QDeclarativeListProperty<DeclarativeXyPoint> DeclarativeLineSeries::data()
38 {
39 return QDeclarativeListProperty<DeclarativeXyPoint>(this, 0, &DeclarativeLineSeries::appendData);
40 }
41
42 void DeclarativeLineSeries::appendData(QDeclarativeListProperty<DeclarativeXyPoint> *list,
43 DeclarativeXyPoint *element)
44 {
45 DeclarativeLineSeries *series = qobject_cast<DeclarativeLineSeries *>(list->object);
46 if (series) {
47 series->m_data.append(element);
48 if (series->m_series)
49 series->m_series->add(element->x(), element->y());
50 }
51 }
11 }
52
12
53 #include "moc_declarativelineseries.cpp"
13 #include "moc_declarativelineseries.cpp"
@@ -2,36 +2,17
2 #define DECLARATIVELINESERIES_H
2 #define DECLARATIVELINESERIES_H
3
3
4 #include "qchartglobal.h"
4 #include "qchartglobal.h"
5 #include "declarativexypoint.h"
5 #include "declarativexyseries.h"
6 #include <QDeclarativeItem>
6 #include <QDeclarativeItem>
7
7
8 QTCOMMERCIALCHART_BEGIN_NAMESPACE
8 QTCOMMERCIALCHART_BEGIN_NAMESPACE
9
9
10 class QChart;
10 class DeclarativeLineSeries : public DeclarativeXySeries
11 class QLineSeries;
12
13 class DeclarativeLineSeries : public QDeclarativeItem
14 {
11 {
15 Q_OBJECT
12 Q_OBJECT
16 Q_PROPERTY(QDeclarativeListProperty<DeclarativeXyPoint> data READ data)
17
13
18 public:
14 public:
19 explicit DeclarativeLineSeries(QDeclarativeItem *parent = 0);
15 explicit DeclarativeLineSeries(QDeclarativeItem *parent = 0);
20 QDeclarativeListProperty<DeclarativeXyPoint> data();
21
22 signals:
23
24 public slots:
25 static void appendData(QDeclarativeListProperty<DeclarativeXyPoint> *list,
26 DeclarativeXyPoint *element);
27
28 private slots:
29 void setParentForSeries();
30
31 private:
32 QChart *m_chart;
33 QLineSeries *m_series;
34 QList<DeclarativeXyPoint *> m_data;
35 };
16 };
36
17
37 QTCOMMERCIALCHART_END_NAMESPACE
18 QTCOMMERCIALCHART_END_NAMESPACE
@@ -6,58 +6,11
6 QTCOMMERCIALCHART_BEGIN_NAMESPACE
6 QTCOMMERCIALCHART_BEGIN_NAMESPACE
7
7
8 DeclarativeScatterSeries::DeclarativeScatterSeries(QDeclarativeItem *parent) :
8 DeclarativeScatterSeries::DeclarativeScatterSeries(QDeclarativeItem *parent) :
9 QDeclarativeItem(parent),
9 DeclarativeXySeries(QSeries::SeriesTypeScatter, parent)
10 m_chart(0),
11 m_series(0)
12 {
10 {
13 setFlag(QGraphicsItem::ItemHasNoContents, false);
11 setFlag(QGraphicsItem::ItemHasNoContents, false);
14 }
12 }
15
13
16 DeclarativeScatterSeries::~DeclarativeScatterSeries()
17 {
18 }
19
20 void DeclarativeScatterSeries::componentComplete()
21 {
22 Q_ASSERT(!m_series);
23 DeclarativeChart *declarativeChart = qobject_cast<DeclarativeChart *>(parent());
24
25 if (declarativeChart) {
26 m_chart = qobject_cast<QChart *>(declarativeChart->m_chart);
27 qDebug() << "creating scatter series for chart: " << m_chart;
28 Q_ASSERT(m_chart);
29
30 m_series = new QScatterSeries();
31 for (int i(0); i < m_points.count(); i++) {
32 DeclarativeXyPoint *element = m_points.at(i);
33 *m_series << QPointF(element->x(), element->y());
34 }
35 m_chart->addSeries(m_series);
36 }
37 }
38
39 QDeclarativeListProperty<DeclarativeXyPoint> DeclarativeScatterSeries::points()
40 {
41 return QDeclarativeListProperty<DeclarativeXyPoint>(this, 0,
42 &DeclarativeScatterSeries::appendPoints);
43 }
44
45 void DeclarativeScatterSeries::appendPoints(QDeclarativeListProperty<DeclarativeXyPoint> *list,
46 DeclarativeXyPoint *element)
47 {
48 DeclarativeScatterSeries *series = qobject_cast<DeclarativeScatterSeries *>(list->object);
49 qDebug() << "appendPoints: " << series;
50 qDebug() << "appendPoints: " << element;
51 qDebug() << "appendPoints: " << element->x();
52 qDebug() << "appendPoints: " << element->y();
53 qDebug() << "appendPoints: " << series->m_series;
54 if (series) {
55 series->m_points.append(element);
56 if (series->m_series)
57 series->m_series->add(element->x(), element->y());
58 }
59 }
60
61 #include "moc_declarativescatterseries.cpp"
14 #include "moc_declarativescatterseries.cpp"
62
15
63 QTCOMMERCIALCHART_END_NAMESPACE
16 QTCOMMERCIALCHART_END_NAMESPACE
@@ -2,41 +2,17
2 #define DECLARATIVESCATTERSERIES_H
2 #define DECLARATIVESCATTERSERIES_H
3
3
4 #include "qchartglobal.h"
4 #include "qchartglobal.h"
5 #include "declarativexypoint.h"
5 #include "declarativexyseries.h"
6 #include <QDeclarativeItem>
6 #include <QDeclarativeItem>
7
7
8 QTCOMMERCIALCHART_BEGIN_NAMESPACE
8 QTCOMMERCIALCHART_BEGIN_NAMESPACE
9
9
10 class QChart;
10 class DeclarativeScatterSeries : public DeclarativeXySeries
11 class QScatterSeries;
12
13 class DeclarativeScatterSeries : public QDeclarativeItem
14 {
11 {
15 Q_OBJECT
12 Q_OBJECT
16 Q_PROPERTY(QDeclarativeListProperty<DeclarativeXyPoint> points READ points)
17
13
18 public:
14 public:
19 explicit DeclarativeScatterSeries(QDeclarativeItem *parent = 0);
15 explicit DeclarativeScatterSeries(QDeclarativeItem *parent = 0);
20 ~DeclarativeScatterSeries();
21
22 public: // from QDeclarativeParserStatus
23 void componentComplete();
24
25 public:
26 QDeclarativeListProperty<DeclarativeXyPoint> points();
27
28 signals:
29
30 public slots:
31 static void appendPoints(QDeclarativeListProperty<DeclarativeXyPoint> *list,
32 DeclarativeXyPoint *element);
33
34 private slots:
35
36 public:
37 QChart *m_chart; // not owned
38 QScatterSeries *m_series; // not owned
39 QList<DeclarativeXyPoint *> m_points; // not owned
40 };
16 };
41
17
42 QTCOMMERCIALCHART_END_NAMESPACE
18 QTCOMMERCIALCHART_END_NAMESPACE
@@ -2,8 +2,9
2 #include <QtDeclarative/qdeclarative.h>
2 #include <QtDeclarative/qdeclarative.h>
3 #include "declarativechart.h"
3 #include "declarativechart.h"
4 #include "declarativexypoint.h"
4 #include "declarativexypoint.h"
5 #include "declarativescatterseries.h"
6 #include "declarativelineseries.h"
5 #include "declarativelineseries.h"
6 #include "declarativesplineseries.h"
7 #include "declarativescatterseries.h"
7 #include "declarativebarseries.h"
8 #include "declarativebarseries.h"
8 #include "declarativepieseries.h"
9 #include "declarativepieseries.h"
9
10
@@ -21,6 +22,7 public:
21 qmlRegisterType<DeclarativeXyPoint>(uri, 1, 0, "XyPoint");
22 qmlRegisterType<DeclarativeXyPoint>(uri, 1, 0, "XyPoint");
22 qmlRegisterType<DeclarativeScatterSeries>(uri, 1, 0, "ScatterSeries");
23 qmlRegisterType<DeclarativeScatterSeries>(uri, 1, 0, "ScatterSeries");
23 qmlRegisterType<DeclarativeLineSeries>(uri, 1, 0, "LineSeries");
24 qmlRegisterType<DeclarativeLineSeries>(uri, 1, 0, "LineSeries");
25 qmlRegisterType<DeclarativeSplineSeries>(uri, 1, 0, "SplineSeries");
24 qmlRegisterType<DeclarativeBarSeries>(uri, 1, 0, "BarSeries");
26 qmlRegisterType<DeclarativeBarSeries>(uri, 1, 0, "BarSeries");
25 qmlRegisterType<DeclarativePieSeries>(uri, 1, 0, "PieSeries");
27 qmlRegisterType<DeclarativePieSeries>(uri, 1, 0, "PieSeries");
26 qmlRegisterType<QPieSlice>(uri, 1, 0, "PieSlice");
28 qmlRegisterType<QPieSlice>(uri, 1, 0, "PieSlice");
@@ -24,17 +24,20 RCC_DIR = $$CHART_BUILD_DIR/plugin
24 SOURCES += \
24 SOURCES += \
25 plugin.cpp \
25 plugin.cpp \
26 declarativechart.cpp \
26 declarativechart.cpp \
27 declarativescatterseries.cpp \
28 declarativexypoint.cpp \
27 declarativexypoint.cpp \
29 declarativepieseries.cpp \
28 declarativexyseries.cpp \
30 declarativelineseries.cpp \
29 declarativelineseries.cpp \
30 declarativescatterseries.cpp \
31 declarativepieseries.cpp \
31 declarativebarseries.cpp
32 declarativebarseries.cpp
32 HEADERS += \
33 HEADERS += \
33 declarativechart.h \
34 declarativechart.h \
34 declarativescatterseries.h \
35 declarativexypoint.h \
35 declarativexypoint.h \
36 declarativepieseries.h \
36 declarativexyseries.h \
37 declarativelineseries.h \
37 declarativelineseries.h \
38 declarativesplineseries.h \
39 declarativescatterseries.h \
40 declarativepieseries.h \
38 declarativebarseries.h
41 declarativebarseries.h
39
42
40 TARGETPATH = QtCommercial/Chart
43 TARGETPATH = QtCommercial/Chart
@@ -63,7 +63,7 Rectangle {
63 theme: Chart.ThemeBrownSand
63 theme: Chart.ThemeBrownSand
64
64
65 LineSeries {
65 LineSeries {
66 data: [
66 points: [
67 XyPoint { x: 0.0; y: 0.0 },
67 XyPoint { x: 0.0; y: 0.0 },
68 XyPoint { x: 1.1; y: 2.1 },
68 XyPoint { x: 1.1; y: 2.1 },
69 XyPoint { x: 2.9; y: 4.9 },
69 XyPoint { x: 2.9; y: 4.9 },
@@ -71,12 +71,12 Rectangle {
71 ]
71 ]
72 }
72 }
73
73
74 ScatterSeries {
74 SplineSeries {
75 id: scatter
75 id: scatter
76 points: [
76 points: [
77 XyPoint { x: 1.1; y: 1.1 },
77 XyPoint { x: 0.0; y: 0.3 },
78 XyPoint { x: 1.1; y: 1.2 },
78 XyPoint { x: 1.1; y: 3.2 },
79 XyPoint { x: 1.17; y: 1.15 }
79 XyPoint { x: 4.17; y: 3.15 }
80 ]
80 ]
81 }
81 }
82 ScatterSeries {
82 ScatterSeries {
General Comments 0
You need to be logged in to leave comments. Login now