diff options
Diffstat (limited to 'src/location/declarativemaps')
4 files changed, 34 insertions, 28 deletions
diff --git a/src/location/declarativemaps/qdeclarativepolylinemapitem.cpp b/src/location/declarativemaps/qdeclarativepolylinemapitem.cpp index 44f9b3a1..dffec4d5 100644 --- a/src/location/declarativemaps/qdeclarativepolylinemapitem.cpp +++ b/src/location/declarativemaps/qdeclarativepolylinemapitem.cpp @@ -519,7 +519,8 @@ void QGeoMapPolylineGeometry::updateSourcePoints(const QGeoMap &map, \internal */ void QGeoMapPolylineGeometry::updateScreenPoints(const QGeoMap &map, - qreal strokeWidth) + qreal strokeWidth, + bool adjustTranslation) { if (!screenDirty_) return; @@ -531,20 +532,14 @@ void QGeoMapPolylineGeometry::updateScreenPoints(const QGeoMap &map, return; } - // Create the viewport rect in the same coordinate system - // as the actual points - QRectF viewport(0, 0, map.viewportWidth(), map.viewportHeight()); - viewport.adjust(-strokeWidth, -strokeWidth, strokeWidth, strokeWidth); - viewport.translate(-1 * origin); - // The geometry has already been clipped against the visible region projection in wrapped mercator space. QVector<qreal> points = srcPoints_; QVector<QPainterPath::ElementType> types = srcPointTypes_; QVectorPath vp(points.data(), types.size(), types.data()); QTriangulatingStroker ts; - // viewport is not used in the call below. - ts.process(vp, QPen(QBrush(Qt::black), strokeWidth), viewport, QPainter::Qt4CompatiblePainting); + // As of Qt5.11, the clip argument is not actually used, in the call below. + ts.process(vp, QPen(QBrush(Qt::black), strokeWidth), QRectF(), QPainter::Qt4CompatiblePainting); clear(); @@ -583,7 +578,8 @@ void QGeoMapPolylineGeometry::updateScreenPoints(const QGeoMap &map, } screenBounds_ = bb; - this->translate( -1 * sourceBounds_.topLeft() + QPointF(strokeWidth, strokeWidth)); + const QPointF strokeOffset = (adjustTranslation) ? QPointF(strokeWidth, strokeWidth) : QPointF(); + this->translate( -1 * sourceBounds_.topLeft() + strokeOffset); } void QGeoMapPolylineGeometry::clearSource() @@ -592,6 +588,24 @@ void QGeoMapPolylineGeometry::clearSource() srcPointTypes_.clear(); } +bool QGeoMapPolylineGeometry::contains(const QPointF &point) const +{ + // screenOutline_.contains(screenPoint) doesn't work, as, it appears, that + // screenOutline_ for QGeoMapPolylineGeometry is empty (QRectF(0,0 0x0)) + const QVector<QPointF> &verts = vertices(); + QPolygonF tri; + for (int i = 0; i < verts.size(); ++i) { + tri << verts[i]; + if (tri.size() == 3) { + if (tri.containsPoint(point,Qt::OddEvenFill)) + return true; + tri.remove(0); + } + } + + return false; +} + QDeclarativePolylineMapItem::QDeclarativePolylineMapItem(QQuickItem *parent) : QDeclarativeGeoMapItemBase(parent), line_(this), dirtyMaterial_(true), updatingGeometry_(false) { @@ -948,7 +962,7 @@ void QDeclarativePolylineMapItem::updatePolish() setWidth(geometry_.sourceBoundingBox().width() + 2 * line_.width()); setHeight(geometry_.sourceBoundingBox().height() + 2 * line_.width()); - setPositionOnMap(geometry_.origin(), -1 * geometry_.sourceBoundingBox().topLeft()); + setPositionOnMap(geometry_.origin(), -1 * geometry_.sourceBoundingBox().topLeft() + QPointF(line_.width(), line_.width())); } void QDeclarativePolylineMapItem::markSourceDirtyAndUpdate() @@ -982,18 +996,7 @@ QSGNode *QDeclarativePolylineMapItem::updateMapItemPaintNode(QSGNode *oldNode, U bool QDeclarativePolylineMapItem::contains(const QPointF &point) const { - QVector<QPointF> vertices = geometry_.vertices(); - QPolygonF tri; - for (int i = 0; i < vertices.size(); ++i) { - tri << vertices[i]; - if (tri.size() == 3) { - if (tri.containsPoint(point,Qt::OddEvenFill)) - return true; - tri.remove(0); - } - } - - return false; + return geometry_.contains(point); } const QGeoShape &QDeclarativePolylineMapItem::geoShape() const diff --git a/src/location/declarativemaps/qdeclarativepolylinemapitem_p.h b/src/location/declarativemaps/qdeclarativepolylinemapitem_p.h index 61439097..ca01de12 100644 --- a/src/location/declarativemaps/qdeclarativepolylinemapitem_p.h +++ b/src/location/declarativemaps/qdeclarativepolylinemapitem_p.h @@ -95,10 +95,13 @@ public: const QGeoCoordinate geoLeftBound); void updateScreenPoints(const QGeoMap &map, - qreal strokeWidth); + qreal strokeWidth, + bool adjustTranslation = true); void clearSource(); + bool contains(const QPointF &point) const override; + QList<QList<QDoubleVector2D> > clipPath(const QGeoMap &map, const QList<QDoubleVector2D> &path, QDoubleVector2D &leftBoundWrapped); diff --git a/src/location/declarativemaps/qdeclarativerectanglemapitem.cpp b/src/location/declarativemaps/qdeclarativerectanglemapitem.cpp index 9e32c427..e90c0596 100644 --- a/src/location/declarativemaps/qdeclarativerectanglemapitem.cpp +++ b/src/location/declarativemaps/qdeclarativerectanglemapitem.cpp @@ -290,7 +290,7 @@ void QDeclarativeRectangleMapItem::updatePolish() geometry_.setPreserveGeometry(true, rectangle_.topLeft()); geometry_.updateSourcePoints(*map(), pathMercator_); - geometry_.updateScreenPoints(*map()); + geometry_.updateScreenPoints(*map(), border_.width()); QList<QGeoMapItemGeometry *> geoms; geoms << &geometry_; @@ -320,8 +320,8 @@ void QDeclarativeRectangleMapItem::updatePolish() } QRectF combined = QGeoMapItemGeometry::translateToCommonOrigin(geoms); - setWidth(combined.width()); - setHeight(combined.height()); + setWidth(combined.width() + 2 * border_.width()); + setHeight(combined.height() + 2 * border_.width()); setPositionOnMap(geometry_.origin(), geometry_.firstPointOffset()); } diff --git a/src/location/declarativemaps/qgeomapitemgeometry_p.h b/src/location/declarativemaps/qgeomapitemgeometry_p.h index 1011cd0c..ab81ff0b 100644 --- a/src/location/declarativemaps/qgeomapitemgeometry_p.h +++ b/src/location/declarativemaps/qgeomapitemgeometry_p.h @@ -95,7 +95,7 @@ public: return screenOutline_; } - inline bool contains(const QPointF &screenPoint) const { + virtual bool contains(const QPointF &screenPoint) const { return screenOutline_.contains(screenPoint); } |