diff --git a/python/core/auto_additions/qgsprocessing.py b/python/core/auto_additions/qgsprocessing.py new file mode 100644 index 00000000000..1165bccdeed --- /dev/null +++ b/python/core/auto_additions/qgsprocessing.py @@ -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__ +# -- diff --git a/python/core/auto_generated/processing/qgsprocessing.sip.in b/python/core/auto_generated/processing/qgsprocessing.sip.in index d639cbaf9b5..33375a3a3b0 100644 --- a/python/core/auto_generated/processing/qgsprocessing.sip.in +++ b/python/core/auto_generated/processing/qgsprocessing.sip.in @@ -47,6 +47,13 @@ and parameters. PythonQgsProcessingAlgorithmSubclass, }; + enum class LayerOptionsFlag + { + SkipIndexGeneration, + }; + typedef QFlags LayerOptionsFlags; + + static QString sourceTypeToString( SourceType type ); %Docstring Converts a source ``type`` to a string representation. diff --git a/python/core/auto_generated/processing/qgsprocessingalgorithm.sip.in b/python/core/auto_generated/processing/qgsprocessingalgorithm.sip.in index 840e68069cd..c92fefa8e57 100644 --- a/python/core/auto_generated/processing/qgsprocessingalgorithm.sip.in +++ b/python/core/auto_generated/processing/qgsprocessingalgorithm.sip.in @@ -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 diff --git a/python/core/auto_generated/processing/qgsprocessingparameters.sip.in b/python/core/auto_generated/processing/qgsprocessingparameters.sip.in index 328c6361cc9..5726842b3ee 100644 --- a/python/core/auto_generated/processing/qgsprocessingparameters.sip.in +++ b/python/core/auto_generated/processing/qgsprocessingparameters.sip.in @@ -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 diff --git a/python/core/auto_generated/processing/qgsprocessingutils.sip.in b/python/core/auto_generated/processing/qgsprocessingutils.sip.in index cbcbbef0710..23410befdff 100644 --- a/python/core/auto_generated/processing/qgsprocessingutils.sip.in +++ b/python/core/auto_generated/processing/qgsprocessingutils.sip.in @@ -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``. diff --git a/src/core/processing/qgsprocessing.h b/src/core/processing/qgsprocessing.h index a4a5c9340d6..374fafe5dea 100644 --- a/src/core/processing/qgsprocessing.h +++ b/src/core/processing/qgsprocessing.h @@ -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. * diff --git a/src/core/processing/qgsprocessingalgorithm.cpp b/src/core/processing/qgsprocessingalgorithm.cpp index cc88cfcc6db..7f66cefd7ca 100644 --- a/src/core/processing/qgsprocessingalgorithm.cpp +++ b/src/core/processing/qgsprocessingalgorithm.cpp @@ -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 diff --git a/src/core/processing/qgsprocessingalgorithm.h b/src/core/processing/qgsprocessingalgorithm.h index f01ae3a7eeb..75fd1e7a491 100644 --- a/src/core/processing/qgsprocessingalgorithm.h +++ b/src/core/processing/qgsprocessingalgorithm.h @@ -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. diff --git a/src/core/processing/qgsprocessingparameters.cpp b/src/core/processing/qgsprocessingparameters.cpp index 9bef94434a0..9ea2cb40bd1 100644 --- a/src/core/processing/qgsprocessingparameters.cpp +++ b/src/core/processing/qgsprocessingparameters.cpp @@ -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; diff --git a/src/core/processing/qgsprocessingparameters.h b/src/core/processing/qgsprocessingparameters.h index aa47e0749b9..d218e4ab776 100644 --- a/src/core/processing/qgsprocessingparameters.h +++ b/src/core/processing/qgsprocessingparameters.h @@ -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. diff --git a/src/core/processing/qgsprocessingutils.cpp b/src/core/processing/qgsprocessingutils.cpp index 74bfdbc6063..2cdafcb2a51 100644 --- a/src/core/processing/qgsprocessingutils.cpp +++ b/src/core/processing/qgsprocessingutils.cpp @@ -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 ); diff --git a/src/core/processing/qgsprocessingutils.h b/src/core/processing/qgsprocessingutils.h index 5557648a6b2..de9bf7ef114 100644 --- a/src/core/processing/qgsprocessingutils.h +++ b/src/core/processing/qgsprocessingutils.h @@ -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