Don't identify 3d layers when clicking the terrain

This commit is contained in:
uclaros 2024-12-09 12:30:52 +02:00 committed by Martin Dobias
parent fcaba8aaae
commit 786dca61b3
7 changed files with 37 additions and 15 deletions

View File

@ -212,17 +212,19 @@ Works only if layer was already rendered (triangular mesh is created)
Returns derived attributes map for a clicked point in map coordinates. May be 2D or 3D point.
%End
void setCanvasPropertiesOverrides( double searchRadiusMapUnits );
void setCanvasPropertiesOverrides( double searchRadiusMapUnits, bool skip3DLayers = true );
%Docstring
Overrides some map canvas properties inside the map tool for the upcoming identify requests.
This is useful when the identification is triggered by some other piece of GUI like a 3D map view
and some properties like search radius need to be adjusted so that identification returns correct
results. Currently only search radius may be overridden.
results.
When the custom identification has finished, :py:func:`~QgsMapToolIdentify.restoreCanvasPropertiesOverrides` should
be called to erase any overrides.
:param searchRadiusMapUnits: The overridden search radius in map units
:param skip3DLayers: Optional override to skip identify results from layers that have a 3d renderer set (since QGIS 3.42)
.. seealso:: :py:func:`restoreCanvasPropertiesOverrides`
.. versionadded:: 3.4

View File

@ -212,17 +212,19 @@ Works only if layer was already rendered (triangular mesh is created)
Returns derived attributes map for a clicked point in map coordinates. May be 2D or 3D point.
%End
void setCanvasPropertiesOverrides( double searchRadiusMapUnits );
void setCanvasPropertiesOverrides( double searchRadiusMapUnits, bool skip3DLayers = true );
%Docstring
Overrides some map canvas properties inside the map tool for the upcoming identify requests.
This is useful when the identification is triggered by some other piece of GUI like a 3D map view
and some properties like search radius need to be adjusted so that identification returns correct
results. Currently only search radius may be overridden.
results.
When the custom identification has finished, :py:func:`~QgsMapToolIdentify.restoreCanvasPropertiesOverrides` should
be called to erase any overrides.
:param searchRadiusMapUnits: The overridden search radius in map units
:param skip3DLayers: Optional override to skip identify results from layers that have a 3d renderer set (since QGIS 3.42)
.. seealso:: :py:func:`restoreCanvasPropertiesOverrides`
.. versionadded:: 3.4

View File

@ -172,7 +172,7 @@ void Qgs3DMapToolIdentify::mouseReleaseEvent( QMouseEvent *event )
QgsDebugError( QStringLiteral( "Could not transform identified coordinates to project crs: %1" ).arg( e.what() ) );
}
identifyTool2D->identifyAndShowResults( QgsGeometry::fromPointXY( mapPointCanvas2D ), searchRadiusCanvas2D );
identifyTool2D->identifyAndShowResults( QgsGeometry::fromPointXY( mapPointCanvas2D ), searchRadiusCanvas2D, true );
}
// We need to show other layer type results AFTER terrain results so they don't get overwritten

View File

@ -207,9 +207,9 @@ void QgsMapToolIdentifyAction::deactivate()
QgsMapToolIdentify::deactivate();
}
void QgsMapToolIdentifyAction::identifyAndShowResults( const QgsGeometry &geom, double searchRadiusMapUnits )
void QgsMapToolIdentifyAction::identifyAndShowResults( const QgsGeometry &geom, double searchRadiusMapUnits, bool skip3DLayers )
{
setCanvasPropertiesOverrides( searchRadiusMapUnits );
setCanvasPropertiesOverrides( searchRadiusMapUnits, skip3DLayers );
mSelectionHandler->setSelectedGeometry( geom );
restoreCanvasPropertiesOverrides();
}

View File

