mirror of
https://github.com/qgis/QGIS.git
synced 2025-02-28 00:17:30 -05:00
More efficient canvas features flash
This commit is contained in:
parent
e54ea73e0b
commit
fc844c66d4
@ -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 );
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user