Skip to content
Permalink
Browse files

[processing] allow selection of open layers in batch interface

  • Loading branch information
volaya committed Apr 17, 2014
1 parent 06fe244 commit 5c19713291ecbe275538fcf68580a74a75b2bbba
@@ -28,6 +28,11 @@
import os
from PyQt4 import QtGui, QtCore
from processing.parameters.ParameterMultipleInput import ParameterMultipleInput
from processing.gui.MultipleInputDialog import MultipleInputDialog
from processing.tools import dataobjects
from processing.parameters.ParameterRaster import ParameterRaster
from processing.parameters.ParameterVector import ParameterVector
from processing.parameters.ParameterTable import ParameterTable


class BatchInputSelectionPanel(QtGui.QWidget):
@@ -49,11 +54,55 @@ def __init__(self, param, row, col, batchDialog, parent=None):
self.horizontalLayout.addWidget(self.text)
self.pushButton = QtGui.QPushButton()
self.pushButton.setText('...')
self.pushButton.clicked.connect(self.showSelectionDialog)
self.pushButton.clicked.connect(self.showPopupMenu)
self.horizontalLayout.addWidget(self.pushButton)
self.setLayout(self.horizontalLayout)

def showPopupMenu(self):
popupmenu = QtGui.QMenu()
if not (isinstance(self.param, ParameterMultipleInput)
and self.param.datatype == ParameterMultipleInput.TYPE_FILE):
selectLayerAction = QtGui.QAction('Select from open layers',
self.pushButton)
selectLayerAction.triggered.connect(self.showLayerSelectionDialog)
popupmenu.addAction(selectLayerAction)
selectFileAction = QtGui.QAction('Select from filesystem',
self.pushButton)
selectFileAction.triggered.connect(self.showFileSelectionDialog)
popupmenu.addAction(selectFileAction)
popupmenu.exec_(QtGui.QCursor.pos())

def showSelectionDialog(self):
def showLayerSelectionDialog(self):
if (isinstance(self.param, ParameterRaster)
or (isinstance(self.param, ParameterMultipleInput)
and self.param.datatype == ParameterMultipleInput.TYPE_RASTER)):
layers = dataobjects.getRasterLayers()
elif isinstance(self.param, ParameterTable):
layers = dataobjects.getTables()
else:
if isinstance(self.param, ParameterVector):
datatype = self.param.shapetype
else:
datatype = [self.param.datatype]
layers = dataobjects.getVectorLayers(datatype)
dlg = MultipleInputDialog([layer.name() for layer in layers])
dlg.exec_()
if dlg.selectedoptions is not None:
selected = dlg.selectedoptions
if len(selected) == 1:
self.text.setText(layers[selected[0]])
else:
if isinstance(self.param, ParameterMultipleInput):
self.text.setText(';'.join(layers[idx].name() for idx in selected))
else:
rowdif = len(layers) - (self.table.rowCount() - self.row)
for i in range(rowdif):
self.batchDialog.addRow()
for i, layeridx in enumerate(selected):
self.table.cellWidget(i + self.row,
self.col).setText(layers[layeridx].name())

def showFileSelectionDialog(self):
settings = QtCore.QSettings()
text = unicode(self.text.text())
if os.path.isdir(text):
@@ -72,7 +121,7 @@ def showSelectionDialog(self):
if len(files) == 1:
settings.setValue('/Processing/LastInputPath',
os.path.dirname(unicode(files[0])))
self.text.setText(str(files[0]))
self.text.setText(files[0])
else:
settings.setValue('/Processing/LastInputPath',
os.path.dirname(unicode(files[0])))
@@ -82,9 +131,9 @@ def showSelectionDialog(self):
rowdif = len(files) - (self.table.rowCount() - self.row)
for i in range(rowdif):
self.batchDialog.addRow()
for i in range(len(files)):
for i, f in enumerate(files):
self.table.cellWidget(i + self.row,
self.col).setText(files[i])
self.col).setText(f)

def setText(self, text):
return self.text.setText(text)
@@ -25,7 +25,7 @@

__revision__ = '$Format:%H$'

from PyQt4 import QtCore, QtGui
from PyQt4 import QtGui
from PyQt4.QtCore import *
from PyQt4.QtGui import *
from processing.core.ProcessingResults import ProcessingResults
@@ -86,8 +86,10 @@ def __init__(self, alg):
self.buttonBox.addButton(self.deleteRowButton,
QtGui.QDialogButtonBox.ActionRole)

nOutputs = self.alg.getVisibleOutputsCount() + 1
if nOutputs == 1: nOutputs = 0
self.table.setColumnCount(self.alg.getVisibleParametersCount()
+ self.alg.getVisibleOutputsCount() + 1)
+ nOutputs)
self.setTableContent()
self.table.horizontalHeader().setStretchLastSection(True)
self.table.verticalHeader().setVisible(False)
@@ -146,8 +148,9 @@ def setTableContent(self):
QtGui.QTableWidgetItem(out.description))
i += 1

self.table.setColumnWidth(i, 200)
self.table.setHorizontalHeaderItem(i,
if self.alg.getVisibleOutputsCount():
self.table.setColumnWidth(i, 200)
self.table.setHorizontalHeaderItem(i,
QtGui.QTableWidgetItem('Load in QGIS'))

for i in range(3):
@@ -314,21 +317,26 @@ def addRow(self):
self.table.setRowHeight(self.table.rowCount() - 1, 22)
i = 0
for param in self.alg.parameters:
if param.hidden:
continue
self.table.setCellWidget(self.table.rowCount() - 1, i,
self.getWidgetFromParameter(param,
self.table.rowCount() - 1, i))
i += 1
for out in self.alg.outputs:
if out.hidden:
continue
self.table.setCellWidget(self.table.rowCount() - 1, i,
BatchOutputSelectionPanel(out, self.alg,
self.table.rowCount() - 1, i, self))
i += 1

item = QtGui.QComboBox()
item.addItem('Yes')
item.addItem('No')
item.setCurrentIndex(0)
self.table.setCellWidget(self.table.rowCount() - 1, i, item)
if self.alg.getVisibleOutputsCount():
item = QtGui.QComboBox()
item.addItem('Yes')
item.addItem('No')
item.setCurrentIndex(0)
self.table.setCellWidget(self.table.rowCount() - 1, i, item)

def showAdvancedParametersClicked(self):
self.showAdvanced = not self.showAdvanced
@@ -38,7 +38,7 @@ def __init__(self, options, selectedoptions=None):
self.setupUi(self)

self.options = options
self.selectedoptions = selectedoptions
self.selectedoptions = selectedoptions or []

# Additional buttons
self.btnSelectAll = QPushButton(self.tr('Select all'))
@@ -66,7 +66,7 @@ def getSupportedOutputTableExtensions():

def getRasterLayers():
layers = QgsMapLayerRegistry.instance().mapLayers().values()
raster = list()
raster = []

for layer in layers:
if layer.type() == layer.RasterLayer:

0 comments on commit 5c19713

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