diff options
Diffstat (limited to 'src/location/labs/qgeotiledmaplabs.cpp')
-rw-r--r-- | src/location/labs/qgeotiledmaplabs.cpp | 150 |
1 files changed, 13 insertions, 137 deletions
diff --git a/src/location/labs/qgeotiledmaplabs.cpp b/src/location/labs/qgeotiledmaplabs.cpp index 2e4b2c16..22d582c0 100644 --- a/src/location/labs/qgeotiledmaplabs.cpp +++ b/src/location/labs/qgeotiledmaplabs.cpp @@ -42,26 +42,20 @@ #include <QtLocation/private/qmapcircleobjectqsg_p_p.h> #include <QtLocation/private/qmaprouteobjectqsg_p_p.h> #include <QtLocation/private/qmapiconobjectqsg_p_p.h> +#include <QtLocation/private/qdeclarativepolylinemapitem_p.h> +#include <QtLocation/private/qgeomapobjectqsgsupport_p.h> QT_BEGIN_NAMESPACE -struct MapObject { - MapObject(QPointer<QGeoMapObject> &o, QQSGMapObject *sgo) - : object(o), sgObject(sgo) {} - QPointer<QGeoMapObject> object; - QQSGMapObject *sgObject = nullptr; -}; - class QGeoTiledMapLabsPrivate : public QGeoTiledMapPrivate { Q_DECLARE_PUBLIC(QGeoTiledMapLabs) public: - QGeoTiledMapLabsPrivate(QGeoTiledMappingManagerEngine *engine); + QGeoTiledMapLabsPrivate(QGeoTiledMappingManagerEngine *engine, QGeoTiledMapLabs *map); virtual ~QGeoTiledMapLabsPrivate(); QGeoMapObjectPrivate *createMapObjectImplementation(QGeoMapObject *obj) override; virtual QList<QGeoMapObject *> mapObjects() const override; - static int findMapObject(QGeoMapObject *o, const QList<MapObject> &list); void removeMapObject(QGeoMapObject *obj); void updateMapObjects(QSGNode *root, QQuickWindow *window); @@ -72,14 +66,13 @@ protected: void changeCameraData(const QGeoCameraData &oldCameraData) override; void changeActiveMapType(const QGeoMapType mapType) override; - QList<MapObject> m_mapObjects; - QList<MapObject> m_pendingMapObjects; + QGeoMapObjectQSGSupport m_qsgSupport; }; -QGeoTiledMapLabsPrivate::QGeoTiledMapLabsPrivate(QGeoTiledMappingManagerEngine *engine) +QGeoTiledMapLabsPrivate::QGeoTiledMapLabsPrivate(QGeoTiledMappingManagerEngine *engine, QGeoTiledMapLabs *map) : QGeoTiledMapPrivate(engine) { - + m_qsgSupport.m_map = map; } QGeoTiledMapLabsPrivate::~QGeoTiledMapLabsPrivate() @@ -89,136 +82,27 @@ QGeoTiledMapLabsPrivate::~QGeoTiledMapLabsPrivate() QGeoMapObjectPrivate *QGeoTiledMapLabsPrivate::createMapObjectImplementation(QGeoMapObject *obj) { - switch (obj->type()) { - case QGeoMapObject::PolylineType: { - QMapPolylineObjectPrivate &oldImpl = static_cast<QMapPolylineObjectPrivate &>(*obj->implementation()); - QMapPolylineObjectPrivateQSG *pimpl = - new QMapPolylineObjectPrivateQSG(oldImpl); - QPointer<QGeoMapObject> p(obj); - MapObject mo(p, pimpl); - m_pendingMapObjects << mo; - return pimpl; - } - case QGeoMapObject::PolygonType: { - QMapPolygonObjectPrivate &oldImpl = static_cast<QMapPolygonObjectPrivate &>(*obj->implementation()); - QMapPolygonObjectPrivateQSG *pimpl = - new QMapPolygonObjectPrivateQSG(oldImpl); - QPointer<QGeoMapObject> p(obj); - MapObject mo(p, pimpl); - m_pendingMapObjects << mo; - return pimpl; - } - case QGeoMapObject::CircleType: { - QMapCircleObjectPrivate &oldImpl = static_cast<QMapCircleObjectPrivate &>(*obj->implementation()); - QMapCircleObjectPrivateQSG *pimpl = - new QMapCircleObjectPrivateQSG(oldImpl); - QPointer<QGeoMapObject> p(obj); - MapObject mo(p, pimpl); - m_pendingMapObjects << mo; - return pimpl; - } - case QGeoMapObject::RouteType: { - QMapRouteObjectPrivate &oldImpl = static_cast<QMapRouteObjectPrivate &>(*obj->implementation()); - QMapRouteObjectPrivateQSG *pimpl = - new QMapRouteObjectPrivateQSG(oldImpl); - QPointer<QGeoMapObject> p(obj); - MapObject mo(p, pimpl); - m_pendingMapObjects << mo; - return pimpl; - } - case QGeoMapObject::IconType: { - QMapIconObjectPrivate &oldImpl = static_cast<QMapIconObjectPrivate &>(*obj->implementation()); - QMapIconObjectPrivateQSG *pimpl = - new QMapIconObjectPrivateQSG(oldImpl); - QPointer<QGeoMapObject> p(obj); - MapObject mo(p, pimpl); - m_pendingMapObjects << mo; - return pimpl; - } - default: - qWarning() << "Unsupported object type: " << obj->type(); - break; - } - return nullptr; + return m_qsgSupport.createMapObjectImplementationPrivate(obj); } QList<QGeoMapObject *> QGeoTiledMapLabsPrivate::mapObjects() const { - return QList<QGeoMapObject *>(); -} - -int QGeoTiledMapLabsPrivate::findMapObject(QGeoMapObject *o, const QList<MapObject> &list) -{ - for (int i = 0; i < list.size(); ++i) - { - if (list.at(i).object.data() == o) - return i; - } - return -1; + return m_qsgSupport.mapObjects(); } void QGeoTiledMapLabsPrivate::removeMapObject(QGeoMapObject *obj) { - int idx = findMapObject(obj, m_mapObjects); - if (idx >= 0) { - m_mapObjects.removeAt(idx); - } else { - idx = findMapObject(obj, m_pendingMapObjects); - if (idx >= 0) { - m_pendingMapObjects.removeAt(idx); - } else { - // obj not here. - } - } + m_qsgSupport.removeMapObject(obj); } void QGeoTiledMapLabsPrivate::updateMapObjects(QSGNode *root, QQuickWindow *window) { - for (int i = 0; i < m_mapObjects.size(); ++i) { - // already added as node - if (!m_mapObjects.at(i).object) { - qWarning() << "m_mapObjects at "<<i<< " NULLed!!"; - continue; - } - - QQSGMapObject *sgo = m_mapObjects.at(i).sgObject; - QSGNode *oldNode = sgo->node; - sgo->node = sgo->updateMapObjectNode(oldNode, root, window); - } - - QList<int> toRemove; - for (int i = 0; i < m_pendingMapObjects.size(); ++i) { - // already added as node - QQSGMapObject *sgo = m_pendingMapObjects.at(i).sgObject; - QSGNode *oldNode = sgo->node; - sgo->updateGeometry(); // or subtree will be blocked - sgo->node = sgo->updateMapObjectNode(oldNode, root, window); - if (sgo->node) { - m_mapObjects << m_pendingMapObjects.at(i); - toRemove.push_front(i); - } else { - // leave it to be processed - } - } - - for (int i: qAsConst(toRemove)) - m_pendingMapObjects.removeAt(i); + m_qsgSupport.updateMapObjects(root, window); } void QGeoTiledMapLabsPrivate::updateObjectsGeometry() { - Q_Q(QGeoTiledMapLabs); - for (int i = 0; i < m_mapObjects.size(); ++i) { - // already added as node - if (!m_mapObjects.at(i).object) { - qWarning() << "m_mapObjects at "<<i<< " NULLed!!"; - continue; - } - - QQSGMapObject *sgo = m_mapObjects.at(i).sgObject; - sgo->updateGeometry(); - } - emit q->sgNodeChanged(); + m_qsgSupport.updateObjectsGeometry(); } void QGeoTiledMapLabsPrivate::changeViewportSize(const QSize &size) @@ -247,7 +131,7 @@ void QGeoTiledMapLabsPrivate::changeActiveMapType(const QGeoMapType mapType) QGeoTiledMapLabs::QGeoTiledMapLabs(QGeoTiledMappingManagerEngine *engine, QObject *parent) - : QGeoTiledMap(*new QGeoTiledMapLabsPrivate(engine), engine, parent) + : QGeoTiledMap(*new QGeoTiledMapLabsPrivate(engine, this), engine, parent) { } @@ -260,15 +144,7 @@ QGeoTiledMapLabs::~QGeoTiledMapLabs() bool QGeoTiledMapLabs::createMapObjectImplementation(QGeoMapObject *obj) { Q_D(QGeoTiledMapLabs); - QExplicitlySharedDataPointer<QGeoMapObjectPrivate> pimpl = - QExplicitlySharedDataPointer<QGeoMapObjectPrivate>(d->createMapObjectImplementation(obj)); - if (pimpl.constData()) { - bool res = obj->setImplementation(pimpl); - if (res) - emit sgNodeChanged(); - return res; - } - return false; + return d->m_qsgSupport.createMapObjectImplementation(obj, d); } QSGNode *QGeoTiledMapLabs::updateSceneGraph(QSGNode *node, QQuickWindow *window) |