From 8e53b4913946801f5ba51807feda21778f264bf0 Mon Sep 17 00:00:00 2001 From: Paolo Angelelli Date: Thu, 26 Dec 2019 21:24:29 +0100 Subject: Add parent property to QParametrizableObject Also emitting signals when the parent is changed internally (e.g., in a MapObjectView). Not revisioning it since it is used both in QtLocation and in Qt.labs.location, and setting it to 15 would break the property in map objects. Change-Id: Ib11b18b7fcc507b5a11481f84f2bf0bd8c9f558e Reviewed-by: Alex Blasche --- .../declarativemaps/qparameterizableobject.cpp | 41 +++++++++++++++++++--- .../declarativemaps/qparameterizableobject_p.h | 4 +++ 2 files changed, 41 insertions(+), 4 deletions(-) diff --git a/src/location/declarativemaps/qparameterizableobject.cpp b/src/location/declarativemaps/qparameterizableobject.cpp index 0e138b86..26d9a11e 100644 --- a/src/location/declarativemaps/qparameterizableobject.cpp +++ b/src/location/declarativemaps/qparameterizableobject.cpp @@ -37,13 +37,10 @@ #include "qparameterizableobject_p.h" #include "qdeclarativegeomapparameter_p.h" #include +#include QT_BEGIN_NAMESPACE -QParameterizableObject::QParameterizableObject(QObject *parent) - : QObject(parent) -{} - void QParameterizableObject::appendChild(QObject *v) { m_children.append(v); @@ -85,4 +82,40 @@ void QParameterizableObject::clear(QQmlListProperty *p) object->clearChildren(); } +class QParameterizableObjectData: public QAbstractDeclarativeData +{ +public: + QParameterizableObjectData() + { + init(); + } + + static inline void init() { + static bool initialized = false; + if (!initialized) { + initialized = true; + QAbstractDeclarativeData::parentChanged = parentChanged; + } + } + + static void parentChanged(QAbstractDeclarativeData *d, QObject *o, QObject *p); +}; + +Q_GLOBAL_STATIC(QParameterizableObjectData, parametrizableObjectData) + +QParameterizableObject::QParameterizableObject(QObject *parent) + : QObject(parent) +{ + QObjectPrivate::get(this)->declarativeData = parametrizableObjectData; +} + +void QParameterizableObjectData::parentChanged(QAbstractDeclarativeData *d, QObject *o, QObject *p) +{ + Q_UNUSED(p) + Q_UNUSED(d) + QParameterizableObject *po = qobject_cast(o); + if (po) + po->parentChanged(); +} + QT_END_NAMESPACE diff --git a/src/location/declarativemaps/qparameterizableobject_p.h b/src/location/declarativemaps/qparameterizableobject_p.h index e450c6ec..cf393aee 100644 --- a/src/location/declarativemaps/qparameterizableobject_p.h +++ b/src/location/declarativemaps/qparameterizableobject_p.h @@ -58,6 +58,7 @@ class QGeoMapParameter; class Q_LOCATION_PRIVATE_EXPORT QParameterizableObject : public QObject { Q_OBJECT + Q_PROPERTY(QObject *parent READ parent NOTIFY parentChanged DESIGNABLE false FINAL) Q_PROPERTY(QQmlListProperty quickChildren READ declarativeChildren DESIGNABLE false) Q_CLASSINFO("DefaultProperty", "quickChildren") @@ -76,6 +77,9 @@ public: return res; } +Q_SIGNALS: + void parentChanged(); + protected: virtual void appendChild(QObject *v); virtual void clearChildren(); -- cgit v1.2.1