mirror of
https://github.com/qgis/QGIS.git
synced 2025-12-04 00:06:46 -05:00
Move method to a common place
This commit is contained in:
parent
8986c43748
commit
f9fe7e4311
@ -36,6 +36,17 @@ Flashes features from the specified ``layer`` which match the given ``filter`` e
|
||||
The total count of matching features will be returned.
|
||||
%End
|
||||
|
||||
static QString filterForLayer( QgsMapCanvas *canvas, QgsVectorLayer *layer );
|
||||
%Docstring
|
||||
Constructs a filter to use for selecting features from the given ``layer``, in order to
|
||||
apply filters which prevent some features from being displayed (e.g. as a result
|
||||
of temporal range of the canvas and the layer's temporal settings).
|
||||
|
||||
Will return an empty string if no filtering is required, or "``False``" if ALL features are filtered
|
||||
out by the canvas.
|
||||
|
||||
.. versionadded:: 3.26
|
||||
%End
|
||||
};
|
||||
|
||||
/************************************************************************
|
||||
|
||||
@ -34,6 +34,7 @@ email : jpalmer at linz dot govt dot nz
|
||||
#include "qgsexpressioncontextutils.h"
|
||||
#include "qgsmessagelog.h"
|
||||
#include "qgsvectorlayertemporalproperties.h"
|
||||
#include "qgsmapcanvasutils.h"
|
||||
|
||||
#include <QMouseEvent>
|
||||
#include <QApplication>
|
||||
@ -264,16 +265,9 @@ QgsFeatureIds QgsMapToolSelectUtils::getMatchingFeatures( QgsMapCanvas *canvas,
|
||||
r->startRender( context, vlayer->fields() );
|
||||
}
|
||||
|
||||
QString temporalFilter;
|
||||
if ( canvas->mapSettings().isTemporal() )
|
||||
{
|
||||
if ( !vlayer->temporalProperties()->isVisibleInTemporalRange( canvas->temporalRange() ) )
|
||||
return newSelectedFeatures;
|
||||
|
||||
QgsVectorLayerTemporalContext temporalContext;
|
||||
temporalContext.setLayer( vlayer );
|
||||
temporalFilter = qobject_cast< const QgsVectorLayerTemporalProperties * >( vlayer->temporalProperties() )->createFilterString( temporalContext, canvas->temporalRange() );
|
||||
}
|
||||
const QString canvasFilter = QgsMapCanvasUtils::filterForLayer( canvas, vlayer );
|
||||
if ( canvasFilter == QLatin1String( "FALSE" ) )
|
||||
return newSelectedFeatures;
|
||||
|
||||
QgsFeatureRequest request;
|
||||
request.setFilterRect( selectGeomTrans.boundingBox() );
|
||||
@ -283,8 +277,8 @@ QgsFeatureIds QgsMapToolSelectUtils::getMatchingFeatures( QgsMapCanvas *canvas,
|
||||
else
|
||||
request.setNoAttributes();
|
||||
|
||||
if ( !temporalFilter.isEmpty() )
|
||||
request.setFilterExpression( temporalFilter );
|
||||
if ( !canvasFilter.isEmpty() )
|
||||
request.setFilterExpression( canvasFilter );
|
||||
if ( r )
|
||||
{
|
||||
const QString filterExpression = r->filter( vlayer->fields() );
|
||||
@ -415,23 +409,16 @@ void QgsMapToolSelectUtils::QgsMapToolSelectMenuActions::populateMenu( QMenu *me
|
||||
|
||||
void QgsMapToolSelectUtils::QgsMapToolSelectMenuActions::startFeatureSearch()
|
||||
{
|
||||
QString temporalFilter;
|
||||
if ( mCanvas->mapSettings().isTemporal() )
|
||||
{
|
||||
if ( !mVectorLayer->temporalProperties()->isVisibleInTemporalRange( mCanvas->temporalRange() ) )
|
||||
return;
|
||||
|
||||
QgsVectorLayerTemporalContext temporalContext;
|
||||
temporalContext.setLayer( mVectorLayer );
|
||||
temporalFilter = qobject_cast< const QgsVectorLayerTemporalProperties * >( mVectorLayer->temporalProperties() )->createFilterString( temporalContext, mCanvas->temporalRange() );
|
||||
}
|
||||
const QString canvasFilter = QgsMapCanvasUtils::filterForLayer( mCanvas, mVectorLayer );
|
||||
if ( canvasFilter == QLatin1String( "FALSE" ) )
|
||||
return;
|
||||
|
||||
mJobData = std::make_shared<DataForSearchingJob>();
|
||||
mJobData->isCanceled = false;
|
||||
mJobData->source.reset( new QgsVectorLayerFeatureSource( mVectorLayer ) );
|
||||
mJobData->selectGeometry = mSelectGeometry;
|
||||
mJobData->context = QgsRenderContext::fromMapSettings( mCanvas->mapSettings() );
|
||||
mJobData->filterString = temporalFilter;
|
||||
mJobData->filterString = canvasFilter;
|
||||
mJobData->ct = QgsCoordinateTransform( mCanvas->mapSettings().destinationCrs(), mVectorLayer->crs(), mJobData->context.transformContext() );
|
||||
mJobData->featureRenderer.reset( mVectorLayer->renderer()->clone() );
|
||||
|
||||
|
||||
@ -30,6 +30,7 @@
|
||||
#include "qgsapplication.h"
|
||||
#include "qgsvectorlayercache.h"
|
||||
#include "qgsrendercontext.h"
|
||||
#include "qgsmapcanvasutils.h"
|
||||
|
||||
//////////////////
|
||||
// Filter Model //
|
||||
@ -624,17 +625,11 @@ void QgsAttributeTableFilterModel::generateListOfVisibleFeatures()
|
||||
r.setFilterRect( rect );
|
||||
}
|
||||
|
||||
if ( mCanvas->mapSettings().isTemporal() )
|
||||
{
|
||||
if ( !layer()->temporalProperties()->isVisibleInTemporalRange( mCanvas->mapSettings().temporalRange() ) )
|
||||
return;
|
||||
|
||||
QgsVectorLayerTemporalContext temporalContext;
|
||||
temporalContext.setLayer( layer() );
|
||||
const QString temporalFilter = qobject_cast< const QgsVectorLayerTemporalProperties * >( layer()->temporalProperties() )->createFilterString( temporalContext, mCanvas->mapSettings().temporalRange() );
|
||||
if ( !temporalFilter.isEmpty() )
|
||||
r.setFilterExpression( temporalFilter );
|
||||
}
|
||||
const QString canvasFilter = QgsMapCanvasUtils::filterForLayer( mCanvas, layer() );
|
||||
if ( canvasFilter == QLatin1String( "FALSE" ) )
|
||||
return;
|
||||
if ( !canvasFilter.isEmpty() )
|
||||
r.setFilterExpression( canvasFilter );
|
||||
|
||||
QgsFeatureIterator features = masterModel()->layerCache()->getFeatures( r );
|
||||
|
||||
|
||||
@ -17,6 +17,7 @@
|
||||
#include "qgsmapcanvas.h"
|
||||
#include "qgsvectorlayer.h"
|
||||
#include "qgsexpressioncontextutils.h"
|
||||
#include "qgsvectorlayertemporalproperties.h"
|
||||
|
||||
long QgsMapCanvasUtils::zoomToMatchingFeatures( QgsMapCanvas *canvas, QgsVectorLayer *layer, const QString &filter )
|
||||
{
|
||||
@ -74,3 +75,20 @@ long QgsMapCanvasUtils::flashMatchingFeatures( QgsMapCanvas *canvas, QgsVectorLa
|
||||
}
|
||||
return geoms.size();
|
||||
}
|
||||
|
||||
QString QgsMapCanvasUtils::filterForLayer( QgsMapCanvas *canvas, QgsVectorLayer *layer )
|
||||
{
|
||||
if ( canvas->mapSettings().isTemporal() )
|
||||
{
|
||||
if ( !layer->temporalProperties()->isVisibleInTemporalRange( canvas->temporalRange() ) )
|
||||
return QStringLiteral( "FALSE" );
|
||||
|
||||
QgsVectorLayerTemporalContext temporalContext;
|
||||
temporalContext.setLayer( layer );
|
||||
return qobject_cast< const QgsVectorLayerTemporalProperties * >( layer->temporalProperties() )->createFilterString( temporalContext, canvas->temporalRange() );
|
||||
}
|
||||
else
|
||||
{
|
||||
return QString();
|
||||
}
|
||||
}
|
||||
|
||||
@ -47,6 +47,17 @@ class GUI_EXPORT QgsMapCanvasUtils
|
||||
*/
|
||||
static long flashMatchingFeatures( QgsMapCanvas *canvas, QgsVectorLayer *layer, const QString &filter );
|
||||
|
||||
/**
|
||||
* Constructs a filter to use for selecting features from the given \a layer, in order to
|
||||
* apply filters which prevent some features from being displayed (e.g. as a result
|
||||
* of temporal range of the canvas and the layer's temporal settings).
|
||||
*
|
||||
* Will return an empty string if no filtering is required, or "FALSE" if ALL features are filtered
|
||||
* out by the canvas.
|
||||
*
|
||||
* \since QGIS 3.26
|
||||
*/
|
||||
static QString filterForLayer( QgsMapCanvas *canvas, QgsVectorLayer *layer );
|
||||
};
|
||||
|
||||
#endif //QGSMAPCANVASUTILS_H
|
||||
|
||||
@ -28,6 +28,7 @@
|
||||
#include "qgsmaplayertemporalproperties.h"
|
||||
#include "qgsvectorlayertemporalproperties.h"
|
||||
#include "qgsrendercontext.h"
|
||||
#include "qgsmapcanvasutils.h"
|
||||
|
||||
// Qt includes
|
||||
#include <QPoint>
|
||||
@ -211,16 +212,9 @@ QString QgsMapTip::fetchFeature( QgsMapLayer *layer, QgsPointXY &mapPosition, Qg
|
||||
QgsExpressionContext context( QgsExpressionContextUtils::globalProjectLayerScopes( vlayer ) );
|
||||
context.appendScope( QgsExpressionContextUtils::mapSettingsScope( mapCanvas->mapSettings() ) );
|
||||
|
||||
QString temporalFilter;
|
||||
if ( mapCanvas->mapSettings().isTemporal() )
|
||||
{
|
||||
if ( !layer->temporalProperties()->isVisibleInTemporalRange( mapCanvas->temporalRange() ) )
|
||||
return QString();
|
||||
|
||||
QgsVectorLayerTemporalContext temporalContext;
|
||||
temporalContext.setLayer( vlayer );
|
||||
temporalFilter = qobject_cast< const QgsVectorLayerTemporalProperties * >( layer->temporalProperties() )->createFilterString( temporalContext, mapCanvas->temporalRange() );
|
||||
}
|
||||
const QString canvasFilter = QgsMapCanvasUtils::filterForLayer( mapCanvas, vlayer );
|
||||
if ( canvasFilter == QLatin1String( "FALSE" ) )
|
||||
return QString();
|
||||
|
||||
const QString mapTip = vlayer->mapTipTemplate();
|
||||
QString tipString;
|
||||
@ -230,8 +224,8 @@ QString QgsMapTip::fetchFeature( QgsMapLayer *layer, QgsPointXY &mapPosition, Qg
|
||||
QgsFeatureRequest request;
|
||||
request.setFilterRect( r );
|
||||
request.setFlags( QgsFeatureRequest::ExactIntersect );
|
||||
if ( !temporalFilter.isEmpty() )
|
||||
request.setFilterExpression( temporalFilter );
|
||||
if ( !canvasFilter.isEmpty() )
|
||||
request.setFilterExpression( canvasFilter );
|
||||
|
||||
if ( mapTip.isEmpty() )
|
||||
{
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user