Skip to content

Commit be5f951

Browse files
arnaud-morvanvolaya
authored andcommittedOct 5, 2016
Support layer objects in BatchInputSelectionPanel
1 parent 9e36582 commit be5f951

File tree

1 file changed

+26
-11
lines changed

1 file changed

+26
-11
lines changed
 

‎python/plugins/processing/gui/BatchInputSelectionPanel.py

Lines changed: 26 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,12 @@
2929

3030
import os
3131

32-
from qgis.PyQt.QtCore import QSettings
32+
from qgis.PyQt.QtCore import QSettings, pyqtSignal
3333
from qgis.PyQt.QtWidgets import QWidget, QHBoxLayout, QMenu, QPushButton, QLineEdit, QSizePolicy, QAction, QFileDialog
3434
from qgis.PyQt.QtGui import QCursor
3535

36+
from qgis.core import QgsMapLayer
37+
3638
from processing.gui.MultipleInputDialog import MultipleInputDialog
3739

3840
from processing.core.parameters import ParameterMultipleInput
@@ -45,6 +47,8 @@
4547

4648
class BatchInputSelectionPanel(QWidget):
4749

50+
valueChanged = pyqtSignal()
51+
4852
def __init__(self, param, row, col, dialog):
4953
super(BatchInputSelectionPanel, self).__init__(None)
5054
self.param = param
@@ -55,8 +59,10 @@ def __init__(self, param, row, col, dialog):
5559
self.horizontalLayout.setSpacing(0)
5660
self.horizontalLayout.setMargin(0)
5761
self.text = QLineEdit()
62+
self.text.setObjectName('text')
5863
self.text.setMinimumWidth(300)
59-
self.text.setText('')
64+
self.setValue('')
65+
self.text.editingFinished.connect(self.on_text_EditingFinished)
6066
self.text.setSizePolicy(QSizePolicy.Expanding,
6167
QSizePolicy.Expanding)
6268
self.horizontalLayout.addWidget(self.text)
@@ -67,7 +73,7 @@ def __init__(self, param, row, col, dialog):
6773
self.setLayout(self.horizontalLayout)
6874

6975
def _panel(self):
70-
return self.dialog.mainWidget()
76+
return self.dialog.mainWidget
7177

7278
def _table(self):
7379
return self._panel().tblParameters
@@ -118,7 +124,7 @@ def showLayerSelectionDialog(self):
118124
self._panel().addRow()
119125
for i, layeridx in enumerate(selected):
120126
self._table().cellWidget(i + self.row,
121-
self.col).setText(layers[layeridx].name())
127+
self.col).setValue(layers[layeridx])
122128

123129
def showFileSelectionDialog(self):
124130
settings = QSettings()
@@ -151,10 +157,19 @@ def showFileSelectionDialog(self):
151157
self._panel().addRow()
152158
for i, f in enumerate(files):
153159
self._table().cellWidget(i + self.row,
154-
self.col).setText(f)
155-
156-
def setText(self, text):
157-
return self.text.setText(text)
158-
159-
def getText(self):
160-
return self.text.text()
160+
self.col).setValue(f)
161+
162+
def on_text_EditingFinished(self):
163+
self._value = self.text.text()
164+
self.valueChanged.emit()
165+
166+
def value(self):
167+
return self._value
168+
169+
def setValue(self, value):
170+
self._value = value
171+
if isinstance(value, QgsMapLayer):
172+
self.text.setText(value.name())
173+
else: # should be basestring
174+
self.text.setText(value)
175+
self.valueChanged.emit()

0 commit comments

Comments
 (0)
Please sign in to comment.