Revert, use a new struct as parameter

This commit is contained in:
uclaros 2024-12-11 15:14:43 +02:00 committed by Martin Dobias
parent 786dca61b3
commit f76c3e1e9d
9 changed files with 157 additions and 31 deletions

View File

@ -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]']}

View File

@ -63,6 +63,12 @@ after selecting a point, performs the identification:
QMap<QString, QVariant> 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
};

View File

@ -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]']}

View File

@ -63,6 +63,12 @@ after selecting a point, performs the identification:
QMap<QString, QVariant> 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
};

View File

@ -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

View File

@ -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()

View File

@ -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

View File

@ -189,16 +189,26 @@ QList<QgsMapToolIdentify::IdentifyResult> 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( QList<QgsMapToolIdentify::IdentifyRe
if ( !layer )
return false;
if ( mSkip3DLayers && layer->renderer3D() )
if ( mPropertiesOverrides.skip3DLayers && layer->renderer3D() )
return false;
if ( !identifyContext.zRange().isInfinite() )
@ -291,7 +301,7 @@ bool QgsMapToolIdentify::identifyMeshLayer( QList<QgsMapToolIdentify::IdentifyRe
return false;
}
double searchRadius = mOverrideCanvasSearchRadius < 0 ? searchRadiusMU( mCanvas ) : mOverrideCanvasSearchRadius;
double searchRadius = mPropertiesOverrides.searchRadiusMapUnits < 0 ? searchRadiusMU( mCanvas ) : mPropertiesOverrides.searchRadiusMapUnits;
bool isTemporal = identifyContext.isTemporal() && layer->temporalProperties()->isActive();
QList<QgsMeshDatasetIndex> datasetIndexList;
@ -454,7 +464,7 @@ bool QgsMapToolIdentify::identifyVectorTileLayer( QList<QgsMapToolIdentify::Iden
QgsRectangle r;
if ( isSingleClick )
{
double sr = mOverrideCanvasSearchRadius < 0 ? searchRadiusMU( mCanvas ) : mOverrideCanvasSearchRadius;
double sr = mPropertiesOverrides.searchRadiusMapUnits < 0 ? searchRadiusMU( mCanvas ) : mPropertiesOverrides.searchRadiusMapUnits;
r = toLayerCoordinates( layer, QgsRectangle( point.x() - sr, point.y() - sr, point.x() + sr, point.y() + sr ) );
}
else
@ -540,7 +550,7 @@ 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() )
if ( mPropertiesOverrides.skip3DLayers && layer->renderer3D() )
return false;
if ( !identifyContext.zRange().isInfinite() )
@ -556,7 +566,7 @@ bool QgsMapToolIdentify::identifyPointCloudLayer( QList<QgsMapToolIdentify::Iden
if ( !identifyContext.zRange().isInfinite() )
context.setZRange( identifyContext.zRange() );
const double searchRadiusMapUnits = mOverrideCanvasSearchRadius < 0 ? searchRadiusMU( mCanvas ) : mOverrideCanvasSearchRadius;
const double searchRadiusMapUnits = mPropertiesOverrides.searchRadiusMapUnits < 0 ? searchRadiusMU( mCanvas ) : mPropertiesOverrides.searchRadiusMapUnits;
const QVector<QVariantMap> points = renderer->identify( layer, context, geometry, searchRadiusMapUnits );
@ -585,7 +595,7 @@ bool QgsMapToolIdentify::identifyVectorLayer( QList<QgsMapToolIdentify::Identify
if ( !layer || !layer->isSpatial() || !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<QgsMapToolIdentify::Identify
QgsRectangle r;
if ( isSingleClick )
{
double sr = mOverrideCanvasSearchRadius < 0 ? searchRadiusMU( mCanvas ) : mOverrideCanvasSearchRadius;
double sr = mPropertiesOverrides.searchRadiusMapUnits < 0 ? searchRadiusMU( mCanvas ) : mPropertiesOverrides.searchRadiusMapUnits;
r = toLayerCoordinates( layer, QgsRectangle( point.x() - sr, point.y() - sr, point.x() + sr, point.y() + sr ) );
}
else

View File

@ -99,6 +99,14 @@ class GUI_EXPORT QgsMapToolIdentify : public QgsMapTool
QMap<QString, QVariant> 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<QgsMapToolIdentify::IdentifyResult> *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 )