Add QgsRubberBand::setToGeometry with crs parameter

This commit is contained in:
Matthias Kuhn 2018-09-29 10:35:32 +02:00 committed by Nyall Dawson
parent ad7d03c64f
commit db65b9a8fc
3 changed files with 36 additions and 2 deletions

View File

@ -212,7 +212,7 @@ Returns number of vertices in feature part
void setToGeometry( const QgsGeometry &geom, QgsVectorLayer *layer ); void setToGeometry( const QgsGeometry &geom, QgsVectorLayer *layer );
%Docstring %Docstring
Sets this rubber band to the geometry of an existing feature. Sets this rubber band to ``geom``.
This is useful for feature highlighting. This is useful for feature highlighting.
In contrast to addGeometry(), this method does also change the geometry type of the rubberband. 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. crs. In case of 0 pointer, the coordinates are not going to be transformed.
%End %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 ); void setToCanvasRectangle( QRect rect );
%Docstring %Docstring
Sets this rubber band to a map canvas rectangle Sets this rubber band to a map canvas rectangle

View File

@ -231,6 +231,18 @@ void QgsRubberBand::setToGeometry( const QgsGeometry &geom, QgsVectorLayer *laye
addGeometry( geom, layer ); 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 ) void QgsRubberBand::addGeometry( const QgsGeometry &geometry, QgsVectorLayer *layer )
{ {
QgsGeometry geom = geometry; QgsGeometry geom = geometry;

View File

@ -237,7 +237,7 @@ class GUI_EXPORT QgsRubberBand: public QgsMapCanvasItem
int partSize( int geometryIndex ) const; 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. * This is useful for feature highlighting.
* In contrast to addGeometry(), this method does also change the geometry type of the rubberband. * In contrast to addGeometry(), this method does also change the geometry type of the rubberband.
* \param geom the geometry object * \param geom the geometry object
@ -246,6 +246,17 @@ class GUI_EXPORT QgsRubberBand: public QgsMapCanvasItem
*/ */
void setToGeometry( const QgsGeometry &geom, QgsVectorLayer *layer ); 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 * Sets this rubber band to a map canvas rectangle
* \param rect rectangle in canvas coordinates * \param rect rectangle in canvas coordinates