Skip to content

Commit

Permalink
Add QgsRubberBand::setToGeometry with crs parameter
Browse files Browse the repository at this point in the history
  • Loading branch information
m-kuhn authored and nyalldawson committed Sep 29, 2018
1 parent ad7d03c commit db65b9a
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 2 deletions.
13 changes: 12 additions & 1 deletion python/gui/auto_generated/qgsrubberband.sip.in
Expand Up @@ -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.

Expand All @@ -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
Expand Down
12 changes: 12 additions & 0 deletions src/gui/qgsrubberband.cpp
Expand Up @@ -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;
Expand Down
13 changes: 12 additions & 1 deletion src/gui/qgsrubberband.h
Expand Up @@ -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
Expand All @@ -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
Expand Down

0 comments on commit db65b9a

Please sign in to comment.