diff options
author | Laszlo Agocs <laszlo.agocs@qt.io> | 2017-06-06 15:51:14 +0200 |
---|---|---|
committer | Laszlo Agocs <laszlo.agocs@qt.io> | 2017-06-08 13:59:50 +0000 |
commit | 123f698c5bbf23ad816bf2274620ab4f0a82ed2f (patch) | |
tree | 12bbb64f44a4110ab1f2d5124245fefdc845d509 /src | |
parent | f4f89858cffa1107af5139dfb1e1d7b16ca3a1a0 (diff) |
Allow freely mixing non-ShapePath objects in Shape
The own list property must be kept. However, we can reuse
QQuickItemPrivate's data accessors in order to start supporting
code like:
Shape {
..
ShapePath { ... }
ShapePath { ... }
Rectangle { ... }
Image { ... }
// any other visual type
// or non-visual:
Timer { ... }
}
Change-Id: I6d502d697cae37bf16857770273a749cee1b3aa3
Reviewed-by: J-P Nurmi <jpnurmi@qt.io>
Diffstat (limited to 'src')
-rw-r--r-- | src/imports/shapes/qquickshape.cpp | 52 | ||||
-rw-r--r-- | src/imports/shapes/qquickshape_p.h | 6 |
2 files changed, 29 insertions, 29 deletions
diff --git a/src/imports/shapes/qquickshape.cpp b/src/imports/shapes/qquickshape.cpp index 3c253eabd4..0d060242b4 100644 --- a/src/imports/shapes/qquickshape.cpp +++ b/src/imports/shapes/qquickshape.cpp @@ -588,6 +588,11 @@ void QQuickShapePath::resetFillGradient() \image pathitem-code-example.png + Like \l Item, Shape also allows any visual or non-visual objects to be + declared as children. ShapePath objects are handled specially. This is + useful since it allows adding visual items, like \l Rectangle or \l Image, + and non-visual objects, like \l Timer directly as children of Shape. + \note It is important to be aware of performance implications, in particular when the application is running on the generic Shape implementation due to not having support for accelerated path rendering. The geometry generation @@ -788,31 +793,23 @@ QQuickShape::Status QQuickShape::status() const return d->status; } -static QQuickShapePath *vpe_at(QQmlListProperty<QQuickShapePath> *property, int index) -{ - QQuickShapePrivate *d = QQuickShapePrivate::get(static_cast<QQuickShape *>(property->object)); - return d->qmlData.sp.at(index); -} - -static void vpe_append(QQmlListProperty<QQuickShapePath> *property, QQuickShapePath *obj) +static void vpe_append(QQmlListProperty<QObject> *property, QObject *obj) { QQuickShape *item = static_cast<QQuickShape *>(property->object); QQuickShapePrivate *d = QQuickShapePrivate::get(item); - d->qmlData.sp.append(obj); + QQuickShapePath *path = qobject_cast<QQuickShapePath *>(obj); + if (path) + d->qmlData.sp.append(path); + + QQuickItemPrivate::data_append(property, obj); - if (d->componentComplete) { - QObject::connect(obj, SIGNAL(shapePathChanged()), item, SLOT(_q_shapePathChanged())); + if (path && d->componentComplete) { + QObject::connect(path, SIGNAL(shapePathChanged()), item, SLOT(_q_shapePathChanged())); d->_q_shapePathChanged(); } } -static int vpe_count(QQmlListProperty<QQuickShapePath> *property) -{ - QQuickShapePrivate *d = QQuickShapePrivate::get(static_cast<QQuickShape *>(property->object)); - return d->qmlData.sp.count(); -} - -static void vpe_clear(QQmlListProperty<QQuickShapePath> *property) +static void vpe_clear(QQmlListProperty<QObject> *property) { QQuickShape *item = static_cast<QQuickShape *>(property->object); QQuickShapePrivate *d = QQuickShapePrivate::get(item); @@ -822,27 +819,30 @@ static void vpe_clear(QQmlListProperty<QQuickShapePath> *property) d->qmlData.sp.clear(); + QQuickItemPrivate::data_clear(property); + if (d->componentComplete) d->_q_shapePathChanged(); } /*! - \qmlproperty list<ShapePath> QtQuick.Shapes::Shape::elements + \qmlproperty list<Object> QtQuick.Shapes::Shape::data This property holds the ShapePath objects that define the contents of the - Shape. + Shape. It can also contain any other type of objects, since Shape, like Item, + allows adding any visual or non-visual objects as children. \default */ -QQmlListProperty<QQuickShapePath> QQuickShape::elements() +QQmlListProperty<QObject> QQuickShape::data() { - return QQmlListProperty<QQuickShapePath>(this, - nullptr, - vpe_append, - vpe_count, - vpe_at, - vpe_clear); + return QQmlListProperty<QObject>(this, + nullptr, + vpe_append, + QQuickItemPrivate::data_count, + QQuickItemPrivate::data_at, + vpe_clear); } void QQuickShape::classBegin() diff --git a/src/imports/shapes/qquickshape_p.h b/src/imports/shapes/qquickshape_p.h index 50b242e492..c5096be229 100644 --- a/src/imports/shapes/qquickshape_p.h +++ b/src/imports/shapes/qquickshape_p.h @@ -227,8 +227,8 @@ class QQuickShape : public QQuickItem Q_PROPERTY(bool asynchronous READ asynchronous WRITE setAsynchronous NOTIFY asynchronousChanged) Q_PROPERTY(bool enableVendorExtensions READ enableVendorExtensions WRITE setEnableVendorExtensions NOTIFY enableVendorExtensionsChanged) Q_PROPERTY(Status status READ status NOTIFY statusChanged) - Q_PROPERTY(QQmlListProperty<QQuickShapePath> elements READ elements) - Q_CLASSINFO("DefaultProperty", "elements") + Q_PROPERTY(QQmlListProperty<QObject> data READ data) + Q_CLASSINFO("DefaultProperty", "data") public: enum RendererType { @@ -259,7 +259,7 @@ public: Status status() const; - QQmlListProperty<QQuickShapePath> elements(); + QQmlListProperty<QObject> data(); protected: QSGNode *updatePaintNode(QSGNode *node, UpdatePaintNodeData *) override; |