##// END OF EJS Templates
Added bar series draft to QML API
Tero Ahola -
r723:37842f579a1d
parent child
Show More
@@ -1,6 +1,5
1 #include "declarativescatterseries.h"
1 #include "declarativescatterseries.h"
2 #include "declarativechart.h"
2 #include "declarativechart.h"
3 #include "declarativetablemodel.h"
4 #include "qchart.h"
3 #include "qchart.h"
5 #include "qscatterseries.h"
4 #include "qscatterseries.h"
6
5
@@ -9,10 +8,7 QTCOMMERCIALCHART_BEGIN_NAMESPACE
9 DeclarativeScatterSeries::DeclarativeScatterSeries(QDeclarativeItem *parent) :
8 DeclarativeScatterSeries::DeclarativeScatterSeries(QDeclarativeItem *parent) :
10 QDeclarativeItem(parent),
9 QDeclarativeItem(parent),
11 m_chart(0),
10 m_chart(0),
12 m_series(0),
11 m_series(0)
13 m_model(0),
14 m_xColumn(0),
15 m_yColumn(1)
16 {
12 {
17 setFlag(QGraphicsItem::ItemHasNoContents, false);
13 setFlag(QGraphicsItem::ItemHasNoContents, false);
18 }
14 }
@@ -32,12 +28,6 void DeclarativeScatterSeries::componentComplete()
32 Q_ASSERT(m_chart);
28 Q_ASSERT(m_chart);
33
29
34 m_series = new QScatterSeries();
30 m_series = new QScatterSeries();
35 // if (!m_model)
36 // m_model = new DeclarativeTableModel();
37 if (m_model) {
38 m_series->setModel(m_model);
39 m_series->setModelMapping(m_xColumn, m_yColumn);
40 }
41 for (int i(0); i < m_data.count(); i++) {
31 for (int i(0); i < m_data.count(); i++) {
42 DeclarativeXyPoint *element = m_data.at(i);
32 DeclarativeXyPoint *element = m_data.at(i);
43 *m_series << QPointF(element->x(), element->y());
33 *m_series << QPointF(element->x(), element->y());
@@ -68,41 +58,6 void DeclarativeScatterSeries::appendData(QDeclarativeListProperty<DeclarativeXy
68 }
58 }
69 }
59 }
70
60
71 DeclarativeTableModel *DeclarativeScatterSeries::model()
72 {
73 if (m_series)
74 return (DeclarativeTableModel *) m_series->model();
75 else
76 return m_model;
77 }
78
79 void DeclarativeScatterSeries::setModel(DeclarativeTableModel *model)
80 {
81 m_model = model;
82 if (m_chart && m_series) {
83 // Hack: remove and add the series to force an update for the chart range
84 m_chart->removeSeries(m_series);
85 m_series = new QScatterSeries();
86 m_series->setModel(m_model);
87 m_series->setModelMapping(m_xColumn, m_yColumn);
88 m_chart->addSeries(m_series);
89 }
90 }
91
92 void DeclarativeScatterSeries::setXColumn(int xColumn)
93 {
94 m_xColumn = xColumn;
95 if (m_series && m_series->model())
96 m_series->setModelMapping(m_xColumn, m_yColumn);
97 }
98
99 void DeclarativeScatterSeries::setYColumn(int yColumn)
100 {
101 m_yColumn = yColumn;
102 if (m_series && m_series->model())
103 m_series->setModelMapping(m_xColumn, m_yColumn);
104 }
105
106 #include "moc_declarativescatterseries.cpp"
61 #include "moc_declarativescatterseries.cpp"
107
62
108 QTCOMMERCIALCHART_END_NAMESPACE
63 QTCOMMERCIALCHART_END_NAMESPACE
@@ -2,7 +2,6
2 #define DECLARATIVESCATTERSERIES_H
2 #define DECLARATIVESCATTERSERIES_H
3
3
4 #include "qchartglobal.h"
4 #include "qchartglobal.h"
5 #include "declarativetablemodel.h"
6 #include "declarativexypoint.h"
5 #include "declarativexypoint.h"
7 #include <QDeclarativeItem>
6 #include <QDeclarativeItem>
8 #include <QDeclarativeParserStatus>
7 #include <QDeclarativeParserStatus>
@@ -16,10 +15,6 class DeclarativeScatterSeries : public QDeclarativeItem//, public QDeclarativeP
16 {
15 {
17 Q_OBJECT
16 Q_OBJECT
18 Q_PROPERTY(QDeclarativeListProperty<DeclarativeXyPoint> data READ data)
17 Q_PROPERTY(QDeclarativeListProperty<DeclarativeXyPoint> data READ data)
19 Q_PROPERTY(DeclarativeTableModel *model READ model WRITE setModel)
20 // Q_PROPERTY(QObject *listModel READ listModel WRITE setListModel)
21 Q_PROPERTY(int xColumn READ xColumn WRITE setXColumn)
22 Q_PROPERTY(int yColumn READ yColumn WRITE setYColumn)
23
18
24 public:
19 public:
25 explicit DeclarativeScatterSeries(QDeclarativeItem *parent = 0);
20 explicit DeclarativeScatterSeries(QDeclarativeItem *parent = 0);
@@ -30,14 +25,6 public: // from QDeclarativeParserStatus
30
25
31 public:
26 public:
32 QDeclarativeListProperty<DeclarativeXyPoint> data();
27 QDeclarativeListProperty<DeclarativeXyPoint> data();
33 DeclarativeTableModel *model();
34 void setModel(DeclarativeTableModel *model);
35 //QObject *listModel();
36 //void setListModel(QObject *model);
37 int xColumn() { return m_xColumn; }
38 void setXColumn(int xColumn);
39 int yColumn() { return m_yColumn; }
40 void setYColumn(int yColumn);
41
28
42 signals:
29 signals:
43
30
@@ -50,10 +37,7 private slots:
50 public:
37 public:
51 QChart *m_chart; // not owned
38 QChart *m_chart; // not owned
52 QScatterSeries *m_series; // not owned
39 QScatterSeries *m_series; // not owned
53 DeclarativeTableModel *m_model; // not owned
54 QList<DeclarativeXyPoint *> m_data;
40 QList<DeclarativeXyPoint *> m_data;
55 int m_xColumn;
56 int m_yColumn;
57 };
41 };
58
42
59 QTCOMMERCIALCHART_END_NAMESPACE
43 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,7 +1,6
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 "declarativetablemodel.h"
5 #include "declarativexypoint.h"
4 #include "declarativexypoint.h"
6 #include "declarativescatterseries.h"
5 #include "declarativescatterseries.h"
7 #include "declarativelineseries.h"
6 #include "declarativelineseries.h"
@@ -19,7 +18,6 public:
19 Q_ASSERT(QLatin1String(uri) == QLatin1String("QtCommercial.Chart"));
18 Q_ASSERT(QLatin1String(uri) == QLatin1String("QtCommercial.Chart"));
20
19
21 qmlRegisterType<DeclarativeChart>(uri, 1, 0, "Chart");
20 qmlRegisterType<DeclarativeChart>(uri, 1, 0, "Chart");
22 qmlRegisterType<DeclarativeTableModel>(uri, 1, 0, "ChartTableModel");
23 qmlRegisterType<DeclarativeXyPoint>(uri, 1, 0, "XyPoint");
21 qmlRegisterType<DeclarativeXyPoint>(uri, 1, 0, "XyPoint");
24 qmlRegisterType<DeclarativeScatterSeries>(uri, 1, 0, "ScatterSeries");
22 qmlRegisterType<DeclarativeScatterSeries>(uri, 1, 0, "ScatterSeries");
25 qmlRegisterType<DeclarativeLineSeries>(uri, 1, 0, "LineSeries");
23 qmlRegisterType<DeclarativeLineSeries>(uri, 1, 0, "LineSeries");
@@ -28,16 +28,14 SOURCES += \
28 declarativexypoint.cpp \
28 declarativexypoint.cpp \
29 declarativepieseries.cpp \
29 declarativepieseries.cpp \
30 declarativelineseries.cpp \
30 declarativelineseries.cpp \
31 declarativebarseries.cpp \
31 declarativebarseries.cpp
32 declarativetablemodel.cpp
33 HEADERS += \
32 HEADERS += \
34 declarativechart.h \
33 declarativechart.h \
35 declarativescatterseries.h \
34 declarativescatterseries.h \
36 declarativexypoint.h \
35 declarativexypoint.h \
37 declarativepieseries.h \
36 declarativepieseries.h \
38 declarativelineseries.h \
37 declarativelineseries.h \
39 declarativebarseries.h \
38 declarativebarseries.h
40 declarativetablemodel.h
41
39
42 TARGETPATH = QtCommercial/Chart
40 TARGETPATH = QtCommercial/Chart
43 target.path = $$[QT_INSTALL_IMPORTS]/$$TARGETPATH
41 target.path = $$[QT_INSTALL_IMPORTS]/$$TARGETPATH
@@ -20,47 +20,11 Rectangle {
20 // }
20 // }
21
21
22 Component.onCompleted: {
22 Component.onCompleted: {
23 console.log("model: " + myModel);
24 // console.log("model:" + myModel.item(0));
23 // console.log("model:" + myModel.item(0));
25 // myModel.insert(1, {"time":1.4; "speed":41.1 });
24 // myModel.insert(1, {"time":1.4; "speed":41.1 });
26 // scatter.appendData();
25 // scatter.appendData();
27 }
26 }
28
27
29 ListModel {
30 ListElement {
31 time: 0.0
32 speed: 45.2
33 }
34 }
35 ChartTableModel {
36 id: myModel
37
38 // ListElement {
39 // time: 0.0
40 // speed: 45.2
41 // }
42 // ListElement {
43 // time: 0.5
44 // speed: 48.9
45 // }
46 // ListElement {
47 // time: 1.1
48 // speed: 42.6
49 // }
50
51 // ChartTableElement {
52 // time: 0.0
53 // speed: 45.2
54 // }
55 // ChartTableElement {
56 // time: 0.5
57 // speed: 48.9
58 // }
59 // ChartTableElement {
60 // time: 1.1
61 // speed: 42.6
62 // }
63 }
64
28
65 Chart {
29 Chart {
66 id: chart1
30 id: chart1
@@ -70,13 +34,7 Rectangle {
70 height: parent.height / 2
34 height: parent.height / 2
71 theme: Chart.ThemeBlueCerulean
35 theme: Chart.ThemeBlueCerulean
72
36
73 // BarSeries {
37 BarSeries {
74 // }
75
76 ScatterSeries {
77 model: myModel
78 // xColumn: time
79 // yColumn: speed
80 }
38 }
81
39
82 // PieSeries {
40 // PieSeries {
1 NO CONTENT: file was removed
NO CONTENT: file was removed
1 NO CONTENT: file was removed
NO CONTENT: file was removed
General Comments 0
You need to be logged in to leave comments. Login now