Skip to content
Permalink
Browse files

[processing] Add flag to indicate whether an algorithm is safe

to run in a background thread
  • Loading branch information
nyalldawson committed Dec 5, 2017
1 parent 5babec5 commit 40e47e0fe75d8c67e27c97c2e86b9009b2c6c2c2
@@ -44,6 +44,7 @@ Abstract base class for processing algorithms.
FlagSupportsBatch,
FlagCanCancel,
FlagRequiresMatchingCrs,
FlagCanRunInBackground,
FlagDeprecated,
};
typedef QFlags<QgsProcessingAlgorithm::Flag> Flags;
@@ -53,7 +53,7 @@
from processing.gui.ParametersPanel import ParametersPanel
from processing.gui.BatchAlgorithmDialog import BatchAlgorithmDialog
from processing.gui.AlgorithmDialogBase import AlgorithmDialogBase
from processing.gui.AlgorithmExecutor import executeIterating
from processing.gui.AlgorithmExecutor import executeIterating, execute
from processing.gui.Postprocessing import handleAlgorithmResults

from processing.tools import dataobjects
@@ -243,9 +243,14 @@ def on_complete(ok, results):
self.cancelButton().setEnabled(False)
self.finish(ok, results, context, feedback)

task = QgsProcessingAlgRunnerTask(self.algorithm(), parameters, context, feedback)
task.executed.connect(on_complete)
QgsApplication.taskManager().addTask(task)
if self.algorithm().flags() & QgsProcessingAlgorithm.FlagCanRunInBackground:
task = QgsProcessingAlgRunnerTask(self.algorithm(), parameters, context, feedback)
task.executed.connect(on_complete)
QgsApplication.taskManager().addTask(task)
else:
self.setWindowModality(Qt.ApplicationModal)
ok, results = execute(self.algorithm(), parameters, context, feedback)
on_complete(ok, results)

except AlgorithmDialogBase.InvalidParameterValue as e:
try:
@@ -72,6 +72,7 @@ class CORE_EXPORT QgsProcessingAlgorithm
FlagSupportsBatch = 1 << 3, //!< Algorithm supports batch mode
FlagCanCancel = 1 << 4, //!< Algorithm can be canceled
FlagRequiresMatchingCrs = 1 << 5, //!< Algorithm requires that all input layers have matching coordinate reference systems
FlagCanRunInBackground = 1 << 6, //!< Algorithm is safe to run in a background thread
FlagDeprecated = FlagHideFromToolbox | FlagHideFromModeler, //!< Algorithm is deprecated
};
Q_DECLARE_FLAGS( Flags, Flag )

0 comments on commit 40e47e0

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