Skip to content
Permalink
Browse files

[processing] show warning when file-based layer could not be loaded a…

…nd dependent params updated

For algorithms with multiple parameters depending on a vector layer parameter, the code that loads the layer in the background is called repeatedly, impacting performance. A small layer cache is implemented with these changes, so the dialog only tries to load the layer once.

(cherry picked from commit 6eaa511)
  • Loading branch information
volaya authored and nyalldawson committed Jan 29, 2019
1 parent 421fe45 commit 722e4fe30879cdb55ebed85ceb05f95f7dec1630
Showing with 18 additions and 2 deletions.
  1. +18 −2 python/plugins/processing/gui/wrappers.py
@@ -45,6 +45,7 @@
QgsSettings,
QgsProject,
QgsMapLayer,
QgsVectorLayer,
QgsProcessing,
QgsProcessingUtils,
QgsProcessingParameterDefinition,
@@ -78,7 +79,8 @@
QgsProcessingModelChildParameterSource,
QgsProcessingModelAlgorithm,
QgsRasterDataProvider,
NULL)
NULL,
Qgis)

from qgis.PyQt.QtWidgets import (
QCheckBox,
@@ -1049,6 +1051,7 @@ class FeatureSourceWidgetWrapper(WidgetWrapper):
NOT_SELECTED = '[Not selected]'

def createWidget(self):
self.fileBasedLayers = {}
if self.dialogType == DIALOG_STANDARD:
widget = QWidget()
layout = QHBoxLayout()
@@ -1391,6 +1394,7 @@ class VectorLayerWidgetWrapper(WidgetWrapper):
NOT_SELECTED = '[Not selected]'

def createWidget(self):
self.fileBasedLayers = {}
if self.dialogType == DIALOG_STANDARD:
widget = QWidget()
layout = QHBoxLayout()
@@ -1576,14 +1580,26 @@ def postInitialize(self, wrappers):
break

def parentValueChanged(self, wrapper):
self.setLayer(wrapper.parameterValue())
value = wrapper.parameterValue()
if value in wrapper.fileBasedLayers:
self.setLayer(wrapper.fileBasedLayers[value])
else:
self.setLayer(value)
wrapper.fileBasedLayers[value] = self._layer

def setLayer(self, layer):
if isinstance(layer, QgsProcessingFeatureSourceDefinition):
layer, ok = layer.source.valueAsString(self.context.expressionContext())
if isinstance(layer, str):
layer = QgsProcessingUtils.mapLayerFromString(layer, self.context)
if not isinstance(layer, QgsVectorLayer) or not layer.isValid():
self.dialog.messageBar().clearWidgets()
self.dialog.messageBar().pushMessage("", self.tr("Could not load selected layer/table. Dependent field could not be populated"),
level=Qgis.Warning, duration=5)
return

self._layer = layer

self.refreshItems()

def refreshItems(self):

0 comments on commit 722e4fe

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