summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaolo Angelelli <paolo.angelelli.qt@gmail.com>2019-12-26 21:24:29 +0100
committerpaolo <paolo.angelelli.qt@gmail.com>2020-01-18 14:38:50 +0100
commit8e53b4913946801f5ba51807feda21778f264bf0 (patch)
treebc0dd78486cd79b38c6be29b43a391ee8747d2fb
parent1bba966b8df1cc1d39276833ff4533f967df247e (diff)
downloadqtlocation-8e53b4913946801f5ba51807feda21778f264bf0.tar.gz
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 <alexander.blasche@qt.io>
-rw-r--r--src/location/declarativemaps/qparameterizableobject.cpp41
-rw-r--r--src/location/declarativemaps/qparameterizableobject_p.h4
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 <QtLocation/private/qgeomapparameter_p.h>
+#include <private/qobject_p.h>
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<QObject> *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<QParameterizableObject *>(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<QObject> 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();