##// END OF EJS Templates
Added bar series draft to QML API
Tero Ahola -
r723:37842f579a1d
parent child
Show More
@@ -1,108 +1,63
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
7 6 QTCOMMERCIALCHART_BEGIN_NAMESPACE
8 7
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 }
19 15
20 16 DeclarativeScatterSeries::~DeclarativeScatterSeries()
21 17 {
22 18 }
23 19
24 20 void DeclarativeScatterSeries::componentComplete()
25 21 {
26 22 Q_ASSERT(!m_series);
27 23 DeclarativeChart *declarativeChart = qobject_cast<DeclarativeChart *>(parent());
28 24
29 25 if (declarativeChart) {
30 26 m_chart = qobject_cast<QChart *>(declarativeChart->m_chart);
31 27 qDebug() << "creating scatter series for chart: " << m_chart;
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());
44 34 }
45 35 m_chart->addSeries(m_series);
46 36 }
47 37 }
48 38
49 39 QDeclarativeListProperty<DeclarativeXyPoint> DeclarativeScatterSeries::data()
50 40 {
51 41 return QDeclarativeListProperty<DeclarativeXyPoint>(this, 0,
52 42 &DeclarativeScatterSeries::appendData);
53 43 }
54 44
55 45 void DeclarativeScatterSeries::appendData(QDeclarativeListProperty<DeclarativeXyPoint> *list,
56 46 DeclarativeXyPoint *element)
57 47 {
58 48 DeclarativeScatterSeries *series = qobject_cast<DeclarativeScatterSeries *>(list->object);
59 49 qDebug() << "appendData: " << series;
60 50 qDebug() << "appendData: " << element;
61 51 qDebug() << "appendData: " << element->x();
62 52 qDebug() << "appendData: " << element->y();
63 53 qDebug() << "appendData: " << series->m_series;
64 54 if (series) {
65 55 series->m_data.append(element);
66 56 if (series->m_series)
67 57 series->m_series->add(element->x(), element->y());
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
@@ -1,61 +1,45
1 1 #ifndef DECLARATIVESCATTERSERIES_H
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>
9 8
10 9 QTCOMMERCIALCHART_BEGIN_NAMESPACE
11 10
12 11 class QChart;
13 12 class QScatterSeries;
14 13
15 14 class DeclarativeScatterSeries : public QDeclarativeItem//, public QDeclarativeParserStatus
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);
26 21 ~DeclarativeScatterSeries();
27 22
28 23 public: // from QDeclarativeParserStatus
29 24 void componentComplete();
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
44 31 public slots:
45 32 static void appendData(QDeclarativeListProperty<DeclarativeXyPoint> *list,
46 33 DeclarativeXyPoint *element);
47 34
48 35 private slots:
49 36
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
60 44
61 45 #endif // DECLARATIVESCATTERSERIES_H
@@ -1,38 +1,36
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"
8 7 #include "declarativebarseries.h"
9 8 #include "declarativepieseries.h"
10 9
11 10 QTCOMMERCIALCHART_BEGIN_NAMESPACE
12 11
13 12 class ChartQmlPlugin : public QDeclarativeExtensionPlugin
14 13 {
15 14 Q_OBJECT
16 15 public:
17 16 virtual void registerTypes(const char *uri)
18 17 {
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");
26 24 qmlRegisterType<DeclarativeBarSeries>(uri, 1, 0, "BarSeries");
27 25 qmlRegisterType<DeclarativePieSeries>(uri, 1, 0, "PieSeries");
28 26 qmlRegisterType<QPieSlice>(uri, 1, 0, "PieSlice");
29 27 }
30 28 };
31 29
32 30 #include "plugin.moc"
33 31
34 32 QTCOMMERCIALCHART_END_NAMESPACE
35 33
36 34 QTCOMMERCIALCHART_USE_NAMESPACE
37 35
38 36 Q_EXPORT_PLUGIN2(qtcommercialchartqml, QT_PREPEND_NAMESPACE(ChartQmlPlugin))
@@ -1,47 +1,45
1 1 TEMPLATE = lib
2 2 TARGET = qtcommercialchartqml
3 3 CONFIG += qt plugin
4 4 QT += declarative
5 5
6 6 !include( ../common.pri ) {
7 7 error( "Couldn't find the common.pri file!" )
8 8 }
9 9 !include( ../integrated.pri ) {
10 10 error( "Couldn't find the integrated.pri file !")
11 11 }
12 12
13 13 DESTDIR = $$CHART_BUILD_PLUGIN_DIR
14 14 contains(QT_MAJOR_VERSION, 5) {
15 15 # TODO: QtQuick2 not supported by the implementation currently
16 16 DEFINES += QTQUICK2
17 17 }
18 18
19 19 OBJECTS_DIR = $$CHART_BUILD_DIR/plugin
20 20 MOC_DIR = $$CHART_BUILD_DIR/plugin
21 21 UI_DIR = $$CHART_BUILD_DIR/plugin
22 22 RCC_DIR = $$CHART_BUILD_DIR/plugin
23 23
24 24 SOURCES += \
25 25 plugin.cpp \
26 26 declarativechart.cpp \
27 27 declarativescatterseries.cpp \
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
44 42 qmldir.files += $$PWD/qmldir
45 43 qmldir.path += $$[QT_INSTALL_IMPORTS]/$$TARGETPATH
46 44
47 45 INSTALLS += target qmldir
@@ -1,142 +1,100
1 1 import QtQuick 1.0
2 2 import QtCommercial.Chart 1.0
3 3
4 4 Rectangle {
5 5 width: parent.width
6 6 height: parent.height
7 7
8 8 // Another option for QML data api:
9 9 // ListModel {
10 10 // id: listModelForPie
11 11 // // PieDataElement
12 12 // ListElement {
13 13 // label: "Apple"
14 14 // value: 4.3
15 15 // }
16 16 // ListElement {
17 17 // label: "Blackberry"
18 18 // value: 15.1
19 19 // }
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
67 31 anchors.top: parent.top
68 32 anchors.left: parent.left
69 33 anchors.right: parent.right
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 {
83 41 // data: [
84 42 // PieSlice { label: "Volkswagen"; value: 13.5 },
85 43 // PieSlice { label: "Toyota"; value: 10.9 },
86 44 // PieSlice { label: "Ford"; value: 8.6 },
87 45 // PieSlice { label: "Skoda"; value: 8.2 },
88 46 // PieSlice { label: "Volvo"; value: 6.8 },
89 47 // PieSlice { label: "Others"; value: 52.0 }
90 48 // ]
91 49 // }
92 50 }
93 51
94 52
95 53 Chart {
96 54 id: chart2
97 55 anchors.top: chart1.bottom
98 56 anchors.bottom: parent.bottom
99 57 anchors.left: parent.left
100 58 anchors.right: parent.right
101 59 theme: Chart.ThemeScientific
102 60
103 61 LineSeries {
104 62 data: [
105 63 XyPoint { x: 0.0; y: 0.0 },
106 64 XyPoint { x: 1.1; y: 2.1 },
107 65 XyPoint { x: 2.9; y: 4.9 },
108 66 XyPoint { x: 3.2; y: 3.0 }
109 67 ]
110 68 }
111 69
112 70 // ScatterSeries {
113 71 // id: scatter
114 72 // data: [
115 73 // XyPoint { x: 1.1; y: 1.1 },
116 74 // XyPoint { x: 1.1; y: 1.2 },
117 75 // XyPoint { x: 1.17; y: 1.15 }
118 76 // ]
119 77 // }
120 78 // ScatterSeries {
121 79 // data: [
122 80 // XyPoint { x: 1.5; y: 1.5 },
123 81 // XyPoint { x: 1.5; y: 1.6 },
124 82 // XyPoint { x: 1.57; y: 1.55 }
125 83 // ]
126 84 // }
127 85 // ScatterSeries {
128 86 // data: [
129 87 // XyPoint { x: 2.0; y: 2.0 },
130 88 // XyPoint { x: 2.0; y: 2.1 },
131 89 // XyPoint { x: 2.07; y: 2.05 }
132 90 // ]
133 91 // }
134 92 // ScatterSeries {
135 93 // data: [
136 94 // XyPoint { x: 2.6; y: 2.6 },
137 95 // XyPoint { x: 2.6; y: 2.7 },
138 96 // XyPoint { x: 2.67; y: 2.65 }
139 97 // ]
140 98 // }
141 99 }
142 100 }
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