diff options
author | Paolo Angelelli <paolo.angelelli@qt.io> | 2018-12-08 18:45:36 +0100 |
---|---|---|
committer | Paolo Angelelli <paolo.angelelli@qt.io> | 2019-02-01 14:09:48 +0000 |
commit | 587b8812c9b2fc7ed7ad4ab35d27114ee98eafc6 (patch) | |
tree | 4589a6518d38b504a6941524a959d871cbf2537c | |
parent | 8e923d801b460ccc6fdc92d4a7bc8750410ad042 (diff) | |
download | qtlocation-587b8812c9b2fc7ed7ad4ab35d27114ee98eafc6.tar.gz |
Introduce QGeoMapObject::geoShape property
In this way MapObjects become a little closer to MapItems,
and this property can be used to, for example, center the map
on one specific object or object group.
Fixes: QTBUG-69640
Change-Id: I4dbead9e670bf5d1eeaccb2bd09d956b8de7da87
Reviewed-by: Eskil Abrahamsen Blomfeldt <eskil.abrahamsen-blomfeldt@qt.io>
23 files changed, 243 insertions, 93 deletions
diff --git a/src/location/declarativemaps/qgeomapobject.cpp b/src/location/declarativemaps/qgeomapobject.cpp index 9a2e37bd..00faac9b 100644 --- a/src/location/declarativemaps/qgeomapobject.cpp +++ b/src/location/declarativemaps/qgeomapobject.cpp @@ -220,6 +220,16 @@ QGeoMap *QGeoMapObject::map() const return d_ptr->m_map; } +QGeoShape QGeoMapObject::geoShape() const +{ + return d_ptr->geoShape(); +} + +void QGeoMapObject::setGeoShape(const QGeoShape &shape) +{ + d_ptr->setGeoShape(shape); +} + // // QGeoMapObjectPrivate diff --git a/src/location/declarativemaps/qgeomapobject_p.h b/src/location/declarativemaps/qgeomapobject_p.h index e6618804..bc63e0a6 100644 --- a/src/location/declarativemaps/qgeomapobject_p.h +++ b/src/location/declarativemaps/qgeomapobject_p.h @@ -50,6 +50,7 @@ #include <QtLocation/private/qparameterizableobject_p.h> #include <QExplicitlySharedDataPointer> +#include <QtPositioning/qgeoshape.h> QT_BEGIN_NAMESPACE @@ -62,6 +63,7 @@ class Q_LOCATION_PRIVATE_EXPORT QGeoMapObject : public QParameterizableObject, p Q_PROPERTY(bool visible READ visible WRITE setVisible NOTIFY visibleChanged) Q_PROPERTY(Type type READ type CONSTANT) + Q_PROPERTY(QGeoShape geoShape READ geoShape WRITE setGeoShape STORED false) // non-NOTIFYable Q_INTERFACES(QQmlParserStatus) public: @@ -107,6 +109,9 @@ public: virtual void setMap(QGeoMap *map); QGeoMap *map() const; + QGeoShape geoShape() const; + void setGeoShape(const QGeoShape &shape); + Q_SIGNALS: void visibleChanged(); void selected(); diff --git a/src/location/declarativemaps/qgeomapobject_p_p.h b/src/location/declarativemaps/qgeomapobject_p_p.h index 242a93ce..a2083bbd 100644 --- a/src/location/declarativemaps/qgeomapobject_p_p.h +++ b/src/location/declarativemaps/qgeomapobject_p_p.h @@ -75,6 +75,8 @@ public: virtual void setParentVisibility(bool visible); virtual void setMap(QGeoMap *map); virtual QGeoMapObjectPrivate *clone() = 0; // to allow proper detaching + virtual QGeoShape geoShape() const = 0; + virtual void setGeoShape(const QGeoShape &shape) = 0; QGeoMapObject *q = nullptr; QPointer<QGeoMap> m_map; diff --git a/src/location/labs/qmapcircleobject.cpp b/src/location/labs/qmapcircleobject.cpp index d7f1d58f..5f0db29d 100644 --- a/src/location/labs/qmapcircleobject.cpp +++ b/src/location/labs/qmapcircleobject.cpp @@ -37,6 +37,7 @@ #include "qmapcircleobject_p.h" #include "qmapcircleobject_p_p.h" #include <QExplicitlySharedDataPointer> +#include <QtPositioning/qgeocircle.h> QT_BEGIN_NAMESPACE @@ -68,7 +69,30 @@ QGeoMapObject::Type QMapCircleObjectPrivate::type() const return QGeoMapObject::CircleType; } +QGeoShape QMapCircleObjectPrivate::geoShape() const +{ + return QGeoCircle(center(), radius()); +} + +void QMapCircleObjectPrivate::setGeoShape(const QGeoShape &shape) +{ + if (shape == geoShape()) + return; + const QGeoCircle circle(shape); // if shape isn't a circle, circle will be created as a default-constructed circle + const bool centerHasChanged = circle.center() != center(); + const bool radiusHasChanged = circle.radius() != radius(); + + if (centerHasChanged) + setCenter(circle.center()); // to handle overrides + if (radiusHasChanged) + setRadius(circle.radius()); // to handle overrides + + if (centerHasChanged) + emit static_cast<QMapCircleObject *>(q)->centerChanged(); + if (radiusHasChanged) + emit static_cast<QMapCircleObject *>(q)->radiusChanged(); +} // // QMapCircleObjectPrivate default implementation @@ -162,8 +186,6 @@ QGeoMapObjectPrivate *QMapCircleObjectPrivateDefault::clone() return new QMapCircleObjectPrivateDefault(static_cast<QMapCircleObjectPrivate &>(*this)); } - - QMapCircleObject::QMapCircleObject(QObject *parent) : QGeoMapObject(QExplicitlySharedDataPointer<QGeoMapObjectPrivate>(new QMapCircleObjectPrivateDefault(this)), parent) diff --git a/src/location/labs/qmapcircleobject_p_p.h b/src/location/labs/qmapcircleobject_p_p.h index b3353b62..4bf212c7 100644 --- a/src/location/labs/qmapcircleobject_p_p.h +++ b/src/location/labs/qmapcircleobject_p_p.h @@ -76,6 +76,8 @@ public: // QGeoMapObjectPrivate interface bool equals(const QGeoMapObjectPrivate &other) const override; + virtual QGeoShape geoShape() const override; + virtual void setGeoShape(const QGeoShape &shape) override; }; diff --git a/src/location/labs/qmapiconobject.cpp b/src/location/labs/qmapiconobject.cpp index a9f6f5b3..a0cd4d46 100644 --- a/src/location/labs/qmapiconobject.cpp +++ b/src/location/labs/qmapiconobject.cpp @@ -37,6 +37,7 @@ #include "qmapiconobject_p.h" #include "qmapiconobject_p_p.h" #include <QExplicitlySharedDataPointer> +#include <QtPositioning/QGeoCircle> QT_BEGIN_NAMESPACE @@ -92,6 +93,8 @@ QMapIconObjectPrivateDefault::QMapIconObjectPrivateDefault(const QMapIconObjectP m_coordinate = other.coordinate(); m_content = other.content(); m_iconSize = other.iconSize(); + qreal radius = QGeoCircle(other.geoShape()).radius(); + m_radius = (qIsFinite(radius)) ? radius : 100.0; } QMapIconObjectPrivateDefault::~QMapIconObjectPrivateDefault() @@ -104,9 +107,9 @@ QGeoCoordinate QMapIconObjectPrivateDefault::coordinate() const return m_coordinate; } -void QMapIconObjectPrivateDefault::setCoordinate(const QGeoCoordinate ¢er) +void QMapIconObjectPrivateDefault::setCoordinate(const QGeoCoordinate &coordinate) { - m_coordinate = center; + m_coordinate = coordinate; } QVariant QMapIconObjectPrivateDefault::content() const @@ -134,6 +137,30 @@ QGeoMapObjectPrivate *QMapIconObjectPrivateDefault::clone() return new QMapIconObjectPrivateDefault(static_cast<QMapIconObjectPrivate &>(*this)); } +QGeoShape QMapIconObjectPrivateDefault::geoShape() const +{ + return QGeoCircle(coordinate(), m_radius); // fixing the radius to 100 meters, as a meaningful size for + // fitting the viewport to this icon without losing context completely +} + +void QMapIconObjectPrivateDefault::setGeoShape(const QGeoShape &shape) +{ + QGeoCoordinate crd; + const QGeoCircle circle(shape); // if shape isn't a circle, circle will be created as a default-constructed circle + if (circle.isValid()) { + crd = circle.center(); + m_radius = circle.radius(); + } else { + crd = shape.boundingGeoRectangle().center(); + } + + if (crd == coordinate()) + return; + + setCoordinate(crd); + emit static_cast<QMapIconObject *>(q)->coordinateChanged(crd); +} + /* diff --git a/src/location/labs/qmapiconobject_p_p.h b/src/location/labs/qmapiconobject_p_p.h index 763b5389..01ed5b4a 100644 --- a/src/location/labs/qmapiconobject_p_p.h +++ b/src/location/labs/qmapiconobject_p_p.h @@ -88,13 +88,16 @@ public: virtual QSizeF iconSize() const override; virtual void setIconSize(const QSizeF &size) override; - // QMapIconObjectPrivate interface + // QGeoMapObjectPrivate interface QGeoMapObjectPrivate *clone() override; + QGeoShape geoShape() const override; + void setGeoShape(const QGeoShape &shape) override; public: QVariant m_content; QGeoCoordinate m_coordinate; QSizeF m_iconSize; + qreal m_radius = 100.0; // can be set only via setGeoShape, will be used only by private: QMapIconObjectPrivateDefault(const QMapIconObjectPrivateDefault &other) = delete; diff --git a/src/location/labs/qmapobjectview.cpp b/src/location/labs/qmapobjectview.cpp index 27b0ecb8..90234ea6 100644 --- a/src/location/labs/qmapobjectview.cpp +++ b/src/location/labs/qmapobjectview.cpp @@ -140,6 +140,25 @@ bool QMapObjectViewPrivateDefault::equals(const QGeoMapObjectPrivate &other) con && delegate() == o.delegate()); } +QGeoShape QMapObjectViewPrivateDefault::geoShape() const +{ + const QMapObjectView *qq = static_cast<const QMapObjectView *>(q); + QGeoRectangle rect; + const QList<QGeoMapObject *> kids = qq->geoMapObjectChildren(); + for (const auto &kid: kids) { + if (!rect.isValid()) + rect = kid->geoShape().boundingGeoRectangle(); + else + rect = rect.united(kid->geoShape().boundingGeoRectangle()); + } + return rect; +} + +void QMapObjectViewPrivateDefault::setGeoShape(const QGeoShape &/*shape*/) +{ + // MOV doesn't support setting the geoshape. +} + /* QMapObjectView diff --git a/src/location/labs/qmapobjectview_p_p.h b/src/location/labs/qmapobjectview_p_p.h index e283f1b0..55f45f67 100644 --- a/src/location/labs/qmapobjectview_p_p.h +++ b/src/location/labs/qmapobjectview_p_p.h @@ -89,6 +89,8 @@ public: public: QGeoMapObjectPrivate *clone() override; bool equals(const QGeoMapObjectPrivate &other) const override; + virtual QGeoShape geoShape() const override; + virtual void setGeoShape(const QGeoShape &shape) override; QVariant m_model; QQmlComponent *m_delegate = nullptr; diff --git a/src/location/labs/qmappolygonobject.cpp b/src/location/labs/qmappolygonobject.cpp index 1d495899..6ccba748 100644 --- a/src/location/labs/qmappolygonobject.cpp +++ b/src/location/labs/qmappolygonobject.cpp @@ -70,7 +70,10 @@ QMapPolygonObjectPrivateDefault::QMapPolygonObjectPrivateDefault(QGeoMapObject * QMapPolygonObjectPrivateDefault::QMapPolygonObjectPrivateDefault(const QMapPolygonObjectPrivate &other) : QMapPolygonObjectPrivate(other.q) { - m_path = other.path(); + m_path.setPath(other.path()); // to stay on the safe side + QGeoPolygon poly(other.geoShape()); // to handle holes + for (int i = 0; i < poly.holesCount(); i++) + m_path.addHole(poly.holePath(i)); m_borderColor = other.borderColor(); m_fillColor = other.fillColor(); m_borderWidth = other.borderWidth(); @@ -88,12 +91,12 @@ QGeoMapObject::Type QMapPolygonObjectPrivate::type() const QList<QGeoCoordinate> QMapPolygonObjectPrivateDefault::path() const { - return m_path; + return m_path.path(); } void QMapPolygonObjectPrivateDefault::setPath(const QList<QGeoCoordinate> &path) { - m_path = path; + m_path.setPath(path); } QColor QMapPolygonObjectPrivateDefault::fillColor() const @@ -131,6 +134,23 @@ QGeoMapObjectPrivate *QMapPolygonObjectPrivateDefault::clone() return new QMapPolygonObjectPrivateDefault(static_cast<QMapPolygonObjectPrivate &>(*this)); } +QGeoShape QMapPolygonObjectPrivateDefault::geoShape() const +{ + return m_path; +} + +void QMapPolygonObjectPrivateDefault::setGeoShape(const QGeoShape &shape) +{ + if (shape == m_path) + return; + + const QGeoPolygon poly(shape); + setPath(poly.path()); // to handle overrides + for (int i = 0; i < poly.holesCount(); i++) + m_path.addHole(poly.holePath(i)); + emit static_cast<QMapPolygonObject *>(q)->pathChanged(); +} + bool QMapPolygonObjectPrivate::equals(const QGeoMapObjectPrivate &other) const { if (other.type() != type()) // This check might be unnecessary, depending on how equals gets used @@ -138,12 +158,27 @@ bool QMapPolygonObjectPrivate::equals(const QGeoMapObjectPrivate &other) const const QMapPolygonObjectPrivate &o = static_cast<const QMapPolygonObjectPrivate &>(other); return (QGeoMapObjectPrivate::equals(o) - && path() == o.path() + && geoShape() == o.geoShape() && borderColor() == o.borderColor() && fillColor() == o.fillColor() && borderWidth() == o.borderWidth()); } +QGeoShape QMapPolygonObjectPrivate::geoShape() const +{ + return QGeoPolygon(path()); +} + +void QMapPolygonObjectPrivate::setGeoShape(const QGeoShape &shape) +{ + if (shape == geoShape()) + return; + + const QGeoPolygon poly(shape); + setPath(poly.path()); // to handle overrides + emit static_cast<QMapPolygonObject *>(q)->pathChanged(); +} + diff --git a/src/location/labs/qmappolygonobject_p_p.h b/src/location/labs/qmappolygonobject_p_p.h index d7e95d49..767765df 100644 --- a/src/location/labs/qmappolygonobject_p_p.h +++ b/src/location/labs/qmappolygonobject_p_p.h @@ -52,6 +52,7 @@ #include <QtLocation/private/qgeomapobject_p_p.h> #include <QGeoCoordinate> #include <QColor> +#include <QGeoPolygon> QT_BEGIN_NAMESPACE @@ -74,6 +75,8 @@ public: // QGeoMapObjectPrivate interface bool equals(const QGeoMapObjectPrivate &other) const override; + virtual QGeoShape geoShape() const override; + virtual void setGeoShape(const QGeoShape &shape) override; }; class Q_LOCATION_PRIVATE_EXPORT QMapPolygonObjectPrivateDefault : public QMapPolygonObjectPrivate @@ -95,9 +98,11 @@ public: // QGeoMapObjectPrivate interface QGeoMapObjectPrivate *clone() override; + virtual QGeoShape geoShape() const override; + virtual void setGeoShape(const QGeoShape &shape) override; public: - QList<QGeoCoordinate> m_path; + QGeoPolygon m_path; // small overhead compared to plain QList<QGeoCoordinate> QColor m_borderColor; QColor m_fillColor = Qt::transparent; qreal m_borderWidth = 0; diff --git a/src/location/labs/qmappolylineobject.cpp b/src/location/labs/qmappolylineobject.cpp index 1c351962..c6d3cdaf 100644 --- a/src/location/labs/qmappolylineobject.cpp +++ b/src/location/labs/qmappolylineobject.cpp @@ -37,6 +37,7 @@ #include "qmappolylineobject_p.h" #include "qmappolylineobject_p_p.h" #include <QtLocation/private/locationvaluetypehelper_p.h> +#include <QtPositioning/QGeoPath> QT_BEGIN_NAMESPACE @@ -127,6 +128,23 @@ bool QMapPolylineObjectPrivate::equals(const QGeoMapObjectPrivate &other) const && width() == o.width()); } +QGeoShape QMapPolylineObjectPrivate::geoShape() const +{ + return QGeoPath(path()); +} + +void QMapPolylineObjectPrivate::setGeoShape(const QGeoShape &shape) +{ + const QGeoPath p(shape); + if (p == path()) + return; + + setPath(p.path()); // to handle overrides + emit static_cast<QMapPolylineObject *>(q)->pathChanged(); +} + + + QGeoMapObjectPrivate *QMapPolylineObjectPrivateDefault::clone() { return new QMapPolylineObjectPrivateDefault(static_cast<QMapPolylineObjectPrivate &>(*this)); diff --git a/src/location/labs/qmappolylineobject_p_p.h b/src/location/labs/qmappolylineobject_p_p.h index 1d5919d2..a0eb3711 100644 --- a/src/location/labs/qmappolylineobject_p_p.h +++ b/src/location/labs/qmappolylineobject_p_p.h @@ -72,6 +72,8 @@ public: // QGeoMapObjectPrivate interface bool equals(const QGeoMapObjectPrivate &other) const override; + virtual QGeoShape geoShape() const override; + virtual void setGeoShape(const QGeoShape &shape) override; }; class Q_LOCATION_PRIVATE_EXPORT QMapPolylineObjectPrivateDefault : public QMapPolylineObjectPrivate diff --git a/src/location/labs/qmaprouteobject.cpp b/src/location/labs/qmaprouteobject.cpp index a4a71cac..fd29954b 100644 --- a/src/location/labs/qmaprouteobject.cpp +++ b/src/location/labs/qmaprouteobject.cpp @@ -118,6 +118,16 @@ QGeoMapObjectPrivate *QMapRouteObjectPrivate::clone() return new QMapRouteObjectPrivate(*this); } +QGeoShape QMapRouteObjectPrivate::geoShape() const +{ + return route().bounds(); +} + +void QMapRouteObjectPrivate::setGeoShape(const QGeoShape &/*shape*/) +{ + // Not supported for MapRouteObject +} + /* @@ -172,7 +182,7 @@ void QMapRouteObject::setMap(QGeoMap *map) if (!map) { // Map was set, now it has ben re-set to NULL, but not inside d_ptr. // so m_map inside d_ptr can still be used to remove itself, inside the destructor. - d_ptr = new QMapRouteObjectPrivate(*d); + d_ptr = new QMapRouteObjectPrivate(*d); // This is not losing data: check MapRouteObjectPrivate::declarativeGeoRoute() // Old pimpl deleted implicitly by QExplicitlySharedDataPointer } } diff --git a/src/location/labs/qmaprouteobject_p_p.h b/src/location/labs/qmaprouteobject_p_p.h index e01b1cc6..f12f9b33 100644 --- a/src/location/labs/qmaprouteobject_p_p.h +++ b/src/location/labs/qmaprouteobject_p_p.h @@ -72,6 +72,8 @@ public: // QGeoMapObjectPrivate interface bool equals(const QGeoMapObjectPrivate &other) const override; QGeoMapObjectPrivate *clone() override; + virtual QGeoShape geoShape() const override; + virtual void setGeoShape(const QGeoShape &shape) override; }; QT_END_NAMESPACE diff --git a/src/location/labs/qsg/qmapcircleobjectqsg.cpp b/src/location/labs/qsg/qmapcircleobjectqsg.cpp index 269c9ebb..32f3030b 100644 --- a/src/location/labs/qsg/qmapcircleobjectqsg.cpp +++ b/src/location/labs/qsg/qmapcircleobjectqsg.cpp @@ -50,12 +50,10 @@ QMapCircleObjectPrivateQSG::QMapCircleObjectPrivateQSG(const QMapCircleObjectPri : QMapCircleObjectPrivateDefault(other) { // Data already cloned by the *Default copy constructor, but necessary - // update operations triggered by setters overrides - setCenter(center()); - setRadius(radius()); - setColor(color()); - setBorderColor(borderColor()); - setBorderWidth(borderWidth()); + // update operations triggered only by setters overrides + updateGeometry(); + if (m_map) + emit m_map->sgNodeChanged(); } QMapCircleObjectPrivateQSG::~QMapCircleObjectPrivateQSG() @@ -77,7 +75,7 @@ void QMapCircleObjectPrivateQSG::updateCirclePath() void QMapCircleObjectPrivateQSG::updateGeometry() { if (!m_map || m_map->geoProjection().projectionType() != QGeoProjection::ProjectionWebMercator - || !qIsFinite(m_radius) || !m_center.isValid()) + || !qIsFinite(radius()) || !center().isValid()) return; const QGeoProjectionWebMercator &p = static_cast<const QGeoProjectionWebMercator&>(m_map->geoProjection()); @@ -182,7 +180,7 @@ QSGNode *QMapCircleObjectPrivateQSG::updateMapObjectNode(QSGNode *oldNode, void QMapCircleObjectPrivateQSG::setCenter(const QGeoCoordinate ¢er) { - m_center = center; + QMapCircleObjectPrivateDefault::setCenter(center); updateGeometry(); if (m_map) emit m_map->sgNodeChanged(); @@ -190,7 +188,7 @@ void QMapCircleObjectPrivateQSG::setCenter(const QGeoCoordinate ¢er) void QMapCircleObjectPrivateQSG::setRadius(qreal radius) { - m_radius = radius; + QMapCircleObjectPrivateDefault::setRadius(radius); updateGeometry(); if (m_map) emit m_map->sgNodeChanged(); @@ -198,7 +196,7 @@ void QMapCircleObjectPrivateQSG::setRadius(qreal radius) void QMapCircleObjectPrivateQSG::setColor(const QColor &color) { - m_fillColor = color; + QMapCircleObjectPrivateDefault::setColor(color); updateGeometry(); if (m_map) emit m_map->sgNodeChanged(); @@ -206,7 +204,7 @@ void QMapCircleObjectPrivateQSG::setColor(const QColor &color) void QMapCircleObjectPrivateQSG::setBorderColor(const QColor &color) { - m_borderColor = color; + QMapCircleObjectPrivateDefault::setBorderColor(color); updateGeometry(); if (m_map) emit m_map->sgNodeChanged(); @@ -214,7 +212,7 @@ void QMapCircleObjectPrivateQSG::setBorderColor(const QColor &color) void QMapCircleObjectPrivateQSG::setBorderWidth(qreal width) { - m_borderWidth = width; + QMapCircleObjectPrivateDefault::setBorderWidth(width); updateGeometry(); if (m_map) emit m_map->sgNodeChanged(); diff --git a/src/location/labs/qsg/qmapiconobjectqsg.cpp b/src/location/labs/qsg/qmapiconobjectqsg.cpp index 2e7a00e0..d9a80c91 100644 --- a/src/location/labs/qsg/qmapiconobjectqsg.cpp +++ b/src/location/labs/qsg/qmapiconobjectqsg.cpp @@ -67,8 +67,10 @@ QMapIconObjectPrivateQSG::QMapIconObjectPrivateQSG(QGeoMapObject *q) QMapIconObjectPrivateQSG::QMapIconObjectPrivateQSG(const QMapIconObjectPrivate &other) : QMapIconObjectPrivateDefault(other) { + // Data already cloned by the *Default copy constructor, but necessary + // update operations triggered only by setters overrides setContent(content()); - setCoordinate(coordinate()); +// setCoordinate(coordinate()); } QMapIconObjectPrivateQSG::~QMapIconObjectPrivateQSG() diff --git a/src/location/labs/qsg/qmappolygonobjectqsg.cpp b/src/location/labs/qsg/qmappolygonobjectqsg.cpp index 01653a0e..9963cac9 100644 --- a/src/location/labs/qsg/qmappolygonobjectqsg.cpp +++ b/src/location/labs/qsg/qmappolygonobjectqsg.cpp @@ -37,22 +37,24 @@ #include "qmappolygonobjectqsg_p_p.h" #include <QtQuick/qsgnode.h> #include <QtQuick/qsgsimplerectnode.h> +#include <QtPositioning/private/qgeopolygon_p.h> QT_BEGIN_NAMESPACE QMapPolygonObjectPrivateQSG::QMapPolygonObjectPrivateQSG(QGeoMapObject *q) - : QMapPolygonObjectPrivate(q) + : QMapPolygonObjectPrivateDefault(q) { } QMapPolygonObjectPrivateQSG::QMapPolygonObjectPrivateQSG(const QMapPolygonObjectPrivate &other) - : QMapPolygonObjectPrivate(other.q) + : QMapPolygonObjectPrivateDefault(other) { - setPath(other.path()); - setFillColor(other.fillColor()); - setBorderColor(other.borderColor()); - setBorderWidth(other.borderWidth()); + // Data already cloned by the *Default copy constructor, but necessary + // update operations triggered only by setters overrides + updateGeometry(); + if (m_map) + emit m_map->sgNodeChanged(); } QMapPolygonObjectPrivateQSG::~QMapPolygonObjectPrivateQSG() @@ -69,8 +71,8 @@ QList<QDoubleVector2D> QMapPolygonObjectPrivateQSG::projectPath() const QGeoProjectionWebMercator &p = static_cast<const QGeoProjectionWebMercator&>(m_map->geoProjection()); - geopathProjected_.reserve(m_geoPath.path().size()); - for (const QGeoCoordinate &c : m_geoPath.path()) + geopathProjected_.reserve(m_path.path().size()); + for (const QGeoCoordinate &c : m_path.path()) geopathProjected_ << p.geoToMapProjection(c); return geopathProjected_; } @@ -107,29 +109,9 @@ QSGNode *QMapPolygonObjectPrivateQSG::updateMapObjectNode(QSGNode *oldNode, return node; } -QList<QGeoCoordinate> QMapPolygonObjectPrivateQSG::path() const -{ - return m_geoPath.path(); -} - -QColor QMapPolygonObjectPrivateQSG::fillColor() const -{ - return m_fillColor; -} - -QColor QMapPolygonObjectPrivateQSG::borderColor() const -{ - return m_borderColor; -} - -qreal QMapPolygonObjectPrivateQSG::borderWidth() const -{ - return m_borderWidth; -} - void QMapPolygonObjectPrivateQSG::setPath(const QList<QGeoCoordinate> &path) { - m_geoPath.setPath(path); + QMapPolygonObjectPrivateDefault::setPath(path); updateGeometry(); if (m_map) @@ -138,7 +120,7 @@ void QMapPolygonObjectPrivateQSG::setPath(const QList<QGeoCoordinate> &path) void QMapPolygonObjectPrivateQSG::setFillColor(const QColor &color) { - m_fillColor = color; + QMapPolygonObjectPrivateDefault::setFillColor(color); updateGeometry(); if (m_map) @@ -147,7 +129,7 @@ void QMapPolygonObjectPrivateQSG::setFillColor(const QColor &color) void QMapPolygonObjectPrivateQSG::setBorderColor(const QColor &color) { - m_borderColor = color; + QMapPolygonObjectPrivateDefault::setBorderColor(color); updateGeometry(); if (m_map) @@ -156,7 +138,7 @@ void QMapPolygonObjectPrivateQSG::setBorderColor(const QColor &color) void QMapPolygonObjectPrivateQSG::setBorderWidth(qreal width) { - m_borderWidth = width; + QMapPolygonObjectPrivateDefault::setBorderWidth(width); updateGeometry(); if (m_map) @@ -168,9 +150,21 @@ QGeoMapObjectPrivate *QMapPolygonObjectPrivateQSG::clone() return new QMapPolygonObjectPrivateQSG(static_cast<QMapPolygonObjectPrivate &>(*this)); } +void QMapPolygonObjectPrivateQSG::setGeoShape(const QGeoShape &shape) +{ + if (shape == m_path) + return; + + m_path = QGeoPathEager(shape); + updateGeometry(); + if (m_map) + emit m_map->sgNodeChanged(); + emit static_cast<QMapPolygonObject *>(q)->pathChanged(); +} + void QMapPolygonObjectPrivateQSG::updateGeometry() { - if (!m_map || m_geoPath.path().length() == 0 + if (!m_map || m_path.path().length() == 0 || m_map->geoProjection().projectionType() != QGeoProjection::ProjectionWebMercator) return; @@ -180,7 +174,7 @@ void QMapPolygonObjectPrivateQSG::updateGeometry() const QList<QDoubleVector2D> &geopathProjected = projectPath(); m_geometry.markSourceDirty(); - m_geometry.setPreserveGeometry(true, m_geoPath.boundingGeoRectangle().topLeft()); + m_geometry.setPreserveGeometry(true, m_path.boundingGeoRectangle().topLeft()); m_geometry.updateSourcePoints(*m_map, geopathProjected); m_geometry.updateScreenPoints(*m_map); @@ -193,7 +187,7 @@ void QMapPolygonObjectPrivateQSG::updateGeometry() closedPath << closedPath.first(); m_borderGeometry.markSourceDirty(); - m_borderGeometry.setPreserveGeometry(true, m_geoPath.boundingGeoRectangle().topLeft()); + m_borderGeometry.setPreserveGeometry(true, m_path.boundingGeoRectangle().topLeft()); const QGeoCoordinate &geometryOrigin = m_geometry.origin(); diff --git a/src/location/labs/qsg/qmappolygonobjectqsg_p_p.h b/src/location/labs/qsg/qmappolygonobjectqsg_p_p.h index b288528a..0f42a92e 100644 --- a/src/location/labs/qsg/qmappolygonobjectqsg_p_p.h +++ b/src/location/labs/qsg/qmappolygonobjectqsg_p_p.h @@ -57,7 +57,7 @@ QT_BEGIN_NAMESPACE -class Q_LOCATION_PRIVATE_EXPORT QMapPolygonObjectPrivateQSG : public QMapPolygonObjectPrivate, public QQSGMapObject +class Q_LOCATION_PRIVATE_EXPORT QMapPolygonObjectPrivateQSG : public QMapPolygonObjectPrivateDefault, public QQSGMapObject { public: QMapPolygonObjectPrivateQSG(QGeoMapObject *q); @@ -73,12 +73,7 @@ public: QSGNode *root, QQuickWindow *window) override; - // QGeoMapPolylinePrivate interface - QList<QGeoCoordinate> path() const override; - QColor fillColor() const override; - QColor borderColor() const override; - qreal borderWidth() const override; - + // QGeoMapPolygonPrivate interface void setPath(const QList<QGeoCoordinate> &path) override; void setFillColor(const QColor &color) override; void setBorderColor(const QColor &color) override; @@ -86,15 +81,12 @@ public: // QGeoMapObjectPrivate QGeoMapObjectPrivate *clone() override; + virtual void setGeoShape(const QGeoShape &shape) override; // Data Members QGeoMapPolygonGeometry m_geometry; QGeoMapPolylineGeometry m_borderGeometry; - QGeoPath m_geoPath; - QColor m_fillColor; - QColor m_borderColor; - qreal m_borderWidth = 0; bool m_updatingGeometry = false; }; diff --git a/src/location/labs/qsg/qmappolylineobjectqsg.cpp b/src/location/labs/qsg/qmappolylineobjectqsg.cpp index b2cdc607..66656b23 100644 --- a/src/location/labs/qsg/qmappolylineobjectqsg.cpp +++ b/src/location/labs/qsg/qmappolylineobjectqsg.cpp @@ -45,18 +45,19 @@ QT_BEGIN_NAMESPACE */ QMapPolylineObjectPrivateQSG::QMapPolylineObjectPrivateQSG(QGeoMapObject *q) - : QMapPolylineObjectPrivate(q) + : QMapPolylineObjectPrivateDefault(q) { } QMapPolylineObjectPrivateQSG::QMapPolylineObjectPrivateQSG(const QMapPolylineObjectPrivate &other) - : QMapPolylineObjectPrivate(other.q) + : QMapPolylineObjectPrivateDefault(other) { - // do the appropriate internal update and trigger map repaint - setPath(other.path()); - setColor(other.color()); - setWidth(other.width()); + // Data already cloned by the *Default copy constructor, but necessary + // update operations triggered only by setters overrides + updateGeometry(); + if (m_map) + emit m_map->sgNodeChanged(); } QMapPolylineObjectPrivateQSG::~QMapPolylineObjectPrivateQSG() @@ -127,24 +128,22 @@ QSGNode *QMapPolylineObjectPrivateQSG::updateMapObjectNode(QSGNode *oldNode, return node; } -QList<QGeoCoordinate> QMapPolylineObjectPrivateQSG::path() const { return m_geoPath.path(); } - -QColor QMapPolylineObjectPrivateQSG::color() const { return m_color; } - -qreal QMapPolylineObjectPrivateQSG::width() const { return m_width; } +QList<QGeoCoordinate> QMapPolylineObjectPrivateQSG::path() const +{ + return m_geoPath.path(); +} void QMapPolylineObjectPrivateQSG::setPath(const QList<QGeoCoordinate> &path) { m_geoPath.setPath(path); updateGeometry(); - if (m_map) emit m_map->sgNodeChanged(); } void QMapPolylineObjectPrivateQSG::setColor(const QColor &color) { - m_color = color; + QMapPolylineObjectPrivateDefault::setColor(color); updateGeometry(); if (m_map) @@ -153,7 +152,7 @@ void QMapPolylineObjectPrivateQSG::setColor(const QColor &color) void QMapPolylineObjectPrivateQSG::setWidth(qreal width) { - m_width = width; + QMapPolylineObjectPrivateDefault::setWidth(width); updateGeometry(); if (m_map) @@ -165,4 +164,9 @@ QGeoMapObjectPrivate *QMapPolylineObjectPrivateQSG::clone() return new QMapPolylineObjectPrivateQSG(static_cast<QMapPolylineObjectPrivate &>(*this)); } +QGeoShape QMapPolylineObjectPrivateQSG::geoShape() const +{ + return m_geoPath; +} + QT_END_NAMESPACE diff --git a/src/location/labs/qsg/qmappolylineobjectqsg_p_p.h b/src/location/labs/qsg/qmappolylineobjectqsg_p_p.h index 792413e5..e8eb5839 100644 --- a/src/location/labs/qsg/qmappolylineobjectqsg_p_p.h +++ b/src/location/labs/qsg/qmappolylineobjectqsg_p_p.h @@ -54,10 +54,11 @@ #include <QtLocation/private/qmappolylineobject_p.h> #include <QtLocation/private/qqsgmapobject_p.h> #include <QtCore/qscopedvaluerollback.h> +#include <QtPositioning/private/qgeopath_p.h> QT_BEGIN_NAMESPACE -class Q_LOCATION_PRIVATE_EXPORT QMapPolylineObjectPrivateQSG : public QMapPolylineObjectPrivate, public QQSGMapObject +class Q_LOCATION_PRIVATE_EXPORT QMapPolylineObjectPrivateQSG : public QMapPolylineObjectPrivateDefault, public QQSGMapObject { public: QMapPolylineObjectPrivateQSG(QGeoMapObject *q); @@ -75,22 +76,17 @@ public: // QGeoMapPolylinePrivate interface QList<QGeoCoordinate> path() const override; - QColor color() const override; - qreal width() const override; - void setPath(const QList<QGeoCoordinate> &path) override; void setColor(const QColor &color) override; void setWidth(qreal width) override; // QGeoMapObjectPrivate QGeoMapObjectPrivate *clone() override; + virtual QGeoShape geoShape() const override; // Data Members + QGeoPathEager m_geoPath; QGeoMapPolylineGeometry m_geometry; - QGeoPath m_geoPath; - - QColor m_color; - qreal m_width = 0; bool m_updatingGeometry = false; }; diff --git a/src/positioning/qgeopath_p.h b/src/positioning/qgeopath_p.h index 4fffe61d..be73994f 100644 --- a/src/positioning/qgeopath_p.h +++ b/src/positioning/qgeopath_p.h @@ -55,7 +55,6 @@ #include "qgeoshape_p.h" #include "qgeocoordinate.h" #include "qlocationutils_p.h" -#include <QtPositioning/private/qclipperutils_p.h> #include <QtPositioning/qgeopath.h> #include <QtCore/QVector> diff --git a/src/positioning/qgeopolygon_p.h b/src/positioning/qgeopolygon_p.h index d28fcc6e..880a2784 100644 --- a/src/positioning/qgeopolygon_p.h +++ b/src/positioning/qgeopolygon_p.h @@ -53,6 +53,7 @@ #include <QtPositioning/private/qgeopath_p.h> #include <QtPositioning/qgeopolygon.h> +#include <QtPositioning/private/qclipperutils_p.h> QT_BEGIN_NAMESPACE |