Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix "zoom" and "flash" features buttons have no effect when opening
filter mode in attribute form (For reference: not a regression -- these buttons were originally added for the "select by form" dialog only, and they've just never been hooked up for use inside the attribute form itself!) Fixes #34506
- Loading branch information
1 parent
9fd82dc
commit 6b27958
Showing
7 changed files
with
198 additions
and
46 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
/************************************************************************ | ||
* This file has been generated automatically from * | ||
* * | ||
* src/gui/qgsmapcanvasutils.h * | ||
* * | ||
* Do not edit manually ! Edit header and run scripts/sipify.pl again * | ||
************************************************************************/ | ||
|
||
|
||
|
||
|
||
class QgsMapCanvasUtils | ||
{ | ||
%Docstring | ||
Utility functions for working with QgsMapCanvas widgets. | ||
|
||
.. versionadded:: 3.14 | ||
%End | ||
|
||
%TypeHeaderCode | ||
#include "qgsmapcanvasutils.h" | ||
%End | ||
public: | ||
|
||
static long zoomToMatchingFeatures( QgsMapCanvas *canvas, QgsVectorLayer *layer, const QString &filter ); | ||
%Docstring | ||
Zooms a map ``canvas`` to features from the specified ``layer`` which match the given ``filter`` expression string. | ||
|
||
The total count of matching features will be returned. | ||
%End | ||
|
||
static long flashMatchingFeatures( QgsMapCanvas *canvas, QgsVectorLayer *layer, const QString &filter ); | ||
%Docstring | ||
Flashes features from the specified ``layer`` which match the given ``filter`` expression string with a map ``canvas``. | ||
|
||
The total count of matching features will be returned. | ||
%End | ||
|
||
}; | ||
|
||
/************************************************************************ | ||
* This file has been generated automatically from * | ||
* * | ||
* src/gui/qgsmapcanvasutils.h * | ||
* * | ||
* Do not edit manually ! Edit header and run scripts/sipify.pl again * | ||
************************************************************************/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
/*************************************************************************** | ||
qgsmapcanvasutils.cpp | ||
------------------- | ||
begin : June 2020 | ||
copyright : (C) 2020 by Nyall Dawson | ||
email : nyall dot dawson at gmail dot com | ||
*************************************************************************** | ||
* * | ||
* This program is free software; you can redistribute it and/or modify * | ||
* it under the terms of the GNU General Public License as published by * | ||
* the Free Software Foundation; either version 2 of the License, or * | ||
* (at your option) any later version. * | ||
* * | ||
***************************************************************************/ | ||
|
||
#include "qgsmapcanvasutils.h" | ||
#include "qgsmapcanvas.h" | ||
#include "qgsvectorlayer.h" | ||
#include "qgsexpressioncontextutils.h" | ||
|
||
long QgsMapCanvasUtils::zoomToMatchingFeatures( QgsMapCanvas *canvas, QgsVectorLayer *layer, const QString &filter ) | ||
{ | ||
QgsExpressionContext context( QgsExpressionContextUtils::globalProjectLayerScopes( layer ) ); | ||
|
||
QgsFeatureRequest request = QgsFeatureRequest().setFilterExpression( filter ) | ||
.setExpressionContext( context ) | ||
.setNoAttributes(); | ||
|
||
QgsFeatureIterator features = layer->getFeatures( request ); | ||
|
||
QgsRectangle bbox; | ||
bbox.setMinimal(); | ||
QgsFeature feat; | ||
int featureCount = 0; | ||
while ( features.nextFeature( feat ) ) | ||
{ | ||
QgsGeometry geom = feat.geometry(); | ||
if ( geom.isNull() || geom.constGet()->isEmpty() ) | ||
continue; | ||
|
||
QgsRectangle r = canvas->mapSettings().layerExtentToOutputExtent( layer, geom.boundingBox() ); | ||
bbox.combineExtentWith( r ); | ||
featureCount++; | ||
} | ||
features.close(); | ||
|
||
if ( featureCount > 0 ) | ||
{ | ||
canvas->zoomToFeatureExtent( bbox ); | ||
} | ||
return featureCount; | ||
} | ||
|
||
long QgsMapCanvasUtils::flashMatchingFeatures( QgsMapCanvas *canvas, QgsVectorLayer *layer, const QString &filter ) | ||
{ | ||
QgsExpressionContext context( QgsExpressionContextUtils::globalProjectLayerScopes( layer ) ); | ||
|
||
QgsFeatureRequest request = QgsFeatureRequest().setFilterExpression( filter ) | ||
.setExpressionContext( context ) | ||
.setNoAttributes(); | ||
|
||
QgsFeatureIterator features = layer->getFeatures( request ); | ||
QgsFeature feat; | ||
QList< QgsGeometry > geoms; | ||
while ( features.nextFeature( feat ) ) | ||
{ | ||
if ( feat.hasGeometry() ) | ||
geoms << feat.geometry(); | ||
} | ||
|
||
if ( !geoms.empty() ) | ||
{ | ||
canvas->flashGeometries( geoms, layer->crs() ); | ||
} | ||
return geoms.size(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
/*************************************************************************** | ||
qgsmapcanvasutils.h | ||
------------------- | ||
begin : June 2020 | ||
copyright : (C) 2020 by Nyall Dawson | ||
email : nyall dot dawson at gmail dot com | ||
*************************************************************************** | ||
* * | ||
* This program is free software; you can redistribute it and/or modify * | ||
* it under the terms of the GNU General Public License as published by * | ||
* the Free Software Foundation; either version 2 of the License, or * | ||
* (at your option) any later version. * | ||
* * | ||
***************************************************************************/ | ||
|
||
#ifndef QGSMAPCANVASUTILS_H | ||
#define QGSMAPCANVASUTILS_H | ||
|
||
#include "qgis_gui.h" | ||
|
||
class QgsMapCanvas; | ||
class QgsVectorLayer; | ||
class QString; | ||
|
||
/** | ||
* \ingroup gui | ||
* \class QgsMapCanvasUtils | ||
* Utility functions for working with QgsMapCanvas widgets. | ||
* \since QGIS 3.14 | ||
*/ | ||
class GUI_EXPORT QgsMapCanvasUtils | ||
{ | ||
|
||
public: | ||
|
||
/** | ||
* Zooms a map \a canvas to features from the specified \a layer which match the given \a filter expression string. | ||
* | ||
* The total count of matching features will be returned. | ||
*/ | ||
static long zoomToMatchingFeatures( QgsMapCanvas *canvas, QgsVectorLayer *layer, const QString &filter ); | ||
|
||
/** | ||
* Flashes features from the specified \a layer which match the given \a filter expression string with a map \a canvas. | ||
* | ||
* The total count of matching features will be returned. | ||
*/ | ||
static long flashMatchingFeatures( QgsMapCanvas *canvas, QgsVectorLayer *layer, const QString &filter ); | ||
|
||
}; | ||
|
||
#endif //QGSMAPCANVASUTILS_H |