mirror of
https://github.com/qgis/QGIS.git
synced 2025-04-18 00:03:05 -04:00
[processing] Add flag to indicate whether an algorithm is safe
to run in a background thread
This commit is contained in:
parent
5babec5e07
commit
40e47e0fe7
@ -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.core.ProcessingResults import resultsList
|
||||
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 @@ class AlgorithmDialog(QgsProcessingAlgorithmDialogBase):
|
||||
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 )
|
||||
|
Loading…
x
Reference in New Issue
Block a user