Skip to content
Permalink
Browse files

More efficient canvas features flash

  • Loading branch information
nyalldawson committed Oct 1, 2017
1 parent e54ea73 commit fc844c66d48d7329b300717776adf5dd013f1579
Showing with 53 additions and 8 deletions.
  1. +21 −0 python/gui/qgsmapcanvas.sip
  2. +5 −5 src/app/qgsselectbyformdialog.cpp
  3. +8 −3 src/gui/qgsmapcanvas.cpp
  4. +19 −0 src/gui/qgsmapcanvas.h
@@ -244,7 +244,28 @@ Pan to the selected features of current (vector) layer keeping same extent.
The ``startColor`` and ``endColor`` can be specified, along with the number of
``flashes`` and ``duration`` of each flash (in milliseconds).

.. note::

If the features or geometries are already available, flashGeometries() is much more efficient.

.. versionadded:: 3.0
.. seealso:: flashGeometries()
%End

void flashGeometries( QgsVectorLayer *layer, const QList< QgsGeometry > &geometries,
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.

The ``startColor`` and ``endColor`` can be specified, along with the number of
``flashes`` and ``duration`` of each flash (in milliseconds).

.. versionadded:: 3.0
.. seealso:: flashFeatureIds()
%End

void setMapTool( QgsMapTool *mapTool );
@@ -119,23 +119,23 @@ void QgsSelectByFormDialog::flashFeatures( const QString &filter )
QgsExpressionContext context( QgsExpressionContextUtils::globalProjectLayerScopes( mLayer ) );

QgsFeatureRequest request = QgsFeatureRequest().setFilterExpression( filter )
.setFlags( QgsFeatureRequest::NoGeometry )
.setExpressionContext( context )
.setSubsetOfAttributes( QgsAttributeList() );

QgsFeatureIterator features = mLayer->getFeatures( request );
QgsFeature feat;
QgsFeatureIds ids;
QList< QgsGeometry > geoms;
while ( features.nextFeature( feat ) )
{
ids.insert( feat.id() );
if ( feat.hasGeometry() )
geoms << feat.geometry();
}

QgsSettings settings;
int timeout = settings.value( QStringLiteral( "qgis/messageTimeout" ), 5 ).toInt();
if ( !ids.empty() )
if ( !geoms.empty() )
{
mMapCanvas->flashFeatureIds( mLayer, ids );
mMapCanvas->flashGeometries( mLayer, geoms );
}
else if ( mMessageBar )
{
@@ -1078,12 +1078,17 @@ void QgsMapCanvas::flashFeatureIds( QgsVectorLayer *layer, const QgsFeatureIds &
geoms << fet.geometry();
}

if ( geoms.isEmpty() )
flashGeometries( layer, geoms, color1, color2, flashes, duration );
}

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

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

if ( geomType == QgsWkbTypes::LineGeometry || geomType == QgsWkbTypes::PointGeometry )
@@ -243,12 +243,31 @@ class GUI_EXPORT QgsMapCanvas : public QGraphicsView
* The \a startColor and \a endColor can be specified, along with the number of
* \a flashes and \a duration of each flash (in milliseconds).
*
* \note If the features or geometries are already available, flashGeometries() is much more efficient.
*
* \since QGIS 3.0
* \see flashGeometries()
*/
void flashFeatureIds( QgsVectorLayer *layer, const QgsFeatureIds &ids,
const QColor &startColor = QColor( 255, 0, 0, 255 ), const QColor &endColor = QColor( 255, 0, 0, 0 ),
int flashes = 3, int duration = 500 );

/**
* 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.
*
* 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,
const QColor &startColor = QColor( 255, 0, 0, 255 ), const QColor &endColor = QColor( 255, 0, 0, 0 ),
int flashes = 3, int duration = 500 );

//! \brief Sets the map tool currently being used on the canvas
void setMapTool( QgsMapTool *mapTool );

0 comments on commit fc844c6

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