Skip to content

Commit 40e47e0

Browse files
committedJan 9, 2018
[processing] Add flag to indicate whether an algorithm is safe
to run in a background thread
1 parent 5babec5 commit 40e47e0

File tree

3 files changed

+11
-4
lines changed

3 files changed

+11
-4
lines changed
 

‎python/core/processing/qgsprocessingalgorithm.sip

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ Abstract base class for processing algorithms.
4444
FlagSupportsBatch,
4545
FlagCanCancel,
4646
FlagRequiresMatchingCrs,
47+
FlagCanRunInBackground,
4748
FlagDeprecated,
4849
};
4950
typedef QFlags<QgsProcessingAlgorithm::Flag> Flags;

‎python/plugins/processing/gui/AlgorithmDialog.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@
5353
from processing.gui.ParametersPanel import ParametersPanel
5454
from processing.gui.BatchAlgorithmDialog import BatchAlgorithmDialog
5555
from processing.gui.AlgorithmDialogBase import AlgorithmDialogBase
56-
from processing.gui.AlgorithmExecutor import executeIterating
56+
from processing.gui.AlgorithmExecutor import executeIterating, execute
5757
from processing.gui.Postprocessing import handleAlgorithmResults
5858

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

246-
task = QgsProcessingAlgRunnerTask(self.algorithm(), parameters, context, feedback)
247-
task.executed.connect(on_complete)
248-
QgsApplication.taskManager().addTask(task)
246+
if self.algorithm().flags() & QgsProcessingAlgorithm.FlagCanRunInBackground:
247+
task = QgsProcessingAlgRunnerTask(self.algorithm(), parameters, context, feedback)
248+
task.executed.connect(on_complete)
249+
QgsApplication.taskManager().addTask(task)
250+
else:
251+
self.setWindowModality(Qt.ApplicationModal)
252+
ok, results = execute(self.algorithm(), parameters, context, feedback)
253+
on_complete(ok, results)
249254

250255
except AlgorithmDialogBase.InvalidParameterValue as e:
251256
try:

‎src/core/processing/qgsprocessingalgorithm.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ class CORE_EXPORT QgsProcessingAlgorithm
7272
FlagSupportsBatch = 1 << 3, //!< Algorithm supports batch mode
7373
FlagCanCancel = 1 << 4, //!< Algorithm can be canceled
7474
FlagRequiresMatchingCrs = 1 << 5, //!< Algorithm requires that all input layers have matching coordinate reference systems
75+
FlagCanRunInBackground = 1 << 6, //!< Algorithm is safe to run in a background thread
7576
FlagDeprecated = FlagHideFromToolbox | FlagHideFromModeler, //!< Algorithm is deprecated
7677
};
7778
Q_DECLARE_FLAGS( Flags, Flag )

0 commit comments

Comments
 (0)
Please sign in to comment.