[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
This commit is contained in:
Nyall Dawson 2020-07-29 08:57:01 +10:00
parent 8049da8daf
commit 937a41a656
3 changed files with 11 additions and 0 deletions

View File

@ -49,6 +49,7 @@ Abstract base class for processing algorithms.
FlagCustomException,
FlagPruneModelBranchesBasedOnAlgorithmResults,
FlagSkipGenericModelLogging,
FlagNotAvailableInStandaloneTool,
FlagDeprecated,
};
typedef QFlags<QgsProcessingAlgorithm::Flag> Flags;

View File

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

View File

@ -314,6 +314,9 @@ void QgsProcessingExec::listAlgorithms()
const QList<const QgsProcessingAlgorithm *> 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 &params, 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";