def __init__(self, datain, parent=None, *args):
self.arraydata = datain
def rowCount(self, parent):
return len(self.arraydata)
def columnCount(self, parent):
return BankRecord.getMaxIdx()
def data(self, index, role):
if not index.isValid():
elif role != Qt.DisplayRole:
return QVariant(self.
arraydata[index.
row()].
getIdxData(index.
column()))
def headerData(self, section, orientation, role):
if orientation == QtCore.Qt.Vertical:
if role != Qt.DisplayRole:
return QVariant(BankRecord.
getIdxHeaderData(section
))
def __init__(self, parent):
super(RecordFilter,self).__init__(parent)
self.filterHeader = None
def setFilterHeader(self, filterHeader):
self.filterHeader = filterHeader
def filterAcceptsRow(self, source_row, source_parent):
sourceModel = self.sourceModel()
if not self.filterHeader:
return False
for i in range(BankRecord.getMaxIdx()):
idx = sourceModel.index(source_row, i, source_parent)
dataString = sourceModel.data(idx, Qt.DisplayRole).value().lower()
filterText = self.filterHeader.filterText(i).lower()
if len(filterText) > 0 and not dataString.find(filterText) >= 0:
return False
return True
class MyTableModel(QAbstractTableModel):
def __init__(self, datain, parent=None, *args):
QAbstractTableModel.__init__(self, parent, *args)
self.arraydata = datain
def rowCount(self, parent):
return len(self.arraydata)
def columnCount(self, parent):
return BankRecord.getMaxIdx()
def data(self, index, role):
if not index.isValid():
return QVariant()
elif role != Qt.DisplayRole:
return QVariant()
return QVariant(self.arraydata[index.row()].getIdxData(index.column()))
def headerData(self, section, orientation, role):
if orientation == QtCore.Qt.Vertical:
return QVariant()
if role != Qt.DisplayRole:
return QVariant()
return QVariant(BankRecord.getIdxHeaderData(section))
class RecordFilter(QSortFilterProxyModel):
def __init__(self, parent):
super(RecordFilter,self).__init__(parent)
self.filterHeader = None
def setFilterHeader(self, filterHeader):
self.filterHeader = filterHeader
def filterAcceptsRow(self, source_row, source_parent):
sourceModel = self.sourceModel()
if not self.filterHeader:
return False
for i in range(BankRecord.getMaxIdx()):
idx = sourceModel.index(source_row, i, source_parent)
dataString = sourceModel.data(idx, Qt.DisplayRole).value().lower()
filterText = self.filterHeader.filterText(i).lower()
if len(filterText) > 0 and not dataString.find(filterText) >= 0:
return False
return True
To copy to clipboard, switch view to plain text mode
Bookmarks