Skip to content
Permalink
Browse files

[processing] use InputLayerSelectorPanel for vector layers

  • Loading branch information
volaya committed Oct 5, 2016
1 parent c605c67 commit a20c86c0c3fc82c063584bc1063832ddca704685
Showing with 30 additions and 13 deletions.
  1. +10 −1 python/plugins/processing/gui/InputLayerSelectorPanel.py
  2. +20 −12 python/plugins/processing/gui/wrappers.py
@@ -29,7 +29,7 @@
import os

from qgis.PyQt import uic
from qgis.PyQt.QtCore import QSettings
from qgis.PyQt.QtCore import QSettings, pyqtSignal
from qgis.PyQt.QtGui import QIcon
from qgis.PyQt.QtWidgets import QFileDialog
from processing.tools import dataobjects
@@ -41,6 +41,8 @@

class InputLayerSelectorPanel(BASE, WIDGET):

valueHasChanged = pyqtSignal()

def __init__(self, options, param):
super(InputLayerSelectorPanel, self).__init__(None)
self.setupUi(self)
@@ -55,6 +57,7 @@ def __init__(self, options, param):
self.cmbText.addItem(name, value)

self.btnSelect.clicked.connect(self.showSelectionDialog)
self.cmbText.currentIndexChanged.connect(self.valueHasChanged.emit)

def showSelectionDialog(self):
settings = QSettings()
@@ -77,5 +80,11 @@ def showSelectionDialog(self):
self.cmbText.addItem(filename, filename)
self.cmbText.setCurrentIndex(self.cmbText.count() - 1)

def update(self, options):
self.cmbText.clear()
for (name, value) in options:
self.cmbText.addItem(name, value)
self.valueHasChanged.emit()

def getValue(self):
return self.cmbText.itemData(self.cmbText.currentIndex())
@@ -490,13 +490,13 @@ def createWidget(self):
return widget

def refresh(self):
self.widget.cmbText.clear()
layers = dataobjects.getRasterLayers(self)
layers.sort(key=lambda lay: lay.name())
items = []
layers = dataobjects.getRasterLayers()
if self.param.optional:
self.widget.cmbText.addItem(self.NOT_SELECTED, None)
items.append((self.NOT_SELECTED, None))
for layer in layers:
self.widget.cmbText.addItem(getExtendedLayerName(layer), layer)
items.append((getExtendedLayerName(layer), layer))
self.widget.update(items)

def setValue(self, value):
if self.dialogType == DIALOG_STANDARD:
@@ -551,9 +551,15 @@ class VectorWidgetWrapper(WidgetWrapper):

def createWidget(self):
if self.dialogType == DIALOG_STANDARD:
widget = QComboBox()
self._populate(widget)
widget.currentIndexChanged.connect(lambda: self.widgetValueHasChanged.emit(self))
layers = dataobjects.getVectorLayers(self.param.datatype)
items = []
if self.param.optional:
items.append((self.NOT_SELECTED, None))
for layer in layers:
items.append((getExtendedLayerName(layer), layer))
widget = InputLayerSelectorPanel(items, self.param)
widget.name = self.param.name
widget.valueChanged.connect(lambda: self.widgetValueHasChanged.emit(self))
return widget
elif self.dialogType == DIALOG_BATCH:
widget = BatchInputSelectionPanel(self.param, self.row, self.col, self.dialog)
@@ -570,14 +576,16 @@ def createWidget(self):
return widget

def _populate(self, widget):
widget.clear()
items = []
layers = dataobjects.getVectorLayers(self.param.datatype)
layers.sort(key=lambda lay: lay.name())
if self.param.optional:
widget.addItem(self.NOT_SELECTED, None)
items.append((self.NOT_SELECTED, None))
for layer in layers:
widget.addItem(getExtendedLayerName(layer), layer)
widget.name = self.param.name
items.append((getExtendedLayerName(layer), layer))
self.widget.update(items)



def refresh(self):
self._populate(self.widget)

0 comments on commit a20c86c

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