Skip to content

Commit

Permalink
[processing] Add a flag for algorithms to indicate that they should
Browse files Browse the repository at this point in the history
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
  • Loading branch information
nyalldawson committed Jul 29, 2020
1 parent 8049da8 commit 937a41a
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 0 deletions.
Expand Up @@ -49,6 +49,7 @@ Abstract base class for processing algorithms.
FlagCustomException,
FlagPruneModelBranchesBasedOnAlgorithmResults,
FlagSkipGenericModelLogging,
FlagNotAvailableInStandaloneTool,
FlagDeprecated,
};
typedef QFlags<QgsProcessingAlgorithm::Flag> Flags;
Expand Down
1 change: 1 addition & 0 deletions src/core/processing/qgsprocessingalgorithm.h
Expand Up @@ -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 )
Expand Down
9 changes: 9 additions & 0 deletions src/process/qgsprocess.cpp
Expand Up @@ -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";
}

Expand Down Expand Up @@ -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";
Expand Down

0 comments on commit 937a41a

Please sign in to comment.