##// END OF EJS Templates
Added bar series draft to QML API
Tero Ahola -
r723:37842f579a1d
parent child
Show More
@@ -1,6 +1,5
1 1 #include "declarativescatterseries.h"
2 2 #include "declarativechart.h"
3 #include "declarativetablemodel.h"
4 3 #include "qchart.h"
5 4 #include "qscatterseries.h"
6 5
@@ -9,10 +8,7 QTCOMMERCIALCHART_BEGIN_NAMESPACE
9 8 DeclarativeScatterSeries::DeclarativeScatterSeries(QDeclarativeItem *parent) :
10 9 QDeclarativeItem(parent),
11 10 m_chart(0),
12 m_series(0),
13 m_model(0),
14 m_xColumn(0),
15 m_yColumn(1)
11 m_series(0)
16 12 {
17 13 setFlag(QGraphicsItem::ItemHasNoContents, false);
18 14 }
@@ -32,12 +28,6 void DeclarativeScatterSeries::componentComplete()
32 28 Q_ASSERT(m_chart);
33 29
34 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 31 for (int i(0); i < m_data.count(); i++) {
42 32 DeclarativeXyPoint *element = m_data.at(i);
43 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 61 #include "moc_declarativescatterseries.cpp"
107 62
108 63 QTCOMMERCIALCHART_END_NAMESPACE
@@ -2,7 +2,6
2 2 #define DECLARATIVESCATTERSERIES_H
3 3
4 4 #include "qchartglobal.h"
5 #include "declarativetablemodel.h"
6 5 #include "declarativexypoint.h"
7 6 #include <QDeclarativeItem>
8 7 #include <QDeclarativeParserStatus>
@@ -16,10 +15,6 class DeclarativeScatterSeries : public QDeclarativeItem//, public QDeclarativeP
16 15 {
17 16 Q_OBJECT
18 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 19 public:
25 20 explicit DeclarativeScatterSeries(QDeclarativeItem *parent = 0);
@@ -30,14 +25,6 public: // from QDeclarativeParserStatus
30 25
31 26 public:
32 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 29 signals:
43 30
@@ -50,10 +37,7 private slots:
50 37 public:
51 38 QChart *m_chart; // not owned
52 39 QScatterSeries *m_series; // not owned
53 DeclarativeTableModel *m_model; // not owned
54 40 QList<DeclarativeXyPoint *> m_data;
55 int m_xColumn;
56 int m_yColumn;
57 41 };
58 42
59 43 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,7 +1,6
1 1 #include <QtDeclarative/qdeclarativeextensionplugin.h>
2 2 #include <QtDeclarative/qdeclarative.h>
3 3 #include "declarativechart.h"
4 #include "declarativetablemodel.h"
5 4 #include "declarativexypoint.h"
6 5 #include "declarativescatterseries.h"
7 6 #include "declarativelineseries.h"
@@ -19,7 +18,6 public:
19 18 Q_ASSERT(QLatin1String(uri) == QLatin1String("QtCommercial.Chart"));
20 19
21 20 qmlRegisterType<DeclarativeChart>(uri, 1, 0, "Chart");
22 qmlRegisterType<DeclarativeTableModel>(uri, 1, 0, "ChartTableModel");
23 21 qmlRegisterType<DeclarativeXyPoint>(uri, 1, 0, "XyPoint");
24 22 qmlRegisterType<DeclarativeScatterSeries>(uri, 1, 0, "ScatterSeries");
25 23 qmlRegisterType<DeclarativeLineSeries>(uri, 1, 0, "LineSeries");
@@ -28,16 +28,14 SOURCES += \
28 28 declarativexypoint.cpp \
29 29 declarativepieseries.cpp \
30 30 declarativelineseries.cpp \
31 declarativebarseries.cpp \
32 declarativetablemodel.cpp
31 declarativebarseries.cpp
33 32 HEADERS += \
34 33 declarativechart.h \
35 34 declarativescatterseries.h \
36 35 declarativexypoint.h \
37 36 declarativepieseries.h \
38 37 declarativelineseries.h \
39 declarativebarseries.h \
40 declarativetablemodel.h
38 declarativebarseries.h
41 39
42 40 TARGETPATH = QtCommercial/Chart
43 41 target.path = $$[QT_INSTALL_IMPORTS]/$$TARGETPATH
@@ -20,47 +20,11 Rectangle {
20 20 // }
21 21
22 22 Component.onCompleted: {
23 console.log("model: " + myModel);
24 23 // console.log("model:" + myModel.item(0));
25 24 // myModel.insert(1, {"time":1.4; "speed":41.1 });
26 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 29 Chart {
66 30 id: chart1
@@ -70,13 +34,7 Rectangle {
70 34 height: parent.height / 2
71 35 theme: Chart.ThemeBlueCerulean
72 36
73 // BarSeries {
74 // }
75
76 ScatterSeries {
77 model: myModel
78 // xColumn: time
79 // yColumn: speed
37 BarSeries {
80 38 }
81 39
82 40 // PieSeries {
1 NO CONTENT: file was removed
1 NO CONTENT: file was removed
General Comments 0
You need to be logged in to leave comments. Login now