From 937a41a65628efe22389bb38db90e30ec8127462 Mon Sep 17 00:00:00 2001 From: Nyall Dawson Date: Wed, 29 Jul 2020 08:57:01 +1000 Subject: [PATCH] [processing] Add a flag for algorithms to indicate that they should not be available from the standalone qgis_process tool (e.g. "select by " algorithms, which have no meaning outside of a GUI application) These algorithms are hidden from the algorithm list for qgis_process and cannot be run by the tool --- .../processing/qgsprocessingalgorithm.sip.in | 1 + src/core/processing/qgsprocessingalgorithm.h | 1 + src/process/qgsprocess.cpp | 9 +++++++++ 3 files changed, 11 insertions(+) diff --git a/python/core/auto_generated/processing/qgsprocessingalgorithm.sip.in b/python/core/auto_generated/processing/qgsprocessingalgorithm.sip.in index 6b3c8b863c3..2654daf74f2 100644 --- a/python/core/auto_generated/processing/qgsprocessingalgorithm.sip.in +++ b/python/core/auto_generated/processing/qgsprocessingalgorithm.sip.in @@ -49,6 +49,7 @@ Abstract base class for processing algorithms. FlagCustomException, FlagPruneModelBranchesBasedOnAlgorithmResults, FlagSkipGenericModelLogging, + FlagNotAvailableInStandaloneTool, FlagDeprecated, }; typedef QFlags Flags; diff --git a/src/core/processing/qgsprocessingalgorithm.h b/src/core/processing/qgsprocessingalgorithm.h index e1663c9c676..7fcac94b061 100644 --- a/src/core/processing/qgsprocessingalgorithm.h +++ b/src/core/processing/qgsprocessingalgorithm.h @@ -79,6 +79,7 @@ class CORE_EXPORT QgsProcessingAlgorithm FlagCustomException = 1 << 10, //!< Algorithm raises custom exception notices, don't use the standard ones FlagPruneModelBranchesBasedOnAlgorithmResults = 1 << 11, //!< Algorithm results will cause remaining model branches to be pruned based on the results of running the algorithm FlagSkipGenericModelLogging = 1 << 12, //!< When running as part of a model, the generic algorithm setup and results logging should be skipped + FlagNotAvailableInStandaloneTool = 1 << 13, //!< Algorithm should not be available from the standalone "qgis_process" tool. Used to flag algorithms which make no sense outside of the QGIS application, such as "select by..." style algorithms. FlagDeprecated = FlagHideFromToolbox | FlagHideFromModeler, //!< Algorithm is deprecated }; Q_DECLARE_FLAGS( Flags, Flag ) diff --git a/src/process/qgsprocess.cpp b/src/process/qgsprocess.cpp index 3b489b8e0af..236d4cccf39 100644 --- a/src/process/qgsprocess.cpp +++ b/src/process/qgsprocess.cpp @@ -314,6 +314,9 @@ void QgsProcessingExec::listAlgorithms() const QList algorithms = provider->algorithms(); for ( const QgsProcessingAlgorithm *algorithm : algorithms ) { + if ( algorithm->flags() & QgsProcessingAlgorithm::FlagDeprecated || algorithm->flags() & QgsProcessingAlgorithm::FlagNotAvailableInStandaloneTool ) + continue; + std::cout << "\t" << algorithm->id().toLocal8Bit().constData() << "\t" << algorithm->displayName().toLocal8Bit().constData() << "\n"; } @@ -450,6 +453,12 @@ int QgsProcessingExec::execute( const QString &id, const QVariantMap ¶ms, co std::cerr << QStringLiteral( "Algorithm %1 not found!\n" ).arg( id ).toLocal8Bit().constData(); return 1; } + + if ( alg->flags() & QgsProcessingAlgorithm::FlagNotAvailableInStandaloneTool ) + { + std::cerr << QStringLiteral( "The \"%1\" algorithm is not available for use outside of the QGIS desktop application\n" ).arg( id ).toLocal8Bit().constData(); + return 1; + } } std::cout << "\n----------------\n";