From f8e37aa7cb245407a13b28c5b0c68bd1865b25dc Mon Sep 17 00:00:00 2001 From: Nyall Dawson Date: Tue, 27 Jun 2017 13:50:13 +1000 Subject: [PATCH 01/13] Fix some processing algorithm exception handling --- src/core/processing/qgsnativealgorithms.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/core/processing/qgsnativealgorithms.cpp b/src/core/processing/qgsnativealgorithms.cpp index d6f5f9be376..62fc38d41b8 100644 --- a/src/core/processing/qgsnativealgorithms.cpp +++ b/src/core/processing/qgsnativealgorithms.cpp @@ -1035,8 +1035,7 @@ QVariantMap QgsExtractByAttributeAlgorithm::processAlgorithm( const QVariantMap QgsExpression expression( expr ); if ( expression.hasParserError() ) { - // raise GeoAlgorithmExecutionException(expression.parserErrorString()) - return QVariantMap(); + throw QgsProcessingException( expression.parserErrorString() ); } QgsExpressionContext expressionContext = createExpressionContext( parameters, context ); From 9e184feaedaff9930a7336fe7367a3a48b544fc0 Mon Sep 17 00:00:00 2001 From: Nyall Dawson Date: Tue, 27 Jun 2017 15:24:48 +1000 Subject: [PATCH 02/13] Add method to evaluate parameters to compatible vector layers of a specified type --- .../processing/qgsprocessingparameters.sip | 16 ++++ python/core/processing/qgsprocessingutils.sip | 21 +++++ .../processing/qgsprocessingparameters.cpp | 44 +++++++++++ src/core/processing/qgsprocessingparameters.h | 16 ++++ src/core/processing/qgsprocessingutils.cpp | 36 +++++++++ src/core/processing/qgsprocessingutils.h | 21 +++++ tests/src/core/testqgsprocessing.cpp | 76 +++++++++++++++++++ 7 files changed, 230 insertions(+) diff --git a/python/core/processing/qgsprocessingparameters.sip b/python/core/processing/qgsprocessingparameters.sip index 42f408ad01e..4b6355977ef 100644 --- a/python/core/processing/qgsprocessingparameters.sip +++ b/python/core/processing/qgsprocessingparameters.sip @@ -472,6 +472,22 @@ class QgsProcessingParameters :rtype: QgsProcessingFeatureSource %End + static QString parameterAsCompatibleSourceLayerPath( const QgsProcessingParameterDefinition *definition, const QVariantMap ¶meters, + QgsProcessingContext &context, const QStringList &compatibleFormats, const QString &preferredFormat = QString( "shp" ), QgsProcessingFeedback *feedback = 0 ); +%Docstring + Evaluates the parameter with matching ``definition`` to a source vector layer file path of compatible format. + + If the parameter is evaluated to an existing layer, and that layer is not of the format listed in the + ``compatibleFormats`` argument, then the layer will first be exported to a compatible format + in a temporary location. The function will then return the path to that temporary file. + + ``compatibleFormats`` should consist entirely of lowercase file extensions, e.g. 'shp'. + + The ``preferredFormat`` argument is used to specify to desired file extension to use when a temporary + layer export is required. This defaults to shapefiles, because shapefiles are the future (don't believe the geopackage hype!). + :rtype: str +%End + static QgsMapLayer *parameterAsLayer( const QgsProcessingParameterDefinition *definition, const QVariantMap ¶meters, QgsProcessingContext &context ); %Docstring Evaluates the parameter with matching ``definition`` to a map layer. diff --git a/python/core/processing/qgsprocessingutils.sip b/python/core/processing/qgsprocessingutils.sip index 73c4c2e9298..4c206caab36 100644 --- a/python/core/processing/qgsprocessingutils.sip +++ b/python/core/processing/qgsprocessingutils.sip @@ -158,6 +158,27 @@ class QgsProcessingUtils :rtype: str %End + static QString convertToCompatibleFormat( const QgsVectorLayer *layer, + bool selectedFeaturesOnly, + const QString &baseName, + const QStringList &compatibleFormats, + const QString &preferredFormat, + QgsProcessingContext &context, + QgsProcessingFeedback *feedback ); +%Docstring + Converts a source vector ``layer`` to a file path to a vector layer of compatible format. + + If the specified ``layer`` is not of the format listed in the + ``compatibleFormats`` argument, then the layer will first be exported to a compatible format + in a temporary location using ``baseName``. The function will then return the path to that temporary file. + + ``compatibleFormats`` should consist entirely of lowercase file extensions, e.g. 'shp'. + + The ``preferredFormat`` argument is used to specify to desired file extension to use when a temporary + layer export is required. This defaults to shapefiles. + :rtype: str +%End + }; class QgsProcessingFeatureSource : QgsFeatureSource diff --git a/src/core/processing/qgsprocessingparameters.cpp b/src/core/processing/qgsprocessingparameters.cpp index 625880636d5..196e4862c45 100644 --- a/src/core/processing/qgsprocessingparameters.cpp +++ b/src/core/processing/qgsprocessingparameters.cpp @@ -21,6 +21,7 @@ #include "qgsvectorlayerfeatureiterator.h" #include "qgsprocessingoutputs.h" #include "qgssettings.h" +#include "qgsvectorfilewriter.h" bool QgsProcessingParameters::isDynamic( const QVariantMap ¶meters, const QString &name ) { @@ -327,6 +328,49 @@ QgsProcessingFeatureSource *QgsProcessingParameters::parameterAsSource( const Qg } } +QString QgsProcessingParameters::parameterAsCompatibleSourceLayerPath( const QgsProcessingParameterDefinition *definition, const QVariantMap ¶meters, QgsProcessingContext &context, const QStringList &compatibleFormats, const QString &preferredFormat, QgsProcessingFeedback *feedback ) +{ + if ( !definition ) + return QString(); + + QVariant val = parameters.value( definition->name() ); + + bool selectedFeaturesOnly = false; + if ( val.canConvert() ) + { + // input is a QgsProcessingFeatureSourceDefinition - get extra properties from it + QgsProcessingFeatureSourceDefinition fromVar = qvariant_cast( val ); + selectedFeaturesOnly = fromVar.selectedFeaturesOnly; + val = fromVar.source; + } + + QString layerRef; + if ( val.canConvert() ) + { + layerRef = val.value< QgsProperty >().valueAsString( context.expressionContext(), definition->defaultValue().toString() ); + } + else if ( !val.isValid() || val.toString().isEmpty() ) + { + // fall back to default + layerRef = definition->defaultValue().toString(); + } + else + { + layerRef = val.toString(); + } + + if ( layerRef.isEmpty() ) + return QString(); + + QgsVectorLayer *vl = qobject_cast< QgsVectorLayer *>( QgsProcessingUtils::mapLayerFromString( layerRef, context ) ); + if ( !vl ) + return QString(); + + return QgsProcessingUtils::convertToCompatibleFormat( vl, selectedFeaturesOnly, definition->name(), + compatibleFormats, preferredFormat, context, feedback ); +} + + QgsMapLayer *QgsProcessingParameters::parameterAsLayer( const QgsProcessingParameterDefinition *definition, const QVariantMap ¶meters, QgsProcessingContext &context ) { if ( !definition ) diff --git a/src/core/processing/qgsprocessingparameters.h b/src/core/processing/qgsprocessingparameters.h index 5f4cab2a4b2..bc428577bf0 100644 --- a/src/core/processing/qgsprocessingparameters.h +++ b/src/core/processing/qgsprocessingparameters.h @@ -32,6 +32,7 @@ class QgsFeatureSink; class QgsFeatureSource; class QgsProcessingFeatureSource; class QgsProcessingOutputDefinition; +class QgsProcessingFeedback; /** * \class QgsProcessingFeatureSourceDefinition @@ -508,6 +509,21 @@ class CORE_EXPORT QgsProcessingParameters */ static QgsProcessingFeatureSource *parameterAsSource( const QgsProcessingParameterDefinition *definition, const QVariantMap ¶meters, QgsProcessingContext &context ) SIP_FACTORY; + /** + * Evaluates the parameter with matching \a definition to a source vector layer file path of compatible format. + * + * If the parameter is evaluated to an existing layer, and that layer is not of the format listed in the + * \a compatibleFormats argument, then the layer will first be exported to a compatible format + * in a temporary location. The function will then return the path to that temporary file. + * + * \a compatibleFormats should consist entirely of lowercase file extensions, e.g. 'shp'. + * + * The \a preferredFormat argument is used to specify to desired file extension to use when a temporary + * layer export is required. This defaults to shapefiles, because shapefiles are the future (don't believe the geopackage hype!). + */ + static QString parameterAsCompatibleSourceLayerPath( const QgsProcessingParameterDefinition *definition, const QVariantMap ¶meters, + QgsProcessingContext &context, const QStringList &compatibleFormats, const QString &preferredFormat = QString( "shp" ), QgsProcessingFeedback *feedback = nullptr ); + /** * Evaluates the parameter with matching \a definition to a map layer. * diff --git a/src/core/processing/qgsprocessingutils.cpp b/src/core/processing/qgsprocessingutils.cpp index ded185b973d..4efaa880176 100644 --- a/src/core/processing/qgsprocessingutils.cpp +++ b/src/core/processing/qgsprocessingutils.cpp @@ -461,6 +461,42 @@ QString QgsProcessingUtils::formatHelpMapAsHtml( const QVariantMap &map, const Q return s; } +QString QgsProcessingUtils::convertToCompatibleFormat( const QgsVectorLayer *vl, bool selectedFeaturesOnly, const QString &baseName, const QStringList &compatibleFormats, const QString &preferredFormat, QgsProcessingContext &context, QgsProcessingFeedback *feedback ) +{ + bool requiresTranslation = selectedFeaturesOnly; + if ( !selectedFeaturesOnly ) + { + QFileInfo fi( vl->source() ); + requiresTranslation = !compatibleFormats.contains( fi.suffix(), Qt::CaseInsensitive ); + } + + if ( requiresTranslation ) + { + QString temp = QgsProcessingUtils::generateTempFilename( baseName + '.' + preferredFormat ); + + QgsVectorFileWriter writer( temp, context.defaultEncoding(), + vl->fields(), vl->wkbType(), vl->crs(), QgsVectorFileWriter::driverForExtension( preferredFormat ) ); + QgsFeature f; + QgsFeatureIterator it; + if ( selectedFeaturesOnly ) + it = vl->getSelectedFeatures(); + else + it = vl->getFeatures(); + + while ( it.nextFeature( f ) ) + { + if ( feedback->isCanceled() ) + return QString(); + writer.addFeature( f, QgsFeatureSink::FastInsert ); + } + return temp; + } + else + { + return vl->source(); + } +} + // // QgsProcessingFeatureSource diff --git a/src/core/processing/qgsprocessingutils.h b/src/core/processing/qgsprocessingutils.h index 0e023bbf218..11f6a0c609d 100644 --- a/src/core/processing/qgsprocessingutils.h +++ b/src/core/processing/qgsprocessingutils.h @@ -28,6 +28,7 @@ class QgsProject; class QgsProcessingContext; class QgsMapLayerStore; +class QgsProcessingFeedback; #include #include @@ -189,6 +190,26 @@ class CORE_EXPORT QgsProcessingUtils */ static QString formatHelpMapAsHtml( const QVariantMap &map, const QgsProcessingAlgorithm *algorithm ); + /** + * Converts a source vector \a layer to a file path to a vector layer of compatible format. + * + * If the specified \a layer is not of the format listed in the + * \a compatibleFormats argument, then the layer will first be exported to a compatible format + * in a temporary location using \a baseName. The function will then return the path to that temporary file. + * + * \a compatibleFormats should consist entirely of lowercase file extensions, e.g. 'shp'. + * + * The \a preferredFormat argument is used to specify to desired file extension to use when a temporary + * layer export is required. This defaults to shapefiles. + */ + static QString convertToCompatibleFormat( const QgsVectorLayer *layer, + bool selectedFeaturesOnly, + const QString &baseName, + const QStringList &compatibleFormats, + const QString &preferredFormat, + QgsProcessingContext &context, + QgsProcessingFeedback *feedback ); + private: static bool canUseLayer( const QgsRasterLayer *layer ); diff --git a/tests/src/core/testqgsprocessing.cpp b/tests/src/core/testqgsprocessing.cpp index 60a6de1d293..c11d20fce78 100644 --- a/tests/src/core/testqgsprocessing.cpp +++ b/tests/src/core/testqgsprocessing.cpp @@ -333,6 +333,7 @@ class TestQgsProcessing: public QObject void modelExecution(); void modelAcceptableValues(); void tempUtils(); + void convertCompatible(); private: @@ -5039,5 +5040,80 @@ void TestQgsProcessing::tempUtils() QVERIFY( tempFile2.startsWith( tempFolder ) ); } +void TestQgsProcessing::convertCompatible() +{ + // start with a compatible shapefile + QString testDataDir = QStringLiteral( TEST_DATA_DIR ) + '/'; //defined in CmakeLists.txt + QString vector = testDataDir + "points.shp"; + QgsVectorLayer *layer = new QgsVectorLayer( vector, "vl" ); + QgsProject p; + p.addMapLayer( layer ); + + QgsProcessingContext context; + context.setProject( &p ); + QgsProcessingFeedback feedback; + QString out = QgsProcessingUtils::convertToCompatibleFormat( layer, false, QStringLiteral( "test" ), QStringList() << "shp", QString( "shp" ), context, &feedback ); + // layer should be returned unchanged - underlying source is compatible + QCOMPARE( out, layer->source() ); + + // don't include shp as compatible type + out = QgsProcessingUtils::convertToCompatibleFormat( layer, false, QStringLiteral( "test" ), QStringList() << "tab", QString( "tab" ), context, &feedback ); + QVERIFY( out != layer->source() ); + QVERIFY( out.endsWith( ".tab" ) ); + QVERIFY( out.startsWith( QgsProcessingUtils::tempFolder() ) ); + + // make sure all features are copied + QgsVectorLayer *t = new QgsVectorLayer( out, "vl2" ); + QCOMPARE( layer->featureCount(), t->featureCount() ); + QCOMPARE( layer->crs(), t->crs() ); + + // use a selection - this will require translation + QgsFeatureIds ids; + QgsFeature f; + QgsFeatureIterator it = layer->getFeatures(); + it.nextFeature( f ); + ids.insert( f.id() ); + it.nextFeature( f ); + ids.insert( f.id() ); + + layer->selectByIds( ids ); + out = QgsProcessingUtils::convertToCompatibleFormat( layer, true, QStringLiteral( "test" ), QStringList() << "tab", QString( "tab" ), context, &feedback ); + QVERIFY( out != layer->source() ); + QVERIFY( out.endsWith( ".tab" ) ); + QVERIFY( out.startsWith( QgsProcessingUtils::tempFolder() ) ); + delete t; + t = new QgsVectorLayer( out, "vl2" ); + QCOMPARE( t->featureCount(), static_cast< long >( ids.count() ) ); + + // using a selection but existing format - will still require translation + out = QgsProcessingUtils::convertToCompatibleFormat( layer, true, QStringLiteral( "test" ), QStringList() << "shp", QString( "shp" ), context, &feedback ); + QVERIFY( out != layer->source() ); + QVERIFY( out.endsWith( ".shp" ) ); + QVERIFY( out.startsWith( QgsProcessingUtils::tempFolder() ) ); + delete t; + t = new QgsVectorLayer( out, "vl2" ); + QCOMPARE( t->featureCount(), static_cast< long >( ids.count() ) ); + + + // also test evaluating parameter to compatible format + std::unique_ptr< QgsProcessingParameterDefinition > def( new QgsProcessingParameterFeatureSource( QStringLiteral( "source" ) ) ); + QVariantMap params; + params.insert( QStringLiteral( "source" ), QgsProcessingFeatureSourceDefinition( layer->id(), false ) ); + out = QgsProcessingParameters::parameterAsCompatibleSourceLayerPath( def.get(), params, context, QStringList() << "shp", QString( "shp" ), &feedback ); + QCOMPARE( out, layer->source() ); + + out = QgsProcessingParameters::parameterAsCompatibleSourceLayerPath( def.get(), params, context, QStringList() << "tab", QString( "tab" ), &feedback ); + QVERIFY( out != layer->source() ); + QVERIFY( out.endsWith( ".tab" ) ); + QVERIFY( out.startsWith( QgsProcessingUtils::tempFolder() ) ); + + // selected only, will force export + params.insert( QStringLiteral( "source" ), QgsProcessingFeatureSourceDefinition( layer->id(), true ) ); + out = QgsProcessingParameters::parameterAsCompatibleSourceLayerPath( def.get(), params, context, QStringList() << "shp", QString( "shp" ), &feedback ); + QVERIFY( out != layer->source() ); + QVERIFY( out.endsWith( ".shp" ) ); + QVERIFY( out.startsWith( QgsProcessingUtils::tempFolder() ) ); +} + QGSTEST_MAIN( TestQgsProcessing ) #include "testqgsprocessing.moc" From d443bb3cbebcecb7c342383ab18ff932e21577da Mon Sep 17 00:00:00 2001 From: Nyall Dawson Date: Tue, 27 Jun 2017 17:18:53 +1000 Subject: [PATCH 03/13] Expose compatible vector layer parameter evaluation to QgsProcessingAlgorithm --- .../core/processing/qgsprocessingalgorithm.sip | 18 +++++++++++++++++- src/core/processing/qgsprocessingalgorithm.cpp | 5 +++++ src/core/processing/qgsprocessingalgorithm.h | 18 +++++++++++++++++- 3 files changed, 39 insertions(+), 2 deletions(-) diff --git a/python/core/processing/qgsprocessingalgorithm.sip b/python/core/processing/qgsprocessingalgorithm.sip index 72c4cd29674..e10f1598d13 100644 --- a/python/core/processing/qgsprocessingalgorithm.sip +++ b/python/core/processing/qgsprocessingalgorithm.sip @@ -514,7 +514,7 @@ class QgsProcessingAlgorithm QgsProcessingFeatureSource *parameterAsSource( const QVariantMap ¶meters, const QString &name, QgsProcessingContext &context ) const /Factory/; %Docstring - Evaluates the parameter with matching ``definition`` to a feature source. + Evaluates the parameter with matching ``name`` to a feature source. Sources will either be taken from ``context``'s active project, or loaded from external sources and stored temporarily in the ``context``. @@ -523,6 +523,22 @@ class QgsProcessingAlgorithm :rtype: QgsProcessingFeatureSource %End + QString parameterAsCompatibleSourceLayerPath( const QVariantMap ¶meters, const QString &name, + QgsProcessingContext &context, const QStringList &compatibleFormats, const QString &preferredFormat = QString( "shp" ), QgsProcessingFeedback *feedback = 0 ); +%Docstring + Evaluates the parameter with matching ``name`` to a source vector layer file path of compatible format. + + If the parameter is evaluated to an existing layer, and that layer is not of the format listed in the + ``compatibleFormats`` argument, then the layer will first be exported to a compatible format + in a temporary location. The function will then return the path to that temporary file. + + ``compatibleFormats`` should consist entirely of lowercase file extensions, e.g. 'shp'. + + The ``preferredFormat`` argument is used to specify to desired file extension to use when a temporary + layer export is required. + :rtype: str +%End + QgsMapLayer *parameterAsLayer( const QVariantMap ¶meters, const QString &name, QgsProcessingContext &context ) const; %Docstring Evaluates the parameter with matching ``name`` to a map layer. diff --git a/src/core/processing/qgsprocessingalgorithm.cpp b/src/core/processing/qgsprocessingalgorithm.cpp index 5f5370dc510..3fc2eb2b570 100644 --- a/src/core/processing/qgsprocessingalgorithm.cpp +++ b/src/core/processing/qgsprocessingalgorithm.cpp @@ -503,6 +503,11 @@ QgsProcessingFeatureSource *QgsProcessingAlgorithm::parameterAsSource( const QVa return QgsProcessingParameters::parameterAsSource( parameterDefinition( name ), parameters, context ); } +QString QgsProcessingAlgorithm::parameterAsCompatibleSourceLayerPath( const QVariantMap ¶meters, const QString &name, QgsProcessingContext &context, const QStringList &compatibleFormats, const QString &preferredFormat, QgsProcessingFeedback *feedback ) +{ + return QgsProcessingParameters::parameterAsCompatibleSourceLayerPath( parameterDefinition( name ), parameters, context, compatibleFormats, preferredFormat, feedback ); +} + QgsMapLayer *QgsProcessingAlgorithm::parameterAsLayer( const QVariantMap ¶meters, const QString &name, QgsProcessingContext &context ) const { return QgsProcessingParameters::parameterAsLayer( parameterDefinition( name ), parameters, context ); diff --git a/src/core/processing/qgsprocessingalgorithm.h b/src/core/processing/qgsprocessingalgorithm.h index 488af884b5d..892a047b662 100644 --- a/src/core/processing/qgsprocessingalgorithm.h +++ b/src/core/processing/qgsprocessingalgorithm.h @@ -30,6 +30,7 @@ class QgsProcessingProvider; class QgsProcessingFeedback; class QgsFeatureSink; +class QgsProcessingFeedback; /** @@ -485,7 +486,7 @@ class CORE_EXPORT QgsProcessingAlgorithm const QgsFields &fields, QgsWkbTypes::Type geometryType = QgsWkbTypes::NoGeometry, const QgsCoordinateReferenceSystem &crs = QgsCoordinateReferenceSystem() ) const SIP_FACTORY; /** - * Evaluates the parameter with matching \a definition to a feature source. + * Evaluates the parameter with matching \a name to a feature source. * * Sources will either be taken from \a context's active project, or loaded from external * sources and stored temporarily in the \a context. @@ -494,6 +495,21 @@ class CORE_EXPORT QgsProcessingAlgorithm */ QgsProcessingFeatureSource *parameterAsSource( const QVariantMap ¶meters, const QString &name, QgsProcessingContext &context ) const SIP_FACTORY; + /** + * Evaluates the parameter with matching \a name to a source vector layer file path of compatible format. + * + * If the parameter is evaluated to an existing layer, and that layer is not of the format listed in the + * \a compatibleFormats argument, then the layer will first be exported to a compatible format + * in a temporary location. The function will then return the path to that temporary file. + * + * \a compatibleFormats should consist entirely of lowercase file extensions, e.g. 'shp'. + * + * The \a preferredFormat argument is used to specify to desired file extension to use when a temporary + * layer export is required. + */ + QString parameterAsCompatibleSourceLayerPath( const QVariantMap ¶meters, const QString &name, + QgsProcessingContext &context, const QStringList &compatibleFormats, const QString &preferredFormat = QString( "shp" ), QgsProcessingFeedback *feedback = nullptr ); + /** * Evaluates the parameter with matching \a name to a map layer. * From febf0a0e6e5b23d1ac9af58542d0469a7da00aa0 Mon Sep 17 00:00:00 2001 From: Nyall Dawson Date: Tue, 27 Jun 2017 17:25:57 +1000 Subject: [PATCH 04/13] Rename method to more generic name - it's usable by vector layer outputs too --- python/core/processing/qgsprocessingalgorithm.sip | 4 ++-- python/core/processing/qgsprocessingparameters.sip | 4 ++-- python/plugins/processing/algs/qgis/Aspect.py | 2 +- src/core/processing/qgsprocessingalgorithm.cpp | 4 ++-- src/core/processing/qgsprocessingalgorithm.h | 4 ++-- src/core/processing/qgsprocessingparameters.cpp | 2 +- src/core/processing/qgsprocessingparameters.h | 4 ++-- tests/src/core/testqgsprocessing.cpp | 6 +++--- 8 files changed, 15 insertions(+), 15 deletions(-) diff --git a/python/core/processing/qgsprocessingalgorithm.sip b/python/core/processing/qgsprocessingalgorithm.sip index e10f1598d13..a6a39c7fa0d 100644 --- a/python/core/processing/qgsprocessingalgorithm.sip +++ b/python/core/processing/qgsprocessingalgorithm.sip @@ -559,9 +559,9 @@ class QgsProcessingAlgorithm :rtype: QgsRasterLayer %End - QString parameterAsRasterOutputLayer( const QVariantMap ¶meters, const QString &name, QgsProcessingContext &context ) const; + QString parameterAsOutputLayer( const QVariantMap ¶meters, const QString &name, QgsProcessingContext &context ) const; %Docstring - Evaluates the parameter with matching ``name`` to a raster output layer destination. + Evaluates the parameter with matching ``name`` to a output layer destination. :rtype: str %End diff --git a/python/core/processing/qgsprocessingparameters.sip b/python/core/processing/qgsprocessingparameters.sip index 4b6355977ef..a31102935b4 100644 --- a/python/core/processing/qgsprocessingparameters.sip +++ b/python/core/processing/qgsprocessingparameters.sip @@ -508,9 +508,9 @@ class QgsProcessingParameters :rtype: QgsRasterLayer %End - static QString parameterAsRasterOutputLayer( const QgsProcessingParameterDefinition *definition, const QVariantMap ¶meters, QgsProcessingContext &context ); + static QString parameterAsOutputLayer( const QgsProcessingParameterDefinition *definition, const QVariantMap ¶meters, QgsProcessingContext &context ); %Docstring - Evaluates the parameter with matching ``definition`` to a raster output layer destination. + Evaluates the parameter with matching ``definition`` to a output layer destination. :rtype: str %End diff --git a/python/plugins/processing/algs/qgis/Aspect.py b/python/plugins/processing/algs/qgis/Aspect.py index a371ef3937e..9a4aee737e3 100644 --- a/python/plugins/processing/algs/qgis/Aspect.py +++ b/python/plugins/processing/algs/qgis/Aspect.py @@ -78,7 +78,7 @@ class Aspect(QgisAlgorithm): inputFile = exportRasterLayer(self.parameterAsRasterLayer(parameters, self.INPUT, context)) zFactor = self.parameterAsDouble(parameters, self.Z_FACTOR, context) - outputFile = self.parameterAsRasterOutputLayer(parameters, self.OUTPUT, context) + outputFile = self.parameterAsOutputLayer(parameters, self.OUTPUT, context) outputFormat = raster.formatShortNameFromFileName(outputFile) diff --git a/src/core/processing/qgsprocessingalgorithm.cpp b/src/core/processing/qgsprocessingalgorithm.cpp index 3fc2eb2b570..9a0432a10be 100644 --- a/src/core/processing/qgsprocessingalgorithm.cpp +++ b/src/core/processing/qgsprocessingalgorithm.cpp @@ -518,9 +518,9 @@ QgsRasterLayer *QgsProcessingAlgorithm::parameterAsRasterLayer( const QVariantMa return QgsProcessingParameters::parameterAsRasterLayer( parameterDefinition( name ), parameters, context ); } -QString QgsProcessingAlgorithm::parameterAsRasterOutputLayer( const QVariantMap ¶meters, const QString &name, QgsProcessingContext &context ) const +QString QgsProcessingAlgorithm::parameterAsOutputLayer( const QVariantMap ¶meters, const QString &name, QgsProcessingContext &context ) const { - return QgsProcessingParameters::parameterAsRasterOutputLayer( parameterDefinition( name ), parameters, context ); + return QgsProcessingParameters::parameterAsOutputLayer( parameterDefinition( name ), parameters, context ); } QString QgsProcessingAlgorithm::parameterAsFileOutput( const QVariantMap ¶meters, const QString &name, QgsProcessingContext &context ) const diff --git a/src/core/processing/qgsprocessingalgorithm.h b/src/core/processing/qgsprocessingalgorithm.h index 892a047b662..5fbaefff686 100644 --- a/src/core/processing/qgsprocessingalgorithm.h +++ b/src/core/processing/qgsprocessingalgorithm.h @@ -529,9 +529,9 @@ class CORE_EXPORT QgsProcessingAlgorithm QgsRasterLayer *parameterAsRasterLayer( const QVariantMap ¶meters, const QString &name, QgsProcessingContext &context ) const; /** - * Evaluates the parameter with matching \a name to a raster output layer destination. + * Evaluates the parameter with matching \a name to a output layer destination. */ - QString parameterAsRasterOutputLayer( const QVariantMap ¶meters, const QString &name, QgsProcessingContext &context ) const; + QString parameterAsOutputLayer( const QVariantMap ¶meters, const QString &name, QgsProcessingContext &context ) const; /** * Evaluates the parameter with matching \a name to a file based output destination. diff --git a/src/core/processing/qgsprocessingparameters.cpp b/src/core/processing/qgsprocessingparameters.cpp index 196e4862c45..327c778ce16 100644 --- a/src/core/processing/qgsprocessingparameters.cpp +++ b/src/core/processing/qgsprocessingparameters.cpp @@ -413,7 +413,7 @@ QgsRasterLayer *QgsProcessingParameters::parameterAsRasterLayer( const QgsProces return qobject_cast< QgsRasterLayer *>( parameterAsLayer( definition, parameters, context ) ); } -QString QgsProcessingParameters::parameterAsRasterOutputLayer( const QgsProcessingParameterDefinition *definition, const QVariantMap ¶meters, QgsProcessingContext &context ) +QString QgsProcessingParameters::parameterAsOutputLayer( const QgsProcessingParameterDefinition *definition, const QVariantMap ¶meters, QgsProcessingContext &context ) { QVariant val; if ( definition ) diff --git a/src/core/processing/qgsprocessingparameters.h b/src/core/processing/qgsprocessingparameters.h index bc428577bf0..261264cd6f3 100644 --- a/src/core/processing/qgsprocessingparameters.h +++ b/src/core/processing/qgsprocessingparameters.h @@ -543,9 +543,9 @@ class CORE_EXPORT QgsProcessingParameters static QgsRasterLayer *parameterAsRasterLayer( const QgsProcessingParameterDefinition *definition, const QVariantMap ¶meters, QgsProcessingContext &context ); /** - * Evaluates the parameter with matching \a definition to a raster output layer destination. + * Evaluates the parameter with matching \a definition to a output layer destination. */ - static QString parameterAsRasterOutputLayer( const QgsProcessingParameterDefinition *definition, const QVariantMap ¶meters, QgsProcessingContext &context ); + static QString parameterAsOutputLayer( const QgsProcessingParameterDefinition *definition, const QVariantMap ¶meters, QgsProcessingContext &context ); /** * Evaluates the parameter with matching \a definition to a file based output destination. diff --git a/tests/src/core/testqgsprocessing.cpp b/tests/src/core/testqgsprocessing.cpp index c11d20fce78..9c008b33a24 100644 --- a/tests/src/core/testqgsprocessing.cpp +++ b/tests/src/core/testqgsprocessing.cpp @@ -3696,9 +3696,9 @@ void TestQgsProcessing::parameterRasterOut() QVariantMap params; params.insert( "non_optional", "test.tif" ); - QCOMPARE( QgsProcessingParameters::parameterAsRasterOutputLayer( def.get(), params, context ), QStringLiteral( "test.tif" ) ); + QCOMPARE( QgsProcessingParameters::parameterAsOutputLayer( def.get(), params, context ), QStringLiteral( "test.tif" ) ); params.insert( "non_optional", QgsProcessingOutputLayerDefinition( "test.tif" ) ); - QCOMPARE( QgsProcessingParameters::parameterAsRasterOutputLayer( def.get(), params, context ), QStringLiteral( "test.tif" ) ); + QCOMPARE( QgsProcessingParameters::parameterAsOutputLayer( def.get(), params, context ), QStringLiteral( "test.tif" ) ); QCOMPARE( def->valueAsPythonString( QStringLiteral( "abc" ), context ), QStringLiteral( "'abc'" ) ); QCOMPARE( def->valueAsPythonString( QVariant::fromValue( QgsProcessingOutputLayerDefinition( "abc" ) ), context ), QStringLiteral( "QgsProcessingOutputLayerDefinition('abc')" ) ); @@ -3738,7 +3738,7 @@ void TestQgsProcessing::parameterRasterOut() QVERIFY( def->checkValueIsAcceptable( QgsProcessingOutputLayerDefinition( "layer1231123" ) ) ); params.insert( "optional", QVariant() ); - QCOMPARE( QgsProcessingParameters::parameterAsRasterOutputLayer( def.get(), params, context ), QStringLiteral( "default.tif" ) ); + QCOMPARE( QgsProcessingParameters::parameterAsOutputLayer( def.get(), params, context ), QStringLiteral( "default.tif" ) ); code = def->asScriptCode(); QCOMPARE( code, QStringLiteral( "##optional=optional rasterOut default.tif" ) ); From f82b41e0019dec565e4b79c83a937126695dcc47 Mon Sep 17 00:00:00 2001 From: Nyall Dawson Date: Sat, 8 Jul 2017 14:43:07 +1000 Subject: [PATCH 05/13] Move an enum to new QgsProcessing class --- python/core/core_auto.sip | 1 + python/core/processing/qgsprocessing.sip | 51 ++++++++ .../core/processing/qgsprocessingoutputs.sip | 8 +- .../processing/qgsprocessingparameters.sip | 36 ++---- .../plugins/processing/algs/qgis/Boundary.py | 3 +- .../processing/algs/qgis/BoundingBox.py | 3 +- .../processing/algs/qgis/CheckValidity.py | 7 +- .../processing/algs/qgis/ConcaveHull.py | 7 +- .../plugins/processing/algs/qgis/Delaunay.py | 7 +- .../processing/algs/qgis/DeleteHoles.py | 7 +- .../processing/algs/qgis/DensifyGeometries.py | 3 +- .../algs/qgis/DensifyGeometriesInterval.py | 3 +- .../processing/algs/qgis/DropGeometry.py | 3 +- .../processing/algs/qgis/ExtentFromLayer.py | 3 +- .../processing/algs/qgis/FixGeometry.py | 3 +- .../processing/algs/qgis/GridPolygon.py | 3 +- python/plugins/processing/algs/qgis/Merge.py | 3 +- .../algs/qgis/PointsLayerFromTable.py | 7 +- .../processing/algs/qgis/RegularPoints.py | 5 +- .../processing/algs/qgis/SnapGeometries.py | 9 +- .../processing/algs/qgis/VoronoiPolygons.py | 7 +- .../processing/algs/qgis/ZonalStatistics.py | 5 +- .../gui/BatchInputSelectionPanel.py | 7 +- .../processing/gui/ParameterGuiUtils.py | 12 +- python/plugins/processing/gui/wrappers.py | 47 ++++---- src/core/CMakeLists.txt | 1 + src/core/processing/qgsnativealgorithms.cpp | 14 +-- src/core/processing/qgsprocessing.h | 61 ++++++++++ .../qgsprocessingmodelalgorithm.cpp | 4 +- src/core/processing/qgsprocessingoutputs.cpp | 6 +- src/core/processing/qgsprocessingoutputs.h | 8 +- .../processing/qgsprocessingparameters.cpp | 112 +++++++++--------- src/core/processing/qgsprocessingparameters.h | 40 +++---- tests/src/core/testqgsprocessing.cpp | 102 ++++++++-------- 34 files changed, 354 insertions(+), 244 deletions(-) create mode 100644 python/core/processing/qgsprocessing.sip create mode 100644 src/core/processing/qgsprocessing.h diff --git a/python/core/core_auto.sip b/python/core/core_auto.sip index 3cc27bf4b26..a3c2f144f0f 100644 --- a/python/core/core_auto.sip +++ b/python/core/core_auto.sip @@ -161,6 +161,7 @@ %Include layout/qgslayoutsize.sip %Include metadata/qgslayermetadata.sip %Include metadata/qgslayermetadatavalidator.sip +%Include processing/qgsprocessing.sip %Include processing/qgsprocessingalgorithm.sip %Include processing/qgsprocessingcontext.sip %Include processing/qgsprocessingmodelalgorithm.sip diff --git a/python/core/processing/qgsprocessing.sip b/python/core/processing/qgsprocessing.sip new file mode 100644 index 00000000000..4775f0c5d2c --- /dev/null +++ b/python/core/processing/qgsprocessing.sip @@ -0,0 +1,51 @@ +/************************************************************************ + * This file has been generated automatically from * + * * + * src/core/processing/qgsprocessing.h * + * * + * Do not edit manually ! Edit header and run scripts/sipify.pl again * + ************************************************************************/ + + + + + + +class QgsProcessing +{ +%Docstring + + Contains enumerations and other constants for use in processing algorithms + and parameters. + +.. versionadded:: 3.0 +%End + +%TypeHeaderCode +#include "qgsprocessing.h" +%End + public: + + enum LayerType + { + TypeAny, + TypeVectorAny, + TypeVectorPoint, + TypeVectorLine, + TypeVectorPolygon, + TypeRaster, + TypeFile, + TypeTable, + }; + + + +}; + +/************************************************************************ + * This file has been generated automatically from * + * * + * src/core/processing/qgsprocessing.h * + * * + * Do not edit manually ! Edit header and run scripts/sipify.pl again * + ************************************************************************/ diff --git a/python/core/processing/qgsprocessingoutputs.sip b/python/core/processing/qgsprocessingoutputs.sip index c9779d97e0e..44a26a74243 100644 --- a/python/core/processing/qgsprocessingoutputs.sip +++ b/python/core/processing/qgsprocessingoutputs.sip @@ -106,7 +106,7 @@ class QgsProcessingOutputVectorLayer : QgsProcessingOutputDefinition %End public: - QgsProcessingOutputVectorLayer( const QString &name, const QString &description = QString(), QgsProcessingParameterDefinition::LayerType type = QgsProcessingParameterDefinition::TypeVectorAny ); + QgsProcessingOutputVectorLayer( const QString &name, const QString &description = QString(), QgsProcessing::LayerType type = QgsProcessing::TypeVectorAny ); %Docstring Constructor for QgsProcessingOutputVectorLayer. %End @@ -118,14 +118,14 @@ class QgsProcessingOutputVectorLayer : QgsProcessingOutputDefinition %End virtual QString type() const; - QgsProcessingParameterDefinition::LayerType dataType() const; + QgsProcessing::LayerType dataType() const; %Docstring Returns the layer type for the output layer. .. seealso:: setDataType() - :rtype: QgsProcessingParameterDefinition.LayerType + :rtype: QgsProcessing.LayerType %End - void setDataType( QgsProcessingParameterDefinition::LayerType type ); + void setDataType( QgsProcessing::LayerType type ); %Docstring Sets the layer ``type`` for the output layer. .. seealso:: dataType() diff --git a/python/core/processing/qgsprocessingparameters.sip b/python/core/processing/qgsprocessingparameters.sip index a31102935b4..6d7ba01a901 100644 --- a/python/core/processing/qgsprocessingparameters.sip +++ b/python/core/processing/qgsprocessingparameters.sip @@ -201,18 +201,6 @@ class QgsProcessingParameterDefinition typedef QFlags Flags; - enum LayerType - { - TypeAny, - TypeVectorAny, - TypeVectorPoint, - TypeVectorLine, - TypeVectorPolygon, - TypeRaster, - TypeFile, - TypeTable, - }; - QgsProcessingParameterDefinition( const QString &name, const QString &description = QString(), const QVariant &defaultValue = QVariant(), bool optional = false ); %Docstring @@ -963,7 +951,7 @@ class QgsProcessingParameterMultipleLayers : QgsProcessingParameterDefinition %End public: - QgsProcessingParameterMultipleLayers( const QString &name, const QString &description = QString(), QgsProcessingParameterDefinition::LayerType layerType = QgsProcessingParameterDefinition::TypeVectorAny, + QgsProcessingParameterMultipleLayers( const QString &name, const QString &description = QString(), QgsProcessing::LayerType layerType = QgsProcessing::TypeVectorAny, const QVariant &defaultValue = QVariant(), bool optional = false ); %Docstring @@ -983,14 +971,14 @@ class QgsProcessingParameterMultipleLayers : QgsProcessingParameterDefinition virtual QString asScriptCode() const; - QgsProcessingParameterDefinition::LayerType layerType() const; + QgsProcessing::LayerType layerType() const; %Docstring Returns the layer type for layers acceptable by the parameter. .. seealso:: setLayerType() - :rtype: QgsProcessingParameterDefinition.LayerType + :rtype: QgsProcessing.LayerType %End - void setLayerType( QgsProcessingParameterDefinition::LayerType type ); + void setLayerType( QgsProcessing::LayerType type ); %Docstring Sets the layer ``type`` for layers acceptable by the parameter. .. seealso:: layerType() @@ -1665,7 +1653,7 @@ class QgsProcessingParameterFeatureSink : QgsProcessingDestinationParameter %End public: - QgsProcessingParameterFeatureSink( const QString &name, const QString &description = QString(), QgsProcessingParameterDefinition::LayerType type = QgsProcessingParameterDefinition::TypeVectorAny, const QVariant &defaultValue = QVariant(), + QgsProcessingParameterFeatureSink( const QString &name, const QString &description = QString(), QgsProcessing::LayerType type = QgsProcessing::TypeVectorAny, const QVariant &defaultValue = QVariant(), bool optional = false ); %Docstring Constructor for QgsProcessingParameterFeatureSink. @@ -1688,11 +1676,11 @@ class QgsProcessingParameterFeatureSink : QgsProcessingDestinationParameter virtual QString defaultFileExtension() const; - QgsProcessingParameterDefinition::LayerType dataType() const; + QgsProcessing::LayerType dataType() const; %Docstring Returns the layer type for sinks associated with the parameter. .. seealso:: setDataType() - :rtype: QgsProcessingParameterDefinition.LayerType + :rtype: QgsProcessing.LayerType %End bool hasGeometry() const; @@ -1702,7 +1690,7 @@ class QgsProcessingParameterFeatureSink : QgsProcessingDestinationParameter :rtype: bool %End - void setDataType( QgsProcessingParameterDefinition::LayerType type ); + void setDataType( QgsProcessing::LayerType type ); %Docstring Sets the layer ``type`` for the sinks associated with the parameter. .. seealso:: dataType() @@ -1737,7 +1725,7 @@ class QgsProcessingParameterVectorOutput : QgsProcessingDestinationParameter %End public: - QgsProcessingParameterVectorOutput( const QString &name, const QString &description = QString(), QgsProcessingParameterDefinition::LayerType type = QgsProcessingParameterDefinition::TypeVectorAny, const QVariant &defaultValue = QVariant(), + QgsProcessingParameterVectorOutput( const QString &name, const QString &description = QString(), QgsProcessing::LayerType type = QgsProcessing::TypeVectorAny, const QVariant &defaultValue = QVariant(), bool optional = false ); %Docstring Constructor for QgsProcessingParameterVectorOutput. @@ -1760,11 +1748,11 @@ class QgsProcessingParameterVectorOutput : QgsProcessingDestinationParameter virtual QString defaultFileExtension() const; - QgsProcessingParameterDefinition::LayerType dataType() const; + QgsProcessing::LayerType dataType() const; %Docstring Returns the layer type for layers associated with the parameter. .. seealso:: setDataType() - :rtype: QgsProcessingParameterDefinition.LayerType + :rtype: QgsProcessing.LayerType %End bool hasGeometry() const; @@ -1774,7 +1762,7 @@ class QgsProcessingParameterVectorOutput : QgsProcessingDestinationParameter :rtype: bool %End - void setDataType( QgsProcessingParameterDefinition::LayerType type ); + void setDataType( QgsProcessing::LayerType type ); %Docstring Sets the layer ``type`` for the layers associated with the parameter. .. seealso:: dataType() diff --git a/python/plugins/processing/algs/qgis/Boundary.py b/python/plugins/processing/algs/qgis/Boundary.py index 8c883ed2bd3..3c7ef2db84d 100644 --- a/python/plugins/processing/algs/qgis/Boundary.py +++ b/python/plugins/processing/algs/qgis/Boundary.py @@ -30,6 +30,7 @@ import os from qgis.core import (QgsGeometry, QgsWkbTypes, QgsFeatureSink, + QgsProcessing, QgsProcessingUtils, QgsProcessingParameterDefinition, QgsProcessingParameterFeatureSource, @@ -54,7 +55,7 @@ class Boundary(QgisAlgorithm): def __init__(self): super().__init__() - self.addParameter(QgsProcessingParameterFeatureSource(self.INPUT_LAYER, self.tr('Input layer'), [QgsProcessingParameterDefinition.TypeVectorLine, QgsProcessingParameterDefinition.TypeVectorPolygon])) + self.addParameter(QgsProcessingParameterFeatureSource(self.INPUT_LAYER, self.tr('Input layer'), [QgsProcessing.TypeVectorLine, QgsProcessing.TypeVectorPolygon])) self.addParameter(QgsProcessingParameterFeatureSink(self.OUTPUT_LAYER, self.tr('Boundary'))) self.addOutput(QgsProcessingOutputVectorLayer(self.OUTPUT_LAYER, self.tr("Boundaries"))) diff --git a/python/plugins/processing/algs/qgis/BoundingBox.py b/python/plugins/processing/algs/qgis/BoundingBox.py index 502a2108c35..f474d20d502 100644 --- a/python/plugins/processing/algs/qgis/BoundingBox.py +++ b/python/plugins/processing/algs/qgis/BoundingBox.py @@ -30,6 +30,7 @@ import os from qgis.core import (QgsGeometry, QgsWkbTypes, QgsFeatureSink, + QgsProcessing, QgsProcessingUtils, QgsProcessingParameterFeatureSource, QgsProcessingParameterFeatureSink, @@ -63,7 +64,7 @@ class BoundingBox(QgisAlgorithm): super().__init__() self.addParameter(QgsProcessingParameterFeatureSource(self.INPUT_LAYER, self.tr('Input layer'))) - self.addParameter(QgsProcessingParameterFeatureSink(self.OUTPUT_LAYER, self.tr('Bounds'), QgsProcessingParameterDefinition.TypeVectorPolygon)) + self.addParameter(QgsProcessingParameterFeatureSink(self.OUTPUT_LAYER, self.tr('Bounds'), QgsProcessing.TypeVectorPolygon)) self.addOutput(QgsProcessingOutputVectorLayer(self.OUTPUT_LAYER, self.tr("Bounds"))) def name(self): diff --git a/python/plugins/processing/algs/qgis/CheckValidity.py b/python/plugins/processing/algs/qgis/CheckValidity.py index fe5a6a9a7aa..a77df5882bf 100644 --- a/python/plugins/processing/algs/qgis/CheckValidity.py +++ b/python/plugins/processing/algs/qgis/CheckValidity.py @@ -39,6 +39,7 @@ from qgis.core import (QgsSettings, QgsWkbTypes, QgsProcessingUtils, QgsFields, + QgsProcessing, QgsProcessingFeatureSource, QgsProcessingParameterFeatureSource, QgsProcessingParameterEnum, @@ -81,15 +82,15 @@ class CheckValidity(QgisAlgorithm): self.addParameter(QgsProcessingParameterEnum(self.METHOD, self.tr('Method'), self.methods)) - self.addParameter(QgsProcessingParameterFeatureSink(self.VALID_OUTPUT, self.tr('Valid output'), QgsProcessingParameterDefinition.TypeVectorAny, '', True)) + self.addParameter(QgsProcessingParameterFeatureSink(self.VALID_OUTPUT, self.tr('Valid output'), QgsProcessing.TypeVectorAny, '', True)) self.addOutput(QgsProcessingOutputVectorLayer(self.VALID_OUTPUT, self.tr('Valid output'))) self.addOutput(QgsProcessingOutputNumber(self.VALID_COUNT, self.tr('Count of valid features'))) - self.addParameter(QgsProcessingParameterFeatureSink(self.INVALID_OUTPUT, self.tr('Invalid output'), QgsProcessingParameterDefinition.TypeVectorAny, '', True)) + self.addParameter(QgsProcessingParameterFeatureSink(self.INVALID_OUTPUT, self.tr('Invalid output'), QgsProcessing.TypeVectorAny, '', True)) self.addOutput(QgsProcessingOutputVectorLayer(self.INVALID_OUTPUT, self.tr('Invalid output'))) self.addOutput(QgsProcessingOutputNumber(self.INVALID_COUNT, self.tr('Count of invalid features'))) - self.addParameter(QgsProcessingParameterFeatureSink(self.ERROR_OUTPUT, self.tr('Error output'), QgsProcessingParameterDefinition.TypeVectorAny, '', True)) + self.addParameter(QgsProcessingParameterFeatureSink(self.ERROR_OUTPUT, self.tr('Error output'), QgsProcessing.TypeVectorAny, '', True)) self.addOutput(QgsProcessingOutputVectorLayer(self.ERROR_OUTPUT, self.tr('Error output'))) self.addOutput(QgsProcessingOutputNumber(self.ERROR_COUNT, self.tr('Count of errors'))) diff --git a/python/plugins/processing/algs/qgis/ConcaveHull.py b/python/plugins/processing/algs/qgis/ConcaveHull.py index b91ed220250..11b59d96e2b 100644 --- a/python/plugins/processing/algs/qgis/ConcaveHull.py +++ b/python/plugins/processing/algs/qgis/ConcaveHull.py @@ -32,6 +32,7 @@ from qgis.core import (QgsFeatureRequest, QgsFeatureSink, QgsWkbTypes, QgsApplication, + QgsProcessing, QgsProcessingUtils, QgsProcessingParameterFeatureSource, QgsProcessingParameterVectorLayer, @@ -60,7 +61,7 @@ class ConcaveHull(QgisAlgorithm): def __init__(self): super().__init__() - self.addParameter(QgsProcessingParameterFeatureSource(self.INPUT, self.tr('Input point layer'), [QgsProcessingParameterDefinition.TypeVectorPoint])) + self.addParameter(QgsProcessingParameterFeatureSource(self.INPUT, self.tr('Input point layer'), [QgsProcessing.TypeVectorPoint])) self.addParameter(QgsProcessingParameterNumber(self.ALPHA, self.tr('Threshold (0-1, where 1 is equivalent with Convex Hull)'), minValue=0, maxValue=1, defaultValue=0.3, type=QgsProcessingParameterNumber.Double)) @@ -70,8 +71,8 @@ class ConcaveHull(QgisAlgorithm): self.addParameter(QgsProcessingParameterBoolean(self.NO_MULTIGEOMETRY, self.tr('Split multipart geometry into singleparts geometries'), defaultValue=False)) - self.addParameter(QgsProcessingParameterFeatureSink(self.OUTPUT, self.tr('Concave hull'), type=QgsProcessingParameterDefinition.TypeVectorPolygon)) - self.addOutput(QgsProcessingOutputVectorLayer(self.OUTPUT, self.tr("Concave hull"), type=QgsProcessingParameterDefinition.TypeVectorPolygon)) + self.addParameter(QgsProcessingParameterFeatureSink(self.OUTPUT, self.tr('Concave hull'), type=QgsProcessing.TypeVectorPolygon)) + self.addOutput(QgsProcessingOutputVectorLayer(self.OUTPUT, self.tr("Concave hull"), type=QgsProcessing.TypeVectorPolygon)) def name(self): return 'concavehull' diff --git a/python/plugins/processing/algs/qgis/Delaunay.py b/python/plugins/processing/algs/qgis/Delaunay.py index 05b3bb0676f..43fae780039 100644 --- a/python/plugins/processing/algs/qgis/Delaunay.py +++ b/python/plugins/processing/algs/qgis/Delaunay.py @@ -38,6 +38,7 @@ from qgis.core import (QgsField, QgsGeometry, QgsPointXY, QgsWkbTypes, + QgsProcessing, QgsProcessingUtils, QgsFields, QgsProcessingParameterFeatureSource, @@ -67,9 +68,9 @@ class Delaunay(QgisAlgorithm): def __init__(self): super().__init__() - self.addParameter(QgsProcessingParameterFeatureSource(self.INPUT, self.tr('Input layer'), [QgsProcessingParameterDefinition.TypeVectorPoint])) - self.addParameter(QgsProcessingParameterFeatureSink(self.OUTPUT, self.tr('Delaunay triangulation'), type=QgsProcessingParameterDefinition.TypeVectorPolygon)) - self.addOutput(QgsProcessingOutputVectorLayer(self.OUTPUT, self.tr("Delaunay triangulation"), type=QgsProcessingParameterDefinition.TypeVectorPolygon)) + self.addParameter(QgsProcessingParameterFeatureSource(self.INPUT, self.tr('Input layer'), [QgsProcessing.TypeVectorPoint])) + self.addParameter(QgsProcessingParameterFeatureSink(self.OUTPUT, self.tr('Delaunay triangulation'), type=QgsProcessing.TypeVectorPolygon)) + self.addOutput(QgsProcessingOutputVectorLayer(self.OUTPUT, self.tr("Delaunay triangulation"), type=QgsProcessing.TypeVectorPolygon)) def name(self): return 'delaunaytriangulation' diff --git a/python/plugins/processing/algs/qgis/DeleteHoles.py b/python/plugins/processing/algs/qgis/DeleteHoles.py index b5baf2d254b..878ee8d4909 100644 --- a/python/plugins/processing/algs/qgis/DeleteHoles.py +++ b/python/plugins/processing/algs/qgis/DeleteHoles.py @@ -26,6 +26,7 @@ __revision__ = '$Format:%H$' from qgis.core import (QgsApplication, QgsFeatureSink, + QgsProcessing, QgsProcessingUtils, QgsProcessingParameterFeatureSource, QgsProcessingParameterNumber, @@ -50,13 +51,13 @@ class DeleteHoles(QgisAlgorithm): def __init__(self): super().__init__() self.addParameter(QgsProcessingParameterFeatureSource(self.INPUT, - self.tr('Input layer'), [QgsProcessingParameterDefinition.TypeVectorPolygon])) + self.tr('Input layer'), [QgsProcessing.TypeVectorPolygon])) self.addParameter(QgsProcessingParameterNumber(self.MIN_AREA, self.tr('Remove holes with area less than'), QgsProcessingParameterNumber.Double, 0, True, 0.0, 10000000.0)) - self.addParameter(QgsProcessingParameterFeatureSink(self.OUTPUT, self.tr('Cleaned'), QgsProcessingParameterDefinition.TypeVectorPolygon)) - self.addOutput(QgsProcessingOutputVectorLayer(self.OUTPUT, self.tr('Cleaned'), QgsProcessingParameterDefinition.TypeVectorPolygon)) + self.addParameter(QgsProcessingParameterFeatureSink(self.OUTPUT, self.tr('Cleaned'), QgsProcessing.TypeVectorPolygon)) + self.addOutput(QgsProcessingOutputVectorLayer(self.OUTPUT, self.tr('Cleaned'), QgsProcessing.TypeVectorPolygon)) def name(self): return 'deleteholes' diff --git a/python/plugins/processing/algs/qgis/DensifyGeometries.py b/python/plugins/processing/algs/qgis/DensifyGeometries.py index 591b79b3163..9e44f8139ad 100644 --- a/python/plugins/processing/algs/qgis/DensifyGeometries.py +++ b/python/plugins/processing/algs/qgis/DensifyGeometries.py @@ -31,6 +31,7 @@ import os from qgis.core import (QgsWkbTypes, QgsFeatureSink, QgsApplication, + QgsProcessing, QgsProcessingParameterFeatureSource, QgsProcessingParameterNumber, QgsProcessingParameterFeatureSink, @@ -55,7 +56,7 @@ class DensifyGeometries(QgisAlgorithm): super().__init__() self.addParameter(QgsProcessingParameterFeatureSource(self.INPUT, - self.tr('Input layer'), [QgsProcessingParameterDefinition.TypeVectorPolygon, QgsProcessingParameterDefinition.TypeVectorLine])) + self.tr('Input layer'), [QgsProcessing.TypeVectorPolygon, QgsProcessing.TypeVectorLine])) self.addParameter(QgsProcessingParameterNumber(self.VERTICES, self.tr('Vertices to add'), QgsProcessingParameterNumber.Integer, 1, False, 1, 10000000)) diff --git a/python/plugins/processing/algs/qgis/DensifyGeometriesInterval.py b/python/plugins/processing/algs/qgis/DensifyGeometriesInterval.py index 1618fa0fe87..cee0d155f72 100644 --- a/python/plugins/processing/algs/qgis/DensifyGeometriesInterval.py +++ b/python/plugins/processing/algs/qgis/DensifyGeometriesInterval.py @@ -32,6 +32,7 @@ from math import sqrt from qgis.core import (QgsWkbTypes, QgsApplication, QgsFeatureSink, + QgsProcessing, QgsProcessingParameterFeatureSource, QgsProcessingParameterNumber, QgsProcessingParameterFeatureSink, @@ -53,7 +54,7 @@ class DensifyGeometriesInterval(QgisAlgorithm): super().__init__() self.addParameter(QgsProcessingParameterFeatureSource(self.INPUT, - self.tr('Input layer'), [QgsProcessingParameterDefinition.TypeVectorPolygon, QgsProcessingParameterDefinition.TypeVectorLine])) + self.tr('Input layer'), [QgsProcessing.TypeVectorPolygon, QgsProcessing.TypeVectorLine])) self.addParameter(QgsProcessingParameterNumber(self.INTERVAL, self.tr('Interval between vertices to add'), QgsProcessingParameterNumber.Double, 1, False, 0, 10000000)) diff --git a/python/plugins/processing/algs/qgis/DropGeometry.py b/python/plugins/processing/algs/qgis/DropGeometry.py index 5705cc6a103..128f4312ceb 100644 --- a/python/plugins/processing/algs/qgis/DropGeometry.py +++ b/python/plugins/processing/algs/qgis/DropGeometry.py @@ -30,6 +30,7 @@ from qgis.core import (QgsFeatureRequest, QgsFeatureSink, QgsCoordinateReferenceSystem, QgsApplication, + QgsProcessing, QgsProcessingParameterDefinition, QgsProcessingParameterFeatureSource, QgsProcessingParameterFeatureSink, @@ -51,7 +52,7 @@ class DropGeometry(QgisAlgorithm): def __init__(self): super().__init__() - self.addParameter(QgsProcessingParameterFeatureSource(self.INPUT, self.tr('Input layer'), [QgsProcessingParameterDefinition.TypeVectorPoint, QgsProcessingParameterDefinition.TypeVectorLine, QgsProcessingParameterDefinition.TypeVectorPolygon])) + self.addParameter(QgsProcessingParameterFeatureSource(self.INPUT, self.tr('Input layer'), [QgsProcessing.TypeVectorPoint, QgsProcessing.TypeVectorLine, QgsProcessing.TypeVectorPolygon])) self.addParameter(QgsProcessingParameterFeatureSink(self.OUTPUT, self.tr('Dropped geometry'))) self.addOutput(QgsProcessingOutputVectorLayer(self.OUTPUT, self.tr("Dropped geometry"))) diff --git a/python/plugins/processing/algs/qgis/ExtentFromLayer.py b/python/plugins/processing/algs/qgis/ExtentFromLayer.py index e3f2e00adfc..1e5d03a4f47 100644 --- a/python/plugins/processing/algs/qgis/ExtentFromLayer.py +++ b/python/plugins/processing/algs/qgis/ExtentFromLayer.py @@ -36,6 +36,7 @@ from qgis.core import (QgsField, QgsGeometry, QgsFeature, QgsWkbTypes, + QgsProcessing, QgsProcessingUtils, QgsProcessingParameterFeatureSource, QgsProcessingParameterFeatureSink, @@ -77,7 +78,7 @@ class ExtentFromLayer(QgisAlgorithm): self.tr('Calculate extent for each feature separately'), False)) self.addParameter(QgsProcessingParameterFeatureSink(self.OUTPUT, self.tr('Extent'))) - self.addOutput(QgsProcessingOutputVectorLayer(self.OUTPUT, self.tr("Extent"), QgsProcessingParameterDefinition.TypeVectorPolygon)) + self.addOutput(QgsProcessingOutputVectorLayer(self.OUTPUT, self.tr("Extent"), QgsProcessing.TypeVectorPolygon)) def name(self): return 'polygonfromlayerextent' diff --git a/python/plugins/processing/algs/qgis/FixGeometry.py b/python/plugins/processing/algs/qgis/FixGeometry.py index e06fe5943c9..fe47eabd53a 100644 --- a/python/plugins/processing/algs/qgis/FixGeometry.py +++ b/python/plugins/processing/algs/qgis/FixGeometry.py @@ -30,6 +30,7 @@ from qgis.core import (QgsWkbTypes, QgsFeatureRequest, QgsProcessingFeatureSource, QgsGeometry, + QgsProcessing, QgsProcessingParameterDefinition, QgsProcessingParameterFeatureSource, QgsProcessingParameterFeatureSink, @@ -51,7 +52,7 @@ class FixGeometry(QgisAlgorithm): def __init__(self): super().__init__() - self.addParameter(QgsProcessingParameterFeatureSource(self.INPUT, self.tr('Input layer'), [QgsProcessingParameterDefinition.TypeVectorLine, QgsProcessingParameterDefinition.TypeVectorPolygon])) + self.addParameter(QgsProcessingParameterFeatureSource(self.INPUT, self.tr('Input layer'), [QgsProcessing.TypeVectorLine, QgsProcessing.TypeVectorPolygon])) self.addParameter(QgsProcessingParameterFeatureSink(self.OUTPUT, self.tr('Fixed geometries'))) self.addOutput(QgsProcessingOutputVectorLayer(self.OUTPUT, self.tr("Fixed geometries"))) diff --git a/python/plugins/processing/algs/qgis/GridPolygon.py b/python/plugins/processing/algs/qgis/GridPolygon.py index e450a48be62..5b0d71cc62d 100644 --- a/python/plugins/processing/algs/qgis/GridPolygon.py +++ b/python/plugins/processing/algs/qgis/GridPolygon.py @@ -38,6 +38,7 @@ from qgis.core import (QgsRectangle, QgsGeometry, QgsPointXY, QgsWkbTypes, + QgsProcessing, QgsProcessingParameterEnum, QgsProcessingParameterExtent, QgsProcessingParameterNumber, @@ -100,7 +101,7 @@ class GridPolygon(QgisAlgorithm): self.addParameter(QgsProcessingParameterCrs(self.CRS, 'Grid CRS', 'ProjectCrs')) self.addParameter(QgsProcessingParameterFeatureSink(self.OUTPUT, self.tr('Grid'))) - self.addOutput(QgsProcessingOutputVectorLayer(self.OUTPUT, self.tr('Grid'), QgsProcessingParameterDefinition.TypeVectorPolygon)) + self.addOutput(QgsProcessingOutputVectorLayer(self.OUTPUT, self.tr('Grid'), QgsProcessing.TypeVectorPolygon)) def name(self): return 'creategridpolygon' diff --git a/python/plugins/processing/algs/qgis/Merge.py b/python/plugins/processing/algs/qgis/Merge.py index cd9923c53e5..17843ccdf9b 100644 --- a/python/plugins/processing/algs/qgis/Merge.py +++ b/python/plugins/processing/algs/qgis/Merge.py @@ -33,6 +33,7 @@ from qgis.core import (QgsFields, QgsField, QgsFeatureRequest, QgsFeatureSink, + QgsProcessing, QgsProcessingUtils, QgsProcessingParameterMultipleLayers, QgsProcessingParameterDefinition, @@ -63,7 +64,7 @@ class Merge(QgisAlgorithm): super().__init__() self.addParameter(QgsProcessingParameterMultipleLayers(self.LAYERS, self.tr('Layers to merge'), - QgsProcessingParameterDefinition.TypeVectorAny)) + QgsProcessing.TypeVectorAny)) self.addParameter(QgsProcessingParameterFeatureSink(self.OUTPUT, self.tr('Merged'))) self.addOutput(QgsProcessingOutputVectorLayer(self.OUTPUT, self.tr('Merged'))) diff --git a/python/plugins/processing/algs/qgis/PointsLayerFromTable.py b/python/plugins/processing/algs/qgis/PointsLayerFromTable.py index 065459c178e..0f2cdba8932 100644 --- a/python/plugins/processing/algs/qgis/PointsLayerFromTable.py +++ b/python/plugins/processing/algs/qgis/PointsLayerFromTable.py @@ -30,6 +30,7 @@ from qgis.core import (QgsApplication, QgsPoint, QgsFeatureRequest, QgsGeometry, + QgsProcessing, QgsProcessingParameterDefinition, QgsProcessingParameterFeatureSink, QgsProcessingParameterFeatureSource, @@ -64,7 +65,7 @@ class PointsLayerFromTable(QgisAlgorithm): def __init__(self): super().__init__() - self.addParameter(QgsProcessingParameterFeatureSource(self.INPUT, self.tr('Input layer'), types=[QgsProcessingParameterField.TypeTable])) + self.addParameter(QgsProcessingParameterFeatureSource(self.INPUT, self.tr('Input layer'), types=[QgsProcessing.TypeTable])) self.addParameter(QgsProcessingParameterField(self.XFIELD, self.tr('X field'), parentLayerParameterName=self.INPUT, type=QgsProcessingParameterField.Any)) @@ -77,8 +78,8 @@ class PointsLayerFromTable(QgisAlgorithm): self.addParameter(QgsProcessingParameterCrs(self.TARGET_CRS, self.tr('Target CRS'), defaultValue='EPSG:4326')) - self.addParameter(QgsProcessingParameterFeatureSink(self.OUTPUT, self.tr('Points from table'), type=QgsProcessingParameterDefinition.TypeVectorPoint)) - self.addOutput(QgsProcessingOutputVectorLayer(self.OUTPUT, self.tr('Points from table'), type=QgsProcessingParameterDefinition.TypeVectorPoint)) + self.addParameter(QgsProcessingParameterFeatureSink(self.OUTPUT, self.tr('Points from table'), type=QgsProcessing.TypeVectorPoint)) + self.addOutput(QgsProcessingOutputVectorLayer(self.OUTPUT, self.tr('Points from table'), type=QgsProcessing.TypeVectorPoint)) def name(self): return 'createpointslayerfromtable' diff --git a/python/plugins/processing/algs/qgis/RegularPoints.py b/python/plugins/processing/algs/qgis/RegularPoints.py index 6a0b25f8ec3..a5ee2aa239c 100644 --- a/python/plugins/processing/algs/qgis/RegularPoints.py +++ b/python/plugins/processing/algs/qgis/RegularPoints.py @@ -34,6 +34,7 @@ from qgis.PyQt.QtGui import QIcon from qgis.PyQt.QtCore import QVariant from qgis.core import (QgsRectangle, QgsFields, QgsFeatureSink, QgsField, QgsFeature, QgsWkbTypes, QgsGeometry, QgsPointXY, QgsCoordinateReferenceSystem, + QgsProcessing, QgsProcessingParameterExtent, QgsProcessingParameterNumber, QgsProcessingParameterBoolean, @@ -78,8 +79,8 @@ class RegularPoints(QgisAlgorithm): self.addParameter(QgsProcessingParameterCrs(self.CRS, self.tr('Output layer CRS'), 'ProjectCrs')) - self.addParameter(QgsProcessingParameterFeatureSink(self.OUTPUT, self.tr('Regular points'), QgsProcessingParameterDefinition.TypeVectorPoint)) - self.addOutput(QgsProcessingOutputVectorLayer(self.OUTPUT, self.tr('Regular points'), QgsProcessingParameterDefinition.TypeVectorPoint)) + self.addParameter(QgsProcessingParameterFeatureSink(self.OUTPUT, self.tr('Regular points'), QgsProcessing.TypeVectorPoint)) + self.addOutput(QgsProcessingOutputVectorLayer(self.OUTPUT, self.tr('Regular points'), QgsProcessing.TypeVectorPoint)) def name(self): return 'regularpoints' diff --git a/python/plugins/processing/algs/qgis/SnapGeometries.py b/python/plugins/processing/algs/qgis/SnapGeometries.py index 25eef8cad7e..27c5008550f 100644 --- a/python/plugins/processing/algs/qgis/SnapGeometries.py +++ b/python/plugins/processing/algs/qgis/SnapGeometries.py @@ -28,6 +28,7 @@ __revision__ = '$Format:%H$' from qgis.analysis import (QgsGeometrySnapper, QgsInternalGeometrySnapper) from qgis.core import (QgsFeatureSink, + QgsProcessing, QgsProcessingParameterDefinition, QgsProcessingParameterFeatureSource, QgsProcessingParameterFeatureSink, @@ -52,11 +53,11 @@ class SnapGeometriesToLayer(QgisAlgorithm): def __init__(self): super().__init__() - self.addParameter(QgsProcessingParameterFeatureSource(self.INPUT, self.tr('Input layer'), [QgsProcessingParameterDefinition.TypeVectorPoint, QgsProcessingParameterDefinition.TypeVectorLine, QgsProcessingParameterDefinition.TypeVectorPolygon])) + self.addParameter(QgsProcessingParameterFeatureSource(self.INPUT, self.tr('Input layer'), [QgsProcessing.TypeVectorPoint, QgsProcessing.TypeVectorLine, QgsProcessing.TypeVectorPolygon])) self.addParameter(QgsProcessingParameterFeatureSource(self.REFERENCE_LAYER, self.tr('Reference layer'), - [QgsProcessingParameterDefinition.TypeVectorPoint, - QgsProcessingParameterDefinition.TypeVectorLine, - QgsProcessingParameterDefinition.TypeVectorPolygon])) + [QgsProcessing.TypeVectorPoint, + QgsProcessing.TypeVectorLine, + QgsProcessing.TypeVectorPolygon])) self.addParameter(QgsProcessingParameterNumber(self.TOLERANCE, self.tr('Tolerance (layer units)'), type=QgsProcessingParameterNumber.Double, minValue=0.00000001, maxValue=9999999999, defaultValue=10.0)) diff --git a/python/plugins/processing/algs/qgis/VoronoiPolygons.py b/python/plugins/processing/algs/qgis/VoronoiPolygons.py index 73b9567df99..cbe9bf9dd1f 100644 --- a/python/plugins/processing/algs/qgis/VoronoiPolygons.py +++ b/python/plugins/processing/algs/qgis/VoronoiPolygons.py @@ -36,6 +36,7 @@ from qgis.core import (QgsFeatureRequest, QgsGeometry, QgsPointXY, QgsWkbTypes, + QgsProcessing, QgsProcessingUtils, QgsProcessingParameterFeatureSource, QgsProcessingParameterDefinition, @@ -66,12 +67,12 @@ class VoronoiPolygons(QgisAlgorithm): def __init__(self): super().__init__() - self.addParameter(QgsProcessingParameterFeatureSource(self.INPUT, self.tr('Input layer'), [QgsProcessingParameterDefinition.TypeVectorPoint])) + self.addParameter(QgsProcessingParameterFeatureSource(self.INPUT, self.tr('Input layer'), [QgsProcessing.TypeVectorPoint])) self.addParameter(QgsProcessingParameterNumber(self.BUFFER, self.tr('Buffer region'), type=QgsProcessingParameterNumber.Double, minValue=0.0, maxValue=9999999999, defaultValue=0.0)) - self.addParameter(QgsProcessingParameterFeatureSink(self.OUTPUT, self.tr('Voronoi polygons'), type=QgsProcessingParameterDefinition.TypeVectorPolygon)) - self.addOutput(QgsProcessingOutputVectorLayer(self.OUTPUT, self.tr("Voronoi polygons"), type=QgsProcessingParameterDefinition.TypeVectorPolygon)) + self.addParameter(QgsProcessingParameterFeatureSink(self.OUTPUT, self.tr('Voronoi polygons'), type=QgsProcessing.TypeVectorPolygon)) + self.addOutput(QgsProcessingOutputVectorLayer(self.OUTPUT, self.tr("Voronoi polygons"), type=QgsProcessing.TypeVectorPolygon)) def name(self): return 'voronoipolygons' diff --git a/python/plugins/processing/algs/qgis/ZonalStatistics.py b/python/plugins/processing/algs/qgis/ZonalStatistics.py index 2ae842b5edc..20e5f102d3f 100644 --- a/python/plugins/processing/algs/qgis/ZonalStatistics.py +++ b/python/plugins/processing/algs/qgis/ZonalStatistics.py @@ -32,6 +32,7 @@ from qgis.PyQt.QtGui import QIcon from qgis.analysis import QgsZonalStatistics from qgis.core import (QgsFeatureSink, + QgsProcessing, QgsProcessingUtils, QgsProcessingParameterDefinition, QgsProcessingParameterVectorLayer, @@ -83,7 +84,7 @@ class ZonalStatistics(QgisAlgorithm): minValue=1, maxValue=999, defaultValue=1)) self.addParameter(QgsProcessingParameterVectorLayer(self.INPUT_VECTOR, self.tr('Vector layer containing zones'), - [QgsProcessingParameterDefinition.TypeVectorPolygon])) + [QgsProcessing.TypeVectorPolygon])) self.addParameter(QgsProcessingParameterString(self.COLUMN_PREFIX, self.tr('Output column prefix'), '_')) keys = list(self.STATS.keys()) @@ -93,7 +94,7 @@ class ZonalStatistics(QgisAlgorithm): allowMultiple=True, defaultValue=[0, 1, 2])) self.addOutput(QgsProcessingOutputVectorLayer(self.INPUT_VECTOR, self.tr('Zonal statistics'), - QgsProcessingParameterDefinition.TypeVectorPolygon)) + QgsProcessing.TypeVectorPolygon)) self.bandNumber = None self.columnPrefix = None diff --git a/python/plugins/processing/gui/BatchInputSelectionPanel.py b/python/plugins/processing/gui/BatchInputSelectionPanel.py index 46f21802465..216878af460 100644 --- a/python/plugins/processing/gui/BatchInputSelectionPanel.py +++ b/python/plugins/processing/gui/BatchInputSelectionPanel.py @@ -36,6 +36,7 @@ from qgis.PyQt.QtGui import QCursor from qgis.core import (QgsMapLayer, QgsSettings, QgsProject, + QgsProcessing, QgsProcessingUtils, QgsProcessingParameterMultipleLayers, QgsProcessingParameterRasterLayer, @@ -103,18 +104,18 @@ class BatchInputSelectionPanel(QWidget): layers = [] if (isinstance(self.param, QgsProcessingParameterRasterLayer) or (isinstance(self.param, QgsProcessingParameterMultipleLayers) and - self.param.layerType() == QgsProcessingParameterDefinition.TypeRaster)): + self.param.layerType() == QgsProcessing.TypeRaster)): layers = QgsProcessingUtils.compatibleRasterLayers(QgsProject.instance()) elif isinstance(self.param, QgsProcessingParameterVectorLayer): layers = QgsProcessingUtils.compatibleVectorLayers(QgsProject.instance()) else: - datatypes = [QgsProcessingParameterDefinition.TypeVectorAny] + datatypes = [QgsProcessing.TypeVectorAny] if isinstance(self.param, QgsProcessingParameterFeatureSource): datatypes = self.param.dataTypes() elif isinstance(self.param, QgsProcessingParameterMultipleLayers): datatypes = [self.param.layerType()] - if QgsProcessingParameterDefinition.TypeVectorAny not in datatypes: + if QgsProcessing.TypeVectorAny not in datatypes: layers = QgsProcessingUtils.compatibleVectorLayers(QgsProject.instance(), datatypes) else: layers = QgsProcessingUtils.compatibleVectorLayers(QgsProject.instance()) diff --git a/python/plugins/processing/gui/ParameterGuiUtils.py b/python/plugins/processing/gui/ParameterGuiUtils.py index cd15dd847a8..caf0d0ce1ad 100644 --- a/python/plugins/processing/gui/ParameterGuiUtils.py +++ b/python/plugins/processing/gui/ParameterGuiUtils.py @@ -26,10 +26,10 @@ __copyright__ = '(C) 2017, Nyall Dawson' __revision__ = '$Format:%H$' -from qgis.core import ( - QgsProcessingParameterDefinition, - QgsProcessingFeatureSourceDefinition, - QgsVectorFileWriter) +from qgis.core import (QgsProcessing, + QgsProcessingParameterDefinition, + QgsProcessingFeatureSourceDefinition, + QgsVectorFileWriter) from qgis.PyQt.QtCore import QCoreApplication from processing.tools import dataobjects @@ -47,9 +47,9 @@ def getFileFilter(param): :return: """ if param.type() == 'multilayer': - if param.layerType() == QgsProcessingParameterDefinition.TypeRaster: + if param.layerType() == QgsProcessing.TypeRaster: exts = dataobjects.getSupportedOutputRasterLayerExtensions() - elif param.layerType() == QgsProcessingParameterDefinition.TypeFile: + elif param.layerType() == QgsProcessing.TypeFile: return tr('All files (*.*)', 'QgsProcessingParameterMultipleLayers') else: exts = QgsVectorFileWriter.supportedFormatExtensions() diff --git a/python/plugins/processing/gui/wrappers.py b/python/plugins/processing/gui/wrappers.py index 01122545992..95db14ea33b 100644 --- a/python/plugins/processing/gui/wrappers.py +++ b/python/plugins/processing/gui/wrappers.py @@ -45,6 +45,7 @@ from qgis.core import ( QgsSettings, QgsProject, QgsMapLayer, + QgsProcessing, QgsProcessingUtils, QgsProcessingParameterDefinition, QgsProcessingParameterBoolean, @@ -517,20 +518,20 @@ class FixedTableWidgetWrapper(WidgetWrapper): class MultipleInputWidgetWrapper(WidgetWrapper): def _getOptions(self): - if self.param.layerType() == QgsProcessingParameterDefinition.TypeVectorAny: + if self.param.layerType() == QgsProcessing.TypeVectorAny: options = self.dialog.getAvailableValuesOfType(QgsProcessingParameterFeatureSource, QgsProcessingOutputVectorLayer) - elif self.param.layerType() == QgsProcessingParameterDefinition.TypeVectorPoint: + elif self.param.layerType() == QgsProcessing.TypeVectorPoint: options = self.dialog.getAvailableValuesOfType(QgsProcessingParameterFeatureSource, QgsProcessingOutputVectorLayer, - [QgsProcessingParameterDefinition.TypeVectorPoint, QgsProcessingParameterDefinition.TypeVectorAny]) - elif self.param.layerType() == QgsProcessingParameterDefinition.TypeVectorLine: + [QgsProcessing.TypeVectorPoint, QgsProcessing.TypeVectorAny]) + elif self.param.layerType() == QgsProcessing.TypeVectorLine: options = self.dialog.getAvailableValuesOfType(QgsProcessingParameterFeatureSource, QgsProcessingOutputVectorLayer, - [QgsProcessingParameterDefinition.TypeVectorLine, QgsProcessingParameterDefinition.TypeVectorAny]) - elif self.param.layerType() == QgsProcessingParameterDefinition.TypeVectorPolygon: + [QgsProcessing.TypeVectorLine, QgsProcessing.TypeVectorAny]) + elif self.param.layerType() == QgsProcessing.TypeVectorPolygon: options = self.dialog.getAvailableValuesOfType(QgsProcessingParameterFeatureSource, QgsProcessingOutputVectorLayer, - [QgsProcessingParameterDefinition.TypeVectorPolygon, QgsProcessingParameterDefinition.TypeVectorAny]) - elif self.param.layerType() == QgsProcessingParameterDefinition.TypeRaster: + [QgsProcessing.TypeVectorPolygon, QgsProcessing.TypeVectorAny]) + elif self.param.layerType() == QgsProcessing.TypeRaster: options = self.dialog.getAvailableValuesOfType(QgsProcessingParameterRasterLayer, QgsProcessingOutputRasterLayer) - elif self.param.layerType() == QgsProcessingParameterDefinition.TypeTable: + elif self.param.layerType() == QgsProcessing.TypeTable: options = self.dialog.getAvailableValuesOfType(QgsProcessingParameterVectorLayer, OutputTable) else: options = self.dialog.getAvailableValuesOfType(QgsProcessingParameterFile, OutputFile) @@ -539,12 +540,12 @@ class MultipleInputWidgetWrapper(WidgetWrapper): def createWidget(self): if self.dialogType == DIALOG_STANDARD: - if self.param.layerType() == QgsProcessingParameterDefinition.TypeFile: + if self.param.layerType() == QgsProcessing.TypeFile: return MultipleInputPanel(datatype=dataobjects.TYPE_FILE) else: - if self.param.layerType() == QgsProcessingParameterDefinition.TypeRaster: + if self.param.layerType() == QgsProcessing.TypeRaster: options = QgsProcessingUtils.compatibleRasterLayers(QgsProject.instance(), False) - elif self.param.layerType() in (QgsProcessingParameterDefinition.TypeVectorAny, QgsProcessingParameterDefinition.TypeTable): + elif self.param.layerType() in (QgsProcessing.TypeVectorAny, QgsProcessing.TypeTable): options = QgsProcessingUtils.compatibleVectorLayers(QgsProject.instance(), [], False) else: options = QgsProcessingUtils.compatibleVectorLayers(QgsProject.instance(), [self.param.layerType()], False) @@ -559,10 +560,10 @@ class MultipleInputWidgetWrapper(WidgetWrapper): return MultipleInputPanel(options) def refresh(self): - if self.param.layerType() != QgsProcessingParameterDefinition.TypeFile: - if self.param.layerType() == QgsProcessingParameterDefinition.TypeRaster: + if self.param.layerType() != QgsProcessing.TypeFile: + if self.param.layerType() == QgsProcessing.TypeRaster: options = QgsProcessingUtils.compatibleRasterLayers(QgsProject.instance(), False) - elif self.param.layerType() in (QgsProcessingParameterDefinition.TypeVectorAny, QgsProcessingParameterDefinition.TypeTable): + elif self.param.layerType() in (QgsProcessing.TypeVectorAny, QgsProcessing.TypeTable): options = QgsProcessingUtils.compatibleVectorLayers(QgsProject.instance(), [], False) else: options = QgsProcessingUtils.compatibleVectorLayers(QgsProject.instance(), [self.param.layerType()], False) @@ -584,12 +585,12 @@ class MultipleInputWidgetWrapper(WidgetWrapper): def value(self): if self.dialogType == DIALOG_STANDARD: - if self.param.layerType() == QgsProcessingParameterDefinition.TypeFile: + if self.param.layerType() == QgsProcessing.TypeFile: return self.param.setValue(self.widget.selectedoptions) else: - if self.param.layerType() == QgsProcessingParameterDefinition.TypeRaster: + if self.param.layerType() == QgsProcessing.TypeRaster: options = QgsProcessingUtils.compatibleRasterLayers(QgsProject.instance(), False) - elif self.param.layerType() in (QgsProcessingParameterDefinition.TypeVectorAny, QgsProcessingParameterDefinition.TypeTable): + elif self.param.layerType() in (QgsProcessing.TypeVectorAny, QgsProcessing.TypeTable): options = QgsProcessingUtils.compatibleVectorLayers(QgsProject.instance(), [], False) else: options = QgsProcessingUtils.compatibleVectorLayers(QgsProject.instance(), [self.param.layerType()], False) @@ -599,7 +600,7 @@ class MultipleInputWidgetWrapper(WidgetWrapper): else: options = self._getOptions() values = [options[i] for i in self.widget.selectedoptions] - if len(values) == 0 and not self.param.flags() & QgsProcessingParameterDefinition.FlagOptional: + if len(values) == 0 and not self.param.flags() & QgsProcessing.FlagOptional: raise InvalidParameterValue() return values @@ -784,13 +785,13 @@ class VectorWidgetWrapper(WidgetWrapper): widget.setLayout(vl) filters = QgsMapLayerProxyModel.Filters() - if QgsProcessingParameterDefinition.TypeVectorAny in self.param.dataTypes() or len(self.param.dataTypes()) == 0: + if QgsProcessing.TypeVectorAny in self.param.dataTypes() or len(self.param.dataTypes()) == 0: filters = QgsMapLayerProxyModel.HasGeometry - if QgsProcessingParameterDefinition.TypeVectorPoint in self.param.dataTypes(): + if QgsProcessing.TypeVectorPoint in self.param.dataTypes(): filters |= QgsMapLayerProxyModel.PointLayer - if QgsProcessingParameterDefinition.TypeVectorLine in self.param.dataTypes(): + if QgsProcessing.TypeVectorLine in self.param.dataTypes(): filters |= QgsMapLayerProxyModel.LineLayer - if QgsProcessingParameterDefinition.TypeVectorPolygon in self.param.dataTypes(): + if QgsProcessing.TypeVectorPolygon in self.param.dataTypes(): filters |= QgsMapLayerProxyModel.PolygonLayer try: diff --git a/src/core/CMakeLists.txt b/src/core/CMakeLists.txt index eddc25eed96..5181794b642 100755 --- a/src/core/CMakeLists.txt +++ b/src/core/CMakeLists.txt @@ -922,6 +922,7 @@ SET(QGIS_CORE_HDRS metadata/qgslayermetadatavalidator.h processing/qgsnativealgorithms.h + processing/qgsprocessing.h processing/qgsprocessingalgorithm.h processing/qgsprocessingcontext.h processing/qgsprocessingmodelalgorithm.h diff --git a/src/core/processing/qgsnativealgorithms.cpp b/src/core/processing/qgsnativealgorithms.cpp index 62fc38d41b8..f262d2b280e 100644 --- a/src/core/processing/qgsnativealgorithms.cpp +++ b/src/core/processing/qgsnativealgorithms.cpp @@ -74,8 +74,8 @@ void QgsNativeAlgorithms::loadAlgorithms() QgsCentroidAlgorithm::QgsCentroidAlgorithm() { addParameter( new QgsProcessingParameterFeatureSource( QStringLiteral( "INPUT" ), QObject::tr( "Input layer" ) ) ); - addParameter( new QgsProcessingParameterFeatureSink( QStringLiteral( "OUTPUT" ), QObject::tr( "Centroids" ), QgsProcessingParameterDefinition::TypeVectorPoint ) ); - addOutput( new QgsProcessingOutputVectorLayer( QStringLiteral( "OUTPUT" ), QObject::tr( "Centroids" ), QgsProcessingParameterDefinition::TypeVectorPoint ) ); + addParameter( new QgsProcessingParameterFeatureSink( QStringLiteral( "OUTPUT" ), QObject::tr( "Centroids" ), QgsProcessing::TypeVectorPoint ) ); + addOutput( new QgsProcessingOutputVectorLayer( QStringLiteral( "OUTPUT" ), QObject::tr( "Centroids" ), QgsProcessing::TypeVectorPoint ) ); } QString QgsCentroidAlgorithm::shortHelpString() const @@ -151,8 +151,8 @@ QgsBufferAlgorithm::QgsBufferAlgorithm() addParameter( new QgsProcessingParameterNumber( QStringLiteral( "MITRE_LIMIT" ), QObject::tr( "Miter limit" ), QgsProcessingParameterNumber::Double, 2, false, 1 ) ); addParameter( new QgsProcessingParameterBoolean( QStringLiteral( "DISSOLVE" ), QObject::tr( "Dissolve result" ), false ) ); - addParameter( new QgsProcessingParameterFeatureSink( QStringLiteral( "OUTPUT" ), QObject::tr( "Buffered" ), QgsProcessingParameterDefinition::TypeVectorPolygon ) ); - addOutput( new QgsProcessingOutputVectorLayer( QStringLiteral( "OUTPUT" ), QObject::tr( "Buffered" ), QgsProcessingParameterDefinition::TypeVectorPoint ) ); + addParameter( new QgsProcessingParameterFeatureSink( QStringLiteral( "OUTPUT" ), QObject::tr( "Buffered" ), QgsProcessing::TypeVectorPolygon ) ); + addOutput( new QgsProcessingOutputVectorLayer( QStringLiteral( "OUTPUT" ), QObject::tr( "Buffered" ), QgsProcessing::TypeVectorPoint ) ); } QString QgsBufferAlgorithm::shortHelpString() const @@ -415,7 +415,7 @@ QVariantMap QgsDissolveAlgorithm::processAlgorithm( const QVariantMap ¶meter QgsClipAlgorithm::QgsClipAlgorithm() { addParameter( new QgsProcessingParameterFeatureSource( QStringLiteral( "INPUT" ), QObject::tr( "Input layer" ) ) ); - addParameter( new QgsProcessingParameterFeatureSource( QStringLiteral( "OVERLAY" ), QObject::tr( "Clip layer" ), QList< int >() << QgsProcessingParameterDefinition::TypeVectorPolygon ) ); + addParameter( new QgsProcessingParameterFeatureSource( QStringLiteral( "OVERLAY" ), QObject::tr( "Clip layer" ), QList< int >() << QgsProcessing::TypeVectorPolygon ) ); addParameter( new QgsProcessingParameterFeatureSink( QStringLiteral( "OUTPUT" ), QObject::tr( "Clipped" ) ) ); addOutput( new QgsProcessingOutputVectorLayer( QStringLiteral( "OUTPUT" ), QObject::tr( "Clipped" ) ) ); @@ -799,7 +799,7 @@ QgsExtractByExpressionAlgorithm::QgsExtractByExpressionAlgorithm() addParameter( new QgsProcessingParameterFeatureSink( QStringLiteral( "OUTPUT" ), QObject::tr( "Matching features" ) ) ); addOutput( new QgsProcessingOutputVectorLayer( QStringLiteral( "OUTPUT" ), QObject::tr( "Matching (expression)" ) ) ); addParameter( new QgsProcessingParameterFeatureSink( QStringLiteral( "FAIL_OUTPUT" ), QObject::tr( "Non-matching" ), - QgsProcessingParameterDefinition::TypeVectorAny, QVariant(), true ) ); + QgsProcessing::TypeVectorAny, QVariant(), true ) ); addOutput( new QgsProcessingOutputVectorLayer( QStringLiteral( "FAIL_OUTPUT" ), QObject::tr( "Non-matching (expression)" ) ) ); } @@ -930,7 +930,7 @@ QgsExtractByAttributeAlgorithm::QgsExtractByAttributeAlgorithm() addParameter( new QgsProcessingParameterFeatureSink( QStringLiteral( "OUTPUT" ), QObject::tr( "Extracted (attribute)" ) ) ); addOutput( new QgsProcessingOutputVectorLayer( QStringLiteral( "OUTPUT" ), QObject::tr( "Matching (attribute)" ) ) ); addParameter( new QgsProcessingParameterFeatureSink( QStringLiteral( "FAIL_OUTPUT" ), QObject::tr( "Extracted (non-matching)" ), - QgsProcessingParameterDefinition::TypeVectorAny, QVariant(), true ) ); + QgsProcessing::TypeVectorAny, QVariant(), true ) ); addOutput( new QgsProcessingOutputVectorLayer( QStringLiteral( "FAIL_OUTPUT" ), QObject::tr( "Non-matching (attribute)" ) ) ); } diff --git a/src/core/processing/qgsprocessing.h b/src/core/processing/qgsprocessing.h new file mode 100644 index 00000000000..497c693ae60 --- /dev/null +++ b/src/core/processing/qgsprocessing.h @@ -0,0 +1,61 @@ +/*************************************************************************** + qgsprocessing.h + --------------- + begin : July 2017 + copyright : (C) 2017 by Nyall Dawson + email : nyall dot dawson at gmail dot com + ***************************************************************************/ + +/*************************************************************************** + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + ***************************************************************************/ + +#ifndef QGSPROCESSING_H +#define QGSPROCESSING_H + +#include "qgis_core.h" +#include "qgis.h" +#include "qgsprocessingparameters.h" + +// +// Output definitions +// + +/** + * \class QgsProcessing + * \ingroup core + * + * Contains enumerations and other constants for use in processing algorithms + * and parameters. + * + * \since QGIS 3.0 + */ + +class CORE_EXPORT QgsProcessing +{ + + public: + + //! Layer types enum + enum LayerType + { + TypeAny = -2, //!< Any layer + TypeVectorAny = -1, //!< Any vector layer with geometry + TypeVectorPoint = 0, //!< Vector point layers + TypeVectorLine = 1, //!< Vector line layers + TypeVectorPolygon = 2, //!< Vector polygon layers + TypeRaster = 3, //!< Raster layers + TypeFile = 4, //!< Files + TypeTable = 5, //!< Tables (i.e. vector layers with or without geometry). When used for a sink this indicates the sink has no geometry. + }; + + + +}; + +#endif // QGSPROCESSING_H diff --git a/src/core/processing/qgsprocessingmodelalgorithm.cpp b/src/core/processing/qgsprocessingmodelalgorithm.cpp index 844aebb0989..8d8e0d07f4c 100644 --- a/src/core/processing/qgsprocessingmodelalgorithm.cpp +++ b/src/core/processing/qgsprocessingmodelalgorithm.cpp @@ -874,7 +874,7 @@ QgsProcessingModelAlgorithm::ChildParameterSources QgsProcessingModelAlgorithm:: bool ok = !sourceDef->dataTypes().isEmpty(); Q_FOREACH ( int type, sourceDef->dataTypes() ) { - if ( dataTypes.contains( type ) || type == QgsProcessingParameterDefinition::TypeAny ) + if ( dataTypes.contains( type ) || type == QgsProcessing::TypeAny ) { ok = true; break; @@ -914,7 +914,7 @@ QgsProcessingModelAlgorithm::ChildParameterSources QgsProcessingModelAlgorithm:: if ( out->type() == QgsProcessingOutputVectorLayer::typeName() ) { const QgsProcessingOutputVectorLayer *vectorOut = static_cast< const QgsProcessingOutputVectorLayer *>( out ); - if ( !( dataTypes.contains( vectorOut->dataType() ) || vectorOut->dataType() == QgsProcessingParameterDefinition::TypeAny ) ) + if ( !( dataTypes.contains( vectorOut->dataType() ) || vectorOut->dataType() == QgsProcessing::TypeAny ) ) { continue; } diff --git a/src/core/processing/qgsprocessingoutputs.cpp b/src/core/processing/qgsprocessingoutputs.cpp index f0a6446dced..940cbc5667c 100644 --- a/src/core/processing/qgsprocessingoutputs.cpp +++ b/src/core/processing/qgsprocessingoutputs.cpp @@ -24,17 +24,17 @@ QgsProcessingOutputDefinition::QgsProcessingOutputDefinition( const QString &nam } -QgsProcessingOutputVectorLayer::QgsProcessingOutputVectorLayer( const QString &name, const QString &description, QgsProcessingParameterDefinition::LayerType type ) +QgsProcessingOutputVectorLayer::QgsProcessingOutputVectorLayer( const QString &name, const QString &description, QgsProcessing::LayerType type ) : QgsProcessingOutputDefinition( name, description ) , mDataType( type ) {} -QgsProcessingParameterDefinition::LayerType QgsProcessingOutputVectorLayer::dataType() const +QgsProcessing::LayerType QgsProcessingOutputVectorLayer::dataType() const { return mDataType; } -void QgsProcessingOutputVectorLayer::setDataType( QgsProcessingParameterDefinition::LayerType type ) +void QgsProcessingOutputVectorLayer::setDataType( QgsProcessing::LayerType type ) { mDataType = type; } diff --git a/src/core/processing/qgsprocessingoutputs.h b/src/core/processing/qgsprocessingoutputs.h index 95b77f684f2..5157d2c2ca8 100644 --- a/src/core/processing/qgsprocessingoutputs.h +++ b/src/core/processing/qgsprocessingoutputs.h @@ -126,7 +126,7 @@ class CORE_EXPORT QgsProcessingOutputVectorLayer : public QgsProcessingOutputDef /** * Constructor for QgsProcessingOutputVectorLayer. */ - QgsProcessingOutputVectorLayer( const QString &name, const QString &description = QString(), QgsProcessingParameterDefinition::LayerType type = QgsProcessingParameterDefinition::TypeVectorAny ); + QgsProcessingOutputVectorLayer( const QString &name, const QString &description = QString(), QgsProcessing::LayerType type = QgsProcessing::TypeVectorAny ); /** * Returns the type name for the output class. @@ -138,17 +138,17 @@ class CORE_EXPORT QgsProcessingOutputVectorLayer : public QgsProcessingOutputDef * Returns the layer type for the output layer. * \see setDataType() */ - QgsProcessingParameterDefinition::LayerType dataType() const; + QgsProcessing::LayerType dataType() const; /** * Sets the layer \a type for the output layer. * \see dataType() */ - void setDataType( QgsProcessingParameterDefinition::LayerType type ); + void setDataType( QgsProcessing::LayerType type ); private: - QgsProcessingParameterDefinition::LayerType mDataType = QgsProcessingParameterDefinition::TypeVectorAny; + QgsProcessing::LayerType mDataType = QgsProcessing::TypeVectorAny; }; /** diff --git a/src/core/processing/qgsprocessingparameters.cpp b/src/core/processing/qgsprocessingparameters.cpp index 327c778ce16..4805244dd03 100644 --- a/src/core/processing/qgsprocessingparameters.cpp +++ b/src/core/processing/qgsprocessingparameters.cpp @@ -1421,7 +1421,7 @@ QgsProcessingParameterMatrix *QgsProcessingParameterMatrix::fromScriptCode( cons return new QgsProcessingParameterMatrix( name, description, 0, false, QStringList(), definition.isEmpty() ? QVariant() : definition, isOptional ); } -QgsProcessingParameterMultipleLayers::QgsProcessingParameterMultipleLayers( const QString &name, const QString &description, LayerType layerType, const QVariant &defaultValue, bool optional ) +QgsProcessingParameterMultipleLayers::QgsProcessingParameterMultipleLayers( const QString &name, const QString &description, QgsProcessing::LayerType layerType, const QVariant &defaultValue, bool optional ) : QgsProcessingParameterDefinition( name, description, defaultValue, optional ) , mLayerType( layerType ) { @@ -1521,11 +1521,11 @@ QString QgsProcessingParameterMultipleLayers::asScriptCode() const code += QStringLiteral( "optional " ); switch ( mLayerType ) { - case TypeRaster: + case QgsProcessing::TypeRaster: code += QStringLiteral( "multiple raster" ); break; - case TypeFile: + case QgsProcessing::TypeFile: code += QStringLiteral( "multiple file" ); break; @@ -1554,12 +1554,12 @@ QString QgsProcessingParameterMultipleLayers::asScriptCode() const return code.trimmed(); } -QgsProcessingParameterDefinition::LayerType QgsProcessingParameterMultipleLayers::layerType() const +QgsProcessing::LayerType QgsProcessingParameterMultipleLayers::layerType() const { return mLayerType; } -void QgsProcessingParameterMultipleLayers::setLayerType( LayerType type ) +void QgsProcessingParameterMultipleLayers::setLayerType( QgsProcessing::LayerType type ) { mLayerType = type; } @@ -1586,7 +1586,7 @@ QVariantMap QgsProcessingParameterMultipleLayers::toVariantMap() const bool QgsProcessingParameterMultipleLayers::fromVariantMap( const QVariantMap &map ) { QgsProcessingParameterDefinition::fromVariantMap( map ); - mLayerType = static_cast< LayerType >( map.value( QStringLiteral( "layer_type" ) ).toInt() ); + mLayerType = static_cast< QgsProcessing::LayerType >( map.value( QStringLiteral( "layer_type" ) ).toInt() ); mMinimumNumberInputs = map.value( QStringLiteral( "min_inputs" ) ).toInt(); return true; } @@ -1602,13 +1602,13 @@ QgsProcessingParameterMultipleLayers *QgsProcessingParameterMultipleLayers::from type = m.captured( 1 ).toLower().trimmed(); defaultVal = m.captured( 2 ); } - LayerType layerType = TypeVectorAny; + QgsProcessing::LayerType layerType = QgsProcessing::TypeVectorAny; if ( type == QStringLiteral( "vector" ) ) - layerType = TypeVectorAny; + layerType = QgsProcessing::TypeVectorAny; else if ( type == QStringLiteral( "raster" ) ) - layerType = TypeRaster; + layerType = QgsProcessing::TypeRaster; else if ( type == QStringLiteral( "file" ) ) - layerType = TypeFile; + layerType = QgsProcessing::TypeFile; return new QgsProcessingParameterMultipleLayers( name, description, layerType, defaultVal.isEmpty() ? QVariant() : defaultVal, isOptional ); } @@ -2476,15 +2476,15 @@ QString QgsProcessingParameterFeatureSource::asScriptCode() const { switch ( type ) { - case TypeVectorPoint: + case QgsProcessing::TypeVectorPoint: code += QStringLiteral( "point " ); break; - case TypeVectorLine: + case QgsProcessing::TypeVectorLine: code += QStringLiteral( "line " ); break; - case TypeVectorPolygon: + case QgsProcessing::TypeVectorPolygon: code += QStringLiteral( "polygon " ); break; @@ -2537,19 +2537,19 @@ QgsProcessingParameterFeatureSource *QgsProcessingParameterFeatureSource::fromSc { if ( def.startsWith( QStringLiteral( "point" ), Qt::CaseInsensitive ) ) { - types << QgsProcessingParameterDefinition::TypeVectorPoint; + types << QgsProcessing::TypeVectorPoint; def = def.mid( 6 ); continue; } else if ( def.startsWith( QStringLiteral( "line" ), Qt::CaseInsensitive ) ) { - types << QgsProcessingParameterDefinition::TypeVectorLine; + types << QgsProcessing::TypeVectorLine; def = def.mid( 5 ); continue; } else if ( def.startsWith( QStringLiteral( "polygon" ), Qt::CaseInsensitive ) ) { - types << QgsProcessingParameterDefinition::TypeVectorPolygon; + types << QgsProcessing::TypeVectorPolygon; def = def.mid( 8 ); continue; } @@ -2559,7 +2559,7 @@ QgsProcessingParameterFeatureSource *QgsProcessingParameterFeatureSource::fromSc return new QgsProcessingParameterFeatureSource( name, description, types, def, isOptional ); } -QgsProcessingParameterFeatureSink::QgsProcessingParameterFeatureSink( const QString &name, const QString &description, QgsProcessingParameterDefinition::LayerType type, const QVariant &defaultValue, bool optional ) +QgsProcessingParameterFeatureSink::QgsProcessingParameterFeatureSink( const QString &name, const QString &description, QgsProcessing::LayerType type, const QVariant &defaultValue, bool optional ) : QgsProcessingDestinationParameter( name, description, defaultValue, optional ) , mDataType( type ) { @@ -2622,19 +2622,19 @@ QString QgsProcessingParameterFeatureSink::asScriptCode() const switch ( mDataType ) { - case TypeVectorPoint: + case QgsProcessing::TypeVectorPoint: code += QStringLiteral( "point " ); break; - case TypeVectorLine: + case QgsProcessing::TypeVectorLine: code += QStringLiteral( "line " ); break; - case TypeVectorPolygon: + case QgsProcessing::TypeVectorPolygon: code += QStringLiteral( "polygon " ); break; - case TypeTable: + case QgsProcessing::TypeTable: code += QStringLiteral( "table " ); break; @@ -2664,7 +2664,7 @@ QString QgsProcessingParameterFeatureSink::defaultFileExtension() const } } -QgsProcessingParameterDefinition::LayerType QgsProcessingParameterFeatureSink::dataType() const +QgsProcessing::LayerType QgsProcessingParameterFeatureSink::dataType() const { return mDataType; } @@ -2673,22 +2673,22 @@ bool QgsProcessingParameterFeatureSink::hasGeometry() const { switch ( mDataType ) { - case TypeAny: - case TypeVectorAny: - case TypeVectorPoint: - case TypeVectorLine: - case TypeVectorPolygon: - case TypeTable: + case QgsProcessing::TypeAny: + case QgsProcessing::TypeVectorAny: + case QgsProcessing::TypeVectorPoint: + case QgsProcessing::TypeVectorLine: + case QgsProcessing::TypeVectorPolygon: + case QgsProcessing::TypeTable: return true; - case TypeRaster: - case TypeFile: + case QgsProcessing::TypeRaster: + case QgsProcessing::TypeFile: return false; } return true; } -void QgsProcessingParameterFeatureSink::setDataType( QgsProcessingParameterDefinition::LayerType type ) +void QgsProcessingParameterFeatureSink::setDataType( QgsProcessing::LayerType type ) { mDataType = type; } @@ -2703,7 +2703,7 @@ QVariantMap QgsProcessingParameterFeatureSink::toVariantMap() const bool QgsProcessingParameterFeatureSink::fromVariantMap( const QVariantMap &map ) { QgsProcessingDestinationParameter::fromVariantMap( map ); - mDataType = static_cast< QgsProcessingParameterDefinition::LayerType >( map.value( QStringLiteral( "data_type" ) ).toInt() ); + mDataType = static_cast< QgsProcessing::LayerType >( map.value( QStringLiteral( "data_type" ) ).toInt() ); return true; } @@ -2717,26 +2717,26 @@ QString QgsProcessingParameterFeatureSink::generateTemporaryDestination() const QgsProcessingParameterFeatureSink *QgsProcessingParameterFeatureSink::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition ) { - QgsProcessingParameterDefinition::LayerType type = QgsProcessingParameterDefinition::TypeVectorAny; + QgsProcessing::LayerType type = QgsProcessing::TypeVectorAny; QString def = definition; if ( def.startsWith( QStringLiteral( "point" ), Qt::CaseInsensitive ) ) { - type = QgsProcessingParameterDefinition::TypeVectorPoint; + type = QgsProcessing::TypeVectorPoint; def = def.mid( 6 ); } else if ( def.startsWith( QStringLiteral( "line" ), Qt::CaseInsensitive ) ) { - type = QgsProcessingParameterDefinition::TypeVectorLine; + type = QgsProcessing::TypeVectorLine; def = def.mid( 5 ); } else if ( def.startsWith( QStringLiteral( "polygon" ), Qt::CaseInsensitive ) ) { - type = QgsProcessingParameterDefinition::TypeVectorPolygon; + type = QgsProcessing::TypeVectorPolygon; def = def.mid( 8 ); } else if ( def.startsWith( QStringLiteral( "table" ), Qt::CaseInsensitive ) ) { - type = QgsProcessingParameterDefinition::TypeTable; + type = QgsProcessing::TypeTable; def = def.mid( 6 ); } @@ -2980,7 +2980,7 @@ QString QgsProcessingDestinationParameter::generateTemporaryDestination() const return QgsProcessingUtils::generateTempFilename( name() + '.' + defaultFileExtension() ); } -QgsProcessingParameterVectorOutput::QgsProcessingParameterVectorOutput( const QString &name, const QString &description, QgsProcessingParameterDefinition::LayerType type, const QVariant &defaultValue, bool optional ) +QgsProcessingParameterVectorOutput::QgsProcessingParameterVectorOutput( const QString &name, const QString &description, QgsProcessing::LayerType type, const QVariant &defaultValue, bool optional ) : QgsProcessingDestinationParameter( name, description, defaultValue, optional ) , mDataType( type ) { @@ -3043,15 +3043,15 @@ QString QgsProcessingParameterVectorOutput::asScriptCode() const switch ( mDataType ) { - case TypeVectorPoint: + case QgsProcessing::TypeVectorPoint: code += QStringLiteral( "point " ); break; - case TypeVectorLine: + case QgsProcessing::TypeVectorLine: code += QStringLiteral( "line " ); break; - case TypeVectorPolygon: + case QgsProcessing::TypeVectorPolygon: code += QStringLiteral( "polygon " ); break; @@ -3081,7 +3081,7 @@ QString QgsProcessingParameterVectorOutput::defaultFileExtension() const } } -QgsProcessingParameterDefinition::LayerType QgsProcessingParameterVectorOutput::dataType() const +QgsProcessing::LayerType QgsProcessingParameterVectorOutput::dataType() const { return mDataType; } @@ -3090,22 +3090,22 @@ bool QgsProcessingParameterVectorOutput::hasGeometry() const { switch ( mDataType ) { - case TypeAny: - case TypeVectorAny: - case TypeVectorPoint: - case TypeVectorLine: - case TypeVectorPolygon: - case TypeTable: + case QgsProcessing::TypeAny: + case QgsProcessing::TypeVectorAny: + case QgsProcessing::TypeVectorPoint: + case QgsProcessing::TypeVectorLine: + case QgsProcessing::TypeVectorPolygon: + case QgsProcessing::TypeTable: return true; - case TypeRaster: - case TypeFile: + case QgsProcessing::TypeRaster: + case QgsProcessing::TypeFile: return false; } return true; } -void QgsProcessingParameterVectorOutput::setDataType( QgsProcessingParameterDefinition::LayerType type ) +void QgsProcessingParameterVectorOutput::setDataType( QgsProcessing::LayerType type ) { mDataType = type; } @@ -3120,27 +3120,27 @@ QVariantMap QgsProcessingParameterVectorOutput::toVariantMap() const bool QgsProcessingParameterVectorOutput::fromVariantMap( const QVariantMap &map ) { QgsProcessingDestinationParameter::fromVariantMap( map ); - mDataType = static_cast< QgsProcessingParameterDefinition::LayerType >( map.value( QStringLiteral( "data_type" ) ).toInt() ); + mDataType = static_cast< QgsProcessing::LayerType >( map.value( QStringLiteral( "data_type" ) ).toInt() ); return true; } QgsProcessingParameterVectorOutput *QgsProcessingParameterVectorOutput::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition ) { - QgsProcessingParameterDefinition::LayerType type = QgsProcessingParameterDefinition::TypeVectorAny; + QgsProcessing::LayerType type = QgsProcessing::TypeVectorAny; QString def = definition; if ( def.startsWith( QStringLiteral( "point" ), Qt::CaseInsensitive ) ) { - type = QgsProcessingParameterDefinition::TypeVectorPoint; + type = QgsProcessing::TypeVectorPoint; def = def.mid( 6 ); } else if ( def.startsWith( QStringLiteral( "line" ), Qt::CaseInsensitive ) ) { - type = QgsProcessingParameterDefinition::TypeVectorLine; + type = QgsProcessing::TypeVectorLine; def = def.mid( 5 ); } else if ( def.startsWith( QStringLiteral( "polygon" ), Qt::CaseInsensitive ) ) { - type = QgsProcessingParameterDefinition::TypeVectorPolygon; + type = QgsProcessing::TypeVectorPolygon; def = def.mid( 8 ); } diff --git a/src/core/processing/qgsprocessingparameters.h b/src/core/processing/qgsprocessingparameters.h index 261264cd6f3..00ae0f2dc6e 100644 --- a/src/core/processing/qgsprocessingparameters.h +++ b/src/core/processing/qgsprocessingparameters.h @@ -20,6 +20,7 @@ #include "qgis_core.h" #include "qgis.h" +#include "qgsprocessing.h" #include "qgsproperty.h" #include "qgscoordinatereferencesystem.h" #include @@ -244,19 +245,6 @@ class CORE_EXPORT QgsProcessingParameterDefinition }; Q_DECLARE_FLAGS( Flags, Flag ) - //! Layer types enum - enum LayerType - { - TypeAny = -2, //!< Any layer - TypeVectorAny = -1, //!< Any vector layer with geometry - TypeVectorPoint = 0, //!< Vector point layers - TypeVectorLine = 1, //!< Vector line layers - TypeVectorPolygon = 2, //!< Vector polygon layers - TypeRaster = 3, //!< Raster layers - TypeFile = 4, //!< Files - TypeTable = 5, //!< Tables (i.e. vector layers with or without geometry). When used for a sink this indicates the sink has no geometry. - }; - /** * Constructor for QgsProcessingParameterDefinition. */ @@ -948,7 +936,7 @@ class CORE_EXPORT QgsProcessingParameterMultipleLayers : public QgsProcessingPar /** * Constructor for QgsProcessingParameterMultipleLayers. */ - QgsProcessingParameterMultipleLayers( const QString &name, const QString &description = QString(), QgsProcessingParameterDefinition::LayerType layerType = QgsProcessingParameterDefinition::TypeVectorAny, + QgsProcessingParameterMultipleLayers( const QString &name, const QString &description = QString(), QgsProcessing::LayerType layerType = QgsProcessing::TypeVectorAny, const QVariant &defaultValue = QVariant(), bool optional = false ); @@ -965,13 +953,13 @@ class CORE_EXPORT QgsProcessingParameterMultipleLayers : public QgsProcessingPar * Returns the layer type for layers acceptable by the parameter. * \see setLayerType() */ - QgsProcessingParameterDefinition::LayerType layerType() const; + QgsProcessing::LayerType layerType() const; /** * Sets the layer \a type for layers acceptable by the parameter. * \see layerType() */ - void setLayerType( QgsProcessingParameterDefinition::LayerType type ); + void setLayerType( QgsProcessing::LayerType type ); /** * Returns the minimum number of layers required for the parameter. If the return value is < 1 @@ -997,7 +985,7 @@ class CORE_EXPORT QgsProcessingParameterMultipleLayers : public QgsProcessingPar private: - LayerType mLayerType = TypeVectorAny; + QgsProcessing::LayerType mLayerType = QgsProcessing::TypeVectorAny; int mMinimumNumberInputs = 0; }; @@ -1509,7 +1497,7 @@ class CORE_EXPORT QgsProcessingParameterFeatureSource : public QgsProcessingPara private: - QList< int > mDataTypes = QList< int >() << QgsProcessingParameterDefinition::TypeVectorAny; + QList< int > mDataTypes = QList< int >() << QgsProcessing::TypeVectorAny; }; @@ -1589,7 +1577,7 @@ class CORE_EXPORT QgsProcessingParameterFeatureSink : public QgsProcessingDestin /** * Constructor for QgsProcessingParameterFeatureSink. */ - QgsProcessingParameterFeatureSink( const QString &name, const QString &description = QString(), QgsProcessingParameterDefinition::LayerType type = QgsProcessingParameterDefinition::TypeVectorAny, const QVariant &defaultValue = QVariant(), + QgsProcessingParameterFeatureSink( const QString &name, const QString &description = QString(), QgsProcessing::LayerType type = QgsProcessing::TypeVectorAny, const QVariant &defaultValue = QVariant(), bool optional = false ); /** @@ -1607,7 +1595,7 @@ class CORE_EXPORT QgsProcessingParameterFeatureSink : public QgsProcessingDestin * Returns the layer type for sinks associated with the parameter. * \see setDataType() */ - QgsProcessingParameterDefinition::LayerType dataType() const; + QgsProcessing::LayerType dataType() const; /** * Returns true if sink is likely to include geometries. In cases were presence of geometry @@ -1619,7 +1607,7 @@ class CORE_EXPORT QgsProcessingParameterFeatureSink : public QgsProcessingDestin * Sets the layer \a type for the sinks associated with the parameter. * \see dataType() */ - void setDataType( QgsProcessingParameterDefinition::LayerType type ); + void setDataType( QgsProcessing::LayerType type ); QVariantMap toVariantMap() const override; bool fromVariantMap( const QVariantMap &map ) override; @@ -1632,7 +1620,7 @@ class CORE_EXPORT QgsProcessingParameterFeatureSink : public QgsProcessingDestin private: - QgsProcessingParameterDefinition::LayerType mDataType = QgsProcessingParameterDefinition::TypeVectorAny; + QgsProcessing::LayerType mDataType = QgsProcessing::TypeVectorAny; }; @@ -1650,7 +1638,7 @@ class CORE_EXPORT QgsProcessingParameterVectorOutput : public QgsProcessingDesti /** * Constructor for QgsProcessingParameterVectorOutput. */ - QgsProcessingParameterVectorOutput( const QString &name, const QString &description = QString(), QgsProcessingParameterDefinition::LayerType type = QgsProcessingParameterDefinition::TypeVectorAny, const QVariant &defaultValue = QVariant(), + QgsProcessingParameterVectorOutput( const QString &name, const QString &description = QString(), QgsProcessing::LayerType type = QgsProcessing::TypeVectorAny, const QVariant &defaultValue = QVariant(), bool optional = false ); /** @@ -1668,7 +1656,7 @@ class CORE_EXPORT QgsProcessingParameterVectorOutput : public QgsProcessingDesti * Returns the layer type for layers associated with the parameter. * \see setDataType() */ - QgsProcessingParameterDefinition::LayerType dataType() const; + QgsProcessing::LayerType dataType() const; /** * Returns true if the layer is likely to include geometries. In cases were presence of geometry @@ -1680,7 +1668,7 @@ class CORE_EXPORT QgsProcessingParameterVectorOutput : public QgsProcessingDesti * Sets the layer \a type for the layers associated with the parameter. * \see dataType() */ - void setDataType( QgsProcessingParameterDefinition::LayerType type ); + void setDataType( QgsProcessing::LayerType type ); QVariantMap toVariantMap() const override; bool fromVariantMap( const QVariantMap &map ) override; @@ -1693,7 +1681,7 @@ class CORE_EXPORT QgsProcessingParameterVectorOutput : public QgsProcessingDesti private: - QgsProcessingParameterDefinition::LayerType mDataType = QgsProcessingParameterDefinition::TypeVectorAny; + QgsProcessing::LayerType mDataType = QgsProcessing::TypeVectorAny; }; /** diff --git a/tests/src/core/testqgsprocessing.cpp b/tests/src/core/testqgsprocessing.cpp index 9c008b33a24..2779550165d 100644 --- a/tests/src/core/testqgsprocessing.cpp +++ b/tests/src/core/testqgsprocessing.cpp @@ -2159,7 +2159,7 @@ void TestQgsProcessing::parameterLayerList() context.setProject( &p ); // not optional! - std::unique_ptr< QgsProcessingParameterMultipleLayers > def( new QgsProcessingParameterMultipleLayers( "non_optional", QString(), QgsProcessingParameterDefinition::TypeAny, QString(), false ) ); + std::unique_ptr< QgsProcessingParameterMultipleLayers > def( new QgsProcessingParameterMultipleLayers( "non_optional", QString(), QgsProcessing::TypeAny, QString(), false ) ); QVERIFY( !def->checkValueIsAcceptable( false ) ); QVERIFY( !def->checkValueIsAcceptable( true ) ); QVERIFY( !def->checkValueIsAcceptable( 5 ) ); @@ -2245,7 +2245,7 @@ void TestQgsProcessing::parameterLayerList() QCOMPARE( fromCode->description(), QStringLiteral( "non optional" ) ); QCOMPARE( fromCode->flags(), def->flags() ); QVERIFY( !fromCode->defaultValue().isValid() ); - QCOMPARE( fromCode->layerType(), QgsProcessingParameterDefinition::TypeVectorAny ); + QCOMPARE( fromCode->layerType(), QgsProcessing::TypeVectorAny ); QVariantMap map = def->toVariantMap(); QgsProcessingParameterMultipleLayers fromMap( "x" ); @@ -2260,7 +2260,7 @@ void TestQgsProcessing::parameterLayerList() QVERIFY( dynamic_cast< QgsProcessingParameterMultipleLayers *>( def.get() ) ); // optional with one default layer - def.reset( new QgsProcessingParameterMultipleLayers( "optional", QString(), QgsProcessingParameterDefinition::TypeAny, v1->id(), true ) ); + def.reset( new QgsProcessingParameterMultipleLayers( "optional", QString(), QgsProcessing::TypeAny, v1->id(), true ) ); QVERIFY( !def->checkValueIsAcceptable( false ) ); QVERIFY( !def->checkValueIsAcceptable( true ) ); QVERIFY( !def->checkValueIsAcceptable( 5 ) ); @@ -2289,10 +2289,10 @@ void TestQgsProcessing::parameterLayerList() QCOMPARE( fromCode->description(), QStringLiteral( "optional" ) ); QCOMPARE( fromCode->flags(), def->flags() ); QCOMPARE( fromCode->defaultValue(), def->defaultValue() ); - QCOMPARE( fromCode->layerType(), QgsProcessingParameterDefinition::TypeVectorAny ); + QCOMPARE( fromCode->layerType(), QgsProcessing::TypeVectorAny ); // optional with two default layers - def.reset( new QgsProcessingParameterMultipleLayers( "optional", QString(), QgsProcessingParameterDefinition::TypeAny, QVariantList() << v1->id() << r1->publicSource(), true ) ); + def.reset( new QgsProcessingParameterMultipleLayers( "optional", QString(), QgsProcessing::TypeAny, QVariantList() << v1->id() << r1->publicSource(), true ) ); params.insert( "optional", QVariant() ); QCOMPARE( QgsProcessingParameters::parameterAsLayerList( def.get(), params, context ), QList< QgsMapLayer *>() << v1 << r1 ); @@ -2304,17 +2304,17 @@ void TestQgsProcessing::parameterLayerList() QCOMPARE( fromCode->description(), QStringLiteral( "optional" ) ); QCOMPARE( fromCode->flags(), def->flags() ); QCOMPARE( fromCode->defaultValue().toString(), v1->id() + "," + r1->publicSource() ); - QCOMPARE( fromCode->layerType(), QgsProcessingParameterDefinition::TypeVectorAny ); + QCOMPARE( fromCode->layerType(), QgsProcessing::TypeVectorAny ); // optional with one default direct layer - def.reset( new QgsProcessingParameterMultipleLayers( "optional", QString(), QgsProcessingParameterDefinition::TypeAny, QVariant::fromValue( v1 ), true ) ); + def.reset( new QgsProcessingParameterMultipleLayers( "optional", QString(), QgsProcessing::TypeAny, QVariant::fromValue( v1 ), true ) ); QCOMPARE( QgsProcessingParameters::parameterAsLayerList( def.get(), params, context ), QList< QgsMapLayer *>() << v1 ); // optional with two default direct layers - def.reset( new QgsProcessingParameterMultipleLayers( "optional", QString(), QgsProcessingParameterDefinition::TypeAny, QVariantList() << QVariant::fromValue( v1 ) << QVariant::fromValue( r1 ), true ) ); + def.reset( new QgsProcessingParameterMultipleLayers( "optional", QString(), QgsProcessing::TypeAny, QVariantList() << QVariant::fromValue( v1 ) << QVariant::fromValue( r1 ), true ) ); QCOMPARE( QgsProcessingParameters::parameterAsLayerList( def.get(), params, context ), QList< QgsMapLayer *>() << v1 << r1 ); - def.reset( new QgsProcessingParameterMultipleLayers( "type", QString(), QgsProcessingParameterDefinition::TypeRaster ) ); + def.reset( new QgsProcessingParameterMultipleLayers( "type", QString(), QgsProcessing::TypeRaster ) ); code = def->asScriptCode(); QCOMPARE( code, QStringLiteral( "##type=multiple raster" ) ); fromCode.reset( dynamic_cast< QgsProcessingParameterMultipleLayers * >( QgsProcessingParameters::parameterFromScriptCode( code ) ) ); @@ -2323,9 +2323,9 @@ void TestQgsProcessing::parameterLayerList() QCOMPARE( fromCode->description(), QStringLiteral( "type" ) ); QCOMPARE( fromCode->flags(), def->flags() ); QVERIFY( !fromCode->defaultValue().isValid() ); - QCOMPARE( fromCode->layerType(), QgsProcessingParameterDefinition::TypeRaster ); + QCOMPARE( fromCode->layerType(), QgsProcessing::TypeRaster ); - def.reset( new QgsProcessingParameterMultipleLayers( "type", QString(), QgsProcessingParameterDefinition::TypeFile ) ); + def.reset( new QgsProcessingParameterMultipleLayers( "type", QString(), QgsProcessing::TypeFile ) ); code = def->asScriptCode(); QCOMPARE( code, QStringLiteral( "##type=multiple file" ) ); fromCode.reset( dynamic_cast< QgsProcessingParameterMultipleLayers * >( QgsProcessingParameters::parameterFromScriptCode( code ) ) ); @@ -3345,7 +3345,7 @@ void TestQgsProcessing::parameterFeatureSource() context.setProject( &p ); // not optional! - std::unique_ptr< QgsProcessingParameterFeatureSource > def( new QgsProcessingParameterFeatureSource( "non_optional", QString(), QList< int >() << QgsProcessingParameterDefinition::TypeVectorAny, QString(), false ) ); + std::unique_ptr< QgsProcessingParameterFeatureSource > def( new QgsProcessingParameterFeatureSource( "non_optional", QString(), QList< int >() << QgsProcessing::TypeVectorAny, QString(), false ) ); QVERIFY( !def->checkValueIsAcceptable( false ) ); QVERIFY( !def->checkValueIsAcceptable( true ) ); QVERIFY( !def->checkValueIsAcceptable( 5 ) ); @@ -3413,25 +3413,25 @@ void TestQgsProcessing::parameterFeatureSource() QCOMPARE( fromCode->flags(), def->flags() ); QCOMPARE( fromCode->defaultValue(), def->defaultValue() ); - def->setDataTypes( QList< int >() << QgsProcessingParameterDefinition::TypeVectorPoint ); + def->setDataTypes( QList< int >() << QgsProcessing::TypeVectorPoint ); code = def->asScriptCode(); QCOMPARE( code, QStringLiteral( "##non_optional=source point" ) ); - def->setDataTypes( QList< int >() << QgsProcessingParameterDefinition::TypeVectorLine ); + def->setDataTypes( QList< int >() << QgsProcessing::TypeVectorLine ); code = def->asScriptCode(); QCOMPARE( code, QStringLiteral( "##non_optional=source line" ) ); - def->setDataTypes( QList< int >() << QgsProcessingParameterDefinition::TypeVectorPolygon ); + def->setDataTypes( QList< int >() << QgsProcessing::TypeVectorPolygon ); code = def->asScriptCode(); QCOMPARE( code, QStringLiteral( "##non_optional=source polygon" ) ); - def->setDataTypes( QList< int >() << QgsProcessingParameterDefinition::TypeVectorPoint << QgsProcessingParameterDefinition::TypeVectorLine ); + def->setDataTypes( QList< int >() << QgsProcessing::TypeVectorPoint << QgsProcessing::TypeVectorLine ); code = def->asScriptCode(); QCOMPARE( code, QStringLiteral( "##non_optional=source point line" ) ); - def->setDataTypes( QList< int >() << QgsProcessingParameterDefinition::TypeVectorPoint << QgsProcessingParameterDefinition::TypeVectorPolygon ); + def->setDataTypes( QList< int >() << QgsProcessing::TypeVectorPoint << QgsProcessing::TypeVectorPolygon ); code = def->asScriptCode(); QCOMPARE( code, QStringLiteral( "##non_optional=source point polygon" ) ); // optional - def.reset( new QgsProcessingParameterFeatureSource( "optional", QString(), QList< int >() << QgsProcessingParameterDefinition::TypeVectorAny, v1->id(), true ) ); + def.reset( new QgsProcessingParameterFeatureSource( "optional", QString(), QList< int >() << QgsProcessing::TypeVectorAny, v1->id(), true ) ); params.insert( "optional", QVariant() ); QCOMPARE( QgsProcessingParameters::parameterAsVectorLayer( def.get(), params, context )->id(), v1->id() ); QVERIFY( def->checkValueIsAcceptable( false ) ); @@ -3454,7 +3454,7 @@ void TestQgsProcessing::parameterFeatureSource() //optional with direct layer default - def.reset( new QgsProcessingParameterFeatureSource( "optional", QString(), QList< int >() << QgsProcessingParameterDefinition::TypeVectorAny, QVariant::fromValue( v1 ), true ) ); + def.reset( new QgsProcessingParameterFeatureSource( "optional", QString(), QList< int >() << QgsProcessing::TypeVectorAny, QVariant::fromValue( v1 ), true ) ); QCOMPARE( QgsProcessingParameters::parameterAsVectorLayer( def.get(), params, context )->id(), v1->id() ); } @@ -3467,7 +3467,7 @@ void TestQgsProcessing::parameterFeatureSink() context.setProject( &p ); // not optional! - std::unique_ptr< QgsProcessingParameterFeatureSink > def( new QgsProcessingParameterFeatureSink( "non_optional", QString(), QgsProcessingParameterDefinition::TypeVectorAny, QString(), false ) ); + std::unique_ptr< QgsProcessingParameterFeatureSink > def( new QgsProcessingParameterFeatureSink( "non_optional", QString(), QgsProcessing::TypeVectorAny, QString(), false ) ); QVERIFY( !def->checkValueIsAcceptable( false ) ); QVERIFY( !def->checkValueIsAcceptable( true ) ); QVERIFY( !def->checkValueIsAcceptable( 5 ) ); @@ -3514,29 +3514,29 @@ void TestQgsProcessing::parameterFeatureSink() QCOMPARE( fromCode->defaultValue(), def->defaultValue() ); QCOMPARE( fromCode->dataType(), def->dataType() ); - def->setDataType( QgsProcessingParameterDefinition::TypeVectorPoint ); + def->setDataType( QgsProcessing::TypeVectorPoint ); code = def->asScriptCode(); QCOMPARE( code, QStringLiteral( "##non_optional=sink point" ) ); fromCode.reset( dynamic_cast< QgsProcessingParameterFeatureSink * >( QgsProcessingParameters::parameterFromScriptCode( code ) ) ); QCOMPARE( fromCode->dataType(), def->dataType() ); - def->setDataType( QgsProcessingParameterDefinition::TypeVectorLine ); + def->setDataType( QgsProcessing::TypeVectorLine ); code = def->asScriptCode(); QCOMPARE( code, QStringLiteral( "##non_optional=sink line" ) ); fromCode.reset( dynamic_cast< QgsProcessingParameterFeatureSink * >( QgsProcessingParameters::parameterFromScriptCode( code ) ) ); QCOMPARE( fromCode->dataType(), def->dataType() ); - def->setDataType( QgsProcessingParameterDefinition::TypeVectorPolygon ); + def->setDataType( QgsProcessing::TypeVectorPolygon ); code = def->asScriptCode(); QCOMPARE( code, QStringLiteral( "##non_optional=sink polygon" ) ); fromCode.reset( dynamic_cast< QgsProcessingParameterFeatureSink * >( QgsProcessingParameters::parameterFromScriptCode( code ) ) ); QCOMPARE( fromCode->dataType(), def->dataType() ); - def->setDataType( QgsProcessingParameterDefinition::TypeTable ); + def->setDataType( QgsProcessing::TypeTable ); code = def->asScriptCode(); QCOMPARE( code, QStringLiteral( "##non_optional=sink table" ) ); fromCode.reset( dynamic_cast< QgsProcessingParameterFeatureSink * >( QgsProcessingParameters::parameterFromScriptCode( code ) ) ); QCOMPARE( fromCode->dataType(), def->dataType() ); // optional - def.reset( new QgsProcessingParameterFeatureSink( "optional", QString(), QgsProcessingParameterDefinition::TypeVectorAny, QString(), true ) ); + def.reset( new QgsProcessingParameterFeatureSink( "optional", QString(), QgsProcessing::TypeVectorAny, QString(), true ) ); QVERIFY( !def->checkValueIsAcceptable( false ) ); QVERIFY( !def->checkValueIsAcceptable( true ) ); QVERIFY( !def->checkValueIsAcceptable( 5 ) ); @@ -3556,14 +3556,14 @@ void TestQgsProcessing::parameterFeatureSink() QCOMPARE( fromCode->dataType(), def->dataType() ); // test hasGeometry - QVERIFY( QgsProcessingParameterFeatureSink( "test", QString(), QgsProcessingParameterDefinition::TypeAny ).hasGeometry() ); - QVERIFY( QgsProcessingParameterFeatureSink( "test", QString(), QgsProcessingParameterDefinition::TypeVectorAny ).hasGeometry() ); - QVERIFY( QgsProcessingParameterFeatureSink( "test", QString(), QgsProcessingParameterDefinition::TypeVectorPoint ).hasGeometry() ); - QVERIFY( QgsProcessingParameterFeatureSink( "test", QString(), QgsProcessingParameterDefinition::TypeVectorLine ).hasGeometry() ); - QVERIFY( QgsProcessingParameterFeatureSink( "test", QString(), QgsProcessingParameterDefinition::TypeVectorPolygon ).hasGeometry() ); - QVERIFY( !QgsProcessingParameterFeatureSink( "test", QString(), QgsProcessingParameterDefinition::TypeRaster ).hasGeometry() ); - QVERIFY( !QgsProcessingParameterFeatureSink( "test", QString(), QgsProcessingParameterDefinition::TypeFile ).hasGeometry() ); - QVERIFY( QgsProcessingParameterFeatureSink( "test", QString(), QgsProcessingParameterDefinition::TypeTable ).hasGeometry() ); + QVERIFY( QgsProcessingParameterFeatureSink( "test", QString(), QgsProcessing::TypeAny ).hasGeometry() ); + QVERIFY( QgsProcessingParameterFeatureSink( "test", QString(), QgsProcessing::TypeVectorAny ).hasGeometry() ); + QVERIFY( QgsProcessingParameterFeatureSink( "test", QString(), QgsProcessing::TypeVectorPoint ).hasGeometry() ); + QVERIFY( QgsProcessingParameterFeatureSink( "test", QString(), QgsProcessing::TypeVectorLine ).hasGeometry() ); + QVERIFY( QgsProcessingParameterFeatureSink( "test", QString(), QgsProcessing::TypeVectorPolygon ).hasGeometry() ); + QVERIFY( !QgsProcessingParameterFeatureSink( "test", QString(), QgsProcessing::TypeRaster ).hasGeometry() ); + QVERIFY( !QgsProcessingParameterFeatureSink( "test", QString(), QgsProcessing::TypeFile ).hasGeometry() ); + QVERIFY( QgsProcessingParameterFeatureSink( "test", QString(), QgsProcessing::TypeTable ).hasGeometry() ); } @@ -3576,7 +3576,7 @@ void TestQgsProcessing::parameterVectorOut() context.setProject( &p ); // not optional! - std::unique_ptr< QgsProcessingParameterVectorOutput > def( new QgsProcessingParameterVectorOutput( "non_optional", QString(), QgsProcessingParameterDefinition::TypeVectorAny, QString(), false ) ); + std::unique_ptr< QgsProcessingParameterVectorOutput > def( new QgsProcessingParameterVectorOutput( "non_optional", QString(), QgsProcessing::TypeVectorAny, QString(), false ) ); QVERIFY( !def->checkValueIsAcceptable( false ) ); QVERIFY( !def->checkValueIsAcceptable( true ) ); QVERIFY( !def->checkValueIsAcceptable( 5 ) ); @@ -3620,24 +3620,24 @@ void TestQgsProcessing::parameterVectorOut() QCOMPARE( fromCode->defaultValue(), def->defaultValue() ); QCOMPARE( fromCode->dataType(), def->dataType() ); - def->setDataType( QgsProcessingParameterDefinition::TypeVectorPoint ); + def->setDataType( QgsProcessing::TypeVectorPoint ); code = def->asScriptCode(); QCOMPARE( code, QStringLiteral( "##non_optional=vectorOut point" ) ); fromCode.reset( dynamic_cast< QgsProcessingParameterVectorOutput * >( QgsProcessingParameters::parameterFromScriptCode( code ) ) ); QCOMPARE( fromCode->dataType(), def->dataType() ); - def->setDataType( QgsProcessingParameterDefinition::TypeVectorLine ); + def->setDataType( QgsProcessing::TypeVectorLine ); code = def->asScriptCode(); QCOMPARE( code, QStringLiteral( "##non_optional=vectorOut line" ) ); fromCode.reset( dynamic_cast< QgsProcessingParameterVectorOutput * >( QgsProcessingParameters::parameterFromScriptCode( code ) ) ); QCOMPARE( fromCode->dataType(), def->dataType() ); - def->setDataType( QgsProcessingParameterDefinition::TypeVectorPolygon ); + def->setDataType( QgsProcessing::TypeVectorPolygon ); code = def->asScriptCode(); QCOMPARE( code, QStringLiteral( "##non_optional=vectorOut polygon" ) ); fromCode.reset( dynamic_cast< QgsProcessingParameterVectorOutput * >( QgsProcessingParameters::parameterFromScriptCode( code ) ) ); QCOMPARE( fromCode->dataType(), def->dataType() ); // optional - def.reset( new QgsProcessingParameterVectorOutput( "optional", QString(), QgsProcessingParameterDefinition::TypeVectorAny, QString(), true ) ); + def.reset( new QgsProcessingParameterVectorOutput( "optional", QString(), QgsProcessing::TypeVectorAny, QString(), true ) ); QVERIFY( !def->checkValueIsAcceptable( false ) ); QVERIFY( !def->checkValueIsAcceptable( true ) ); QVERIFY( !def->checkValueIsAcceptable( 5 ) ); @@ -3657,14 +3657,14 @@ void TestQgsProcessing::parameterVectorOut() QCOMPARE( fromCode->dataType(), def->dataType() ); // test hasGeometry - QVERIFY( QgsProcessingParameterVectorOutput( "test", QString(), QgsProcessingParameterDefinition::TypeAny ).hasGeometry() ); - QVERIFY( QgsProcessingParameterVectorOutput( "test", QString(), QgsProcessingParameterDefinition::TypeVectorAny ).hasGeometry() ); - QVERIFY( QgsProcessingParameterVectorOutput( "test", QString(), QgsProcessingParameterDefinition::TypeVectorPoint ).hasGeometry() ); - QVERIFY( QgsProcessingParameterVectorOutput( "test", QString(), QgsProcessingParameterDefinition::TypeVectorLine ).hasGeometry() ); - QVERIFY( QgsProcessingParameterVectorOutput( "test", QString(), QgsProcessingParameterDefinition::TypeVectorPolygon ).hasGeometry() ); - QVERIFY( !QgsProcessingParameterVectorOutput( "test", QString(), QgsProcessingParameterDefinition::TypeRaster ).hasGeometry() ); - QVERIFY( !QgsProcessingParameterVectorOutput( "test", QString(), QgsProcessingParameterDefinition::TypeFile ).hasGeometry() ); - QVERIFY( QgsProcessingParameterVectorOutput( "test", QString(), QgsProcessingParameterDefinition::TypeTable ).hasGeometry() ); + QVERIFY( QgsProcessingParameterVectorOutput( "test", QString(), QgsProcessing::TypeAny ).hasGeometry() ); + QVERIFY( QgsProcessingParameterVectorOutput( "test", QString(), QgsProcessing::TypeVectorAny ).hasGeometry() ); + QVERIFY( QgsProcessingParameterVectorOutput( "test", QString(), QgsProcessing::TypeVectorPoint ).hasGeometry() ); + QVERIFY( QgsProcessingParameterVectorOutput( "test", QString(), QgsProcessing::TypeVectorLine ).hasGeometry() ); + QVERIFY( QgsProcessingParameterVectorOutput( "test", QString(), QgsProcessing::TypeVectorPolygon ).hasGeometry() ); + QVERIFY( !QgsProcessingParameterVectorOutput( "test", QString(), QgsProcessing::TypeRaster ).hasGeometry() ); + QVERIFY( !QgsProcessingParameterVectorOutput( "test", QString(), QgsProcessing::TypeFile ).hasGeometry() ); + QVERIFY( QgsProcessingParameterVectorOutput( "test", QString(), QgsProcessing::TypeTable ).hasGeometry() ); } @@ -3754,7 +3754,7 @@ void TestQgsProcessing::parameterRasterOut() QgsProcessingOutputLayerDefinition fs = QgsProcessingOutputLayerDefinition( QStringLiteral( "test.tif" ) ); fs.destinationProject = &p; params.insert( QStringLiteral( "x" ), QVariant::fromValue( fs ) ); - QCOMPARE( QgsProcessingParameters::parameterAsRasterOutputLayer( def.get(), params, context ), QStringLiteral( "test.tif" ) ); + QCOMPARE( QgsProcessingParameters::parameterAsOutputLayer( def.get(), params, context ), QStringLiteral( "test.tif" ) ); // make sure layer was automatically added to list to load on completion QCOMPARE( context.layersToLoadOnCompletion().size(), 1 ); @@ -3767,7 +3767,7 @@ void TestQgsProcessing::parameterRasterOut() fs.destinationProject = &p; fs.destinationName = QStringLiteral( "my_dest" ); params.insert( QStringLiteral( "x" ), QVariant::fromValue( fs ) ); - QCOMPARE( QgsProcessingParameters::parameterAsRasterOutputLayer( def.get(), params, context2 ), QStringLiteral( "test.tif" ) ); + QCOMPARE( QgsProcessingParameters::parameterAsOutputLayer( def.get(), params, context2 ), QStringLiteral( "test.tif" ) ); QCOMPARE( context2.layersToLoadOnCompletion().size(), 1 ); QCOMPARE( context2.layersToLoadOnCompletion().keys().at( 0 ), QStringLiteral( "test.tif" ) ); QCOMPARE( context2.layersToLoadOnCompletion().values().at( 0 ).name, QStringLiteral( "my_dest" ) ); @@ -4075,7 +4075,7 @@ void TestQgsProcessing::processingFeatureSink() // non optional sink - def.reset( new QgsProcessingParameterFeatureSink( QStringLiteral( "layer" ), QString(), QgsProcessingParameterDefinition::TypeAny, QVariant(), false ) ); + def.reset( new QgsProcessingParameterFeatureSink( QStringLiteral( "layer" ), QString(), QgsProcessing::TypeAny, QVariant(), false ) ); QVERIFY( def->checkValueIsAcceptable( QStringLiteral( "memory:test" ) ) ); QVERIFY( def->checkValueIsAcceptable( QgsProcessingOutputLayerDefinition( "memory:test" ) ) ); QVERIFY( def->checkValueIsAcceptable( QgsProperty::fromValue( "memory:test" ) ) ); @@ -4087,7 +4087,7 @@ void TestQgsProcessing::processingFeatureSink() QVERIFY( sink.get() ); // optional sink - def.reset( new QgsProcessingParameterFeatureSink( QStringLiteral( "layer" ), QString(), QgsProcessingParameterDefinition::TypeAny, QVariant(), true ) ); + def.reset( new QgsProcessingParameterFeatureSink( QStringLiteral( "layer" ), QString(), QgsProcessing::TypeAny, QVariant(), true ) ); QVERIFY( def->checkValueIsAcceptable( QStringLiteral( "memory:test" ) ) ); QVERIFY( def->checkValueIsAcceptable( QgsProcessingOutputLayerDefinition( "memory:test" ) ) ); QVERIFY( def->checkValueIsAcceptable( QgsProperty::fromValue( "memory:test" ) ) ); @@ -4103,7 +4103,7 @@ void TestQgsProcessing::processingFeatureSink() QVERIFY( !sink.get() ); //.... unless there's a default set - def.reset( new QgsProcessingParameterFeatureSink( QStringLiteral( "layer" ), QString(), QgsProcessingParameterDefinition::TypeAny, QStringLiteral( "memory:defaultlayer" ), true ) ); + def.reset( new QgsProcessingParameterFeatureSink( QStringLiteral( "layer" ), QString(), QgsProcessing::TypeAny, QStringLiteral( "memory:defaultlayer" ), true ) ); params.insert( QStringLiteral( "layer" ), QVariant() ); sink.reset( QgsProcessingParameters::parameterAsSink( def.get(), params, QgsFields(), QgsWkbTypes::Point, QgsCoordinateReferenceSystem( "EPSG:3113" ), context, dest ) ); QVERIFY( sink.get() ); From 9d04f87249c06022989cbc689dc35a6c3acb054c Mon Sep 17 00:00:00 2001 From: Nyall Dawson Date: Sat, 8 Jul 2017 15:25:45 +1000 Subject: [PATCH 06/13] Rename "output" style parameters for clarity The previous naming was too easily confused with processing outputs. Rename them to QgsProcessingParameterFileDestination, etc... to make it clearer what they are used for. --- .../processing/qgsprocessingparameters.sip | 97 ++++++++-------- python/plugins/processing/algs/qgis/Aspect.py | 4 +- .../plugins/processing/algs/qgis/BarPlot.py | 4 +- .../processing/algs/qgis/BasicStatistics.py | 4 +- .../processing/algs/qgis/VectorSplit.py | 6 +- .../plugins/processing/gui/AlgorithmDialog.py | 6 +- .../processing/gui/BatchAlgorithmDialog.py | 4 +- .../gui/BatchOutputSelectionPanel.py | 4 +- .../gui/DestinationSelectionPanel.py | 8 +- .../processing/gui/ParameterGuiUtils.py | 4 +- .../plugins/processing/gui/ParametersPanel.py | 6 +- .../modeler/ModelerParametersDialog.py | 10 +- .../testdata/scripts/selectbyattribute.py | 2 +- .../testdata/scripts/selectbyexpression.py | 2 +- python/plugins/processing/tools/general.py | 6 +- .../processing/qgsprocessingparameters.cpp | 106 +++++++++--------- src/core/processing/qgsprocessingparameters.h | 105 +++++++++-------- tests/src/core/testqgsprocessing.cpp | 80 ++++++------- 18 files changed, 237 insertions(+), 221 deletions(-) diff --git a/python/core/processing/qgsprocessingparameters.sip b/python/core/processing/qgsprocessingparameters.sip index 6d7ba01a901..8a9d5d266f6 100644 --- a/python/core/processing/qgsprocessingparameters.sip +++ b/python/core/processing/qgsprocessingparameters.sip @@ -181,14 +181,14 @@ class QgsProcessingParameterDefinition sipType = sipType_QgsProcessingParameterFeatureSource; else if ( sipCpp->type() == QgsProcessingParameterFeatureSink::typeName() ) sipType = sipType_QgsProcessingParameterFeatureSink; - else if ( sipCpp->type() == QgsProcessingParameterVectorOutput::typeName() ) - sipType = sipType_QgsProcessingParameterVectorOutput; - else if ( sipCpp->type() == QgsProcessingParameterRasterOutput::typeName() ) - sipType = sipType_QgsProcessingParameterRasterOutput; - else if ( sipCpp->type() == QgsProcessingParameterFileOutput::typeName() ) - sipType = sipType_QgsProcessingParameterFileOutput; - else if ( sipCpp->type() == QgsProcessingParameterFolderOutput::typeName() ) - sipType = sipType_QgsProcessingParameterFolderOutput; + else if ( sipCpp->type() == QgsProcessingParameterVectorDestination::typeName() ) + sipType = sipType_QgsProcessingParameterVectorDestination; + else if ( sipCpp->type() == QgsProcessingParameterRasterDestination::typeName() ) + sipType = sipType_QgsProcessingParameterRasterDestination; + else if ( sipCpp->type() == QgsProcessingParameterFileDestination::typeName() ) + sipType = sipType_QgsProcessingParameterFileDestination; + else if ( sipCpp->type() == QgsProcessingParameterFolderDestination::typeName() ) + sipType = sipType_QgsProcessingParameterFolderDestination; %End public: @@ -1712,10 +1712,15 @@ class QgsProcessingParameterFeatureSink : QgsProcessingDestinationParameter }; -class QgsProcessingParameterVectorOutput : QgsProcessingDestinationParameter +class QgsProcessingParameterVectorDestination : QgsProcessingDestinationParameter { %Docstring - A vector layer output parameter. Consider using the more flexible QgsProcessingParameterFeatureSink wherever + A vector layer destination parameter, for specifying the destination path for a vector layer + created by the algorithm. + +.. note:: + + Consider using the more flexible QgsProcessingParameterFeatureSink wherever possible. .. versionadded:: 3.0 %End @@ -1725,10 +1730,10 @@ class QgsProcessingParameterVectorOutput : QgsProcessingDestinationParameter %End public: - QgsProcessingParameterVectorOutput( const QString &name, const QString &description = QString(), QgsProcessing::LayerType type = QgsProcessing::TypeVectorAny, const QVariant &defaultValue = QVariant(), - bool optional = false ); + QgsProcessingParameterVectorDestination( const QString &name, const QString &description = QString(), QgsProcessing::LayerType type = QgsProcessing::TypeVectorAny, const QVariant &defaultValue = QVariant(), + bool optional = false ); %Docstring - Constructor for QgsProcessingParameterVectorOutput. + Constructor for QgsProcessingParameterVectorDestination. %End static QString typeName(); @@ -1750,21 +1755,21 @@ class QgsProcessingParameterVectorOutput : QgsProcessingDestinationParameter QgsProcessing::LayerType dataType() const; %Docstring - Returns the layer type for layers associated with the parameter. + Returns the layer type for this created vector layer. .. seealso:: setDataType() :rtype: QgsProcessing.LayerType %End bool hasGeometry() const; %Docstring - Returns true if the layer is likely to include geometries. In cases were presence of geometry + Returns true if the created layer is likely to include geometries. In cases were presence of geometry cannot be reliably determined in advance, this method will default to returning true. :rtype: bool %End void setDataType( QgsProcessing::LayerType type ); %Docstring - Sets the layer ``type`` for the layers associated with the parameter. + Sets the layer ``type`` for the created vector layer. .. seealso:: dataType() %End @@ -1773,19 +1778,20 @@ class QgsProcessingParameterVectorOutput : QgsProcessingDestinationParameter virtual bool fromVariantMap( const QVariantMap &map ); - static QgsProcessingParameterVectorOutput *fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition ) /Factory/; + static QgsProcessingParameterVectorDestination *fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition ) /Factory/; %Docstring Creates a new parameter using the definition from a script code. - :rtype: QgsProcessingParameterVectorOutput + :rtype: QgsProcessingParameterVectorDestination %End }; -class QgsProcessingParameterRasterOutput : QgsProcessingDestinationParameter +class QgsProcessingParameterRasterDestination : QgsProcessingDestinationParameter { %Docstring - A raster layer output parameter. + A raster layer destination parameter, for specifying the destination path for a raster layer + created by the algorithm. .. versionadded:: 3.0 %End @@ -1794,11 +1800,11 @@ class QgsProcessingParameterRasterOutput : QgsProcessingDestinationParameter %End public: - QgsProcessingParameterRasterOutput( const QString &name, const QString &description = QString(), - const QVariant &defaultValue = QVariant(), - bool optional = false ); + QgsProcessingParameterRasterDestination( const QString &name, const QString &description = QString(), + const QVariant &defaultValue = QVariant(), + bool optional = false ); %Docstring - Constructor for QgsProcessingParameterRasterOutput. + Constructor for QgsProcessingParameterRasterDestination. %End static QString typeName(); @@ -1816,17 +1822,18 @@ class QgsProcessingParameterRasterOutput : QgsProcessingDestinationParameter virtual QString defaultFileExtension() const; - static QgsProcessingParameterRasterOutput *fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition ) /Factory/; + static QgsProcessingParameterRasterDestination *fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition ) /Factory/; %Docstring Creates a new parameter using the definition from a script code. - :rtype: QgsProcessingParameterRasterOutput + :rtype: QgsProcessingParameterRasterDestination %End }; -class QgsProcessingParameterFileOutput : QgsProcessingDestinationParameter +class QgsProcessingParameterFileDestination : QgsProcessingDestinationParameter { %Docstring - A generic file based output parameter. + A generic file based destination parameter, for specifying the destination path for a file (non-map layer) + created by the algorithm. .. versionadded:: 3.0 %End @@ -1835,12 +1842,12 @@ class QgsProcessingParameterFileOutput : QgsProcessingDestinationParameter %End public: - QgsProcessingParameterFileOutput( const QString &name, const QString &description = QString(), - const QString &fileFilter = QString(), - const QVariant &defaultValue = QVariant(), - bool optional = false ); + QgsProcessingParameterFileDestination( const QString &name, const QString &description = QString(), + const QString &fileFilter = QString(), + const QVariant &defaultValue = QVariant(), + bool optional = false ); %Docstring - Constructor for QgsProcessingParameterFileOutput. + Constructor for QgsProcessingParameterFileDestination. %End static QString typeName(); @@ -1860,14 +1867,14 @@ class QgsProcessingParameterFileOutput : QgsProcessingDestinationParameter QString fileFilter() const; %Docstring - Returns the file filter string for files compatible with this output. + Returns the file filter string for file destinations compatible with this parameter. .. seealso:: setFileFilter() :rtype: str %End void setFileFilter( const QString &filter ); %Docstring - Sets the file ``filter`` string for files compatible with this output. + Sets the file ``filter`` string for file destinations compatible with this parameter. .. seealso:: fileFilter() %End @@ -1876,18 +1883,20 @@ class QgsProcessingParameterFileOutput : QgsProcessingDestinationParameter virtual bool fromVariantMap( const QVariantMap &map ); - static QgsProcessingParameterFileOutput *fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition ) /Factory/; + static QgsProcessingParameterFileDestination *fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition ) /Factory/; %Docstring Creates a new parameter using the definition from a script code. - :rtype: QgsProcessingParameterFileOutput + :rtype: QgsProcessingParameterFileDestination %End }; -class QgsProcessingParameterFolderOutput : QgsProcessingDestinationParameter +class QgsProcessingParameterFolderDestination : QgsProcessingDestinationParameter { %Docstring + A folder destination parameter, for specifying the destination path for a folder created + by the algorithm or used for creating new files within the algorithm. A folder output parameter. .. versionadded:: 3.0 %End @@ -1897,11 +1906,11 @@ class QgsProcessingParameterFolderOutput : QgsProcessingDestinationParameter %End public: - QgsProcessingParameterFolderOutput( const QString &name, const QString &description = QString(), - const QVariant &defaultValue = QVariant(), - bool optional = false ); + QgsProcessingParameterFolderDestination( const QString &name, const QString &description = QString(), + const QVariant &defaultValue = QVariant(), + bool optional = false ); %Docstring - Constructor for QgsProcessingParameterFolderOutput. + Constructor for QgsProcessingParameterFolderDestination. %End static QString typeName(); @@ -1917,10 +1926,10 @@ class QgsProcessingParameterFolderOutput : QgsProcessingDestinationParameter virtual QString defaultFileExtension() const; - static QgsProcessingParameterFolderOutput *fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition ) /Factory/; + static QgsProcessingParameterFolderDestination *fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition ) /Factory/; %Docstring Creates a new parameter using the definition from a script code. - :rtype: QgsProcessingParameterFolderOutput + :rtype: QgsProcessingParameterFolderDestination %End }; diff --git a/python/plugins/processing/algs/qgis/Aspect.py b/python/plugins/processing/algs/qgis/Aspect.py index 9a4aee737e3..67cd9421232 100644 --- a/python/plugins/processing/algs/qgis/Aspect.py +++ b/python/plugins/processing/algs/qgis/Aspect.py @@ -32,7 +32,7 @@ from qgis.PyQt.QtGui import QIcon from qgis.analysis import QgsAspectFilter from qgis.core import (QgsProcessingParameterRasterLayer, QgsProcessingParameterNumber, - QgsProcessingParameterRasterOutput, + QgsProcessingParameterRasterDestination, QgsProcessingOutputRasterLayer, QgsFeatureSink) from processing.algs.qgis.QgisAlgorithm import QgisAlgorithm @@ -65,7 +65,7 @@ class Aspect(QgisAlgorithm): self.addParameter(QgsProcessingParameterNumber(self.Z_FACTOR, self.tr('Z factor'), QgsProcessingParameterNumber.Double, 1, False, 1, 999999.99)) - self.addParameter(QgsProcessingParameterRasterOutput(self.OUTPUT, self.tr('Aspect'))) + self.addParameter(QgsProcessingParameterRasterDestination(self.OUTPUT, self.tr('Aspect'))) self.addOutput(QgsProcessingOutputRasterLayer(self.OUTPUT, self.tr('Aspect'))) def name(self): diff --git a/python/plugins/processing/algs/qgis/BarPlot.py b/python/plugins/processing/algs/qgis/BarPlot.py index a1767dea718..b78db4626ed 100644 --- a/python/plugins/processing/algs/qgis/BarPlot.py +++ b/python/plugins/processing/algs/qgis/BarPlot.py @@ -34,7 +34,7 @@ from qgis.core import (QgsApplication, QgsProcessingUtils, QgsProcessingParameterFeatureSource, QgsProcessingParameterField, - QgsProcessingParameterFileOutput, + QgsProcessingParameterFileDestination, QgsProcessingOutputHtml) from processing.algs.qgis.QgisAlgorithm import QgisAlgorithm from processing.tools import vector @@ -62,7 +62,7 @@ class BarPlot(QgisAlgorithm): self.tr('Value field'), None, self.INPUT, QgsProcessingParameterField.Numeric)) - self.addParameter(QgsProcessingParameterFileOutput(self.OUTPUT, self.tr('Added'), self.tr('HTML files (*.html)'))) + self.addParameter(QgsProcessingParameterFileDestination(self.OUTPUT, self.tr('Added'), self.tr('HTML files (*.html)'))) self.addOutput(QgsProcessingOutputHtml(self.OUTPUT, self.tr('Bar plot'))) diff --git a/python/plugins/processing/algs/qgis/BasicStatistics.py b/python/plugins/processing/algs/qgis/BasicStatistics.py index 0c1ce80992c..9407322c98a 100644 --- a/python/plugins/processing/algs/qgis/BasicStatistics.py +++ b/python/plugins/processing/algs/qgis/BasicStatistics.py @@ -39,7 +39,7 @@ from qgis.core import (QgsStatisticalSummary, QgsProcessingUtils, QgsProcessingParameterFeatureSource, QgsProcessingParameterField, - QgsProcessingParameterFileOutput, + QgsProcessingParameterFileDestination, QgsProcessingOutputHtml, QgsProcessingOutputNumber) @@ -95,7 +95,7 @@ class BasicStatisticsForField(QgisAlgorithm): self.tr('Field to calculate statistics on'), None, self.INPUT_LAYER, QgsProcessingParameterField.Any)) - self.addParameter(QgsProcessingParameterFileOutput(self.OUTPUT_HTML_FILE, self.tr('Statistics'), self.tr('HTML files (*.html)'), None, True)) + self.addParameter(QgsProcessingParameterFileDestination(self.OUTPUT_HTML_FILE, self.tr('Statistics'), self.tr('HTML files (*.html)'), None, True)) self.addOutput(QgsProcessingOutputHtml(self.OUTPUT_HTML_FILE, self.tr('Statistics'))) self.addOutput(QgsProcessingOutputNumber(self.COUNT, self.tr('Count'))) diff --git a/python/plugins/processing/algs/qgis/VectorSplit.py b/python/plugins/processing/algs/qgis/VectorSplit.py index 6019e8c3752..c8bd9aa7044 100644 --- a/python/plugins/processing/algs/qgis/VectorSplit.py +++ b/python/plugins/processing/algs/qgis/VectorSplit.py @@ -32,7 +32,7 @@ from qgis.core import (QgsProcessingUtils, QgsFeatureSink, QgsProcessingParameterFeatureSource, QgsProcessingParameterField, - QgsProcessingParameterFolderOutput, + QgsProcessingParameterFolderDestination, QgsProcessingOutputFolder, QgsExpression, QgsFeatureRequest) @@ -61,8 +61,8 @@ class VectorSplit(QgisAlgorithm): self.addParameter(QgsProcessingParameterField(self.FIELD, self.tr('Unique ID field'), None, self.INPUT)) - self.addParameter(QgsProcessingParameterFolderOutput(self.OUTPUT, - self.tr('Output directory'))) + self.addParameter(QgsProcessingParameterFolderDestination(self.OUTPUT, + self.tr('Output directory'))) self.addOutput(QgsProcessingOutputFolder(self.OUTPUT, self.tr('Output directory'))) diff --git a/python/plugins/processing/gui/AlgorithmDialog.py b/python/plugins/processing/gui/AlgorithmDialog.py index 6593fb502fe..c8f758d22d6 100644 --- a/python/plugins/processing/gui/AlgorithmDialog.py +++ b/python/plugins/processing/gui/AlgorithmDialog.py @@ -42,10 +42,10 @@ from qgis.core import (QgsProject, QgsProcessingOutputVectorLayer, QgsProcessingAlgRunnerTask, QgsProcessingOutputHtml, - QgsProcessingParameterVectorOutput, + QgsProcessingParameterVectorDestination, QgsProcessingOutputLayerDefinition, QgsProcessingParameterFeatureSink, - QgsProcessingParameterRasterOutput, + QgsProcessingParameterRasterDestination, QgsProcessingAlgorithm) from qgis.gui import QgsMessageBar from qgis.utils import iface @@ -119,7 +119,7 @@ class AlgorithmDialog(AlgorithmDialogBase): else: dest_project = None if not param.flags() & QgsProcessingParameterDefinition.FlagHidden and \ - isinstance(param, (QgsProcessingParameterRasterOutput, QgsProcessingParameterFeatureSink, QgsProcessingParameterVectorOutput)): + isinstance(param, (QgsProcessingParameterRasterDestination, QgsProcessingParameterFeatureSink, QgsProcessingParameterVectorDestination)): if self.mainWidget.checkBoxes[param.name()].isChecked(): dest_project = QgsProject.instance() diff --git a/python/plugins/processing/gui/BatchAlgorithmDialog.py b/python/plugins/processing/gui/BatchAlgorithmDialog.py index 7c8c2b49965..a94ccaadacc 100644 --- a/python/plugins/processing/gui/BatchAlgorithmDialog.py +++ b/python/plugins/processing/gui/BatchAlgorithmDialog.py @@ -34,7 +34,7 @@ from qgis.PyQt.QtGui import QCursor from qgis.PyQt.QtCore import Qt from qgis.core import (QgsProcessingParameterDefinition, - QgsProcessingParameterRasterOutput, + QgsProcessingParameterRasterDestination, QgsProcessingParameterFeatureSink, QgsProcessingOutputLayerDefinition, QgsProcessingOutputHtml, @@ -104,7 +104,7 @@ class BatchAlgorithmDialog(AlgorithmDialogBase): widget = self.mainWidget.tblParameters.cellWidget(row, col) text = widget.getValue() if param.checkValueIsAcceptable(text, context): - if isinstance(out, (QgsProcessingParameterRasterOutput, + if isinstance(out, (QgsProcessingParameterRasterDestination, QgsProcessingParameterFeatureSink)): # load rasters and sinks on completion parameters[out.name()] = QgsProcessingOutputLayerDefinition(text, context.project()) diff --git a/python/plugins/processing/gui/BatchOutputSelectionPanel.py b/python/plugins/processing/gui/BatchOutputSelectionPanel.py index 588afcbeb8a..69162c59eb2 100644 --- a/python/plugins/processing/gui/BatchOutputSelectionPanel.py +++ b/python/plugins/processing/gui/BatchOutputSelectionPanel.py @@ -33,7 +33,7 @@ import re from qgis.core import (QgsMapLayer, QgsSettings, - QgsProcessingParameterFolderOutput, + QgsProcessingParameterFolderDestination, QgsProcessingParameterRasterLayer, QgsProcessingParameterFeatureSource, QgsProcessingParameterVectorLayer, @@ -73,7 +73,7 @@ class BatchOutputSelectionPanel(QWidget): self.setLayout(self.horizontalLayout) def showSelectionDialog(self): - if isinstance(self.output, QgsProcessingParameterFolderOutput): + if isinstance(self.output, QgsProcessingParameterFolderDestination): self.selectDirectory() return diff --git a/python/plugins/processing/gui/DestinationSelectionPanel.py b/python/plugins/processing/gui/DestinationSelectionPanel.py index 1808292d7d9..d8d3f3e654d 100644 --- a/python/plugins/processing/gui/DestinationSelectionPanel.py +++ b/python/plugins/processing/gui/DestinationSelectionPanel.py @@ -41,7 +41,7 @@ from qgis.core import (QgsDataSourceUri, QgsProcessingParameterFeatureSink, QgsProcessingOutputLayerDefinition, QgsProcessingParameterDefinition, - QgsProcessingParameterFolderOutput) + QgsProcessingParameterFolderDestination) from processing.core.ProcessingConfig import ProcessingConfig from processing.tools.dataobjects import createContext from processing.gui.PostgisTableSelector import PostgisTableSelector @@ -79,7 +79,7 @@ class DestinationSelectionPanel(BASE, WIDGET): and alg.provider().supportsNonFileBasedOutput(): # use memory layers for temporary files if supported self.leText.setPlaceholderText(self.SAVE_TO_TEMP_LAYER) - elif not isinstance(self.parameter, QgsProcessingParameterFolderOutput): + elif not isinstance(self.parameter, QgsProcessingParameterFolderDestination): self.leText.setPlaceholderText(self.SAVE_TO_TEMP_FILE) self.btnSelect.clicked.connect(self.selectOutput) @@ -94,7 +94,7 @@ class DestinationSelectionPanel(BASE, WIDGET): self.use_temporary = False def selectOutput(self): - if isinstance(self.parameter, QgsProcessingParameterFolderOutput): + if isinstance(self.parameter, QgsProcessingParameterFolderDestination): self.selectDirectory() else: popupMenu = QMenu() @@ -275,7 +275,7 @@ class DestinationSelectionPanel(BASE, WIDGET): if not key and self.parameter.flags() & QgsProcessingParameterDefinition.FlagOptional: return None - if isinstance(self.parameter, QgsProcessingParameterFolderOutput): + if isinstance(self.parameter, QgsProcessingParameterFolderDestination): return self.leText.text() value = QgsProcessingOutputLayerDefinition(key) diff --git a/python/plugins/processing/gui/ParameterGuiUtils.py b/python/plugins/processing/gui/ParameterGuiUtils.py index caf0d0ce1ad..3694daf8e8a 100644 --- a/python/plugins/processing/gui/ParameterGuiUtils.py +++ b/python/plugins/processing/gui/ParameterGuiUtils.py @@ -56,10 +56,10 @@ def getFileFilter(param): for i in range(len(exts)): exts[i] = tr('{0} files (*.{1})', 'QgsProcessingParameterMultipleLayers').format(exts[i].upper(), exts[i].lower()) return ';;'.join(exts) - elif param.type() in ('raster', 'rasterOut'): + elif param.type() in ('raster', 'rasterDestination'): exts = dataobjects.getSupportedOutputRasterLayerExtensions() for i in range(len(exts)): - exts[i] = tr('{0} files (*.{1})', 'QgsProcessingParameterRasterOutput').format(exts[i].upper(), exts[i].lower()) + exts[i] = tr('{0} files (*.{1})', 'QgsProcessingParameterRasterDestination').format(exts[i].upper(), exts[i].lower()) return ';;'.join(exts) elif param.type() == 'table': exts = ['csv', 'dbf'] diff --git a/python/plugins/processing/gui/ParametersPanel.py b/python/plugins/processing/gui/ParametersPanel.py index 1dc62a6a162..3eb8fcf9e35 100644 --- a/python/plugins/processing/gui/ParametersPanel.py +++ b/python/plugins/processing/gui/ParametersPanel.py @@ -37,9 +37,9 @@ from qgis.core import (QgsProcessingParameterDefinition, QgsProcessingParameterFeatureSource, QgsProcessingOutputVectorLayer, QgsProcessingOutputRasterLayer, - QgsProcessingParameterRasterOutput, + QgsProcessingParameterRasterDestination, QgsProcessingParameterFeatureSink, - QgsProcessingParameterVectorOutput) + QgsProcessingParameterVectorDestination) from qgis.PyQt import uic from qgis.PyQt.QtCore import QCoreApplication, Qt from qgis.PyQt.QtWidgets import (QWidget, QHBoxLayout, QToolButton, @@ -158,7 +158,7 @@ class ParametersPanel(BASE, WIDGET): widget = DestinationSelectionPanel(output, self.alg) self.layoutMain.insertWidget(self.layoutMain.count() - 1, label) self.layoutMain.insertWidget(self.layoutMain.count() - 1, widget) - if isinstance(output, (QgsProcessingParameterRasterOutput, QgsProcessingParameterFeatureSink, QgsProcessingParameterVectorOutput)): + if isinstance(output, (QgsProcessingParameterRasterDestination, QgsProcessingParameterFeatureSink, QgsProcessingParameterVectorDestination)): check = QCheckBox() check.setText(self.tr('Open output file after running algorithm')) check.setChecked(True) diff --git a/python/plugins/processing/modeler/ModelerParametersDialog.py b/python/plugins/processing/modeler/ModelerParametersDialog.py index 13cbb4f2afb..b131196af5f 100644 --- a/python/plugins/processing/modeler/ModelerParametersDialog.py +++ b/python/plugins/processing/modeler/ModelerParametersDialog.py @@ -38,9 +38,9 @@ from qgis.core import (QgsProcessingParameterDefinition, QgsProcessingParameterExtent, QgsProcessingModelAlgorithm, QgsProcessingParameterFeatureSink, - QgsProcessingParameterRasterOutput, - QgsProcessingParameterFileOutput, - QgsProcessingParameterFolderOutput, + QgsProcessingParameterRasterDestination, + QgsProcessingParameterFileDestination, + QgsProcessingParameterFolderDestination, QgsProcessingOutputDefinition) from qgis.gui import (QgsMessageBar, @@ -150,8 +150,8 @@ class ModelerParametersDialog(QDialog): for dest in self._alg.destinationParameterDefinitions(): if dest.flags() & QgsProcessingParameterDefinition.FlagHidden: continue - if isinstance(dest, (QgsProcessingParameterRasterOutput, QgsProcessingParameterFeatureSink, - QgsProcessingParameterFileOutput, QgsProcessingParameterFolderOutput)): + if isinstance(dest, (QgsProcessingParameterRasterDestination, QgsProcessingParameterFeatureSink, + QgsProcessingParameterFileDestination, QgsProcessingParameterFolderDestination)): label = QLabel(dest.description()) item = QLineEdit() if hasattr(item, 'setPlaceholderText'): diff --git a/python/plugins/processing/tests/testdata/scripts/selectbyattribute.py b/python/plugins/processing/tests/testdata/scripts/selectbyattribute.py index 28f0250a07c..7cbf5730978 100644 --- a/python/plugins/processing/tests/testdata/scripts/selectbyattribute.py +++ b/python/plugins/processing/tests/testdata/scripts/selectbyattribute.py @@ -4,7 +4,7 @@ #inputs ##INPUT_LAYER=vector -##OUTPUT_LAYER=vectorOut +##OUTPUT_LAYER=vectorDestination #outputs diff --git a/python/plugins/processing/tests/testdata/scripts/selectbyexpression.py b/python/plugins/processing/tests/testdata/scripts/selectbyexpression.py index 25e693b9242..55e43d3e1b8 100644 --- a/python/plugins/processing/tests/testdata/scripts/selectbyexpression.py +++ b/python/plugins/processing/tests/testdata/scripts/selectbyexpression.py @@ -4,7 +4,7 @@ #inputs ##INPUT_LAYER=vector -##OUTPUT_LAYER=vectorOut +##OUTPUT_LAYER=vectorDestination #outputs diff --git a/python/plugins/processing/tools/general.py b/python/plugins/processing/tools/general.py index 1ab0e29fad7..5675cec3078 100644 --- a/python/plugins/processing/tools/general.py +++ b/python/plugins/processing/tools/general.py @@ -38,8 +38,8 @@ except ImportError: from qgis.core import (QgsApplication, QgsProcessingAlgorithm, QgsProcessingParameterFeatureSink, - QgsProcessingParameterVectorOutput, - QgsProcessingParameterRasterOutput, + QgsProcessingParameterVectorDestination, + QgsProcessingParameterRasterDestination, QgsProcessingOutputLayerDefinition, QgsProject) from processing.core.Processing import Processing @@ -96,7 +96,7 @@ def runAndLoadResults(algOrName, parameters, feedback=None, context=None): if not param.name() in parameters: continue - if isinstance(param, (QgsProcessingParameterFeatureSink, QgsProcessingParameterVectorOutput, QgsProcessingParameterRasterOutput)): + if isinstance(param, (QgsProcessingParameterFeatureSink, QgsProcessingParameterVectorDestination, QgsProcessingParameterRasterDestination)): p = parameters[param.name()] if not isinstance(p, QgsProcessingOutputLayerDefinition): parameters[param.name()] = QgsProcessingOutputLayerDefinition(p, QgsProject.instance()) diff --git a/src/core/processing/qgsprocessingparameters.cpp b/src/core/processing/qgsprocessingparameters.cpp index 4805244dd03..198265aa3b6 100644 --- a/src/core/processing/qgsprocessingparameters.cpp +++ b/src/core/processing/qgsprocessingparameters.cpp @@ -827,14 +827,14 @@ QgsProcessingParameterDefinition *QgsProcessingParameters::parameterFromVariantM def.reset( new QgsProcessingParameterFeatureSource( name ) ); else if ( type == QgsProcessingParameterFeatureSink::typeName() ) def.reset( new QgsProcessingParameterFeatureSink( name ) ); - else if ( type == QgsProcessingParameterVectorOutput::typeName() ) - def.reset( new QgsProcessingParameterVectorOutput( name ) ); - else if ( type == QgsProcessingParameterRasterOutput::typeName() ) - def.reset( new QgsProcessingParameterRasterOutput( name ) ); - else if ( type == QgsProcessingParameterFileOutput::typeName() ) - def.reset( new QgsProcessingParameterFileOutput( name ) ); - else if ( type == QgsProcessingParameterFolderOutput::typeName() ) - def.reset( new QgsProcessingParameterFolderOutput( name ) ); + else if ( type == QgsProcessingParameterVectorDestination::typeName() ) + def.reset( new QgsProcessingParameterVectorDestination( name ) ); + else if ( type == QgsProcessingParameterRasterDestination::typeName() ) + def.reset( new QgsProcessingParameterRasterDestination( name ) ); + else if ( type == QgsProcessingParameterFileDestination::typeName() ) + def.reset( new QgsProcessingParameterFileDestination( name ) ); + else if ( type == QgsProcessingParameterFolderDestination::typeName() ) + def.reset( new QgsProcessingParameterFolderDestination( name ) ); if ( !def ) return nullptr; @@ -899,14 +899,14 @@ QgsProcessingParameterDefinition *QgsProcessingParameters::parameterFromScriptCo return QgsProcessingParameterFeatureSource::fromScriptCode( name, description, isOptional, definition ); else if ( type == QStringLiteral( "sink" ) ) return QgsProcessingParameterFeatureSink::fromScriptCode( name, description, isOptional, definition ); - else if ( type == QStringLiteral( "vectorout" ) ) - return QgsProcessingParameterVectorOutput::fromScriptCode( name, description, isOptional, definition ); - else if ( type == QStringLiteral( "rasterout" ) ) - return QgsProcessingParameterRasterOutput::fromScriptCode( name, description, isOptional, definition ); - else if ( type == QStringLiteral( "fileout" ) ) - return QgsProcessingParameterFileOutput::fromScriptCode( name, description, isOptional, definition ); - else if ( type == QStringLiteral( "folderout" ) ) - return QgsProcessingParameterFolderOutput::fromScriptCode( name, description, isOptional, definition ); + else if ( type == QStringLiteral( "vectordestination" ) ) + return QgsProcessingParameterVectorDestination::fromScriptCode( name, description, isOptional, definition ); + else if ( type == QStringLiteral( "rasterdestination" ) ) + return QgsProcessingParameterRasterDestination::fromScriptCode( name, description, isOptional, definition ); + else if ( type == QStringLiteral( "filedestination" ) ) + return QgsProcessingParameterFileDestination::fromScriptCode( name, description, isOptional, definition ); + else if ( type == QStringLiteral( "folderDestination" ) ) + return QgsProcessingParameterFolderDestination::fromScriptCode( name, description, isOptional, definition ); return nullptr; } @@ -2743,11 +2743,11 @@ QgsProcessingParameterFeatureSink *QgsProcessingParameterFeatureSink::fromScript return new QgsProcessingParameterFeatureSink( name, description, type, definition, isOptional ); } -QgsProcessingParameterRasterOutput::QgsProcessingParameterRasterOutput( const QString &name, const QString &description, const QVariant &defaultValue, bool optional ) +QgsProcessingParameterRasterDestination::QgsProcessingParameterRasterDestination( const QString &name, const QString &description, const QVariant &defaultValue, bool optional ) : QgsProcessingDestinationParameter( name, description, defaultValue, optional ) {} -bool QgsProcessingParameterRasterOutput::checkValueIsAcceptable( const QVariant &input, QgsProcessingContext * ) const +bool QgsProcessingParameterRasterDestination::checkValueIsAcceptable( const QVariant &input, QgsProcessingContext * ) const { QVariant var = input; if ( !var.isValid() ) @@ -2773,7 +2773,7 @@ bool QgsProcessingParameterRasterOutput::checkValueIsAcceptable( const QVariant return true; } -QString QgsProcessingParameterRasterOutput::valueAsPythonString( const QVariant &value, QgsProcessingContext & ) const +QString QgsProcessingParameterRasterDestination::valueAsPythonString( const QVariant &value, QgsProcessingContext & ) const { if ( value.canConvert() ) return QStringLiteral( "QgsProperty.fromExpression('%1')" ).arg( value.value< QgsProperty >().asExpression() ); @@ -2794,31 +2794,31 @@ QString QgsProcessingParameterRasterOutput::valueAsPythonString( const QVariant return value.toString().prepend( '\'' ).append( '\'' ); } -QgsProcessingOutputDefinition *QgsProcessingParameterRasterOutput::toOutputDefinition() const +QgsProcessingOutputDefinition *QgsProcessingParameterRasterDestination::toOutputDefinition() const { return new QgsProcessingOutputRasterLayer( name(), description() ); } -QString QgsProcessingParameterRasterOutput::defaultFileExtension() const +QString QgsProcessingParameterRasterDestination::defaultFileExtension() const { QgsSettings settings; return settings.value( QStringLiteral( "Processing/DefaultOutputRasterLayerExt" ), QStringLiteral( "tif" ), QgsSettings::Core ).toString(); } -QgsProcessingParameterRasterOutput *QgsProcessingParameterRasterOutput::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition ) +QgsProcessingParameterRasterDestination *QgsProcessingParameterRasterDestination::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition ) { - return new QgsProcessingParameterRasterOutput( name, description, definition.isEmpty() ? QVariant() : definition, isOptional ); + return new QgsProcessingParameterRasterDestination( name, description, definition.isEmpty() ? QVariant() : definition, isOptional ); } -QgsProcessingParameterFileOutput::QgsProcessingParameterFileOutput( const QString &name, const QString &description, const QString &fileFilter, const QVariant &defaultValue, bool optional ) +QgsProcessingParameterFileDestination::QgsProcessingParameterFileDestination( const QString &name, const QString &description, const QString &fileFilter, const QVariant &defaultValue, bool optional ) : QgsProcessingDestinationParameter( name, description, defaultValue, optional ) , mFileFilter( fileFilter.isEmpty() ? QObject::tr( "All files (*.*)" ) : fileFilter ) { } -bool QgsProcessingParameterFileOutput::checkValueIsAcceptable( const QVariant &input, QgsProcessingContext * ) const +bool QgsProcessingParameterFileDestination::checkValueIsAcceptable( const QVariant &input, QgsProcessingContext * ) const { QVariant var = input; if ( !var.isValid() ) @@ -2846,7 +2846,7 @@ bool QgsProcessingParameterFileOutput::checkValueIsAcceptable( const QVariant &i return true; } -QString QgsProcessingParameterFileOutput::valueAsPythonString( const QVariant &value, QgsProcessingContext & ) const +QString QgsProcessingParameterFileDestination::valueAsPythonString( const QVariant &value, QgsProcessingContext & ) const { if ( value.canConvert() ) return QStringLiteral( "QgsProperty.fromExpression('%1')" ).arg( value.value< QgsProperty >().asExpression() ); @@ -2867,12 +2867,12 @@ QString QgsProcessingParameterFileOutput::valueAsPythonString( const QVariant &v return value.toString().prepend( '\'' ).append( '\'' ); } -QgsProcessingOutputDefinition *QgsProcessingParameterFileOutput::toOutputDefinition() const +QgsProcessingOutputDefinition *QgsProcessingParameterFileDestination::toOutputDefinition() const { return nullptr; } -QString QgsProcessingParameterFileOutput::defaultFileExtension() const +QString QgsProcessingParameterFileDestination::defaultFileExtension() const { if ( mFileFilter.isEmpty() || mFileFilter == QObject::tr( "All files (*.*)" ) ) return QStringLiteral( "file" ); @@ -2886,24 +2886,24 @@ QString QgsProcessingParameterFileOutput::defaultFileExtension() const return match.captured( 1 ); } -QString QgsProcessingParameterFileOutput::fileFilter() const +QString QgsProcessingParameterFileDestination::fileFilter() const { return mFileFilter; } -void QgsProcessingParameterFileOutput::setFileFilter( const QString &fileFilter ) +void QgsProcessingParameterFileDestination::setFileFilter( const QString &fileFilter ) { mFileFilter = fileFilter; } -QVariantMap QgsProcessingParameterFileOutput::toVariantMap() const +QVariantMap QgsProcessingParameterFileDestination::toVariantMap() const { QVariantMap map = QgsProcessingDestinationParameter::toVariantMap(); map.insert( QStringLiteral( "file_filter" ), mFileFilter ); return map; } -bool QgsProcessingParameterFileOutput::fromVariantMap( const QVariantMap &map ) +bool QgsProcessingParameterFileDestination::fromVariantMap( const QVariantMap &map ) { QgsProcessingDestinationParameter::fromVariantMap( map ); mFileFilter = map.value( QStringLiteral( "file_filter" ) ).toString(); @@ -2911,16 +2911,16 @@ bool QgsProcessingParameterFileOutput::fromVariantMap( const QVariantMap &map ) } -QgsProcessingParameterFileOutput *QgsProcessingParameterFileOutput::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition ) +QgsProcessingParameterFileDestination *QgsProcessingParameterFileDestination::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition ) { - return new QgsProcessingParameterFileOutput( name, description, QString(), definition.isEmpty() ? QVariant() : definition, isOptional ); + return new QgsProcessingParameterFileDestination( name, description, QString(), definition.isEmpty() ? QVariant() : definition, isOptional ); } -QgsProcessingParameterFolderOutput::QgsProcessingParameterFolderOutput( const QString &name, const QString &description, const QVariant &defaultValue, bool optional ) +QgsProcessingParameterFolderDestination::QgsProcessingParameterFolderDestination( const QString &name, const QString &description, const QVariant &defaultValue, bool optional ) : QgsProcessingDestinationParameter( name, description, defaultValue, optional ) {} -bool QgsProcessingParameterFolderOutput::checkValueIsAcceptable( const QVariant &input, QgsProcessingContext * ) const +bool QgsProcessingParameterFolderDestination::checkValueIsAcceptable( const QVariant &input, QgsProcessingContext * ) const { QVariant var = input; if ( !var.isValid() ) @@ -2940,19 +2940,19 @@ bool QgsProcessingParameterFolderOutput::checkValueIsAcceptable( const QVariant return true; } -QgsProcessingOutputDefinition *QgsProcessingParameterFolderOutput::toOutputDefinition() const +QgsProcessingOutputDefinition *QgsProcessingParameterFolderDestination::toOutputDefinition() const { return new QgsProcessingOutputFolder( name(), description() ); } -QString QgsProcessingParameterFolderOutput::defaultFileExtension() const +QString QgsProcessingParameterFolderDestination::defaultFileExtension() const { return QString(); } -QgsProcessingParameterFolderOutput *QgsProcessingParameterFolderOutput::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition ) +QgsProcessingParameterFolderDestination *QgsProcessingParameterFolderDestination::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition ) { - return new QgsProcessingParameterFolderOutput( name, description, definition.isEmpty() ? QVariant() : definition, isOptional ); + return new QgsProcessingParameterFolderDestination( name, description, definition.isEmpty() ? QVariant() : definition, isOptional ); } QgsProcessingDestinationParameter::QgsProcessingDestinationParameter( const QString &name, const QString &description, const QVariant &defaultValue, bool optional ) @@ -2980,14 +2980,14 @@ QString QgsProcessingDestinationParameter::generateTemporaryDestination() const return QgsProcessingUtils::generateTempFilename( name() + '.' + defaultFileExtension() ); } -QgsProcessingParameterVectorOutput::QgsProcessingParameterVectorOutput( const QString &name, const QString &description, QgsProcessing::LayerType type, const QVariant &defaultValue, bool optional ) +QgsProcessingParameterVectorDestination::QgsProcessingParameterVectorDestination( const QString &name, const QString &description, QgsProcessing::LayerType type, const QVariant &defaultValue, bool optional ) : QgsProcessingDestinationParameter( name, description, defaultValue, optional ) , mDataType( type ) { } -bool QgsProcessingParameterVectorOutput::checkValueIsAcceptable( const QVariant &input, QgsProcessingContext * ) const +bool QgsProcessingParameterVectorDestination::checkValueIsAcceptable( const QVariant &input, QgsProcessingContext * ) const { QVariant var = input; if ( !var.isValid() ) @@ -3013,7 +3013,7 @@ bool QgsProcessingParameterVectorOutput::checkValueIsAcceptable( const QVariant return true; } -QString QgsProcessingParameterVectorOutput::valueAsPythonString( const QVariant &value, QgsProcessingContext & ) const +QString QgsProcessingParameterVectorDestination::valueAsPythonString( const QVariant &value, QgsProcessingContext & ) const { if ( value.canConvert() ) return QStringLiteral( "QgsProperty.fromExpression('%1')" ).arg( value.value< QgsProperty >().asExpression() ); @@ -3034,7 +3034,7 @@ QString QgsProcessingParameterVectorOutput::valueAsPythonString( const QVariant return value.toString().prepend( '\'' ).append( '\'' ); } -QString QgsProcessingParameterVectorOutput::asScriptCode() const +QString QgsProcessingParameterVectorDestination::asScriptCode() const { QString code = QStringLiteral( "##%1=" ).arg( mName ); if ( mFlags & FlagOptional ) @@ -3063,12 +3063,12 @@ QString QgsProcessingParameterVectorOutput::asScriptCode() const return code.trimmed(); } -QgsProcessingOutputDefinition *QgsProcessingParameterVectorOutput::toOutputDefinition() const +QgsProcessingOutputDefinition *QgsProcessingParameterVectorDestination::toOutputDefinition() const { return new QgsProcessingOutputVectorLayer( name(), description(), mDataType ); } -QString QgsProcessingParameterVectorOutput::defaultFileExtension() const +QString QgsProcessingParameterVectorDestination::defaultFileExtension() const { QgsSettings settings; if ( hasGeometry() ) @@ -3081,12 +3081,12 @@ QString QgsProcessingParameterVectorOutput::defaultFileExtension() const } } -QgsProcessing::LayerType QgsProcessingParameterVectorOutput::dataType() const +QgsProcessing::LayerType QgsProcessingParameterVectorDestination::dataType() const { return mDataType; } -bool QgsProcessingParameterVectorOutput::hasGeometry() const +bool QgsProcessingParameterVectorDestination::hasGeometry() const { switch ( mDataType ) { @@ -3105,26 +3105,26 @@ bool QgsProcessingParameterVectorOutput::hasGeometry() const return true; } -void QgsProcessingParameterVectorOutput::setDataType( QgsProcessing::LayerType type ) +void QgsProcessingParameterVectorDestination::setDataType( QgsProcessing::LayerType type ) { mDataType = type; } -QVariantMap QgsProcessingParameterVectorOutput::toVariantMap() const +QVariantMap QgsProcessingParameterVectorDestination::toVariantMap() const { QVariantMap map = QgsProcessingDestinationParameter::toVariantMap(); map.insert( QStringLiteral( "data_type" ), mDataType ); return map; } -bool QgsProcessingParameterVectorOutput::fromVariantMap( const QVariantMap &map ) +bool QgsProcessingParameterVectorDestination::fromVariantMap( const QVariantMap &map ) { QgsProcessingDestinationParameter::fromVariantMap( map ); mDataType = static_cast< QgsProcessing::LayerType >( map.value( QStringLiteral( "data_type" ) ).toInt() ); return true; } -QgsProcessingParameterVectorOutput *QgsProcessingParameterVectorOutput::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition ) +QgsProcessingParameterVectorDestination *QgsProcessingParameterVectorDestination::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition ) { QgsProcessing::LayerType type = QgsProcessing::TypeVectorAny; QString def = definition; @@ -3144,5 +3144,5 @@ QgsProcessingParameterVectorOutput *QgsProcessingParameterVectorOutput::fromScri def = def.mid( 8 ); } - return new QgsProcessingParameterVectorOutput( name, description, type, definition, isOptional ); + return new QgsProcessingParameterVectorDestination( name, description, type, definition, isOptional ); } diff --git a/src/core/processing/qgsprocessingparameters.h b/src/core/processing/qgsprocessingparameters.h index 00ae0f2dc6e..6421b1dc783 100644 --- a/src/core/processing/qgsprocessingparameters.h +++ b/src/core/processing/qgsprocessingparameters.h @@ -223,14 +223,14 @@ class CORE_EXPORT QgsProcessingParameterDefinition sipType = sipType_QgsProcessingParameterFeatureSource; else if ( sipCpp->type() == QgsProcessingParameterFeatureSink::typeName() ) sipType = sipType_QgsProcessingParameterFeatureSink; - else if ( sipCpp->type() == QgsProcessingParameterVectorOutput::typeName() ) - sipType = sipType_QgsProcessingParameterVectorOutput; - else if ( sipCpp->type() == QgsProcessingParameterRasterOutput::typeName() ) - sipType = sipType_QgsProcessingParameterRasterOutput; - else if ( sipCpp->type() == QgsProcessingParameterFileOutput::typeName() ) - sipType = sipType_QgsProcessingParameterFileOutput; - else if ( sipCpp->type() == QgsProcessingParameterFolderOutput::typeName() ) - sipType = sipType_QgsProcessingParameterFolderOutput; + else if ( sipCpp->type() == QgsProcessingParameterVectorDestination::typeName() ) + sipType = sipType_QgsProcessingParameterVectorDestination; + else if ( sipCpp->type() == QgsProcessingParameterRasterDestination::typeName() ) + sipType = sipType_QgsProcessingParameterRasterDestination; + else if ( sipCpp->type() == QgsProcessingParameterFileDestination::typeName() ) + sipType = sipType_QgsProcessingParameterFileDestination; + else if ( sipCpp->type() == QgsProcessingParameterFolderDestination::typeName() ) + sipType = sipType_QgsProcessingParameterFolderDestination; SIP_END #endif @@ -1625,26 +1625,29 @@ class CORE_EXPORT QgsProcessingParameterFeatureSink : public QgsProcessingDestin /** - * \class QgsProcessingParameterVectorOutput + * \class QgsProcessingParameterVectorDestination * \ingroup core - * A vector layer output parameter. Consider using the more flexible QgsProcessingParameterFeatureSink wherever + * A vector layer destination parameter, for specifying the destination path for a vector layer + * created by the algorithm. + * + * \note Consider using the more flexible QgsProcessingParameterFeatureSink wherever * possible. * \since QGIS 3.0 */ -class CORE_EXPORT QgsProcessingParameterVectorOutput : public QgsProcessingDestinationParameter +class CORE_EXPORT QgsProcessingParameterVectorDestination : public QgsProcessingDestinationParameter { public: /** - * Constructor for QgsProcessingParameterVectorOutput. + * Constructor for QgsProcessingParameterVectorDestination. */ - QgsProcessingParameterVectorOutput( const QString &name, const QString &description = QString(), QgsProcessing::LayerType type = QgsProcessing::TypeVectorAny, const QVariant &defaultValue = QVariant(), - bool optional = false ); + QgsProcessingParameterVectorDestination( const QString &name, const QString &description = QString(), QgsProcessing::LayerType type = QgsProcessing::TypeVectorAny, const QVariant &defaultValue = QVariant(), + bool optional = false ); /** * Returns the type name for the parameter class. */ - static QString typeName() { return QStringLiteral( "vectorOut" ); } + static QString typeName() { return QStringLiteral( "vectorDestination" ); } QString type() const override { return typeName(); } bool checkValueIsAcceptable( const QVariant &input, QgsProcessingContext *context = nullptr ) const override; QString valueAsPythonString( const QVariant &value, QgsProcessingContext &context ) const override; @@ -1653,19 +1656,19 @@ class CORE_EXPORT QgsProcessingParameterVectorOutput : public QgsProcessingDesti QString defaultFileExtension() const override; /** - * Returns the layer type for layers associated with the parameter. + * Returns the layer type for this created vector layer. * \see setDataType() */ QgsProcessing::LayerType dataType() const; /** - * Returns true if the layer is likely to include geometries. In cases were presence of geometry + * Returns true if the created layer is likely to include geometries. In cases were presence of geometry * cannot be reliably determined in advance, this method will default to returning true. */ bool hasGeometry() const; /** - * Sets the layer \a type for the layers associated with the parameter. + * Sets the layer \a type for the created vector layer. * \see dataType() */ void setDataType( QgsProcessing::LayerType type ); @@ -1676,7 +1679,7 @@ class CORE_EXPORT QgsProcessingParameterVectorOutput : public QgsProcessingDesti /** * Creates a new parameter using the definition from a script code. */ - static QgsProcessingParameterVectorOutput *fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition ) SIP_FACTORY; + static QgsProcessingParameterVectorDestination *fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition ) SIP_FACTORY; private: @@ -1685,26 +1688,27 @@ class CORE_EXPORT QgsProcessingParameterVectorOutput : public QgsProcessingDesti }; /** - * \class QgsProcessingParameterRasterOutput + * \class QgsProcessingParameterRasterDestination * \ingroup core - * A raster layer output parameter. + * A raster layer destination parameter, for specifying the destination path for a raster layer + * created by the algorithm. * \since QGIS 3.0 */ -class CORE_EXPORT QgsProcessingParameterRasterOutput : public QgsProcessingDestinationParameter +class CORE_EXPORT QgsProcessingParameterRasterDestination : public QgsProcessingDestinationParameter { public: /** - * Constructor for QgsProcessingParameterRasterOutput. + * Constructor for QgsProcessingParameterRasterDestination. */ - QgsProcessingParameterRasterOutput( const QString &name, const QString &description = QString(), - const QVariant &defaultValue = QVariant(), - bool optional = false ); + QgsProcessingParameterRasterDestination( const QString &name, const QString &description = QString(), + const QVariant &defaultValue = QVariant(), + bool optional = false ); /** * Returns the type name for the parameter class. */ - static QString typeName() { return QStringLiteral( "rasterOut" ); } + static QString typeName() { return QStringLiteral( "rasterDestination" ); } QString type() const override { return typeName(); } bool checkValueIsAcceptable( const QVariant &input, QgsProcessingContext *context = nullptr ) const override; QString valueAsPythonString( const QVariant &value, QgsProcessingContext &context ) const override; @@ -1714,31 +1718,32 @@ class CORE_EXPORT QgsProcessingParameterRasterOutput : public QgsProcessingDesti /** * Creates a new parameter using the definition from a script code. */ - static QgsProcessingParameterRasterOutput *fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition ) SIP_FACTORY; + static QgsProcessingParameterRasterDestination *fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition ) SIP_FACTORY; }; /** - * \class QgsProcessingParameterFileOutput + * \class QgsProcessingParameterFileDestination * \ingroup core - * A generic file based output parameter. + * A generic file based destination parameter, for specifying the destination path for a file (non-map layer) + * created by the algorithm. * \since QGIS 3.0 */ -class CORE_EXPORT QgsProcessingParameterFileOutput : public QgsProcessingDestinationParameter +class CORE_EXPORT QgsProcessingParameterFileDestination : public QgsProcessingDestinationParameter { public: /** - * Constructor for QgsProcessingParameterFileOutput. + * Constructor for QgsProcessingParameterFileDestination. */ - QgsProcessingParameterFileOutput( const QString &name, const QString &description = QString(), - const QString &fileFilter = QString(), - const QVariant &defaultValue = QVariant(), - bool optional = false ); + QgsProcessingParameterFileDestination( const QString &name, const QString &description = QString(), + const QString &fileFilter = QString(), + const QVariant &defaultValue = QVariant(), + bool optional = false ); /** * Returns the type name for the parameter class. */ - static QString typeName() { return QStringLiteral( "fileOut" ); } + static QString typeName() { return QStringLiteral( "fileDestination" ); } QString type() const override { return typeName(); } bool checkValueIsAcceptable( const QVariant &input, QgsProcessingContext *context = nullptr ) const override; QString valueAsPythonString( const QVariant &value, QgsProcessingContext &context ) const override; @@ -1746,13 +1751,13 @@ class CORE_EXPORT QgsProcessingParameterFileOutput : public QgsProcessingDestina QString defaultFileExtension() const override; /** - * Returns the file filter string for files compatible with this output. + * Returns the file filter string for file destinations compatible with this parameter. * \see setFileFilter() */ QString fileFilter() const; /** - * Sets the file \a filter string for files compatible with this output. + * Sets the file \a filter string for file destinations compatible with this parameter. * \see fileFilter() */ void setFileFilter( const QString &filter ); @@ -1763,7 +1768,7 @@ class CORE_EXPORT QgsProcessingParameterFileOutput : public QgsProcessingDestina /** * Creates a new parameter using the definition from a script code. */ - static QgsProcessingParameterFileOutput *fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition ) SIP_FACTORY; + static QgsProcessingParameterFileDestination *fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition ) SIP_FACTORY; private: @@ -1772,26 +1777,28 @@ class CORE_EXPORT QgsProcessingParameterFileOutput : public QgsProcessingDestina }; /** - * \class QgsProcessingParameterFolderOutput + * \class QgsProcessingParameterFolderDestination * \ingroup core + * A folder destination parameter, for specifying the destination path for a folder created + * by the algorithm or used for creating new files within the algorithm. * A folder output parameter. - * \since QGIS 3.0 + * \since QGIS 3.0 */ -class CORE_EXPORT QgsProcessingParameterFolderOutput : public QgsProcessingDestinationParameter +class CORE_EXPORT QgsProcessingParameterFolderDestination : public QgsProcessingDestinationParameter { public: /** - * Constructor for QgsProcessingParameterFolderOutput. + * Constructor for QgsProcessingParameterFolderDestination. */ - QgsProcessingParameterFolderOutput( const QString &name, const QString &description = QString(), - const QVariant &defaultValue = QVariant(), - bool optional = false ); + QgsProcessingParameterFolderDestination( const QString &name, const QString &description = QString(), + const QVariant &defaultValue = QVariant(), + bool optional = false ); /** * Returns the type name for the parameter class. */ - static QString typeName() { return QStringLiteral( "folderOut" ); } + static QString typeName() { return QStringLiteral( "folderDestination" ); } QString type() const override { return typeName(); } bool checkValueIsAcceptable( const QVariant &input, QgsProcessingContext *context = nullptr ) const override; QgsProcessingOutputDefinition *toOutputDefinition() const override SIP_FACTORY; @@ -1800,7 +1807,7 @@ class CORE_EXPORT QgsProcessingParameterFolderOutput : public QgsProcessingDesti /** * Creates a new parameter using the definition from a script code. */ - static QgsProcessingParameterFolderOutput *fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition ) SIP_FACTORY; + static QgsProcessingParameterFolderDestination *fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition ) SIP_FACTORY; }; diff --git a/tests/src/core/testqgsprocessing.cpp b/tests/src/core/testqgsprocessing.cpp index 2779550165d..f43b67c1b8f 100644 --- a/tests/src/core/testqgsprocessing.cpp +++ b/tests/src/core/testqgsprocessing.cpp @@ -3576,7 +3576,7 @@ void TestQgsProcessing::parameterVectorOut() context.setProject( &p ); // not optional! - std::unique_ptr< QgsProcessingParameterVectorOutput > def( new QgsProcessingParameterVectorOutput( "non_optional", QString(), QgsProcessing::TypeVectorAny, QString(), false ) ); + std::unique_ptr< QgsProcessingParameterVectorDestination > def( new QgsProcessingParameterVectorDestination( "non_optional", QString(), QgsProcessing::TypeVectorAny, QString(), false ) ); QVERIFY( !def->checkValueIsAcceptable( false ) ); QVERIFY( !def->checkValueIsAcceptable( true ) ); QVERIFY( !def->checkValueIsAcceptable( 5 ) ); @@ -3600,19 +3600,19 @@ void TestQgsProcessing::parameterVectorOut() QVERIFY( def->generateTemporaryDestination().startsWith( QgsProcessingUtils::tempFolder() ) ); QVariantMap map = def->toVariantMap(); - QgsProcessingParameterVectorOutput fromMap( "x" ); + QgsProcessingParameterVectorDestination fromMap( "x" ); QVERIFY( fromMap.fromVariantMap( map ) ); QCOMPARE( fromMap.name(), def->name() ); QCOMPARE( fromMap.description(), def->description() ); QCOMPARE( fromMap.flags(), def->flags() ); QCOMPARE( fromMap.defaultValue(), def->defaultValue() ); QCOMPARE( fromMap.dataType(), def->dataType() ); - def.reset( dynamic_cast< QgsProcessingParameterVectorOutput *>( QgsProcessingParameters::parameterFromVariantMap( map ) ) ); - QVERIFY( dynamic_cast< QgsProcessingParameterVectorOutput *>( def.get() ) ); + def.reset( dynamic_cast< QgsProcessingParameterVectorDestination *>( QgsProcessingParameters::parameterFromVariantMap( map ) ) ); + QVERIFY( dynamic_cast< QgsProcessingParameterVectorDestination *>( def.get() ) ); QString code = def->asScriptCode(); QCOMPARE( code, QStringLiteral( "##non_optional=vectorOut" ) ); - std::unique_ptr< QgsProcessingParameterVectorOutput > fromCode( dynamic_cast< QgsProcessingParameterVectorOutput * >( QgsProcessingParameters::parameterFromScriptCode( code ) ) ); + std::unique_ptr< QgsProcessingParameterVectorDestination > fromCode( dynamic_cast< QgsProcessingParameterVectorDestination * >( QgsProcessingParameters::parameterFromScriptCode( code ) ) ); QVERIFY( fromCode.get() ); QCOMPARE( fromCode->name(), def->name() ); QCOMPARE( fromCode->description(), QStringLiteral( "non optional" ) ); @@ -3623,21 +3623,21 @@ void TestQgsProcessing::parameterVectorOut() def->setDataType( QgsProcessing::TypeVectorPoint ); code = def->asScriptCode(); QCOMPARE( code, QStringLiteral( "##non_optional=vectorOut point" ) ); - fromCode.reset( dynamic_cast< QgsProcessingParameterVectorOutput * >( QgsProcessingParameters::parameterFromScriptCode( code ) ) ); + fromCode.reset( dynamic_cast< QgsProcessingParameterVectorDestination * >( QgsProcessingParameters::parameterFromScriptCode( code ) ) ); QCOMPARE( fromCode->dataType(), def->dataType() ); def->setDataType( QgsProcessing::TypeVectorLine ); code = def->asScriptCode(); QCOMPARE( code, QStringLiteral( "##non_optional=vectorOut line" ) ); - fromCode.reset( dynamic_cast< QgsProcessingParameterVectorOutput * >( QgsProcessingParameters::parameterFromScriptCode( code ) ) ); + fromCode.reset( dynamic_cast< QgsProcessingParameterVectorDestination * >( QgsProcessingParameters::parameterFromScriptCode( code ) ) ); QCOMPARE( fromCode->dataType(), def->dataType() ); def->setDataType( QgsProcessing::TypeVectorPolygon ); code = def->asScriptCode(); QCOMPARE( code, QStringLiteral( "##non_optional=vectorOut polygon" ) ); - fromCode.reset( dynamic_cast< QgsProcessingParameterVectorOutput * >( QgsProcessingParameters::parameterFromScriptCode( code ) ) ); + fromCode.reset( dynamic_cast< QgsProcessingParameterVectorDestination * >( QgsProcessingParameters::parameterFromScriptCode( code ) ) ); QCOMPARE( fromCode->dataType(), def->dataType() ); // optional - def.reset( new QgsProcessingParameterVectorOutput( "optional", QString(), QgsProcessing::TypeVectorAny, QString(), true ) ); + def.reset( new QgsProcessingParameterVectorDestination( "optional", QString(), QgsProcessing::TypeVectorAny, QString(), true ) ); QVERIFY( !def->checkValueIsAcceptable( false ) ); QVERIFY( !def->checkValueIsAcceptable( true ) ); QVERIFY( !def->checkValueIsAcceptable( 5 ) ); @@ -3649,7 +3649,7 @@ void TestQgsProcessing::parameterVectorOut() code = def->asScriptCode(); QCOMPARE( code, QStringLiteral( "##optional=optional vectorOut" ) ); - fromCode.reset( dynamic_cast< QgsProcessingParameterVectorOutput * >( QgsProcessingParameters::parameterFromScriptCode( code ) ) ); + fromCode.reset( dynamic_cast< QgsProcessingParameterVectorDestination * >( QgsProcessingParameters::parameterFromScriptCode( code ) ) ); QCOMPARE( fromCode->name(), def->name() ); QCOMPARE( fromCode->description(), QStringLiteral( "optional" ) ); QCOMPARE( fromCode->flags(), def->flags() ); @@ -3657,14 +3657,14 @@ void TestQgsProcessing::parameterVectorOut() QCOMPARE( fromCode->dataType(), def->dataType() ); // test hasGeometry - QVERIFY( QgsProcessingParameterVectorOutput( "test", QString(), QgsProcessing::TypeAny ).hasGeometry() ); - QVERIFY( QgsProcessingParameterVectorOutput( "test", QString(), QgsProcessing::TypeVectorAny ).hasGeometry() ); - QVERIFY( QgsProcessingParameterVectorOutput( "test", QString(), QgsProcessing::TypeVectorPoint ).hasGeometry() ); - QVERIFY( QgsProcessingParameterVectorOutput( "test", QString(), QgsProcessing::TypeVectorLine ).hasGeometry() ); - QVERIFY( QgsProcessingParameterVectorOutput( "test", QString(), QgsProcessing::TypeVectorPolygon ).hasGeometry() ); - QVERIFY( !QgsProcessingParameterVectorOutput( "test", QString(), QgsProcessing::TypeRaster ).hasGeometry() ); - QVERIFY( !QgsProcessingParameterVectorOutput( "test", QString(), QgsProcessing::TypeFile ).hasGeometry() ); - QVERIFY( QgsProcessingParameterVectorOutput( "test", QString(), QgsProcessing::TypeTable ).hasGeometry() ); + QVERIFY( QgsProcessingParameterVectorDestination( "test", QString(), QgsProcessing::TypeAny ).hasGeometry() ); + QVERIFY( QgsProcessingParameterVectorDestination( "test", QString(), QgsProcessing::TypeVectorAny ).hasGeometry() ); + QVERIFY( QgsProcessingParameterVectorDestination( "test", QString(), QgsProcessing::TypeVectorPoint ).hasGeometry() ); + QVERIFY( QgsProcessingParameterVectorDestination( "test", QString(), QgsProcessing::TypeVectorLine ).hasGeometry() ); + QVERIFY( QgsProcessingParameterVectorDestination( "test", QString(), QgsProcessing::TypeVectorPolygon ).hasGeometry() ); + QVERIFY( !QgsProcessingParameterVectorDestination( "test", QString(), QgsProcessing::TypeRaster ).hasGeometry() ); + QVERIFY( !QgsProcessingParameterVectorDestination( "test", QString(), QgsProcessing::TypeFile ).hasGeometry() ); + QVERIFY( QgsProcessingParameterVectorDestination( "test", QString(), QgsProcessing::TypeTable ).hasGeometry() ); } @@ -3677,7 +3677,7 @@ void TestQgsProcessing::parameterRasterOut() context.setProject( &p ); // not optional! - std::unique_ptr< QgsProcessingParameterRasterOutput > def( new QgsProcessingParameterRasterOutput( "non_optional", QString(), QVariant(), false ) ); + std::unique_ptr< QgsProcessingParameterRasterDestination > def( new QgsProcessingParameterRasterDestination( "non_optional", QString(), QVariant(), false ) ); QVERIFY( !def->checkValueIsAcceptable( false ) ); QVERIFY( !def->checkValueIsAcceptable( true ) ); QVERIFY( !def->checkValueIsAcceptable( 5 ) ); @@ -3707,19 +3707,19 @@ void TestQgsProcessing::parameterRasterOut() QCOMPARE( def->valueAsPythonString( QVariant::fromValue( QgsProperty::fromExpression( "\"a\"=1" ) ), context ), QStringLiteral( "QgsProperty.fromExpression('\"a\"=1')" ) ); QVariantMap map = def->toVariantMap(); - QgsProcessingParameterRasterOutput fromMap( "x" ); + QgsProcessingParameterRasterDestination fromMap( "x" ); QVERIFY( fromMap.fromVariantMap( map ) ); QCOMPARE( fromMap.name(), def->name() ); QCOMPARE( fromMap.description(), def->description() ); QCOMPARE( fromMap.flags(), def->flags() ); QCOMPARE( fromMap.defaultValue(), def->defaultValue() ); QCOMPARE( fromMap.supportsNonFileBasedOutputs(), def->supportsNonFileBasedOutputs() ); - def.reset( dynamic_cast< QgsProcessingParameterRasterOutput *>( QgsProcessingParameters::parameterFromVariantMap( map ) ) ); - QVERIFY( dynamic_cast< QgsProcessingParameterRasterOutput *>( def.get() ) ); + def.reset( dynamic_cast< QgsProcessingParameterRasterDestination *>( QgsProcessingParameters::parameterFromVariantMap( map ) ) ); + QVERIFY( dynamic_cast< QgsProcessingParameterRasterDestination *>( def.get() ) ); QString code = def->asScriptCode(); QCOMPARE( code, QStringLiteral( "##non_optional=rasterOut" ) ); - std::unique_ptr< QgsProcessingParameterRasterOutput > fromCode( dynamic_cast< QgsProcessingParameterRasterOutput * >( QgsProcessingParameters::parameterFromScriptCode( code ) ) ); + std::unique_ptr< QgsProcessingParameterRasterDestination > fromCode( dynamic_cast< QgsProcessingParameterRasterDestination * >( QgsProcessingParameters::parameterFromScriptCode( code ) ) ); QVERIFY( fromCode.get() ); QCOMPARE( fromCode->name(), def->name() ); QCOMPARE( fromCode->description(), QStringLiteral( "non optional" ) ); @@ -3727,7 +3727,7 @@ void TestQgsProcessing::parameterRasterOut() QCOMPARE( fromCode->defaultValue(), def->defaultValue() ); // optional - def.reset( new QgsProcessingParameterRasterOutput( "optional", QString(), QString( "default.tif" ), true ) ); + def.reset( new QgsProcessingParameterRasterDestination( "optional", QString(), QString( "default.tif" ), true ) ); QVERIFY( !def->checkValueIsAcceptable( false ) ); QVERIFY( !def->checkValueIsAcceptable( true ) ); QVERIFY( !def->checkValueIsAcceptable( 5 ) ); @@ -3742,7 +3742,7 @@ void TestQgsProcessing::parameterRasterOut() code = def->asScriptCode(); QCOMPARE( code, QStringLiteral( "##optional=optional rasterOut default.tif" ) ); - fromCode.reset( dynamic_cast< QgsProcessingParameterRasterOutput * >( QgsProcessingParameters::parameterFromScriptCode( code ) ) ); + fromCode.reset( dynamic_cast< QgsProcessingParameterRasterDestination * >( QgsProcessingParameters::parameterFromScriptCode( code ) ) ); QVERIFY( fromCode.get() ); QCOMPARE( fromCode->name(), def->name() ); QCOMPARE( fromCode->description(), QStringLiteral( "optional" ) ); @@ -3750,7 +3750,7 @@ void TestQgsProcessing::parameterRasterOut() QCOMPARE( fromCode->defaultValue(), def->defaultValue() ); // test layers to load on completion - def.reset( new QgsProcessingParameterRasterOutput( "x", QStringLiteral( "desc" ), QStringLiteral( "default.tif" ), true ) ); + def.reset( new QgsProcessingParameterRasterDestination( "x", QStringLiteral( "desc" ), QStringLiteral( "default.tif" ), true ) ); QgsProcessingOutputLayerDefinition fs = QgsProcessingOutputLayerDefinition( QStringLiteral( "test.tif" ) ); fs.destinationProject = &p; params.insert( QStringLiteral( "x" ), QVariant::fromValue( fs ) ); @@ -3782,7 +3782,7 @@ void TestQgsProcessing::parameterFileOut() context.setProject( &p ); // not optional! - std::unique_ptr< QgsProcessingParameterFileOutput > def( new QgsProcessingParameterFileOutput( "non_optional", QString(), QStringLiteral( "BMP files (*.bmp)" ), QVariant(), false ) ); + std::unique_ptr< QgsProcessingParameterFileDestination > def( new QgsProcessingParameterFileDestination( "non_optional", QString(), QStringLiteral( "BMP files (*.bmp)" ), QVariant(), false ) ); QCOMPARE( def->fileFilter(), QStringLiteral( "BMP files (*.bmp)" ) ); QCOMPARE( def->defaultFileExtension(), QStringLiteral( "bmp" ) ); QVERIFY( def->generateTemporaryDestination().endsWith( QStringLiteral( ".bmp" ) ) ); @@ -3824,7 +3824,7 @@ void TestQgsProcessing::parameterFileOut() QCOMPARE( def->valueAsPythonString( QVariant::fromValue( QgsProperty::fromExpression( "\"a\"=1" ) ), context ), QStringLiteral( "QgsProperty.fromExpression('\"a\"=1')" ) ); QVariantMap map = def->toVariantMap(); - QgsProcessingParameterFileOutput fromMap( "x" ); + QgsProcessingParameterFileDestination fromMap( "x" ); QVERIFY( fromMap.fromVariantMap( map ) ); QCOMPARE( fromMap.name(), def->name() ); QCOMPARE( fromMap.description(), def->description() ); @@ -3832,12 +3832,12 @@ void TestQgsProcessing::parameterFileOut() QCOMPARE( fromMap.defaultValue(), def->defaultValue() ); QCOMPARE( fromMap.fileFilter(), def->fileFilter() ); QCOMPARE( fromMap.supportsNonFileBasedOutputs(), def->supportsNonFileBasedOutputs() ); - def.reset( dynamic_cast< QgsProcessingParameterFileOutput *>( QgsProcessingParameters::parameterFromVariantMap( map ) ) ); - QVERIFY( dynamic_cast< QgsProcessingParameterFileOutput *>( def.get() ) ); + def.reset( dynamic_cast< QgsProcessingParameterFileDestination *>( QgsProcessingParameters::parameterFromVariantMap( map ) ) ); + QVERIFY( dynamic_cast< QgsProcessingParameterFileDestination *>( def.get() ) ); QString code = def->asScriptCode(); QCOMPARE( code, QStringLiteral( "##non_optional=fileOut" ) ); - std::unique_ptr< QgsProcessingParameterFileOutput > fromCode( dynamic_cast< QgsProcessingParameterFileOutput * >( QgsProcessingParameters::parameterFromScriptCode( code ) ) ); + std::unique_ptr< QgsProcessingParameterFileDestination > fromCode( dynamic_cast< QgsProcessingParameterFileDestination * >( QgsProcessingParameters::parameterFromScriptCode( code ) ) ); QVERIFY( fromCode.get() ); QCOMPARE( fromCode->name(), def->name() ); QCOMPARE( fromCode->description(), QStringLiteral( "non optional" ) ); @@ -3845,7 +3845,7 @@ void TestQgsProcessing::parameterFileOut() QCOMPARE( fromCode->defaultValue(), def->defaultValue() ); // optional - def.reset( new QgsProcessingParameterFileOutput( "optional", QString(), QString(), QString( "default.txt" ), true ) ); + def.reset( new QgsProcessingParameterFileDestination( "optional", QString(), QString(), QString( "default.txt" ), true ) ); QVERIFY( !def->checkValueIsAcceptable( false ) ); QVERIFY( !def->checkValueIsAcceptable( true ) ); QVERIFY( !def->checkValueIsAcceptable( 5 ) ); @@ -3860,7 +3860,7 @@ void TestQgsProcessing::parameterFileOut() code = def->asScriptCode(); QCOMPARE( code, QStringLiteral( "##optional=optional fileOut default.txt" ) ); - fromCode.reset( dynamic_cast< QgsProcessingParameterFileOutput * >( QgsProcessingParameters::parameterFromScriptCode( code ) ) ); + fromCode.reset( dynamic_cast< QgsProcessingParameterFileDestination * >( QgsProcessingParameters::parameterFromScriptCode( code ) ) ); QVERIFY( fromCode.get() ); QCOMPARE( fromCode->name(), def->name() ); QCOMPARE( fromCode->description(), QStringLiteral( "optional" ) ); @@ -3876,7 +3876,7 @@ void TestQgsProcessing::parameterFolderOut() context.setProject( &p ); // not optional! - std::unique_ptr< QgsProcessingParameterFolderOutput > def( new QgsProcessingParameterFolderOutput( "non_optional", QString(), QVariant(), false ) ); + std::unique_ptr< QgsProcessingParameterFolderDestination > def( new QgsProcessingParameterFolderDestination( "non_optional", QString(), QVariant(), false ) ); QVERIFY( !def->checkValueIsAcceptable( false ) ); QVERIFY( !def->checkValueIsAcceptable( true ) ); @@ -3897,19 +3897,19 @@ void TestQgsProcessing::parameterFolderOut() QCOMPARE( def->valueAsPythonString( QVariant::fromValue( QgsProperty::fromExpression( "\"a\"=1" ) ), context ), QStringLiteral( "QgsProperty.fromExpression('\"a\"=1')" ) ); QVariantMap map = def->toVariantMap(); - QgsProcessingParameterFolderOutput fromMap( "x" ); + QgsProcessingParameterFolderDestination fromMap( "x" ); QVERIFY( fromMap.fromVariantMap( map ) ); QCOMPARE( fromMap.name(), def->name() ); QCOMPARE( fromMap.description(), def->description() ); QCOMPARE( fromMap.flags(), def->flags() ); QCOMPARE( fromMap.defaultValue(), def->defaultValue() ); QCOMPARE( fromMap.supportsNonFileBasedOutputs(), def->supportsNonFileBasedOutputs() ); - def.reset( dynamic_cast< QgsProcessingParameterFolderOutput *>( QgsProcessingParameters::parameterFromVariantMap( map ) ) ); - QVERIFY( dynamic_cast< QgsProcessingParameterFolderOutput *>( def.get() ) ); + def.reset( dynamic_cast< QgsProcessingParameterFolderDestination *>( QgsProcessingParameters::parameterFromVariantMap( map ) ) ); + QVERIFY( dynamic_cast< QgsProcessingParameterFolderDestination *>( def.get() ) ); QString code = def->asScriptCode(); QCOMPARE( code, QStringLiteral( "##non_optional=folderOut" ) ); - std::unique_ptr< QgsProcessingParameterFolderOutput > fromCode( dynamic_cast< QgsProcessingParameterFolderOutput * >( QgsProcessingParameters::parameterFromScriptCode( code ) ) ); + std::unique_ptr< QgsProcessingParameterFolderDestination > fromCode( dynamic_cast< QgsProcessingParameterFolderDestination * >( QgsProcessingParameters::parameterFromScriptCode( code ) ) ); QVERIFY( fromCode.get() ); QCOMPARE( fromCode->name(), def->name() ); QCOMPARE( fromCode->description(), QStringLiteral( "non optional" ) ); @@ -3917,7 +3917,7 @@ void TestQgsProcessing::parameterFolderOut() QCOMPARE( fromCode->defaultValue(), def->defaultValue() ); // optional - def.reset( new QgsProcessingParameterFolderOutput( "optional", QString(), QString( "c:/junk" ), true ) ); + def.reset( new QgsProcessingParameterFolderDestination( "optional", QString(), QString( "c:/junk" ), true ) ); QVERIFY( !def->checkValueIsAcceptable( false ) ); QVERIFY( !def->checkValueIsAcceptable( true ) ); QVERIFY( !def->checkValueIsAcceptable( 5 ) ); @@ -3931,7 +3931,7 @@ void TestQgsProcessing::parameterFolderOut() code = def->asScriptCode(); QCOMPARE( code, QStringLiteral( "##optional=optional folderOut c:/junk" ) ); - fromCode.reset( dynamic_cast< QgsProcessingParameterFolderOutput * >( QgsProcessingParameters::parameterFromScriptCode( code ) ) ); + fromCode.reset( dynamic_cast< QgsProcessingParameterFolderDestination * >( QgsProcessingParameters::parameterFromScriptCode( code ) ) ); QVERIFY( fromCode.get() ); QCOMPARE( fromCode->name(), def->name() ); QCOMPARE( fromCode->description(), QStringLiteral( "optional" ) ); From 0836c60712aa6b63814563c2f161231c685c4888 Mon Sep 17 00:00:00 2001 From: Nyall Dawson Date: Sat, 8 Jul 2017 15:58:44 +1000 Subject: [PATCH 07/13] Make model editor dialog more robust while loading models --- python/plugins/processing/gui/wrappers.py | 5 ++++- python/plugins/processing/modeler/ModelerParametersDialog.py | 5 ++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/python/plugins/processing/gui/wrappers.py b/python/plugins/processing/gui/wrappers.py index 95db14ea33b..332d775b580 100644 --- a/python/plugins/processing/gui/wrappers.py +++ b/python/plugins/processing/gui/wrappers.py @@ -177,7 +177,10 @@ class WidgetWrapper(QObject): if combobox is None: combobox = self.widget if isinstance(value, list): - value = value[0] + if value: + value = value[0] + else: + value = None values = [combobox.itemData(i) for i in range(combobox.count())] try: idx = values.index(value) diff --git a/python/plugins/processing/modeler/ModelerParametersDialog.py b/python/plugins/processing/modeler/ModelerParametersDialog.py index b131196af5f..8d10a5b31d6 100644 --- a/python/plugins/processing/modeler/ModelerParametersDialog.py +++ b/python/plugins/processing/modeler/ModelerParametersDialog.py @@ -251,11 +251,14 @@ class ModelerParametersDialog(QDialog): for param in alg.algorithm().parameterDefinitions(): if param.isDestination() or param.flags() & QgsProcessingParameterDefinition.FlagHidden: continue + value = None if param.name() in alg.parameterSources(): value = alg.parameterSources()[param.name()] if isinstance(value, list) and len(value) == 1: value = value[0] - else: + elif isinstance(value, list) and len(value) == 0: + value = None + if value is None: value = param.defaultValue() if isinstance(value, QgsProcessingModelAlgorithm.ChildParameterSource) and value.source() == QgsProcessingModelAlgorithm.ChildParameterSource.StaticValue: From 3665e462c8c69ea9b4012043f1d858537c548ab7 Mon Sep 17 00:00:00 2001 From: Nyall Dawson Date: Sat, 8 Jul 2017 15:58:56 +1000 Subject: [PATCH 08/13] Use a filter line edit for outputs --- python/plugins/processing/modeler/ModelerParametersDialog.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/python/plugins/processing/modeler/ModelerParametersDialog.py b/python/plugins/processing/modeler/ModelerParametersDialog.py index 8d10a5b31d6..32aa8d97b07 100644 --- a/python/plugins/processing/modeler/ModelerParametersDialog.py +++ b/python/plugins/processing/modeler/ModelerParametersDialog.py @@ -44,7 +44,8 @@ from qgis.core import (QgsProcessingParameterDefinition, QgsProcessingOutputDefinition) from qgis.gui import (QgsMessageBar, - QgsScrollArea) + QgsScrollArea, + QgsFilterLineEdit) from processing.gui.wrappers import WidgetWrapperFactory from processing.gui.wrappers import InvalidParameterValue @@ -153,7 +154,7 @@ class ModelerParametersDialog(QDialog): if isinstance(dest, (QgsProcessingParameterRasterDestination, QgsProcessingParameterFeatureSink, QgsProcessingParameterFileDestination, QgsProcessingParameterFolderDestination)): label = QLabel(dest.description()) - item = QLineEdit() + item = QgsFilterLineEdit() if hasattr(item, 'setPlaceholderText'): item.setPlaceholderText(ModelerParametersDialog.ENTER_NAME) self.verticalLayout.addWidget(label) From 7db1a9dfd3492bcda18f23bea12144c3dbde5d26 Mon Sep 17 00:00:00 2001 From: Nyall Dawson Date: Sat, 8 Jul 2017 16:05:39 +1000 Subject: [PATCH 09/13] Save and restore window geometry for modeler dialogs --- .../modeler/ModelerParameterDefinitionDialog.py | 13 +++++++++++-- .../processing/modeler/ModelerParametersDialog.py | 15 +++++++++++++-- 2 files changed, 24 insertions(+), 4 deletions(-) diff --git a/python/plugins/processing/modeler/ModelerParameterDefinitionDialog.py b/python/plugins/processing/modeler/ModelerParameterDefinitionDialog.py index 05055506093..95d78d97235 100644 --- a/python/plugins/processing/modeler/ModelerParameterDefinitionDialog.py +++ b/python/plugins/processing/modeler/ModelerParameterDefinitionDialog.py @@ -29,7 +29,8 @@ __revision__ = '$Format:%H$' import math from qgis.gui import QgsExpressionLineEdit, QgsProjectionSelectionWidget -from qgis.core import (QgsCoordinateReferenceSystem, +from qgis.core import (QgsSettings, + QgsCoordinateReferenceSystem, QgsProcessingParameterDefinition, QgsProcessingParameterBoolean, QgsProcessingParameterCrs, @@ -48,7 +49,8 @@ from qgis.core import (QgsCoordinateReferenceSystem, QgsProcessingParameterVectorLayer, QgsProcessingParameterField, QgsProcessingParameterFeatureSource) -from qgis.PyQt.QtCore import Qt +from qgis.PyQt.QtCore import (Qt, + QByteArray) from qgis.PyQt.QtWidgets import (QDialog, QVBoxLayout, QLabel, @@ -98,6 +100,13 @@ class ModelerParameterDefinitionDialog(QDialog): QDialog.__init__(self) self.setModal(True) self.setupUi() + settings = QgsSettings() + self.restoreGeometry(settings.value("/Processing/modelParametersDefinitionDialogGeometry", QByteArray())) + + def closeEvent(self, event): + settings = QgsSettings() + settings.setValue("/Processing/modelParametersDefinitionDialogGeometry", self.saveGeometry()) + super(ModelerParameterDefinitionDialog, self).closeEvent(event) def setupUi(self): self.setWindowTitle(self.tr('Parameter definition')) diff --git a/python/plugins/processing/modeler/ModelerParametersDialog.py b/python/plugins/processing/modeler/ModelerParametersDialog.py index 32aa8d97b07..2a9dd5edf53 100644 --- a/python/plugins/processing/modeler/ModelerParametersDialog.py +++ b/python/plugins/processing/modeler/ModelerParametersDialog.py @@ -28,7 +28,10 @@ __revision__ = '$Format:%H$' import webbrowser -from qgis.PyQt.QtCore import Qt, QUrl, QMetaObject +from qgis.PyQt.QtCore import (Qt, + QUrl, + QMetaObject, + QByteArray) from qgis.PyQt.QtWidgets import (QDialog, QDialogButtonBox, QLabel, QLineEdit, QFrame, QPushButton, QSizePolicy, QVBoxLayout, QHBoxLayout, QWidget) @@ -41,7 +44,8 @@ from qgis.core import (QgsProcessingParameterDefinition, QgsProcessingParameterRasterDestination, QgsProcessingParameterFileDestination, QgsProcessingParameterFolderDestination, - QgsProcessingOutputDefinition) + QgsProcessingOutputDefinition, + QgsSettings) from qgis.gui import (QgsMessageBar, QgsScrollArea, @@ -70,6 +74,13 @@ class ModelerParametersDialog(QDialog): self.childId = algName self.setupUi() self.params = None + settings = QgsSettings() + self.restoreGeometry(settings.value("/Processing/modelParametersDialogGeometry", QByteArray())) + + def closeEvent(self, event): + settings = QgsSettings() + settings.setValue("/Processing/modelParametersDialogGeometry", self.saveGeometry()) + super(ModelerParametersDialog, self).closeEvent(event) def setupUi(self): self.labels = {} From a3fdb95d0a8e3a16a5f7fb1c0b7576520b5381ca Mon Sep 17 00:00:00 2001 From: Nyall Dawson Date: Sat, 8 Jul 2017 16:09:38 +1000 Subject: [PATCH 10/13] Update model input type names --- .../modeler/ModelerParameterDefinitionDialog.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/python/plugins/processing/modeler/ModelerParameterDefinitionDialog.py b/python/plugins/processing/modeler/ModelerParameterDefinitionDialog.py index 95d78d97235..6b86b32e67f 100644 --- a/python/plugins/processing/modeler/ModelerParameterDefinitionDialog.py +++ b/python/plugins/processing/modeler/ModelerParameterDefinitionDialog.py @@ -64,18 +64,18 @@ from qgis.PyQt.QtWidgets import (QDialog, class ModelerParameterDefinitionDialog(QDialog): PARAMETER_NUMBER = 'Number' - PARAMETER_RASTER = 'Raster layer' - PARAMETER_TABLE = 'Table' - PARAMETER_VECTOR = 'Vector layer' + PARAMETER_RASTER = 'Raster Layer' + PARAMETER_TABLE = 'Vector Layer' + PARAMETER_VECTOR = 'Feature Source' PARAMETER_STRING = 'String' PARAMETER_EXPRESSION = 'Expression' PARAMETER_BOOLEAN = 'Boolean' - PARAMETER_TABLE_FIELD = 'Table field' + PARAMETER_TABLE_FIELD = 'Layer Field' PARAMETER_EXTENT = 'Extent' PARAMETER_FILE = 'File' PARAMETER_POINT = 'Point' PARAMETER_CRS = 'CRS' - PARAMETER_MULTIPLE = 'Multiple input' + PARAMETER_MULTIPLE = 'Multiple Input' paramTypes = [ PARAMETER_BOOLEAN, From cfa18039af80695218c95d9ce60fc6207a31686f Mon Sep 17 00:00:00 2001 From: Nyall Dawson Date: Sat, 8 Jul 2017 17:27:03 +1000 Subject: [PATCH 11/13] Fix incorrect icon size in processing windows Well... kind of. It fixes the toolbar button size, but for some reason the actual icon content itself isn't being resized. I can't work out why this is... --- python/plugins/processing/gui/ScriptEditorDialog.py | 2 +- python/plugins/processing/modeler/ModelerDialog.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/python/plugins/processing/gui/ScriptEditorDialog.py b/python/plugins/processing/gui/ScriptEditorDialog.py index 64343bb12ec..3abccb0f022 100644 --- a/python/plugins/processing/gui/ScriptEditorDialog.py +++ b/python/plugins/processing/gui/ScriptEditorDialog.py @@ -68,7 +68,7 @@ class ScriptEditorDialog(BASE, WIDGET): self.restoreState(settings.value("/Processing/stateScriptEditor", QByteArray())) self.restoreGeometry(settings.value("/Processing/geometryScriptEditor", QByteArray())) - iconSize = int(settings.value("iconsize", 24)) + iconSize = int(settings.value("IconSize", 24)) self.toolBar.setIconSize(QSize(iconSize, iconSize)) self.actionOpenScript.setIcon( diff --git a/python/plugins/processing/modeler/ModelerDialog.py b/python/plugins/processing/modeler/ModelerDialog.py index 00740150cfc..b67cfd26c87 100644 --- a/python/plugins/processing/modeler/ModelerDialog.py +++ b/python/plugins/processing/modeler/ModelerDialog.py @@ -217,7 +217,7 @@ class ModelerDialog(BASE, WIDGET): ctrlEquals.activated.connect(self.zoomIn) try: - iconSize = int(settings.value("iconsize", 24)) + iconSize = int(settings.value("IconSize", 24)) except: iconSize = 24 self.mToolbar.setIconSize(QSize(iconSize, iconSize)) From f49b603443f3bf8fef1e5441ea7b7843c2874342 Mon Sep 17 00:00:00 2001 From: Nyall Dawson Date: Sat, 8 Jul 2017 20:00:40 +1000 Subject: [PATCH 12/13] Split QgsProcessingModelAlgorithm into separate components The cpp/h file was getting too large, so split off the individual subcomponents into their own h/cpp files to keep code maintainable. --- python/CMakeLists.txt | 1 + python/core/core_auto.sip | 7 +- .../models/qgsprocessingmodelalgorithm.sip | 379 +++++++ .../qgsprocessingmodelchildalgorithm.sip | 236 +++++ ...qgsprocessingmodelchildparametersource.sip | 192 ++++ .../models/qgsprocessingmodelcomponent.sip | 85 ++ .../models/qgsprocessingmodeloutput.sip | 92 ++ .../models/qgsprocessingmodelparameter.sip | 70 ++ .../processing/gui/NumberInputPanel.py | 16 +- .../processing/modeler/ModelerArrowItem.py | 10 +- .../processing/modeler/ModelerDialog.py | 3 +- .../processing/modeler/ModelerGraphicItem.py | 49 +- .../modeler/ModelerParametersDialog.py | 23 +- .../processing/modeler/ModelerScene.py | 10 +- .../plugins/processing/tests/ModelerTest.py | 15 +- src/core/CMakeLists.txt | 15 +- .../qgsprocessingmodelalgorithm.cpp | 631 ++--------- .../models/qgsprocessingmodelalgorithm.h | 405 ++++++++ .../qgsprocessingmodelchildalgorithm.cpp | 181 ++++ .../models/qgsprocessingmodelchildalgorithm.h | 254 +++++ ...qgsprocessingmodelchildparametersource.cpp | 149 +++ .../qgsprocessingmodelchildparametersource.h | 198 ++++ .../models/qgsprocessingmodelcomponent.cpp | 62 ++ .../models/qgsprocessingmodelcomponent.h | 94 ++ .../models/qgsprocessingmodeloutput.cpp | 47 + .../models/qgsprocessingmodeloutput.h | 98 ++ .../models/qgsprocessingmodelparameter.cpp | 44 + .../models/qgsprocessingmodelparameter.h | 77 ++ .../processing/qgsprocessingmodelalgorithm.h | 977 ------------------ .../processing/qgsprocessingparameters.cpp | 4 +- tests/src/core/CMakeLists.txt | 1 + tests/src/core/testqgsprocessing.cpp | 354 +++---- 32 files changed, 3017 insertions(+), 1762 deletions(-) create mode 100644 python/core/processing/models/qgsprocessingmodelalgorithm.sip create mode 100644 python/core/processing/models/qgsprocessingmodelchildalgorithm.sip create mode 100644 python/core/processing/models/qgsprocessingmodelchildparametersource.sip create mode 100644 python/core/processing/models/qgsprocessingmodelcomponent.sip create mode 100644 python/core/processing/models/qgsprocessingmodeloutput.sip create mode 100644 python/core/processing/models/qgsprocessingmodelparameter.sip rename src/core/processing/{ => models}/qgsprocessingmodelalgorithm.cpp (60%) create mode 100644 src/core/processing/models/qgsprocessingmodelalgorithm.h create mode 100644 src/core/processing/models/qgsprocessingmodelchildalgorithm.cpp create mode 100644 src/core/processing/models/qgsprocessingmodelchildalgorithm.h create mode 100644 src/core/processing/models/qgsprocessingmodelchildparametersource.cpp create mode 100644 src/core/processing/models/qgsprocessingmodelchildparametersource.h create mode 100644 src/core/processing/models/qgsprocessingmodelcomponent.cpp create mode 100644 src/core/processing/models/qgsprocessingmodelcomponent.h create mode 100644 src/core/processing/models/qgsprocessingmodeloutput.cpp create mode 100644 src/core/processing/models/qgsprocessingmodeloutput.h create mode 100644 src/core/processing/models/qgsprocessingmodelparameter.cpp create mode 100644 src/core/processing/models/qgsprocessingmodelparameter.h delete mode 100644 src/core/processing/qgsprocessingmodelalgorithm.h diff --git a/python/CMakeLists.txt b/python/CMakeLists.txt index ea46709cf21..1aa9cc79f07 100755 --- a/python/CMakeLists.txt +++ b/python/CMakeLists.txt @@ -117,6 +117,7 @@ INCLUDE_DIRECTORIES( ${CMAKE_SOURCE_DIR}/src/core/layout ${CMAKE_SOURCE_DIR}/src/core/metadata ${CMAKE_SOURCE_DIR}/src/core/processing + ${CMAKE_SOURCE_DIR}/src/core/processing/models ${CMAKE_SOURCE_DIR}/src/core/providers ${CMAKE_SOURCE_DIR}/src/core/providers/memory ${CMAKE_SOURCE_DIR}/src/core/raster diff --git a/python/core/core_auto.sip b/python/core/core_auto.sip index a3c2f144f0f..222dd725031 100644 --- a/python/core/core_auto.sip +++ b/python/core/core_auto.sip @@ -164,10 +164,15 @@ %Include processing/qgsprocessing.sip %Include processing/qgsprocessingalgorithm.sip %Include processing/qgsprocessingcontext.sip -%Include processing/qgsprocessingmodelalgorithm.sip %Include processing/qgsprocessingoutputs.sip %Include processing/qgsprocessingparameters.sip %Include processing/qgsprocessingutils.sip +%Include processing/models/qgsprocessingmodelalgorithm.sip +%Include processing/models/qgsprocessingmodelchildalgorithm.sip +%Include processing/models/qgsprocessingmodelchildparametersource.sip +%Include processing/models/qgsprocessingmodelcomponent.sip +%Include processing/models/qgsprocessingmodeloutput.sip +%Include processing/models/qgsprocessingmodelparameter.sip %Include providers/memory/qgsmemoryproviderutils.sip %Include raster/qgsbilinearrasterresampler.sip %Include raster/qgsbrightnesscontrastfilter.sip diff --git a/python/core/processing/models/qgsprocessingmodelalgorithm.sip b/python/core/processing/models/qgsprocessingmodelalgorithm.sip new file mode 100644 index 00000000000..a940fcbf7b2 --- /dev/null +++ b/python/core/processing/models/qgsprocessingmodelalgorithm.sip @@ -0,0 +1,379 @@ +/************************************************************************ + * This file has been generated automatically from * + * * + * src/core/processing/models/qgsprocessingmodelalgorithm.h * + * * + * Do not edit manually ! Edit header and run scripts/sipify.pl again * + ************************************************************************/ + + + + + +class QgsProcessingModelAlgorithm : QgsProcessingAlgorithm +{ +%Docstring + Model based algorithm with processing. +.. versionadded:: 3.0 +%End + +%TypeHeaderCode +#include "qgsprocessingmodelalgorithm.h" +%End + public: + + QgsProcessingModelAlgorithm( const QString &name = QString(), const QString &group = QString() ); +%Docstring + Constructor for QgsProcessingModelAlgorithm. +%End + + virtual QString name() const; + + virtual QString displayName() const; + + virtual QString group() const; + + virtual QIcon icon() const; + + virtual QString svgIconPath() const; + + virtual QString shortHelpString() const; + + virtual QString helpUrl() const; + + + virtual bool canExecute( QString *errorMessage /Out/ = 0 ) const; + + virtual QString asPythonCommand( const QVariantMap ¶meters, QgsProcessingContext &context ) const; + + virtual QgsProcessingModelAlgorithm *create() const /Factory/; + + + void setName( const QString &name ); +%Docstring + Sets the model ``name``. +.. seealso:: name() +%End + + void setGroup( const QString &group ); +%Docstring + Sets the model ``group``. +.. seealso:: group() +%End + + QMap childAlgorithms() const; +%Docstring + Returns the map of child algorithms contained in the model. The keys + are the child algorithm ids (see QgsProcessingModelAlgorithm.ChildAlgorithm.childId()). +.. seealso:: childAlgorithm() +.. seealso:: setChildAlgorithms() +.. seealso:: addChildAlgorithm() + :rtype: QMap +%End + + void setChildAlgorithms( const QMap &childAlgorithms ); +%Docstring + Sets the map of child algorithms contained in the model. The keys + are the child algorithm ids (see QgsProcessingModelAlgorithm.ChildAlgorithm.childId()). + All existing child algorithms will be replaced. +.. seealso:: childAlgorithms() +.. seealso:: childAlgorithm() +.. seealso:: setChildAlgorithm() +.. seealso:: addChildAlgorithm() +%End + + void setChildAlgorithm( const QgsProcessingModelChildAlgorithm &algorithm ); +%Docstring + Sets the child ``algorithm`` within the model. If a child algorithm already + exists in the model with the same child ID then that algorithm will be replaced. +.. seealso:: addChildAlgorithm() +.. seealso:: setChildAlgorithms() +%End + + QString addChildAlgorithm( QgsProcessingModelChildAlgorithm &algorithm ); +%Docstring + Adds a new child ``algorithm`` to the model. If a child algorithm already exists + in the model with the same child ID then ``algorithm`` will be assigned a new + autogenerated unique ID. + The assigned child ID will be returned. +.. seealso:: childAlgorithms() +.. seealso:: childAlgorithm() +.. seealso:: setChildAlgorithm() +.. seealso:: setChildAlgorithms() + :rtype: str +%End + + QgsProcessingModelChildAlgorithm &childAlgorithm( const QString &id ); +%Docstring + Returns the child algorithm with matching ``id``. If no child algorithm exists with + this ID a new algorithm will be added to the model and returned. +.. seealso:: addChildAlgorithm() +.. seealso:: childAlgorithms() + :rtype: QgsProcessingModelChildAlgorithm +%End + + bool removeChildAlgorithm( const QString &id ); +%Docstring + Attempts to remove the child algorithm with matching ``id``. + Returns true if the algorithm could be removed, or false + if the algorithm could not be removed (e.g. due to other + child algorithms depending on it). +.. seealso:: deactivateChildAlgorithm() + :rtype: bool +%End + + void deactivateChildAlgorithm( const QString &id ); +%Docstring + Deactivates the child algorithm with matching ``id``. + All other child algorithms which depend on the child + algorithm will also be deactivated. +.. seealso:: removeChildAlgorithm() +.. seealso:: activateChildAlgorithm() +%End + + bool activateChildAlgorithm( const QString &id ); +%Docstring + Attempts to activate the child algorithm with matching ``id``. + If any child algorithms on which the child depends are not active, + then the child will not be activated and false will be returned. +.. seealso:: deactivateChildAlgorithm() + :rtype: bool +%End + + QSet< QString > dependentChildAlgorithms( const QString &childId ) const; +%Docstring + Returns a list of the child algorithm IDs depending on the child + algorithm with the specified ``childId``. +.. seealso:: dependsOnChildAlgorithms() + :rtype: set of str +%End + + QSet< QString > dependsOnChildAlgorithms( const QString &childId ) const; +%Docstring + Returns a list of the child algorithm IDs on which the child + algorithm with the specified ``childId`` depends upon. +.. seealso:: dependentChildAlgorithms() + :rtype: set of str +%End + + void addModelParameter( QgsProcessingParameterDefinition *definition /Transfer/, const QgsProcessingModelParameter &component ); +%Docstring + Adds a new parameter to the model, with the specified ``definition`` and graphical ``component``. + Ownership of ``definition`` is transferred to the model. +.. seealso:: updateModelParameter() +.. seealso:: removeModelParameter() +%End + + void updateModelParameter( QgsProcessingParameterDefinition *definition /Transfer/ ); +%Docstring + Replaces the definition of an existing parameter (by parameter name) with a new ``definition``. Ownership of + ``definition`` is transferred to the model, and any existing parameter is deleted. +.. seealso:: addModelParameter() +.. seealso:: removeModelParameter() +%End + + void removeModelParameter( const QString &name ); +%Docstring + Removes an existing model parameter by ``name``. The definition of the matching parameter + is deleted. +.. seealso:: addModelParameter() +.. seealso:: updateModelParameter() +%End + + bool childAlgorithmsDependOnParameter( const QString &name ) const; +%Docstring + Returns true if any child algorithms depend on the model parameter + with the specified ``name``. +.. seealso:: otherParametersDependOnParameter() + :rtype: bool +%End + + bool otherParametersDependOnParameter( const QString &name ) const; +%Docstring + Returns true if any other model parameters depend on the parameter + with the specified ``name`` (e.g. field parameters where ``name`` + is the parent layer parameter). +.. seealso:: childAlgorithmsDependOnParameter() + :rtype: bool +%End + + QMap parameterComponents() const; +%Docstring + Returns the map of parameter components used by the model. The keys + should match the algorithm's parameter names (see parameterDefinitions() ). +.. seealso:: setParameterComponent() +.. seealso:: parameterComponent() + :rtype: QMap +%End + + void setParameterComponents( const QMap ¶meterComponents ); +%Docstring + Sets the map of parameter components used by the model. The keys + should match the algorithm's parameter names (see parameterDefinitions() ). + All existing parameter components will be replaced. +.. seealso:: parameterComponents() +.. seealso:: setParameterComponent() +.. seealso:: parameterComponent() +%End + + void setParameterComponent( const QgsProcessingModelParameter &component ); +%Docstring + Sets a parameter ``component`` for the model. If a parameter component already + exists in the model with the same parameter name then that component will be replaced. +.. seealso:: parameterComponents() +.. seealso:: setParameterComponents() +.. seealso:: parameterComponent() +%End + + QgsProcessingModelParameter ¶meterComponent( const QString &name ); +%Docstring + Returns the parameter component with matching ``name``. If no parameter component exists with + this name a new component will be added to the model and returned. +.. seealso:: parameterComponents() +.. seealso:: setParameterComponents() +.. seealso:: setParameterComponent() + :rtype: QgsProcessingModelParameter +%End + + void updateDestinationParameters(); +%Docstring + Updates the model's parameter definitions to include all relevant destination + parameters as required by child algorithm ModelOutputs. + Must be called whenever child algorithm ModelOutputs are altered. +%End + + bool toFile( const QString &path ) const; +%Docstring + Writes the model to a file, at the specified ``path``. +.. seealso:: fromFile() + :rtype: bool +%End + + bool fromFile( const QString &path ); +%Docstring + Reads the model from a file, at the specified ``path``. +.. seealso:: toFile() + :rtype: bool +%End + + QVariantMap &helpContent(); +%Docstring + Returns the model's help contents (a free-form map of values describing the algorithm's + use and metadata). +.. seealso:: setHelpContent() + :rtype: QVariantMap +%End + + + void setHelpContent( const QVariantMap &contents ); +%Docstring + Sets the model's help ``contents`` (a free-form map of values describing the algorithm's + use and metadata). +.. seealso:: helpContent() +%End + + QString sourceFilePath() const; +%Docstring + Returns the source file path for the model, if available. +.. seealso:: setSourceFilePath() + :rtype: str +%End + + void setSourceFilePath( const QString &path ); +%Docstring + Sets the source file ``path`` for the model, if available. +.. seealso:: sourceFilePath() +%End + + QString asPythonCode() const; +%Docstring + Attempts to convert the model to executable Python code. + :rtype: str +%End + + QList< QgsProcessingModelChildParameterSource > availableSourcesForChild( const QString &childId, const QStringList ¶meterTypes = QStringList(), + const QStringList &outputTypes = QStringList(), const QList< int > dataTypes = QList< int >() ) const; +%Docstring + Returns a list of possible sources which can be used for the parameters for a child + algorithm in the model. Returned sources are those which match either one of the + specified ``parameterTypes`` (see QgsProcessingParameterDefinition.type() ) or + on of the specified ``outputTypes`` (see QgsProcessingOutputDefinition.type() ). + If specified, an optional list of ``dataTypes`` can be used to filter the returned + sources to those with compatible data types for the parameter/outputs. + :rtype: list of QgsProcessingModelChildParameterSource +%End + + class VariableDefinition +{ +%Docstring + Definition of a expression context variable available during model execution. +.. versionadded:: 3.0 +%End + +%TypeHeaderCode +#include "qgsprocessingmodelalgorithm.h" +%End + public: + + VariableDefinition( const QVariant &value = QVariant(), const QgsProcessingModelChildParameterSource &source = QgsProcessingModelChildParameterSource::fromStaticValue( QVariant() ), const QString &description = QString() ); +%Docstring + Constructor for a new VariableDefinition with the specified ``value`` and original + parameter ``source``, and ``description``. +%End + + QVariant value; +%Docstring +Value of variable +%End + + QgsProcessingModelChildParameterSource source; +%Docstring +Original source of variable's value +%End + + QString description; +%Docstring +Translated description of variable +%End + }; + + QMap< QString, QgsProcessingModelAlgorithm::VariableDefinition > variablesForChildAlgorithm( const QString &childId, QgsProcessingContext &context, const QVariantMap &modelParameters = QVariantMap(), + const QVariantMap &results = QVariantMap() ) const; +%Docstring + Returns a map of variable name to variable definition for expression context variables which are available + for use by child algorithm during model execution. + + The child algorithm ``childId`` and processing ``context`` + are manadatory. If ``modelParameters`` and ``results`` are not specified, then only the variable names and sources + will be returned, but all variable values will be null. This can be used to determine in advance which variables + will be available for a specific child algorithm, e.g. for use in expression builder widgets. + + In order to calculate the actual variable value, the input model ``modelParameters`` and already executed child + algorithm ``results`` must be passed. +.. seealso:: createExpressionContextScopeForChildAlgorithm() + :rtype: QMap< str, QgsProcessingModelAlgorithm.VariableDefinition > +%End + + QgsExpressionContextScope *createExpressionContextScopeForChildAlgorithm( const QString &childId, QgsProcessingContext &context, const QVariantMap &modelParameters = QVariantMap(), + const QVariantMap &results = QVariantMap() ) const /Factory/; +%Docstring + Creates a new expression context scope for a child algorithm within the model. +.. seealso:: variablesForChildAlgorithm() + :rtype: QgsExpressionContextScope +%End + + protected: + + virtual QVariantMap processAlgorithm( const QVariantMap ¶meters, QgsProcessingContext &context, QgsProcessingFeedback *feedback ); + + +}; + + +/************************************************************************ + * This file has been generated automatically from * + * * + * src/core/processing/models/qgsprocessingmodelalgorithm.h * + * * + * Do not edit manually ! Edit header and run scripts/sipify.pl again * + ************************************************************************/ diff --git a/python/core/processing/models/qgsprocessingmodelchildalgorithm.sip b/python/core/processing/models/qgsprocessingmodelchildalgorithm.sip new file mode 100644 index 00000000000..212b3d1a360 --- /dev/null +++ b/python/core/processing/models/qgsprocessingmodelchildalgorithm.sip @@ -0,0 +1,236 @@ +/************************************************************************ + * This file has been generated automatically from * + * * + * src/core/processing/models/qgsprocessingmodelchildalgorithm.h * + * * + * Do not edit manually ! Edit header and run scripts/sipify.pl again * + ************************************************************************/ + + + + + + +class QgsProcessingModelChildAlgorithm : QgsProcessingModelComponent +{ +%Docstring + Child algorithm representing a single component of a QgsProcessingModelAlgorithm. +.. versionadded:: 3.0 +%End + +%TypeHeaderCode +#include "qgsprocessingmodelchildalgorithm.h" +%End + public: + + QgsProcessingModelChildAlgorithm( const QString &algorithmId = QString() ); +%Docstring + Constructor for QgsProcessingModelChildAlgorithm. The ``algorithmId`` parameter + should be set to a QgsProcessingAlgorithm algorithm ID. +%End + + QString childId() const; +%Docstring + Returns the child algorithm's unique ID string, used the identify + this child algorithm within its parent model. +.. seealso:: setChildId() +.. seealso:: generateChildId() + :rtype: str +%End + + void setChildId( const QString &id ); +%Docstring + Sets the child algorithm's unique ``id`` string, used the identify + this child algorithm within its parent model. +.. seealso:: childId() +.. seealso:: generateChildId() +%End + + void generateChildId( const QgsProcessingModelAlgorithm &model ); +%Docstring + Automatically generates a unique childId() for the algorithm, + avoiding child IDs which are already present in ``model``. +.. seealso:: childId() +.. seealso:: setChildId() +%End + + QString algorithmId() const; +%Docstring + Returns the underlying child algorithm's ID. +.. seealso:: algorithm() +.. seealso:: setAlgorithmId() + :rtype: str +%End + + void setAlgorithmId( const QString &algorithmId ); +%Docstring + Sets the underlying child algorithm's ID. This + should be set to an existing QgsProcessingAlgorithm algorithm ID. +.. seealso:: algorithm() +.. seealso:: algorithmId() +%End + + const QgsProcessingAlgorithm *algorithm() const; +%Docstring + Returns the underlying child algorithm, or a None + if a matching algorithm is not available. +.. seealso:: algorithmId() + :rtype: QgsProcessingAlgorithm +%End + + QMap< QString, QList< QgsProcessingModelChildParameterSource > > parameterSources() const; +%Docstring + Returns a map of parameter sources. The keys are the child algorithm + parameter names, the values are the sources for that parameter. +.. seealso:: setParameterSources() +.. seealso:: addParameterSources() + :rtype: QMap< str, QList< QgsProcessingModelChildParameterSource > > +%End + + void setParameterSources( const QMap< QString, QList< QgsProcessingModelChildParameterSource > > &sources ); +%Docstring + Sets the map of parameter ``sources``. The keys are the child algorithm + parameter names, the values are the sources for that parameter. +.. seealso:: parameterSources() +.. seealso:: addParameterSources() +%End + + void addParameterSources( const QString &name, const QList< QgsProcessingModelChildParameterSource > &source ); +%Docstring + Adds a parameter source. The ``name`` argument should match + one of the child algorithm's parameter names, and the ``sources`` + argument is used to set the sources for that parameter. + + Any existing parameter sources with matching name will be replaced. +.. seealso:: parameterSources() +.. seealso:: setParameterSources() +%End + + bool isActive() const; +%Docstring + Returns true if the child algorithm is active. +.. seealso:: setActive() + :rtype: bool +%End + + void setActive( bool active ); +%Docstring + Sets whether the child algorithm is active. +.. seealso:: isActive() +%End + + QStringList dependencies() const; +%Docstring + Returns the list of child algorithms from the parent model on which this + algorithm is dependent. The returned list contains the id() of the + dependent algorithms. +.. seealso:: setDependencies() + :rtype: list of str +%End + + void setDependencies( const QStringList &dependencies ); +%Docstring + Sets the list of child algorithms from the parent model on which this + algorithm is dependent. The list should contain the id() of the + dependent algorithms. +.. seealso:: dependencies() +%End + + bool parametersCollapsed() const; +%Docstring + Returns true if the list of parameters for this algorithm should be collapsed + in the graphical modeller. +.. seealso:: setParametersCollapsed() +.. seealso:: outputsCollapsed() + :rtype: bool +%End + + void setParametersCollapsed( bool collapsed ); +%Docstring + Sets whether the list of parameters for this algorithm should be collapsed + in the graphical modeller. +.. seealso:: parametersCollapsed() +.. seealso:: setOutputsCollapsed() +%End + + bool outputsCollapsed() const; +%Docstring + Returns true if the list of outputs for this algorithm should be collapsed + in the graphical modeller. +.. seealso:: setParametersCollapsed() +.. seealso:: parametersCollapsed() + :rtype: bool +%End + + void setOutputsCollapsed( bool collapsed ); +%Docstring + Sets whether the list of outputs for this algorithm should be collapsed + in the graphical modeller. +.. seealso:: outputsCollapsed() +.. seealso:: setParametersCollapsed() +%End + + QMap modelOutputs() const; +%Docstring + Returns the map of final model outputs which are generated by this child algorithm. + The keys are the output names from this child algorithm. Only outputs which are + part of the final outputs from the model are included in this map. +.. seealso:: setModelOutputs() +.. seealso:: modelOutput() + :rtype: QMap +%End + + QgsProcessingModelOutput &modelOutput( const QString &name ); +%Docstring + Returns the final model output with matching ``name``. If no output + exists with the name, a new one will be created and returned. + + If child model outputs are altered by this method, QgsProcessingModelAlgorithm.updateDestinationParameters() + must be called on the parent model. + +.. seealso:: modelOutputs() +.. seealso:: setModelOutputs() + :rtype: QgsProcessingModelOutput +%End + + void setModelOutputs( const QMap &outputs ); +%Docstring + Sets the map of final model ``outputs`` which are generated by this child algorithm. + Only outputs which are part of the final outputs from the model should be included in this map. + + If child model outputs are altered by this method, QgsProcessingModelAlgorithm.updateDestinationParameters() + must be called on the parent model. + +.. seealso:: modelOutputs() +%End + + QVariant toVariant() const; +%Docstring + Saves this child to a QVariant. +.. seealso:: loadVariant() + :rtype: QVariant +%End + + bool loadVariant( const QVariant &child ); +%Docstring + Loads this child from a QVariant. +.. seealso:: toVariant() + :rtype: bool +%End + + QString asPythonCode() const; +%Docstring + Attempts to convert the child to executable Python code. + :rtype: str +%End + +}; + + +/************************************************************************ + * This file has been generated automatically from * + * * + * src/core/processing/models/qgsprocessingmodelchildalgorithm.h * + * * + * Do not edit manually ! Edit header and run scripts/sipify.pl again * + ************************************************************************/ diff --git a/python/core/processing/models/qgsprocessingmodelchildparametersource.sip b/python/core/processing/models/qgsprocessingmodelchildparametersource.sip new file mode 100644 index 00000000000..6b92b9c26a0 --- /dev/null +++ b/python/core/processing/models/qgsprocessingmodelchildparametersource.sip @@ -0,0 +1,192 @@ +/************************************************************************ + * This file has been generated automatically from * + * * + * src/core/processing/models/qgsprocessingmodelchildparametersource.h * + * * + * Do not edit manually ! Edit header and run scripts/sipify.pl again * + ************************************************************************/ + + + + + +class QgsProcessingModelChildParameterSource +{ +%Docstring + Source for the value of a parameter for a child algorithm within a model. +.. versionadded:: 3.0 +%End + +%TypeHeaderCode +#include "qgsprocessingmodelchildparametersource.h" +%End + public: + + enum Source + { + ModelParameter, + ChildOutput, + StaticValue, + Expression, + }; + + QgsProcessingModelChildParameterSource(); +%Docstring + Constructor for QgsProcessingModelChildParameterSource. It is recommended that the static methods + fromStaticValue(), fromModelParameter(), fromChildOutput() and fromExpression() are used instead. +%End + + bool operator==( const QgsProcessingModelChildParameterSource &other ) const; + bool operator!=( const QgsProcessingModelChildParameterSource &other ) const; +%Docstring + :rtype: bool +%End + + static QgsProcessingModelChildParameterSource fromStaticValue( const QVariant &value ); +%Docstring + Returns a new QgsProcessingModelChildParameterSource which takes its value from a static ``value``. +.. seealso:: fromModelParameter() +.. seealso:: fromChildOutput() +.. seealso:: fromExpression() + :rtype: QgsProcessingModelChildParameterSource +%End + + static QgsProcessingModelChildParameterSource fromModelParameter( const QString ¶meterName ); +%Docstring + Returns a new QgsProcessingModelChildParameterSource which takes its value from a parent model parameter. +.. seealso:: fromStaticValue() +.. seealso:: fromChildOutput() +.. seealso:: fromExpression() + :rtype: QgsProcessingModelChildParameterSource +%End + + static QgsProcessingModelChildParameterSource fromChildOutput( const QString &childId, const QString &outputName ); +%Docstring + Returns a new QgsProcessingModelChildParameterSource which takes its value from an output generated by a child algorithm. +.. seealso:: fromStaticValue() +.. seealso:: fromModelParameter() +.. seealso:: fromExpression() + :rtype: QgsProcessingModelChildParameterSource +%End + + static QgsProcessingModelChildParameterSource fromExpression( const QString &expression ); +%Docstring + Returns a new QgsProcessingModelChildParameterSource which takes its value from an expression. The expression + is evaluated just before the child algorithm executes, and can use functions available + in its expression context to include results calculated from the child algorithms already + executed by the model. +.. seealso:: fromStaticValue() +.. seealso:: fromChildOutput() +.. seealso:: fromModelParameter() + :rtype: QgsProcessingModelChildParameterSource +%End + + Source source() const; +%Docstring + Returns the parameter value's source. + :rtype: Source +%End + + QVariant staticValue() const; +%Docstring + Returns the source's static value. This is only used when the source() is StaticValue. +.. seealso:: setStaticValue() + :rtype: QVariant +%End + + void setStaticValue( const QVariant &value ); +%Docstring + Sets the source's static value. Calling this will also change the source() to StaticValue. +.. seealso:: staticValue() +%End + + QString parameterName() const; +%Docstring + Returns the source's model parameter name. This is only used when the source() is ModelParameter. +.. seealso:: setParameterName() + :rtype: str +%End + + void setParameterName( const QString &name ); +%Docstring + Sets the source's model parameter ``name``. Calling this will also change the source() to ModelParameter. +.. seealso:: parameterName() +%End + + QString outputChildId() const; +%Docstring + Returns the source's child algorithm ID from which the output value will be taken. This is only used when the source() is ChildOutput. +.. seealso:: setOutputChildId() +.. seealso:: outputName() + :rtype: str +%End + + void setOutputChildId( const QString &id ); +%Docstring + Sets the source's child algorithm ``id`` from which the output value will be taken. Calling this will also change the source() to ChildOutput. +.. seealso:: parameterName() +.. seealso:: setOutputName() +%End + + QString outputName() const; +%Docstring + Returns the source's child algorithm output name from which the output value will be taken. This is only used when the source() is ChildOutput. +.. seealso:: setOutputName() +.. seealso:: outputChildId() + :rtype: str +%End + + void setOutputName( const QString &name ); +%Docstring + Sets the source's child algorithm output ``name`` from which the output value will be taken. Calling this will also change the source() to ChildOutput. +.. seealso:: outputName() +.. seealso:: setOutputChildId() +%End + + QString expression() const; +%Docstring + Returns the source's expression. This is only used when the source() is Expression. +.. seealso:: setExpression() + :rtype: str +%End + + void setExpression( const QString &expression ); +%Docstring + Sets the source's expression. Calling this will also change the source() to Expression. + The expression is evaluated just before the child algorithm executes, and can use functions available + in its expression context to include results calculated from the child algorithms already + executed by the model. +.. seealso:: expression() +%End + + QVariant toVariant() const; +%Docstring + Saves this source to a QVariant. +.. seealso:: loadVariant() + :rtype: QVariant +%End + + bool loadVariant( const QVariantMap &map ); +%Docstring + Loads this source from a QVariantMap. +.. seealso:: toVariant() + :rtype: bool +%End + + QString asPythonCode() const; +%Docstring + Attempts to convert the source to executable Python code. + :rtype: str +%End + +}; + + + +/************************************************************************ + * This file has been generated automatically from * + * * + * src/core/processing/models/qgsprocessingmodelchildparametersource.h * + * * + * Do not edit manually ! Edit header and run scripts/sipify.pl again * + ************************************************************************/ diff --git a/python/core/processing/models/qgsprocessingmodelcomponent.sip b/python/core/processing/models/qgsprocessingmodelcomponent.sip new file mode 100644 index 00000000000..e2e0adce6d3 --- /dev/null +++ b/python/core/processing/models/qgsprocessingmodelcomponent.sip @@ -0,0 +1,85 @@ +/************************************************************************ + * This file has been generated automatically from * + * * + * src/core/processing/models/qgsprocessingmodelcomponent.h * + * * + * Do not edit manually ! Edit header and run scripts/sipify.pl again * + ************************************************************************/ + + + + + +class QgsProcessingModelComponent +{ +%Docstring + Represents a component of a model algorithm. +.. versionadded:: 3.0 +%End + +%TypeHeaderCode +#include "qgsprocessingmodelcomponent.h" +%End + public: + + QString description() const; +%Docstring + Returns the friendly description text for the component. +.. seealso:: setDescription() + :rtype: str +%End + + void setDescription( const QString &description ); +%Docstring + Sets the friendly ``description`` text for the component. +.. seealso:: description() +%End + + QPointF position() const; +%Docstring + Returns the position of the model component within the graphical modeler. +.. seealso:: setPosition() + :rtype: QPointF +%End + + void setPosition( const QPointF &position ); +%Docstring + Sets the ``position`` of the model component within the graphical modeler. +.. seealso:: position() +%End + + protected: + + QgsProcessingModelComponent( const QString &description = QString() ); +%Docstring +Only subclasses can be created +%End + + QgsProcessingModelComponent( const QgsProcessingModelComponent &other ); +%Docstring +Copies are protected to avoid slicing +%End + + + void saveCommonProperties( QVariantMap &map ) const; +%Docstring + Saves the component properties to a QVariantMap. +.. seealso:: restoreCommonProperties() +%End + + void restoreCommonProperties( const QVariantMap &map ); +%Docstring + Restores the component properties from a QVariantMap. +.. seealso:: saveCommonProperties() +%End + +}; + + +/************************************************************************ + * This file has been generated automatically from * + * * + * src/core/processing/models/qgsprocessingmodelcomponent.h * + * * + * Do not edit manually ! Edit header and run scripts/sipify.pl again * + ************************************************************************/ diff --git a/python/core/processing/models/qgsprocessingmodeloutput.sip b/python/core/processing/models/qgsprocessingmodeloutput.sip new file mode 100644 index 00000000000..ea420e38ac5 --- /dev/null +++ b/python/core/processing/models/qgsprocessingmodeloutput.sip @@ -0,0 +1,92 @@ +/************************************************************************ + * This file has been generated automatically from * + * * + * src/core/processing/models/qgsprocessingmodeloutput.h * + * * + * Do not edit manually ! Edit header and run scripts/sipify.pl again * + ************************************************************************/ + + + + + +class QgsProcessingModelOutput : QgsProcessingModelComponent +{ +%Docstring + Represents a final output created by the model. +.. versionadded:: 3.0 +%End + +%TypeHeaderCode +#include "qgsprocessingmodeloutput.h" +%End + public: + + QgsProcessingModelOutput( const QString &name = QString(), const QString &description = QString() ); +%Docstring + Constructor for QgsProcessingModelOutput with the specified ``name`` and ``description``. +%End + + QString name() const; +%Docstring + Returns the model output name. +.. seealso:: setName() + :rtype: str +%End + + void setName( const QString &name ); +%Docstring + Sets the model output ``name``. +.. seealso:: name() +%End + + QString childId() const; +%Docstring + Returns the child algorithm ID from which this output is generated. +.. seealso:: setChildId() + :rtype: str +%End + + void setChildId( const QString &id ); +%Docstring + Sets the child algorithm ``id`` from which this output is generated. +.. seealso:: childId() +%End + + QString childOutputName() const; +%Docstring + Returns the child algorithm output name from which this output is generated. +.. seealso:: setOutputName() + :rtype: str +%End + + void setChildOutputName( const QString &name ); +%Docstring + Sets the child algorithm output ``name`` from which this output is generated. +.. seealso:: outputName() +%End + + QVariant toVariant() const; +%Docstring + Saves this output to a QVariant. +.. seealso:: loadVariant() + :rtype: QVariant +%End + + bool loadVariant( const QVariantMap &map ); +%Docstring + Loads this output from a QVariantMap. +.. seealso:: toVariant() + :rtype: bool +%End + +}; + + +/************************************************************************ + * This file has been generated automatically from * + * * + * src/core/processing/models/qgsprocessingmodeloutput.h * + * * + * Do not edit manually ! Edit header and run scripts/sipify.pl again * + ************************************************************************/ diff --git a/python/core/processing/models/qgsprocessingmodelparameter.sip b/python/core/processing/models/qgsprocessingmodelparameter.sip new file mode 100644 index 00000000000..fb95c81b143 --- /dev/null +++ b/python/core/processing/models/qgsprocessingmodelparameter.sip @@ -0,0 +1,70 @@ +/************************************************************************ + * This file has been generated automatically from * + * * + * src/core/processing/models/qgsprocessingmodelparameter.h * + * * + * Do not edit manually ! Edit header and run scripts/sipify.pl again * + ************************************************************************/ + + + + + + +class QgsProcessingModelParameter : QgsProcessingModelComponent +{ +%Docstring + Represents an input parameter used by the model. +.. versionadded:: 3.0 +%End + +%TypeHeaderCode +#include "qgsprocessingmodelparameter.h" +%End + public: + + QgsProcessingModelParameter( const QString ¶meterName = QString() ); +%Docstring + Constructor for QgsProcessingModelParameter. The parameter name should match one of the + parameters from the parent model. +%End + + QString parameterName() const; +%Docstring + Returns the associated parameter name. The parameter name should match one of the + parameters from the parent model. +.. seealso:: parameterName() + :rtype: str +%End + + void setParameterName( const QString &name ); +%Docstring + Sets the associated parameter name. The parameter name should match one of the + parameters from the parent model. +.. seealso:: parameterName() +%End + + QVariant toVariant() const; +%Docstring + Saves this parameter to a QVariant. +.. seealso:: loadVariant() + :rtype: QVariant +%End + + bool loadVariant( const QVariantMap &map ); +%Docstring + Loads this parameter from a QVariantMap. +.. seealso:: toVariant() + :rtype: bool +%End + +}; + + +/************************************************************************ + * This file has been generated automatically from * + * * + * src/core/processing/models/qgsprocessingmodelparameter.h * + * * + * Do not edit manually ! Edit header and run scripts/sipify.pl again * + ************************************************************************/ diff --git a/python/plugins/processing/gui/NumberInputPanel.py b/python/plugins/processing/gui/NumberInputPanel.py index d904f11033a..888a3db30e1 100644 --- a/python/plugins/processing/gui/NumberInputPanel.py +++ b/python/plugins/processing/gui/NumberInputPanel.py @@ -36,7 +36,7 @@ from qgis.PyQt.QtWidgets import QDialog from qgis.core import (QgsExpression, QgsProcessingParameterNumber, QgsProcessingOutputNumber, - QgsProcessingModelAlgorithm) + QgsProcessingModelChildParameterSource) from qgis.gui import QgsExpressionBuilderDialog from processing.tools.dataobjects import createExpressionContext, createContext @@ -92,26 +92,26 @@ class ModellerNumberInputPanel(BASE, WIDGET): for param in self.modelParametersDialog.model.parameterDefinitions(): if isinstance(param, QgsProcessingParameterNumber): if "@" + param.name() == value.strip(): - return QgsProcessingModelAlgorithm.ChildParameterSource.fromModelParameter(param.name()) + return QgsProcessingModelChildParameterSource.fromModelParameter(param.name()) for alg in list(self.modelParametersDialog.model.childAlgorithms().values()): for out in alg.algorithm().outputDefinitions(): if isinstance(out, QgsProcessingOutputNumber) and "@%s_%s" % (alg.childId(), out.name()) == value.strip(): - return QgsProcessingModelAlgorithm.ChildParameterSource.fromChildOutput(alg.childId(), out.outputName()) + return QgsProcessingModelChildParameterSource.fromChildOutput(alg.childId(), out.outputName()) try: return float(value.strip()) except: - return QgsProcessingModelAlgorithm.ChildParameterSource.fromExpression(self.leText.text()) + return QgsProcessingModelChildParameterSource.fromExpression(self.leText.text()) def setValue(self, value): - if isinstance(value, QgsProcessingModelAlgorithm.ChildParameterSource): - if value.source() == QgsProcessingModelAlgorithm.ChildParameterSource.ModelParameter: + if isinstance(value, QgsProcessingModelChildParameterSource): + if value.source() == QgsProcessingModelChildParameterSource.ModelParameter: self.leText.setText('@' + value.parameterName()) - elif value.source() == QgsProcessingModelAlgorithm.ChildParameterSource.ChildOutput: + elif value.source() == QgsProcessingModelChildParameterSource.ChildOutput: name = "%s_%s" % (value.outputChildId(), value.outputName()) self.leText.setText(name) - elif value.source() == QgsProcessingModelAlgorithm.ChildParameterSource.Expression: + elif value.source() == QgsProcessingModelChildParameterSource.Expression: self.leText.setText(value.expression()) else: self.leText.setText(str(value.staticValue())) diff --git a/python/plugins/processing/modeler/ModelerArrowItem.py b/python/plugins/processing/modeler/ModelerArrowItem.py index 5392d240653..db45df9e25e 100644 --- a/python/plugins/processing/modeler/ModelerArrowItem.py +++ b/python/plugins/processing/modeler/ModelerArrowItem.py @@ -46,7 +46,9 @@ *************************************************************************** """ -from qgis.core import QgsProcessingModelAlgorithm +from qgis.core import (QgsProcessingModelAlgorithm, + QgsProcessingModelChildAlgorithm, + QgsProcessingModelParameter) from qgis.PyQt.QtCore import Qt, QPointF from qgis.PyQt.QtWidgets import QGraphicsPathItem, QGraphicsItem from qgis.PyQt.QtGui import QPen, QPainterPath, QPolygonF, QPainter @@ -80,14 +82,14 @@ class ModelerArrowItem(QGraphicsPathItem): self.endPoints = [] controlPoints = [] endPt = self.endItem.getLinkPointForParameter(self.endIndex) - if isinstance(self.startItem.element, QgsProcessingModelAlgorithm.ModelParameter): + if isinstance(self.startItem.element, QgsProcessingModelParameter): startPt = self.startItem.getLinkPointForParameter(self.startIndex) else: startPt = self.startItem.getLinkPointForOutput(self.startIndex) - if isinstance(self.endItem.element, QgsProcessingModelAlgorithm.ModelParameter): + if isinstance(self.endItem.element, QgsProcessingModelParameter): endPt = self.endItem.getLinkPointForParameter(self.startIndex) - if isinstance(self.startItem.element, QgsProcessingModelAlgorithm.ChildAlgorithm): + if isinstance(self.startItem.element, QgsProcessingModelChildAlgorithm): if self.startIndex != -1: controlPoints.append(self.startItem.pos() + startPt) controlPoints.append(self.startItem.pos() + startPt + diff --git a/python/plugins/processing/modeler/ModelerDialog.py b/python/plugins/processing/modeler/ModelerDialog.py index b67cfd26c87..d9580a68be5 100644 --- a/python/plugins/processing/modeler/ModelerDialog.py +++ b/python/plugins/processing/modeler/ModelerDialog.py @@ -43,6 +43,7 @@ from qgis.core import (QgsApplication, QgsMessageLog, QgsProcessingUtils, QgsProcessingModelAlgorithm, + QgsProcessingModelParameter, QgsXmlUtils) from qgis.gui import QgsMessageBar from processing.gui.HelpEditionDialog import HelpEditionDialog @@ -513,7 +514,7 @@ class ModelerDialog(BASE, WIDGET): pos = self.getPositionForParameterItem() if isinstance(pos, QPoint): pos = QPointF(pos) - component = QgsProcessingModelAlgorithm.ModelParameter(dlg.param.name()) + component = QgsProcessingModelParameter(dlg.param.name()) component.setDescription(dlg.param.name()) component.setPosition(pos) self.model.addModelParameter(dlg.param, component) diff --git a/python/plugins/processing/modeler/ModelerGraphicItem.py b/python/plugins/processing/modeler/ModelerGraphicItem.py index 39b957e8adc..84807100353 100644 --- a/python/plugins/processing/modeler/ModelerGraphicItem.py +++ b/python/plugins/processing/modeler/ModelerGraphicItem.py @@ -34,6 +34,9 @@ from qgis.PyQt.QtGui import QFont, QFontMetricsF, QPen, QBrush, QColor, QPolygon from qgis.PyQt.QtWidgets import QGraphicsItem, QMessageBox, QMenu from qgis.PyQt.QtSvg import QSvgRenderer from qgis.core import (QgsProcessingParameterDefinition, + QgsProcessingModelParameter, + QgsProcessingModelOutput, + QgsProcessingModelChildAlgorithm, QgsProcessingModelAlgorithm) from processing.modeler.ModelerParameterDefinitionDialog import ModelerParameterDefinitionDialog from processing.modeler.ModelerParametersDialog import ModelerParametersDialog @@ -52,14 +55,14 @@ class ModelerGraphicItem(QGraphicsItem): self.model = model self.scene = scene self.element = element - if isinstance(element, QgsProcessingModelAlgorithm.ModelParameter): + if isinstance(element, QgsProcessingModelParameter): svg = QSvgRenderer(os.path.join(pluginPath, 'images', 'input.svg')) self.picture = QPicture() painter = QPainter(self.picture) svg.render(painter) self.pixmap = None self.text = self.model.parameterDefinition(element.parameterName()).description() - elif isinstance(element, QgsProcessingModelAlgorithm.ModelOutput): + elif isinstance(element, QgsProcessingModelOutput): # Output name svg = QSvgRenderer(os.path.join(pluginPath, 'images', 'output.svg')) self.picture = QPicture() @@ -76,7 +79,7 @@ class ModelerGraphicItem(QGraphicsItem): self.setFlag(QGraphicsItem.ItemSendsGeometryChanges, True) self.setZValue(1000) - if not isinstance(element, QgsProcessingModelAlgorithm.ModelOutput) and controls: + if not isinstance(element, QgsProcessingModelOutput) and controls: svg = QSvgRenderer(os.path.join(pluginPath, 'images', 'edit.svg')) picture = QPicture() painter = QPainter(picture) @@ -99,7 +102,7 @@ class ModelerGraphicItem(QGraphicsItem): self.removeElement) self.deleteButton.setParentItem(self) - if isinstance(element, QgsProcessingModelAlgorithm.ChildAlgorithm): + if isinstance(element, QgsProcessingModelChildAlgorithm): alg = element.algorithm() if [a for a in alg.parameterDefinitions() if not a.isDestination()]: pt = self.getLinkPointForParameter(-1) @@ -143,9 +146,9 @@ class ModelerGraphicItem(QGraphicsItem): font = QFont('Verdana', 8) font.setPixelSize(12) fm = QFontMetricsF(font) - unfolded = isinstance(self.element, QgsProcessingModelAlgorithm.ChildAlgorithm) and not self.element.parametersCollapsed() + unfolded = isinstance(self.element, QgsProcessingModelChildAlgorithm) and not self.element.parametersCollapsed() numParams = len([a for a in self.element.algorithm().parameterDefinitions() if not a.isDestination()]) if unfolded else 0 - unfolded = isinstance(self.element, QgsProcessingModelAlgorithm.ChildAlgorithm) and not self.element.outputsCollapsed() + unfolded = isinstance(self.element, QgsProcessingModelChildAlgorithm) and not self.element.outputsCollapsed() numOutputs = len(self.element.algorithm().outputDefinitions()) if unfolded else 0 hUp = fm.height() * 1.2 * (numParams + 2) @@ -160,14 +163,14 @@ class ModelerGraphicItem(QGraphicsItem): self.editElement() def contextMenuEvent(self, event): - if isinstance(self.element, QgsProcessingModelAlgorithm.ModelOutput): + if isinstance(self.element, QgsProcessingModelOutput): return popupmenu = QMenu() removeAction = popupmenu.addAction('Remove') removeAction.triggered.connect(self.removeElement) editAction = popupmenu.addAction('Edit') editAction.triggered.connect(self.editElement) - if isinstance(self.element, QgsProcessingModelAlgorithm.ChildAlgorithm): + if isinstance(self.element, QgsProcessingModelChildAlgorithm): if not self.element.isActive(): removeAction = popupmenu.addAction('Activate') removeAction.triggered.connect(self.activateAlgorithm) @@ -189,7 +192,7 @@ class ModelerGraphicItem(QGraphicsItem): 'Activate them them before trying to activate it.') def editElement(self): - if isinstance(self.element, QgsProcessingModelAlgorithm.ModelParameter): + if isinstance(self.element, QgsProcessingModelParameter): dlg = ModelerParameterDefinitionDialog(self.model, param=self.model.parameterDefinition(self.element.parameterName())) dlg.exec_() @@ -200,7 +203,7 @@ class ModelerGraphicItem(QGraphicsItem): self.model.addModelParameter(dlg.param, self.element) self.text = dlg.param.description() self.scene.dialog.repaintModel() - elif isinstance(self.element, QgsProcessingModelAlgorithm.ChildAlgorithm): + elif isinstance(self.element, QgsProcessingModelChildAlgorithm): dlg = None try: dlg = self.element.algorithm().getCustomModelerParametersDialog(self.model, self.element.childId()) @@ -227,7 +230,7 @@ class ModelerGraphicItem(QGraphicsItem): self.model.setChildAlgorithm(alg) def removeElement(self): - if isinstance(self.element, QgsProcessingModelAlgorithm.ModelParameter): + if isinstance(self.element, QgsProcessingModelParameter): if self.model.childAlgorithmsDependOnParameter(self.element.parameterName()): QMessageBox.warning(None, 'Could not remove input', 'Algorithms depend on the selected input.\n' @@ -240,7 +243,7 @@ class ModelerGraphicItem(QGraphicsItem): self.model.removeModelParameter(self.element.parameterName()) self.scene.dialog.haschanged = True self.scene.dialog.repaintModel() - elif isinstance(self.element, QgsProcessingModelAlgorithm.ChildAlgorithm): + elif isinstance(self.element, QgsProcessingModelChildAlgorithm): if not self.model.removeChildAlgorithm(self.element.childId()): QMessageBox.warning(None, 'Could not remove element', 'Other elements depend on the selected one.\n' @@ -270,11 +273,11 @@ class ModelerGraphicItem(QGraphicsItem): ModelerGraphicItem.BOX_WIDTH + 2, ModelerGraphicItem.BOX_HEIGHT + 2) - if isinstance(self.element, QgsProcessingModelAlgorithm.ModelParameter): + if isinstance(self.element, QgsProcessingModelParameter): color = QColor(238, 242, 131) stroke = QColor(234, 226, 118) selected = QColor(116, 113, 68) - elif isinstance(self.element, QgsProcessingModelAlgorithm.ChildAlgorithm): + elif isinstance(self.element, QgsProcessingModelChildAlgorithm): color = QColor(255, 255, 255) stroke = Qt.gray selected = QColor(50, 50, 50) @@ -293,7 +296,7 @@ class ModelerGraphicItem(QGraphicsItem): painter.setFont(font) painter.setPen(QPen(Qt.black)) text = self.getAdjustedText(self.text) - if isinstance(self.element, QgsProcessingModelAlgorithm.ChildAlgorithm) and not self.element.isActive(): + if isinstance(self.element, QgsProcessingModelChildAlgorithm) and not self.element.isActive(): painter.setPen(QPen(Qt.gray)) text = text + "\n(deactivated)" fm = QFontMetricsF(font) @@ -302,7 +305,7 @@ class ModelerGraphicItem(QGraphicsItem): pt = QPointF(-ModelerGraphicItem.BOX_WIDTH / 2 + 25, ModelerGraphicItem.BOX_HEIGHT / 2.0 - h + 1) painter.drawText(pt, text) painter.setPen(QPen(Qt.black)) - if isinstance(self.element, QgsProcessingModelAlgorithm.ChildAlgorithm): + if isinstance(self.element, QgsProcessingModelChildAlgorithm): h = -(fm.height() * 1.2) h = h - ModelerGraphicItem.BOX_HEIGHT / 2.0 + 5 pt = QPointF(-ModelerGraphicItem.BOX_WIDTH / 2 + 25, h) @@ -337,16 +340,16 @@ class ModelerGraphicItem(QGraphicsItem): def getLinkPointForParameter(self, paramIndex): offsetX = 25 - if isinstance(self.element, QgsProcessingModelAlgorithm.ChildAlgorithm) and self.element.parametersCollapsed(): + if isinstance(self.element, QgsProcessingModelChildAlgorithm) and self.element.parametersCollapsed(): paramIndex = -1 offsetX = 17 - if isinstance(self.element, QgsProcessingModelAlgorithm.ModelParameter): + if isinstance(self.element, QgsProcessingModelParameter): paramIndex = -1 offsetX = 0 font = QFont('Verdana', 8) font.setPixelSize(12) fm = QFontMetricsF(font) - if isinstance(self.element, QgsProcessingModelAlgorithm.ChildAlgorithm): + if isinstance(self.element, QgsProcessingModelChildAlgorithm): h = -(fm.height() * 1.2) * (paramIndex + 2) - fm.height() / 2.0 + 8 h = h - ModelerGraphicItem.BOX_HEIGHT / 2.0 else: @@ -354,7 +357,7 @@ class ModelerGraphicItem(QGraphicsItem): return QPointF(-ModelerGraphicItem.BOX_WIDTH / 2 + offsetX, h) def getLinkPointForOutput(self, outputIndex): - if isinstance(self.element, QgsProcessingModelAlgorithm.ChildAlgorithm) and self.element.algorithm().outputDefinitions(): + if isinstance(self.element, QgsProcessingModelChildAlgorithm) and self.element.algorithm().outputDefinitions(): outputIndex = (outputIndex if not self.element.outputsCollapsed() else -1) text = self.getAdjustedText(self.element.algorithm().outputDefinitions()[outputIndex].description()) font = QFont('Verdana', 8) @@ -377,11 +380,11 @@ class ModelerGraphicItem(QGraphicsItem): self.element.setPosition(self.pos()) # also need to update the model's stored component's position - if isinstance(self.element, QgsProcessingModelAlgorithm.ChildAlgorithm): + if isinstance(self.element, QgsProcessingModelChildAlgorithm): self.model.childAlgorithm(self.element.childId()).setPosition(self.pos()) - elif isinstance(self.element, QgsProcessingModelAlgorithm.ModelParameter): + elif isinstance(self.element, QgsProcessingModelParameter): self.model.parameterComponent(self.element.parameterName()).setPosition(self.pos()) - elif isinstance(self.element, QgsProcessingModelAlgorithm.ModelOutput): + elif isinstance(self.element, QgsProcessingModelOutput): self.model.childAlgorithm(self.element.childId()).modelOutput(self.element.name()).setPosition(self.pos()) return value diff --git a/python/plugins/processing/modeler/ModelerParametersDialog.py b/python/plugins/processing/modeler/ModelerParametersDialog.py index 2a9dd5edf53..cb13e4f7168 100644 --- a/python/plugins/processing/modeler/ModelerParametersDialog.py +++ b/python/plugins/processing/modeler/ModelerParametersDialog.py @@ -40,6 +40,9 @@ from qgis.core import (QgsProcessingParameterDefinition, QgsProcessingParameterPoint, QgsProcessingParameterExtent, QgsProcessingModelAlgorithm, + QgsProcessingModelOutput, + QgsProcessingModelChildAlgorithm, + QgsProcessingModelChildParameterSource, QgsProcessingParameterFeatureSink, QgsProcessingParameterRasterDestination, QgsProcessingParameterFileDestination, @@ -244,12 +247,12 @@ class ModelerParametersDialog(QDialog): [o.typeName() for o in outTypes if issubclass(o, QgsProcessingOutputDefinition)], dataTypes) def resolveValueDescription(self, value): - if isinstance(value, QgsProcessingModelAlgorithm.ChildParameterSource): - if value.source() == QgsProcessingModelAlgorithm.ChildParameterSource.StaticValue: + if isinstance(value, QgsProcessingModelChildParameterSource): + if value.source() == QgsProcessingModelChildParameterSource.StaticValue: return value.staticValue() - elif value.source() == QgsProcessingModelAlgorithm.ChildParameterSource.ModelParameter: + elif value.source() == QgsProcessingModelChildParameterSource.ModelParameter: return self.model.parameterDefinition(value.parameterName()).description() - elif value.source() == QgsProcessingModelAlgorithm.ChildParameterSource.ChildOutput: + elif value.source() == QgsProcessingModelChildParameterSource.ChildOutput: alg = self.model.childAlgorithm(value.outputChildId()) return self.tr("'{0}' from algorithm '{1}'").format( alg.algorithm().outputDefinition(value.outputName()).description(), alg.description()) @@ -273,7 +276,7 @@ class ModelerParametersDialog(QDialog): if value is None: value = param.defaultValue() - if isinstance(value, QgsProcessingModelAlgorithm.ChildParameterSource) and value.source() == QgsProcessingModelAlgorithm.ChildParameterSource.StaticValue: + if isinstance(value, QgsProcessingModelChildParameterSource) and value.source() == QgsProcessingModelChildParameterSource.StaticValue: value = value.staticValue() self.wrappers[param.name()].setValue(value) @@ -290,7 +293,7 @@ class ModelerParametersDialog(QDialog): self.dependenciesPanel.setSelectedItems(selected) def createAlgorithm(self): - alg = QgsProcessingModelAlgorithm.ChildAlgorithm(self._alg.id()) + alg = QgsProcessingModelChildAlgorithm(self._alg.id()) if not self.childId: alg.generateChildId(self.model) else: @@ -301,7 +304,7 @@ class ModelerParametersDialog(QDialog): continue val = self.wrappers[param.name()].value() if (isinstance(val, - QgsProcessingModelAlgorithm.ChildParameterSource) and val.source() == QgsProcessingModelAlgorithm.ChildParameterSource.StaticValue and not param.checkValueIsAcceptable( + QgsProcessingModelChildParameterSource) and val.source() == QgsProcessingModelChildParameterSource.StaticValue and not param.checkValueIsAcceptable( val.staticValue())) \ or (val is None and not param.flags() & QgsProcessingParameterDefinition.FlagOptional): self.bar.pushMessage("Error", "Wrong or missing value for parameter '%s'" % param.description(), @@ -309,19 +312,19 @@ class ModelerParametersDialog(QDialog): return None if val is None: continue - elif isinstance(val, QgsProcessingModelAlgorithm.ChildParameterSource): + elif isinstance(val, QgsProcessingModelChildParameterSource): alg.addParameterSources(param.name(), [val]) elif isinstance(val, list): alg.addParameterSources(param.name(), val) else: - alg.addParameterSources(param.name(), [QgsProcessingModelAlgorithm.ChildParameterSource.fromStaticValue(val)]) + alg.addParameterSources(param.name(), [QgsProcessingModelChildParameterSource.fromStaticValue(val)]) outputs = {} for dest in self._alg.destinationParameterDefinitions(): if not dest.flags() & QgsProcessingParameterDefinition.FlagHidden: name = str(self.valueItems[dest.name()].text()) if name.strip() != '' and name != ModelerParametersDialog.ENTER_NAME: - output = QgsProcessingModelAlgorithm.ModelOutput(name, name) + output = QgsProcessingModelOutput(name, name) output.setChildId(alg.childId()) output.setChildOutputName(dest.name()) outputs[name] = output diff --git a/python/plugins/processing/modeler/ModelerScene.py b/python/plugins/processing/modeler/ModelerScene.py index 2221a891cb2..fba5ae935dd 100644 --- a/python/plugins/processing/modeler/ModelerScene.py +++ b/python/plugins/processing/modeler/ModelerScene.py @@ -29,7 +29,7 @@ __revision__ = '$Format:%H$' from qgis.PyQt.QtCore import QPointF, Qt from qgis.PyQt.QtWidgets import QGraphicsItem, QGraphicsScene from qgis.core import (QgsProcessingParameterDefinition, - QgsProcessingModelAlgorithm, + QgsProcessingModelChildParameterSource, QgsExpression) from processing.modeler.ModelerGraphicItem import ModelerGraphicItem from processing.modeler.ModelerArrowItem import ModelerArrowItem @@ -69,17 +69,17 @@ class ModelerScene(QGraphicsScene): if isinstance(value, list): for v in value: items.extend(self.getItemsFromParamValue(v, child_id, context)) - elif isinstance(value, QgsProcessingModelAlgorithm.ChildParameterSource): - if value.source() == QgsProcessingModelAlgorithm.ChildParameterSource.ModelParameter: + elif isinstance(value, QgsProcessingModelChildParameterSource): + if value.source() == QgsProcessingModelChildParameterSource.ModelParameter: items.append((self.paramItems[value.parameterName()], 0)) - elif value.source() == QgsProcessingModelAlgorithm.ChildParameterSource.ChildOutput: + elif value.source() == QgsProcessingModelChildParameterSource.ChildOutput: outputs = self.model.childAlgorithm(value.outputChildId()).algorithm().outputDefinitions() for i, out in enumerate(outputs): if out.name() == value.outputName(): break if value.outputChildId() in self.algItems: items.append((self.algItems[value.outputChildId()], i)) - elif value.source() == QgsProcessingModelAlgorithm.ChildParameterSource.Expression: + elif value.source() == QgsProcessingModelChildParameterSource.Expression: variables = self.model.variablesForChildAlgorithm(child_id, context) exp = QgsExpression(value.expression()) for v in exp.referencedVariables(): diff --git a/python/plugins/processing/tests/ModelerTest.py b/python/plugins/processing/tests/ModelerTest.py index 09a835d89cd..02da7a27dd2 100644 --- a/python/plugins/processing/tests/ModelerTest.py +++ b/python/plugins/processing/tests/ModelerTest.py @@ -28,15 +28,12 @@ __revision__ = '$Format:%H$' from qgis.testing import start_app, unittest from qgis.core import (QgsProcessingModelAlgorithm, + QgsProcessingModelParameter, QgsProcessingParameterString, QgsProcessingParameterNumber, QgsProcessingParameterField, QgsProcessingParameterFile) from processing.modeler.ModelerParametersDialog import (ModelerParametersDialog) -from processing.core.parameters import (ParameterFile, - ParameterNumber, - ParameterString, - ParameterTableField) start_app() @@ -47,19 +44,19 @@ class ModelerTest(unittest.TestCase): m = QgsProcessingModelAlgorithm() - string_param_1 = QgsProcessingModelAlgorithm.ModelParameter('string') + string_param_1 = QgsProcessingModelParameter('string') m.addModelParameter(QgsProcessingParameterString('string'), string_param_1) - string_param_2 = QgsProcessingModelAlgorithm.ModelParameter('string2') + string_param_2 = QgsProcessingModelParameter('string2') m.addModelParameter(QgsProcessingParameterString('string2'), string_param_2) - num_param = QgsProcessingModelAlgorithm.ModelParameter('number') + num_param = QgsProcessingModelParameter('number') m.addModelParameter(QgsProcessingParameterNumber('number'), num_param) - table_field_param = QgsProcessingModelAlgorithm.ModelParameter('field') + table_field_param = QgsProcessingModelParameter('field') m.addModelParameter(QgsProcessingParameterField('field'), table_field_param) - file_param = QgsProcessingModelAlgorithm.ModelParameter('file') + file_param = QgsProcessingModelParameter('file') m.addModelParameter(QgsProcessingParameterFile('file'), file_param) dlg = ModelerParametersDialog(m, m) diff --git a/src/core/CMakeLists.txt b/src/core/CMakeLists.txt index 5181794b642..bd92bfc7cad 100755 --- a/src/core/CMakeLists.txt +++ b/src/core/CMakeLists.txt @@ -96,12 +96,17 @@ SET(QGIS_CORE_SRCS processing/qgsnativealgorithms.cpp processing/qgsprocessingalgorithm.cpp processing/qgsprocessingalgrunnertask.cpp - processing/qgsprocessingmodelalgorithm.cpp processing/qgsprocessingoutputs.cpp processing/qgsprocessingparameters.cpp processing/qgsprocessingprovider.cpp processing/qgsprocessingregistry.cpp processing/qgsprocessingutils.cpp + processing/models/qgsprocessingmodelalgorithm.cpp + processing/models/qgsprocessingmodelchildalgorithm.cpp + processing/models/qgsprocessingmodelchildparametersource.cpp + processing/models/qgsprocessingmodelcomponent.cpp + processing/models/qgsprocessingmodelparameter.cpp + processing/models/qgsprocessingmodeloutput.cpp providers/memory/qgsmemoryfeatureiterator.cpp providers/memory/qgsmemoryprovider.cpp @@ -925,10 +930,15 @@ SET(QGIS_CORE_HDRS processing/qgsprocessing.h processing/qgsprocessingalgorithm.h processing/qgsprocessingcontext.h - processing/qgsprocessingmodelalgorithm.h processing/qgsprocessingoutputs.h processing/qgsprocessingparameters.h processing/qgsprocessingutils.h + processing/models/qgsprocessingmodelalgorithm.h + processing/models/qgsprocessingmodelchildalgorithm.h + processing/models/qgsprocessingmodelchildparametersource.h + processing/models/qgsprocessingmodelcomponent.h + processing/models/qgsprocessingmodeloutput.h + processing/models/qgsprocessingmodelparameter.h providers/memory/qgsmemoryfeatureiterator.h providers/memory/qgsmemoryproviderutils.h @@ -1073,6 +1083,7 @@ INCLUDE_DIRECTORIES( metadata pal processing + processing/models providers providers/memory raster diff --git a/src/core/processing/qgsprocessingmodelalgorithm.cpp b/src/core/processing/models/qgsprocessingmodelalgorithm.cpp similarity index 60% rename from src/core/processing/qgsprocessingmodelalgorithm.cpp rename to src/core/processing/models/qgsprocessingmodelalgorithm.cpp index 8d8e0d07f4c..afcde6597bf 100644 --- a/src/core/processing/qgsprocessingmodelalgorithm.cpp +++ b/src/core/processing/models/qgsprocessingmodelalgorithm.cpp @@ -26,288 +26,6 @@ ///@cond NOT_STABLE -QgsProcessingModelAlgorithm::ChildAlgorithm::ChildAlgorithm( const QString &algorithmId ) - : mAlgorithmId( algorithmId ) -{ - -} - -const QgsProcessingAlgorithm *QgsProcessingModelAlgorithm::ChildAlgorithm::algorithm() const -{ - return QgsApplication::processingRegistry()->algorithmById( mAlgorithmId ); -} - -QString QgsProcessingModelAlgorithm::Component::description() const -{ - return mDescription; -} - -void QgsProcessingModelAlgorithm::Component::setDescription( const QString &description ) -{ - mDescription = description; -} - -QMap QgsProcessingModelAlgorithm::ChildAlgorithm::parameterSources() const -{ - return mParams; -} - -void QgsProcessingModelAlgorithm::ChildAlgorithm::setParameterSources( const QMap< QString, QgsProcessingModelAlgorithm::ChildParameterSources > ¶ms ) -{ - mParams = params; -} - -void QgsProcessingModelAlgorithm::ChildAlgorithm::addParameterSources( const QString &name, const ChildParameterSources &source ) -{ - mParams.insert( name, source ); -} - -bool QgsProcessingModelAlgorithm::ChildAlgorithm::isActive() const -{ - return mActive; -} - -void QgsProcessingModelAlgorithm::ChildAlgorithm::setActive( bool active ) -{ - mActive = active; -} - -QPointF QgsProcessingModelAlgorithm::Component::position() const -{ - return mPosition; -} - -void QgsProcessingModelAlgorithm::Component::setPosition( const QPointF &position ) -{ - mPosition = position; -} - -QgsProcessingModelAlgorithm::Component::Component( const QString &description ) - : mDescription( description ) -{} - -void QgsProcessingModelAlgorithm::Component::saveCommonProperties( QVariantMap &map ) const -{ - map.insert( QStringLiteral( "component_pos_x" ), mPosition.x() ); - map.insert( QStringLiteral( "component_pos_y" ), mPosition.y() ); - map.insert( QStringLiteral( "component_description" ), mDescription ); -} - -void QgsProcessingModelAlgorithm::Component::restoreCommonProperties( const QVariantMap &map ) -{ - QPointF pos; - pos.setX( map.value( QStringLiteral( "component_pos_x" ) ).toDouble() ); - pos.setY( map.value( QStringLiteral( "component_pos_y" ) ).toDouble() ); - mPosition = pos; - mDescription = map.value( QStringLiteral( "component_description" ) ).toString(); -} - -QStringList QgsProcessingModelAlgorithm::ChildAlgorithm::dependencies() const -{ - return mDependencies; -} - -void QgsProcessingModelAlgorithm::ChildAlgorithm::setDependencies( const QStringList &dependencies ) -{ - mDependencies = dependencies; -} - -bool QgsProcessingModelAlgorithm::ChildAlgorithm::outputsCollapsed() const -{ - return mOutputsCollapsed; -} - -void QgsProcessingModelAlgorithm::ChildAlgorithm::setOutputsCollapsed( bool outputsCollapsed ) -{ - mOutputsCollapsed = outputsCollapsed; -} - -QMap QgsProcessingModelAlgorithm::ChildAlgorithm::modelOutputs() const -{ - return mModelOutputs; -} - -QgsProcessingModelAlgorithm::ModelOutput &QgsProcessingModelAlgorithm::ChildAlgorithm::modelOutput( const QString &name ) -{ - return mModelOutputs[ name ]; -} - -void QgsProcessingModelAlgorithm::ChildAlgorithm::setModelOutputs( const QMap &modelOutputs ) -{ - mModelOutputs = modelOutputs; - QMap::iterator outputIt = mModelOutputs.begin(); - for ( ; outputIt != mModelOutputs.end(); ++outputIt ) - { - // make sure values are consistent - outputIt->setName( outputIt.key() ); - outputIt->setChildId( mId ); - } -} - -QVariant QgsProcessingModelAlgorithm::ChildAlgorithm::toVariant() const -{ - QVariantMap map; - map.insert( QStringLiteral( "id" ), mId ); - map.insert( QStringLiteral( "alg_id" ), mAlgorithmId ); - map.insert( QStringLiteral( "active" ), mActive ); - map.insert( QStringLiteral( "dependencies" ), mDependencies ); - map.insert( QStringLiteral( "parameters_collapsed" ), mParametersCollapsed ); - map.insert( QStringLiteral( "outputs_collapsed" ), mOutputsCollapsed ); - - saveCommonProperties( map ); - - QVariantMap paramMap; - QMap< QString, QgsProcessingModelAlgorithm::ChildParameterSources >::const_iterator paramIt = mParams.constBegin(); - for ( ; paramIt != mParams.constEnd(); ++paramIt ) - { - QVariantList sources; - Q_FOREACH ( const ChildParameterSource &source, paramIt.value() ) - { - sources << source.toVariant(); - } - paramMap.insert( paramIt.key(), sources ); - } - map.insert( "params", paramMap ); - - QVariantMap outputMap; - QMap< QString, QgsProcessingModelAlgorithm::ModelOutput >::const_iterator outputIt = mModelOutputs.constBegin(); - for ( ; outputIt != mModelOutputs.constEnd(); ++outputIt ) - { - outputMap.insert( outputIt.key(), outputIt.value().toVariant() ); - } - map.insert( "outputs", outputMap ); - - return map; -} - -bool QgsProcessingModelAlgorithm::ChildAlgorithm::loadVariant( const QVariant &child ) -{ - QVariantMap map = child.toMap(); - - mId = map.value( QStringLiteral( "id" ) ).toString(); - mAlgorithmId = map.value( QStringLiteral( "alg_id" ) ).toString(); - mActive = map.value( QStringLiteral( "active" ) ).toBool(); - mDependencies = map.value( QStringLiteral( "dependencies" ) ).toStringList(); - mParametersCollapsed = map.value( QStringLiteral( "parameters_collapsed" ) ).toBool(); - mOutputsCollapsed = map.value( QStringLiteral( "outputs_collapsed" ) ).toBool(); - - restoreCommonProperties( map ); - - mParams.clear(); - QVariantMap paramMap = map.value( QStringLiteral( "params" ) ).toMap(); - QVariantMap::const_iterator paramIt = paramMap.constBegin(); - for ( ; paramIt != paramMap.constEnd(); ++paramIt ) - { - ChildParameterSources sources; - Q_FOREACH ( const QVariant &sourceVar, paramIt->toList() ) - { - ChildParameterSource param; - if ( !param.loadVariant( sourceVar.toMap() ) ) - return false; - sources << param; - } - mParams.insert( paramIt.key(), sources ); - } - - mModelOutputs.clear(); - QVariantMap outputMap = map.value( QStringLiteral( "outputs" ) ).toMap(); - QVariantMap::const_iterator outputIt = outputMap.constBegin(); - for ( ; outputIt != outputMap.constEnd(); ++outputIt ) - { - ModelOutput output; - if ( !output.loadVariant( outputIt.value().toMap() ) ) - return false; - - mModelOutputs.insert( outputIt.key(), output ); - } - - return true; -} - -QString QgsProcessingModelAlgorithm::ChildAlgorithm::asPythonCode() const -{ - QStringList lines; - - if ( !algorithm() ) - return QString(); - - QStringList paramParts; - QMap< QString, QgsProcessingModelAlgorithm::ChildParameterSources >::const_iterator paramIt = mParams.constBegin(); - for ( ; paramIt != mParams.constEnd(); ++paramIt ) - { - QStringList sourceParts; - Q_FOREACH ( const ChildParameterSource &source, paramIt.value() ) - { - QString part = source.asPythonCode(); - if ( !part.isEmpty() ) - sourceParts << QStringLiteral( "'%1':%2" ).arg( paramIt.key(), part ); - } - if ( sourceParts.count() == 1 ) - paramParts << sourceParts.at( 0 ); - else - paramParts << QStringLiteral( "[%1]" ).arg( paramParts.join( ',' ) ); - } - - lines << QStringLiteral( "outputs['%1']=processing.run('%2', {%3}, context=context, feedback=feedback)" ).arg( mId, mAlgorithmId, paramParts.join( ',' ) ); - - QMap< QString, QgsProcessingModelAlgorithm::ModelOutput >::const_iterator outputIt = mModelOutputs.constBegin(); - for ( ; outputIt != mModelOutputs.constEnd(); ++outputIt ) - { - lines << QStringLiteral( "results['%1']=outputs['%2']['%3']" ).arg( outputIt.key(), mId, outputIt.value().childOutputName() ); - } - - return lines.join( '\n' ); -} - -bool QgsProcessingModelAlgorithm::ChildAlgorithm::parametersCollapsed() const -{ - return mParametersCollapsed; -} - -void QgsProcessingModelAlgorithm::ChildAlgorithm::setParametersCollapsed( bool parametersCollapsed ) -{ - mParametersCollapsed = parametersCollapsed; -} - -QString QgsProcessingModelAlgorithm::ChildAlgorithm::childId() const -{ - return mId; -} - -void QgsProcessingModelAlgorithm::ChildAlgorithm::setChildId( const QString &id ) -{ - mId = id; -} - -void QgsProcessingModelAlgorithm::ChildAlgorithm::generateChildId( const QgsProcessingModelAlgorithm &model ) -{ - int i = 1; - QString id; - while ( true ) - { - id = QStringLiteral( "%1_%2" ).arg( mAlgorithmId ).arg( i ); - if ( !model.childAlgorithms().contains( id ) ) - break; - i++; - } - mId = id; -} - -QString QgsProcessingModelAlgorithm::ChildAlgorithm::algorithmId() const -{ - return mAlgorithmId; -} - -void QgsProcessingModelAlgorithm::ChildAlgorithm::setAlgorithmId( const QString &algorithmId ) -{ - mAlgorithmId = algorithmId; -} - - -// -// QgsProcessingModelAlgorithm -// - QgsProcessingModelAlgorithm::QgsProcessingModelAlgorithm( const QString &name, const QString &group ) : QgsProcessingAlgorithm() , mModelName( name.isEmpty() ? QObject::tr( "model" ) : name ) @@ -351,7 +69,7 @@ QString QgsProcessingModelAlgorithm::helpUrl() const return QgsProcessingUtils::formatHelpMapAsHtml( mHelpContent, this ); } -QVariantMap QgsProcessingModelAlgorithm::parametersForChildAlgorithm( const ChildAlgorithm &child, const QVariantMap &modelParameters, const QVariantMap &results, const QgsExpressionContext &expressionContext ) const +QVariantMap QgsProcessingModelAlgorithm::parametersForChildAlgorithm( const QgsProcessingModelChildAlgorithm &child, const QVariantMap &modelParameters, const QVariantMap &results, const QgsExpressionContext &expressionContext ) const { QVariantMap childParams; Q_FOREACH ( const QgsProcessingParameterDefinition *def, child.algorithm()->parameterDefinitions() ) @@ -364,29 +82,29 @@ QVariantMap QgsProcessingModelAlgorithm::parametersForChildAlgorithm( const Chil if ( !child.parameterSources().contains( def->name() ) ) continue; // use default value - ChildParameterSources paramSources = child.parameterSources().value( def->name() ); + QgsProcessingModelChildParameterSources paramSources = child.parameterSources().value( def->name() ); QVariantList paramParts; - Q_FOREACH ( const ChildParameterSource &source, paramSources ) + Q_FOREACH ( const QgsProcessingModelChildParameterSource &source, paramSources ) { switch ( source.source() ) { - case ChildParameterSource::StaticValue: + case QgsProcessingModelChildParameterSource::StaticValue: paramParts << source.staticValue(); break; - case ChildParameterSource::ModelParameter: + case QgsProcessingModelChildParameterSource::ModelParameter: paramParts << modelParameters.value( source.parameterName() ); break; - case ChildParameterSource::ChildOutput: + case QgsProcessingModelChildParameterSource::ChildOutput: { QVariantMap linkedChildResults = results.value( source.outputChildId() ).toMap(); paramParts << linkedChildResults.value( source.outputName() ); break; } - case ChildParameterSource::Expression: + case QgsProcessingModelChildParameterSource::Expression: { QgsExpression exp( source.expression() ); paramParts << exp.evaluate( &expressionContext ); @@ -406,8 +124,8 @@ QVariantMap QgsProcessingModelAlgorithm::parametersForChildAlgorithm( const Chil // is destination linked to one of the final outputs from this model? bool isFinalOutput = false; - QMap outputs = child.modelOutputs(); - QMap::const_iterator outputIt = outputs.constBegin(); + QMap outputs = child.modelOutputs(); + QMap::const_iterator outputIt = outputs.constBegin(); for ( ; outputIt != outputs.constEnd(); ++outputIt ) { if ( outputIt->childOutputName() == destParam->name() ) @@ -454,20 +172,20 @@ QVariantMap QgsProcessingModelAlgorithm::parametersForChildAlgorithm( const Chil bool QgsProcessingModelAlgorithm::childOutputIsRequired( const QString &childId, const QString &outputName ) const { // look through all child algs - QMap< QString, ChildAlgorithm >::const_iterator childIt = mChildAlgorithms.constBegin(); + QMap< QString, QgsProcessingModelChildAlgorithm >::const_iterator childIt = mChildAlgorithms.constBegin(); for ( ; childIt != mChildAlgorithms.constEnd(); ++childIt ) { if ( childIt->childId() == childId || !childIt->isActive() ) continue; // look through all sources for child - QMap candidateChildParams = childIt->parameterSources(); - QMap::const_iterator childParamIt = candidateChildParams.constBegin(); + QMap candidateChildParams = childIt->parameterSources(); + QMap::const_iterator childParamIt = candidateChildParams.constBegin(); for ( ; childParamIt != candidateChildParams.constEnd(); ++childParamIt ) { - Q_FOREACH ( const ChildParameterSource &source, childParamIt.value() ) + Q_FOREACH ( const QgsProcessingModelChildParameterSource &source, childParamIt.value() ) { - if ( source.source() == ChildParameterSource::ChildOutput + if ( source.source() == QgsProcessingModelChildParameterSource::ChildOutput && source.outputChildId() == childId && source.outputName() == outputName ) { @@ -482,7 +200,7 @@ bool QgsProcessingModelAlgorithm::childOutputIsRequired( const QString &childId, QVariantMap QgsProcessingModelAlgorithm::processAlgorithm( const QVariantMap ¶meters, QgsProcessingContext &context, QgsProcessingFeedback *feedback ) { QSet< QString > toExecute; - QMap< QString, ChildAlgorithm >::const_iterator childIt = mChildAlgorithms.constBegin(); + QMap< QString, QgsProcessingModelChildAlgorithm >::const_iterator childIt = mChildAlgorithms.constBegin(); for ( ; childIt != mChildAlgorithms.constEnd(); ++childIt ) { if ( childIt->isActive() && childIt->algorithm() ) @@ -522,7 +240,7 @@ QVariantMap QgsProcessingModelAlgorithm::processAlgorithm( const QVariantMap &pa executedAlg = true; feedback->pushDebugInfo( QObject::tr( "Prepare algorithm: %1" ).arg( childId ) ); - const ChildAlgorithm &child = mChildAlgorithms[ childId ]; + const QgsProcessingModelChildAlgorithm &child = mChildAlgorithms[ childId ]; QgsExpressionContext expContext = baseContext; expContext << QgsExpressionContextUtils::processingAlgorithmScope( child.algorithm(), parameters, context ) @@ -550,8 +268,8 @@ QVariantMap QgsProcessingModelAlgorithm::processAlgorithm( const QVariantMap &pa // look through child alg's outputs to determine whether any of these should be copied // to the final model outputs - QMap outputs = child.modelOutputs(); - QMap::const_iterator outputIt = outputs.constBegin(); + QMap outputs = child.modelOutputs(); + QMap::const_iterator outputIt = outputs.constBegin(); for ( ; outputIt != outputs.constEnd(); ++outputIt ) { finalResults.insert( childId + ':' + outputIt->name(), results.value( outputIt->childOutputName() ) ); @@ -582,7 +300,7 @@ QString QgsProcessingModelAlgorithm::asPythonCode() const QStringList lines; lines << QStringLiteral( "##%1=name" ).arg( name() ); - QMap< QString, ModelParameter >::const_iterator paramIt = mParameterComponents.constBegin(); + QMap< QString, QgsProcessingModelParameter >::const_iterator paramIt = mParameterComponents.constBegin(); for ( ; paramIt != mParameterComponents.constEnd(); ++paramIt ) { QString name = paramIt.value().parameterName(); @@ -600,15 +318,15 @@ QString QgsProcessingModelAlgorithm::asPythonCode() const return n; }; - QMap< QString, ChildAlgorithm >::const_iterator childIt = mChildAlgorithms.constBegin(); + QMap< QString, QgsProcessingModelChildAlgorithm >::const_iterator childIt = mChildAlgorithms.constBegin(); for ( ; childIt != mChildAlgorithms.constEnd(); ++childIt ) { if ( !childIt->isActive() || !childIt->algorithm() ) continue; // look through all outputs for child - QMap outputs = childIt->modelOutputs(); - QMap::const_iterator outputIt = outputs.constBegin(); + QMap outputs = childIt->modelOutputs(); + QMap::const_iterator outputIt = outputs.constBegin(); for ( ; outputIt != outputs.constEnd(); ++outputIt ) { const QgsProcessingOutputDefinition *output = childIt->algorithm()->outputDefinition( outputIt->childOutputName() ); @@ -651,7 +369,7 @@ QString QgsProcessingModelAlgorithm::asPythonCode() const executedAlg = true; - const ChildAlgorithm &child = mChildAlgorithms[ childId ]; + const QgsProcessingModelChildAlgorithm &child = mChildAlgorithms[ childId ]; lines << child.asPythonCode(); executed.insert( childId ); @@ -674,30 +392,30 @@ QMap QgsProcessingMode }; // "static"/single value sources - ChildParameterSources sources = availableSourcesForChild( childId, QStringList() << QgsProcessingParameterNumber::typeName() - << QgsProcessingParameterBoolean::typeName() - << QgsProcessingParameterExpression::typeName() - << QgsProcessingParameterField::typeName() - << QgsProcessingParameterString::typeName(), - QStringList() << QgsProcessingOutputNumber::typeName() - << QgsProcessingOutputString::typeName() ); - Q_FOREACH ( const ChildParameterSource &source, sources ) + QgsProcessingModelChildParameterSources sources = availableSourcesForChild( childId, QStringList() << QgsProcessingParameterNumber::typeName() + << QgsProcessingParameterBoolean::typeName() + << QgsProcessingParameterExpression::typeName() + << QgsProcessingParameterField::typeName() + << QgsProcessingParameterString::typeName(), + QStringList() << QgsProcessingOutputNumber::typeName() + << QgsProcessingOutputString::typeName() ); + Q_FOREACH ( const QgsProcessingModelChildParameterSource &source, sources ) { QString name; QVariant value; QString description; switch ( source.source() ) { - case ChildParameterSource::ModelParameter: + case QgsProcessingModelChildParameterSource::ModelParameter: { name = source.parameterName(); value = modelParameters.value( source.parameterName() ); description = parameterDefinition( source.parameterName() )->description(); break; } - case ChildParameterSource::ChildOutput: + case QgsProcessingModelChildParameterSource::ChildOutput: { - const ChildAlgorithm &child = mChildAlgorithms.value( source.outputChildId() ); + const QgsProcessingModelChildAlgorithm &child = mChildAlgorithms.value( source.outputChildId() ); name = QStringLiteral( "%1_%2" ).arg( child.description().isEmpty() ? source.outputChildId() : child.description(), source.outputName() ); if ( const QgsProcessingAlgorithm *alg = child.algorithm() ) @@ -709,8 +427,8 @@ QMap QgsProcessingMode break; } - case ChildParameterSource::Expression: - case ChildParameterSource::StaticValue: + case QgsProcessingModelChildParameterSource::Expression: + case QgsProcessingModelChildParameterSource::StaticValue: continue; }; variables.insert( safeName( name ), VariableDefinition( value, source, description ) ); @@ -723,7 +441,7 @@ QMap QgsProcessingMode QStringList() << QgsProcessingOutputVectorLayer::typeName() << QgsProcessingOutputRasterLayer::typeName() ); - Q_FOREACH ( const ChildParameterSource &source, sources ) + Q_FOREACH ( const QgsProcessingModelChildParameterSource &source, sources ) { QString name; QVariant value; @@ -731,16 +449,16 @@ QMap QgsProcessingMode switch ( source.source() ) { - case ChildParameterSource::ModelParameter: + case QgsProcessingModelChildParameterSource::ModelParameter: { name = source.parameterName(); value = modelParameters.value( source.parameterName() ); description = parameterDefinition( source.parameterName() )->description(); break; } - case ChildParameterSource::ChildOutput: + case QgsProcessingModelChildParameterSource::ChildOutput: { - const ChildAlgorithm &child = mChildAlgorithms.value( source.outputChildId() ); + const QgsProcessingModelChildAlgorithm &child = mChildAlgorithms.value( source.outputChildId() ); name = QStringLiteral( "%1_%2" ).arg( child.description().isEmpty() ? source.outputChildId() : child.description(), source.outputName() ); value = results.value( source.outputChildId() ).toMap().value( source.outputName() ); @@ -752,8 +470,8 @@ QMap QgsProcessingMode break; } - case ChildParameterSource::Expression: - case ChildParameterSource::StaticValue: + case QgsProcessingModelChildParameterSource::Expression: + case QgsProcessingModelChildParameterSource::StaticValue: continue; }; @@ -772,7 +490,7 @@ QMap QgsProcessingMode sources = availableSourcesForChild( childId, QStringList() << QgsProcessingParameterFeatureSource::typeName() ); - Q_FOREACH ( const ChildParameterSource &source, sources ) + Q_FOREACH ( const QgsProcessingModelChildParameterSource &source, sources ) { QString name; QVariant value; @@ -780,16 +498,16 @@ QMap QgsProcessingMode switch ( source.source() ) { - case ChildParameterSource::ModelParameter: + case QgsProcessingModelChildParameterSource::ModelParameter: { name = source.parameterName(); value = modelParameters.value( source.parameterName() ); description = parameterDefinition( source.parameterName() )->description(); break; } - case ChildParameterSource::ChildOutput: + case QgsProcessingModelChildParameterSource::ChildOutput: { - const ChildAlgorithm &child = mChildAlgorithms.value( source.outputChildId() ); + const QgsProcessingModelChildAlgorithm &child = mChildAlgorithms.value( source.outputChildId() ); name = QStringLiteral( "%1_%2" ).arg( child.description().isEmpty() ? source.outputChildId() : child.description(), source.outputName() ); value = results.value( source.outputChildId() ).toMap().value( source.outputName() ); @@ -801,8 +519,8 @@ QMap QgsProcessingMode break; } - case ChildParameterSource::Expression: - case ChildParameterSource::StaticValue: + case QgsProcessingModelChildParameterSource::Expression: + case QgsProcessingModelChildParameterSource::StaticValue: continue; }; @@ -844,12 +562,12 @@ QgsExpressionContextScope *QgsProcessingModelAlgorithm::createExpressionContextS return scope.release(); } -QgsProcessingModelAlgorithm::ChildParameterSources QgsProcessingModelAlgorithm::availableSourcesForChild( const QString &childId, const QStringList ¶meterTypes, const QStringList &outputTypes, const QList dataTypes ) const +QgsProcessingModelChildParameterSources QgsProcessingModelAlgorithm::availableSourcesForChild( const QString &childId, const QStringList ¶meterTypes, const QStringList &outputTypes, const QList dataTypes ) const { - ChildParameterSources sources; + QgsProcessingModelChildParameterSources sources; // first look through model parameters - QMap< QString, ModelParameter >::const_iterator paramIt = mParameterComponents.constBegin(); + QMap< QString, QgsProcessingModelParameter >::const_iterator paramIt = mParameterComponents.constBegin(); for ( ; paramIt != mParameterComponents.constEnd(); ++paramIt ) { const QgsProcessingParameterDefinition *def = parameterDefinition( paramIt->parameterName() ); @@ -884,7 +602,7 @@ QgsProcessingModelAlgorithm::ChildParameterSources QgsProcessingModelAlgorithm:: continue; } } - sources << ChildParameterSource::fromModelParameter( paramIt->parameterName() ); + sources << QgsProcessingModelChildParameterSource::fromModelParameter( paramIt->parameterName() ); } } @@ -895,7 +613,7 @@ QgsProcessingModelAlgorithm::ChildParameterSources QgsProcessingModelAlgorithm:: dependents << childId; } - QMap< QString, ChildAlgorithm >::const_iterator childIt = mChildAlgorithms.constBegin(); + QMap< QString, QgsProcessingModelChildAlgorithm >::const_iterator childIt = mChildAlgorithms.constBegin(); for ( ; childIt != mChildAlgorithms.constEnd(); ++childIt ) { if ( dependents.contains( childIt->childId() ) ) @@ -920,7 +638,7 @@ QgsProcessingModelAlgorithm::ChildParameterSources QgsProcessingModelAlgorithm:: } } } - sources << ChildParameterSource::fromChildOutput( childIt->childId(), out->name() ); + sources << QgsProcessingModelChildParameterSource::fromChildOutput( childIt->childId(), out->name() ); } } } @@ -948,26 +666,26 @@ void QgsProcessingModelAlgorithm::setGroup( const QString &group ) mModelGroup = group; } -QMap QgsProcessingModelAlgorithm::childAlgorithms() const +QMap QgsProcessingModelAlgorithm::childAlgorithms() const { return mChildAlgorithms; } -void QgsProcessingModelAlgorithm::setParameterComponents( const QMap ¶meterComponents ) +void QgsProcessingModelAlgorithm::setParameterComponents( const QMap ¶meterComponents ) { mParameterComponents = parameterComponents; } -void QgsProcessingModelAlgorithm::setParameterComponent( const QgsProcessingModelAlgorithm::ModelParameter &component ) +void QgsProcessingModelAlgorithm::setParameterComponent( const QgsProcessingModelParameter &component ) { mParameterComponents.insert( component.parameterName(), component ); } -QgsProcessingModelAlgorithm::ModelParameter &QgsProcessingModelAlgorithm::parameterComponent( const QString &name ) +QgsProcessingModelParameter &QgsProcessingModelAlgorithm::parameterComponent( const QString &name ) { if ( !mParameterComponents.contains( name ) ) { - QgsProcessingModelAlgorithm::ModelParameter &component = mParameterComponents[ name ]; + QgsProcessingModelParameter &component = mParameterComponents[ name ]; component.setParameterName( name ); return component; } @@ -992,11 +710,11 @@ void QgsProcessingModelAlgorithm::updateDestinationParameters() mOutputs.clear(); // rebuild - QMap< QString, ChildAlgorithm >::const_iterator childIt = mChildAlgorithms.constBegin(); + QMap< QString, QgsProcessingModelChildAlgorithm >::const_iterator childIt = mChildAlgorithms.constBegin(); for ( ; childIt != mChildAlgorithms.constEnd(); ++childIt ) { - QMap outputs = childIt->modelOutputs(); - QMap::const_iterator outputIt = outputs.constBegin(); + QMap outputs = childIt->modelOutputs(); + QMap::const_iterator outputIt = outputs.constBegin(); for ( ; outputIt != outputs.constEnd(); ++outputIt ) { if ( !childIt->isActive() || !childIt->algorithm() ) @@ -1032,7 +750,7 @@ QVariant QgsProcessingModelAlgorithm::toVariant() const map.insert( QStringLiteral( "help" ), mHelpContent ); QVariantMap childMap; - QMap< QString, ChildAlgorithm >::const_iterator childIt = mChildAlgorithms.constBegin(); + QMap< QString, QgsProcessingModelChildAlgorithm >::const_iterator childIt = mChildAlgorithms.constBegin(); for ( ; childIt != mChildAlgorithms.constEnd(); ++childIt ) { childMap.insert( childIt.key(), childIt.value().toVariant() ); @@ -1040,7 +758,7 @@ QVariant QgsProcessingModelAlgorithm::toVariant() const map.insert( "children", childMap ); QVariantMap paramMap; - QMap< QString, ModelParameter >::const_iterator paramIt = mParameterComponents.constBegin(); + QMap< QString, QgsProcessingModelParameter >::const_iterator paramIt = mParameterComponents.constBegin(); for ( ; paramIt != mParameterComponents.constEnd(); ++paramIt ) { paramMap.insert( paramIt.key(), paramIt.value().toVariant() ); @@ -1070,7 +788,7 @@ bool QgsProcessingModelAlgorithm::loadVariant( const QVariant &model ) QVariantMap::const_iterator childIt = childMap.constBegin(); for ( ; childIt != childMap.constEnd(); ++childIt ) { - ChildAlgorithm child; + QgsProcessingModelChildAlgorithm child; if ( !child.loadVariant( childIt.value() ) ) return false; @@ -1082,7 +800,7 @@ bool QgsProcessingModelAlgorithm::loadVariant( const QVariant &model ) QVariantMap::const_iterator paramIt = paramMap.constBegin(); for ( ; paramIt != paramMap.constEnd(); ++paramIt ) { - ModelParameter param; + QgsProcessingModelParameter param; if ( !param.loadVariant( paramIt.value().toMap() ) ) return false; @@ -1141,19 +859,19 @@ bool QgsProcessingModelAlgorithm::fromFile( const QString &path ) return loadVariant( props ); } -void QgsProcessingModelAlgorithm::setChildAlgorithms( const QMap &childAlgorithms ) +void QgsProcessingModelAlgorithm::setChildAlgorithms( const QMap &childAlgorithms ) { mChildAlgorithms = childAlgorithms; updateDestinationParameters(); } -void QgsProcessingModelAlgorithm::setChildAlgorithm( const QgsProcessingModelAlgorithm::ChildAlgorithm &algorithm ) +void QgsProcessingModelAlgorithm::setChildAlgorithm( const QgsProcessingModelChildAlgorithm &algorithm ) { mChildAlgorithms.insert( algorithm.childId(), algorithm ); updateDestinationParameters(); } -QString QgsProcessingModelAlgorithm::addChildAlgorithm( ChildAlgorithm &algorithm ) +QString QgsProcessingModelAlgorithm::addChildAlgorithm( QgsProcessingModelChildAlgorithm &algorithm ) { if ( algorithm.childId().isEmpty() || mChildAlgorithms.contains( algorithm.childId() ) ) algorithm.generateChildId( *this ); @@ -1163,7 +881,7 @@ QString QgsProcessingModelAlgorithm::addChildAlgorithm( ChildAlgorithm &algorith return algorithm.childId(); } -QgsProcessingModelAlgorithm::ChildAlgorithm &QgsProcessingModelAlgorithm::childAlgorithm( const QString &childId ) +QgsProcessingModelChildAlgorithm &QgsProcessingModelAlgorithm::childAlgorithm( const QString &childId ) { return mChildAlgorithms[ childId ]; } @@ -1200,7 +918,7 @@ bool QgsProcessingModelAlgorithm::activateChildAlgorithm( const QString &id ) return true; } -void QgsProcessingModelAlgorithm::addModelParameter( QgsProcessingParameterDefinition *definition, const QgsProcessingModelAlgorithm::ModelParameter &component ) +void QgsProcessingModelAlgorithm::addModelParameter( QgsProcessingParameterDefinition *definition, const QgsProcessingModelParameter &component ) { addParameter( definition ); mParameterComponents.insert( definition->name(), component ); @@ -1220,17 +938,17 @@ void QgsProcessingModelAlgorithm::removeModelParameter( const QString &name ) bool QgsProcessingModelAlgorithm::childAlgorithmsDependOnParameter( const QString &name ) const { - QMap< QString, ChildAlgorithm >::const_iterator childIt = mChildAlgorithms.constBegin(); + QMap< QString, QgsProcessingModelChildAlgorithm >::const_iterator childIt = mChildAlgorithms.constBegin(); for ( ; childIt != mChildAlgorithms.constEnd(); ++childIt ) { // check whether child requires this parameter - QMap childParams = childIt->parameterSources(); - QMap::const_iterator paramIt = childParams.constBegin(); + QMap childParams = childIt->parameterSources(); + QMap::const_iterator paramIt = childParams.constBegin(); for ( ; paramIt != childParams.constEnd(); ++paramIt ) { - Q_FOREACH ( const ChildParameterSource &source, paramIt.value() ) + Q_FOREACH ( const QgsProcessingModelChildParameterSource &source, paramIt.value() ) { - if ( source.source() == ChildParameterSource::ModelParameter + if ( source.source() == QgsProcessingModelChildParameterSource::ModelParameter && source.parameterName() == name ) { return true; @@ -1254,14 +972,14 @@ bool QgsProcessingModelAlgorithm::otherParametersDependOnParameter( const QStrin return false; } -QMap QgsProcessingModelAlgorithm::parameterComponents() const +QMap QgsProcessingModelAlgorithm::parameterComponents() const { return mParameterComponents; } void QgsProcessingModelAlgorithm::dependentChildAlgorithmsRecursive( const QString &childId, QSet &depends ) const { - QMap< QString, ChildAlgorithm >::const_iterator childIt = mChildAlgorithms.constBegin(); + QMap< QString, QgsProcessingModelChildAlgorithm >::const_iterator childIt = mChildAlgorithms.constBegin(); for ( ; childIt != mChildAlgorithms.constEnd(); ++childIt ) { if ( depends.contains( childIt->childId() ) ) @@ -1276,13 +994,13 @@ void QgsProcessingModelAlgorithm::dependentChildAlgorithmsRecursive( const QStri } // check whether child requires any outputs from the target alg - QMap childParams = childIt->parameterSources(); - QMap::const_iterator paramIt = childParams.constBegin(); + QMap childParams = childIt->parameterSources(); + QMap::const_iterator paramIt = childParams.constBegin(); for ( ; paramIt != childParams.constEnd(); ++paramIt ) { - Q_FOREACH ( const ChildParameterSource &source, paramIt.value() ) + Q_FOREACH ( const QgsProcessingModelChildParameterSource &source, paramIt.value() ) { - if ( source.source() == ChildParameterSource::ChildOutput + if ( source.source() == QgsProcessingModelChildParameterSource::ChildOutput && source.outputChildId() == childId ) { depends.insert( childIt->childId() ); @@ -1313,7 +1031,7 @@ QSet QgsProcessingModelAlgorithm::dependentChildAlgorithms( const QStri void QgsProcessingModelAlgorithm::dependsOnChildAlgorithmsRecursive( const QString &childId, QSet< QString > &depends ) const { - ChildAlgorithm alg = mChildAlgorithms.value( childId ); + QgsProcessingModelChildAlgorithm alg = mChildAlgorithms.value( childId ); // add direct dependencies Q_FOREACH ( const QString &c, alg.dependencies() ) @@ -1326,13 +1044,13 @@ void QgsProcessingModelAlgorithm::dependsOnChildAlgorithmsRecursive( const QStri } // check through parameter dependencies - QMap childParams = alg.parameterSources(); - QMap::const_iterator paramIt = childParams.constBegin(); + QMap childParams = alg.parameterSources(); + QMap::const_iterator paramIt = childParams.constBegin(); for ( ; paramIt != childParams.constEnd(); ++paramIt ) { - Q_FOREACH ( const ChildParameterSource &source, paramIt.value() ) + Q_FOREACH ( const QgsProcessingModelChildParameterSource &source, paramIt.value() ) { - if ( source.source() == ChildParameterSource::ChildOutput && !depends.contains( source.outputChildId() ) ) + if ( source.source() == QgsProcessingModelChildParameterSource::ChildOutput && !depends.contains( source.outputChildId() ) ) { depends.insert( source.outputChildId() ); dependsOnChildAlgorithmsRecursive( source.outputChildId(), depends ); @@ -1359,7 +1077,7 @@ QSet< QString > QgsProcessingModelAlgorithm::dependsOnChildAlgorithms( const QSt bool QgsProcessingModelAlgorithm::canExecute( QString *errorMessage ) const { - QMap< QString, ChildAlgorithm >::const_iterator childIt = mChildAlgorithms.constBegin(); + QMap< QString, QgsProcessingModelChildAlgorithm >::const_iterator childIt = mChildAlgorithms.constBegin(); for ( ; childIt != mChildAlgorithms.constEnd(); ++childIt ) { if ( !childIt->algorithm() ) @@ -1390,177 +1108,4 @@ QgsProcessingModelAlgorithm *QgsProcessingModelAlgorithm::create() const return alg; } -bool QgsProcessingModelAlgorithm::ChildParameterSource::operator==( const QgsProcessingModelAlgorithm::ChildParameterSource &other ) const -{ - if ( mSource != other.mSource ) - return false; - - switch ( mSource ) - { - case StaticValue: - return mStaticValue == other.mStaticValue; - case ChildOutput: - return mChildId == other.mChildId && mOutputName == other.mOutputName; - case ModelParameter: - return mParameterName == other.mParameterName; - case Expression: - return mExpression == other.mExpression; - } - return false; -} - -QgsProcessingModelAlgorithm::ChildParameterSource QgsProcessingModelAlgorithm::ChildParameterSource::fromStaticValue( const QVariant &value ) -{ - ChildParameterSource src; - src.mSource = StaticValue; - src.mStaticValue = value; - return src; -} - -QgsProcessingModelAlgorithm::ChildParameterSource QgsProcessingModelAlgorithm::ChildParameterSource::fromModelParameter( const QString ¶meterName ) -{ - ChildParameterSource src; - src.mSource = ModelParameter; - src.mParameterName = parameterName; - return src; -} - -QgsProcessingModelAlgorithm::ChildParameterSource QgsProcessingModelAlgorithm::ChildParameterSource::fromChildOutput( const QString &childId, const QString &outputName ) -{ - ChildParameterSource src; - src.mSource = ChildOutput; - src.mChildId = childId; - src.mOutputName = outputName; - return src; -} - -QgsProcessingModelAlgorithm::ChildParameterSource QgsProcessingModelAlgorithm::ChildParameterSource::fromExpression( const QString &expression ) -{ - ChildParameterSource src; - src.mSource = Expression; - src.mExpression = expression; - return src; -} - -QgsProcessingModelAlgorithm::ChildParameterSource::Source QgsProcessingModelAlgorithm::ChildParameterSource::source() const -{ - return mSource; -} - -QVariant QgsProcessingModelAlgorithm::ChildParameterSource::toVariant() const -{ - QVariantMap map; - map.insert( QStringLiteral( "source" ), mSource ); - switch ( mSource ) - { - case ModelParameter: - map.insert( QStringLiteral( "parameter_name" ), mParameterName ); - break; - - case ChildOutput: - map.insert( QStringLiteral( "child_id" ), mChildId ); - map.insert( QStringLiteral( "output_name" ), mOutputName ); - break; - - case StaticValue: - map.insert( QStringLiteral( "static_value" ), mStaticValue ); - break; - - case Expression: - map.insert( QStringLiteral( "expression" ), mExpression ); - break; - } - return map; -} - -bool QgsProcessingModelAlgorithm::ChildParameterSource::loadVariant( const QVariantMap &map ) -{ - mSource = static_cast< Source >( map.value( QStringLiteral( "source" ) ).toInt() ); - switch ( mSource ) - { - case ModelParameter: - mParameterName = map.value( QStringLiteral( "parameter_name" ) ).toString(); - break; - - case ChildOutput: - mChildId = map.value( QStringLiteral( "child_id" ) ).toString(); - mOutputName = map.value( QStringLiteral( "output_name" ) ).toString(); - break; - - case StaticValue: - mStaticValue = map.value( QStringLiteral( "static_value" ) ); - break; - - case Expression: - mExpression = map.value( QStringLiteral( "expression" ) ).toString(); - break; - } - return true; -} - -QString QgsProcessingModelAlgorithm::ChildParameterSource::asPythonCode() const -{ - switch ( mSource ) - { - case ModelParameter: - return QStringLiteral( "parameters['%1']" ).arg( mParameterName ); - - case ChildOutput: - return QStringLiteral( "outputs['%1']['%2']" ).arg( mChildId, mOutputName ); - - case StaticValue: - return mStaticValue.toString(); - - case Expression: - return QStringLiteral( "QgsExpression('%1').evaluate()" ).arg( mExpression ); - } - return QString(); -} - -QgsProcessingModelAlgorithm::ModelOutput::ModelOutput( const QString &name, const QString &description ) - : QgsProcessingModelAlgorithm::Component( description ) - , mName( name ) -{} - -QVariant QgsProcessingModelAlgorithm::ModelOutput::toVariant() const -{ - QVariantMap map; - map.insert( QStringLiteral( "name" ), mName ); - map.insert( QStringLiteral( "child_id" ), mChildId ); - map.insert( QStringLiteral( "output_name" ), mOutputName ); - saveCommonProperties( map ); - return map; -} - -bool QgsProcessingModelAlgorithm::ModelOutput::loadVariant( const QVariantMap &map ) -{ - mName = map.value( QStringLiteral( "name" ) ).toString(); - mChildId = map.value( QStringLiteral( "child_id" ) ).toString(); - mOutputName = map.value( QStringLiteral( "output_name" ) ).toString(); - restoreCommonProperties( map ); - return true; -} - -QgsProcessingModelAlgorithm::ModelParameter::ModelParameter( const QString ¶meterName ) - : QgsProcessingModelAlgorithm::Component() - , mParameterName( parameterName ) -{ - -} - -QVariant QgsProcessingModelAlgorithm::ModelParameter::toVariant() const -{ - QVariantMap map; - map.insert( QStringLiteral( "name" ), mParameterName ); - saveCommonProperties( map ); - return map; -} - -bool QgsProcessingModelAlgorithm::ModelParameter::loadVariant( const QVariantMap &map ) -{ - mParameterName = map.value( QStringLiteral( "name" ) ).toString(); - restoreCommonProperties( map ); - return true; -} - ///@endcond diff --git a/src/core/processing/models/qgsprocessingmodelalgorithm.h b/src/core/processing/models/qgsprocessingmodelalgorithm.h new file mode 100644 index 00000000000..c39b975c224 --- /dev/null +++ b/src/core/processing/models/qgsprocessingmodelalgorithm.h @@ -0,0 +1,405 @@ +/*************************************************************************** + qgsprocessingmodelalgorithm.h + ----------------------------- + begin : June 2017 + copyright : (C) 2017 by Nyall Dawson + email : nyall dot dawson at gmail dot com + ***************************************************************************/ + +/*************************************************************************** + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + ***************************************************************************/ + +#ifndef QGSPROCESSINGMODELALGORITHM_H +#define QGSPROCESSINGMODELALGORITHM_H + +#include "qgis_core.h" +#include "qgis.h" +#include "qgsprocessingmodelchildalgorithm.h" +#include "qgsprocessingalgorithm.h" +#include "qgsprocessingmodelparameter.h" +#include "qgsprocessingmodelchildparametersource.h" + +///@cond NOT_STABLE + +/** + * \class QgsProcessingModelAlgorithm + * \ingroup core + * Model based algorithm with processing. + * \since QGIS 3.0 + */ +class CORE_EXPORT QgsProcessingModelAlgorithm : public QgsProcessingAlgorithm +{ + public: + + /** + * Constructor for QgsProcessingModelAlgorithm. + */ + QgsProcessingModelAlgorithm( const QString &name = QString(), const QString &group = QString() ); + + QString name() const override; + QString displayName() const override; + QString group() const override; + QIcon icon() const override; + QString svgIconPath() const override; + QString shortHelpString() const override; + QString helpUrl() const override; + + bool canExecute( QString *errorMessage SIP_OUT = nullptr ) const override; + QString asPythonCommand( const QVariantMap ¶meters, QgsProcessingContext &context ) const override; + QgsProcessingModelAlgorithm *create() const override SIP_FACTORY; + + /** + * Sets the model \a name. + * \see name() + */ + void setName( const QString &name ); + + /** + * Sets the model \a group. + * \see group() + */ + void setGroup( const QString &group ); + + /** + * Returns the map of child algorithms contained in the model. The keys + * are the child algorithm ids (see QgsProcessingModelAlgorithm::ChildAlgorithm::childId()). + * \see childAlgorithm() + * \see setChildAlgorithms() + * \see addChildAlgorithm() + */ + QMap childAlgorithms() const; + + /** + * Sets the map of child algorithms contained in the model. The keys + * are the child algorithm ids (see QgsProcessingModelAlgorithm::ChildAlgorithm::childId()). + * All existing child algorithms will be replaced. + * \see childAlgorithms() + * \see childAlgorithm() + * \see setChildAlgorithm() + * \see addChildAlgorithm() + */ + void setChildAlgorithms( const QMap &childAlgorithms ); + + /** + * Sets the child \a algorithm within the model. If a child algorithm already + * exists in the model with the same child ID then that algorithm will be replaced. + * \see addChildAlgorithm() + * \see setChildAlgorithms() + */ + void setChildAlgorithm( const QgsProcessingModelChildAlgorithm &algorithm ); + + /** + * Adds a new child \a algorithm to the model. If a child algorithm already exists + * in the model with the same child ID then \a algorithm will be assigned a new + * autogenerated unique ID. + * The assigned child ID will be returned. + * \see childAlgorithms() + * \see childAlgorithm() + * \see setChildAlgorithm() + * \see setChildAlgorithms() + */ + QString addChildAlgorithm( QgsProcessingModelChildAlgorithm &algorithm ); + + /** + * Returns the child algorithm with matching \a id. If no child algorithm exists with + * this ID a new algorithm will be added to the model and returned. + * \see addChildAlgorithm() + * \see childAlgorithms() + */ + QgsProcessingModelChildAlgorithm &childAlgorithm( const QString &id ); + + /** + * Attempts to remove the child algorithm with matching \a id. + * Returns true if the algorithm could be removed, or false + * if the algorithm could not be removed (e.g. due to other + * child algorithms depending on it). + * \see deactivateChildAlgorithm() + */ + bool removeChildAlgorithm( const QString &id ); + + /** + * Deactivates the child algorithm with matching \a id. + * All other child algorithms which depend on the child + * algorithm will also be deactivated. + * \see removeChildAlgorithm() + * \see activateChildAlgorithm() + */ + void deactivateChildAlgorithm( const QString &id ); + + /** + * Attempts to activate the child algorithm with matching \a id. + * If any child algorithms on which the child depends are not active, + * then the child will not be activated and false will be returned. + * \see deactivateChildAlgorithm() + */ + bool activateChildAlgorithm( const QString &id ); + + /** + * Returns a list of the child algorithm IDs depending on the child + * algorithm with the specified \a childId. + * \see dependsOnChildAlgorithms() + */ + QSet< QString > dependentChildAlgorithms( const QString &childId ) const; + + /** + * Returns a list of the child algorithm IDs on which the child + * algorithm with the specified \a childId depends upon. + * \see dependentChildAlgorithms() + */ + QSet< QString > dependsOnChildAlgorithms( const QString &childId ) const; + + /** + * Adds a new parameter to the model, with the specified \a definition and graphical \a component. + * Ownership of \a definition is transferred to the model. + * \see updateModelParameter() + * \see removeModelParameter() + */ + void addModelParameter( QgsProcessingParameterDefinition *definition SIP_TRANSFER, const QgsProcessingModelParameter &component ); + + /** + * Replaces the definition of an existing parameter (by parameter name) with a new \a definition. Ownership of + * \a definition is transferred to the model, and any existing parameter is deleted. + * \see addModelParameter() + * \see removeModelParameter() + */ + void updateModelParameter( QgsProcessingParameterDefinition *definition SIP_TRANSFER ); + + /** + * Removes an existing model parameter by \a name. The definition of the matching parameter + * is deleted. + * \see addModelParameter() + * \see updateModelParameter() + */ + void removeModelParameter( const QString &name ); + + /** + * Returns true if any child algorithms depend on the model parameter + * with the specified \a name. + * \see otherParametersDependOnParameter() + */ + bool childAlgorithmsDependOnParameter( const QString &name ) const; + + /** + * Returns true if any other model parameters depend on the parameter + * with the specified \a name (e.g. field parameters where \a name + * is the parent layer parameter). + * \see childAlgorithmsDependOnParameter() + */ + bool otherParametersDependOnParameter( const QString &name ) const; + + /** + * Returns the map of parameter components used by the model. The keys + * should match the algorithm's parameter names (see parameterDefinitions() ). + * \see setParameterComponent() + * \see parameterComponent() + */ + QMap parameterComponents() const; + + /** + * Sets the map of parameter components used by the model. The keys + * should match the algorithm's parameter names (see parameterDefinitions() ). + * All existing parameter components will be replaced. + * \see parameterComponents() + * \see setParameterComponent() + * \see parameterComponent() + */ + void setParameterComponents( const QMap ¶meterComponents ); + + /** + * Sets a parameter \a component for the model. If a parameter component already + * exists in the model with the same parameter name then that component will be replaced. + * \see parameterComponents() + * \see setParameterComponents() + * \see parameterComponent() + */ + void setParameterComponent( const QgsProcessingModelParameter &component ); + + /** + * Returns the parameter component with matching \a name. If no parameter component exists with + * this name a new component will be added to the model and returned. + * \see parameterComponents() + * \see setParameterComponents() + * \see setParameterComponent() + */ + QgsProcessingModelParameter ¶meterComponent( const QString &name ); + + /** + * Updates the model's parameter definitions to include all relevant destination + * parameters as required by child algorithm ModelOutputs. + * Must be called whenever child algorithm ModelOutputs are altered. + */ + void updateDestinationParameters(); + + /** + * Writes the model to a file, at the specified \a path. + * \see fromFile() + */ + bool toFile( const QString &path ) const; + + /** + * Reads the model from a file, at the specified \a path. + * \see toFile() + */ + bool fromFile( const QString &path ); + + /** + * Returns the model's help contents (a free-form map of values describing the algorithm's + * use and metadata). + * \see setHelpContent() + */ + QVariantMap &helpContent() { return mHelpContent; } + + /** + * Returns the model's help contents (a free-form map of values describing the algorithm's + * use and metadata). + * \see setHelpContent() + */ + SIP_SKIP QVariantMap helpContent() const; + + /** + * Sets the model's help \a contents (a free-form map of values describing the algorithm's + * use and metadata). + * \see helpContent() + */ + void setHelpContent( const QVariantMap &contents ); + + /** + * Returns the source file path for the model, if available. + * \see setSourceFilePath() + */ + QString sourceFilePath() const; + + /** + * Sets the source file \a path for the model, if available. + * \see sourceFilePath() + */ + void setSourceFilePath( const QString &path ); + + /** + * Attempts to convert the model to executable Python code. + */ + QString asPythonCode() const; + + /** + * Returns a list of possible sources which can be used for the parameters for a child + * algorithm in the model. Returned sources are those which match either one of the + * specified \a parameterTypes (see QgsProcessingParameterDefinition::type() ) or + * on of the specified \a outputTypes (see QgsProcessingOutputDefinition::type() ). + * If specified, an optional list of \a dataTypes can be used to filter the returned + * sources to those with compatible data types for the parameter/outputs. + */ + QList< QgsProcessingModelChildParameterSource > availableSourcesForChild( const QString &childId, const QStringList ¶meterTypes = QStringList(), + const QStringList &outputTypes = QStringList(), const QList< int > dataTypes = QList< int >() ) const; + + /** + * Definition of a expression context variable available during model execution. + * \since QGIS 3.0 + * \ingroup core + */ + class CORE_EXPORT VariableDefinition + { + public: + + /** + * Constructor for a new VariableDefinition with the specified \a value and original + * parameter \a source, and \a description. + */ + VariableDefinition( const QVariant &value = QVariant(), const QgsProcessingModelChildParameterSource &source = QgsProcessingModelChildParameterSource::fromStaticValue( QVariant() ), const QString &description = QString() ) + : value( value ) + , source( source ) + , description( description ) + {} + + //! Value of variable + QVariant value; + + //! Original source of variable's value + QgsProcessingModelChildParameterSource source; + + //! Translated description of variable + QString description; + }; + + /** + * Returns a map of variable name to variable definition for expression context variables which are available + * for use by child algorithm during model execution. + * + * The child algorithm \a childId and processing \a context + * are manadatory. If \a modelParameters and \a results are not specified, then only the variable names and sources + * will be returned, but all variable values will be null. This can be used to determine in advance which variables + * will be available for a specific child algorithm, e.g. for use in expression builder widgets. + * + * In order to calculate the actual variable value, the input model \a modelParameters and already executed child + * algorithm \a results must be passed. + * \see createExpressionContextScopeForChildAlgorithm() + */ + QMap< QString, QgsProcessingModelAlgorithm::VariableDefinition > variablesForChildAlgorithm( const QString &childId, QgsProcessingContext &context, const QVariantMap &modelParameters = QVariantMap(), + const QVariantMap &results = QVariantMap() ) const; + + /** + * Creates a new expression context scope for a child algorithm within the model. + * \see variablesForChildAlgorithm() + */ + QgsExpressionContextScope *createExpressionContextScopeForChildAlgorithm( const QString &childId, QgsProcessingContext &context, const QVariantMap &modelParameters = QVariantMap(), + const QVariantMap &results = QVariantMap() ) const SIP_FACTORY; + + protected: + + QVariantMap processAlgorithm( const QVariantMap ¶meters, QgsProcessingContext &context, QgsProcessingFeedback *feedback ) override; + + private: + + QString mModelName; + QString mModelGroup; + + QMap< QString, QgsProcessingModelChildAlgorithm > mChildAlgorithms; + + //! Map of parameter name to model parameter component + QMap< QString, QgsProcessingModelParameter > mParameterComponents; + + QVariantMap mHelpContent; + + //! Model source file + QString mSourceFile; + + QVariantMap mResults; + + void dependsOnChildAlgorithmsRecursive( const QString &childId, QSet &depends ) const; + void dependentChildAlgorithmsRecursive( const QString &childId, QSet &depends ) const; + + QVariantMap parametersForChildAlgorithm( const QgsProcessingModelChildAlgorithm &child, const QVariantMap &modelParameters, const QVariantMap &results, const QgsExpressionContext &expressionContext ) const; + + /** + * Returns true if an output from a child algorithm is required elsewhere in + * the model. + */ + bool childOutputIsRequired( const QString &childId, const QString &outputName ) const; + + /** + * Saves this model to a QVariantMap, wrapped in a QVariant. + * You can use QgsXmlUtils::writeVariant to save it to an XML document. + * + * \see loadVariant() + */ + QVariant toVariant() const; + + /** + * Loads this model from a QVariantMap, wrapped in a QVariant. + * You can use QgsXmlUtils::readVariant to load it from an XML document. + * + * \see toVariant() + */ + bool loadVariant( const QVariant &model ); + + friend class TestQgsProcessing; +}; + +///@endcond + +#endif // QGSPROCESSINGMODELALGORITHM_H diff --git a/src/core/processing/models/qgsprocessingmodelchildalgorithm.cpp b/src/core/processing/models/qgsprocessingmodelchildalgorithm.cpp new file mode 100644 index 00000000000..99d7659089a --- /dev/null +++ b/src/core/processing/models/qgsprocessingmodelchildalgorithm.cpp @@ -0,0 +1,181 @@ +/*************************************************************************** + qgsprocessingmodelchildalgorithm.cpp + ------------------------------------ + begin : June 2017 + copyright : (C) 2017 by Nyall Dawson + email : nyall dot dawson at gmail dot com + ***************************************************************************/ + +/*************************************************************************** + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + ***************************************************************************/ + +#include "qgsprocessingmodelchildalgorithm.h" +#include "qgsapplication.h" +#include "qgsprocessingregistry.h" +#include "qgsprocessingmodelalgorithm.h" + +///@cond NOT_STABLE + +QgsProcessingModelChildAlgorithm::QgsProcessingModelChildAlgorithm( const QString &algorithmId ) + : mAlgorithmId( algorithmId ) +{ + +} + +const QgsProcessingAlgorithm *QgsProcessingModelChildAlgorithm::algorithm() const +{ + return QgsApplication::processingRegistry()->algorithmById( mAlgorithmId ); +} + +void QgsProcessingModelChildAlgorithm::setModelOutputs( const QMap &modelOutputs ) +{ + mModelOutputs = modelOutputs; + QMap::iterator outputIt = mModelOutputs.begin(); + for ( ; outputIt != mModelOutputs.end(); ++outputIt ) + { + // make sure values are consistent + outputIt->setName( outputIt.key() ); + outputIt->setChildId( mId ); + } +} + +QVariant QgsProcessingModelChildAlgorithm::toVariant() const +{ + QVariantMap map; + map.insert( QStringLiteral( "id" ), mId ); + map.insert( QStringLiteral( "alg_id" ), mAlgorithmId ); + map.insert( QStringLiteral( "active" ), mActive ); + map.insert( QStringLiteral( "dependencies" ), mDependencies ); + map.insert( QStringLiteral( "parameters_collapsed" ), mParametersCollapsed ); + map.insert( QStringLiteral( "outputs_collapsed" ), mOutputsCollapsed ); + + saveCommonProperties( map ); + + QVariantMap paramMap; + QMap< QString, QgsProcessingModelChildParameterSources >::const_iterator paramIt = mParams.constBegin(); + for ( ; paramIt != mParams.constEnd(); ++paramIt ) + { + QVariantList sources; + Q_FOREACH ( const QgsProcessingModelChildParameterSource &source, paramIt.value() ) + { + sources << source.toVariant(); + } + paramMap.insert( paramIt.key(), sources ); + } + map.insert( "params", paramMap ); + + QVariantMap outputMap; + QMap< QString, QgsProcessingModelOutput >::const_iterator outputIt = mModelOutputs.constBegin(); + for ( ; outputIt != mModelOutputs.constEnd(); ++outputIt ) + { + outputMap.insert( outputIt.key(), outputIt.value().toVariant() ); + } + map.insert( "outputs", outputMap ); + + return map; +} + +bool QgsProcessingModelChildAlgorithm::loadVariant( const QVariant &child ) +{ + QVariantMap map = child.toMap(); + + mId = map.value( QStringLiteral( "id" ) ).toString(); + mAlgorithmId = map.value( QStringLiteral( "alg_id" ) ).toString(); + mActive = map.value( QStringLiteral( "active" ) ).toBool(); + mDependencies = map.value( QStringLiteral( "dependencies" ) ).toStringList(); + mParametersCollapsed = map.value( QStringLiteral( "parameters_collapsed" ) ).toBool(); + mOutputsCollapsed = map.value( QStringLiteral( "outputs_collapsed" ) ).toBool(); + + restoreCommonProperties( map ); + + mParams.clear(); + QVariantMap paramMap = map.value( QStringLiteral( "params" ) ).toMap(); + QVariantMap::const_iterator paramIt = paramMap.constBegin(); + for ( ; paramIt != paramMap.constEnd(); ++paramIt ) + { + QgsProcessingModelChildParameterSources sources; + Q_FOREACH ( const QVariant &sourceVar, paramIt->toList() ) + { + QgsProcessingModelChildParameterSource param; + if ( !param.loadVariant( sourceVar.toMap() ) ) + return false; + sources << param; + } + mParams.insert( paramIt.key(), sources ); + } + + mModelOutputs.clear(); + QVariantMap outputMap = map.value( QStringLiteral( "outputs" ) ).toMap(); + QVariantMap::const_iterator outputIt = outputMap.constBegin(); + for ( ; outputIt != outputMap.constEnd(); ++outputIt ) + { + QgsProcessingModelOutput output; + if ( !output.loadVariant( outputIt.value().toMap() ) ) + return false; + + mModelOutputs.insert( outputIt.key(), output ); + } + + return true; +} + +QString QgsProcessingModelChildAlgorithm::asPythonCode() const +{ + QStringList lines; + + if ( !algorithm() ) + return QString(); + + QStringList paramParts; + QMap< QString, QgsProcessingModelChildParameterSources >::const_iterator paramIt = mParams.constBegin(); + for ( ; paramIt != mParams.constEnd(); ++paramIt ) + { + QStringList sourceParts; + Q_FOREACH ( const QgsProcessingModelChildParameterSource &source, paramIt.value() ) + { + QString part = source.asPythonCode(); + if ( !part.isEmpty() ) + sourceParts << QStringLiteral( "'%1':%2" ).arg( paramIt.key(), part ); + } + if ( sourceParts.count() == 1 ) + paramParts << sourceParts.at( 0 ); + else + paramParts << QStringLiteral( "[%1]" ).arg( paramParts.join( ',' ) ); + } + + lines << QStringLiteral( "outputs['%1']=processing.run('%2', {%3}, context=context, feedback=feedback)" ).arg( mId, mAlgorithmId, paramParts.join( ',' ) ); + + QMap< QString, QgsProcessingModelOutput >::const_iterator outputIt = mModelOutputs.constBegin(); + for ( ; outputIt != mModelOutputs.constEnd(); ++outputIt ) + { + lines << QStringLiteral( "results['%1']=outputs['%2']['%3']" ).arg( outputIt.key(), mId, outputIt.value().childOutputName() ); + } + + return lines.join( '\n' ); +} + + + + + +void QgsProcessingModelChildAlgorithm::generateChildId( const QgsProcessingModelAlgorithm &model ) +{ + int i = 1; + QString id; + while ( true ) + { + id = QStringLiteral( "%1_%2" ).arg( mAlgorithmId ).arg( i ); + if ( !model.childAlgorithms().contains( id ) ) + break; + i++; + } + mId = id; +} + +///@endcond diff --git a/src/core/processing/models/qgsprocessingmodelchildalgorithm.h b/src/core/processing/models/qgsprocessingmodelchildalgorithm.h new file mode 100644 index 00000000000..95cc5083bc4 --- /dev/null +++ b/src/core/processing/models/qgsprocessingmodelchildalgorithm.h @@ -0,0 +1,254 @@ +/*************************************************************************** + qgsprocessingmodelchildalgorithm.h + ---------------------------------- + begin : June 2017 + copyright : (C) 2017 by Nyall Dawson + email : nyall dot dawson at gmail dot com + ***************************************************************************/ + +/*************************************************************************** + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + ***************************************************************************/ + +#ifndef QGSPROCESSINGMODELCHILDALGORITHM_H +#define QGSPROCESSINGMODELCHILDALGORITHM_H + +#include "qgis_core.h" +#include "qgis.h" +#include "qgsprocessingmodelcomponent.h" +#include "qgsprocessingmodelchildparametersource.h" +#include "qgsprocessingmodeloutput.h" + +class QgsProcessingModelAlgorithm; +class QgsProcessingAlgorithm; + +///@cond NOT_STABLE + +/** + * Child algorithm representing a single component of a QgsProcessingModelAlgorithm. + * \since QGIS 3.0 + * \ingroup core + */ +class CORE_EXPORT QgsProcessingModelChildAlgorithm : public QgsProcessingModelComponent +{ + public: + + /** + * Constructor for QgsProcessingModelChildAlgorithm. The \a algorithmId parameter + * should be set to a QgsProcessingAlgorithm algorithm ID. + */ + QgsProcessingModelChildAlgorithm( const QString &algorithmId = QString() ); + + /** + * Returns the child algorithm's unique ID string, used the identify + * this child algorithm within its parent model. + * \see setChildId() + * \see generateChildId() + */ + QString childId() const { return mId; } + + /** + * Sets the child algorithm's unique \a id string, used the identify + * this child algorithm within its parent model. + * \see childId() + * \see generateChildId() + */ + void setChildId( const QString &id ) { mId = id; } + + /** + * Automatically generates a unique childId() for the algorithm, + * avoiding child IDs which are already present in \a model. + * \see childId() + * \see setChildId() + */ + void generateChildId( const QgsProcessingModelAlgorithm &model ); + + /** + * Returns the underlying child algorithm's ID. + * \see algorithm() + * \see setAlgorithmId() + */ + QString algorithmId() const { return mAlgorithmId; } + + /** + * Sets the underlying child algorithm's ID. This + * should be set to an existing QgsProcessingAlgorithm algorithm ID. + * \see algorithm() + * \see algorithmId() + */ + void setAlgorithmId( const QString &algorithmId ) { mAlgorithmId = algorithmId; } + + /** + * Returns the underlying child algorithm, or a nullptr + * if a matching algorithm is not available. + * \see algorithmId() + */ + const QgsProcessingAlgorithm *algorithm() const; + + /** + * Returns a map of parameter sources. The keys are the child algorithm + * parameter names, the values are the sources for that parameter. + * \see setParameterSources() + * \see addParameterSources() + */ + QMap< QString, QList< QgsProcessingModelChildParameterSource > > parameterSources() const { return mParams; } + + /** + * Sets the map of parameter \a sources. The keys are the child algorithm + * parameter names, the values are the sources for that parameter. + * \see parameterSources() + * \see addParameterSources() + */ + void setParameterSources( const QMap< QString, QList< QgsProcessingModelChildParameterSource > > &sources ) { mParams = sources; } + + /** + * Adds a parameter source. The \a name argument should match + * one of the child algorithm's parameter names, and the \a sources + * argument is used to set the sources for that parameter. + * + * Any existing parameter sources with matching name will be replaced. + * \see parameterSources() + * \see setParameterSources() + */ + void addParameterSources( const QString &name, const QList< QgsProcessingModelChildParameterSource > &source ) { mParams.insert( name, source ); } + + /** + * Returns true if the child algorithm is active. + * \see setActive() + */ + bool isActive() const { return mActive; } + + /** + * Sets whether the child algorithm is active. + * \see isActive() + */ + void setActive( bool active ) { mActive = active; } + + /** + * Returns the list of child algorithms from the parent model on which this + * algorithm is dependent. The returned list contains the id() of the + * dependent algorithms. + * \see setDependencies() + */ + QStringList dependencies() const { return mDependencies; } + + /** + * Sets the list of child algorithms from the parent model on which this + * algorithm is dependent. The list should contain the id() of the + * dependent algorithms. + * \see dependencies() + */ + void setDependencies( const QStringList &dependencies ) { mDependencies = dependencies; } + + /** + * Returns true if the list of parameters for this algorithm should be collapsed + * in the graphical modeller. + * \see setParametersCollapsed() + * \see outputsCollapsed() + */ + bool parametersCollapsed() const { return mParametersCollapsed; } + + /** + * Sets whether the list of parameters for this algorithm should be collapsed + * in the graphical modeller. + * \see parametersCollapsed() + * \see setOutputsCollapsed() + */ + void setParametersCollapsed( bool collapsed ) { mParametersCollapsed = collapsed; } + + /** + * Returns true if the list of outputs for this algorithm should be collapsed + * in the graphical modeller. + * \see setParametersCollapsed() + * \see parametersCollapsed() + */ + bool outputsCollapsed() const { return mOutputsCollapsed; } + + /** + * Sets whether the list of outputs for this algorithm should be collapsed + * in the graphical modeller. + * \see outputsCollapsed() + * \see setParametersCollapsed() + */ + void setOutputsCollapsed( bool collapsed ) { mOutputsCollapsed = collapsed; } + + /** + * Returns the map of final model outputs which are generated by this child algorithm. + * The keys are the output names from this child algorithm. Only outputs which are + * part of the final outputs from the model are included in this map. + * \see setModelOutputs() + * \see modelOutput() + */ + QMap modelOutputs() const { return mModelOutputs; } + + /** + * Returns the final model output with matching \a name. If no output + * exists with the name, a new one will be created and returned. + * + * If child model outputs are altered by this method, QgsProcessingModelAlgorithm::updateDestinationParameters() + * must be called on the parent model. + * + * \see modelOutputs() + * \see setModelOutputs() + */ + QgsProcessingModelOutput &modelOutput( const QString &name ) { return mModelOutputs[ name ]; } + + /** + * Sets the map of final model \a outputs which are generated by this child algorithm. + * Only outputs which are part of the final outputs from the model should be included in this map. + * + * If child model outputs are altered by this method, QgsProcessingModelAlgorithm::updateDestinationParameters() + * must be called on the parent model. + * + * \see modelOutputs() + */ + void setModelOutputs( const QMap &outputs ); + + /** + * Saves this child to a QVariant. + * \see loadVariant() + */ + QVariant toVariant() const; + + /** + * Loads this child from a QVariant. + * \see toVariant() + */ + bool loadVariant( const QVariant &child ); + + /** + * Attempts to convert the child to executable Python code. + */ + QString asPythonCode() const; + + private: + + QString mId; + + QString mAlgorithmId; + + //! A map of parameter sources. Keys are algorithm parameter names. + QMap< QString, QgsProcessingModelChildParameterSources > mParams; + + //! A map of ModelOutput for final model outputs generated by this child algorithm. Keys are output names from the child algorithm. + QMap< QString, QgsProcessingModelOutput > mModelOutputs; + + bool mActive = true; + + //! List of child algorithms from the parent model on which this algorithm is dependent + QStringList mDependencies; + + //! Whether list of parameters should be collapsed in the graphical modeller + bool mParametersCollapsed = true; + //! Whether list of outputs should be collapsed in the graphical modeller + bool mOutputsCollapsed = true; +}; + +///@endcond + +#endif // QGSPROCESSINGMODELCHILDALGORITHM_H diff --git a/src/core/processing/models/qgsprocessingmodelchildparametersource.cpp b/src/core/processing/models/qgsprocessingmodelchildparametersource.cpp new file mode 100644 index 00000000000..5bb6ae2379d --- /dev/null +++ b/src/core/processing/models/qgsprocessingmodelchildparametersource.cpp @@ -0,0 +1,149 @@ +/*************************************************************************** + qgsprocessingmodelchildparametersource.cpp + ------------------------------------------ + begin : June 2017 + copyright : (C) 2017 by Nyall Dawson + email : nyall dot dawson at gmail dot com + ***************************************************************************/ + +/*************************************************************************** + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + ***************************************************************************/ + +#include "qgsprocessingmodelchildparametersource.h" + +///@cond NOT_STABLE + +bool QgsProcessingModelChildParameterSource::operator==( const QgsProcessingModelChildParameterSource &other ) const +{ + if ( mSource != other.mSource ) + return false; + + switch ( mSource ) + { + case StaticValue: + return mStaticValue == other.mStaticValue; + case ChildOutput: + return mChildId == other.mChildId && mOutputName == other.mOutputName; + case ModelParameter: + return mParameterName == other.mParameterName; + case Expression: + return mExpression == other.mExpression; + } + return false; +} + +QgsProcessingModelChildParameterSource QgsProcessingModelChildParameterSource::fromStaticValue( const QVariant &value ) +{ + QgsProcessingModelChildParameterSource src; + src.mSource = StaticValue; + src.mStaticValue = value; + return src; +} + +QgsProcessingModelChildParameterSource QgsProcessingModelChildParameterSource::fromModelParameter( const QString ¶meterName ) +{ + QgsProcessingModelChildParameterSource src; + src.mSource = ModelParameter; + src.mParameterName = parameterName; + return src; +} + +QgsProcessingModelChildParameterSource QgsProcessingModelChildParameterSource::fromChildOutput( const QString &childId, const QString &outputName ) +{ + QgsProcessingModelChildParameterSource src; + src.mSource = ChildOutput; + src.mChildId = childId; + src.mOutputName = outputName; + return src; +} + +QgsProcessingModelChildParameterSource QgsProcessingModelChildParameterSource::fromExpression( const QString &expression ) +{ + QgsProcessingModelChildParameterSource src; + src.mSource = Expression; + src.mExpression = expression; + return src; +} + +QgsProcessingModelChildParameterSource::Source QgsProcessingModelChildParameterSource::source() const +{ + return mSource; +} + +QVariant QgsProcessingModelChildParameterSource::toVariant() const +{ + QVariantMap map; + map.insert( QStringLiteral( "source" ), mSource ); + switch ( mSource ) + { + case ModelParameter: + map.insert( QStringLiteral( "parameter_name" ), mParameterName ); + break; + + case ChildOutput: + map.insert( QStringLiteral( "child_id" ), mChildId ); + map.insert( QStringLiteral( "output_name" ), mOutputName ); + break; + + case StaticValue: + map.insert( QStringLiteral( "static_value" ), mStaticValue ); + break; + + case Expression: + map.insert( QStringLiteral( "expression" ), mExpression ); + break; + } + return map; +} + +bool QgsProcessingModelChildParameterSource::loadVariant( const QVariantMap &map ) +{ + mSource = static_cast< Source >( map.value( QStringLiteral( "source" ) ).toInt() ); + switch ( mSource ) + { + case ModelParameter: + mParameterName = map.value( QStringLiteral( "parameter_name" ) ).toString(); + break; + + case ChildOutput: + mChildId = map.value( QStringLiteral( "child_id" ) ).toString(); + mOutputName = map.value( QStringLiteral( "output_name" ) ).toString(); + break; + + case StaticValue: + mStaticValue = map.value( QStringLiteral( "static_value" ) ); + break; + + case Expression: + mExpression = map.value( QStringLiteral( "expression" ) ).toString(); + break; + } + return true; +} + +QString QgsProcessingModelChildParameterSource::asPythonCode() const +{ + switch ( mSource ) + { + case ModelParameter: + return QStringLiteral( "parameters['%1']" ).arg( mParameterName ); + + case ChildOutput: + return QStringLiteral( "outputs['%1']['%2']" ).arg( mChildId, mOutputName ); + + case StaticValue: + return mStaticValue.toString(); + + case Expression: + return QStringLiteral( "QgsExpression('%1').evaluate()" ).arg( mExpression ); + } + return QString(); +} + +///@endcond diff --git a/src/core/processing/models/qgsprocessingmodelchildparametersource.h b/src/core/processing/models/qgsprocessingmodelchildparametersource.h new file mode 100644 index 00000000000..25f1c415d84 --- /dev/null +++ b/src/core/processing/models/qgsprocessingmodelchildparametersource.h @@ -0,0 +1,198 @@ +/*************************************************************************** + qgsprocessingmodelchildparametersource.h + ---------------------------------------- + begin : June 2017 + copyright : (C) 2017 by Nyall Dawson + email : nyall dot dawson at gmail dot com + ***************************************************************************/ + +/*************************************************************************** + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + ***************************************************************************/ + +#ifndef QGSPROCESSINGMODELCHILDPARAMETERSOURCE_H +#define QGSPROCESSINGMODELCHILDPARAMETERSOURCE_H + +#include "qgis_core.h" +#include "qgis.h" + +///@cond NOT_STABLE + +/** + * Source for the value of a parameter for a child algorithm within a model. + * \since QGIS 3.0 + * \ingroup core + */ +class CORE_EXPORT QgsProcessingModelChildParameterSource +{ + public: + + //! Possible parameter value sources + enum Source + { + ModelParameter, //!< Parameter value is taken from a parent model parameter + ChildOutput, //!< Parameter value is taken from an output generated by a child algorithm + StaticValue, //!< Parameter value is a static value + Expression, //!< Parameter value is taken from an expression, evaluated just before the algorithm runs + }; + + /** + * Constructor for QgsProcessingModelChildParameterSource. It is recommended that the static methods + * fromStaticValue(), fromModelParameter(), fromChildOutput() and fromExpression() are used instead. + */ + QgsProcessingModelChildParameterSource() = default; + + bool operator==( const QgsProcessingModelChildParameterSource &other ) const; + bool operator!=( const QgsProcessingModelChildParameterSource &other ) const + { + return !operator==( other ); + } + + /** + * Returns a new QgsProcessingModelChildParameterSource which takes its value from a static \a value. + * \see fromModelParameter() + * \see fromChildOutput() + * \see fromExpression() + */ + static QgsProcessingModelChildParameterSource fromStaticValue( const QVariant &value ); + + /** + * Returns a new QgsProcessingModelChildParameterSource which takes its value from a parent model parameter. + * \see fromStaticValue() + * \see fromChildOutput() + * \see fromExpression() + */ + static QgsProcessingModelChildParameterSource fromModelParameter( const QString ¶meterName ); + + /** + * Returns a new QgsProcessingModelChildParameterSource which takes its value from an output generated by a child algorithm. + * \see fromStaticValue() + * \see fromModelParameter() + * \see fromExpression() + */ + static QgsProcessingModelChildParameterSource fromChildOutput( const QString &childId, const QString &outputName ); + + /** + * Returns a new QgsProcessingModelChildParameterSource which takes its value from an expression. The expression + * is evaluated just before the child algorithm executes, and can use functions available + * in its expression context to include results calculated from the child algorithms already + * executed by the model. + * \see fromStaticValue() + * \see fromChildOutput() + * \see fromModelParameter() + */ + static QgsProcessingModelChildParameterSource fromExpression( const QString &expression ); + + /** + * Returns the parameter value's source. + */ + Source source() const; + + /** + * Returns the source's static value. This is only used when the source() is StaticValue. + * \see setStaticValue() + */ + QVariant staticValue() const { return mStaticValue; } + + /** + * Sets the source's static value. Calling this will also change the source() to StaticValue. + * \see staticValue() + */ + void setStaticValue( const QVariant &value ) { mStaticValue = value; mSource = StaticValue; } + + /** + * Returns the source's model parameter name. This is only used when the source() is ModelParameter. + * \see setParameterName() + */ + QString parameterName() const { return mParameterName; } + + /** + * Sets the source's model parameter \a name. Calling this will also change the source() to ModelParameter. + * \see parameterName() + */ + void setParameterName( const QString &name ) { mParameterName = name; mSource = ModelParameter; } + + /** + * Returns the source's child algorithm ID from which the output value will be taken. This is only used when the source() is ChildOutput. + * \see setOutputChildId() + * \see outputName() + */ + QString outputChildId() const { return mChildId; } + + /** + * Sets the source's child algorithm \a id from which the output value will be taken. Calling this will also change the source() to ChildOutput. + * \see parameterName() + * \see setOutputName() + */ + void setOutputChildId( const QString &id ) { mChildId = id; mSource = ChildOutput; } + + /** + * Returns the source's child algorithm output name from which the output value will be taken. This is only used when the source() is ChildOutput. + * \see setOutputName() + * \see outputChildId() + */ + QString outputName() const { return mOutputName; } + + /** + * Sets the source's child algorithm output \a name from which the output value will be taken. Calling this will also change the source() to ChildOutput. + * \see outputName() + * \see setOutputChildId() + */ + void setOutputName( const QString &name ) { mOutputName = name; mSource = ChildOutput; } + + /** + * Returns the source's expression. This is only used when the source() is Expression. + * \see setExpression() + */ + QString expression() const { return mExpression; } + + /** + * Sets the source's expression. Calling this will also change the source() to Expression. + * The expression is evaluated just before the child algorithm executes, and can use functions available + * in its expression context to include results calculated from the child algorithms already + * executed by the model. + * \see expression() + */ + void setExpression( const QString &expression ) { mExpression = expression; mSource = Expression; } + + /** + * Saves this source to a QVariant. + * \see loadVariant() + */ + QVariant toVariant() const; + + /** + * Loads this source from a QVariantMap. + * \see toVariant() + */ + bool loadVariant( const QVariantMap &map ); + + /** + * Attempts to convert the source to executable Python code. + */ + QString asPythonCode() const; + + private: + + Source mSource = StaticValue; + QVariant mStaticValue; + QString mParameterName; + QString mChildId; + QString mOutputName; + QString mExpression; + +}; + +#ifndef SIP_RUN +//! List of child parameter sources +typedef QList< QgsProcessingModelChildParameterSource > QgsProcessingModelChildParameterSources; +#endif + +///@endcond + +#endif // QGSPROCESSINGMODELCHILDPARAMETERSOURCE_H diff --git a/src/core/processing/models/qgsprocessingmodelcomponent.cpp b/src/core/processing/models/qgsprocessingmodelcomponent.cpp new file mode 100644 index 00000000000..6dff848d824 --- /dev/null +++ b/src/core/processing/models/qgsprocessingmodelcomponent.cpp @@ -0,0 +1,62 @@ +/*************************************************************************** + qgsprocessingmodelcomponent.cpp + ------------------------------- + begin : June 2017 + copyright : (C) 2017 by Nyall Dawson + email : nyall dot dawson at gmail dot com + ***************************************************************************/ + +/*************************************************************************** + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + ***************************************************************************/ + +#include "qgsprocessingmodelcomponent.h" + +///@cond NOT_STABLE + +QgsProcessingModelComponent::QgsProcessingModelComponent( const QString &description ) + : mDescription( description ) +{} + +QString QgsProcessingModelComponent::description() const +{ + return mDescription; +} + +void QgsProcessingModelComponent::setDescription( const QString &description ) +{ + mDescription = description; +} + +QPointF QgsProcessingModelComponent::position() const +{ + return mPosition; +} + +void QgsProcessingModelComponent::setPosition( const QPointF &position ) +{ + mPosition = position; +} + +void QgsProcessingModelComponent::saveCommonProperties( QVariantMap &map ) const +{ + map.insert( QStringLiteral( "component_pos_x" ), mPosition.x() ); + map.insert( QStringLiteral( "component_pos_y" ), mPosition.y() ); + map.insert( QStringLiteral( "component_description" ), mDescription ); +} + +void QgsProcessingModelComponent::restoreCommonProperties( const QVariantMap &map ) +{ + QPointF pos; + pos.setX( map.value( QStringLiteral( "component_pos_x" ) ).toDouble() ); + pos.setY( map.value( QStringLiteral( "component_pos_y" ) ).toDouble() ); + mPosition = pos; + mDescription = map.value( QStringLiteral( "component_description" ) ).toString(); +} + +///@endcond diff --git a/src/core/processing/models/qgsprocessingmodelcomponent.h b/src/core/processing/models/qgsprocessingmodelcomponent.h new file mode 100644 index 00000000000..34963855637 --- /dev/null +++ b/src/core/processing/models/qgsprocessingmodelcomponent.h @@ -0,0 +1,94 @@ +/*************************************************************************** + qgsprocessingmodelcomponent.h + ----------------------------- + begin : June 2017 + copyright : (C) 2017 by Nyall Dawson + email : nyall dot dawson at gmail dot com + ***************************************************************************/ + +/*************************************************************************** + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + ***************************************************************************/ + +#ifndef QGSPROCESSINGMODELCOMPONENT_H +#define QGSPROCESSINGMODELCOMPONENT_H + +#include "qgis_core.h" +#include "qgis.h" +#include + +///@cond NOT_STABLE + +/** + * Represents a component of a model algorithm. + * \since QGIS 3.0 + * \ingroup core + */ +class CORE_EXPORT QgsProcessingModelComponent +{ + public: + + /** + * Returns the friendly description text for the component. + * \see setDescription() + */ + QString description() const; + + /** + * Sets the friendly \a description text for the component. + * \see description() + */ + void setDescription( const QString &description ); + + /** + * Returns the position of the model component within the graphical modeler. + * \see setPosition() + */ + QPointF position() const; + + /** + * Sets the \a position of the model component within the graphical modeler. + * \see position() + */ + void setPosition( const QPointF &position ); + + protected: + + //! Only subclasses can be created + QgsProcessingModelComponent( const QString &description = QString() ); + + //! Copies are protected to avoid slicing + QgsProcessingModelComponent( const QgsProcessingModelComponent &other ) = default; + + //! Copies are protected to avoid slicing + QgsProcessingModelComponent &operator=( const QgsProcessingModelComponent &other ) = default; + + /** + * Saves the component properties to a QVariantMap. + * \see restoreCommonProperties() + */ + void saveCommonProperties( QVariantMap &map ) const; + + /** + * Restores the component properties from a QVariantMap. + * \see saveCommonProperties() + */ + void restoreCommonProperties( const QVariantMap &map ); + + private: + + //! Position of component within model + QPointF mPosition; + + QString mDescription; + +}; + +///@endcond + +#endif // QGSPROCESSINGMODELCOMPONENT_H diff --git a/src/core/processing/models/qgsprocessingmodeloutput.cpp b/src/core/processing/models/qgsprocessingmodeloutput.cpp new file mode 100644 index 00000000000..70c71a0643f --- /dev/null +++ b/src/core/processing/models/qgsprocessingmodeloutput.cpp @@ -0,0 +1,47 @@ +/*************************************************************************** + qgsprocessingmodeloutput.cpp + ---------------------------- + begin : June 2017 + copyright : (C) 2017 by Nyall Dawson + email : nyall dot dawson at gmail dot com + ***************************************************************************/ + +/*************************************************************************** + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + ***************************************************************************/ + +#include "qgsprocessingmodeloutput.h" + +///@cond NOT_STABLE + +QgsProcessingModelOutput::QgsProcessingModelOutput( const QString &name, const QString &description ) + : QgsProcessingModelComponent( description ) + , mName( name ) +{} + +QVariant QgsProcessingModelOutput::toVariant() const +{ + QVariantMap map; + map.insert( QStringLiteral( "name" ), mName ); + map.insert( QStringLiteral( "child_id" ), mChildId ); + map.insert( QStringLiteral( "output_name" ), mOutputName ); + saveCommonProperties( map ); + return map; +} + +bool QgsProcessingModelOutput::loadVariant( const QVariantMap &map ) +{ + mName = map.value( QStringLiteral( "name" ) ).toString(); + mChildId = map.value( QStringLiteral( "child_id" ) ).toString(); + mOutputName = map.value( QStringLiteral( "output_name" ) ).toString(); + restoreCommonProperties( map ); + return true; +} + + +///@endcond diff --git a/src/core/processing/models/qgsprocessingmodeloutput.h b/src/core/processing/models/qgsprocessingmodeloutput.h new file mode 100644 index 00000000000..cf6db09b07a --- /dev/null +++ b/src/core/processing/models/qgsprocessingmodeloutput.h @@ -0,0 +1,98 @@ +/*************************************************************************** + qgsprocessingmodeloutput.h + -------------------------- + begin : June 2017 + copyright : (C) 2017 by Nyall Dawson + email : nyall dot dawson at gmail dot com + ***************************************************************************/ + +/*************************************************************************** + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + ***************************************************************************/ + +#ifndef QGSPROCESSINGMODELOUTPUT_H +#define QGSPROCESSINGMODELOUTPUT_H + +#include "qgis_core.h" +#include "qgis.h" +#include "qgsprocessingmodelcomponent.h" + +///@cond NOT_STABLE + +/** + * Represents a final output created by the model. + * \since QGIS 3.0 + * \ingroup core + */ +class CORE_EXPORT QgsProcessingModelOutput : public QgsProcessingModelComponent +{ + public: + + /** + * Constructor for QgsProcessingModelOutput with the specified \a name and \a description. + */ + QgsProcessingModelOutput( const QString &name = QString(), const QString &description = QString() ); + + /** + * Returns the model output name. + * \see setName() + */ + QString name() const { return mName; } + + /** + * Sets the model output \a name. + * \see name() + */ + void setName( const QString &name ) { mName = name; } + + /** + * Returns the child algorithm ID from which this output is generated. + * \see setChildId() + */ + QString childId() const { return mChildId; } + + /** + * Sets the child algorithm \a id from which this output is generated. + * \see childId() + */ + void setChildId( const QString &id ) { mChildId = id; } + + /** + * Returns the child algorithm output name from which this output is generated. + * \see setOutputName() + */ + QString childOutputName() const { return mOutputName; } + + /** + * Sets the child algorithm output \a name from which this output is generated. + * \see outputName() + */ + void setChildOutputName( const QString &name ) { mOutputName = name; } + + /** + * Saves this output to a QVariant. + * \see loadVariant() + */ + QVariant toVariant() const; + + /** + * Loads this output from a QVariantMap. + * \see toVariant() + */ + bool loadVariant( const QVariantMap &map ); + + private: + + QString mName; + QString mChildId; + QString mOutputName; +}; + +///@endcond + +#endif // QGSPROCESSINGMODELOUTPUT_H diff --git a/src/core/processing/models/qgsprocessingmodelparameter.cpp b/src/core/processing/models/qgsprocessingmodelparameter.cpp new file mode 100644 index 00000000000..4ab48c1facb --- /dev/null +++ b/src/core/processing/models/qgsprocessingmodelparameter.cpp @@ -0,0 +1,44 @@ +/*************************************************************************** + qgsprocessingmodelparameter.cpp + ------------------------------ + begin : June 2017 + copyright : (C) 2017 by Nyall Dawson + email : nyall dot dawson at gmail dot com + ***************************************************************************/ + +/*************************************************************************** + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + ***************************************************************************/ + +#include "qgsprocessingmodelparameter.h" + +///@cond NOT_STABLE + +QgsProcessingModelParameter::QgsProcessingModelParameter( const QString ¶meterName ) + : QgsProcessingModelComponent() + , mParameterName( parameterName ) +{ + +} + +QVariant QgsProcessingModelParameter::toVariant() const +{ + QVariantMap map; + map.insert( QStringLiteral( "name" ), mParameterName ); + saveCommonProperties( map ); + return map; +} + +bool QgsProcessingModelParameter::loadVariant( const QVariantMap &map ) +{ + mParameterName = map.value( QStringLiteral( "name" ) ).toString(); + restoreCommonProperties( map ); + return true; +} + +///@endcond diff --git a/src/core/processing/models/qgsprocessingmodelparameter.h b/src/core/processing/models/qgsprocessingmodelparameter.h new file mode 100644 index 00000000000..5deda289c88 --- /dev/null +++ b/src/core/processing/models/qgsprocessingmodelparameter.h @@ -0,0 +1,77 @@ +/*************************************************************************** + qgsprocessingmodelparameter.h + ----------------------------- + begin : June 2017 + copyright : (C) 2017 by Nyall Dawson + email : nyall dot dawson at gmail dot com + ***************************************************************************/ + +/*************************************************************************** + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + ***************************************************************************/ + +#ifndef QGSPROCESSINGMODELPARAMETER_H +#define QGSPROCESSINGMODELPARAMETER_H + +#include "qgis_core.h" +#include "qgis.h" +#include "qgsprocessingmodelcomponent.h" + +///@cond NOT_STABLE + + +/** + * Represents an input parameter used by the model. + * \since QGIS 3.0 + * \ingroup core + */ +class CORE_EXPORT QgsProcessingModelParameter : public QgsProcessingModelComponent +{ + public: + + /** + * Constructor for QgsProcessingModelParameter. The parameter name should match one of the + * parameters from the parent model. + */ + QgsProcessingModelParameter( const QString ¶meterName = QString() ); + + /** + * Returns the associated parameter name. The parameter name should match one of the + * parameters from the parent model. + * \see parameterName() + */ + QString parameterName() const { return mParameterName; } + + /** + * Sets the associated parameter name. The parameter name should match one of the + * parameters from the parent model. + * \see parameterName() + */ + void setParameterName( const QString &name ) { mParameterName = name; } + + /** + * Saves this parameter to a QVariant. + * \see loadVariant() + */ + QVariant toVariant() const; + + /** + * Loads this parameter from a QVariantMap. + * \see toVariant() + */ + bool loadVariant( const QVariantMap &map ); + + private: + + QString mParameterName; + +}; + +///@endcond + +#endif // QGSPROCESSINGMODELPARAMETER_H diff --git a/src/core/processing/qgsprocessingmodelalgorithm.h b/src/core/processing/qgsprocessingmodelalgorithm.h deleted file mode 100644 index 3be80b009bb..00000000000 --- a/src/core/processing/qgsprocessingmodelalgorithm.h +++ /dev/null @@ -1,977 +0,0 @@ -/*************************************************************************** - qgsprocessingmodelalgorithm.h - ----------------------------- - begin : June 2017 - copyright : (C) 2017 by Nyall Dawson - email : nyall dot dawson at gmail dot com - ***************************************************************************/ - -/*************************************************************************** - * * - * This program is free software; you can redistribute it and/or modify * - * it under the terms of the GNU General Public License as published by * - * the Free Software Foundation; either version 2 of the License, or * - * (at your option) any later version. * - * * - ***************************************************************************/ - -#ifndef QGSPROCESSINGMODELALGORITHM_H -#define QGSPROCESSINGMODELALGORITHM_H - -#include "qgis_core.h" -#include "qgis.h" -#include "qgsprocessingalgorithm.h" -#include "qgsprocessingcontext.h" - -///@cond NOT_STABLE - -/** - * \class QgsProcessingModelAlgorithm - * \ingroup core - * Model based algorithm with processing. - * \since QGIS 3.0 - */ -class CORE_EXPORT QgsProcessingModelAlgorithm : public QgsProcessingAlgorithm -{ - public: - - /** - * Source for the value of a parameter for a child algorithm within a model. - * \since QGIS 3.0 - * \ingroup core - */ - class CORE_EXPORT ChildParameterSource - { - public: - - //! Possible parameter value sources - enum Source - { - ModelParameter, //!< Parameter value is taken from a parent model parameter - ChildOutput, //!< Parameter value is taken from an output generated by a child algorithm - StaticValue, //!< Parameter value is a static value - Expression, //!< Parameter value is taken from an expression, evaluated just before the algorithm runs - }; - - /** - * Constructor for ChildParameterSource. It is recommended that the static methods - * fromStaticValue(), fromModelParameter(), fromChildOutput() and fromExpression() are used instead. - */ - ChildParameterSource() = default; - - bool operator==( const QgsProcessingModelAlgorithm::ChildParameterSource &other ) const; - bool operator!=( const QgsProcessingModelAlgorithm::ChildParameterSource &other ) const - { - return !operator==( other ); - } - - /** - * Returns a new ChildParameterSource which takes its value from a static \a value. - * \see fromModelParameter() - * \see fromChildOutput() - * \see fromExpression() - */ - static QgsProcessingModelAlgorithm::ChildParameterSource fromStaticValue( const QVariant &value ); - - /** - * Returns a new ChildParameterSource which takes its value from a parent model parameter. - * \see fromStaticValue() - * \see fromChildOutput() - * \see fromExpression() - */ - static QgsProcessingModelAlgorithm::ChildParameterSource fromModelParameter( const QString ¶meterName ); - - /** - * Returns a new ChildParameterSource which takes its value from an output generated by a child algorithm. - * \see fromStaticValue() - * \see fromModelParameter() - * \see fromExpression() - */ - static QgsProcessingModelAlgorithm::ChildParameterSource fromChildOutput( const QString &childId, const QString &outputName ); - - /** - * Returns a new ChildParameterSource which takes its value from an expression. The expression - * is evaluated just before the child algorithm executes, and can use functions available - * in its expression context to include results calculated from the child algorithms already - * executed by the model. - * \see fromStaticValue() - * \see fromChildOutput() - * \see fromModelParameter() - */ - static QgsProcessingModelAlgorithm::ChildParameterSource fromExpression( const QString &expression ); - - /** - * Returns the parameter value's source. - */ - Source source() const; - - /** - * Returns the source's static value. This is only used when the source() is StaticValue. - * \see setStaticValue() - */ - QVariant staticValue() const { return mStaticValue; } - - /** - * Sets the source's static value. Calling this will also change the source() to StaticValue. - * \see staticValue() - */ - void setStaticValue( const QVariant &value ) { mStaticValue = value; mSource = StaticValue; } - - /** - * Returns the source's model parameter name. This is only used when the source() is ModelParameter. - * \see setParameterName() - */ - QString parameterName() const { return mParameterName; } - - /** - * Sets the source's model parameter \a name. Calling this will also change the source() to ModelParameter. - * \see parameterName() - */ - void setParameterName( const QString &name ) { mParameterName = name; mSource = ModelParameter; } - - /** - * Returns the source's child algorithm ID from which the output value will be taken. This is only used when the source() is ChildOutput. - * \see setOutputChildId() - * \see outputName() - */ - QString outputChildId() const { return mChildId; } - - /** - * Sets the source's child algorithm \a id from which the output value will be taken. Calling this will also change the source() to ChildOutput. - * \see parameterName() - * \see setOutputName() - */ - void setOutputChildId( const QString &id ) { mChildId = id; mSource = ChildOutput; } - - /** - * Returns the source's child algorithm output name from which the output value will be taken. This is only used when the source() is ChildOutput. - * \see setOutputName() - * \see outputChildId() - */ - QString outputName() const { return mOutputName; } - - /** - * Sets the source's child algorithm output \a name from which the output value will be taken. Calling this will also change the source() to ChildOutput. - * \see outputName() - * \see setOutputChildId() - */ - void setOutputName( const QString &name ) { mOutputName = name; mSource = ChildOutput; } - - /** - * Returns the source's expression. This is only used when the source() is Expression. - * \see setExpression() - */ - QString expression() const { return mExpression; } - - /** - * Sets the source's expression. Calling this will also change the source() to Expression. - * The expression is evaluated just before the child algorithm executes, and can use functions available - * in its expression context to include results calculated from the child algorithms already - * executed by the model. - * \see expression() - */ - void setExpression( const QString &expression ) { mExpression = expression; mSource = Expression; } - - /** - * Saves this source to a QVariant. - * \see loadVariant() - */ - QVariant toVariant() const; - - /** - * Loads this source from a QVariantMap. - * \see toVariant() - */ - bool loadVariant( const QVariantMap &map ); - - /** - * Attempts to convert the source to executable Python code. - */ - QString asPythonCode() const; - - private: - - Source mSource = StaticValue; - QVariant mStaticValue; - QString mParameterName; - QString mChildId; - QString mOutputName; - QString mExpression; - - }; - -#ifndef SIP_RUN - //! List of child parameter sources - typedef QList< QgsProcessingModelAlgorithm::ChildParameterSource > ChildParameterSources; -#endif - - /** - * Represents a component of a model algorithm. - * \since QGIS 3.0 - * \ingroup core - */ - class CORE_EXPORT Component - { - public: - - /** - * Returns the friendly description text for the component. - * \see setDescription() - */ - QString description() const; - - /** - * Sets the friendly \a description text for the component. - * \see description() - */ - void setDescription( const QString &description ); - - /** - * Returns the position of the model component within the graphical modeler. - * \see setPosition() - */ - QPointF position() const; - - /** - * Sets the \a position of the model component within the graphical modeler. - * \see position() - */ - void setPosition( const QPointF &position ); - - protected: - - //! Only subclasses can be created - Component( const QString &description = QString() ); - - //! Copies are protected to avoid slicing - Component( const QgsProcessingModelAlgorithm::Component &other ) = default; - - //! Copies are protected to avoid slicing - Component &operator=( const QgsProcessingModelAlgorithm::Component &other ) = default; - - /** - * Saves the component properties to a QVariantMap. - * \see restoreCommonProperties() - */ - void saveCommonProperties( QVariantMap &map ) const; - - /** - * Restores the component properties from a QVariantMap. - * \see saveCommonProperties() - */ - void restoreCommonProperties( const QVariantMap &map ); - - private: - - //! Position of component within model - QPointF mPosition; - - QString mDescription; - - }; - - /** - * Represents an input parameter used by the model. - * \since QGIS 3.0 - * \ingroup core - */ - class CORE_EXPORT ModelParameter : public QgsProcessingModelAlgorithm::Component - { - public: - - /** - * Constructor for ModelParameter. The parameter name should match one of the - * parameters from the parent model. - */ - ModelParameter( const QString ¶meterName = QString() ); - - /** - * Returns the associated parameter name. The parameter name should match one of the - * parameters from the parent model. - * \see parameterName() - */ - QString parameterName() const { return mParameterName; } - - /** - * Sets the associated parameter name. The parameter name should match one of the - * parameters from the parent model. - * \see parameterName() - */ - void setParameterName( const QString &name ) { mParameterName = name; } - - /** - * Saves this parameter to a QVariant. - * \see loadVariant() - */ - QVariant toVariant() const; - - /** - * Loads this parameter from a QVariantMap. - * \see toVariant() - */ - bool loadVariant( const QVariantMap &map ); - - private: - - QString mParameterName; - - }; - - - /** - * Represents a final output created by the model. - * \since QGIS 3.0 - * \ingroup core - */ - class CORE_EXPORT ModelOutput : public QgsProcessingModelAlgorithm::Component - { - public: - - /** - * Constructor for ModelOutput with the specified \a name and \a description. - */ - ModelOutput( const QString &name = QString(), const QString &description = QString() ); - - /** - * Returns the model output name. - * \see setName() - */ - QString name() const { return mName; } - - /** - * Sets the model output \a name. - * \see name() - */ - void setName( const QString &name ) { mName = name; } - - /** - * Returns the child algorithm ID from which this output is generated. - * \see setChildId() - */ - QString childId() const { return mChildId; } - - /** - * Sets the child algorithm \a id from which this output is generated. - * \see childId() - */ - void setChildId( const QString &id ) { mChildId = id; } - - /** - * Returns the child algorithm output name from which this output is generated. - * \see setOutputName() - */ - QString childOutputName() const { return mOutputName; } - - /** - * Sets the child algorithm output \a name from which this output is generated. - * \see outputName() - */ - void setChildOutputName( const QString &name ) { mOutputName = name; } - - /** - * Saves this output to a QVariant. - * \see loadVariant() - */ - QVariant toVariant() const; - - /** - * Loads this output from a QVariantMap. - * \see toVariant() - */ - bool loadVariant( const QVariantMap &map ); - - private: - - QString mName; - QString mChildId; - QString mOutputName; - }; - - /** - * Child algorithm representing a single component of a QgsProcessingModelAlgorithm. - * \since QGIS 3.0 - * \ingroup core - */ - class CORE_EXPORT ChildAlgorithm : public QgsProcessingModelAlgorithm::Component - { - public: - - /** - * Constructor for ChildAlgorithm. The \a algorithmId parameter - * should be set to a QgsProcessingAlgorithm algorithm ID. - */ - ChildAlgorithm( const QString &algorithmId = QString() ); - - /** - * Returns the child algorithm's unique ID string, used the identify - * this child algorithm within its parent model. - * \see setChildId() - * \see generateChildId() - */ - QString childId() const; - - /** - * Sets the child algorithm's unique \a id string, used the identify - * this child algorithm within its parent model. - * \see childId() - * \see generateChildId() - */ - void setChildId( const QString &id ); - - /** - * Automatically generates a unique childId() for the algorithm, - * avoiding child IDs which are already present in \a model. - * \see childId() - * \see setChildId() - */ - void generateChildId( const QgsProcessingModelAlgorithm &model ); - - /** - * Returns the underlying child algorithm's ID. - * \see algorithm() - * \see setAlgorithmId() - */ - QString algorithmId() const; - - /** - * Sets the underlying child algorithm's ID. This - * should be set to an existing QgsProcessingAlgorithm algorithm ID. - * \see algorithm() - * \see algorithmId() - */ - void setAlgorithmId( const QString &algorithmId ); - - /** - * Returns the underlying child algorithm, or a nullptr - * if a matching algorithm is not available. - * \see algorithmId() - */ - const QgsProcessingAlgorithm *algorithm() const; - - /** - * Returns a map of parameter sources. The keys are the child algorithm - * parameter names, the values are the sources for that parameter. - * \see setParameterSources() - * \see addParameterSources() - */ - QMap< QString, QList< QgsProcessingModelAlgorithm::ChildParameterSource > > parameterSources() const; - - /** - * Sets the map of parameter \a sources. The keys are the child algorithm - * parameter names, the values are the sources for that parameter. - * \see parameterSources() - * \see addParameterSources() - */ - void setParameterSources( const QMap< QString, QList< QgsProcessingModelAlgorithm::ChildParameterSource > > &sources ); - - /** - * Adds a parameter source. The \a name argument should match - * one of the child algorithm's parameter names, and the \a sources - * argument is used to set the sources for that parameter. - * - * Any existing parameter sources with matching name will be replaced. - * \see parameterSources() - * \see setParameterSources() - */ - void addParameterSources( const QString &name, const QList< QgsProcessingModelAlgorithm::ChildParameterSource > &source ); - - /** - * Returns true if the child algorithm is active. - * \see setActive() - */ - bool isActive() const; - - /** - * Sets whether the child algorithm is active. - * \see isActive() - */ - void setActive( bool active ); - - /** - * Returns the list of child algorithms from the parent model on which this - * algorithm is dependent. The returned list contains the id() of the - * dependent algorithms. - * \see setDependencies() - */ - QStringList dependencies() const; - - /** - * Sets the list of child algorithms from the parent model on which this - * algorithm is dependent. The list should contain the id() of the - * dependent algorithms. - * \see dependencies() - */ - void setDependencies( const QStringList &dependencies ); - - /** - * Returns true if the list of parameters for this algorithm should be collapsed - * in the graphical modeller. - * \see setParametersCollapsed() - * \see outputsCollapsed() - */ - bool parametersCollapsed() const; - - /** - * Sets whether the list of parameters for this algorithm should be collapsed - * in the graphical modeller. - * \see parametersCollapsed() - * \see setOutputsCollapsed() - */ - void setParametersCollapsed( bool collapsed ); - - /** - * Returns true if the list of outputs for this algorithm should be collapsed - * in the graphical modeller. - * \see setParametersCollapsed() - * \see parametersCollapsed() - */ - bool outputsCollapsed() const; - - /** - * Sets whether the list of outputs for this algorithm should be collapsed - * in the graphical modeller. - * \see outputsCollapsed() - * \see setParametersCollapsed() - */ - void setOutputsCollapsed( bool collapsed ); - - /** - * Returns the map of final model outputs which are generated by this child algorithm. - * The keys are the output names from this child algorithm. Only outputs which are - * part of the final outputs from the model are included in this map. - * \see setModelOutputs() - * \see modelOutput() - */ - QMap modelOutputs() const; - - /** - * Returns the final model output with matching \a name. If no output - * exists with the name, a new one will be created and returned. - * - * If child model outputs are altered by this method, QgsProcessingModelAlgorithm::updateDestinationParameters() - * must be called on the parent model. - * - * \see modelOutputs() - * \see setModelOutputs() - */ - QgsProcessingModelAlgorithm::ModelOutput &modelOutput( const QString &name ); - - /** - * Sets the map of final model \a outputs which are generated by this child algorithm. - * Only outputs which are part of the final outputs from the model should be included in this map. - * - * If child model outputs are altered by this method, QgsProcessingModelAlgorithm::updateDestinationParameters() - * must be called on the parent model. - * - * \see modelOutputs() - */ - void setModelOutputs( const QMap &outputs ); - - /** - * Saves this child to a QVariant. - * \see loadVariant() - */ - QVariant toVariant() const; - - /** - * Loads this child from a QVariant. - * \see toVariant() - */ - bool loadVariant( const QVariant &child ); - - /** - * Attempts to convert the child to executable Python code. - */ - QString asPythonCode() const; - - private: - - QString mId; - - QString mAlgorithmId; - - //! A map of parameter sources. Keys are algorithm parameter names. - QMap< QString, QgsProcessingModelAlgorithm::ChildParameterSources > mParams; - - //! A map of ModelOutput for final model outputs generated by this child algorithm. Keys are output names from the child algorithm. - QMap< QString, QgsProcessingModelAlgorithm::ModelOutput > mModelOutputs; - - bool mActive = true; - - //! List of child algorithms from the parent model on which this algorithm is dependent - QStringList mDependencies; - - //! Whether list of parameters should be collapsed in the graphical modeller - bool mParametersCollapsed = true; - //! Whether list of outputs should be collapsed in the graphical modeller - bool mOutputsCollapsed = true; - }; - - /** - * Constructor for QgsProcessingModelAlgorithm. - */ - QgsProcessingModelAlgorithm( const QString &name = QString(), const QString &group = QString() ); - - QString name() const override; - QString displayName() const override; - QString group() const override; - QIcon icon() const override; - QString svgIconPath() const override; - QString shortHelpString() const override; - QString helpUrl() const override; - - bool canExecute( QString *errorMessage SIP_OUT = nullptr ) const override; - QString asPythonCommand( const QVariantMap ¶meters, QgsProcessingContext &context ) const override; - QgsProcessingModelAlgorithm *create() const override SIP_FACTORY; - - /** - * Sets the model \a name. - * \see name() - */ - void setName( const QString &name ); - - /** - * Sets the model \a group. - * \see group() - */ - void setGroup( const QString &group ); - - /** - * Returns the map of child algorithms contained in the model. The keys - * are the child algorithm ids (see QgsProcessingModelAlgorithm::ChildAlgorithm::childId()). - * \see childAlgorithm() - * \see setChildAlgorithms() - * \see addChildAlgorithm() - */ - QMap childAlgorithms() const; - - /** - * Sets the map of child algorithms contained in the model. The keys - * are the child algorithm ids (see QgsProcessingModelAlgorithm::ChildAlgorithm::childId()). - * All existing child algorithms will be replaced. - * \see childAlgorithms() - * \see childAlgorithm() - * \see setChildAlgorithm() - * \see addChildAlgorithm() - */ - void setChildAlgorithms( const QMap &childAlgorithms ); - - /** - * Sets the child \a algorithm within the model. If a child algorithm already - * exists in the model with the same child ID then that algorithm will be replaced. - * \see addChildAlgorithm() - * \see setChildAlgorithms() - */ - void setChildAlgorithm( const QgsProcessingModelAlgorithm::ChildAlgorithm &algorithm ); - - /** - * Adds a new child \a algorithm to the model. If a child algorithm already exists - * in the model with the same child ID then \a algorithm will be assigned a new - * autogenerated unique ID. - * The assigned child ID will be returned. - * \see childAlgorithms() - * \see childAlgorithm() - * \see setChildAlgorithm() - * \see setChildAlgorithms() - */ - QString addChildAlgorithm( QgsProcessingModelAlgorithm::ChildAlgorithm &algorithm ); - - /** - * Returns the child algorithm with matching \a id. If no child algorithm exists with - * this ID a new algorithm will be added to the model and returned. - * \see addChildAlgorithm() - * \see childAlgorithms() - */ - QgsProcessingModelAlgorithm::ChildAlgorithm &childAlgorithm( const QString &id ); - - /** - * Attempts to remove the child algorithm with matching \a id. - * Returns true if the algorithm could be removed, or false - * if the algorithm could not be removed (e.g. due to other - * child algorithms depending on it). - * \see deactivateChildAlgorithm() - */ - bool removeChildAlgorithm( const QString &id ); - - /** - * Deactivates the child algorithm with matching \a id. - * All other child algorithms which depend on the child - * algorithm will also be deactivated. - * \see removeChildAlgorithm() - * \see activateChildAlgorithm() - */ - void deactivateChildAlgorithm( const QString &id ); - - /** - * Attempts to activate the child algorithm with matching \a id. - * If any child algorithms on which the child depends are not active, - * then the child will not be activated and false will be returned. - * \see deactivateChildAlgorithm() - */ - bool activateChildAlgorithm( const QString &id ); - - /** - * Returns a list of the child algorithm IDs depending on the child - * algorithm with the specified \a childId. - * \see dependsOnChildAlgorithms() - */ - QSet< QString > dependentChildAlgorithms( const QString &childId ) const; - - /** - * Returns a list of the child algorithm IDs on which the child - * algorithm with the specified \a childId depends upon. - * \see dependentChildAlgorithms() - */ - QSet< QString > dependsOnChildAlgorithms( const QString &childId ) const; - - /** - * Adds a new parameter to the model, with the specified \a definition and graphical \a component. - * Ownership of \a definition is transferred to the model. - * \see updateModelParameter() - * \see removeModelParameter() - */ - void addModelParameter( QgsProcessingParameterDefinition *definition SIP_TRANSFER, const QgsProcessingModelAlgorithm::ModelParameter &component ); - - /** - * Replaces the definition of an existing parameter (by parameter name) with a new \a definition. Ownership of - * \a definition is transferred to the model, and any existing parameter is deleted. - * \see addModelParameter() - * \see removeModelParameter() - */ - void updateModelParameter( QgsProcessingParameterDefinition *definition SIP_TRANSFER ); - - /** - * Removes an existing model parameter by \a name. The definition of the matching parameter - * is deleted. - * \see addModelParameter() - * \see updateModelParameter() - */ - void removeModelParameter( const QString &name ); - - /** - * Returns true if any child algorithms depend on the model parameter - * with the specified \a name. - * \see otherParametersDependOnParameter() - */ - bool childAlgorithmsDependOnParameter( const QString &name ) const; - - /** - * Returns true if any other model parameters depend on the parameter - * with the specified \a name (e.g. field parameters where \a name - * is the parent layer parameter). - * \see childAlgorithmsDependOnParameter() - */ - bool otherParametersDependOnParameter( const QString &name ) const; - - /** - * Returns the map of parameter components used by the model. The keys - * should match the algorithm's parameter names (see parameterDefinitions() ). - * \see setParameterComponent() - * \see parameterComponent() - */ - QMap parameterComponents() const; - - /** - * Sets the map of parameter components used by the model. The keys - * should match the algorithm's parameter names (see parameterDefinitions() ). - * All existing parameter components will be replaced. - * \see parameterComponents() - * \see setParameterComponent() - * \see parameterComponent() - */ - void setParameterComponents( const QMap ¶meterComponents ); - - /** - * Sets a parameter \a component for the model. If a parameter component already - * exists in the model with the same parameter name then that component will be replaced. - * \see parameterComponents() - * \see setParameterComponents() - * \see parameterComponent() - */ - void setParameterComponent( const QgsProcessingModelAlgorithm::ModelParameter &component ); - - /** - * Returns the parameter component with matching \a name. If no parameter component exists with - * this name a new component will be added to the model and returned. - * \see parameterComponents() - * \see setParameterComponents() - * \see setParameterComponent() - */ - QgsProcessingModelAlgorithm::ModelParameter ¶meterComponent( const QString &name ); - - /** - * Updates the model's parameter definitions to include all relevant destination - * parameters as required by child algorithm ModelOutputs. - * Must be called whenever child algorithm ModelOutputs are altered. - */ - void updateDestinationParameters(); - - /** - * Writes the model to a file, at the specified \a path. - * \see fromFile() - */ - bool toFile( const QString &path ) const; - - /** - * Reads the model from a file, at the specified \a path. - * \see toFile() - */ - bool fromFile( const QString &path ); - - /** - * Returns the model's help contents (a free-form map of values describing the algorithm's - * use and metadata). - * \see setHelpContent() - */ - QVariantMap &helpContent() { return mHelpContent; } - - /** - * Returns the model's help contents (a free-form map of values describing the algorithm's - * use and metadata). - * \see setHelpContent() - */ - SIP_SKIP QVariantMap helpContent() const; - - /** - * Sets the model's help \a contents (a free-form map of values describing the algorithm's - * use and metadata). - * \see helpContent() - */ - void setHelpContent( const QVariantMap &contents ); - - /** - * Returns the source file path for the model, if available. - * \see setSourceFilePath() - */ - QString sourceFilePath() const; - - /** - * Sets the source file \a path for the model, if available. - * \see sourceFilePath() - */ - void setSourceFilePath( const QString &path ); - - /** - * Attempts to convert the model to executable Python code. - */ - QString asPythonCode() const; - - /** - * Returns a list of possible sources which can be used for the parameters for a child - * algorithm in the model. Returned sources are those which match either one of the - * specified \a parameterTypes (see QgsProcessingParameterDefinition::type() ) or - * on of the specified \a outputTypes (see QgsProcessingOutputDefinition::type() ). - * If specified, an optional list of \a dataTypes can be used to filter the returned - * sources to those with compatible data types for the parameter/outputs. - */ - QList< QgsProcessingModelAlgorithm::ChildParameterSource > availableSourcesForChild( const QString &childId, const QStringList ¶meterTypes = QStringList(), - const QStringList &outputTypes = QStringList(), const QList< int > dataTypes = QList< int >() ) const; - - /** - * Definition of a expression context variable available during model execution. - * \since QGIS 3.0 - * \ingroup core - */ - class CORE_EXPORT VariableDefinition - { - public: - - /** - * Constructor for a new VariableDefinition with the specified \a value and original - * parameter \a source, and \a description. - */ - VariableDefinition( const QVariant &value = QVariant(), const QgsProcessingModelAlgorithm::ChildParameterSource &source = QgsProcessingModelAlgorithm::ChildParameterSource::fromStaticValue( QVariant() ), const QString &description = QString() ) - : value( value ) - , source( source ) - , description( description ) - {} - - //! Value of variable - QVariant value; - - //! Original source of variable's value - QgsProcessingModelAlgorithm::ChildParameterSource source; - - //! Translated description of variable - QString description; - }; - - /** - * Returns a map of variable name to variable definition for expression context variables which are available - * for use by child algorithm during model execution. - * - * The child algorithm \a childId and processing \a context - * are manadatory. If \a modelParameters and \a results are not specified, then only the variable names and sources - * will be returned, but all variable values will be null. This can be used to determine in advance which variables - * will be available for a specific child algorithm, e.g. for use in expression builder widgets. - * - * In order to calculate the actual variable value, the input model \a modelParameters and already executed child - * algorithm \a results must be passed. - * \see createExpressionContextScopeForChildAlgorithm() - */ - QMap< QString, QgsProcessingModelAlgorithm::VariableDefinition > variablesForChildAlgorithm( const QString &childId, QgsProcessingContext &context, const QVariantMap &modelParameters = QVariantMap(), - const QVariantMap &results = QVariantMap() ) const; - - /** - * Creates a new expression context scope for a child algorithm within the model. - * \see variablesForChildAlgorithm() - */ - QgsExpressionContextScope *createExpressionContextScopeForChildAlgorithm( const QString &childId, QgsProcessingContext &context, const QVariantMap &modelParameters = QVariantMap(), - const QVariantMap &results = QVariantMap() ) const SIP_FACTORY; - - protected: - - QVariantMap processAlgorithm( const QVariantMap ¶meters, QgsProcessingContext &context, QgsProcessingFeedback *feedback ) override; - - private: - - QString mModelName; - QString mModelGroup; - - QMap< QString, ChildAlgorithm > mChildAlgorithms; - - //! Map of parameter name to model parameter component - QMap< QString, ModelParameter > mParameterComponents; - - QVariantMap mHelpContent; - - //! Model source file - QString mSourceFile; - - QVariantMap mResults; - - void dependsOnChildAlgorithmsRecursive( const QString &childId, QSet &depends ) const; - void dependentChildAlgorithmsRecursive( const QString &childId, QSet &depends ) const; - - QVariantMap parametersForChildAlgorithm( const ChildAlgorithm &child, const QVariantMap &modelParameters, const QVariantMap &results, const QgsExpressionContext &expressionContext ) const; - - /** - * Returns true if an output from a child algorithm is required elsewhere in - * the model. - */ - bool childOutputIsRequired( const QString &childId, const QString &outputName ) const; - - /** - * Saves this model to a QVariantMap, wrapped in a QVariant. - * You can use QgsXmlUtils::writeVariant to save it to an XML document. - * - * \see loadVariant() - */ - QVariant toVariant() const; - - /** - * Loads this model from a QVariantMap, wrapped in a QVariant. - * You can use QgsXmlUtils::readVariant to load it from an XML document. - * - * \see toVariant() - */ - bool loadVariant( const QVariant &model ); - - friend class TestQgsProcessing; -}; - -///@endcond - -#endif // QGSPROCESSINGMODELALGORITHM_H - - diff --git a/src/core/processing/qgsprocessingparameters.cpp b/src/core/processing/qgsprocessingparameters.cpp index 198265aa3b6..151a64bad21 100644 --- a/src/core/processing/qgsprocessingparameters.cpp +++ b/src/core/processing/qgsprocessingparameters.cpp @@ -905,7 +905,7 @@ QgsProcessingParameterDefinition *QgsProcessingParameters::parameterFromScriptCo return QgsProcessingParameterRasterDestination::fromScriptCode( name, description, isOptional, definition ); else if ( type == QStringLiteral( "filedestination" ) ) return QgsProcessingParameterFileDestination::fromScriptCode( name, description, isOptional, definition ); - else if ( type == QStringLiteral( "folderDestination" ) ) + else if ( type == QStringLiteral( "folderdestination" ) ) return QgsProcessingParameterFolderDestination::fromScriptCode( name, description, isOptional, definition ); return nullptr; @@ -3039,7 +3039,7 @@ QString QgsProcessingParameterVectorDestination::asScriptCode() const QString code = QStringLiteral( "##%1=" ).arg( mName ); if ( mFlags & FlagOptional ) code += QStringLiteral( "optional " ); - code += QStringLiteral( "vectorOut " ); + code += QStringLiteral( "vectorDestination " ); switch ( mDataType ) { diff --git a/tests/src/core/CMakeLists.txt b/tests/src/core/CMakeLists.txt index 64ccbaeea9a..8991fe6dbba 100755 --- a/tests/src/core/CMakeLists.txt +++ b/tests/src/core/CMakeLists.txt @@ -19,6 +19,7 @@ INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_SOURCE_DIR}/src/core/layertree ${CMAKE_SOURCE_DIR}/src/core/metadata ${CMAKE_SOURCE_DIR}/src/core/processing + ${CMAKE_SOURCE_DIR}/src/core/processing/models ${CMAKE_SOURCE_DIR}/src/core/raster ${CMAKE_SOURCE_DIR}/src/core/scalebar ${CMAKE_SOURCE_DIR}/src/core/symbology-ng diff --git a/tests/src/core/testqgsprocessing.cpp b/tests/src/core/testqgsprocessing.cpp index f43b67c1b8f..6044bf14f69 100644 --- a/tests/src/core/testqgsprocessing.cpp +++ b/tests/src/core/testqgsprocessing.cpp @@ -3611,7 +3611,7 @@ void TestQgsProcessing::parameterVectorOut() QVERIFY( dynamic_cast< QgsProcessingParameterVectorDestination *>( def.get() ) ); QString code = def->asScriptCode(); - QCOMPARE( code, QStringLiteral( "##non_optional=vectorOut" ) ); + QCOMPARE( code, QStringLiteral( "##non_optional=vectorDestination" ) ); std::unique_ptr< QgsProcessingParameterVectorDestination > fromCode( dynamic_cast< QgsProcessingParameterVectorDestination * >( QgsProcessingParameters::parameterFromScriptCode( code ) ) ); QVERIFY( fromCode.get() ); QCOMPARE( fromCode->name(), def->name() ); @@ -3622,17 +3622,17 @@ void TestQgsProcessing::parameterVectorOut() def->setDataType( QgsProcessing::TypeVectorPoint ); code = def->asScriptCode(); - QCOMPARE( code, QStringLiteral( "##non_optional=vectorOut point" ) ); + QCOMPARE( code, QStringLiteral( "##non_optional=vectorDestination point" ) ); fromCode.reset( dynamic_cast< QgsProcessingParameterVectorDestination * >( QgsProcessingParameters::parameterFromScriptCode( code ) ) ); QCOMPARE( fromCode->dataType(), def->dataType() ); def->setDataType( QgsProcessing::TypeVectorLine ); code = def->asScriptCode(); - QCOMPARE( code, QStringLiteral( "##non_optional=vectorOut line" ) ); + QCOMPARE( code, QStringLiteral( "##non_optional=vectorDestination line" ) ); fromCode.reset( dynamic_cast< QgsProcessingParameterVectorDestination * >( QgsProcessingParameters::parameterFromScriptCode( code ) ) ); QCOMPARE( fromCode->dataType(), def->dataType() ); def->setDataType( QgsProcessing::TypeVectorPolygon ); code = def->asScriptCode(); - QCOMPARE( code, QStringLiteral( "##non_optional=vectorOut polygon" ) ); + QCOMPARE( code, QStringLiteral( "##non_optional=vectorDestination polygon" ) ); fromCode.reset( dynamic_cast< QgsProcessingParameterVectorDestination * >( QgsProcessingParameters::parameterFromScriptCode( code ) ) ); QCOMPARE( fromCode->dataType(), def->dataType() ); @@ -3648,7 +3648,7 @@ void TestQgsProcessing::parameterVectorOut() QVERIFY( def->checkValueIsAcceptable( QgsProcessingOutputLayerDefinition( "layer1231123" ) ) ); code = def->asScriptCode(); - QCOMPARE( code, QStringLiteral( "##optional=optional vectorOut" ) ); + QCOMPARE( code, QStringLiteral( "##optional=optional vectorDestination" ) ); fromCode.reset( dynamic_cast< QgsProcessingParameterVectorDestination * >( QgsProcessingParameters::parameterFromScriptCode( code ) ) ); QCOMPARE( fromCode->name(), def->name() ); QCOMPARE( fromCode->description(), QStringLiteral( "optional" ) ); @@ -3718,7 +3718,7 @@ void TestQgsProcessing::parameterRasterOut() QVERIFY( dynamic_cast< QgsProcessingParameterRasterDestination *>( def.get() ) ); QString code = def->asScriptCode(); - QCOMPARE( code, QStringLiteral( "##non_optional=rasterOut" ) ); + QCOMPARE( code, QStringLiteral( "##non_optional=rasterDestination" ) ); std::unique_ptr< QgsProcessingParameterRasterDestination > fromCode( dynamic_cast< QgsProcessingParameterRasterDestination * >( QgsProcessingParameters::parameterFromScriptCode( code ) ) ); QVERIFY( fromCode.get() ); QCOMPARE( fromCode->name(), def->name() ); @@ -3741,7 +3741,7 @@ void TestQgsProcessing::parameterRasterOut() QCOMPARE( QgsProcessingParameters::parameterAsOutputLayer( def.get(), params, context ), QStringLiteral( "default.tif" ) ); code = def->asScriptCode(); - QCOMPARE( code, QStringLiteral( "##optional=optional rasterOut default.tif" ) ); + QCOMPARE( code, QStringLiteral( "##optional=optional rasterDestination default.tif" ) ); fromCode.reset( dynamic_cast< QgsProcessingParameterRasterDestination * >( QgsProcessingParameters::parameterFromScriptCode( code ) ) ); QVERIFY( fromCode.get() ); QCOMPARE( fromCode->name(), def->name() ); @@ -3836,7 +3836,7 @@ void TestQgsProcessing::parameterFileOut() QVERIFY( dynamic_cast< QgsProcessingParameterFileDestination *>( def.get() ) ); QString code = def->asScriptCode(); - QCOMPARE( code, QStringLiteral( "##non_optional=fileOut" ) ); + QCOMPARE( code, QStringLiteral( "##non_optional=fileDestination" ) ); std::unique_ptr< QgsProcessingParameterFileDestination > fromCode( dynamic_cast< QgsProcessingParameterFileDestination * >( QgsProcessingParameters::parameterFromScriptCode( code ) ) ); QVERIFY( fromCode.get() ); QCOMPARE( fromCode->name(), def->name() ); @@ -3859,7 +3859,7 @@ void TestQgsProcessing::parameterFileOut() QCOMPARE( QgsProcessingParameters::parameterAsFileOutput( def.get(), params, context ), QStringLiteral( "default.txt" ) ); code = def->asScriptCode(); - QCOMPARE( code, QStringLiteral( "##optional=optional fileOut default.txt" ) ); + QCOMPARE( code, QStringLiteral( "##optional=optional fileDestination default.txt" ) ); fromCode.reset( dynamic_cast< QgsProcessingParameterFileDestination * >( QgsProcessingParameters::parameterFromScriptCode( code ) ) ); QVERIFY( fromCode.get() ); QCOMPARE( fromCode->name(), def->name() ); @@ -3908,7 +3908,7 @@ void TestQgsProcessing::parameterFolderOut() QVERIFY( dynamic_cast< QgsProcessingParameterFolderDestination *>( def.get() ) ); QString code = def->asScriptCode(); - QCOMPARE( code, QStringLiteral( "##non_optional=folderOut" ) ); + QCOMPARE( code, QStringLiteral( "##non_optional=folderDestination" ) ); std::unique_ptr< QgsProcessingParameterFolderDestination > fromCode( dynamic_cast< QgsProcessingParameterFolderDestination * >( QgsProcessingParameters::parameterFromScriptCode( code ) ) ); QVERIFY( fromCode.get() ); QCOMPARE( fromCode->name(), def->name() ); @@ -3930,7 +3930,7 @@ void TestQgsProcessing::parameterFolderOut() QCOMPARE( QgsProcessingParameters::parameterAsFileOutput( def.get(), params, context ), QStringLiteral( "c:/junk" ) ); code = def->asScriptCode(); - QCOMPARE( code, QStringLiteral( "##optional=optional folderOut c:/junk" ) ); + QCOMPARE( code, QStringLiteral( "##optional=optional folderDestination c:/junk" ) ); fromCode.reset( dynamic_cast< QgsProcessingParameterFolderDestination * >( QgsProcessingParameters::parameterFromScriptCode( code ) ) ); QVERIFY( fromCode.get() ); QCOMPARE( fromCode->name(), def->name() ); @@ -4175,97 +4175,97 @@ void TestQgsProcessing::asPythonCommand() void TestQgsProcessing::modelerAlgorithm() { //static value source - QgsProcessingModelAlgorithm::ChildParameterSource svSource = QgsProcessingModelAlgorithm::ChildParameterSource::fromStaticValue( 5 ); - QCOMPARE( svSource.source(), QgsProcessingModelAlgorithm::ChildParameterSource::StaticValue ); + QgsProcessingModelChildParameterSource svSource = QgsProcessingModelChildParameterSource::fromStaticValue( 5 ); + QCOMPARE( svSource.source(), QgsProcessingModelChildParameterSource::StaticValue ); QCOMPARE( svSource.staticValue().toInt(), 5 ); svSource.setStaticValue( 7 ); QCOMPARE( svSource.staticValue().toInt(), 7 ); - svSource = QgsProcessingModelAlgorithm::ChildParameterSource::fromModelParameter( "a" ); + svSource = QgsProcessingModelChildParameterSource::fromModelParameter( "a" ); // check that calling setStaticValue flips source to StaticValue - QCOMPARE( svSource.source(), QgsProcessingModelAlgorithm::ChildParameterSource::ModelParameter ); + QCOMPARE( svSource.source(), QgsProcessingModelChildParameterSource::ModelParameter ); svSource.setStaticValue( 7 ); QCOMPARE( svSource.staticValue().toInt(), 7 ); - QCOMPARE( svSource.source(), QgsProcessingModelAlgorithm::ChildParameterSource::StaticValue ); + QCOMPARE( svSource.source(), QgsProcessingModelChildParameterSource::StaticValue ); // model parameter source - QgsProcessingModelAlgorithm::ChildParameterSource mpSource = QgsProcessingModelAlgorithm::ChildParameterSource::fromModelParameter( "a" ); - QCOMPARE( mpSource.source(), QgsProcessingModelAlgorithm::ChildParameterSource::ModelParameter ); + QgsProcessingModelChildParameterSource mpSource = QgsProcessingModelChildParameterSource::fromModelParameter( "a" ); + QCOMPARE( mpSource.source(), QgsProcessingModelChildParameterSource::ModelParameter ); QCOMPARE( mpSource.parameterName(), QStringLiteral( "a" ) ); mpSource.setParameterName( "b" ); QCOMPARE( mpSource.parameterName(), QStringLiteral( "b" ) ); - mpSource = QgsProcessingModelAlgorithm::ChildParameterSource::fromStaticValue( 5 ); + mpSource = QgsProcessingModelChildParameterSource::fromStaticValue( 5 ); // check that calling setParameterName flips source to ModelParameter - QCOMPARE( mpSource.source(), QgsProcessingModelAlgorithm::ChildParameterSource::StaticValue ); + QCOMPARE( mpSource.source(), QgsProcessingModelChildParameterSource::StaticValue ); mpSource.setParameterName( "c" ); QCOMPARE( mpSource.parameterName(), QStringLiteral( "c" ) ); - QCOMPARE( mpSource.source(), QgsProcessingModelAlgorithm::ChildParameterSource::ModelParameter ); + QCOMPARE( mpSource.source(), QgsProcessingModelChildParameterSource::ModelParameter ); // child alg output source - QgsProcessingModelAlgorithm::ChildParameterSource oSource = QgsProcessingModelAlgorithm::ChildParameterSource::fromChildOutput( "a", "b" ); - QCOMPARE( oSource.source(), QgsProcessingModelAlgorithm::ChildParameterSource::ChildOutput ); + QgsProcessingModelChildParameterSource oSource = QgsProcessingModelChildParameterSource::fromChildOutput( "a", "b" ); + QCOMPARE( oSource.source(), QgsProcessingModelChildParameterSource::ChildOutput ); QCOMPARE( oSource.outputChildId(), QStringLiteral( "a" ) ); QCOMPARE( oSource.outputName(), QStringLiteral( "b" ) ); oSource.setOutputChildId( "c" ); QCOMPARE( oSource.outputChildId(), QStringLiteral( "c" ) ); oSource.setOutputName( "d" ); QCOMPARE( oSource.outputName(), QStringLiteral( "d" ) ); - oSource = QgsProcessingModelAlgorithm::ChildParameterSource::fromStaticValue( 5 ); + oSource = QgsProcessingModelChildParameterSource::fromStaticValue( 5 ); // check that calling setOutputChildId flips source to ChildOutput - QCOMPARE( oSource.source(), QgsProcessingModelAlgorithm::ChildParameterSource::StaticValue ); + QCOMPARE( oSource.source(), QgsProcessingModelChildParameterSource::StaticValue ); oSource.setOutputChildId( "c" ); QCOMPARE( oSource.outputChildId(), QStringLiteral( "c" ) ); - QCOMPARE( oSource.source(), QgsProcessingModelAlgorithm::ChildParameterSource::ChildOutput ); - oSource = QgsProcessingModelAlgorithm::ChildParameterSource::fromStaticValue( 5 ); + QCOMPARE( oSource.source(), QgsProcessingModelChildParameterSource::ChildOutput ); + oSource = QgsProcessingModelChildParameterSource::fromStaticValue( 5 ); // check that calling setOutputName flips source to ChildOutput - QCOMPARE( oSource.source(), QgsProcessingModelAlgorithm::ChildParameterSource::StaticValue ); + QCOMPARE( oSource.source(), QgsProcessingModelChildParameterSource::StaticValue ); oSource.setOutputName( "d" ); QCOMPARE( oSource.outputName(), QStringLiteral( "d" ) ); - QCOMPARE( oSource.source(), QgsProcessingModelAlgorithm::ChildParameterSource::ChildOutput ); + QCOMPARE( oSource.source(), QgsProcessingModelChildParameterSource::ChildOutput ); // expression source - QgsProcessingModelAlgorithm::ChildParameterSource expSource = QgsProcessingModelAlgorithm::ChildParameterSource::fromExpression( "1+2" ); - QCOMPARE( expSource.source(), QgsProcessingModelAlgorithm::ChildParameterSource::Expression ); + QgsProcessingModelChildParameterSource expSource = QgsProcessingModelChildParameterSource::fromExpression( "1+2" ); + QCOMPARE( expSource.source(), QgsProcessingModelChildParameterSource::Expression ); QCOMPARE( expSource.expression(), QStringLiteral( "1+2" ) ); expSource.setExpression( "1+3" ); QCOMPARE( expSource.expression(), QStringLiteral( "1+3" ) ); - expSource = QgsProcessingModelAlgorithm::ChildParameterSource::fromStaticValue( 5 ); + expSource = QgsProcessingModelChildParameterSource::fromStaticValue( 5 ); // check that calling setExpression flips source to Expression - QCOMPARE( expSource.source(), QgsProcessingModelAlgorithm::ChildParameterSource::StaticValue ); + QCOMPARE( expSource.source(), QgsProcessingModelChildParameterSource::StaticValue ); expSource.setExpression( "1+4" ); QCOMPARE( expSource.expression(), QStringLiteral( "1+4" ) ); - QCOMPARE( expSource.source(), QgsProcessingModelAlgorithm::ChildParameterSource::Expression ); + QCOMPARE( expSource.source(), QgsProcessingModelChildParameterSource::Expression ); // source equality operator - QVERIFY( QgsProcessingModelAlgorithm::ChildParameterSource::fromStaticValue( 5 ) == - QgsProcessingModelAlgorithm::ChildParameterSource::fromStaticValue( 5 ) ); - QVERIFY( QgsProcessingModelAlgorithm::ChildParameterSource::fromStaticValue( 5 ) != - QgsProcessingModelAlgorithm::ChildParameterSource::fromStaticValue( 7 ) ); - QVERIFY( QgsProcessingModelAlgorithm::ChildParameterSource::fromStaticValue( 5 ) != - QgsProcessingModelAlgorithm::ChildParameterSource::fromModelParameter( QStringLiteral( "a" ) ) ); - QVERIFY( QgsProcessingModelAlgorithm::ChildParameterSource::fromModelParameter( QStringLiteral( "a" ) ) == - QgsProcessingModelAlgorithm::ChildParameterSource::fromModelParameter( QStringLiteral( "a" ) ) ); - QVERIFY( QgsProcessingModelAlgorithm::ChildParameterSource::fromModelParameter( QStringLiteral( "a" ) ) != - QgsProcessingModelAlgorithm::ChildParameterSource::fromModelParameter( QStringLiteral( "b" ) ) ); - QVERIFY( QgsProcessingModelAlgorithm::ChildParameterSource::fromModelParameter( QStringLiteral( "a" ) ) != - QgsProcessingModelAlgorithm::ChildParameterSource::fromChildOutput( QStringLiteral( "alg" ), QStringLiteral( "out" ) ) ); - QVERIFY( QgsProcessingModelAlgorithm::ChildParameterSource::fromChildOutput( QStringLiteral( "alg" ), QStringLiteral( "out" ) ) == - QgsProcessingModelAlgorithm::ChildParameterSource::fromChildOutput( QStringLiteral( "alg" ), QStringLiteral( "out" ) ) ); - QVERIFY( QgsProcessingModelAlgorithm::ChildParameterSource::fromChildOutput( QStringLiteral( "alg" ), QStringLiteral( "out" ) ) != - QgsProcessingModelAlgorithm::ChildParameterSource::fromChildOutput( QStringLiteral( "alg2" ), QStringLiteral( "out" ) ) ); - QVERIFY( QgsProcessingModelAlgorithm::ChildParameterSource::fromChildOutput( QStringLiteral( "alg" ), QStringLiteral( "out" ) ) != - QgsProcessingModelAlgorithm::ChildParameterSource::fromChildOutput( QStringLiteral( "alg" ), QStringLiteral( "out2" ) ) ); - QVERIFY( QgsProcessingModelAlgorithm::ChildParameterSource::fromExpression( QStringLiteral( "a" ) ) == - QgsProcessingModelAlgorithm::ChildParameterSource::fromExpression( QStringLiteral( "a" ) ) ); - QVERIFY( QgsProcessingModelAlgorithm::ChildParameterSource::fromExpression( QStringLiteral( "a" ) ) != - QgsProcessingModelAlgorithm::ChildParameterSource::fromExpression( QStringLiteral( "b" ) ) ); - QVERIFY( QgsProcessingModelAlgorithm::ChildParameterSource::fromExpression( QStringLiteral( "a" ) ) != - QgsProcessingModelAlgorithm::ChildParameterSource::fromStaticValue( QStringLiteral( "b" ) ) ); + QVERIFY( QgsProcessingModelChildParameterSource::fromStaticValue( 5 ) == + QgsProcessingModelChildParameterSource::fromStaticValue( 5 ) ); + QVERIFY( QgsProcessingModelChildParameterSource::fromStaticValue( 5 ) != + QgsProcessingModelChildParameterSource::fromStaticValue( 7 ) ); + QVERIFY( QgsProcessingModelChildParameterSource::fromStaticValue( 5 ) != + QgsProcessingModelChildParameterSource::fromModelParameter( QStringLiteral( "a" ) ) ); + QVERIFY( QgsProcessingModelChildParameterSource::fromModelParameter( QStringLiteral( "a" ) ) == + QgsProcessingModelChildParameterSource::fromModelParameter( QStringLiteral( "a" ) ) ); + QVERIFY( QgsProcessingModelChildParameterSource::fromModelParameter( QStringLiteral( "a" ) ) != + QgsProcessingModelChildParameterSource::fromModelParameter( QStringLiteral( "b" ) ) ); + QVERIFY( QgsProcessingModelChildParameterSource::fromModelParameter( QStringLiteral( "a" ) ) != + QgsProcessingModelChildParameterSource::fromChildOutput( QStringLiteral( "alg" ), QStringLiteral( "out" ) ) ); + QVERIFY( QgsProcessingModelChildParameterSource::fromChildOutput( QStringLiteral( "alg" ), QStringLiteral( "out" ) ) == + QgsProcessingModelChildParameterSource::fromChildOutput( QStringLiteral( "alg" ), QStringLiteral( "out" ) ) ); + QVERIFY( QgsProcessingModelChildParameterSource::fromChildOutput( QStringLiteral( "alg" ), QStringLiteral( "out" ) ) != + QgsProcessingModelChildParameterSource::fromChildOutput( QStringLiteral( "alg2" ), QStringLiteral( "out" ) ) ); + QVERIFY( QgsProcessingModelChildParameterSource::fromChildOutput( QStringLiteral( "alg" ), QStringLiteral( "out" ) ) != + QgsProcessingModelChildParameterSource::fromChildOutput( QStringLiteral( "alg" ), QStringLiteral( "out2" ) ) ); + QVERIFY( QgsProcessingModelChildParameterSource::fromExpression( QStringLiteral( "a" ) ) == + QgsProcessingModelChildParameterSource::fromExpression( QStringLiteral( "a" ) ) ); + QVERIFY( QgsProcessingModelChildParameterSource::fromExpression( QStringLiteral( "a" ) ) != + QgsProcessingModelChildParameterSource::fromExpression( QStringLiteral( "b" ) ) ); + QVERIFY( QgsProcessingModelChildParameterSource::fromExpression( QStringLiteral( "a" ) ) != + QgsProcessingModelChildParameterSource::fromStaticValue( QStringLiteral( "b" ) ) ); - QgsProcessingModelAlgorithm::ChildAlgorithm child( QStringLiteral( "some_id" ) ); + QgsProcessingModelChildAlgorithm child( QStringLiteral( "some_id" ) ); QCOMPARE( child.algorithmId(), QStringLiteral( "some_id" ) ); QVERIFY( !child.algorithm() ); child.setAlgorithmId( QStringLiteral( "native:centroids" ) ); @@ -4291,24 +4291,24 @@ void TestQgsProcessing::modelerAlgorithm() child.setDependencies( QStringList() << "a" << "b" ); QCOMPARE( child.dependencies(), QStringList() << "a" << "b" ); - QMap< QString, QgsProcessingModelAlgorithm::ChildParameterSources > sources; - sources.insert( QStringLiteral( "a" ), QgsProcessingModelAlgorithm::ChildParameterSources() << QgsProcessingModelAlgorithm::ChildParameterSource::fromStaticValue( 5 ) ); + QMap< QString, QgsProcessingModelChildParameterSources > sources; + sources.insert( QStringLiteral( "a" ), QgsProcessingModelChildParameterSources() << QgsProcessingModelChildParameterSource::fromStaticValue( 5 ) ); child.setParameterSources( sources ); QCOMPARE( child.parameterSources().value( QStringLiteral( "a" ) ).at( 0 ).staticValue().toInt(), 5 ); - child.addParameterSources( QStringLiteral( "b" ), QgsProcessingModelAlgorithm::ChildParameterSources() << QgsProcessingModelAlgorithm::ChildParameterSource::fromStaticValue( 7 ) << QgsProcessingModelAlgorithm::ChildParameterSource::fromStaticValue( 9 ) ); + child.addParameterSources( QStringLiteral( "b" ), QgsProcessingModelChildParameterSources() << QgsProcessingModelChildParameterSource::fromStaticValue( 7 ) << QgsProcessingModelChildParameterSource::fromStaticValue( 9 ) ); QCOMPARE( child.parameterSources().value( QStringLiteral( "a" ) ).at( 0 ).staticValue().toInt(), 5 ); QCOMPARE( child.parameterSources().value( QStringLiteral( "b" ) ).count(), 2 ); QCOMPARE( child.parameterSources().value( QStringLiteral( "b" ) ).at( 0 ).staticValue().toInt(), 7 ); QCOMPARE( child.parameterSources().value( QStringLiteral( "b" ) ).at( 1 ).staticValue().toInt(), 9 ); - QgsProcessingModelAlgorithm::ModelOutput testModelOut; + QgsProcessingModelOutput testModelOut; testModelOut.setChildId( QStringLiteral( "my_id" ) ); QCOMPARE( testModelOut.childId(), QStringLiteral( "my_id" ) ); testModelOut.setChildOutputName( QStringLiteral( "my_output" ) ); QCOMPARE( testModelOut.childOutputName(), QStringLiteral( "my_output" ) ); - QMap outputs; - QgsProcessingModelAlgorithm::ModelOutput out1; + QMap outputs; + QgsProcessingModelOutput out1; out1.setDescription( QStringLiteral( "my output" ) ); outputs.insert( QStringLiteral( "a" ), out1 ); child.setModelOutputs( outputs ); @@ -4338,10 +4338,10 @@ void TestQgsProcessing::modelerAlgorithm() QCOMPARE( alg.group(), QStringLiteral( "group2" ) ); // child algorithms - QMap algs; - QgsProcessingModelAlgorithm::ChildAlgorithm a1; + QMap algs; + QgsProcessingModelChildAlgorithm a1; a1.setDescription( QStringLiteral( "alg1" ) ); - QgsProcessingModelAlgorithm::ChildAlgorithm a2; + QgsProcessingModelChildAlgorithm a2; a2.setDescription( QStringLiteral( "alg2" ) ); algs.insert( QStringLiteral( "a" ), a1 ); algs.insert( QStringLiteral( "b" ), a2 ); @@ -4349,7 +4349,7 @@ void TestQgsProcessing::modelerAlgorithm() QCOMPARE( alg.childAlgorithms().count(), 2 ); QCOMPARE( alg.childAlgorithms().value( QStringLiteral( "a" ) ).description(), QStringLiteral( "alg1" ) ); QCOMPARE( alg.childAlgorithms().value( QStringLiteral( "b" ) ).description(), QStringLiteral( "alg2" ) ); - QgsProcessingModelAlgorithm::ChildAlgorithm a3; + QgsProcessingModelChildAlgorithm a3; a3.setChildId( QStringLiteral( "c" ) ); a3.setDescription( QStringLiteral( "alg3" ) ); QCOMPARE( alg.addChildAlgorithm( a3 ), QStringLiteral( "c" ) ); @@ -4365,37 +4365,37 @@ void TestQgsProcessing::modelerAlgorithm() alg.childAlgorithm( "d" ).setDescription( QStringLiteral( "alg4" ) ); QCOMPARE( alg.childAlgorithm( "d" ).description(), QStringLiteral( "alg4" ) ); // overwrite existing - QgsProcessingModelAlgorithm::ChildAlgorithm a4a; + QgsProcessingModelChildAlgorithm a4a; a4a.setChildId( "d" ); a4a.setDescription( "new" ); alg.setChildAlgorithm( a4a ); QCOMPARE( alg.childAlgorithm( "d" ).description(), QStringLiteral( "new" ) ); // generating child ids - QgsProcessingModelAlgorithm::ChildAlgorithm c1; + QgsProcessingModelChildAlgorithm c1; c1.setAlgorithmId( QStringLiteral( "buffer" ) ); c1.generateChildId( alg ); QCOMPARE( c1.childId(), QStringLiteral( "buffer_1" ) ); QCOMPARE( alg.addChildAlgorithm( c1 ), QStringLiteral( "buffer_1" ) ); - QgsProcessingModelAlgorithm::ChildAlgorithm c2; + QgsProcessingModelChildAlgorithm c2; c2.setAlgorithmId( QStringLiteral( "buffer" ) ); c2.generateChildId( alg ); QCOMPARE( c2.childId(), QStringLiteral( "buffer_2" ) ); QCOMPARE( alg.addChildAlgorithm( c2 ), QStringLiteral( "buffer_2" ) ); - QgsProcessingModelAlgorithm::ChildAlgorithm c3; + QgsProcessingModelChildAlgorithm c3; c3.setAlgorithmId( QStringLiteral( "centroid" ) ); c3.generateChildId( alg ); QCOMPARE( c3.childId(), QStringLiteral( "centroid_1" ) ); QCOMPARE( alg.addChildAlgorithm( c3 ), QStringLiteral( "centroid_1" ) ); - QgsProcessingModelAlgorithm::ChildAlgorithm c4; + QgsProcessingModelChildAlgorithm c4; c4.setAlgorithmId( QStringLiteral( "centroid" ) ); c4.setChildId( QStringLiteral( "centroid_1" ) );// dupe id QCOMPARE( alg.addChildAlgorithm( c4 ), QStringLiteral( "centroid_2" ) ); QCOMPARE( alg.childAlgorithm( QStringLiteral( "centroid_2" ) ).childId(), QStringLiteral( "centroid_2" ) ); // parameter components - QMap pComponents; - QgsProcessingModelAlgorithm::ModelParameter pc1; + QMap pComponents; + QgsProcessingModelParameter pc1; pc1.setParameterName( QStringLiteral( "my_param" ) ); QCOMPARE( pc1.parameterName(), QStringLiteral( "my_param" ) ); pComponents.insert( QStringLiteral( "my_param" ), pc1 ); @@ -4413,7 +4413,7 @@ void TestQgsProcessing::modelerAlgorithm() // parameter definitions QgsProcessingModelAlgorithm alg1a( "test", "testGroup" ); - QgsProcessingModelAlgorithm::ModelParameter bool1; + QgsProcessingModelParameter bool1; bool1.setPosition( QPointF( 1, 2 ) ); alg1a.addModelParameter( new QgsProcessingParameterBoolean( "p1", "desc" ), bool1 ); QCOMPARE( alg1a.parameterDefinitions().count(), 1 ); @@ -4432,12 +4432,12 @@ void TestQgsProcessing::modelerAlgorithm() // test canExecute QgsProcessingModelAlgorithm alg2( "test", "testGroup" ); QVERIFY( alg2.canExecute() ); - QgsProcessingModelAlgorithm::ChildAlgorithm c5; + QgsProcessingModelChildAlgorithm c5; c5.setAlgorithmId( "native:centroids" ); alg2.addChildAlgorithm( c5 ); QVERIFY( alg2.canExecute() ); // non-existing alg - QgsProcessingModelAlgorithm::ChildAlgorithm c6; + QgsProcessingModelChildAlgorithm c6; c6.setAlgorithmId( "i'm not an alg" ); alg2.addChildAlgorithm( c6 ); QVERIFY( !alg2.canExecute() ); @@ -4450,14 +4450,14 @@ void TestQgsProcessing::modelerAlgorithm() QVERIFY( alg3.dependsOnChildAlgorithms( "notvalid" ).isEmpty() ); // add a child - QgsProcessingModelAlgorithm::ChildAlgorithm c7; + QgsProcessingModelChildAlgorithm c7; c7.setChildId( "c7" ); alg3.addChildAlgorithm( c7 ); QVERIFY( alg3.dependentChildAlgorithms( "c7" ).isEmpty() ); QVERIFY( alg3.dependsOnChildAlgorithms( "c7" ).isEmpty() ); // direct dependency - QgsProcessingModelAlgorithm::ChildAlgorithm c8; + QgsProcessingModelChildAlgorithm c8; c8.setChildId( "c8" ); c8.setDependencies( QStringList() << "c7" ); alg3.addChildAlgorithm( c8 ); @@ -4469,9 +4469,9 @@ void TestQgsProcessing::modelerAlgorithm() QVERIFY( alg3.dependsOnChildAlgorithms( "c8" ).contains( "c7" ) ); // dependency via parameter source - QgsProcessingModelAlgorithm::ChildAlgorithm c9; + QgsProcessingModelChildAlgorithm c9; c9.setChildId( "c9" ); - c9.addParameterSources( "x", QgsProcessingModelAlgorithm::ChildParameterSources() << QgsProcessingModelAlgorithm::ChildParameterSource::fromChildOutput( "c8", "x" ) ); + c9.addParameterSources( "x", QgsProcessingModelChildParameterSources() << QgsProcessingModelChildParameterSource::fromChildOutput( "c8", "x" ) ); alg3.addChildAlgorithm( c9 ); QVERIFY( alg3.dependentChildAlgorithms( "c9" ).isEmpty() ); QCOMPARE( alg3.dependentChildAlgorithms( "c8" ).count(), 1 ); @@ -4547,23 +4547,23 @@ void TestQgsProcessing::modelerAlgorithm() // parameter dependencies QgsProcessingModelAlgorithm alg4( "test", "testGroup" ); QVERIFY( !alg4.childAlgorithmsDependOnParameter( "not a param" ) ); - QgsProcessingModelAlgorithm::ChildAlgorithm c10; + QgsProcessingModelChildAlgorithm c10; c10.setChildId( "c10" ); alg4.addChildAlgorithm( c10 ); QVERIFY( !alg4.childAlgorithmsDependOnParameter( "not a param" ) ); - QgsProcessingModelAlgorithm::ModelParameter bool2; + QgsProcessingModelParameter bool2; alg4.addModelParameter( new QgsProcessingParameterBoolean( "p1", "desc" ), bool2 ); QVERIFY( !alg4.childAlgorithmsDependOnParameter( "p1" ) ); - c10.addParameterSources( "x", QgsProcessingModelAlgorithm::ChildParameterSources() << QgsProcessingModelAlgorithm::ChildParameterSource::fromModelParameter( "p2" ) ); + c10.addParameterSources( "x", QgsProcessingModelChildParameterSources() << QgsProcessingModelChildParameterSource::fromModelParameter( "p2" ) ); alg4.setChildAlgorithm( c10 ); QVERIFY( !alg4.childAlgorithmsDependOnParameter( "p1" ) ); - c10.addParameterSources( "y", QgsProcessingModelAlgorithm::ChildParameterSources() << QgsProcessingModelAlgorithm::ChildParameterSource::fromModelParameter( "p1" ) ); + c10.addParameterSources( "y", QgsProcessingModelChildParameterSources() << QgsProcessingModelChildParameterSource::fromModelParameter( "p1" ) ); alg4.setChildAlgorithm( c10 ); QVERIFY( alg4.childAlgorithmsDependOnParameter( "p1" ) ); - QgsProcessingModelAlgorithm::ModelParameter vlP; + QgsProcessingModelParameter vlP; alg4.addModelParameter( new QgsProcessingParameterVectorLayer( "layer" ), vlP ); - QgsProcessingModelAlgorithm::ModelParameter field; + QgsProcessingModelParameter field; alg4.addModelParameter( new QgsProcessingParameterField( "field", QString(), QVariant(), QStringLiteral( "layer" ) ), field ); QVERIFY( !alg4.otherParametersDependOnParameter( "p1" ) ); QVERIFY( !alg4.otherParametersDependOnParameter( "field" ) ); @@ -4577,31 +4577,31 @@ void TestQgsProcessing::modelerAlgorithm() QgsProcessingModelAlgorithm alg5( "test", "testGroup" ); alg5.helpContent().insert( "author", "me" ); alg5.helpContent().insert( "usage", "run" ); - QgsProcessingModelAlgorithm::ChildAlgorithm alg5c1; + QgsProcessingModelChildAlgorithm alg5c1; alg5c1.setChildId( "cx1" ); alg5c1.setAlgorithmId( "buffer" ); - alg5c1.addParameterSources( "x", QgsProcessingModelAlgorithm::ChildParameterSources() << QgsProcessingModelAlgorithm::ChildParameterSource::fromModelParameter( "p1" ) ); - alg5c1.addParameterSources( "y", QgsProcessingModelAlgorithm::ChildParameterSources() << QgsProcessingModelAlgorithm::ChildParameterSource::fromChildOutput( "cx2", "out3" ) ); - alg5c1.addParameterSources( "z", QgsProcessingModelAlgorithm::ChildParameterSources() << QgsProcessingModelAlgorithm::ChildParameterSource::fromStaticValue( 5 ) ); - alg5c1.addParameterSources( "a", QgsProcessingModelAlgorithm::ChildParameterSources() << QgsProcessingModelAlgorithm::ChildParameterSource::fromExpression( "2*2" ) ); - alg5c1.addParameterSources( "zm", QgsProcessingModelAlgorithm::ChildParameterSources() << QgsProcessingModelAlgorithm::ChildParameterSource::fromStaticValue( 6 ) - << QgsProcessingModelAlgorithm::ChildParameterSource::fromModelParameter( "p2" ) - << QgsProcessingModelAlgorithm::ChildParameterSource::fromChildOutput( "cx2", "out4" ) - << QgsProcessingModelAlgorithm::ChildParameterSource::fromExpression( "1+2" ) ); + alg5c1.addParameterSources( "x", QgsProcessingModelChildParameterSources() << QgsProcessingModelChildParameterSource::fromModelParameter( "p1" ) ); + alg5c1.addParameterSources( "y", QgsProcessingModelChildParameterSources() << QgsProcessingModelChildParameterSource::fromChildOutput( "cx2", "out3" ) ); + alg5c1.addParameterSources( "z", QgsProcessingModelChildParameterSources() << QgsProcessingModelChildParameterSource::fromStaticValue( 5 ) ); + alg5c1.addParameterSources( "a", QgsProcessingModelChildParameterSources() << QgsProcessingModelChildParameterSource::fromExpression( "2*2" ) ); + alg5c1.addParameterSources( "zm", QgsProcessingModelChildParameterSources() << QgsProcessingModelChildParameterSource::fromStaticValue( 6 ) + << QgsProcessingModelChildParameterSource::fromModelParameter( "p2" ) + << QgsProcessingModelChildParameterSource::fromChildOutput( "cx2", "out4" ) + << QgsProcessingModelChildParameterSource::fromExpression( "1+2" ) ); alg5c1.setActive( true ); alg5c1.setOutputsCollapsed( true ); alg5c1.setParametersCollapsed( true ); alg5c1.setDescription( "child 1" ); alg5c1.setPosition( QPointF( 1, 2 ) ); - QMap alg5c1outputs; - QgsProcessingModelAlgorithm::ModelOutput alg5c1out1; + QMap alg5c1outputs; + QgsProcessingModelOutput alg5c1out1; alg5c1out1.setDescription( QStringLiteral( "my output" ) ); alg5c1out1.setPosition( QPointF( 3, 4 ) ); alg5c1outputs.insert( QStringLiteral( "a" ), alg5c1out1 ); alg5c1.setModelOutputs( alg5c1outputs ); alg5.addChildAlgorithm( alg5c1 ); - QgsProcessingModelAlgorithm::ChildAlgorithm alg5c2; + QgsProcessingModelChildAlgorithm alg5c2; alg5c2.setChildId( "cx2" ); alg5c2.setActive( false ); alg5c2.setOutputsCollapsed( false ); @@ -4609,7 +4609,7 @@ void TestQgsProcessing::modelerAlgorithm() alg5c2.setDependencies( QStringList() << "a" << "b" ); alg5.addChildAlgorithm( alg5c2 ); - QgsProcessingModelAlgorithm::ModelParameter alg5pc1; + QgsProcessingModelParameter alg5pc1; alg5pc1.setParameterName( QStringLiteral( "my_param" ) ); alg5pc1.setPosition( QPointF( 11, 12 ) ); alg5.addModelParameter( new QgsProcessingParameterBoolean( QStringLiteral( "my_param" ) ), alg5pc1 ); @@ -4623,7 +4623,7 @@ void TestQgsProcessing::modelerAlgorithm() QCOMPARE( alg6.name(), QStringLiteral( "test" ) ); QCOMPARE( alg6.group(), QStringLiteral( "testGroup" ) ); QCOMPARE( alg6.helpContent(), alg5.helpContent() ); - QgsProcessingModelAlgorithm::ChildAlgorithm alg6c1 = alg6.childAlgorithm( "cx1" ); + QgsProcessingModelChildAlgorithm alg6c1 = alg6.childAlgorithm( "cx1" ); QCOMPARE( alg6c1.childId(), QStringLiteral( "cx1" ) ); QCOMPARE( alg6c1.algorithmId(), QStringLiteral( "buffer" ) ); QVERIFY( alg6c1.isActive() ); @@ -4633,24 +4633,24 @@ void TestQgsProcessing::modelerAlgorithm() QCOMPARE( alg6c1.position().x(), 1.0 ); QCOMPARE( alg6c1.position().y(), 2.0 ); QCOMPARE( alg6c1.parameterSources().count(), 5 ); - QCOMPARE( alg6c1.parameterSources().value( "x" ).at( 0 ).source(), QgsProcessingModelAlgorithm::ChildParameterSource::ModelParameter ); + QCOMPARE( alg6c1.parameterSources().value( "x" ).at( 0 ).source(), QgsProcessingModelChildParameterSource::ModelParameter ); QCOMPARE( alg6c1.parameterSources().value( "x" ).at( 0 ).parameterName(), QStringLiteral( "p1" ) ); - QCOMPARE( alg6c1.parameterSources().value( "y" ).at( 0 ).source(), QgsProcessingModelAlgorithm::ChildParameterSource::ChildOutput ); + QCOMPARE( alg6c1.parameterSources().value( "y" ).at( 0 ).source(), QgsProcessingModelChildParameterSource::ChildOutput ); QCOMPARE( alg6c1.parameterSources().value( "y" ).at( 0 ).outputChildId(), QStringLiteral( "cx2" ) ); QCOMPARE( alg6c1.parameterSources().value( "y" ).at( 0 ).outputName(), QStringLiteral( "out3" ) ); - QCOMPARE( alg6c1.parameterSources().value( "z" ).at( 0 ).source(), QgsProcessingModelAlgorithm::ChildParameterSource::StaticValue ); + QCOMPARE( alg6c1.parameterSources().value( "z" ).at( 0 ).source(), QgsProcessingModelChildParameterSource::StaticValue ); QCOMPARE( alg6c1.parameterSources().value( "z" ).at( 0 ).staticValue().toInt(), 5 ); - QCOMPARE( alg6c1.parameterSources().value( "a" ).at( 0 ).source(), QgsProcessingModelAlgorithm::ChildParameterSource::Expression ); + QCOMPARE( alg6c1.parameterSources().value( "a" ).at( 0 ).source(), QgsProcessingModelChildParameterSource::Expression ); QCOMPARE( alg6c1.parameterSources().value( "a" ).at( 0 ).expression(), QStringLiteral( "2*2" ) ); QCOMPARE( alg6c1.parameterSources().value( "zm" ).count(), 4 ); - QCOMPARE( alg6c1.parameterSources().value( "zm" ).at( 0 ).source(), QgsProcessingModelAlgorithm::ChildParameterSource::StaticValue ); + QCOMPARE( alg6c1.parameterSources().value( "zm" ).at( 0 ).source(), QgsProcessingModelChildParameterSource::StaticValue ); QCOMPARE( alg6c1.parameterSources().value( "zm" ).at( 0 ).staticValue().toInt(), 6 ); - QCOMPARE( alg6c1.parameterSources().value( "zm" ).at( 1 ).source(), QgsProcessingModelAlgorithm::ChildParameterSource::ModelParameter ); + QCOMPARE( alg6c1.parameterSources().value( "zm" ).at( 1 ).source(), QgsProcessingModelChildParameterSource::ModelParameter ); QCOMPARE( alg6c1.parameterSources().value( "zm" ).at( 1 ).parameterName(), QStringLiteral( "p2" ) ); - QCOMPARE( alg6c1.parameterSources().value( "zm" ).at( 2 ).source(), QgsProcessingModelAlgorithm::ChildParameterSource::ChildOutput ); + QCOMPARE( alg6c1.parameterSources().value( "zm" ).at( 2 ).source(), QgsProcessingModelChildParameterSource::ChildOutput ); QCOMPARE( alg6c1.parameterSources().value( "zm" ).at( 2 ).outputChildId(), QStringLiteral( "cx2" ) ); QCOMPARE( alg6c1.parameterSources().value( "zm" ).at( 2 ).outputName(), QStringLiteral( "out4" ) ); - QCOMPARE( alg6c1.parameterSources().value( "zm" ).at( 3 ).source(), QgsProcessingModelAlgorithm::ChildParameterSource::Expression ); + QCOMPARE( alg6c1.parameterSources().value( "zm" ).at( 3 ).source(), QgsProcessingModelChildParameterSource::Expression ); QCOMPARE( alg6c1.parameterSources().value( "zm" ).at( 3 ).expression(), QStringLiteral( "1+2" ) ); QCOMPARE( alg6c1.modelOutputs().count(), 1 ); @@ -4660,7 +4660,7 @@ void TestQgsProcessing::modelerAlgorithm() QCOMPARE( alg6c1.modelOutput( "a" ).position().y(), 4.0 ); - QgsProcessingModelAlgorithm::ChildAlgorithm alg6c2 = alg6.childAlgorithm( "cx2" ); + QgsProcessingModelChildAlgorithm alg6c2 = alg6.childAlgorithm( "cx2" ); QCOMPARE( alg6c2.childId(), QStringLiteral( "cx2" ) ); QVERIFY( !alg6c2.isActive() ); QVERIFY( !alg6c2.outputsCollapsed() ); @@ -4677,11 +4677,11 @@ void TestQgsProcessing::modelerAlgorithm() // destination parameters QgsProcessingModelAlgorithm alg7( "test", "testGroup" ); - QgsProcessingModelAlgorithm::ChildAlgorithm alg7c1; + QgsProcessingModelChildAlgorithm alg7c1; alg7c1.setChildId( "cx1" ); alg7c1.setAlgorithmId( "native:centroids" ); - QMap alg7c1outputs; - QgsProcessingModelAlgorithm::ModelOutput alg7c1out1( QStringLiteral( "my_output" ) ); + QMap alg7c1outputs; + QgsProcessingModelOutput alg7c1out1( QStringLiteral( "my_output" ) ); alg7c1out1.setChildId( "cx1" ); alg7c1out1.setChildOutputName( "OUTPUT" ); alg7c1out1.setDescription( QStringLiteral( "my output" ) ); @@ -4697,11 +4697,11 @@ void TestQgsProcessing::modelerAlgorithm() QCOMPARE( alg7.outputDefinitions().at( 0 )->type(), QStringLiteral( "outputVector" ) ); QCOMPARE( alg7.outputDefinitions().at( 0 )->description(), QStringLiteral( "my output" ) ); - QgsProcessingModelAlgorithm::ChildAlgorithm alg7c2; + QgsProcessingModelChildAlgorithm alg7c2; alg7c2.setChildId( "cx2" ); alg7c2.setAlgorithmId( "native:centroids" ); - QMap alg7c2outputs; - QgsProcessingModelAlgorithm::ModelOutput alg7c2out1( QStringLiteral( "my_output2" ) ); + QMap alg7c2outputs; + QgsProcessingModelOutput alg7c2out1( QStringLiteral( "my_output2" ) ); alg7c2out1.setChildId( "cx2" ); alg7c2out1.setChildOutputName( "OUTPUT" ); alg7c2out1.setDescription( QStringLiteral( "my output2" ) ); @@ -4736,19 +4736,19 @@ void TestQgsProcessing::modelExecution() { // test childOutputIsRequired QgsProcessingModelAlgorithm model1; - QgsProcessingModelAlgorithm::ChildAlgorithm algc1; + QgsProcessingModelChildAlgorithm algc1; algc1.setChildId( "cx1" ); algc1.setAlgorithmId( "native:centroids" ); model1.addChildAlgorithm( algc1 ); - QgsProcessingModelAlgorithm::ChildAlgorithm algc2; + QgsProcessingModelChildAlgorithm algc2; algc2.setChildId( "cx2" ); algc2.setAlgorithmId( "native:centroids" ); - algc2.addParameterSources( "x", QgsProcessingModelAlgorithm::ChildParameterSources() << QgsProcessingModelAlgorithm::ChildParameterSource::fromChildOutput( "cx1", "p1" ) ); + algc2.addParameterSources( "x", QgsProcessingModelChildParameterSources() << QgsProcessingModelChildParameterSource::fromChildOutput( "cx1", "p1" ) ); model1.addChildAlgorithm( algc2 ); - QgsProcessingModelAlgorithm::ChildAlgorithm algc3; + QgsProcessingModelChildAlgorithm algc3; algc3.setChildId( "cx3" ); algc3.setAlgorithmId( "native:centroids" ); - algc3.addParameterSources( "x", QgsProcessingModelAlgorithm::ChildParameterSources() << QgsProcessingModelAlgorithm::ChildParameterSource::fromChildOutput( "cx1", "p2" ) ); + algc3.addParameterSources( "x", QgsProcessingModelChildParameterSources() << QgsProcessingModelChildParameterSource::fromChildOutput( "cx1", "p2" ) ); algc3.setActive( false ); model1.addChildAlgorithm( algc3 ); @@ -4760,23 +4760,23 @@ void TestQgsProcessing::modelExecution() // test parametersForChildAlgorithm QgsProcessingModelAlgorithm model2; - model2.addModelParameter( new QgsProcessingParameterFeatureSource( "SOURCE_LAYER" ), QgsProcessingModelAlgorithm::ModelParameter( "SOURCE_LAYER" ) ); - model2.addModelParameter( new QgsProcessingParameterNumber( "DIST", QString(), QgsProcessingParameterNumber::Double ), QgsProcessingModelAlgorithm::ModelParameter( "DIST" ) ); - QgsProcessingModelAlgorithm::ChildAlgorithm alg2c1; + model2.addModelParameter( new QgsProcessingParameterFeatureSource( "SOURCE_LAYER" ), QgsProcessingModelParameter( "SOURCE_LAYER" ) ); + model2.addModelParameter( new QgsProcessingParameterNumber( "DIST", QString(), QgsProcessingParameterNumber::Double ), QgsProcessingModelParameter( "DIST" ) ); + QgsProcessingModelChildAlgorithm alg2c1; QgsExpressionContext expContext; QgsExpressionContextScope *scope = new QgsExpressionContextScope(); scope->setVariable( "myvar", 8 ); expContext.appendScope( scope ); alg2c1.setChildId( "cx1" ); alg2c1.setAlgorithmId( "native:buffer" ); - alg2c1.addParameterSources( "INPUT", QgsProcessingModelAlgorithm::ChildParameterSources() << QgsProcessingModelAlgorithm::ChildParameterSource::fromModelParameter( "SOURCE_LAYER" ) ); - alg2c1.addParameterSources( "DISTANCE", QgsProcessingModelAlgorithm::ChildParameterSources() << QgsProcessingModelAlgorithm::ChildParameterSource::fromModelParameter( "DIST" ) ); - alg2c1.addParameterSources( "SEGMENTS", QgsProcessingModelAlgorithm::ChildParameterSources() << QgsProcessingModelAlgorithm::ChildParameterSource::fromExpression( QStringLiteral( "@myvar*2" ) ) ); - alg2c1.addParameterSources( "END_CAP_STYLE", QgsProcessingModelAlgorithm::ChildParameterSources() << QgsProcessingModelAlgorithm::ChildParameterSource::fromStaticValue( 1 ) ); - alg2c1.addParameterSources( "JOIN_STYLE", QgsProcessingModelAlgorithm::ChildParameterSources() << QgsProcessingModelAlgorithm::ChildParameterSource::fromStaticValue( 2 ) ); - alg2c1.addParameterSources( "DISSOLVE", QgsProcessingModelAlgorithm::ChildParameterSources() << QgsProcessingModelAlgorithm::ChildParameterSource::fromStaticValue( false ) ); - QMap outputs1; - QgsProcessingModelAlgorithm::ModelOutput out1( "MODEL_OUT_LAYER" ); + alg2c1.addParameterSources( "INPUT", QgsProcessingModelChildParameterSources() << QgsProcessingModelChildParameterSource::fromModelParameter( "SOURCE_LAYER" ) ); + alg2c1.addParameterSources( "DISTANCE", QgsProcessingModelChildParameterSources() << QgsProcessingModelChildParameterSource::fromModelParameter( "DIST" ) ); + alg2c1.addParameterSources( "SEGMENTS", QgsProcessingModelChildParameterSources() << QgsProcessingModelChildParameterSource::fromExpression( QStringLiteral( "@myvar*2" ) ) ); + alg2c1.addParameterSources( "END_CAP_STYLE", QgsProcessingModelChildParameterSources() << QgsProcessingModelChildParameterSource::fromStaticValue( 1 ) ); + alg2c1.addParameterSources( "JOIN_STYLE", QgsProcessingModelChildParameterSources() << QgsProcessingModelChildParameterSource::fromStaticValue( 2 ) ); + alg2c1.addParameterSources( "DISSOLVE", QgsProcessingModelChildParameterSources() << QgsProcessingModelChildParameterSource::fromStaticValue( false ) ); + QMap outputs1; + QgsProcessingModelOutput out1( "MODEL_OUT_LAYER" ); out1.setChildOutputName( "OUTPUT" ); outputs1.insert( QStringLiteral( "MODEL_OUT_LAYER" ), out1 ); alg2c1.setModelOutputs( outputs1 ); @@ -4809,11 +4809,11 @@ void TestQgsProcessing::modelExecution() // without values QMap variables = model2.variablesForChildAlgorithm( "cx1", context ); QCOMPARE( variables.count(), 5 ); - QCOMPARE( variables.value( "DIST" ).source.source(), QgsProcessingModelAlgorithm::ChildParameterSource::ModelParameter ); - QCOMPARE( variables.value( "SOURCE_LAYER_minx" ).source.source(), QgsProcessingModelAlgorithm::ChildParameterSource::ModelParameter ); - QCOMPARE( variables.value( "SOURCE_LAYER_miny" ).source.source(), QgsProcessingModelAlgorithm::ChildParameterSource::ModelParameter ); - QCOMPARE( variables.value( "SOURCE_LAYER_maxx" ).source.source(), QgsProcessingModelAlgorithm::ChildParameterSource::ModelParameter ); - QCOMPARE( variables.value( "SOURCE_LAYER_maxy" ).source.source(), QgsProcessingModelAlgorithm::ChildParameterSource::ModelParameter ); + QCOMPARE( variables.value( "DIST" ).source.source(), QgsProcessingModelChildParameterSource::ModelParameter ); + QCOMPARE( variables.value( "SOURCE_LAYER_minx" ).source.source(), QgsProcessingModelChildParameterSource::ModelParameter ); + QCOMPARE( variables.value( "SOURCE_LAYER_miny" ).source.source(), QgsProcessingModelChildParameterSource::ModelParameter ); + QCOMPARE( variables.value( "SOURCE_LAYER_maxx" ).source.source(), QgsProcessingModelChildParameterSource::ModelParameter ); + QCOMPARE( variables.value( "SOURCE_LAYER_maxy" ).source.source(), QgsProcessingModelChildParameterSource::ModelParameter ); // with values variables = model2.variablesForChildAlgorithm( "cx1", context, modelInputs, childResults ); @@ -4838,10 +4838,10 @@ void TestQgsProcessing::modelExecution() childResults.insert( "cx1", results ); // a child who uses an output from another alg as a parameter value - QgsProcessingModelAlgorithm::ChildAlgorithm alg2c2; + QgsProcessingModelChildAlgorithm alg2c2; alg2c2.setChildId( "cx2" ); alg2c2.setAlgorithmId( "native:centroids" ); - alg2c2.addParameterSources( "INPUT", QgsProcessingModelAlgorithm::ChildParameterSources() << QgsProcessingModelAlgorithm::ChildParameterSource::fromChildOutput( "cx1", "OUTPUT" ) ); + alg2c2.addParameterSources( "INPUT", QgsProcessingModelChildParameterSources() << QgsProcessingModelChildParameterSource::fromChildOutput( "cx1", "OUTPUT" ) ); model2.addChildAlgorithm( alg2c2 ); params = model2.parametersForChildAlgorithm( model2.childAlgorithm( "cx2" ), modelInputs, childResults, expContext ); QCOMPARE( params.value( "INPUT" ).toString(), QStringLiteral( "dest.shp" ) ); @@ -4850,18 +4850,18 @@ void TestQgsProcessing::modelExecution() variables = model2.variablesForChildAlgorithm( "cx2", context ); QCOMPARE( variables.count(), 9 ); - QCOMPARE( variables.value( "DIST" ).source.source(), QgsProcessingModelAlgorithm::ChildParameterSource::ModelParameter ); - QCOMPARE( variables.value( "SOURCE_LAYER_minx" ).source.source(), QgsProcessingModelAlgorithm::ChildParameterSource::ModelParameter ); - QCOMPARE( variables.value( "SOURCE_LAYER_miny" ).source.source(), QgsProcessingModelAlgorithm::ChildParameterSource::ModelParameter ); - QCOMPARE( variables.value( "SOURCE_LAYER_maxx" ).source.source(), QgsProcessingModelAlgorithm::ChildParameterSource::ModelParameter ); - QCOMPARE( variables.value( "SOURCE_LAYER_maxy" ).source.source(), QgsProcessingModelAlgorithm::ChildParameterSource::ModelParameter ); - QCOMPARE( variables.value( "cx1_OUTPUT_minx" ).source.source(), QgsProcessingModelAlgorithm::ChildParameterSource::ChildOutput ); + QCOMPARE( variables.value( "DIST" ).source.source(), QgsProcessingModelChildParameterSource::ModelParameter ); + QCOMPARE( variables.value( "SOURCE_LAYER_minx" ).source.source(), QgsProcessingModelChildParameterSource::ModelParameter ); + QCOMPARE( variables.value( "SOURCE_LAYER_miny" ).source.source(), QgsProcessingModelChildParameterSource::ModelParameter ); + QCOMPARE( variables.value( "SOURCE_LAYER_maxx" ).source.source(), QgsProcessingModelChildParameterSource::ModelParameter ); + QCOMPARE( variables.value( "SOURCE_LAYER_maxy" ).source.source(), QgsProcessingModelChildParameterSource::ModelParameter ); + QCOMPARE( variables.value( "cx1_OUTPUT_minx" ).source.source(), QgsProcessingModelChildParameterSource::ChildOutput ); QCOMPARE( variables.value( "cx1_OUTPUT_minx" ).source.outputChildId(), QStringLiteral( "cx1" ) ); - QCOMPARE( variables.value( "cx1_OUTPUT_miny" ).source.source(), QgsProcessingModelAlgorithm::ChildParameterSource::ChildOutput ); + QCOMPARE( variables.value( "cx1_OUTPUT_miny" ).source.source(), QgsProcessingModelChildParameterSource::ChildOutput ); QCOMPARE( variables.value( "cx1_OUTPUT_miny" ).source.outputChildId(), QStringLiteral( "cx1" ) ); - QCOMPARE( variables.value( "cx1_OUTPUT_maxx" ).source.source(), QgsProcessingModelAlgorithm::ChildParameterSource::ChildOutput ); + QCOMPARE( variables.value( "cx1_OUTPUT_maxx" ).source.source(), QgsProcessingModelChildParameterSource::ChildOutput ); QCOMPARE( variables.value( "cx1_OUTPUT_maxx" ).source.outputChildId(), QStringLiteral( "cx1" ) ); - QCOMPARE( variables.value( "cx1_OUTPUT_maxy" ).source.source(), QgsProcessingModelAlgorithm::ChildParameterSource::ChildOutput ); + QCOMPARE( variables.value( "cx1_OUTPUT_maxy" ).source.source(), QgsProcessingModelChildParameterSource::ChildOutput ); QCOMPARE( variables.value( "cx1_OUTPUT_maxy" ).source.outputChildId(), QStringLiteral( "cx1" ) ); // with values @@ -4874,15 +4874,15 @@ void TestQgsProcessing::modelExecution() QGSCOMPARENEAR( variables.value( "SOURCE_LAYER_maxy" ).value.toDouble(), 46.8719, 0.001 ); // a child with an optional output - QgsProcessingModelAlgorithm::ChildAlgorithm alg2c3; + QgsProcessingModelChildAlgorithm alg2c3; alg2c3.setChildId( "cx3" ); alg2c3.setAlgorithmId( "native:extractbyexpression" ); - alg2c3.addParameterSources( "INPUT", QgsProcessingModelAlgorithm::ChildParameterSources() << QgsProcessingModelAlgorithm::ChildParameterSource::fromChildOutput( "cx1", "OUTPUT" ) ); - alg2c3.addParameterSources( "EXPRESSION", QgsProcessingModelAlgorithm::ChildParameterSources() << QgsProcessingModelAlgorithm::ChildParameterSource::fromStaticValue( "true" ) ); - alg2c3.addParameterSources( "OUTPUT", QgsProcessingModelAlgorithm::ChildParameterSources() << QgsProcessingModelAlgorithm::ChildParameterSource::fromModelParameter( "MY_OUT" ) ); + alg2c3.addParameterSources( "INPUT", QgsProcessingModelChildParameterSources() << QgsProcessingModelChildParameterSource::fromChildOutput( "cx1", "OUTPUT" ) ); + alg2c3.addParameterSources( "EXPRESSION", QgsProcessingModelChildParameterSources() << QgsProcessingModelChildParameterSource::fromStaticValue( "true" ) ); + alg2c3.addParameterSources( "OUTPUT", QgsProcessingModelChildParameterSources() << QgsProcessingModelChildParameterSource::fromModelParameter( "MY_OUT" ) ); alg2c3.setDependencies( QStringList() << "cx2" ); - QMap outputs3; - QgsProcessingModelAlgorithm::ModelOutput out2( "MY_OUT" ); + QMap outputs3; + QgsProcessingModelOutput out2( "MY_OUT" ); out2.setChildOutputName( "OUTPUT" ); outputs3.insert( QStringLiteral( "MY_OUT" ), out2 ); alg2c3.setModelOutputs( outputs3 ); @@ -4899,26 +4899,26 @@ void TestQgsProcessing::modelExecution() variables = model2.variablesForChildAlgorithm( "cx3", context ); QCOMPARE( variables.count(), 13 ); - QCOMPARE( variables.value( "DIST" ).source.source(), QgsProcessingModelAlgorithm::ChildParameterSource::ModelParameter ); - QCOMPARE( variables.value( "SOURCE_LAYER_minx" ).source.source(), QgsProcessingModelAlgorithm::ChildParameterSource::ModelParameter ); - QCOMPARE( variables.value( "SOURCE_LAYER_miny" ).source.source(), QgsProcessingModelAlgorithm::ChildParameterSource::ModelParameter ); - QCOMPARE( variables.value( "SOURCE_LAYER_maxx" ).source.source(), QgsProcessingModelAlgorithm::ChildParameterSource::ModelParameter ); - QCOMPARE( variables.value( "SOURCE_LAYER_maxy" ).source.source(), QgsProcessingModelAlgorithm::ChildParameterSource::ModelParameter ); - QCOMPARE( variables.value( "cx1_OUTPUT_minx" ).source.source(), QgsProcessingModelAlgorithm::ChildParameterSource::ChildOutput ); + QCOMPARE( variables.value( "DIST" ).source.source(), QgsProcessingModelChildParameterSource::ModelParameter ); + QCOMPARE( variables.value( "SOURCE_LAYER_minx" ).source.source(), QgsProcessingModelChildParameterSource::ModelParameter ); + QCOMPARE( variables.value( "SOURCE_LAYER_miny" ).source.source(), QgsProcessingModelChildParameterSource::ModelParameter ); + QCOMPARE( variables.value( "SOURCE_LAYER_maxx" ).source.source(), QgsProcessingModelChildParameterSource::ModelParameter ); + QCOMPARE( variables.value( "SOURCE_LAYER_maxy" ).source.source(), QgsProcessingModelChildParameterSource::ModelParameter ); + QCOMPARE( variables.value( "cx1_OUTPUT_minx" ).source.source(), QgsProcessingModelChildParameterSource::ChildOutput ); QCOMPARE( variables.value( "cx1_OUTPUT_minx" ).source.outputChildId(), QStringLiteral( "cx1" ) ); - QCOMPARE( variables.value( "cx1_OUTPUT_miny" ).source.source(), QgsProcessingModelAlgorithm::ChildParameterSource::ChildOutput ); + QCOMPARE( variables.value( "cx1_OUTPUT_miny" ).source.source(), QgsProcessingModelChildParameterSource::ChildOutput ); QCOMPARE( variables.value( "cx1_OUTPUT_miny" ).source.outputChildId(), QStringLiteral( "cx1" ) ); - QCOMPARE( variables.value( "cx1_OUTPUT_maxx" ).source.source(), QgsProcessingModelAlgorithm::ChildParameterSource::ChildOutput ); + QCOMPARE( variables.value( "cx1_OUTPUT_maxx" ).source.source(), QgsProcessingModelChildParameterSource::ChildOutput ); QCOMPARE( variables.value( "cx1_OUTPUT_maxx" ).source.outputChildId(), QStringLiteral( "cx1" ) ); - QCOMPARE( variables.value( "cx1_OUTPUT_maxy" ).source.source(), QgsProcessingModelAlgorithm::ChildParameterSource::ChildOutput ); + QCOMPARE( variables.value( "cx1_OUTPUT_maxy" ).source.source(), QgsProcessingModelChildParameterSource::ChildOutput ); QCOMPARE( variables.value( "cx1_OUTPUT_maxy" ).source.outputChildId(), QStringLiteral( "cx1" ) ); - QCOMPARE( variables.value( "cx2_OUTPUT_minx" ).source.source(), QgsProcessingModelAlgorithm::ChildParameterSource::ChildOutput ); + QCOMPARE( variables.value( "cx2_OUTPUT_minx" ).source.source(), QgsProcessingModelChildParameterSource::ChildOutput ); QCOMPARE( variables.value( "cx2_OUTPUT_minx" ).source.outputChildId(), QStringLiteral( "cx2" ) ); - QCOMPARE( variables.value( "cx2_OUTPUT_miny" ).source.source(), QgsProcessingModelAlgorithm::ChildParameterSource::ChildOutput ); + QCOMPARE( variables.value( "cx2_OUTPUT_miny" ).source.source(), QgsProcessingModelChildParameterSource::ChildOutput ); QCOMPARE( variables.value( "cx2_OUTPUT_miny" ).source.outputChildId(), QStringLiteral( "cx2" ) ); - QCOMPARE( variables.value( "cx2_OUTPUT_maxx" ).source.source(), QgsProcessingModelAlgorithm::ChildParameterSource::ChildOutput ); + QCOMPARE( variables.value( "cx2_OUTPUT_maxx" ).source.source(), QgsProcessingModelChildParameterSource::ChildOutput ); QCOMPARE( variables.value( "cx2_OUTPUT_maxx" ).source.outputChildId(), QStringLiteral( "cx2" ) ); - QCOMPARE( variables.value( "cx2_OUTPUT_maxy" ).source.source(), QgsProcessingModelAlgorithm::ChildParameterSource::ChildOutput ); + QCOMPARE( variables.value( "cx2_OUTPUT_maxy" ).source.source(), QgsProcessingModelChildParameterSource::ChildOutput ); QCOMPARE( variables.value( "cx2_OUTPUT_maxy" ).source.outputChildId(), QStringLiteral( "cx2" ) ); // with values variables = model2.variablesForChildAlgorithm( "cx3", context, modelInputs, childResults ); @@ -4948,23 +4948,23 @@ void TestQgsProcessing::modelExecution() void TestQgsProcessing::modelAcceptableValues() { QgsProcessingModelAlgorithm m; - QgsProcessingModelAlgorithm::ModelParameter stringParam1( "string" ); + QgsProcessingModelParameter stringParam1( "string" ); m.addModelParameter( new QgsProcessingParameterString( "string" ), stringParam1 ); - QgsProcessingModelAlgorithm::ModelParameter stringParam2( "string2" ); + QgsProcessingModelParameter stringParam2( "string2" ); m.addModelParameter( new QgsProcessingParameterString( "string2" ), stringParam2 ); - QgsProcessingModelAlgorithm::ModelParameter numParam( "number" ); + QgsProcessingModelParameter numParam( "number" ); m.addModelParameter( new QgsProcessingParameterNumber( "number" ), numParam ); - QgsProcessingModelAlgorithm::ModelParameter tableFieldParam( "field" ); + QgsProcessingModelParameter tableFieldParam( "field" ); m.addModelParameter( new QgsProcessingParameterField( "field" ), tableFieldParam ); - QgsProcessingModelAlgorithm::ModelParameter fileParam( "file" ); + QgsProcessingModelParameter fileParam( "file" ); m.addModelParameter( new QgsProcessingParameterFile( "file" ), fileParam ); // test single types - QgsProcessingModelAlgorithm::ChildParameterSources sources = m.availableSourcesForChild( QString(), QStringList() << "number" ); + QgsProcessingModelChildParameterSources sources = m.availableSourcesForChild( QString(), QStringList() << "number" ); QCOMPARE( sources.count(), 1 ); QCOMPARE( sources.at( 0 ).parameterName(), QStringLiteral( "number" ) ); sources = m.availableSourcesForChild( QString(), QStringList() << "field" ); @@ -4989,7 +4989,7 @@ void TestQgsProcessing::modelAcceptableValues() << QStringLiteral( "file" ) ); // check outputs - QgsProcessingModelAlgorithm::ChildAlgorithm alg2c1; + QgsProcessingModelChildAlgorithm alg2c1; alg2c1.setChildId( "cx1" ); alg2c1.setAlgorithmId( "native:centroids" ); m.addChildAlgorithm( alg2c1 ); @@ -5001,7 +5001,7 @@ void TestQgsProcessing::modelAcceptableValues() QCOMPARE( res, QSet< QString >() << "cx1:OUTPUT" ); // with dependencies between child algs - QgsProcessingModelAlgorithm::ChildAlgorithm alg2c2; + QgsProcessingModelChildAlgorithm alg2c2; alg2c2.setChildId( "cx2" ); alg2c2.setAlgorithmId( "native:centroids" ); alg2c2.setDependencies( QStringList() << "cx1" ); From fedf88ea3d27119a2690557087355d42e7c5e23e Mon Sep 17 00:00:00 2001 From: Nyall Dawson Date: Sat, 8 Jul 2017 20:53:02 +1000 Subject: [PATCH 13/13] Remove redundant sip file --- .../qgsprocessingmodelalgorithm.sip | 955 ------------------ 1 file changed, 955 deletions(-) delete mode 100644 python/core/processing/qgsprocessingmodelalgorithm.sip diff --git a/python/core/processing/qgsprocessingmodelalgorithm.sip b/python/core/processing/qgsprocessingmodelalgorithm.sip deleted file mode 100644 index 884cf58c861..00000000000 --- a/python/core/processing/qgsprocessingmodelalgorithm.sip +++ /dev/null @@ -1,955 +0,0 @@ -/************************************************************************ - * This file has been generated automatically from * - * * - * src/core/processing/qgsprocessingmodelalgorithm.h * - * * - * Do not edit manually ! Edit header and run scripts/sipify.pl again * - ************************************************************************/ - - - - - -class QgsProcessingModelAlgorithm : QgsProcessingAlgorithm -{ -%Docstring - Model based algorithm with processing. -.. versionadded:: 3.0 -%End - -%TypeHeaderCode -#include "qgsprocessingmodelalgorithm.h" -%End - public: - - class ChildParameterSource -{ -%Docstring - Source for the value of a parameter for a child algorithm within a model. -.. versionadded:: 3.0 -%End - -%TypeHeaderCode -#include "qgsprocessingmodelalgorithm.h" -%End - public: - - enum Source - { - ModelParameter, - ChildOutput, - StaticValue, - Expression, - }; - - ChildParameterSource(); -%Docstring - Constructor for ChildParameterSource. It is recommended that the static methods - fromStaticValue(), fromModelParameter(), fromChildOutput() and fromExpression() are used instead. -%End - - bool operator==( const QgsProcessingModelAlgorithm::ChildParameterSource &other ) const; - bool operator!=( const QgsProcessingModelAlgorithm::ChildParameterSource &other ) const; -%Docstring - :rtype: bool -%End - - static QgsProcessingModelAlgorithm::ChildParameterSource fromStaticValue( const QVariant &value ); -%Docstring - Returns a new ChildParameterSource which takes its value from a static ``value``. -.. seealso:: fromModelParameter() -.. seealso:: fromChildOutput() -.. seealso:: fromExpression() - :rtype: QgsProcessingModelAlgorithm.ChildParameterSource -%End - - static QgsProcessingModelAlgorithm::ChildParameterSource fromModelParameter( const QString ¶meterName ); -%Docstring - Returns a new ChildParameterSource which takes its value from a parent model parameter. -.. seealso:: fromStaticValue() -.. seealso:: fromChildOutput() -.. seealso:: fromExpression() - :rtype: QgsProcessingModelAlgorithm.ChildParameterSource -%End - - static QgsProcessingModelAlgorithm::ChildParameterSource fromChildOutput( const QString &childId, const QString &outputName ); -%Docstring - Returns a new ChildParameterSource which takes its value from an output generated by a child algorithm. -.. seealso:: fromStaticValue() -.. seealso:: fromModelParameter() -.. seealso:: fromExpression() - :rtype: QgsProcessingModelAlgorithm.ChildParameterSource -%End - - static QgsProcessingModelAlgorithm::ChildParameterSource fromExpression( const QString &expression ); -%Docstring - Returns a new ChildParameterSource which takes its value from an expression. The expression - is evaluated just before the child algorithm executes, and can use functions available - in its expression context to include results calculated from the child algorithms already - executed by the model. -.. seealso:: fromStaticValue() -.. seealso:: fromChildOutput() -.. seealso:: fromModelParameter() - :rtype: QgsProcessingModelAlgorithm.ChildParameterSource -%End - - Source source() const; -%Docstring - Returns the parameter value's source. - :rtype: Source -%End - - QVariant staticValue() const; -%Docstring - Returns the source's static value. This is only used when the source() is StaticValue. -.. seealso:: setStaticValue() - :rtype: QVariant -%End - - void setStaticValue( const QVariant &value ); -%Docstring - Sets the source's static value. Calling this will also change the source() to StaticValue. -.. seealso:: staticValue() -%End - - QString parameterName() const; -%Docstring - Returns the source's model parameter name. This is only used when the source() is ModelParameter. -.. seealso:: setParameterName() - :rtype: str -%End - - void setParameterName( const QString &name ); -%Docstring - Sets the source's model parameter ``name``. Calling this will also change the source() to ModelParameter. -.. seealso:: parameterName() -%End - - QString outputChildId() const; -%Docstring - Returns the source's child algorithm ID from which the output value will be taken. This is only used when the source() is ChildOutput. -.. seealso:: setOutputChildId() -.. seealso:: outputName() - :rtype: str -%End - - void setOutputChildId( const QString &id ); -%Docstring - Sets the source's child algorithm ``id`` from which the output value will be taken. Calling this will also change the source() to ChildOutput. -.. seealso:: parameterName() -.. seealso:: setOutputName() -%End - - QString outputName() const; -%Docstring - Returns the source's child algorithm output name from which the output value will be taken. This is only used when the source() is ChildOutput. -.. seealso:: setOutputName() -.. seealso:: outputChildId() - :rtype: str -%End - - void setOutputName( const QString &name ); -%Docstring - Sets the source's child algorithm output ``name`` from which the output value will be taken. Calling this will also change the source() to ChildOutput. -.. seealso:: outputName() -.. seealso:: setOutputChildId() -%End - - QString expression() const; -%Docstring - Returns the source's expression. This is only used when the source() is Expression. -.. seealso:: setExpression() - :rtype: str -%End - - void setExpression( const QString &expression ); -%Docstring - Sets the source's expression. Calling this will also change the source() to Expression. - The expression is evaluated just before the child algorithm executes, and can use functions available - in its expression context to include results calculated from the child algorithms already - executed by the model. -.. seealso:: expression() -%End - - QVariant toVariant() const; -%Docstring - Saves this source to a QVariant. -.. seealso:: loadVariant() - :rtype: QVariant -%End - - bool loadVariant( const QVariantMap &map ); -%Docstring - Loads this source from a QVariantMap. -.. seealso:: toVariant() - :rtype: bool -%End - - QString asPythonCode() const; -%Docstring - Attempts to convert the source to executable Python code. - :rtype: str -%End - - }; - - - class Component -{ -%Docstring - Represents a component of a model algorithm. -.. versionadded:: 3.0 -%End - -%TypeHeaderCode -#include "qgsprocessingmodelalgorithm.h" -%End - public: - - QString description() const; -%Docstring - Returns the friendly description text for the component. -.. seealso:: setDescription() - :rtype: str -%End - - void setDescription( const QString &description ); -%Docstring - Sets the friendly ``description`` text for the component. -.. seealso:: description() -%End - - QPointF position() const; -%Docstring - Returns the position of the model component within the graphical modeler. -.. seealso:: setPosition() - :rtype: QPointF -%End - - void setPosition( const QPointF &position ); -%Docstring - Sets the ``position`` of the model component within the graphical modeler. -.. seealso:: position() -%End - - protected: - - Component( const QString &description = QString() ); -%Docstring -Only subclasses can be created -%End - - Component( const QgsProcessingModelAlgorithm::Component &other ); -%Docstring -Copies are protected to avoid slicing -%End - - - void saveCommonProperties( QVariantMap &map ) const; -%Docstring - Saves the component properties to a QVariantMap. -.. seealso:: restoreCommonProperties() -%End - - void restoreCommonProperties( const QVariantMap &map ); -%Docstring - Restores the component properties from a QVariantMap. -.. seealso:: saveCommonProperties() -%End - - }; - - class ModelParameter : QgsProcessingModelAlgorithm::Component -{ -%Docstring - Represents an input parameter used by the model. -.. versionadded:: 3.0 -%End - -%TypeHeaderCode -#include "qgsprocessingmodelalgorithm.h" -%End - public: - - ModelParameter( const QString ¶meterName = QString() ); -%Docstring - Constructor for ModelParameter. The parameter name should match one of the - parameters from the parent model. -%End - - QString parameterName() const; -%Docstring - Returns the associated parameter name. The parameter name should match one of the - parameters from the parent model. -.. seealso:: parameterName() - :rtype: str -%End - - void setParameterName( const QString &name ); -%Docstring - Sets the associated parameter name. The parameter name should match one of the - parameters from the parent model. -.. seealso:: parameterName() -%End - - QVariant toVariant() const; -%Docstring - Saves this parameter to a QVariant. -.. seealso:: loadVariant() - :rtype: QVariant -%End - - bool loadVariant( const QVariantMap &map ); -%Docstring - Loads this parameter from a QVariantMap. -.. seealso:: toVariant() - :rtype: bool -%End - - }; - - - class ModelOutput : QgsProcessingModelAlgorithm::Component -{ -%Docstring - Represents a final output created by the model. -.. versionadded:: 3.0 -%End - -%TypeHeaderCode -#include "qgsprocessingmodelalgorithm.h" -%End - public: - - ModelOutput( const QString &name = QString(), const QString &description = QString() ); -%Docstring - Constructor for ModelOutput with the specified ``name`` and ``description``. -%End - - QString name() const; -%Docstring - Returns the model output name. -.. seealso:: setName() - :rtype: str -%End - - void setName( const QString &name ); -%Docstring - Sets the model output ``name``. -.. seealso:: name() -%End - - QString childId() const; -%Docstring - Returns the child algorithm ID from which this output is generated. -.. seealso:: setChildId() - :rtype: str -%End - - void setChildId( const QString &id ); -%Docstring - Sets the child algorithm ``id`` from which this output is generated. -.. seealso:: childId() -%End - - QString childOutputName() const; -%Docstring - Returns the child algorithm output name from which this output is generated. -.. seealso:: setOutputName() - :rtype: str -%End - - void setChildOutputName( const QString &name ); -%Docstring - Sets the child algorithm output ``name`` from which this output is generated. -.. seealso:: outputName() -%End - - QVariant toVariant() const; -%Docstring - Saves this output to a QVariant. -.. seealso:: loadVariant() - :rtype: QVariant -%End - - bool loadVariant( const QVariantMap &map ); -%Docstring - Loads this output from a QVariantMap. -.. seealso:: toVariant() - :rtype: bool -%End - - }; - - class ChildAlgorithm : QgsProcessingModelAlgorithm::Component -{ -%Docstring - Child algorithm representing a single component of a QgsProcessingModelAlgorithm. -.. versionadded:: 3.0 -%End - -%TypeHeaderCode -#include "qgsprocessingmodelalgorithm.h" -%End - public: - - ChildAlgorithm( const QString &algorithmId = QString() ); -%Docstring - Constructor for ChildAlgorithm. The ``algorithmId`` parameter - should be set to a QgsProcessingAlgorithm algorithm ID. -%End - - QString childId() const; -%Docstring - Returns the child algorithm's unique ID string, used the identify - this child algorithm within its parent model. -.. seealso:: setChildId() -.. seealso:: generateChildId() - :rtype: str -%End - - void setChildId( const QString &id ); -%Docstring - Sets the child algorithm's unique ``id`` string, used the identify - this child algorithm within its parent model. -.. seealso:: childId() -.. seealso:: generateChildId() -%End - - void generateChildId( const QgsProcessingModelAlgorithm &model ); -%Docstring - Automatically generates a unique childId() for the algorithm, - avoiding child IDs which are already present in ``model``. -.. seealso:: childId() -.. seealso:: setChildId() -%End - - QString algorithmId() const; -%Docstring - Returns the underlying child algorithm's ID. -.. seealso:: algorithm() -.. seealso:: setAlgorithmId() - :rtype: str -%End - - void setAlgorithmId( const QString &algorithmId ); -%Docstring - Sets the underlying child algorithm's ID. This - should be set to an existing QgsProcessingAlgorithm algorithm ID. -.. seealso:: algorithm() -.. seealso:: algorithmId() -%End - - const QgsProcessingAlgorithm *algorithm() const; -%Docstring - Returns the underlying child algorithm, or a None - if a matching algorithm is not available. -.. seealso:: algorithmId() - :rtype: QgsProcessingAlgorithm -%End - - QMap< QString, QList< QgsProcessingModelAlgorithm::ChildParameterSource > > parameterSources() const; -%Docstring - Returns a map of parameter sources. The keys are the child algorithm - parameter names, the values are the sources for that parameter. -.. seealso:: setParameterSources() -.. seealso:: addParameterSources() - :rtype: QMap< str, QList< QgsProcessingModelAlgorithm.ChildParameterSource > > -%End - - void setParameterSources( const QMap< QString, QList< QgsProcessingModelAlgorithm::ChildParameterSource > > &sources ); -%Docstring - Sets the map of parameter ``sources``. The keys are the child algorithm - parameter names, the values are the sources for that parameter. -.. seealso:: parameterSources() -.. seealso:: addParameterSources() -%End - - void addParameterSources( const QString &name, const QList< QgsProcessingModelAlgorithm::ChildParameterSource > &source ); -%Docstring - Adds a parameter source. The ``name`` argument should match - one of the child algorithm's parameter names, and the ``sources`` - argument is used to set the sources for that parameter. - - Any existing parameter sources with matching name will be replaced. -.. seealso:: parameterSources() -.. seealso:: setParameterSources() -%End - - bool isActive() const; -%Docstring - Returns true if the child algorithm is active. -.. seealso:: setActive() - :rtype: bool -%End - - void setActive( bool active ); -%Docstring - Sets whether the child algorithm is active. -.. seealso:: isActive() -%End - - QStringList dependencies() const; -%Docstring - Returns the list of child algorithms from the parent model on which this - algorithm is dependent. The returned list contains the id() of the - dependent algorithms. -.. seealso:: setDependencies() - :rtype: list of str -%End - - void setDependencies( const QStringList &dependencies ); -%Docstring - Sets the list of child algorithms from the parent model on which this - algorithm is dependent. The list should contain the id() of the - dependent algorithms. -.. seealso:: dependencies() -%End - - bool parametersCollapsed() const; -%Docstring - Returns true if the list of parameters for this algorithm should be collapsed - in the graphical modeller. -.. seealso:: setParametersCollapsed() -.. seealso:: outputsCollapsed() - :rtype: bool -%End - - void setParametersCollapsed( bool collapsed ); -%Docstring - Sets whether the list of parameters for this algorithm should be collapsed - in the graphical modeller. -.. seealso:: parametersCollapsed() -.. seealso:: setOutputsCollapsed() -%End - - bool outputsCollapsed() const; -%Docstring - Returns true if the list of outputs for this algorithm should be collapsed - in the graphical modeller. -.. seealso:: setParametersCollapsed() -.. seealso:: parametersCollapsed() - :rtype: bool -%End - - void setOutputsCollapsed( bool collapsed ); -%Docstring - Sets whether the list of outputs for this algorithm should be collapsed - in the graphical modeller. -.. seealso:: outputsCollapsed() -.. seealso:: setParametersCollapsed() -%End - - QMap modelOutputs() const; -%Docstring - Returns the map of final model outputs which are generated by this child algorithm. - The keys are the output names from this child algorithm. Only outputs which are - part of the final outputs from the model are included in this map. -.. seealso:: setModelOutputs() -.. seealso:: modelOutput() - :rtype: QMap -%End - - QgsProcessingModelAlgorithm::ModelOutput &modelOutput( const QString &name ); -%Docstring - Returns the final model output with matching ``name``. If no output - exists with the name, a new one will be created and returned. - - If child model outputs are altered by this method, QgsProcessingModelAlgorithm.updateDestinationParameters() - must be called on the parent model. - -.. seealso:: modelOutputs() -.. seealso:: setModelOutputs() - :rtype: QgsProcessingModelAlgorithm.ModelOutput -%End - - void setModelOutputs( const QMap &outputs ); -%Docstring - Sets the map of final model ``outputs`` which are generated by this child algorithm. - Only outputs which are part of the final outputs from the model should be included in this map. - - If child model outputs are altered by this method, QgsProcessingModelAlgorithm.updateDestinationParameters() - must be called on the parent model. - -.. seealso:: modelOutputs() -%End - - QVariant toVariant() const; -%Docstring - Saves this child to a QVariant. -.. seealso:: loadVariant() - :rtype: QVariant -%End - - bool loadVariant( const QVariant &child ); -%Docstring - Loads this child from a QVariant. -.. seealso:: toVariant() - :rtype: bool -%End - - QString asPythonCode() const; -%Docstring - Attempts to convert the child to executable Python code. - :rtype: str -%End - - }; - - QgsProcessingModelAlgorithm( const QString &name = QString(), const QString &group = QString() ); -%Docstring - Constructor for QgsProcessingModelAlgorithm. -%End - - virtual QString name() const; - - virtual QString displayName() const; - - virtual QString group() const; - - virtual QIcon icon() const; - - virtual QString svgIconPath() const; - - virtual QString shortHelpString() const; - - virtual QString helpUrl() const; - - - virtual bool canExecute( QString *errorMessage /Out/ = 0 ) const; - - virtual QString asPythonCommand( const QVariantMap ¶meters, QgsProcessingContext &context ) const; - - virtual QgsProcessingModelAlgorithm *create() const /Factory/; - - - void setName( const QString &name ); -%Docstring - Sets the model ``name``. -.. seealso:: name() -%End - - void setGroup( const QString &group ); -%Docstring - Sets the model ``group``. -.. seealso:: group() -%End - - QMap childAlgorithms() const; -%Docstring - Returns the map of child algorithms contained in the model. The keys - are the child algorithm ids (see QgsProcessingModelAlgorithm.ChildAlgorithm.childId()). -.. seealso:: childAlgorithm() -.. seealso:: setChildAlgorithms() -.. seealso:: addChildAlgorithm() - :rtype: QMap -%End - - void setChildAlgorithms( const QMap &childAlgorithms ); -%Docstring - Sets the map of child algorithms contained in the model. The keys - are the child algorithm ids (see QgsProcessingModelAlgorithm.ChildAlgorithm.childId()). - All existing child algorithms will be replaced. -.. seealso:: childAlgorithms() -.. seealso:: childAlgorithm() -.. seealso:: setChildAlgorithm() -.. seealso:: addChildAlgorithm() -%End - - void setChildAlgorithm( const QgsProcessingModelAlgorithm::ChildAlgorithm &algorithm ); -%Docstring - Sets the child ``algorithm`` within the model. If a child algorithm already - exists in the model with the same child ID then that algorithm will be replaced. -.. seealso:: addChildAlgorithm() -.. seealso:: setChildAlgorithms() -%End - - QString addChildAlgorithm( QgsProcessingModelAlgorithm::ChildAlgorithm &algorithm ); -%Docstring - Adds a new child ``algorithm`` to the model. If a child algorithm already exists - in the model with the same child ID then ``algorithm`` will be assigned a new - autogenerated unique ID. - The assigned child ID will be returned. -.. seealso:: childAlgorithms() -.. seealso:: childAlgorithm() -.. seealso:: setChildAlgorithm() -.. seealso:: setChildAlgorithms() - :rtype: str -%End - - QgsProcessingModelAlgorithm::ChildAlgorithm &childAlgorithm( const QString &id ); -%Docstring - Returns the child algorithm with matching ``id``. If no child algorithm exists with - this ID a new algorithm will be added to the model and returned. -.. seealso:: addChildAlgorithm() -.. seealso:: childAlgorithms() - :rtype: QgsProcessingModelAlgorithm.ChildAlgorithm -%End - - bool removeChildAlgorithm( const QString &id ); -%Docstring - Attempts to remove the child algorithm with matching ``id``. - Returns true if the algorithm could be removed, or false - if the algorithm could not be removed (e.g. due to other - child algorithms depending on it). -.. seealso:: deactivateChildAlgorithm() - :rtype: bool -%End - - void deactivateChildAlgorithm( const QString &id ); -%Docstring - Deactivates the child algorithm with matching ``id``. - All other child algorithms which depend on the child - algorithm will also be deactivated. -.. seealso:: removeChildAlgorithm() -.. seealso:: activateChildAlgorithm() -%End - - bool activateChildAlgorithm( const QString &id ); -%Docstring - Attempts to activate the child algorithm with matching ``id``. - If any child algorithms on which the child depends are not active, - then the child will not be activated and false will be returned. -.. seealso:: deactivateChildAlgorithm() - :rtype: bool -%End - - QSet< QString > dependentChildAlgorithms( const QString &childId ) const; -%Docstring - Returns a list of the child algorithm IDs depending on the child - algorithm with the specified ``childId``. -.. seealso:: dependsOnChildAlgorithms() - :rtype: set of str -%End - - QSet< QString > dependsOnChildAlgorithms( const QString &childId ) const; -%Docstring - Returns a list of the child algorithm IDs on which the child - algorithm with the specified ``childId`` depends upon. -.. seealso:: dependentChildAlgorithms() - :rtype: set of str -%End - - void addModelParameter( QgsProcessingParameterDefinition *definition /Transfer/, const QgsProcessingModelAlgorithm::ModelParameter &component ); -%Docstring - Adds a new parameter to the model, with the specified ``definition`` and graphical ``component``. - Ownership of ``definition`` is transferred to the model. -.. seealso:: updateModelParameter() -.. seealso:: removeModelParameter() -%End - - void updateModelParameter( QgsProcessingParameterDefinition *definition /Transfer/ ); -%Docstring - Replaces the definition of an existing parameter (by parameter name) with a new ``definition``. Ownership of - ``definition`` is transferred to the model, and any existing parameter is deleted. -.. seealso:: addModelParameter() -.. seealso:: removeModelParameter() -%End - - void removeModelParameter( const QString &name ); -%Docstring - Removes an existing model parameter by ``name``. The definition of the matching parameter - is deleted. -.. seealso:: addModelParameter() -.. seealso:: updateModelParameter() -%End - - bool childAlgorithmsDependOnParameter( const QString &name ) const; -%Docstring - Returns true if any child algorithms depend on the model parameter - with the specified ``name``. -.. seealso:: otherParametersDependOnParameter() - :rtype: bool -%End - - bool otherParametersDependOnParameter( const QString &name ) const; -%Docstring - Returns true if any other model parameters depend on the parameter - with the specified ``name`` (e.g. field parameters where ``name`` - is the parent layer parameter). -.. seealso:: childAlgorithmsDependOnParameter() - :rtype: bool -%End - - QMap parameterComponents() const; -%Docstring - Returns the map of parameter components used by the model. The keys - should match the algorithm's parameter names (see parameterDefinitions() ). -.. seealso:: setParameterComponent() -.. seealso:: parameterComponent() - :rtype: QMap -%End - - void setParameterComponents( const QMap ¶meterComponents ); -%Docstring - Sets the map of parameter components used by the model. The keys - should match the algorithm's parameter names (see parameterDefinitions() ). - All existing parameter components will be replaced. -.. seealso:: parameterComponents() -.. seealso:: setParameterComponent() -.. seealso:: parameterComponent() -%End - - void setParameterComponent( const QgsProcessingModelAlgorithm::ModelParameter &component ); -%Docstring - Sets a parameter ``component`` for the model. If a parameter component already - exists in the model with the same parameter name then that component will be replaced. -.. seealso:: parameterComponents() -.. seealso:: setParameterComponents() -.. seealso:: parameterComponent() -%End - - QgsProcessingModelAlgorithm::ModelParameter ¶meterComponent( const QString &name ); -%Docstring - Returns the parameter component with matching ``name``. If no parameter component exists with - this name a new component will be added to the model and returned. -.. seealso:: parameterComponents() -.. seealso:: setParameterComponents() -.. seealso:: setParameterComponent() - :rtype: QgsProcessingModelAlgorithm.ModelParameter -%End - - void updateDestinationParameters(); -%Docstring - Updates the model's parameter definitions to include all relevant destination - parameters as required by child algorithm ModelOutputs. - Must be called whenever child algorithm ModelOutputs are altered. -%End - - bool toFile( const QString &path ) const; -%Docstring - Writes the model to a file, at the specified ``path``. -.. seealso:: fromFile() - :rtype: bool -%End - - bool fromFile( const QString &path ); -%Docstring - Reads the model from a file, at the specified ``path``. -.. seealso:: toFile() - :rtype: bool -%End - - QVariantMap &helpContent(); -%Docstring - Returns the model's help contents (a free-form map of values describing the algorithm's - use and metadata). -.. seealso:: setHelpContent() - :rtype: QVariantMap -%End - - - void setHelpContent( const QVariantMap &contents ); -%Docstring - Sets the model's help ``contents`` (a free-form map of values describing the algorithm's - use and metadata). -.. seealso:: helpContent() -%End - - QString sourceFilePath() const; -%Docstring - Returns the source file path for the model, if available. -.. seealso:: setSourceFilePath() - :rtype: str -%End - - void setSourceFilePath( const QString &path ); -%Docstring - Sets the source file ``path`` for the model, if available. -.. seealso:: sourceFilePath() -%End - - QString asPythonCode() const; -%Docstring - Attempts to convert the model to executable Python code. - :rtype: str -%End - - QList< QgsProcessingModelAlgorithm::ChildParameterSource > availableSourcesForChild( const QString &childId, const QStringList ¶meterTypes = QStringList(), - const QStringList &outputTypes = QStringList(), const QList< int > dataTypes = QList< int >() ) const; -%Docstring - Returns a list of possible sources which can be used for the parameters for a child - algorithm in the model. Returned sources are those which match either one of the - specified ``parameterTypes`` (see QgsProcessingParameterDefinition.type() ) or - on of the specified ``outputTypes`` (see QgsProcessingOutputDefinition.type() ). - If specified, an optional list of ``dataTypes`` can be used to filter the returned - sources to those with compatible data types for the parameter/outputs. - :rtype: list of QgsProcessingModelAlgorithm.ChildParameterSource -%End - - class VariableDefinition -{ -%Docstring - Definition of a expression context variable available during model execution. -.. versionadded:: 3.0 -%End - -%TypeHeaderCode -#include "qgsprocessingmodelalgorithm.h" -%End - public: - - VariableDefinition( const QVariant &value = QVariant(), const QgsProcessingModelAlgorithm::ChildParameterSource &source = QgsProcessingModelAlgorithm::ChildParameterSource::fromStaticValue( QVariant() ), const QString &description = QString() ); -%Docstring - Constructor for a new VariableDefinition with the specified ``value`` and original - parameter ``source``, and ``description``. -%End - - QVariant value; -%Docstring -Value of variable -%End - - QgsProcessingModelAlgorithm::ChildParameterSource source; -%Docstring -Original source of variable's value -%End - - QString description; -%Docstring -Translated description of variable -%End - }; - - QMap< QString, QgsProcessingModelAlgorithm::VariableDefinition > variablesForChildAlgorithm( const QString &childId, QgsProcessingContext &context, const QVariantMap &modelParameters = QVariantMap(), - const QVariantMap &results = QVariantMap() ) const; -%Docstring - Returns a map of variable name to variable definition for expression context variables which are available - for use by child algorithm during model execution. - - The child algorithm ``childId`` and processing ``context`` - are manadatory. If ``modelParameters`` and ``results`` are not specified, then only the variable names and sources - will be returned, but all variable values will be null. This can be used to determine in advance which variables - will be available for a specific child algorithm, e.g. for use in expression builder widgets. - - In order to calculate the actual variable value, the input model ``modelParameters`` and already executed child - algorithm ``results`` must be passed. -.. seealso:: createExpressionContextScopeForChildAlgorithm() - :rtype: QMap< str, QgsProcessingModelAlgorithm.VariableDefinition > -%End - - QgsExpressionContextScope *createExpressionContextScopeForChildAlgorithm( const QString &childId, QgsProcessingContext &context, const QVariantMap &modelParameters = QVariantMap(), - const QVariantMap &results = QVariantMap() ) const /Factory/; -%Docstring - Creates a new expression context scope for a child algorithm within the model. -.. seealso:: variablesForChildAlgorithm() - :rtype: QgsExpressionContextScope -%End - - protected: - - virtual QVariantMap processAlgorithm( const QVariantMap ¶meters, QgsProcessingContext &context, QgsProcessingFeedback *feedback ); - - -}; - - - - -/************************************************************************ - * This file has been generated automatically from * - * * - * src/core/processing/qgsprocessingmodelalgorithm.h * - * * - * Do not edit manually ! Edit header and run scripts/sipify.pl again * - ************************************************************************/