def __init__(self, parent):
super(GenericSortProxyModel, self).__init__()
self.booleanSet = set()
def setParametros(self, booleanColumns=None):
if booleanColumns:
for columna in booleanColumns:
self.booleanSet.add(columna)
def flags(self, index):
if not index.isValid():
return Qt.ItemIsEnabled
if index.column() in self.booleanSet:
return Qt.ItemIsUserCheckable | Qt.ItemIsSelectable | Qt.ItemIsEnabled
else:
def data(self, index, role):
if not index.isValid():
return self.nullVariant()
if index.column() in self.booleanSet and role in (Qt.CheckStateRole, Qt.DisplayRole):
if role == Qt.CheckStateRole:
value
= QVariant(Qt.
Checked) if index.
data(Qt.
EditRole).
toBool() else QVariant(Qt.
Unchecked) return value
else: #if role == Qt.DisplayRole:
return self.nullVariant
else:
def setData(self, index, data, role):
if not index.isValid():
return False
if index.column() in self.booleanSet and role == Qt.CheckStateRole:
else:
class GenericSortProxyModel(QSortFilterProxyModel):
def __init__(self, parent):
super(GenericSortProxyModel, self).__init__()
self.booleanSet = set()
self.nullVariant = QVariant()
def setParametros(self, booleanColumns=None):
if booleanColumns:
for columna in booleanColumns:
self.booleanSet.add(columna)
def flags(self, index):
if not index.isValid():
return Qt.ItemIsEnabled
if index.column() in self.booleanSet:
return Qt.ItemIsUserCheckable | Qt.ItemIsSelectable | Qt.ItemIsEnabled
else:
return QSortFilterProxyModel.flags(self, index)
def data(self, index, role):
if not index.isValid():
return self.nullVariant()
if index.column() in self.booleanSet and role in (Qt.CheckStateRole, Qt.DisplayRole):
if role == Qt.CheckStateRole:
value = QVariant(Qt.Checked) if index.data(Qt.EditRole).toBool() else QVariant(Qt.Unchecked)
return value
else: #if role == Qt.DisplayRole:
return self.nullVariant
else:
return QSortFilterProxyModel.data(self, index, role)
def setData(self, index, data, role):
if not index.isValid():
return False
if index.column() in self.booleanSet and role == Qt.CheckStateRole:
value = QVariant(True) if data.toInt()[0] == Qt.Checked else QVariant(False)
return QSortFilterProxyModel.setData(self, index, value, Qt.EditRole)
else:
return QSortFilterProxyModel.setData(self, index, data, role)
To copy to clipboard, switch view to plain text mode
Bookmarks