diff --git a/python/PyQt6/gui/auto_additions/qgsmaptoolidentify.py b/python/PyQt6/gui/auto_additions/qgsmaptoolidentify.py index 10a8e6a2526..c411ac98509 100644 --- a/python/PyQt6/gui/auto_additions/qgsmaptoolidentify.py +++ b/python/PyQt6/gui/auto_additions/qgsmaptoolidentify.py @@ -24,6 +24,11 @@ QgsMapToolIdentify.Type.__bool__ = lambda flag: bool(_force_int(flag)) QgsMapToolIdentify.Type.__eq__ = lambda flag1, flag2: _force_int(flag1) == _force_int(flag2) QgsMapToolIdentify.Type.__and__ = lambda flag1, flag2: _force_int(flag1) & _force_int(flag2) QgsMapToolIdentify.Type.__or__ = lambda flag1, flag2: QgsMapToolIdentify.Type(_force_int(flag1) | _force_int(flag2)) +try: + QgsMapToolIdentify.IdentifyProperties.__attribute_docs__ = {'searchRadiusMapUnits': 'Identify search radius is map units. Use negative value to ignore', 'skip3DLayers': 'Skip identify results from layers that have a 3d renderer set'} + QgsMapToolIdentify.IdentifyProperties.__group__ = ['maptools'] +except (NameError, AttributeError): + pass try: QgsMapToolIdentify.__attribute_docs__ = {'identifyProgress': 'Emitted when the identify action progresses.\n\n:param processed: number of objects processed so far\n:param total: total number of objects to process\n', 'identifyMessage': 'Emitted when the identify operation needs to show a user-facing message\n\n:param message: Message to show to the user\n', 'changedRasterResults': 'Emitted when the format of raster ``results`` is changed and need to be updated in user-facing displays.\n'} QgsMapToolIdentify.__signal_arguments__ = {'identifyProgress': ['processed: int', 'total: int'], 'identifyMessage': ['message: str'], 'changedRasterResults': ['results: List[QgsMapToolIdentify.IdentifyResult]']} diff --git a/python/PyQt6/gui/auto_generated/maptools/qgsmaptoolidentify.sip.in b/python/PyQt6/gui/auto_generated/maptools/qgsmaptoolidentify.sip.in index cb7d9b2dc7b..33a59501aac 100644 --- a/python/PyQt6/gui/auto_generated/maptools/qgsmaptoolidentify.sip.in +++ b/python/PyQt6/gui/auto_generated/maptools/qgsmaptoolidentify.sip.in @@ -63,6 +63,12 @@ after selecting a point, performs the identification: QMap mParams; }; + struct IdentifyProperties + { + double searchRadiusMapUnits; + bool skip3DLayers; + }; + QgsMapToolIdentify( QgsMapCanvas *canvas ); %Docstring constructor @@ -212,7 +218,7 @@ 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, bool skip3DLayers = true ); + void setCanvasPropertiesOverrides( double searchRadiusMapUnits ) /Deprecated/; %Docstring Overrides some map canvas properties inside the map tool for the upcoming identify requests. @@ -228,15 +234,47 @@ be called to erase any overrides. .. seealso:: :py:func:`restoreCanvasPropertiesOverrides` .. versionadded:: 3.4 + +.. deprecated:: 3.42 + + Use :py:func:`~QgsMapToolIdentify.setPropertiesOverrides` instead. %End - void restoreCanvasPropertiesOverrides(); + void restoreCanvasPropertiesOverrides() /Deprecated/; %Docstring Clears canvas properties overrides previously set with :py:func:`~QgsMapToolIdentify.setCanvasPropertiesOverrides` .. seealso:: :py:func:`setCanvasPropertiesOverrides` .. versionadded:: 3.4 + +.. deprecated:: 3.42 + + Use :py:func:`~QgsMapToolIdentify.restorePropertiesOverrides` instead. +%End + + void setPropertiesOverrides( IdentifyProperties overrides ); +%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. +When the custom identification has finished, :py:func:`~QgsMapToolIdentify.restorePropertiesOverrides` should +be called to erase any overrides. + +:param overrides: The identify tool properties that will be overridden + +.. versionadded:: 3.42 +%End + + void restorePropertiesOverrides(); +%Docstring +Clears canvas properties overrides previously set with :py:func:`~QgsMapToolIdentify.setPropertiesOverrides` + +.. seealso:: :py:func:`setPropertiesOverrides` + +.. versionadded:: 3.42 %End }; diff --git a/python/gui/auto_additions/qgsmaptoolidentify.py b/python/gui/auto_additions/qgsmaptoolidentify.py index 898fb366ed2..a18dc066af3 100644 --- a/python/gui/auto_additions/qgsmaptoolidentify.py +++ b/python/gui/auto_additions/qgsmaptoolidentify.py @@ -2,6 +2,11 @@ QgsMapToolIdentify.IdentifyMode.baseClass = QgsMapToolIdentify QgsMapToolIdentify.LayerType.baseClass = QgsMapToolIdentify LayerType = QgsMapToolIdentify # dirty hack since SIP seems to introduce the flags in module +try: + QgsMapToolIdentify.IdentifyProperties.__attribute_docs__ = {'searchRadiusMapUnits': 'Identify search radius is map units. Use negative value to ignore', 'skip3DLayers': 'Skip identify results from layers that have a 3d renderer set'} + QgsMapToolIdentify.IdentifyProperties.__group__ = ['maptools'] +except (NameError, AttributeError): + pass try: QgsMapToolIdentify.__attribute_docs__ = {'identifyProgress': 'Emitted when the identify action progresses.\n\n:param processed: number of objects processed so far\n:param total: total number of objects to process\n', 'identifyMessage': 'Emitted when the identify operation needs to show a user-facing message\n\n:param message: Message to show to the user\n', 'changedRasterResults': 'Emitted when the format of raster ``results`` is changed and need to be updated in user-facing displays.\n'} QgsMapToolIdentify.__signal_arguments__ = {'identifyProgress': ['processed: int', 'total: int'], 'identifyMessage': ['message: str'], 'changedRasterResults': ['results: List[QgsMapToolIdentify.IdentifyResult]']} diff --git a/python/gui/auto_generated/maptools/qgsmaptoolidentify.sip.in b/python/gui/auto_generated/maptools/qgsmaptoolidentify.sip.in index 7043f14fc41..8f6797ae4a5 100644 --- a/python/gui/auto_generated/maptools/qgsmaptoolidentify.sip.in +++ b/python/gui/auto_generated/maptools/qgsmaptoolidentify.sip.in @@ -63,6 +63,12 @@ after selecting a point, performs the identification: QMap mParams; }; + struct IdentifyProperties + { + double searchRadiusMapUnits; + bool skip3DLayers; + }; + QgsMapToolIdentify( QgsMapCanvas *canvas ); %Docstring constructor @@ -212,7 +218,7 @@ 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, bool skip3DLayers = true ); + void setCanvasPropertiesOverrides( double searchRadiusMapUnits ) /Deprecated/; %Docstring Overrides some map canvas properties inside the map tool for the upcoming identify requests. @@ -228,15 +234,47 @@ be called to erase any overrides. .. seealso:: :py:func:`restoreCanvasPropertiesOverrides` .. versionadded:: 3.4 + +.. deprecated:: 3.42 + + Use :py:func:`~QgsMapToolIdentify.setPropertiesOverrides` instead. %End - void restoreCanvasPropertiesOverrides(); + void restoreCanvasPropertiesOverrides() /Deprecated/; %Docstring Clears canvas properties overrides previously set with :py:func:`~QgsMapToolIdentify.setCanvasPropertiesOverrides` .. seealso:: :py:func:`setCanvasPropertiesOverrides` .. versionadded:: 3.4 + +.. deprecated:: 3.42 + + Use :py:func:`~QgsMapToolIdentify.restorePropertiesOverrides` instead. +%End + + void setPropertiesOverrides( IdentifyProperties overrides ); +%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. +When the custom identification has finished, :py:func:`~QgsMapToolIdentify.restorePropertiesOverrides` should +be called to erase any overrides. + +:param overrides: The identify tool properties that will be overridden + +.. versionadded:: 3.42 +%End + + void restorePropertiesOverrides(); +%Docstring +Clears canvas properties overrides previously set with :py:func:`~QgsMapToolIdentify.setPropertiesOverrides` + +.. seealso:: :py:func:`setPropertiesOverrides` + +.. versionadded:: 3.42 %End }; diff --git a/src/app/3d/qgs3dmaptoolidentify.cpp b/src/app/3d/qgs3dmaptoolidentify.cpp index d634c9ca8d4..21ee7dfdbaf 100644 --- a/src/app/3d/qgs3dmaptoolidentify.cpp +++ b/src/app/3d/qgs3dmaptoolidentify.cpp @@ -139,10 +139,7 @@ void Qgs3DMapToolIdentify::mouseReleaseEvent( QMouseEvent *event ) } } - // We only handle terrain results if there were no vector layer results because: - // a. terrain results will overwrite other existing results. - // b. terrain results use 2d identify logic and may contain results from vector layers that - // are not actually rendered on the terrain as they have a 3d renderer set. + // We only handle terrain results if there were no vector layer results so they don't get overwritten if ( showTerrainResults && allHits.contains( nullptr ) ) { const QgsRayCastingUtils::RayHit hit = allHits.value( nullptr ).first(); @@ -172,7 +169,10 @@ 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, true ); + QgsMapToolIdentify::IdentifyProperties props; + props.searchRadiusMapUnits = searchRadiusCanvas2D; + props.skip3DLayers = true; + identifyTool2D->identifyAndShowResults( QgsGeometry::fromPointXY( mapPointCanvas2D ), props ); } // We need to show other layer type results AFTER terrain results so they don't get overwritten diff --git a/src/app/qgsmaptoolidentifyaction.cpp b/src/app/qgsmaptoolidentifyaction.cpp index e38b0094fe4..d4ddb40e6f5 100644 --- a/src/app/qgsmaptoolidentifyaction.cpp +++ b/src/app/qgsmaptoolidentifyaction.cpp @@ -207,11 +207,11 @@ void QgsMapToolIdentifyAction::deactivate() QgsMapToolIdentify::deactivate(); } -void QgsMapToolIdentifyAction::identifyAndShowResults( const QgsGeometry &geom, double searchRadiusMapUnits, bool skip3DLayers ) +void QgsMapToolIdentifyAction::identifyAndShowResults( const QgsGeometry &geom, IdentifyProperties properties ) { - setCanvasPropertiesOverrides( searchRadiusMapUnits, skip3DLayers ); + setPropertiesOverrides( properties ); mSelectionHandler->setSelectedGeometry( geom ); - restoreCanvasPropertiesOverrides(); + restorePropertiesOverrides(); } void QgsMapToolIdentifyAction::clearResults() diff --git a/src/app/qgsmaptoolidentifyaction.h b/src/app/qgsmaptoolidentifyaction.h index df6df90e64b..94ff3452abc 100644 --- a/src/app/qgsmaptoolidentifyaction.h +++ b/src/app/qgsmaptoolidentifyaction.h @@ -60,10 +60,10 @@ class APP_EXPORT QgsMapToolIdentifyAction : public QgsMapToolIdentify /** * 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 + * \param geom The geometry to use for identification + * \param properties Sets overridden properties for this identification, like search radius */ - void identifyAndShowResults( const QgsGeometry &geom, double searchRadiusMapUnits, bool skip3DLayers ); + void identifyAndShowResults( const QgsGeometry &geom, IdentifyProperties properties ); //! Clears any previous results from the GUI void clearResults(); //! Looks up feature by its ID and outputs the result in GUI diff --git a/src/gui/maptools/qgsmaptoolidentify.cpp b/src/gui/maptools/qgsmaptoolidentify.cpp index 43656da3848..7d7df150cd4 100644 --- a/src/gui/maptools/qgsmaptoolidentify.cpp +++ b/src/gui/maptools/qgsmaptoolidentify.cpp @@ -189,16 +189,26 @@ QList QgsMapToolIdentify::identify( const Qg return results; } -void QgsMapToolIdentify::setCanvasPropertiesOverrides( double searchRadiusMapUnits, bool skip3DLayers ) +void QgsMapToolIdentify::setCanvasPropertiesOverrides( double searchRadiusMapUnits ) { - mOverrideCanvasSearchRadius = searchRadiusMapUnits; - mSkip3DLayers = skip3DLayers; + mPropertiesOverrides.searchRadiusMapUnits = searchRadiusMapUnits; } void QgsMapToolIdentify::restoreCanvasPropertiesOverrides() { - mOverrideCanvasSearchRadius = -1; - mSkip3DLayers = false; + mPropertiesOverrides.searchRadiusMapUnits = -1; + mPropertiesOverrides.skip3DLayers = false; +} + +void QgsMapToolIdentify::setPropertiesOverrides( IdentifyProperties overrides ) +{ + mPropertiesOverrides = overrides; +} + +void QgsMapToolIdentify::restorePropertiesOverrides() +{ + mPropertiesOverrides.searchRadiusMapUnits = -1; + mPropertiesOverrides.skip3DLayers = false; } void QgsMapToolIdentify::activate() @@ -282,7 +292,7 @@ bool QgsMapToolIdentify::identifyMeshLayer( QListrenderer3D() ) + if ( mPropertiesOverrides.skip3DLayers && layer->renderer3D() ) return false; if ( !identifyContext.zRange().isInfinite() ) @@ -291,7 +301,7 @@ bool QgsMapToolIdentify::identifyMeshLayer( QListtemporalProperties()->isActive(); QList datasetIndexList; @@ -454,7 +464,7 @@ bool QgsMapToolIdentify::identifyVectorTileLayer( QList *results, QgsPointCloudLayer *layer, const QgsGeometry &geometry, const QgsIdentifyContext &identifyContext ) { - if ( mSkip3DLayers && layer->renderer3D() ) + if ( mPropertiesOverrides.skip3DLayers && layer->renderer3D() ) return false; if ( !identifyContext.zRange().isInfinite() ) @@ -556,7 +566,7 @@ bool QgsMapToolIdentify::identifyPointCloudLayer( QList points = renderer->identify( layer, context, geometry, searchRadiusMapUnits ); @@ -585,7 +595,7 @@ bool QgsMapToolIdentify::identifyVectorLayer( QListisSpatial() || !layer->dataProvider() ) return false; - if ( mSkip3DLayers && layer->renderer3D() ) + if ( mPropertiesOverrides.skip3DLayers && layer->renderer3D() ) return false; if ( !layer->isInScaleRange( mCanvas->mapSettings().scale() ) ) @@ -639,7 +649,7 @@ bool QgsMapToolIdentify::identifyVectorLayer( QList mParams; }; + struct IdentifyProperties + { + //! Identify search radius is map units. Use negative value to ignore + double searchRadiusMapUnits = -1; + //! Skip identify results from layers that have a 3d renderer set + bool skip3DLayers = true; + }; + //! constructor QgsMapToolIdentify( QgsMapCanvas *canvas ); @@ -251,15 +259,38 @@ class GUI_EXPORT QgsMapToolIdentify : public QgsMapTool * \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 + * \deprecated QGIS 3.42. Use setPropertiesOverrides() instead. */ - void setCanvasPropertiesOverrides( double searchRadiusMapUnits, bool skip3DLayers = true ); + Q_DECL_DEPRECATED void setCanvasPropertiesOverrides( double searchRadiusMapUnits ) SIP_DEPRECATED; /** * Clears canvas properties overrides previously set with setCanvasPropertiesOverrides() * \see setCanvasPropertiesOverrides() * \since QGIS 3.4 + * \deprecated QGIS 3.42. Use restorePropertiesOverrides() instead. */ - void restoreCanvasPropertiesOverrides(); + Q_DECL_DEPRECATED void restoreCanvasPropertiesOverrides() SIP_DEPRECATED; + + /** + * 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. + * When the custom identification has finished, restorePropertiesOverrides() should + * be called to erase any overrides. + * + * \param overrides The identify tool properties that will be overridden + * \since QGIS 3.42 + */ + void setPropertiesOverrides( IdentifyProperties overrides ); + + /** + * Clears canvas properties overrides previously set with setPropertiesOverrides() + * \see setPropertiesOverrides() + * \since QGIS 3.42 + */ + void restorePropertiesOverrides(); private: bool identifyLayer( QList *results, QgsMapLayer *layer, const QgsGeometry &geometry, const QgsRectangle &viewExtent, double mapUnitsPerPixel, QgsMapToolIdentify::LayerType layerType = AllLayers, const QgsIdentifyContext &identifyContext = QgsIdentifyContext() ); @@ -330,8 +361,7 @@ class GUI_EXPORT QgsMapToolIdentify : public QgsMapTool int mCoordinatePrecision; - double mOverrideCanvasSearchRadius = -1; - bool mSkip3DLayers = false; + IdentifyProperties mPropertiesOverrides; }; Q_DECLARE_OPERATORS_FOR_FLAGS( QgsMapToolIdentify::LayerType )