Skip to content

Commit

Permalink
Add a processing algorithm flag to indicate that an algorithm requires
Browse files Browse the repository at this point in the history
a valid project to be set in the context in order to execute

And flag a bunch of algorithms which require this
  • Loading branch information
nyalldawson committed Jul 29, 2020
1 parent 04e07f0 commit d57a638
Show file tree
Hide file tree
Showing 8 changed files with 21 additions and 2 deletions.
Expand Up @@ -50,6 +50,7 @@ Abstract base class for processing algorithms.
FlagPruneModelBranchesBasedOnAlgorithmResults,
FlagSkipGenericModelLogging,
FlagNotAvailableInStandaloneTool,
FlagRequiresProject,
FlagDeprecated,
};
typedef QFlags<QgsProcessingAlgorithm::Flag> Flags;
Expand Down
Expand Up @@ -55,7 +55,7 @@ def __init__(self):
super().__init__()

def flags(self):
return super().flags() | QgsProcessingAlgorithm.FlagNotAvailableInStandaloneTool
return super().flags() | QgsProcessingAlgorithm.FlagNotAvailableInStandaloneTool | QgsProcessingAlgorithm.FlagRequiresProject

def initAlgorithm(self, config=None):
db_param = QgsProcessingParameterProviderConnection(
Expand Down
6 changes: 5 additions & 1 deletion python/plugins/processing/algs/qgis/TilesXYZ.py
Expand Up @@ -49,7 +49,8 @@
QgsMapRendererCustomPainterJob,
QgsLabelingEngineSettings,
QgsApplication,
QgsExpressionContextUtils)
QgsExpressionContextUtils,
QgsProcessingAlgorithm)
from processing.algs.qgis.QgisAlgorithm import QgisAlgorithm
import threading
from concurrent.futures import ThreadPoolExecutor
Expand Down Expand Up @@ -440,6 +441,9 @@ def group(self):
def groupId(self):
return 'rastertools'

def flags(self):
return super().flags() | QgsProcessingAlgorithm.FlagRequiresProject

def processAlgorithm(self, parameters, context, feedback):
output_file = self.parameterAsString(parameters, self.OUTPUT_FILE, context)
if not output_file:
Expand Down
6 changes: 6 additions & 0 deletions src/analysis/processing/qgsalgorithmnetworkanalysisbase.cpp
Expand Up @@ -37,6 +37,12 @@ QString QgsNetworkAnalysisAlgorithmBase::groupId() const
return QStringLiteral( "networkanalysis" );
}

QgsProcessingAlgorithm::Flags QgsNetworkAnalysisAlgorithmBase::flags() const
{
// TODO -- remove the dependancy on the project from these algorithms, it shouldn't be required
return QgsProcessingAlgorithm::flags() | FlagRequiresProject;
}

void QgsNetworkAnalysisAlgorithmBase::addCommonParams()
{
addParameter( new QgsProcessingParameterFeatureSource( QStringLiteral( "INPUT" ), QObject::tr( "Vector layer representing network" ), QList< int >() << QgsProcessing::TypeVectorLine ) );
Expand Down
1 change: 1 addition & 0 deletions src/analysis/processing/qgsalgorithmnetworkanalysisbase.h
Expand Up @@ -41,6 +41,7 @@ class QgsNetworkAnalysisAlgorithmBase : public QgsProcessingAlgorithm
QString groupId() const final;
QIcon icon() const override { return QgsApplication::getThemeIcon( QStringLiteral( "/algorithms/mAlgorithmNetworkAnalysis.svg" ) ); }
QString svgIconPath() const override { return QgsApplication::iconPath( QStringLiteral( "/algorithms/mAlgorithmNetworkAnalysis.svg" ) ); }
Flags flags() const override;

protected:

Expand Down
5 changes: 5 additions & 0 deletions src/analysis/processing/qgsalgorithmrasterize.cpp
Expand Up @@ -49,6 +49,11 @@ QStringList QgsRasterizeAlgorithm::tags() const
return QObject::tr( "layer,raster,convert,file,map themes,tiles,render" ).split( ',' );
}

QgsProcessingAlgorithm::Flags QgsRasterizeAlgorithm::flags() const
{
return QgsProcessingAlgorithm::flags() | FlagRequiresProject;
}

QString QgsRasterizeAlgorithm::group() const
{
return QObject::tr( "Raster tools" );
Expand Down
1 change: 1 addition & 0 deletions src/analysis/processing/qgsalgorithmrasterize.h
Expand Up @@ -43,6 +43,7 @@ class QgsRasterizeAlgorithm : public QgsProcessingAlgorithm
QString name() const override;
QString displayName() const override;
QStringList tags() const override;
Flags flags() const override;
QString group() const override;
QString groupId() const override;
QString shortHelpString() const override;
Expand Down
1 change: 1 addition & 0 deletions src/core/processing/qgsprocessingalgorithm.h
Expand Up @@ -80,6 +80,7 @@ class CORE_EXPORT QgsProcessingAlgorithm
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.
FlagRequiresProject = 1 << 14, //!< The algorithm requires that a valid QgsProject is available from the processing context in order to execute
FlagDeprecated = FlagHideFromToolbox | FlagHideFromModeler, //!< Algorithm is deprecated
};
Q_DECLARE_FLAGS( Flags, Flag )
Expand Down

0 comments on commit d57a638

Please sign in to comment.