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