Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Teach the AlgorithmExecutor to count up to 100
  • Loading branch information
github-actions[bot] authored and nyalldawson committed Apr 27, 2020
1 parent 37aab82 commit bd4173f
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions python/plugins/processing/gui/AlgorithmExecutor.py
Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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 = {}
Expand All @@ -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
Expand Down

0 comments on commit bd4173f

Please sign in to comment.