Skip to content

Commit

Permalink
[processing] use InputLayerSelectorPanel for vector layers
Browse files Browse the repository at this point in the history
  • Loading branch information
volaya committed Oct 5, 2016
1 parent c605c67 commit a20c86c
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 13 deletions.
11 changes: 10 additions & 1 deletion python/plugins/processing/gui/InputLayerSelectorPanel.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -41,6 +41,8 @@

class InputLayerSelectorPanel(BASE, WIDGET):

valueHasChanged = pyqtSignal()

def __init__(self, options, param):
super(InputLayerSelectorPanel, self).__init__(None)
self.setupUi(self)
Expand All @@ -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()
Expand All @@ -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())
32 changes: 20 additions & 12 deletions python/plugins/processing/gui/wrappers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand Down

0 comments on commit a20c86c

Please sign in to comment.