aboutsummaryrefslogtreecommitdiffstats
path: root/src/imports/shapes/qquickshape.cpp
diff options
context:
space:
mode:
authorLaszlo Agocs <laszlo.agocs@qt.io>2017-06-06 15:51:14 +0200
committerLaszlo Agocs <laszlo.agocs@qt.io>2017-06-08 13:59:50 +0000
commit123f698c5bbf23ad816bf2274620ab4f0a82ed2f (patch)
tree12bbb64f44a4110ab1f2d5124245fefdc845d509 /src/imports/shapes/qquickshape.cpp
parentf4f89858cffa1107af5139dfb1e1d7b16ca3a1a0 (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/imports/shapes/qquickshape.cpp')
-rw-r--r--src/imports/shapes/qquickshape.cpp52
1 files changed, 26 insertions, 26 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()