@@ -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 |
@@ -2,6 +2,8 | |||
|
2 | 2 | #include <QtDeclarative/qdeclarative.h> |
|
3 | 3 | #include "declarativechart.h" |
|
4 | 4 | #include "declarativeseries.h" |
|
5 | #include "scatterelement.h" | |
|
6 | #include "declarativescatterseries.h" | |
|
5 | 7 | |
|
6 | 8 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
7 | 9 | |
@@ -14,7 +16,8 public: | |||
|
14 | 16 | Q_ASSERT(QLatin1String(uri) == QLatin1String("QtCommercial.Chart")); |
|
15 | 17 | qmlRegisterType<DeclarativeChart>(uri, 1, 0, "Chart"); |
|
16 | 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 |
@@ -24,10 +24,14 RCC_DIR = $$CHART_BUILD_DIR/lib | |||
|
24 | 24 | SOURCES += \ |
|
25 | 25 | plugin.cpp \ |
|
26 | 26 | declarativechart.cpp \ |
|
27 | declarativeseries.cpp | |
|
27 | declarativeseries.cpp \ | |
|
28 | declarativescatterseries.cpp \ | |
|
29 | scatterelement.cpp | |
|
28 | 30 | HEADERS += \ |
|
29 | 31 | declarativechart.h \ |
|
30 | declarativeseries.h | |
|
32 | declarativeseries.h \ | |
|
33 | declarativescatterseries.h \ | |
|
34 | scatterelement.h | |
|
31 | 35 | |
|
32 | 36 | TARGETPATH = QtCommercial/Chart |
|
33 | 37 | target.path = $$[QT_INSTALL_IMPORTS]/$$TARGETPATH |
@@ -37,3 +41,17 qmldir.path += $$[QT_INSTALL_IMPORTS]/$$TARGETPATH | |||
|
37 | 41 | INSTALLS += target qmldir |
|
38 | 42 | |
|
39 | 43 | |
|
44 | ||
|
45 | ||
|
46 | ||
|
47 | ||
|
48 | ||
|
49 | ||
|
50 | ||
|
51 | ||
|
52 | ||
|
53 | ||
|
54 | ||
|
55 | ||
|
56 | ||
|
57 |
@@ -9,106 +9,64 Rectangle { | |||
|
9 | 9 | anchors.centerIn: parent |
|
10 | 10 | } |
|
11 | 11 | |
|
12 | // Another option for QML data api: | |
|
12 | 13 | // ListModel { |
|
13 | 14 | // id: listModelForPie |
|
14 | 15 | // // PieDataElement |
|
15 | 16 | // ListElement { |
|
16 | 17 | // label: "Apple" |
|
17 |
// value: 4 |
|
|
18 | // value: 4.3 | |
|
18 | 19 | // } |
|
19 | 20 | // ListElement { |
|
20 |
// label: " |
|
|
21 | // value: 10.1 | |
|
22 | // } | |
|
23 | // ListElement { | |
|
24 | // label: "Raspberry" | |
|
21 | // label: "Blackberry" | |
|
25 | 22 | // value: 15.1 |
|
26 | 23 | // } |
|
27 | // ListElement { | |
|
28 | // label: "Strawberry" | |
|
29 | // value: 29.9 | |
|
30 | // } | |
|
31 | // } | |
|
32 | ||
|
33 | // ChartModel { | |
|
34 | // id: chartModel | |
|
35 | // ListElement { | |
|
36 | // label: "dada" | |
|
37 | // x: 1.1 | |
|
38 | // y: 3.2 | |
|
39 | // } | |
|
40 | // } | |
|
41 | ||
|
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 | 24 | // } |
|
47 | 25 | |
|
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 | } | |
|
26 | Component.onCompleted: { | |
|
27 | // console.log("Component.onCompleted: " + scatterElement.x); | |
|
28 | // console.log("Component.onCompleted: " + scatterElement.y); | |
|
29 | // console.log("Component.onCompleted: " + scatterElement.dataX); | |
|
30 | // console.log("Component.onCompleted: " + scatterElement.dataY); | |
|
31 | //console.log("Component.onCompleted: " + chartModel.get(0).x); | |
|
32 | //console.log("Component.onCompleted: " + chartModel.scatterElements); | |
|
33 | // console.log("Component.onCompleted: " + elementt.dataX); | |
|
34 | // console.log("Component.onCompleted: " + chartModel.get(0).dataX); | |
|
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 | 37 | Chart { |
|
76 | 38 | anchors.fill: parent |
|
77 | 39 | theme: Chart.ThemeIcy |
|
78 | 40 | |
|
79 |
|
|
|
80 | // labels: ["point1", "point2", "point3", "point4", "point5"] | |
|
81 |
|
|
|
82 | // } | |
|
83 | // PieSeries { | |
|
84 | // name: "raspberry pie" | |
|
85 | // seriesLabels: ["point1", "point2", "point3", "point4", "point5"] | |
|
86 | // seriesData: [2, 1.5, 3, 3, 3] | |
|
87 | // } | |
|
88 | // ScatterSeries { | |
|
89 | // name: "scatter1" | |
|
90 | // datax: [2, 1.5, 3, 3, 3] | |
|
91 | // datay: [2, 1.5, 3, 3, 3] | |
|
92 | // } | |
|
41 | ScatterSeries { | |
|
42 | id: scatterSeries | |
|
43 | data: [ | |
|
44 | ScatterElement { x: 1.1; y: 2.1 }, | |
|
45 | ScatterElement { x: 1.2; y: 2.0 }, | |
|
46 | ScatterElement { x: 1.4; y: 2.3 }, | |
|
47 | ScatterElement { x: 1.9; y: 2.5 }, | |
|
48 | ScatterElement { x: 1.9; y: 3.4 }, | |
|
49 | ScatterElement { x: 2.9; y: 1.4 }, | |
|
50 | ScatterElement { x: 2.9; y: 2.4 }, | |
|
51 | ScatterElement { x: 3.1; y: 5.3 }, | |
|
52 | ScatterElement { x: 4.1; y: 3.7 } | |
|
53 | ] | |
|
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 | 63 | // Series { |
|
94 | // labels: ["point1", "point2", "point3", "point4", "point5"] | |
|
95 | // datax: [2, 1.5, 3, 3, 3] | |
|
96 | 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 |
|
|
|
106 | // data: {[1.2], "y":2.2 } | |
|
107 | seriesType: Series.SeriesTypeScatter | |
|
108 | } | |
|
109 | Series { | |
|
110 | seriesType: Series.SeriesTypeLine | |
|
111 | } | |
|
67 | // Series { | |
|
68 | // seriesType: Series.SeriesTypeLine | |
|
69 | // } | |
|
112 | 70 | // TODO: |
|
113 | 71 |
|
|
114 | 72 | // seriesType: Series.SeriesTypeBar |
General Comments 0
You need to be logged in to leave comments.
Login now