diff options
Diffstat (limited to 'src/imports/location/qdeclarativepolylinemapitem.cpp')
-rw-r--r-- | src/imports/location/qdeclarativepolylinemapitem.cpp | 126 |
1 files changed, 118 insertions, 8 deletions
diff --git a/src/imports/location/qdeclarativepolylinemapitem.cpp b/src/imports/location/qdeclarativepolylinemapitem.cpp index 71a205d3..f2373abf 100644 --- a/src/imports/location/qdeclarativepolylinemapitem.cpp +++ b/src/imports/location/qdeclarativepolylinemapitem.cpp @@ -199,6 +199,7 @@ void QGeoMapPolylineGeometry::updateSourcePoints(const QGeoMap &map, QDoubleVector2D origin, lastPoint, lastAddedPoint; + const double mapWidthHalf = map.width()/2.0; double unwrapBelowX = 0; if (preserveGeometry_) unwrapBelowX = map.coordinateToItemPosition(geoLeftBound_, false).x(); @@ -219,7 +220,8 @@ void QGeoMapPolylineGeometry::updateSourcePoints(const QGeoMap &map, // unwrap x to preserve geometry if moved to border of map if (preserveGeometry_ && point.x() < unwrapBelowX && !qFuzzyCompare(geoLeftBound_.longitude(), coord.longitude()) - && !qFuzzyCompare(point.x(), unwrapBelowX)) + && !qFuzzyCompare(point.x(), unwrapBelowX) + && !qFuzzyCompare(mapWidthHalf, point.x())) point.setX(unwrapBelowX + geoDistanceToScreenWidth(map, geoLeftBound_, coord)); if (!foundValid) { @@ -534,7 +536,6 @@ void QDeclarativePolylineMapItem::setPath(const QJSValue &value) setPathFromGeoList(pathList); } - /*! \internal */ @@ -551,13 +552,26 @@ void QDeclarativePolylineMapItem::setPathFromGeoList(const QList<QGeoCoordinate> } /*! - \qmlmethod void MapPolyline::addCoordinate(coordinate) + \qmlmethod int MapPolyline::pathLength() + + Returns the number of coordinates of the polyline. - Adds a coordinate to the path. + \since Qt Location 5.6 - \sa removeCoordinate, path + \sa path */ +int QDeclarativePolylineMapItem::pathLength() const +{ + return path_.size(); +} + +/*! + \qmlmethod void MapPolyline::addCoordinate(coordinate) + + Adds a coordinate to the end of the path. + \sa insertCoordinate, removeCoordinate, path +*/ void QDeclarativePolylineMapItem::addCoordinate(const QGeoCoordinate &coordinate) { path_.append(coordinate); @@ -568,6 +582,78 @@ void QDeclarativePolylineMapItem::addCoordinate(const QGeoCoordinate &coordinate } /*! + \qmlmethod void MapPolyline::insertCoordinate(index, coordinate) + + Inserts a \a coordinate to the path at the given \a index. + + \since Qt Location 5.6 + + \sa addCoordinate, removeCoordinate, path +*/ +void QDeclarativePolylineMapItem::insertCoordinate(int index, const QGeoCoordinate &coordinate) +{ + if (index < 0 || index > path_.size()) + return; + + path_.insert(index, coordinate); + + geometry_.markSourceDirty(); + polishAndUpdate(); + emit pathChanged(); +} + +/*! + \qmlmethod void MapPolyline::replaceCoordinate(index, coordinate) + + Replaces the coordinate in the current path at the given \a index + with the new \a coordinate. + + \since Qt Location 5.6 + + \sa addCoordinate, insertCoordinate, removeCoordinate, path +*/ +void QDeclarativePolylineMapItem::replaceCoordinate(int index, const QGeoCoordinate &coordinate) +{ + if (index < 0 || index >= path_.size()) + return; + + path_[index] = coordinate; + + geometry_.markSourceDirty(); + polishAndUpdate(); + emit pathChanged(); +} + +/*! + \qmlmethod coordinate MapPolyline::coordinateAt(index) + + Gets the coordinate of the polyline at the given \a index. + If the index is outside the path's bounds then an invalid + coordinate is returned. + + \since Qt Location 5.6 +*/ +QGeoCoordinate QDeclarativePolylineMapItem::coordinateAt(int index) const +{ + if (index < 0 || index >= path_.size()) + return QGeoCoordinate(); + + return path_.at(index); +} + +/*! + \qmlmethod coordinate MapPolyline::containsCoordinate(coordinate) + + Returns true if the given \a coordinate is part of the path. + + \since Qt Location 5.6 +*/ +bool QDeclarativePolylineMapItem::containsCoordinate(const QGeoCoordinate &coordinate) +{ + return path_.indexOf(coordinate) > -1; +} + +/*! \qmlmethod void MapPolyline::removeCoordinate(coordinate) Removes \a coordinate from the path. If there are multiple instances of the @@ -575,7 +661,7 @@ void QDeclarativePolylineMapItem::addCoordinate(const QGeoCoordinate &coordinate If \a coordinate is not in the path this method does nothing. - \sa addCoordinate, path + \sa addCoordinate, insertCoordinate, path */ void QDeclarativePolylineMapItem::removeCoordinate(const QGeoCoordinate &coordinate) { @@ -591,6 +677,29 @@ void QDeclarativePolylineMapItem::removeCoordinate(const QGeoCoordinate &coordin } /*! + \qmlmethod void MapPolyline::removeCoordinate(index) + + Removes a coordinate from the path at the given \a index. + + If \a index is invalid then this method does nothing. + + \since Qt Location 5.6 + + \sa addCoordinate, insertCoordinate, path +*/ +void QDeclarativePolylineMapItem::removeCoordinate(int index) +{ + if (index < 0 || index >= path_.size()) + return; + + path_.removeAt(index); + + geometry_.markSourceDirty(); + polishAndUpdate(); + emit pathChanged(); +} + +/*! \qmlpropertygroup Location::MapPolyline::line \qmlproperty int MapPolyline::line.width \qmlproperty color MapPolyline::line.color @@ -736,9 +845,10 @@ 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 < geometry_.vertices().size(); ++i) { - tri << geometry_.vertices()[i]; + for (int i = 0; i < vertices.size(); ++i) { + tri << vertices[i]; if (tri.size() == 3) { if (tri.containsPoint(point,Qt::OddEvenFill)) return true; |