mirror of
https://github.com/qgis/QGIS.git
synced 2025-04-13 00:03:09 -04:00
[processing] allow selection of open layers in batch interface
This commit is contained in:
parent
06fe244a29
commit
5c19713291
@ -28,6 +28,11 @@ __revision__ = '$Format:%H$'
|
||||
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 @@ class BatchInputSelectionPanel(QtGui.QWidget):
|
||||
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 @@ class BatchInputSelectionPanel(QtGui.QWidget):
|
||||
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 @@ class BatchInputSelectionPanel(QtGui.QWidget):
|
||||
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 @@ __copyright__ = '(C) 2012, Victor Olaya'
|
||||
|
||||
__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 @@ class BatchProcessingDialog(AlgorithmExecutionDialog):
|
||||
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 @@ class BatchProcessingDialog(AlgorithmExecutionDialog):
|
||||
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 @@ class BatchProcessingDialog(AlgorithmExecutionDialog):
|
||||
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 @@ class MultipleInputDialog(QDialog, Ui_DlgMultipleSelection):
|
||||
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:
|
||||
|
Loading…
x
Reference in New Issue
Block a user