diff --git a/python/gui/auto_generated/qgsrubberband.sip.in b/python/gui/auto_generated/qgsrubberband.sip.in index 0f145fc522d..106cd6b9543 100644 --- a/python/gui/auto_generated/qgsrubberband.sip.in +++ b/python/gui/auto_generated/qgsrubberband.sip.in @@ -212,7 +212,7 @@ Returns number of vertices in feature part void setToGeometry( const QgsGeometry &geom, QgsVectorLayer *layer ); %Docstring -Sets this rubber band to the geometry of an existing feature. +Sets this rubber band to ``geom``. This is useful for feature highlighting. In contrast to addGeometry(), this method does also change the geometry type of the rubberband. @@ -221,6 +221,17 @@ In contrast to addGeometry(), this method does also change the geometry type of crs. In case of 0 pointer, the coordinates are not going to be transformed. %End + void setToGeometry( const QgsGeometry &geometry, const QgsCoordinateReferenceSystem &crs = QgsCoordinateReferenceSystem() ); +%Docstring +Sets this rubber band to ``geometry``. +In contrast to addGeometry(), this method does also change the geometry type of the rubberband. +The coordinate reference system of the geometry can be specified with ``crs``. If an invalid ``crs`` +is passed, the geometry will not be reprojected and needs to be in canvas crs already. +By default, no reprojection is done. + +.. versionadded:: 3.4 +%End + void setToCanvasRectangle( QRect rect ); %Docstring Sets this rubber band to a map canvas rectangle diff --git a/src/gui/qgsrubberband.cpp b/src/gui/qgsrubberband.cpp index d69445fab09..920c83501b0 100644 --- a/src/gui/qgsrubberband.cpp +++ b/src/gui/qgsrubberband.cpp @@ -231,6 +231,18 @@ void QgsRubberBand::setToGeometry( const QgsGeometry &geom, QgsVectorLayer *laye addGeometry( geom, layer ); } +void QgsRubberBand::setToGeometry( const QgsGeometry &geom, const QgsCoordinateReferenceSystem &crs ) +{ + if ( geom.isNull() ) + { + reset( mGeometryType ); + return; + } + + reset( geom.type() ); + addGeometry( geom, crs ); +} + void QgsRubberBand::addGeometry( const QgsGeometry &geometry, QgsVectorLayer *layer ) { QgsGeometry geom = geometry; diff --git a/src/gui/qgsrubberband.h b/src/gui/qgsrubberband.h index dab77c619a8..486804278d5 100644 --- a/src/gui/qgsrubberband.h +++ b/src/gui/qgsrubberband.h @@ -237,7 +237,7 @@ class GUI_EXPORT QgsRubberBand: public QgsMapCanvasItem int partSize( int geometryIndex ) const; /** - * Sets this rubber band to the geometry of an existing feature. + * Sets this rubber band to \a geom. * This is useful for feature highlighting. * In contrast to addGeometry(), this method does also change the geometry type of the rubberband. * \param geom the geometry object @@ -246,6 +246,17 @@ class GUI_EXPORT QgsRubberBand: public QgsMapCanvasItem */ void setToGeometry( const QgsGeometry &geom, QgsVectorLayer *layer ); + /** + * Sets this rubber band to \a geometry. + * In contrast to addGeometry(), this method does also change the geometry type of the rubberband. + * The coordinate reference system of the geometry can be specified with \a crs. If an invalid \a crs + * is passed, the geometry will not be reprojected and needs to be in canvas crs already. + * By default, no reprojection is done. + * + * \since QGIS 3.4 + */ + void setToGeometry( const QgsGeometry &geometry, const QgsCoordinateReferenceSystem &crs = QgsCoordinateReferenceSystem() ); + /** * Sets this rubber band to a map canvas rectangle * \param rect rectangle in canvas coordinates