@ -58,8 +58,12 @@ class APP_EXPORT QgsMapToolIdentifyAction : public QgsMapToolIdentify
void deactivate() override;
//! Triggers map identification of at the given location and outputs results in GUI
void identifyAndShowResults( const QgsGeometry &geom, double searchRadiusMapUnits );
/**
* Triggers map identification at the given location and outputs results in GUI
* \param searchRadiusMapUnits The search radius to use for identification in map units
* \param skip3DLayers When set to TRUE only layers with no 3d renderer set will be identified
*/
void identifyAndShowResults( const QgsGeometry &geom, double searchRadiusMapUnits, bool skip3DLayers );
//! Clears any previous results from the GUI
void clearResults();
//! Looks up feature by its ID and outputs the result in GUI

View File

@ -189,14 +189,16 @@ QList<QgsMapToolIdentify::IdentifyResult> QgsMapToolIdentify::identify( const Qg
return results;
}
void QgsMapToolIdentify::setCanvasPropertiesOverrides( double searchRadiusMapUnits )
void QgsMapToolIdentify::setCanvasPropertiesOverrides( double searchRadiusMapUnits, bool skip3DLayers )
{
mOverrideCanvasSearchRadius = searchRadiusMapUnits;
mSkip3DLayers = skip3DLayers;
}
void QgsMapToolIdentify::restoreCanvasPropertiesOverrides()
{
mOverrideCanvasSearchRadius = -1;
mSkip3DLayers = false;
}
void QgsMapToolIdentify::activate()
@ -280,6 +282,9 @@ bool QgsMapToolIdentify::identifyMeshLayer( QList<QgsMapToolIdentify::IdentifyRe
if ( !layer )
return false;
if ( mSkip3DLayers && layer->renderer3D() )
return false;
if ( !identifyContext.zRange().isInfinite() )
{
if ( !layer->elevationProperties()->isVisibleInZRange( identifyContext.zRange() ) )
@ -535,6 +540,9 @@ bool QgsMapToolIdentify::identifyVectorTileLayer( QList<QgsMapToolIdentify::Iden
bool QgsMapToolIdentify::identifyPointCloudLayer( QList<QgsMapToolIdentify::IdentifyResult> *results, QgsPointCloudLayer *layer, const QgsGeometry &geometry, const QgsIdentifyContext &identifyContext )
{
if ( mSkip3DLayers && layer->renderer3D() )
return false;
if ( !identifyContext.zRange().isInfinite() )
{
if ( !layer->elevationProperties()->isVisibleInZRange( identifyContext.zRange(), layer ) )
@ -577,6 +585,9 @@ bool QgsMapToolIdentify::identifyVectorLayer( QList<QgsMapToolIdentify::Identify
if ( !layer || !layer->isSpatial() || !layer->dataProvider() )
return false;
if ( mSkip3DLayers && layer->renderer3D() )
return false;
if ( !layer->isInScaleRange( mCanvas->mapSettings().scale() ) )
{
QgsDebugMsgLevel( QStringLiteral( "Out of scale limits" ), 2 );

View File

@ -243,14 +243,16 @@ class GUI_EXPORT QgsMapToolIdentify : public QgsMapTool
*
* This is useful when the identification is triggered by some other piece of GUI like a 3D map view
* and some properties like search radius need to be adjusted so that identification returns correct
* results. Currently only search radius may be overridden.
*
* results.
* When the custom identification has finished, restoreCanvasPropertiesOverrides() should
* be called to erase any overrides.
*
* \param searchRadiusMapUnits The overridden search radius in map units
* \param skip3DLayers Optional override to skip identify results from layers that have a 3d renderer set (since QGIS 3.42)
* \see restoreCanvasPropertiesOverrides()
* \since QGIS 3.4
*/
void setCanvasPropertiesOverrides( double searchRadiusMapUnits );
void setCanvasPropertiesOverrides( double searchRadiusMapUnits, bool skip3DLayers = true );
/**
* Clears canvas properties overrides previously set with setCanvasPropertiesOverrides()
@ -329,6 +331,7 @@ class GUI_EXPORT QgsMapToolIdentify : public QgsMapTool
int mCoordinatePrecision;
double mOverrideCanvasSearchRadius = -1;
bool mSkip3DLayers = false;
};
Q_DECLARE_OPERATORS_FOR_FLAGS( QgsMapToolIdentify::LayerType )