mirror of
https://github.com/qgis/QGIS.git
synced 2025-10-05 00:09:32 -04:00
[processing] add layer options flag enum
This enum can be used in the QgsProcessingUtils::mapLayerFromString() and parameterAsPointCloudLayer() calls to control layer loading, e.g. skipping index generation or not applying default style, etc.
This commit is contained in:
parent
f6eb1a3e57
commit
0325cf0c30
5
python/core/auto_additions/qgsprocessing.py
Normal file
5
python/core/auto_additions/qgsprocessing.py
Normal file
@ -0,0 +1,5 @@
|
||||
# The following has been generated automatically from src/core/processing/qgsprocessing.h
|
||||
# monkey patching scoped based enum
|
||||
QgsProcessing.LayerOptionsFlag.SkipIndexGeneration.__doc__ = "Do not generate index when creating a layer. Makes sense only for point cloud layers"
|
||||
QgsProcessing.LayerOptionsFlag.__doc__ = 'Layer options flags\n\n.. versionadded:: 3.32\n\n' + '* ``SkipIndexGeneration``: ' + QgsProcessing.LayerOptionsFlag.SkipIndexGeneration.__doc__
|
||||
# --
|
@ -47,6 +47,13 @@ and parameters.
|
||||
PythonQgsProcessingAlgorithmSubclass,
|
||||
};
|
||||
|
||||
enum class LayerOptionsFlag
|
||||
{
|
||||
SkipIndexGeneration,
|
||||
};
|
||||
typedef QFlags<QgsProcessing::LayerOptionsFlag> LayerOptionsFlags;
|
||||
|
||||
|
||||
static QString sourceTypeToString( SourceType type );
|
||||
%Docstring
|
||||
Converts a source ``type`` to a string representation.
|
||||
|
@ -1002,9 +1002,10 @@ Evaluates the parameter with matching ``name`` to a DateTime, or returns an inva
|
||||
.. versionadded:: 3.14
|
||||
%End
|
||||
|
||||
QgsPointCloudLayer *parameterAsPointCloudLayer( const QVariantMap ¶meters, const QString &name, QgsProcessingContext &context ) const;
|
||||
QgsPointCloudLayer *parameterAsPointCloudLayer( const QVariantMap ¶meters, const QString &name, QgsProcessingContext &context, QgsProcessing::LayerOptionsFlags flags = QgsProcessing::LayerOptionsFlags() ) const;
|
||||
%Docstring
|
||||
Evaluates the parameter with matching ``name`` to a point cloud layer.
|
||||
The ``flags`` are used to set options for loading layer (e.g. skip index generation).
|
||||
|
||||
Layers will either be taken from ``context``'s active project, or loaded from external
|
||||
sources and stored temporarily in the ``context``. In either case, callers do not
|
||||
|
@ -1162,7 +1162,7 @@ a conversion in this case and will return the target layer name in the ``layerNa
|
||||
.. versionadded:: 3.10
|
||||
%End
|
||||
|
||||
static QgsMapLayer *parameterAsLayer( const QgsProcessingParameterDefinition *definition, const QVariantMap ¶meters, QgsProcessingContext &context, QgsProcessingUtils::LayerHint layerHint = QgsProcessingUtils::LayerHint::UnknownType );
|
||||
static QgsMapLayer *parameterAsLayer( const QgsProcessingParameterDefinition *definition, const QVariantMap ¶meters, QgsProcessingContext &context, QgsProcessingUtils::LayerHint layerHint = QgsProcessingUtils::LayerHint::UnknownType, QgsProcessing::LayerOptionsFlags flags = QgsProcessing::LayerOptionsFlags() );
|
||||
%Docstring
|
||||
Evaluates the parameter with matching ``definition`` to a map layer.
|
||||
|
||||
@ -1171,7 +1171,7 @@ sources and stored temporarily in the ``context``. In either case, callers do no
|
||||
need to handle deletion of the returned layer.
|
||||
%End
|
||||
|
||||
static QgsMapLayer *parameterAsLayer( const QgsProcessingParameterDefinition *definition, const QVariant &value, QgsProcessingContext &context, QgsProcessingUtils::LayerHint layerHint = QgsProcessingUtils::LayerHint::UnknownType );
|
||||
static QgsMapLayer *parameterAsLayer( const QgsProcessingParameterDefinition *definition, const QVariant &value, QgsProcessingContext &context, QgsProcessingUtils::LayerHint layerHint = QgsProcessingUtils::LayerHint::UnknownType, QgsProcessing::LayerOptionsFlags flags = QgsProcessing::LayerOptionsFlags() );
|
||||
%Docstring
|
||||
Evaluates the parameter with matching ``definition`` and ``value`` to a map layer.
|
||||
|
||||
@ -1588,9 +1588,10 @@ Evaluates the parameter with matching ``definition`` and ``value`` to a database
|
||||
.. versionadded:: 3.14
|
||||
%End
|
||||
|
||||
static QgsPointCloudLayer *parameterAsPointCloudLayer( const QgsProcessingParameterDefinition *definition, const QVariantMap ¶meters, QgsProcessingContext &context );
|
||||
static QgsPointCloudLayer *parameterAsPointCloudLayer( const QgsProcessingParameterDefinition *definition, const QVariantMap ¶meters, QgsProcessingContext &context, QgsProcessing::LayerOptionsFlags flags = QgsProcessing::LayerOptionsFlags() );
|
||||
%Docstring
|
||||
Evaluates the parameter with matching ``definition`` to a point cloud layer.
|
||||
The ``flags`` are used to set options for loading layer (e.g. skip index generation).
|
||||
|
||||
Layers will either be taken from ``context``'s active project, or loaded from external
|
||||
sources and stored temporarily in the ``context``. In either case, callers do not
|
||||
@ -1599,9 +1600,10 @@ need to handle deletion of the returned layer.
|
||||
.. versionadded:: 3.22
|
||||
%End
|
||||
|
||||
static QgsPointCloudLayer *parameterAsPointCloudLayer( const QgsProcessingParameterDefinition *definition, const QVariant &value, QgsProcessingContext &context );
|
||||
static QgsPointCloudLayer *parameterAsPointCloudLayer( const QgsProcessingParameterDefinition *definition, const QVariant &value, QgsProcessingContext &context, QgsProcessing::LayerOptionsFlags flags = QgsProcessing::LayerOptionsFlags() );
|
||||
%Docstring
|
||||
Evaluates the parameter with matching ``definition`` and ``value`` to a point cloud layer.
|
||||
The ``flags`` are used to set options for loading layer (e.g. skip index generation).
|
||||
|
||||
Layers will either be taken from ``context``'s active project, or loaded from external
|
||||
sources and stored temporarily in the ``context``. In either case, callers do not
|
||||
|
@ -211,7 +211,7 @@ Decodes a provider key and layer ``uri`` from an encoded string, for use with
|
||||
Annotation,
|
||||
};
|
||||
|
||||
static QgsMapLayer *mapLayerFromString( const QString &string, QgsProcessingContext &context, bool allowLoadingNewLayers = true, QgsProcessingUtils::LayerHint typeHint = QgsProcessingUtils::LayerHint::UnknownType );
|
||||
static QgsMapLayer *mapLayerFromString( const QString &string, QgsProcessingContext &context, bool allowLoadingNewLayers = true, QgsProcessingUtils::LayerHint typeHint = QgsProcessingUtils::LayerHint::UnknownType, QgsProcessing::LayerOptionsFlags flags = QgsProcessing::LayerOptionsFlags() );
|
||||
%Docstring
|
||||
Interprets a string as a map layer within the supplied ``context``.
|
||||
|
||||
|
@ -65,6 +65,17 @@ class CORE_EXPORT QgsProcessing
|
||||
PythonQgsProcessingAlgorithmSubclass, //!< Full Python QgsProcessingAlgorithm subclass
|
||||
};
|
||||
|
||||
/**
|
||||
* Layer options flags
|
||||
*
|
||||
* \since QGIS 3.32
|
||||
*/
|
||||
enum class LayerOptionsFlag : int
|
||||
{
|
||||
SkipIndexGeneration = 1 << 0, //!< Do not generate index when creating a layer. Makes sense only for point cloud layers
|
||||
};
|
||||
Q_DECLARE_FLAGS( LayerOptionsFlags, LayerOptionsFlag )
|
||||
|
||||
/**
|
||||
* Converts a source \a type to a string representation.
|
||||
*
|
||||
|
@ -875,9 +875,9 @@ QString QgsProcessingAlgorithm::parameterAsDatabaseTableName( const QVariantMap
|
||||
return QgsProcessingParameters::parameterAsDatabaseTableName( parameterDefinition( name ), parameters, context );
|
||||
}
|
||||
|
||||
QgsPointCloudLayer *QgsProcessingAlgorithm::parameterAsPointCloudLayer( const QVariantMap ¶meters, const QString &name, QgsProcessingContext &context ) const
|
||||
QgsPointCloudLayer *QgsProcessingAlgorithm::parameterAsPointCloudLayer( const QVariantMap ¶meters, const QString &name, QgsProcessingContext &context, QgsProcessing::LayerOptionsFlags flags ) const
|
||||
{
|
||||
return QgsProcessingParameters::parameterAsPointCloudLayer( parameterDefinition( name ), parameters, context );
|
||||
return QgsProcessingParameters::parameterAsPointCloudLayer( parameterDefinition( name ), parameters, context, flags );
|
||||
}
|
||||
|
||||
QgsAnnotationLayer *QgsProcessingAlgorithm::parameterAsAnnotationLayer( const QVariantMap ¶meters, const QString &name, QgsProcessingContext &context ) const
|
||||
|
@ -1002,6 +1002,7 @@ class CORE_EXPORT QgsProcessingAlgorithm
|
||||
|
||||
/**
|
||||
* Evaluates the parameter with matching \a name to a point cloud layer.
|
||||
* The \a flags are used to set options for loading layer (e.g. skip index generation).
|
||||
*
|
||||
* Layers will either be taken from \a context's active project, or loaded from external
|
||||
* sources and stored temporarily in the \a context. In either case, callers do not
|
||||
@ -1009,7 +1010,7 @@ class CORE_EXPORT QgsProcessingAlgorithm
|
||||
*
|
||||
* \since QGIS 3.22
|
||||
*/
|
||||
QgsPointCloudLayer *parameterAsPointCloudLayer( const QVariantMap ¶meters, const QString &name, QgsProcessingContext &context ) const;
|
||||
QgsPointCloudLayer *parameterAsPointCloudLayer( const QVariantMap ¶meters, const QString &name, QgsProcessingContext &context, QgsProcessing::LayerOptionsFlags flags = QgsProcessing::LayerOptionsFlags() ) const;
|
||||
|
||||
/**
|
||||
* Evaluates the parameter with matching \a name to an annotation layer.
|
||||
|
@ -847,15 +847,15 @@ QString QgsProcessingParameters::parameterAsCompatibleSourceLayerPathAndLayerNam
|
||||
return parameterAsCompatibleSourceLayerPathInternal( definition, parameters, context, compatibleFormats, preferredFormat, feedback, destLayer );
|
||||
}
|
||||
|
||||
QgsMapLayer *QgsProcessingParameters::parameterAsLayer( const QgsProcessingParameterDefinition *definition, const QVariantMap ¶meters, QgsProcessingContext &context, QgsProcessingUtils::LayerHint layerHint )
|
||||
QgsMapLayer *QgsProcessingParameters::parameterAsLayer( const QgsProcessingParameterDefinition *definition, const QVariantMap ¶meters, QgsProcessingContext &context, QgsProcessingUtils::LayerHint layerHint, QgsProcessing::LayerOptionsFlags flags )
|
||||
{
|
||||
if ( !definition )
|
||||
return nullptr;
|
||||
|
||||
return parameterAsLayer( definition, parameters.value( definition->name() ), context, layerHint );
|
||||
return parameterAsLayer( definition, parameters.value( definition->name() ), context, layerHint, flags );
|
||||
}
|
||||
|
||||
QgsMapLayer *QgsProcessingParameters::parameterAsLayer( const QgsProcessingParameterDefinition *definition, const QVariant &value, QgsProcessingContext &context, QgsProcessingUtils::LayerHint layerHint )
|
||||
QgsMapLayer *QgsProcessingParameters::parameterAsLayer( const QgsProcessingParameterDefinition *definition, const QVariant &value, QgsProcessingContext &context, QgsProcessingUtils::LayerHint layerHint, QgsProcessing::LayerOptionsFlags flags )
|
||||
{
|
||||
if ( !definition )
|
||||
return nullptr;
|
||||
@ -901,7 +901,7 @@ QgsMapLayer *QgsProcessingParameters::parameterAsLayer( const QgsProcessingParam
|
||||
if ( layerRef.isEmpty() )
|
||||
return nullptr;
|
||||
|
||||
return QgsProcessingUtils::mapLayerFromString( layerRef, context, true, layerHint );
|
||||
return QgsProcessingUtils::mapLayerFromString( layerRef, context, true, layerHint, flags );
|
||||
}
|
||||
|
||||
QgsRasterLayer *QgsProcessingParameters::parameterAsRasterLayer( const QgsProcessingParameterDefinition *definition, const QVariantMap ¶meters, QgsProcessingContext &context )
|
||||
@ -2166,14 +2166,14 @@ QString QgsProcessingParameters::parameterAsDatabaseTableName( const QgsProcessi
|
||||
return parameterAsString( definition, value, context );
|
||||
}
|
||||
|
||||
QgsPointCloudLayer *QgsProcessingParameters::parameterAsPointCloudLayer( const QgsProcessingParameterDefinition *definition, const QVariantMap ¶meters, QgsProcessingContext &context )
|
||||
QgsPointCloudLayer *QgsProcessingParameters::parameterAsPointCloudLayer( const QgsProcessingParameterDefinition *definition, const QVariantMap ¶meters, QgsProcessingContext &context, QgsProcessing::LayerOptionsFlags flags )
|
||||
{
|
||||
return qobject_cast< QgsPointCloudLayer *>( parameterAsLayer( definition, parameters, context, QgsProcessingUtils::LayerHint::PointCloud ) );
|
||||
return qobject_cast< QgsPointCloudLayer *>( parameterAsLayer( definition, parameters, context, QgsProcessingUtils::LayerHint::PointCloud, flags ) );
|
||||
}
|
||||
|
||||
QgsPointCloudLayer *QgsProcessingParameters::parameterAsPointCloudLayer( const QgsProcessingParameterDefinition *definition, const QVariant &value, QgsProcessingContext &context )
|
||||
QgsPointCloudLayer *QgsProcessingParameters::parameterAsPointCloudLayer( const QgsProcessingParameterDefinition *definition, const QVariant &value, QgsProcessingContext &context, QgsProcessing::LayerOptionsFlags flags )
|
||||
{
|
||||
return qobject_cast< QgsPointCloudLayer *>( parameterAsLayer( definition, value, context, QgsProcessingUtils::LayerHint::PointCloud ) );
|
||||
return qobject_cast< QgsPointCloudLayer *>( parameterAsLayer( definition, value, context, QgsProcessingUtils::LayerHint::PointCloud, flags ) );
|
||||
}
|
||||
|
||||
QgsAnnotationLayer *QgsProcessingParameters::parameterAsAnnotationLayer( const QgsProcessingParameterDefinition *definition, const QVariantMap ¶meters, QgsProcessingContext &context )
|
||||
@ -8770,7 +8770,7 @@ bool QgsProcessingParameterPointCloudLayer::checkValueIsAcceptable( const QVaria
|
||||
}
|
||||
|
||||
// try to load as layer
|
||||
if ( QgsProcessingUtils::mapLayerFromString( var.toString(), *context, true, QgsProcessingUtils::LayerHint::PointCloud ) )
|
||||
if ( QgsProcessingUtils::mapLayerFromString( var.toString(), *context, true, QgsProcessingUtils::LayerHint::PointCloud, QgsProcessing::LayerOptionsFlag::SkipIndexGeneration ) )
|
||||
return true;
|
||||
|
||||
return false;
|
||||
|
@ -1280,7 +1280,7 @@ class CORE_EXPORT QgsProcessingParameters
|
||||
* sources and stored temporarily in the \a context. In either case, callers do not
|
||||
* need to handle deletion of the returned layer.
|
||||
*/
|
||||
static QgsMapLayer *parameterAsLayer( const QgsProcessingParameterDefinition *definition, const QVariantMap ¶meters, QgsProcessingContext &context, QgsProcessingUtils::LayerHint layerHint = QgsProcessingUtils::LayerHint::UnknownType );
|
||||
static QgsMapLayer *parameterAsLayer( const QgsProcessingParameterDefinition *definition, const QVariantMap ¶meters, QgsProcessingContext &context, QgsProcessingUtils::LayerHint layerHint = QgsProcessingUtils::LayerHint::UnknownType, QgsProcessing::LayerOptionsFlags flags = QgsProcessing::LayerOptionsFlags() );
|
||||
|
||||
/**
|
||||
* Evaluates the parameter with matching \a definition and \a value to a map layer.
|
||||
@ -1291,7 +1291,7 @@ class CORE_EXPORT QgsProcessingParameters
|
||||
*
|
||||
* \since QGIS 3.4
|
||||
*/
|
||||
static QgsMapLayer *parameterAsLayer( const QgsProcessingParameterDefinition *definition, const QVariant &value, QgsProcessingContext &context, QgsProcessingUtils::LayerHint layerHint = QgsProcessingUtils::LayerHint::UnknownType );
|
||||
static QgsMapLayer *parameterAsLayer( const QgsProcessingParameterDefinition *definition, const QVariant &value, QgsProcessingContext &context, QgsProcessingUtils::LayerHint layerHint = QgsProcessingUtils::LayerHint::UnknownType, QgsProcessing::LayerOptionsFlags flags = QgsProcessing::LayerOptionsFlags() );
|
||||
|
||||
/**
|
||||
* Evaluates the parameter with matching \a definition to a raster layer.
|
||||
@ -1678,6 +1678,7 @@ class CORE_EXPORT QgsProcessingParameters
|
||||
|
||||
/**
|
||||
* Evaluates the parameter with matching \a definition to a point cloud layer.
|
||||
* The \a flags are used to set options for loading layer (e.g. skip index generation).
|
||||
*
|
||||
* Layers will either be taken from \a context's active project, or loaded from external
|
||||
* sources and stored temporarily in the \a context. In either case, callers do not
|
||||
@ -1685,10 +1686,11 @@ class CORE_EXPORT QgsProcessingParameters
|
||||
*
|
||||
* \since QGIS 3.22
|
||||
*/
|
||||
static QgsPointCloudLayer *parameterAsPointCloudLayer( const QgsProcessingParameterDefinition *definition, const QVariantMap ¶meters, QgsProcessingContext &context );
|
||||
static QgsPointCloudLayer *parameterAsPointCloudLayer( const QgsProcessingParameterDefinition *definition, const QVariantMap ¶meters, QgsProcessingContext &context, QgsProcessing::LayerOptionsFlags flags = QgsProcessing::LayerOptionsFlags() );
|
||||
|
||||
/**
|
||||
* Evaluates the parameter with matching \a definition and \a value to a point cloud layer.
|
||||
* The \a flags are used to set options for loading layer (e.g. skip index generation).
|
||||
*
|
||||
* Layers will either be taken from \a context's active project, or loaded from external
|
||||
* sources and stored temporarily in the \a context. In either case, callers do not
|
||||
@ -1696,7 +1698,7 @@ class CORE_EXPORT QgsProcessingParameters
|
||||
*
|
||||
* \since QGIS 3.22
|
||||
*/
|
||||
static QgsPointCloudLayer *parameterAsPointCloudLayer( const QgsProcessingParameterDefinition *definition, const QVariant &value, QgsProcessingContext &context );
|
||||
static QgsPointCloudLayer *parameterAsPointCloudLayer( const QgsProcessingParameterDefinition *definition, const QVariant &value, QgsProcessingContext &context, QgsProcessing::LayerOptionsFlags flags = QgsProcessing::LayerOptionsFlags() );
|
||||
|
||||
/**
|
||||
* Evaluates the parameter with matching \a definition to an annotation layer.
|
||||
|
@ -257,7 +257,7 @@ QgsMapLayer *QgsProcessingUtils::mapLayerFromStore( const QString &string, QgsMa
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
QgsMapLayer *QgsProcessingUtils::loadMapLayerFromString( const QString &string, const QgsCoordinateTransformContext &transformContext, LayerHint typeHint )
|
||||
QgsMapLayer *QgsProcessingUtils::loadMapLayerFromString( const QString &string, const QgsCoordinateTransformContext &transformContext, LayerHint typeHint, QgsProcessing::LayerOptionsFlags flags )
|
||||
{
|
||||
QString provider;
|
||||
QString uri;
|
||||
@ -355,6 +355,11 @@ QgsMapLayer *QgsProcessingUtils::loadMapLayerFromString( const QString &string,
|
||||
QgsPointCloudLayer::LayerOptions pointCloudOptions;
|
||||
pointCloudOptions.skipCrsValidation = true;
|
||||
|
||||
if ( flags & QgsProcessing::LayerOptionsFlag::SkipIndexGeneration )
|
||||
{
|
||||
pointCloudOptions.skipIndexGeneration = true;
|
||||
}
|
||||
|
||||
std::unique_ptr< QgsPointCloudLayer > pointCloudLayer;
|
||||
if ( useProvider )
|
||||
{
|
||||
@ -376,7 +381,7 @@ QgsMapLayer *QgsProcessingUtils::loadMapLayerFromString( const QString &string,
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
QgsMapLayer *QgsProcessingUtils::mapLayerFromString( const QString &string, QgsProcessingContext &context, bool allowLoadingNewLayers, LayerHint typeHint )
|
||||
QgsMapLayer *QgsProcessingUtils::mapLayerFromString( const QString &string, QgsProcessingContext &context, bool allowLoadingNewLayers, LayerHint typeHint, QgsProcessing::LayerOptionsFlags flags )
|
||||
{
|
||||
if ( string.isEmpty() )
|
||||
return nullptr;
|
||||
@ -400,7 +405,7 @@ QgsMapLayer *QgsProcessingUtils::mapLayerFromString( const QString &string, QgsP
|
||||
if ( !allowLoadingNewLayers )
|
||||
return nullptr;
|
||||
|
||||
layer = loadMapLayerFromString( string, context.transformContext(), typeHint );
|
||||
layer = loadMapLayerFromString( string, context.transformContext(), typeHint, flags );
|
||||
if ( layer )
|
||||
{
|
||||
context.temporaryLayerStore()->addMapLayer( layer );
|
||||
|
@ -23,6 +23,7 @@
|
||||
#include "qgsrasterlayer.h"
|
||||
#include "qgsfeaturesink.h"
|
||||
#include "qgsfeaturesource.h"
|
||||
#include "qgsprocessing.h"
|
||||
#include "qgsproxyfeaturesink.h"
|
||||
#include "qgsremappingproxyfeaturesink.h"
|
||||
|
||||
@ -218,7 +219,7 @@ class CORE_EXPORT QgsProcessingUtils
|
||||
*
|
||||
* The \a typeHint can be used to dictate the type of map layer expected.
|
||||
*/
|
||||
static QgsMapLayer *mapLayerFromString( const QString &string, QgsProcessingContext &context, bool allowLoadingNewLayers = true, QgsProcessingUtils::LayerHint typeHint = QgsProcessingUtils::LayerHint::UnknownType );
|
||||
static QgsMapLayer *mapLayerFromString( const QString &string, QgsProcessingContext &context, bool allowLoadingNewLayers = true, QgsProcessingUtils::LayerHint typeHint = QgsProcessingUtils::LayerHint::UnknownType, QgsProcessing::LayerOptionsFlags flags = QgsProcessing::LayerOptionsFlags() );
|
||||
|
||||
/**
|
||||
* Converts a variant \a value to a new feature source.
|
||||
@ -562,7 +563,7 @@ class CORE_EXPORT QgsProcessingUtils
|
||||
*
|
||||
* \since QGIS 3.8
|
||||
*/
|
||||
static QgsMapLayer *loadMapLayerFromString( const QString &string, const QgsCoordinateTransformContext &transformContext, LayerHint typeHint = LayerHint::UnknownType );
|
||||
static QgsMapLayer *loadMapLayerFromString( const QString &string, const QgsCoordinateTransformContext &transformContext, LayerHint typeHint = LayerHint::UnknownType, QgsProcessing::LayerOptionsFlags flags = QgsProcessing::LayerOptionsFlags() );
|
||||
|
||||
/**
|
||||
* Interprets a string as a map layer. The method will attempt to
|
||||
|
Loading…
x
Reference in New Issue
Block a user