Skip to content
Permalink
Browse files

Teach the AlgorithmExecutor to count up to 100

  • Loading branch information
github-actions authored and nyalldawson committed Apr 27, 2020
1 parent 24dc23e commit 1ddc74a10234790cbdf864f1c833579a4d7f43df
Showing with 5 additions and 4 deletions.
  1. +5 −4 python/plugins/processing/gui/AlgorithmExecutor.py
@@ -172,7 +172,6 @@ def execute_in_place_run(alg, parameters, context=None, feedback=None, raise_exc
feature_iterator = active_layer.getFeatures(iterator_req)
step = 100 / len(active_layer.selectedFeatureIds()) if active_layer.selectedFeatureIds() else 1
for current, f in enumerate(feature_iterator):
feedback.setProgress(current * step)
if feedback.isCanceled():
break

@@ -206,6 +205,8 @@ def execute_in_place_run(alg, parameters, context=None, feedback=None, raise_exc
new_ids = set([f.id() for f in active_layer.getFeatures(req)])
new_feature_ids += list(new_ids - old_ids)

feedback.setProgress(int((current + 1) * step))

results, ok = {}, True

else: # Traditional 'run' with delete and add features cycle
@@ -314,7 +315,7 @@ def executeIterating(alg, parameters, paramToIter, context, feedback):
if iter_source.featureCount() == 0:
return False

total = 100.0 / iter_source.featureCount()
step = 100.0 / iter_source.featureCount()
for current, feat in enumerate(iter_source.getFeatures()):
if feedback.isCanceled():
return False
@@ -324,7 +325,7 @@ def executeIterating(alg, parameters, paramToIter, context, feedback):
sink.addFeature(feat, QgsFeatureSink.FastInsert)
del sink

feedback.setProgress(int(current * total))
feedback.setProgress(int((current + 1) * step))

# store output values to use them later as basenames for all outputs
outputs = {}
@@ -345,7 +346,7 @@ def executeIterating(alg, parameters, paramToIter, context, feedback):
o = outputs[out.name()]
parameters[out.name()] = QgsProcessingUtils.generateIteratingDestination(o, i, context)
feedback.setProgressText(QCoreApplication.translate('AlgorithmExecutor', 'Executing iteration {0}/{1}…').format(i + 1, len(sink_list)))
feedback.setProgress(i * 100 / len(sink_list))
feedback.setProgress(int((i + 1) * 100 / len(sink_list)))
ret, results = execute(alg, parameters, context, feedback)
if not ret:
return False

0 comments on commit 1ddc74a

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