Skip to content
Permalink
Browse files

Refine flash features API

Use a QgsCoordinateReferenceSystem object instead of
QgsVectorLayer to make API more flexible
  • Loading branch information
nyalldawson committed Oct 2, 2017
1 parent dfe0cba commit 5b6f02ecdeef9850347362324123c8964271f9cb
@@ -252,14 +252,14 @@ Pan to the selected features of current (vector) layer keeping same extent.
.. seealso:: flashGeometries()
%End

void flashGeometries( QgsVectorLayer *layer, const QList< QgsGeometry > &geometries,
void flashGeometries( const QList< QgsGeometry > &geometries, const QgsCoordinateReferenceSystem &crs = QgsCoordinateReferenceSystem(),
const QColor &startColor = QColor( 255, 0, 0, 255 ), const QColor &endColor = QColor( 255, 0, 0, 0 ),
int flashes = 3, int duration = 500 );
%Docstring
Causes a set of ``geometries`` to flash within the canvas.

If ``layer`` is non-null, the geometries will be automatically transformed from the layer
CRS to canvas CRS.
If ``crs`` is a valid coordinate reference system, the geometries will be automatically
transformed from this CRS to the canvas CRS.

The ``startColor`` and ``endColor`` can be specified, along with the number of
``flashes`` and ``duration`` of each flash (in milliseconds).
@@ -216,19 +216,29 @@ for tracking the mouse while drawing polylines or polygons.
\param rect rectangle in canvas coordinates
%End

void addGeometry( const QgsGeometry &geom, QgsVectorLayer *layer );
void addGeometry( const QgsGeometry &geometry, QgsVectorLayer *layer );
%Docstring
Adds the geometry of an existing feature to a rubberband
This is useful for multi feature highlighting.
As of 2.0, this method does not change the GeometryType any more. You need to set the GeometryType
of the rubberband explicitly by calling reset() or setToGeometry() with appropriate arguments.
setToGeometry() is also to be preferred for backwards-compatibility.

\param geom the geometry object. Will be treated as a collection of vertices.
\param geometry the geometry object. Will be treated as a collection of vertices.
\param layer the layer containing the feature, used for coord transformation to map
crs. In case of 0 pointer, the coordinates are not going to be transformed.
%End

void addGeometry( const QgsGeometry &geometry, const QgsCoordinateReferenceSystem &crs = QgsCoordinateReferenceSystem() );
%Docstring
Adds a ``geometry`` to the rubberband.

If ``crs`` is specified, the geometry will be automatically reprojected from ``crs``
to the canvas CRS.

.. versionadded:: 3.0
%End

void setTranslationOffset( double dx, double dy );
%Docstring
Adds translation to original coordinates (all in map coordinates)
@@ -135,7 +135,7 @@ void QgsSelectByFormDialog::flashFeatures( const QString &filter )
int timeout = settings.value( QStringLiteral( "qgis/messageTimeout" ), 5 ).toInt();
if ( !geoms.empty() )
{
mMapCanvas->flashGeometries( mLayer, geoms );
mMapCanvas->flashGeometries( geoms, mLayer->crs() );
}
else if ( mMessageBar )
{
@@ -1078,18 +1078,18 @@ void QgsMapCanvas::flashFeatureIds( QgsVectorLayer *layer, const QgsFeatureIds &
geoms << fet.geometry();
}

flashGeometries( layer, geoms, color1, color2, flashes, duration );
flashGeometries( geoms, layer->crs(), color1, color2, flashes, duration );
}

void QgsMapCanvas::flashGeometries( QgsVectorLayer *layer, const QList<QgsGeometry> &geometries, const QColor &color1, const QColor &color2, int flashes, int duration )
void QgsMapCanvas::flashGeometries( const QList<QgsGeometry> &geometries, const QgsCoordinateReferenceSystem &crs, const QColor &color1, const QColor &color2, int flashes, int duration )
{
if ( geometries.isEmpty() )
return;

QgsWkbTypes::GeometryType geomType = QgsWkbTypes::geometryType( geometries.at( 0 ).wkbType() );
QgsRubberBand *rb = new QgsRubberBand( this, geomType );
for ( const QgsGeometry &geom : geometries )
rb->addGeometry( geom, layer );
rb->addGeometry( geom, crs );

if ( geomType == QgsWkbTypes::LineGeometry || geomType == QgsWkbTypes::PointGeometry )
{
@@ -255,16 +255,16 @@ class GUI_EXPORT QgsMapCanvas : public QGraphicsView
/**
* Causes a set of \a geometries to flash within the canvas.
*
* If \a layer is non-null, the geometries will be automatically transformed from the layer
* CRS to canvas CRS.
* If \a crs is a valid coordinate reference system, the geometries will be automatically
* transformed from this CRS to the canvas CRS.
*
* The \a startColor and \a endColor can be specified, along with the number of
* \a flashes and \a duration of each flash (in milliseconds).
*
* \since QGIS 3.0
* \see flashFeatureIds()
*/
void flashGeometries( QgsVectorLayer *layer, const QList< QgsGeometry > &geometries,
void flashGeometries( const QList< QgsGeometry > &geometries, const QgsCoordinateReferenceSystem &crs = QgsCoordinateReferenceSystem(),
const QColor &startColor = QColor( 255, 0, 0, 255 ), const QColor &endColor = QColor( 255, 0, 0, 0 ),
int flashes = 3, int duration = 500 );

@@ -231,6 +231,18 @@ void QgsRubberBand::setToGeometry( const QgsGeometry &geom, QgsVectorLayer *laye
}

void QgsRubberBand::addGeometry( const QgsGeometry &geometry, QgsVectorLayer *layer )
{
QgsGeometry geom = geometry;
if ( layer )
{
QgsCoordinateTransform ct = mMapCanvas->mapSettings().layerTransform( layer );
geom.transform( ct );
}

addGeometry( geom );
}

void QgsRubberBand::addGeometry( const QgsGeometry &geometry, const QgsCoordinateReferenceSystem &crs )
{
if ( geometry.isEmpty() )
{
@@ -243,9 +255,9 @@ void QgsRubberBand::addGeometry( const QgsGeometry &geometry, QgsVectorLayer *la
int idx = mPoints.size();

QgsGeometry geom = geometry;
if ( layer )
if ( crs.isValid() )
{
QgsCoordinateTransform ct = ms.layerTransform( layer );
QgsCoordinateTransform ct( crs, ms.destinationCrs() );
geom.transform( ct );
}

@@ -257,11 +257,21 @@ class GUI_EXPORT QgsRubberBand: public QgsMapCanvasItem
* of the rubberband explicitly by calling reset() or setToGeometry() with appropriate arguments.
* setToGeometry() is also to be preferred for backwards-compatibility.
*
* \param geom the geometry object. Will be treated as a collection of vertices.
* \param geometry the geometry object. Will be treated as a collection of vertices.
* \param layer the layer containing the feature, used for coord transformation to map
* crs. In case of 0 pointer, the coordinates are not going to be transformed.
*/
void addGeometry( const QgsGeometry &geom, QgsVectorLayer *layer );
void addGeometry( const QgsGeometry &geometry, QgsVectorLayer *layer );

/**
* Adds a \a geometry to the rubberband.
*
* If \a crs is specified, the geometry will be automatically reprojected from \a crs
* to the canvas CRS.
*
* \since QGIS 3.0
*/
void addGeometry( const QgsGeometry &geometry, const QgsCoordinateReferenceSystem &crs = QgsCoordinateReferenceSystem() );

/**
* Adds translation to original coordinates (all in map coordinates)

0 comments on commit 5b6f02e

Please sign in to comment.
You can’t perform that action at this time.