Skip to content

Commit db65b9a

Browse files
m-kuhnnyalldawson
authored andcommittedSep 29, 2018
Add QgsRubberBand::setToGeometry with crs parameter
1 parent ad7d03c commit db65b9a

File tree

3 files changed

+36
-2
lines changed

3 files changed

+36
-2
lines changed
 

‎python/gui/auto_generated/qgsrubberband.sip.in

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,7 @@ Returns number of vertices in feature part
212212

213213
void setToGeometry( const QgsGeometry &geom, QgsVectorLayer *layer );
214214
%Docstring
215-
Sets this rubber band to the geometry of an existing feature.
215+
Sets this rubber band to ``geom``.
216216
This is useful for feature highlighting.
217217
In contrast to addGeometry(), this method does also change the geometry type of the rubberband.
218218

@@ -221,6 +221,17 @@ In contrast to addGeometry(), this method does also change the geometry type of
221221
crs. In case of 0 pointer, the coordinates are not going to be transformed.
222222
%End
223223

224+
void setToGeometry( const QgsGeometry &geometry, const QgsCoordinateReferenceSystem &crs = QgsCoordinateReferenceSystem() );
225+
%Docstring
226+
Sets this rubber band to ``geometry``.
227+
In contrast to addGeometry(), this method does also change the geometry type of the rubberband.
228+
The coordinate reference system of the geometry can be specified with ``crs``. If an invalid ``crs``
229+
is passed, the geometry will not be reprojected and needs to be in canvas crs already.
230+
By default, no reprojection is done.
231+
232+
.. versionadded:: 3.4
233+
%End
234+
224235
void setToCanvasRectangle( QRect rect );
225236
%Docstring
226237
Sets this rubber band to a map canvas rectangle

‎src/gui/qgsrubberband.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,18 @@ void QgsRubberBand::setToGeometry( const QgsGeometry &geom, QgsVectorLayer *laye
231231
addGeometry( geom, layer );
232232
}
233233

234+
void QgsRubberBand::setToGeometry( const QgsGeometry &geom, const QgsCoordinateReferenceSystem &crs )
235+
{
236+
if ( geom.isNull() )
237+
{
238+
reset( mGeometryType );
239+
return;
240+
}
241+
242+
reset( geom.type() );
243+
addGeometry( geom, crs );
244+
}
245+
234246
void QgsRubberBand::addGeometry( const QgsGeometry &geometry, QgsVectorLayer *layer )
235247
{
236248
QgsGeometry geom = geometry;

‎src/gui/qgsrubberband.h

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,7 @@ class GUI_EXPORT QgsRubberBand: public QgsMapCanvasItem
237237
int partSize( int geometryIndex ) const;
238238

239239
/**
240-
* Sets this rubber band to the geometry of an existing feature.
240+
* Sets this rubber band to \a geom.
241241
* This is useful for feature highlighting.
242242
* In contrast to addGeometry(), this method does also change the geometry type of the rubberband.
243243
* \param geom the geometry object
@@ -246,6 +246,17 @@ class GUI_EXPORT QgsRubberBand: public QgsMapCanvasItem
246246
*/
247247
void setToGeometry( const QgsGeometry &geom, QgsVectorLayer *layer );
248248

249+
/**
250+
* Sets this rubber band to \a geometry.
251+
* In contrast to addGeometry(), this method does also change the geometry type of the rubberband.
252+
* The coordinate reference system of the geometry can be specified with \a crs. If an invalid \a crs
253+
* is passed, the geometry will not be reprojected and needs to be in canvas crs already.
254+
* By default, no reprojection is done.
255+
*
256+
* \since QGIS 3.4
257+
*/
258+
void setToGeometry( const QgsGeometry &geometry, const QgsCoordinateReferenceSystem &crs = QgsCoordinateReferenceSystem() );
259+
249260
/**
250261
* Sets this rubber band to a map canvas rectangle
251262
* \param rect rectangle in canvas coordinates

0 commit comments

Comments
 (0)
Please sign in to comment.