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.
  • Loading branch information
volaya authored and nyalldawson committed Jan 29, 2019
1 parent 8446d3b commit 6eaa511eed775ce36328a3e1465c32dfb82507aa
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,
@@ -79,7 +80,8 @@
QgsProcessingModelChildParameterSource,
QgsProcessingModelAlgorithm,
QgsRasterDataProvider,
NULL)
NULL,
Qgis)

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

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

def createWidget(self):
self.fileBasedLayers = {}
if self.dialogType == DIALOG_STANDARD:
widget = QWidget()
layout = QHBoxLayout()
@@ -1615,14 +1619,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 6eaa511

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