##// END OF EJS Templates
XY model mappers to QML api
Tero Ahola -
r1278:86b61f579398
parent child
Show More
@@ -28,6 +28,8 Rectangle {
28 28 title: "Scatters"
29 29 anchors.fill: parent
30 30 theme: ChartView.ChartThemeBlueCerulean
31 axisX.max: 4
32 axisY.max: 4
31 33
32 34 ScatterSeries {
33 35 id: scatter1
@@ -31,28 +31,39 Rectangle {
31 31 title: "Custom model example"
32 32 anchors.fill: parent
33 33 theme: ChartView.ChartThemeLight
34 axisX.max: 20
35 axisY.max: 20
34 36
35 37 // For dynamic data we use a custom data model derived from QAbstractiItemModel
36 38 CustomModel {
37 39 id: customModel
38 CustomModelElement { values: ["Volkswagen", 13.5, 4.4] }
39 CustomModelElement { values: ["Toyota", 10.9, 4.2] }
40 CustomModelElement { values: ["Ford", 8.6, 3.0] }
41 CustomModelElement { values: ["Skoda", 8.2, 1.9] }
42 CustomModelElement { values: ["Volvo", 6.8, 1.5] }
40 CustomModelElement { values: [index, "Manufacturer", 1, 2] }
41 CustomModelElement { values: [1, "Volkswagen", 13.5, 12.5] }
42 CustomModelElement { values: [2, "Toyota", 10.9, 9.9] }
43 CustomModelElement { values: [3, "Ford", 8.6, 7.6] }
44 CustomModelElement { values: [4, "Skoda", 8.2, 7.2] }
45 CustomModelElement { values: [5, "Volvo", 6.8, 5.8] }
43 46 }
44 47
45 48 LineSeries {
46 name: "line"
47
48 // TODO: the new mapper api
49 // VXYModelMapper {
50 // model: customModel
51 // xColumn: 0
52 // yColumn: 1
53 // }
49 name: "Volkswagen"
50 HXYModelMapper {
51 model: customModel
52 xRow: 0
53 yRow: 1
54 first: 2
55 }
54 56 }
55 57
58 LineSeries {
59 name: "Toyota"
60 HXYModelMapper {
61 model: customModel
62 xRow: 0
63 yRow: 2
64 first: 2
65 }
66 }
56 67
57 68 PieSeries {
58 69 id: pieSeries
@@ -64,15 +75,22 Rectangle {
64 75 VPieModelMapper {
65 76 series: pieSeries
66 77 model: customModel
67 labelsColumn: 0
68 valuesColumn: 1
78 labelsColumn: 1
79 valuesColumn: 2
80 first: 1
69 81 }
70 82
71 // AreaSeries {
72 // name: "area"
73 // upperSeries: LineSeries {}
74 // lowerSeries: LineSeries {}
75 // }
83 AreaSeries {
84 name: "Ford"
85 upperSeries: LineSeries {
86 HXYModelMapper {
87 model: customModel
88 xRow: 0
89 yRow: 3
90 first: 2
91 }
92 }
93 }
76 94
77 95 // BarSeries {
78 96 // model: customModel
@@ -35,7 +35,7 DeclarativeChart::DeclarativeChart(QDeclarativeItem *parent)
35 35 m_legend(LegendTop)
36 36 {
37 37 setFlag(QGraphicsItem::ItemHasNoContents, false);
38 m_chart->axisX()->setNiceNumbersEnabled(false);
38 // m_chart->axisX()->setNiceNumbersEnabled(false);
39 39 }
40 40
41 41 DeclarativeChart::~DeclarativeChart()
@@ -26,12 +26,14
26 26 #include "declarativexyseries.h"
27 27 #include <QDeclarativeParserStatus>
28 28 #include <QDeclarativeListProperty>
29 #include <QDeclarativeParserStatus>
29 30
30 31 QTCOMMERCIALCHART_BEGIN_NAMESPACE
31 32
32 class DeclarativeLineSeries : public QLineSeries, public DeclarativeXySeries
33 class DeclarativeLineSeries : public QLineSeries, public DeclarativeXySeries, public QDeclarativeParserStatus
33 34 {
34 35 Q_OBJECT
36 Q_INTERFACES(QDeclarativeParserStatus)
35 37 Q_PROPERTY(QColor color READ penColor WRITE setPenColor)
36 38 Q_PROPERTY(QDeclarativeListProperty<QObject> declarativeChildren READ declarativeChildren)
37 39 Q_CLASSINFO("DefaultProperty", "declarativeChildren")
@@ -40,6 +42,10 public:
40 42 explicit DeclarativeLineSeries(QObject *parent = 0);
41 43 QDeclarativeListProperty<QObject> declarativeChildren();
42 44
45 public: // from QDeclarativeParserStatus
46 void classBegin() { DeclarativeXySeries::classBegin(); }
47 void componentComplete() { DeclarativeXySeries::componentComplete(); }
48
43 49 public: // from QLineSeries
44 50 Q_INVOKABLE void append(qreal x, qreal y) { QLineSeries::append(x, y); }
45 51 Q_INVOKABLE void remove(qreal x, qreal y) { QLineSeries::remove(x, y); }
@@ -25,12 +25,14
25 25 #include "qscatterseries.h"
26 26 #include "declarativexyseries.h"
27 27 #include <QDeclarativeListProperty>
28 #include <QDeclarativeParserStatus>
28 29
29 30 QTCOMMERCIALCHART_BEGIN_NAMESPACE
30 31
31 class DeclarativeScatterSeries : public QScatterSeries, public DeclarativeXySeries
32 class DeclarativeScatterSeries : public QScatterSeries, public DeclarativeXySeries, public QDeclarativeParserStatus
32 33 {
33 34 Q_OBJECT
35 Q_INTERFACES(QDeclarativeParserStatus)
34 36 Q_PROPERTY(QColor color READ brushColor WRITE setBrushColor)
35 37 Q_PROPERTY(QColor borderColor READ penColor WRITE setPenColor)
36 38 Q_PROPERTY(QDeclarativeListProperty<QObject> declarativeChildren READ declarativeChildren)
@@ -42,6 +44,10 public:
42 44 QColor brushColor();
43 45 void setBrushColor(QColor color);
44 46
47 public: // from QDeclarativeParserStatus
48 void classBegin() { DeclarativeXySeries::classBegin(); }
49 void componentComplete() { DeclarativeXySeries::componentComplete(); }
50
45 51 public: // from QScatterSeries
46 52 Q_INVOKABLE void append(qreal x, qreal y) { QScatterSeries::append(x, y); }
47 53 Q_INVOKABLE void remove(qreal x, qreal y) { QScatterSeries::remove(x, y); }
@@ -26,12 +26,14
26 26 #include "declarativexyseries.h"
27 27 #include <QDeclarativeParserStatus>
28 28 #include <QDeclarativeListProperty>
29 #include <QDeclarativeParserStatus>
29 30
30 31 QTCOMMERCIALCHART_BEGIN_NAMESPACE
31 32
32 class DeclarativeSplineSeries : public QSplineSeries, public DeclarativeXySeries
33 class DeclarativeSplineSeries : public QSplineSeries, public DeclarativeXySeries, public QDeclarativeParserStatus
33 34 {
34 35 Q_OBJECT
36 Q_INTERFACES(QDeclarativeParserStatus)
35 37 Q_PROPERTY(QColor color READ penColor WRITE setPenColor)
36 38 Q_PROPERTY(QDeclarativeListProperty<QObject> declarativeChildren READ declarativeChildren)
37 39 Q_CLASSINFO("DefaultProperty", "declarativeChildren")
@@ -40,6 +42,10 public:
40 42 explicit DeclarativeSplineSeries(QObject *parent = 0);
41 43 QDeclarativeListProperty<QObject> declarativeChildren();
42 44
45 public: // from QDeclarativeParserStatus
46 void classBegin() { DeclarativeXySeries::classBegin(); }
47 void componentComplete() { DeclarativeXySeries::componentComplete(); }
48
43 49 public: // from QSplineSeries
44 50 Q_INVOKABLE void append(qreal x, qreal y) { QSplineSeries::append(x, y); }
45 51 Q_INVOKABLE void remove(qreal x, qreal y) { QSplineSeries::remove(x, y); }
@@ -22,7 +22,8
22 22 #include "declarativexyseries.h"
23 23 #include "declarativechart.h"
24 24 #include <QXYSeries>
25 #include <QXYModelMapper>
25 #include <QVXYModelMapper>
26 #include <QHXYModelMapper>
26 27 #include <QDeclarativeListProperty>
27 28
28 29 QTCOMMERCIALCHART_BEGIN_NAMESPACE
@@ -35,6 +36,29 DeclarativeXySeries::~DeclarativeXySeries()
35 36 {
36 37 }
37 38
39 void DeclarativeXySeries::classBegin()
40 {
41 }
42
43 void DeclarativeXySeries::componentComplete()
44 {
45 // All the inherited objects must be of type QXYSeries, so it is safe to cast
46 QXYSeries *series = reinterpret_cast<QXYSeries *>(this);
47 foreach(QObject *child, series->children()) {
48 if (qobject_cast<DeclarativeXyPoint *>(child)) {
49 // TODO:
50 // series->append(qobject_cast<DeclarativeXyPoint *>(child));
51 } else if(qobject_cast<QVXYModelMapper *>(child)) {
52 QVXYModelMapper *mapper = qobject_cast<QVXYModelMapper *>(child);
53 mapper->setSeries(series);
54 } else if(qobject_cast<QHXYModelMapper *>(child)) {
55 QHXYModelMapper *mapper = qobject_cast<QHXYModelMapper *>(child);
56 mapper->setSeries(series);
57 }
58 }
59 }
60
61
38 62 QColor DeclarativeXySeries::penColor()
39 63 {
40 64 // All the inherited objects must be of type QXYSeries, so it is safe to cast
@@ -37,6 +37,8 public:
37 37 ~DeclarativeXySeries();
38 38
39 39 public:
40 void classBegin();
41 void componentComplete();
40 42 QColor penColor();
41 43 void setPenColor(QColor color);
42 44 DeclarativeXyPoint *at(int index);
@@ -30,9 +30,10
30 30 #include "declarativescatterseries.h"
31 31 #include "declarativebarseries.h"
32 32 #include "declarativepieseries.h"
33 #include <QVXYModelMapper>
34 #include <QHXYModelMapper>
33 35 #include <QHPieModelMapper>
34 36 #include <QVPieModelMapper>
35 #include <QXYModelMapper>
36 37
37 38 QTCOMMERCIALCHART_BEGIN_NAMESPACE
38 39
@@ -55,6 +56,10 public:
55 56 qmlRegisterType<DeclarativePieSeries>(uri, 1, 0, "PieSeries");
56 57 qmlRegisterType<DeclarativePieSlice>(uri, 1, 0, "PieSlice");
57 58 qmlRegisterType<DeclarativeBarSet>(uri, 1, 0, "BarSet");
59 qmlRegisterType<QHXYModelMapper>(uri, 1, 0, "HXYModelMapper");
60 qmlRegisterType<QVXYModelMapper>(uri, 1, 0, "VXYModelMapper");
61 qmlRegisterType<QHPieModelMapper>(uri, 1, 0, "HPieModelMapper");
62 qmlRegisterType<QVPieModelMapper>(uri, 1, 0, "VPieModelMapper");
58 63
59 64
60 65 qmlRegisterUncreatableType<QScatterSeries>(uri, 1, 0, "QScatterSeries",
@@ -63,11 +68,10 public:
63 68 QLatin1String("Trying to create uncreatable: QPieSeries."));
64 69 qmlRegisterUncreatableType<QAbstractItemModel>(uri, 1, 0, "AbstractItemModel",
65 70 QLatin1String("Trying to create uncreatable: AbstractItemModel."));
71 qmlRegisterUncreatableType<QXYModelMapper>(uri, 1, 0, "XYModelMapper",
72 QLatin1String("Trying to create uncreatable: XYModelMapper."));
66 73 qmlRegisterUncreatableType<QPieModelMapper>(uri, 1, 0, "PieModelMapper",
67 74 QLatin1String("Trying to create uncreatable: PieModelMapper."));
68 qmlRegisterType<QHPieModelMapper>(uri, 1, 0, "HPieModelMapper");
69 qmlRegisterType<QVPieModelMapper>(uri, 1, 0, "VPieModelMapper");
70
71 75 qmlRegisterUncreatableType<QAbstractSeries>(uri, 1, 0, "AbstractSeries",
72 76 QLatin1String("Trying to create uncreatable: AbstractSeries."));
73 77 qmlRegisterUncreatableType<QAxis>(uri, 1, 0, "Axis",
@@ -233,6 +233,9 void QXYModelMapperPrivate::handlePointReplaced(int pointPos)
233 233
234 234 void QXYModelMapperPrivate::modelUpdated(QModelIndex topLeft, QModelIndex bottomRight)
235 235 {
236 if (m_model == 0 || m_series == 0)
237 return;
238
236 239 if (m_modelSignalsBlock)
237 240 return;
238 241
General Comments 0
You need to be logged in to leave comments. Login now