Skip to content
Permalink
Browse files

Add a processing algorithm flag to indicate that an algorithm requires

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 d57a638ec495dcff6a462af2d494562b4398a9f5
@@ -50,6 +50,7 @@ Abstract base class for processing algorithms.
FlagPruneModelBranchesBasedOnAlgorithmResults,
FlagSkipGenericModelLogging,
FlagNotAvailableInStandaloneTool,
FlagRequiresProject,
FlagDeprecated,
};
typedef QFlags<QgsProcessingAlgorithm::Flag> Flags;
@@ -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(
@@ -49,7 +49,8 @@
QgsMapRendererCustomPainterJob,
QgsLabelingEngineSettings,
QgsApplication,
QgsExpressionContextUtils)
QgsExpressionContextUtils,
QgsProcessingAlgorithm)
from processing.algs.qgis.QgisAlgorithm import QgisAlgorithm
import threading
from concurrent.futures import ThreadPoolExecutor
@@ -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:
@@ -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 ) );
@@ -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:

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

0 comments on commit d57a638

Please sign in to comment.
You can’t perform that action at this time.