Skip to content
Permalink
Browse files

[processing] use list widget in Multiple selection dialog

  • Loading branch information
alexbruy committed Oct 21, 2013
1 parent 1d87841 commit f9c2b91e52dfd7016093e53c0d761830d7f7d0f0
@@ -41,42 +41,58 @@ def __init__(self, options, selectedoptions=None):
self.selectedoptions = selectedoptions

# Additional buttons
self.btnSelectAll = QPushButton(self.tr('(de)Select all'))
self.btnSelectAll = QPushButton(self.tr('Select all'))
self.buttonBox.addButton(self.btnSelectAll,
QDialogButtonBox.ActionRole)
self.btnClearSelection = QPushButton(self.tr('Clear selection'))
self.buttonBox.addButton(self.btnClearSelection,
QDialogButtonBox.ActionRole)
self.btnToggleSelection = QPushButton(self.tr('Toggle selection'))
self.buttonBox.addButton(self.btnToggleSelection,
QDialogButtonBox.ActionRole)

self.btnSelectAll.clicked.connect(self.toggleSelection)
self.btnSelectAll.clicked.connect(self.selectAll)
self.btnClearSelection.clicked.connect(self.lstLayers.clearSelection)
self.btnToggleSelection.clicked.connect(self.toggleSelection)

self.setTableContent()
self.populateList()

def setTableContent(self):
self.tblLayers.setRowCount(len(self.options))
for i in range(len(self.options)):
item = QCheckBox()
item.setText(self.options[i])
if i in self.selectedoptions:
item.setChecked(True)
self.tblLayers.setCellWidget(i, 0, item)
def populateList(self):
self.lstLayers.clear()
self.lstLayers.addItems(self.options)
selModel = self.lstLayers.selectionModel()
self.lstLayers.blockSignals(True)
for i in xrange(self.lstLayers.count()):
item = self.lstLayers.item(i)
if item.text() in self.selectedoptions:
selModel.select(self.lstLayers.indexFromItem(item),
QItemSelectionModel.Select)
self.lstLayers.blockSignals(False)

def accept(self):
self.selectedoptions = []
for i in range(len(self.options)):
widget = self.tblLayers.cellWidget(i, 0)
if widget.isChecked():
self.selectedoptions.append(i)
for i in self.lstLayers.selectedItems():
self.selectedoptions.append(i.text())
QDialog.accept(self)

def reject(self):
self.selectedoptions = None
QDialog.reject(self)

def selectAll(self):
selModel = self.lstLayers.selectionModel()
self.lstLayers.blockSignals(True)
for i in xrange(self.lstLayers.count()):
item = self.lstLayers.item(i)
selModel.select(self.lstLayers.indexFromItem(item),
QItemSelectionModel.Select)
self.lstLayers.blockSignals(False)

def toggleSelection(self):
checked = False
for i in range(len(self.options)):
widget = self.tblLayers.cellWidget(i, 0)
if not widget.isChecked():
checked = True
break
for i in range(len(self.options)):
widget = self.tblLayers.cellWidget(i, 0)
widget.setChecked(checked)
selModel = self.lstLayers.selectionModel()
self.lstLayers.blockSignals(True)
for i in xrange(self.lstLayers.count()):
item = self.lstLayers.item(i)
selModel.select(self.lstLayers.indexFromItem(item),
QItemSelectionModel.Toggle)
self.lstLayers.blockSignals(False)
@@ -17,24 +17,29 @@
<property name="spacing">
<number>2</number>
</property>
<property name="margin">
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>5</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
<item>
<widget class="QTableWidget" name="tblLayers">
<property name="columnCount">
<number>1</number>
<widget class="QListWidget" name="lstLayers">
<property name="editTriggers">
<set>QAbstractItemView::NoEditTriggers</set>
</property>
<attribute name="horizontalHeaderVisible">
<bool>false</bool>
</attribute>
<attribute name="horizontalHeaderStretchLastSection">
<property name="alternatingRowColors">
<bool>true</bool>
</attribute>
<attribute name="verticalHeaderVisible">
<bool>false</bool>
</attribute>
<column/>
</property>
<property name="selectionMode">
<enum>QAbstractItemView::ExtendedSelection</enum>
</property>
</widget>
</item>
<item>
@@ -2,7 +2,7 @@

# Form implementation generated from reading ui file 'python/plugins/processing/ui/DlgMultipleSelection.ui'
#
# Created: Wed Oct 2 20:04:27 2013
# Created: Thu Oct 3 20:32:49 2013
# by: PyQt4 UI code generator 4.9.1
#
# WARNING! All changes made in this file will be lost!
@@ -20,16 +20,14 @@ def setupUi(self, DlgMultipleSelection):
DlgMultipleSelection.resize(380, 320)
self.horizontalLayout = QtGui.QHBoxLayout(DlgMultipleSelection)
self.horizontalLayout.setSpacing(2)
self.horizontalLayout.setMargin(0)
self.horizontalLayout.setContentsMargins(0, 5, 0, 0)
self.horizontalLayout.setObjectName(_fromUtf8("horizontalLayout"))
self.tblLayers = QtGui.QTableWidget(DlgMultipleSelection)
self.tblLayers.setColumnCount(1)
self.tblLayers.setObjectName(_fromUtf8("tblLayers"))
self.tblLayers.setRowCount(0)
self.tblLayers.horizontalHeader().setVisible(False)
self.tblLayers.horizontalHeader().setStretchLastSection(True)
self.tblLayers.verticalHeader().setVisible(False)
self.horizontalLayout.addWidget(self.tblLayers)
self.lstLayers = QtGui.QListWidget(DlgMultipleSelection)
self.lstLayers.setEditTriggers(QtGui.QAbstractItemView.NoEditTriggers)
self.lstLayers.setAlternatingRowColors(True)
self.lstLayers.setSelectionMode(QtGui.QAbstractItemView.ExtendedSelection)
self.lstLayers.setObjectName(_fromUtf8("lstLayers"))
self.horizontalLayout.addWidget(self.lstLayers)
self.buttonBox = QtGui.QDialogButtonBox(DlgMultipleSelection)
self.buttonBox.setOrientation(QtCore.Qt.Vertical)
self.buttonBox.setStandardButtons(QtGui.QDialogButtonBox.Cancel|QtGui.QDialogButtonBox.Ok)

1 comment on commit f9c2b91

@gioman

This comment has been minimized.

Copy link
Contributor

@gioman gioman commented on f9c2b91 Oct 28, 2013

Hi Alex,
it seems that after this changes running any module that needs to make a multiple selection is causing this error

Traceback (most recent call last):
File "C:/OSGeo4W/apps/qgis-dev/./python/plugins\processing\gui\AlgorithmExecutionDialog.py", line 208, in accept
self.setParamValues()
File "C:/OSGeo4W/apps/qgis-dev/./python/plugins\processing\gui\AlgorithmExecutionDialog.py", line 143, in setParamValues
self.paramTable.valueItems[param.name]):
File "C:/OSGeo4W/apps/qgis-dev/./python/plugins\processing\gui\AlgorithmExecutionDialog.py", line 189, in setParamValue
value.append(options[index])
TypeError: list indices must be integers, not unicode

cheers!

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