Table multicolumn search, split models into new module
This commit is contained in:
48
widgets.py
48
widgets.py
@@ -723,51 +723,3 @@ class LibraryDelegate(QtWidgets.QStyledItemDelegate):
|
||||
y_draw = option.rect.bottomRight().y() - 35
|
||||
if current_chapter != 1:
|
||||
painter.drawPixmap(x_draw, y_draw, read_icon)
|
||||
|
||||
|
||||
class LibraryItemModel(QtGui.QStandardItemModel, QtCore.QAbstractItemModel):
|
||||
def __init__(self, parent=None):
|
||||
# We're using this to be able to access the match() method
|
||||
super(LibraryItemModel, self).__init__(parent)
|
||||
|
||||
class LibraryTableModel(QtCore.QAbstractTableModel):
|
||||
# TODO
|
||||
# Speed up sorting
|
||||
# Associate with a proxy model to enable searching
|
||||
# Double clicking
|
||||
# Auto resize with emphasis on Name
|
||||
# Hide path but send it anyway
|
||||
|
||||
def __init__(self, header_data, display_data, parent=None):
|
||||
super(LibraryTableModel, self).__init__(parent)
|
||||
self.header_data = header_data
|
||||
self.display_data = display_data
|
||||
|
||||
def rowCount(self, parent):
|
||||
return len(self.display_data)
|
||||
|
||||
def columnCount(self, parent):
|
||||
return len(self.header_data)
|
||||
|
||||
def data(self, index, role):
|
||||
if not index.isValid():
|
||||
return None
|
||||
|
||||
if role == QtCore.Qt.DisplayRole:
|
||||
value = self.display_data[index.row()][index.column()]
|
||||
return value
|
||||
else:
|
||||
return QtCore.QVariant()
|
||||
|
||||
def headerData(self, col, orientation, role):
|
||||
if orientation == QtCore.Qt.Horizontal and role == QtCore.Qt.DisplayRole:
|
||||
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()"))
|
||||
|
Reference in New Issue
Block a user