@@ -0,0 +1,69 | |||||
|
1 | #include "declarativescatterseries.h" | |||
|
2 | #include "declarativechart.h" | |||
|
3 | #include "qchart.h" | |||
|
4 | #include "qscatterseries.h" | |||
|
5 | #include <cmath> | |||
|
6 | ||||
|
7 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |||
|
8 | ||||
|
9 | DeclarativeScatterSeries::DeclarativeScatterSeries(QDeclarativeItem *parent) : | |||
|
10 | QDeclarativeItem(parent), | |||
|
11 | m_chart(0), | |||
|
12 | m_series(0) | |||
|
13 | { | |||
|
14 | setFlag(QGraphicsItem::ItemHasNoContents, false); | |||
|
15 | connect(this, SIGNAL(parentChanged()), | |||
|
16 | this, SLOT(setParentForSeries())); | |||
|
17 | } | |||
|
18 | ||||
|
19 | void DeclarativeScatterSeries::setParentForSeries() | |||
|
20 | { | |||
|
21 | if (!m_series) | |||
|
22 | initSeries(); | |||
|
23 | } | |||
|
24 | ||||
|
25 | void DeclarativeScatterSeries::initSeries() | |||
|
26 | { | |||
|
27 | Q_ASSERT(!m_series); | |||
|
28 | DeclarativeChart *declarativeChart = qobject_cast<DeclarativeChart *>(parent()); | |||
|
29 | ||||
|
30 | if (declarativeChart) { | |||
|
31 | QChart *chart = qobject_cast<QChart *>(declarativeChart->m_chart); | |||
|
32 | qDebug() << "creating scatter series for chart: " << chart; | |||
|
33 | Q_ASSERT(chart); | |||
|
34 | ||||
|
35 | m_series = new QScatterSeries(); | |||
|
36 | Q_ASSERT(m_series); | |||
|
37 | for (int i(0); i < m_data.count(); i++) { | |||
|
38 | ScatterElement *element = m_data.at(i); | |||
|
39 | *m_series << QPointF(element->x(), element->y()); | |||
|
40 | } | |||
|
41 | chart->addSeries(m_series); | |||
|
42 | } | |||
|
43 | } | |||
|
44 | ||||
|
45 | QDeclarativeListProperty<ScatterElement> DeclarativeScatterSeries::data() | |||
|
46 | { | |||
|
47 | return QDeclarativeListProperty<ScatterElement>(this, 0, | |||
|
48 | &DeclarativeScatterSeries::appendData); | |||
|
49 | } | |||
|
50 | ||||
|
51 | void DeclarativeScatterSeries::appendData(QDeclarativeListProperty<ScatterElement> *list, | |||
|
52 | ScatterElement *element) | |||
|
53 | { | |||
|
54 | DeclarativeScatterSeries *series = qobject_cast<DeclarativeScatterSeries *>(list->object); | |||
|
55 | qDebug() << "appendData: " << series; | |||
|
56 | qDebug() << "appendData: " << element; | |||
|
57 | qDebug() << "appendData: " << element->x(); | |||
|
58 | qDebug() << "appendData: " << element->y(); | |||
|
59 | qDebug() << "appendData: " << series->m_series; | |||
|
60 | if (series) { | |||
|
61 | series->m_data.append(element); | |||
|
62 | if (series->m_series) | |||
|
63 | series->m_series->addData(QPointF(element->x(), element->y())); | |||
|
64 | } | |||
|
65 | } | |||
|
66 | ||||
|
67 | #include "moc_declarativescatterseries.cpp" | |||
|
68 | ||||
|
69 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -0,0 +1,42 | |||||
|
1 | #ifndef DECLARATIVESCATTERSERIES_H | |||
|
2 | #define DECLARATIVESCATTERSERIES_H | |||
|
3 | ||||
|
4 | #include "qchartglobal.h" | |||
|
5 | #include "scatterelement.h" | |||
|
6 | #include <QDeclarativeItem> | |||
|
7 | ||||
|
8 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |||
|
9 | ||||
|
10 | class QChart; | |||
|
11 | class QScatterSeries; | |||
|
12 | ||||
|
13 | class DeclarativeScatterSeries : public QDeclarativeItem | |||
|
14 | { | |||
|
15 | Q_OBJECT | |||
|
16 | Q_PROPERTY(QDeclarativeListProperty<ScatterElement> data READ data) | |||
|
17 | ||||
|
18 | public: | |||
|
19 | explicit DeclarativeScatterSeries(QDeclarativeItem *parent = 0); | |||
|
20 | QDeclarativeListProperty<ScatterElement> data(); | |||
|
21 | ||||
|
22 | signals: | |||
|
23 | ||||
|
24 | public slots: | |||
|
25 | static void appendData(QDeclarativeListProperty<ScatterElement> *list, | |||
|
26 | ScatterElement *element); | |||
|
27 | // void append(ScatterElement element); | |||
|
28 | ||||
|
29 | private slots: | |||
|
30 | void setParentForSeries(); | |||
|
31 | ||||
|
32 | public: | |||
|
33 | void initSeries(); | |||
|
34 | ||||
|
35 | QChart *m_chart; | |||
|
36 | QScatterSeries *m_series; | |||
|
37 | QList<ScatterElement *> m_data; | |||
|
38 | }; | |||
|
39 | ||||
|
40 | QTCOMMERCIALCHART_END_NAMESPACE | |||
|
41 | ||||
|
42 | #endif // DECLARATIVESCATTERSERIES_H |
@@ -0,0 +1,12 | |||||
|
1 | #include "scatterelement.h" | |||
|
2 | ||||
|
3 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |||
|
4 | ||||
|
5 | ScatterElement::ScatterElement(QObject *parent) : | |||
|
6 | QObject(parent) | |||
|
7 | { | |||
|
8 | } | |||
|
9 | ||||
|
10 | #include "moc_scatterelement.cpp" | |||
|
11 | ||||
|
12 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -0,0 +1,30 | |||||
|
1 | #ifndef SCATTERELEMENT_H | |||
|
2 | #define SCATTERELEMENT_H | |||
|
3 | ||||
|
4 | #include "qchartglobal.h" | |||
|
5 | #include <QObject> | |||
|
6 | ||||
|
7 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |||
|
8 | ||||
|
9 | class ScatterElement : public QObject | |||
|
10 | { | |||
|
11 | Q_OBJECT | |||
|
12 | Q_PROPERTY(qreal x READ x WRITE setX /*NOTIFY dataXChanged*/) | |||
|
13 | Q_PROPERTY(qreal y READ y WRITE setY /*NOTIFY dataYChanged*/) | |||
|
14 | ||||
|
15 | public: | |||
|
16 | explicit ScatterElement(QObject *parent = 0); | |||
|
17 | ||||
|
18 | void setX(qreal x) {m_x = x;} | |||
|
19 | qreal x() {return m_x;} | |||
|
20 | void setY(qreal y) {m_y = y;} | |||
|
21 | qreal y() {return m_y;} | |||
|
22 | ||||
|
23 | public: | |||
|
24 | qreal m_x; | |||
|
25 | qreal m_y; | |||
|
26 | }; | |||
|
27 | ||||
|
28 | QTCOMMERCIALCHART_END_NAMESPACE | |||
|
29 | ||||
|
30 | #endif // SCATTERELEMENT_H |
@@ -1,27 +1,30 | |||||
1 | #include <QtDeclarative/qdeclarativeextensionplugin.h> |
|
1 | #include <QtDeclarative/qdeclarativeextensionplugin.h> | |
2 | #include <QtDeclarative/qdeclarative.h> |
|
2 | #include <QtDeclarative/qdeclarative.h> | |
3 | #include "declarativechart.h" |
|
3 | #include "declarativechart.h" | |
4 | #include "declarativeseries.h" |
|
4 | #include "declarativeseries.h" | |
|
5 | #include "scatterelement.h" | |||
|
6 | #include "declarativescatterseries.h" | |||
5 |
|
7 | |||
6 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
8 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
7 |
|
9 | |||
8 | class ChartQmlPlugin : public QDeclarativeExtensionPlugin |
|
10 | class ChartQmlPlugin : public QDeclarativeExtensionPlugin | |
9 | { |
|
11 | { | |
10 | Q_OBJECT |
|
12 | Q_OBJECT | |
11 | public: |
|
13 | public: | |
12 | virtual void registerTypes(const char *uri) |
|
14 | virtual void registerTypes(const char *uri) | |
13 | { |
|
15 | { | |
14 | Q_ASSERT(QLatin1String(uri) == QLatin1String("QtCommercial.Chart")); |
|
16 | Q_ASSERT(QLatin1String(uri) == QLatin1String("QtCommercial.Chart")); | |
15 | qmlRegisterType<DeclarativeChart>(uri, 1, 0, "Chart"); |
|
17 | qmlRegisterType<DeclarativeChart>(uri, 1, 0, "Chart"); | |
16 | qmlRegisterType<DeclarativeSeries>(uri, 1, 0, "Series"); |
|
18 | qmlRegisterType<DeclarativeSeries>(uri, 1, 0, "Series"); | |
17 | //qmlRegisterUncreatableType<QChartSeries::SeriesTypeBar>(uri, 1, 0, "Series.Se", QLatin1String("Do not create objects of this type.")); |
|
19 | qmlRegisterType<DeclarativeScatterSeries>(uri, 1, 0, "ScatterSeries"); | |
|
20 | qmlRegisterType<ScatterElement>(uri, 1, 0, "ScatterElement"); | |||
18 | } |
|
21 | } | |
19 | }; |
|
22 | }; | |
20 |
|
23 | |||
21 | #include "plugin.moc" |
|
24 | #include "plugin.moc" | |
22 |
|
25 | |||
23 | QTCOMMERCIALCHART_END_NAMESPACE |
|
26 | QTCOMMERCIALCHART_END_NAMESPACE | |
24 |
|
27 | |||
25 | QTCOMMERCIALCHART_USE_NAMESPACE |
|
28 | QTCOMMERCIALCHART_USE_NAMESPACE | |
26 |
|
29 | |||
27 | Q_EXPORT_PLUGIN2(qtcommercialchartqml, QT_PREPEND_NAMESPACE(ChartQmlPlugin)) |
|
30 | Q_EXPORT_PLUGIN2(qtcommercialchartqml, QT_PREPEND_NAMESPACE(ChartQmlPlugin)) |
@@ -1,39 +1,57 | |||||
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 | !include( ../integrated.pri ) { |
|
4 | !include( ../integrated.pri ) { | |
5 | error( "Couldn't find the integrated.pri file !") |
|
5 | error( "Couldn't find the integrated.pri file !") | |
6 | } |
|
6 | } | |
7 |
|
7 | |||
8 | TEMPLATE = lib |
|
8 | TEMPLATE = lib | |
9 | TARGET = qtcommercialchartqml |
|
9 | TARGET = qtcommercialchartqml | |
10 |
|
10 | |||
11 | CONFIG += qt plugin |
|
11 | CONFIG += qt plugin | |
12 | QT += declarative |
|
12 | QT += declarative | |
13 |
|
13 | |||
14 | contains(QT_MAJOR_VERSION, 5) { |
|
14 | contains(QT_MAJOR_VERSION, 5) { | |
15 | # TODO: QtQuick2 not supported by the implementation currently |
|
15 | # TODO: QtQuick2 not supported by the implementation currently | |
16 | DEFINES += QTQUICK2 |
|
16 | DEFINES += QTQUICK2 | |
17 | } |
|
17 | } | |
18 |
|
18 | |||
19 | OBJECTS_DIR = $$CHART_BUILD_DIR/lib |
|
19 | OBJECTS_DIR = $$CHART_BUILD_DIR/lib | |
20 | MOC_DIR = $$CHART_BUILD_DIR/lib |
|
20 | MOC_DIR = $$CHART_BUILD_DIR/lib | |
21 | UI_DIR = $$CHART_BUILD_DIR/lib |
|
21 | UI_DIR = $$CHART_BUILD_DIR/lib | |
22 | RCC_DIR = $$CHART_BUILD_DIR/lib |
|
22 | RCC_DIR = $$CHART_BUILD_DIR/lib | |
23 |
|
23 | |||
24 | SOURCES += \ |
|
24 | SOURCES += \ | |
25 | plugin.cpp \ |
|
25 | plugin.cpp \ | |
26 | declarativechart.cpp \ |
|
26 | declarativechart.cpp \ | |
27 | declarativeseries.cpp |
|
27 | declarativeseries.cpp \ | |
|
28 | declarativescatterseries.cpp \ | |||
|
29 | scatterelement.cpp | |||
28 | HEADERS += \ |
|
30 | HEADERS += \ | |
29 | declarativechart.h \ |
|
31 | declarativechart.h \ | |
30 | declarativeseries.h |
|
32 | declarativeseries.h \ | |
|
33 | declarativescatterseries.h \ | |||
|
34 | scatterelement.h | |||
31 |
|
35 | |||
32 | TARGETPATH = QtCommercial/Chart |
|
36 | TARGETPATH = QtCommercial/Chart | |
33 | target.path = $$[QT_INSTALL_IMPORTS]/$$TARGETPATH |
|
37 | target.path = $$[QT_INSTALL_IMPORTS]/$$TARGETPATH | |
34 | qmldir.files += $$PWD/qmldir |
|
38 | qmldir.files += $$PWD/qmldir | |
35 | qmldir.path += $$[QT_INSTALL_IMPORTS]/$$TARGETPATH |
|
39 | qmldir.path += $$[QT_INSTALL_IMPORTS]/$$TARGETPATH | |
36 |
|
40 | |||
37 | INSTALLS += target qmldir |
|
41 | INSTALLS += target qmldir | |
38 |
|
42 | |||
39 |
|
43 | |||
|
44 | ||||
|
45 | ||||
|
46 | ||||
|
47 | ||||
|
48 | ||||
|
49 | ||||
|
50 | ||||
|
51 | ||||
|
52 | ||||
|
53 | ||||
|
54 | ||||
|
55 | ||||
|
56 | ||||
|
57 |
@@ -1,117 +1,75 | |||||
1 | import QtQuick 1.0 |
|
1 | import QtQuick 1.0 | |
2 | import QtCommercial.Chart 1.0 |
|
2 | import QtCommercial.Chart 1.0 | |
3 |
|
3 | |||
4 | Rectangle { |
|
4 | Rectangle { | |
5 | width: 360 |
|
5 | width: 360 | |
6 | height: 360 |
|
6 | height: 360 | |
7 | Text { |
|
7 | Text { | |
8 | text: qsTr("Hello World") |
|
8 | text: qsTr("Hello World") | |
9 | anchors.centerIn: parent |
|
9 | anchors.centerIn: parent | |
10 | } |
|
10 | } | |
11 |
|
11 | |||
|
12 | // Another option for QML data api: | |||
12 | // ListModel { |
|
13 | // ListModel { | |
13 | // id: listModelForPie |
|
14 | // id: listModelForPie | |
14 | // // PieDataElement |
|
15 | // // PieDataElement | |
15 | // ListElement { |
|
16 | // ListElement { | |
16 | // label: "Apple" |
|
17 | // label: "Apple" | |
17 |
// value: 4 |
|
18 | // value: 4.3 | |
18 | // } |
|
19 | // } | |
19 | // ListElement { |
|
20 | // ListElement { | |
20 |
// label: " |
|
21 | // label: "Blackberry" | |
21 | // value: 10.1 |
|
|||
22 | // } |
|
|||
23 | // ListElement { |
|
|||
24 | // label: "Raspberry" |
|
|||
25 | // value: 15.1 |
|
22 | // value: 15.1 | |
26 | // } |
|
23 | // } | |
27 | // ListElement { |
|
|||
28 | // label: "Strawberry" |
|
|||
29 | // value: 29.9 |
|
|||
30 | // } |
|
|||
31 | // } |
|
24 | // } | |
32 |
|
25 | |||
33 | // ChartModel { |
|
26 | Component.onCompleted: { | |
34 | // id: chartModel |
|
27 | // console.log("Component.onCompleted: " + scatterElement.x); | |
35 | // ListElement { |
|
28 | // console.log("Component.onCompleted: " + scatterElement.y); | |
36 | // label: "dada" |
|
29 | // console.log("Component.onCompleted: " + scatterElement.dataX); | |
37 | // x: 1.1 |
|
30 | // console.log("Component.onCompleted: " + scatterElement.dataY); | |
38 | // y: 3.2 |
|
31 | //console.log("Component.onCompleted: " + chartModel.get(0).x); | |
39 | // } |
|
32 | //console.log("Component.onCompleted: " + chartModel.scatterElements); | |
40 | // } |
|
33 | // console.log("Component.onCompleted: " + elementt.dataX); | |
41 |
|
34 | // console.log("Component.onCompleted: " + chartModel.get(0).dataX); | ||
42 | // ChartModel { |
|
|||
43 | // ScatterElement {x: 1.1; y: 1.2} |
|
|||
44 | // ScatterElement {x: 1.3; y: 1.9} |
|
|||
45 | // ScatterElement {x: 1.1; y: 1.2} |
|
|||
46 | // } |
|
|||
47 |
|
||||
48 | ListModel { |
|
|||
49 | id: listModelScatter |
|
|||
50 | ListElement { |
|
|||
51 | height: 154 |
|
|||
52 | weight: 54 |
|
|||
53 | } |
|
|||
54 | ListElement { |
|
|||
55 | height: 166 |
|
|||
56 | weight: 64 |
|
|||
57 | } |
|
|||
58 | ListElement { |
|
|||
59 | height: 199 |
|
|||
60 | weight: 97 |
|
|||
61 | } |
|
|||
62 | } |
|
35 | } | |
63 |
|
36 | |||
64 | // Chart { |
|
|||
65 | // anchors.fill: parent |
|
|||
66 | // theme: Chart.ThemeIcy |
|
|||
67 | // ScatterSeries { |
|
|||
68 | // model: listModelScatter |
|
|||
69 | // name: "scatter" |
|
|||
70 | // xValue: x |
|
|||
71 | // yValue: y |
|
|||
72 | // } |
|
|||
73 | // } |
|
|||
74 |
|
||||
75 | Chart { |
|
37 | Chart { | |
76 | anchors.fill: parent |
|
38 | anchors.fill: parent | |
77 | theme: Chart.ThemeIcy |
|
39 | theme: Chart.ThemeIcy | |
78 |
|
40 | |||
79 |
|
|
41 | ScatterSeries { | |
80 | // labels: ["point1", "point2", "point3", "point4", "point5"] |
|
42 | id: scatterSeries | |
81 |
|
|
43 | data: [ | |
82 | // } |
|
44 | ScatterElement { x: 1.1; y: 2.1 }, | |
83 | // PieSeries { |
|
45 | ScatterElement { x: 1.2; y: 2.0 }, | |
84 | // name: "raspberry pie" |
|
46 | ScatterElement { x: 1.4; y: 2.3 }, | |
85 | // seriesLabels: ["point1", "point2", "point3", "point4", "point5"] |
|
47 | ScatterElement { x: 1.9; y: 2.5 }, | |
86 | // seriesData: [2, 1.5, 3, 3, 3] |
|
48 | ScatterElement { x: 1.9; y: 3.4 }, | |
87 | // } |
|
49 | ScatterElement { x: 2.9; y: 1.4 }, | |
88 | // ScatterSeries { |
|
50 | ScatterElement { x: 2.9; y: 2.4 }, | |
89 | // name: "scatter1" |
|
51 | ScatterElement { x: 3.1; y: 5.3 }, | |
90 | // datax: [2, 1.5, 3, 3, 3] |
|
52 | ScatterElement { x: 4.1; y: 3.7 } | |
91 | // datay: [2, 1.5, 3, 3, 3] |
|
53 | ] | |
92 | // } |
|
54 | Component.onCompleted: { | |
|
55 | console.log("onCompleted " + data); | |||
|
56 | // console.log("onCompleted " + data.get(0)); | |||
|
57 | // console.log("onCompleted " + data.get(0).x); | |||
|
58 | // var element = {"x": 9.9, "y": 8.5}; | |||
|
59 | // data.append(element); | |||
|
60 | } | |||
|
61 | } | |||
|
62 | ||||
93 | // Series { |
|
63 | // Series { | |
94 | // labels: ["point1", "point2", "point3", "point4", "point5"] |
|
|||
95 | // datax: [2, 1.5, 3, 3, 3] |
|
|||
96 | // seriesType: Series.SeriesTypePie |
|
64 | // seriesType: Series.SeriesTypePie | |
97 | // } |
|
65 | // } | |
98 | Series { |
|
|||
99 | seriesType: Series.SeriesTypePie |
|
|||
100 | //model: listModelForPie |
|
|||
101 | //seriesData: {11.0, 6.4, 12.6, 22.4} |
|
|||
102 | //seriesLabels: {"Strawberry", "Blackberry", "Apple", "Pumpkin"} |
|
|||
103 | } |
|
|||
104 |
|
66 | |||
105 |
|
|
67 | // Series { | |
106 | // data: {[1.2], "y":2.2 } |
|
68 | // seriesType: Series.SeriesTypeLine | |
107 | seriesType: Series.SeriesTypeScatter |
|
69 | // } | |
108 | } |
|
|||
109 | Series { |
|
|||
110 | seriesType: Series.SeriesTypeLine |
|
|||
111 | } |
|
|||
112 | // TODO: |
|
70 | // TODO: | |
113 |
|
|
71 | // Series { | |
114 | // seriesType: Series.SeriesTypeBar |
|
72 | // seriesType: Series.SeriesTypeBar | |
115 | // } |
|
73 | // } | |
116 | } |
|
74 | } | |
117 | } |
|
75 | } |
General Comments 0
You need to be logged in to leave comments.
Login now