Improvements to the Table view

This commit is contained in:
BasioMeusPuga
2017-11-28 19:15:43 +05:30
parent af1cd21ec3
commit a32d140980
5 changed files with 55 additions and 31 deletions

View File

@@ -11,10 +11,11 @@ class LibraryItemModel(QtGui.QStandardItemModel, QtCore.QAbstractItemModel):
class LibraryTableModel(QtCore.QAbstractTableModel):
# TODO
# Speed up sorting
# Double clicking
# Auto resize with emphasis on Name
# Sorting is taken care of by the QSortFilterProxy model
# which has an inbuilt sort method
def __init__(self, header_data, display_data, parent=None):
super(LibraryTableModel, self).__init__(parent)
self.header_data = header_data
@@ -33,6 +34,10 @@ class LibraryTableModel(QtCore.QAbstractTableModel):
if role == QtCore.Qt.DisplayRole:
value = self.display_data[index.row()][index.column()]
return value
elif role == QtCore.Qt.UserRole:
# The rest of the roles can be accomodated here.
value = self.display_data[index.row()][4]
return value
else:
return QtCore.QVariant()
@@ -41,14 +46,6 @@ class LibraryTableModel(QtCore.QAbstractTableModel):
return self.header_data[col]
return None
def sort(self, col, order):
# self.emit(SIGNAL("layoutAboutToBeChanged()"))
self.display_data.sort(key=lambda x: x[col])
if order == QtCore.Qt.DescendingOrder:
self.display_data.sort(key=lambda x: x[col], reverse=True)
# self.emit(SIGNAL("layoutChanged()"))
class TableProxyModel(QtCore.QSortFilterProxyModel):
def __init__(self, parent=None):