Skip to content
Permalink
Browse files
[processing] added checkboxes to multiple input selector
  • Loading branch information
volaya committed May 21, 2014
1 parent fad280e commit fcc24e9be2346976b8d02a9e49906ca4a98d3676
@@ -51,48 +51,44 @@ def __init__(self, options, selectedoptions=None):
self.buttonBox.addButton(self.btnToggleSelection,
QDialogButtonBox.ActionRole)

self.btnSelectAll.clicked.connect(self.selectAll)
self.btnClearSelection.clicked.connect(self.lstLayers.clearSelection)
self.btnSelectAll.clicked.connect(lambda: self.selectAll(True))
self.btnClearSelection.clicked.connect(lambda: self.selectAll(False))
self.btnToggleSelection.clicked.connect(self.toggleSelection)

self.populateList()

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 self.lstLayers.indexFromItem(item).row() in self.selectedoptions:
selModel.select(self.lstLayers.indexFromItem(item),
QItemSelectionModel.Select)
self.lstLayers.blockSignals(False)
model = QStandardItemModel()
for i, option in enumerate(self.options):
item = QStandardItem(option)
item.setCheckState(Qt.Checked if i in self.selectedoptions else Qt.Unchecked)
item.setCheckable(True)
model.appendRow(item)

self.lstLayers.setModel(model)

def accept(self):
self.selectedoptions = []
for i in self.lstLayers.selectedItems():
self.selectedoptions.append(self.lstLayers.indexFromItem(i).row())
model = self.lstLayers.model()
for i in xrange(model.rowCount()):
item = model.item(i)
if item.checkState() == Qt.Checked:
self.selectedoptions.append(i)
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):
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)
def selectAll(self, value):
model = self.lstLayers.model()
for i in xrange(model.rowCount()):
item = model.item(i)
item.setCheckState(Qt.Checked if value else Qt.Unchecked)

def toggleSelection(self):
model = self.lstLayers.model()
for i in xrange(model.rowCount()):
item = model.item(i)
checked = item.checkState() == Qt.Checked
item.setCheckState(Qt.Unchecked if checked else Qt.Checked)
@@ -21,15 +21,15 @@
<number>9</number>
</property>
<item>
<widget class="QListWidget" name="lstLayers">
<widget class="QListView" name="lstLayers">
<property name="editTriggers">
<set>QAbstractItemView::NoEditTriggers</set>
</property>
<property name="alternatingRowColors">
<bool>true</bool>
</property>
<property name="selectionMode">
<enum>QAbstractItemView::ExtendedSelection</enum>
<enum>QAbstractItemView::NoSelection</enum>
</property>
</widget>
</item>
@@ -1,9 +1,9 @@
# -*- coding: utf-8 -*-

# Form implementation generated from reading ui file 'python/plugins/processing/ui/DlgMultipleSelection.ui'
# Form implementation generated from reading ui file 'DlgMultipleSelection.ui'
#
# Created: Thu Oct 3 20:32:49 2013
# by: PyQt4 UI code generator 4.9.1
# Created: Tue May 20 13:40:43 2014
# by: PyQt4 UI code generator 4.9.6
#
# WARNING! All changes made in this file will be lost!

@@ -12,20 +12,29 @@
try:
_fromUtf8 = QtCore.QString.fromUtf8
except AttributeError:
_fromUtf8 = lambda s: s
def _fromUtf8(s):
return s

try:
_encoding = QtGui.QApplication.UnicodeUTF8
def _translate(context, text, disambig):
return QtGui.QApplication.translate(context, text, disambig, _encoding)
except AttributeError:
def _translate(context, text, disambig):
return QtGui.QApplication.translate(context, text, disambig)

class Ui_DlgMultipleSelection(object):
def setupUi(self, DlgMultipleSelection):
DlgMultipleSelection.setObjectName(_fromUtf8("DlgMultipleSelection"))
DlgMultipleSelection.resize(380, 320)
self.horizontalLayout = QtGui.QHBoxLayout(DlgMultipleSelection)
self.horizontalLayout.setSpacing(2)
self.horizontalLayout.setContentsMargins(0, 5, 0, 0)
self.horizontalLayout.setSpacing(6)
self.horizontalLayout.setMargin(9)
self.horizontalLayout.setObjectName(_fromUtf8("horizontalLayout"))
self.lstLayers = QtGui.QListWidget(DlgMultipleSelection)
self.lstLayers = QtGui.QListView(DlgMultipleSelection)
self.lstLayers.setEditTriggers(QtGui.QAbstractItemView.NoEditTriggers)
self.lstLayers.setAlternatingRowColors(True)
self.lstLayers.setSelectionMode(QtGui.QAbstractItemView.ExtendedSelection)
self.lstLayers.setSelectionMode(QtGui.QAbstractItemView.NoSelection)
self.lstLayers.setObjectName(_fromUtf8("lstLayers"))
self.horizontalLayout.addWidget(self.lstLayers)
self.buttonBox = QtGui.QDialogButtonBox(DlgMultipleSelection)
@@ -40,5 +49,5 @@ def setupUi(self, DlgMultipleSelection):
QtCore.QMetaObject.connectSlotsByName(DlgMultipleSelection)

def retranslateUi(self, DlgMultipleSelection):
DlgMultipleSelection.setWindowTitle(QtGui.QApplication.translate("DlgMultipleSelection", "Multiple selection", None, QtGui.QApplication.UnicodeUTF8))
DlgMultipleSelection.setWindowTitle(_translate("DlgMultipleSelection", "Multiple selection", None))

0 comments on commit fcc24e9

Please sign in to comment.