summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaolo Angelelli <paolo.angelelli@qt.io>2018-01-12 18:21:20 +0100
committerPaolo Angelelli <paolo.angelelli@qt.io>2018-01-24 12:45:12 +0000
commiteb8a6480201e6594ef07affda616892ea1824c24 (patch)
tree738139f95935579bf03176c36576ee40a60faff6
parent2ad79b69958f38d4ad6b0965d9563c5ab794ecfa (diff)
downloadqtlocation-eb8a6480201e6594ef07affda616892ea1824c24.tar.gz
Extend QParameterizableObject to accept any QObject as quick child
In this way, not only map parameters can be nested, but also QGeoMapObjects themselves, allowing to avoid one long standing limitation present in map items, where nested items have never been supported. Change-Id: I90ec7a6aeb1d91a38182258b422b8c60bcc9616e Reviewed-by: Eskil Abrahamsen Blomfeldt <eskil.abrahamsen-blomfeldt@qt.io>
-rw-r--r--src/location/declarativemaps/qparameterizableobject.cpp42
-rw-r--r--src/location/declarativemaps/qparameterizableobject_p.h33
2 files changed, 46 insertions, 29 deletions
diff --git a/src/location/declarativemaps/qparameterizableobject.cpp b/src/location/declarativemaps/qparameterizableobject.cpp
index a95f290e..0e138b86 100644
--- a/src/location/declarativemaps/qparameterizableobject.cpp
+++ b/src/location/declarativemaps/qparameterizableobject.cpp
@@ -44,41 +44,45 @@ QParameterizableObject::QParameterizableObject(QObject *parent)
: QObject(parent)
{}
-QQmlListProperty<QDeclarativeGeoMapParameter> QParameterizableObject::declarativeParameters()
+void QParameterizableObject::appendChild(QObject *v)
{
- return QQmlListProperty<QDeclarativeGeoMapParameter>(this, nullptr,
- &QParameterizableObject::append,
- &QParameterizableObject::count,
- &QParameterizableObject::at,
- &QParameterizableObject::clear);
+ m_children.append(v);
}
-QList<QGeoMapParameter*> QParameterizableObject::parameters() const
+void QParameterizableObject::clearChildren()
{
- QList<QGeoMapParameter*> params;
- for (auto param : qAsConst(m_parameters))
- params << param;
- return params;
+ m_children.clear();
}
-void QParameterizableObject::append(QQmlListProperty<QDeclarativeGeoMapParameter> *p, QDeclarativeGeoMapParameter *v)
+QQmlListProperty<QObject> QParameterizableObject::declarativeChildren()
{
- static_cast<QParameterizableObject*>(p->object)->m_parameters.append(v);
+ return QQmlListProperty<QObject>(this, nullptr,
+ &QParameterizableObject::append,
+ &QParameterizableObject::count,
+ &QParameterizableObject::at,
+ &QParameterizableObject::clear);
}
-int QParameterizableObject::count(QQmlListProperty<QDeclarativeGeoMapParameter> *p)
+void QParameterizableObject::append(QQmlListProperty<QObject> *p, QObject *v)
{
- return static_cast<QParameterizableObject*>(p->object)->m_parameters.count();
+ QParameterizableObject *object = static_cast<QParameterizableObject*>(p->object);
+ object->appendChild(v);
}
-QDeclarativeGeoMapParameter *QParameterizableObject::at(QQmlListProperty<QDeclarativeGeoMapParameter> *p, int idx)
+int QParameterizableObject::count(QQmlListProperty<QObject> *p)
{
- return static_cast<QParameterizableObject*>(p->object)->m_parameters.at(idx);
+ return static_cast<QParameterizableObject*>(p->object)->m_children.count();
}
-void QParameterizableObject::clear(QQmlListProperty<QDeclarativeGeoMapParameter> *p)
+QObject *QParameterizableObject::at(QQmlListProperty<QObject> *p, int idx)
{
- static_cast<QParameterizableObject*>(p->object)->m_parameters.clear();
+ return static_cast<QParameterizableObject*>(p->object)->m_children.at(idx);
+}
+
+void QParameterizableObject::clear(QQmlListProperty<QObject> *p)
+{
+ QParameterizableObject *object = static_cast<QParameterizableObject*>(p->object);
+ object->clearChildren();
}
QT_END_NAMESPACE
diff --git a/src/location/declarativemaps/qparameterizableobject_p.h b/src/location/declarativemaps/qparameterizableobject_p.h
index c6118c93..e450c6ec 100644
--- a/src/location/declarativemaps/qparameterizableobject_p.h
+++ b/src/location/declarativemaps/qparameterizableobject_p.h
@@ -54,26 +54,39 @@
#include <QQmlParserStatus>
QT_BEGIN_NAMESPACE
-class QDeclarativeGeoMapParameter;
class QGeoMapParameter;
class Q_LOCATION_PRIVATE_EXPORT QParameterizableObject : public QObject
{
Q_OBJECT
- Q_PROPERTY(QQmlListProperty<QDeclarativeGeoMapParameter> parameters READ declarativeParameters DESIGNABLE false)
- Q_CLASSINFO("DefaultProperty", "parameters")
+ Q_PROPERTY(QQmlListProperty<QObject> quickChildren READ declarativeChildren DESIGNABLE false)
+ Q_CLASSINFO("DefaultProperty", "quickChildren")
public:
explicit QParameterizableObject(QObject *parent = nullptr);
- QList<QGeoMapParameter *> parameters() const;
+
+ template <typename T = QObject>
+ QList<T*> quickChildren() const
+ {
+ QList<T*> res;
+ for (auto kid : qAsConst(m_children)) {
+ auto val = qobject_cast<T*>(kid);
+ if (val)
+ res.push_back(val);
+ }
+ return res;
+ }
protected:
- static void append(QQmlListProperty<QDeclarativeGeoMapParameter> *p, QDeclarativeGeoMapParameter *v);
- static int count(QQmlListProperty<QDeclarativeGeoMapParameter> *p);
- static QDeclarativeGeoMapParameter *at(QQmlListProperty<QDeclarativeGeoMapParameter> *p, int idx);
- static void clear(QQmlListProperty<QDeclarativeGeoMapParameter> *p);
+ virtual void appendChild(QObject *v);
+ virtual void clearChildren();
+
+ static void append(QQmlListProperty<QObject> *p, QObject *v);
+ static int count(QQmlListProperty<QObject> *p);
+ static QObject *at(QQmlListProperty<QObject> *p, int idx);
+ static void clear(QQmlListProperty<QObject> *p);
- QQmlListProperty<QDeclarativeGeoMapParameter> declarativeParameters();
- QList<QDeclarativeGeoMapParameter*> m_parameters;
+ QQmlListProperty<QObject> declarativeChildren();
+ QList<QObject*> m_children;
};
QT_END_NAMESPACE