Skip to content

Commit

Permalink
[processing] Add flag to indicate whether an algorithm is safe
Browse files Browse the repository at this point in the history
to run in a background thread
  • Loading branch information
nyalldawson committed Jan 9, 2018
1 parent 5babec5 commit 40e47e0
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 4 deletions.
1 change: 1 addition & 0 deletions python/core/processing/qgsprocessingalgorithm.sip
Expand Up @@ -44,6 +44,7 @@ Abstract base class for processing algorithms.
FlagSupportsBatch,
FlagCanCancel,
FlagRequiresMatchingCrs,
FlagCanRunInBackground,
FlagDeprecated,
};
typedef QFlags<QgsProcessingAlgorithm::Flag> Flags;
Expand Down
13 changes: 9 additions & 4 deletions python/plugins/processing/gui/AlgorithmDialog.py
Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand Down
1 change: 1 addition & 0 deletions src/core/processing/qgsprocessingalgorithm.h
Expand Up @@ -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 )
Expand Down

0 comments on commit 40e47e0

Please sign in to comment.