Skip to content
Permalink
Browse files

Only use a temporary feedback object when running algorithms

Otherwise canceling a run causes all future runs to be canceled
  • Loading branch information
nyalldawson committed Jun 11, 2017
1 parent 2d2c229 commit aa544a14c003f3ec813990b9711e35a93901aff6
@@ -164,6 +164,8 @@ def accept(self):

checkCRS = ProcessingConfig.getSetting(ProcessingConfig.WARN_UNMATCHING_CRS)
try:
feedback = self.createFeedback()

parameters = self.getParamValues()

QgsMessageLog.logMessage(str(parameters), 'Processing', QgsMessageLog.CRITICAL)
@@ -220,8 +222,8 @@ def accept(self):
self.tr('<b>Algorithm {0} starting...</b>').format(self.alg.displayName()))

if self.iterateParam:
if executeIterating(self.alg, parameters, self.iterateParam, context, self.feedback):
self.finish(parameters, context)
if executeIterating(self.alg, parameters, self.iterateParam, context, feedback):
self.finish(parameters, context, feedback)
else:
QApplication.restoreOverrideCursor()
self.resetGUI()
@@ -231,9 +233,9 @@ def accept(self):
#if command:
# ProcessingLog.addToLog(command)
self.buttonCancel.setEnabled(self.alg.flags() & QgsProcessingAlgorithm.FlagCanCancel)
result = executeAlgorithm(self.alg, parameters, context, self.feedback)
result = executeAlgorithm(self.alg, parameters, context, feedback)
self.buttonCancel.setEnabled(False)
self.finish(result, context)
self.finish(result, context, feedback)
#TODO
#else:
# QApplication.restoreOverrideCursor()
@@ -251,12 +253,12 @@ def accept(self):
self.bar.pushMessage("", self.tr("Wrong or missing parameter value: {0}").format(e.parameter.description()),
level=QgsMessageBar.WARNING, duration=5)

def finish(self, result, context):
def finish(self, result, context, feedback):
keepOpen = ProcessingConfig.getSetting(ProcessingConfig.KEEP_DIALOG_OPEN)

if self.iterateParam is None:

if not handleAlgorithmResults(self.alg, context, self.feedback, not keepOpen):
if not handleAlgorithmResults(self.alg, context, feedback, not keepOpen):
self.resetGUI()
return

@@ -95,10 +95,6 @@ def __init__(self, alg):
handleLayout.addStretch()
splitterHandle.setLayout(handleLayout)

self.feedback = AlgorithmDialogFeedback(self)
self.feedback.progressChanged.connect(self.setPercentage)
self.buttonCancel.clicked.connect(self.feedback.cancel)

self.settings = QgsSettings()
self.splitter.restoreState(self.settings.value("/Processing/dialogBaseSplitter", QByteArray()))
self.restoreGeometry(self.settings.value("/Processing/dialogBase", QByteArray()))
@@ -147,6 +143,12 @@ def linkClicked(url):
self.showDebug = ProcessingConfig.getSetting(
ProcessingConfig.SHOW_DEBUG_IN_DIALOG)

def createFeedback(self):
feedback = AlgorithmDialogFeedback(self)
feedback.progressChanged.connect(self.setPercentage)
self.buttonCancel.clicked.connect(feedback.cancel)
return feedback

def formatHelp(self, alg):
text = alg.shortHelpString()
if not text:
@@ -223,7 +225,7 @@ def reject(self):
self._saveGeometry()
super(AlgorithmDialogBase, self).reject()

def finish(self, context):
def finish(self, context, feedback):
pass

def toggleCollapsed(self):
@@ -56,7 +56,6 @@ def handleAlgorithmResults(alg, context, feedback=None, showResults=True):
feedback.setProgressText(QCoreApplication.translate('Postprocessing', 'Loading resulting layers'))
i = 0
for l, details in context.layersToLoadOnCompletion().items():
feedback.setProgress(100 * i / float(len(context.layersToLoadOnCompletion())))
try:
layer = QgsProcessingUtils.mapLayerFromString(l, context)
if layer is not None:

0 comments on commit aa544a1

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