Table sorting functional
This commit is contained in:
1
TODO
1
TODO
@@ -21,7 +21,6 @@ TODO
|
||||
✓ Mass tagging
|
||||
✓ Add capability to sort by new
|
||||
Table view
|
||||
Get sorting working again
|
||||
Ignore a / the / numbers for sorting purposes
|
||||
Information dialog widget
|
||||
Context menu: Cache, Read, Edit database, delete, Mark read/unread
|
||||
|
11
__main__.py
11
__main__.py
@@ -210,13 +210,16 @@ class MainUI(QtWidgets.QMainWindow, mainwindow.Ui_MainWindow):
|
||||
self.tableView.doubleClicked.connect(self.library_doubleclick)
|
||||
self.tableView.horizontalHeader().setSectionResizeMode(
|
||||
QtWidgets.QHeaderView.Interactive)
|
||||
self.tableView.horizontalHeader().setSortIndicator(2, QtCore.Qt.AscendingOrder)
|
||||
self.tableView.horizontalHeader().setSortIndicator(
|
||||
2, QtCore.Qt.AscendingOrder)
|
||||
self.tableView.setColumnHidden(0, True)
|
||||
self.tableView.horizontalHeader().setHighlightSections(False)
|
||||
if self.settings['main_window_headers']:
|
||||
for count, i in enumerate(self.settings['main_window_headers']):
|
||||
self.tableView.horizontalHeader().resizeSection(count, int(i))
|
||||
self.tableView.horizontalHeader().setStretchLastSection(True)
|
||||
self.tableView.horizontalHeader().sectionClicked.connect(
|
||||
self.lib_ref.table_proxy_model.sort_table_columns)
|
||||
|
||||
# Keyboard shortcuts
|
||||
self.ks_close_tab = QtWidgets.QShortcut(QtGui.QKeySequence('Ctrl+W'), self)
|
||||
@@ -235,9 +238,9 @@ class MainUI(QtWidgets.QMainWindow, mainwindow.Ui_MainWindow):
|
||||
self.settings_dialog.start_library_scan()
|
||||
|
||||
def open_books_at_startup(self):
|
||||
# TODO
|
||||
# See if there's some reason why last open books and command line
|
||||
# argument books can't be opened together
|
||||
# Last open books and command line books aren't being opened together
|
||||
# so that command line books are processed last and therefore retain
|
||||
# focus
|
||||
|
||||
# Open last... open books.
|
||||
# Then set the value to None for the next run
|
||||
|
@@ -150,10 +150,7 @@ class Library:
|
||||
self.table_proxy_model = TableProxyModel(self.parent.temp_dir.path())
|
||||
self.table_proxy_model.setSourceModel(self.view_model)
|
||||
self.table_proxy_model.setSortCaseSensitivity(False)
|
||||
self.table_proxy_model.sort(0, QtCore.Qt.AscendingOrder)
|
||||
self.parent.tableView.setModel(self.table_proxy_model)
|
||||
self.parent.tableView.horizontalHeader().setSortIndicator(
|
||||
0, QtCore.Qt.AscendingOrder)
|
||||
|
||||
self.update_proxymodels()
|
||||
|
||||
|
32
models.py
32
models.py
@@ -69,11 +69,17 @@ class TableProxyModel(QtCore.QSortFilterProxyModel):
|
||||
# TODO
|
||||
# The setData method
|
||||
super(TableProxyModel, self).__init__(parent)
|
||||
self.header_data = [None, 'Title', 'Author', 'Status', 'Year', 'Tags']
|
||||
self.header_data = [
|
||||
None, 'Title', 'Author', 'Status', 'Year', 'Tags']
|
||||
self.temp_dir = temp_dir
|
||||
self.filter_text = None
|
||||
self.active_library_filters = None
|
||||
self.sorting_box_position = None
|
||||
self.role_dictionary = {
|
||||
1: QtCore.Qt.UserRole, # Title
|
||||
2: QtCore.Qt.UserRole + 1, # Author
|
||||
4: QtCore.Qt.UserRole + 2, # Year
|
||||
5: QtCore.Qt.UserRole + 4} # Tags
|
||||
self.common_functions = ProxyModelsCommonFunctions(self)
|
||||
|
||||
def columnCount(self, parent):
|
||||
@@ -84,11 +90,8 @@ class TableProxyModel(QtCore.QSortFilterProxyModel):
|
||||
return self.header_data[column]
|
||||
|
||||
def flags(self, index):
|
||||
# This means only the Tags column is editable
|
||||
if index.column() == 4:
|
||||
return QtCore.Qt.ItemIsEnabled | QtCore.Qt.ItemIsSelectable | QtCore.Qt.ItemIsEditable
|
||||
else:
|
||||
# These are standard select but don't edit values
|
||||
# Tag editing will take place by way of a right click menu
|
||||
# These tags denote clickable and that's about it
|
||||
return QtCore.Qt.ItemIsEnabled | QtCore.Qt.ItemIsSelectable
|
||||
|
||||
def data(self, index, role):
|
||||
@@ -117,17 +120,10 @@ class TableProxyModel(QtCore.QSortFilterProxyModel):
|
||||
return return_pixmap
|
||||
|
||||
elif role == QtCore.Qt.DisplayRole or role == QtCore.Qt.EditRole:
|
||||
|
||||
if index.column() in (0, 3): # Cover and Status
|
||||
return QtCore.QVariant()
|
||||
|
||||
role_dictionary = {
|
||||
1: QtCore.Qt.UserRole, # Title
|
||||
2: QtCore.Qt.UserRole + 1, # Author
|
||||
4: QtCore.Qt.UserRole + 2, # Year
|
||||
5: QtCore.Qt.UserRole + 4} # Tags
|
||||
|
||||
return item.data(role_dictionary[index.column()])
|
||||
return item.data(self.role_dictionary[index.column()])
|
||||
|
||||
else:
|
||||
return QtCore.QVariant()
|
||||
@@ -140,6 +136,14 @@ class TableProxyModel(QtCore.QSortFilterProxyModel):
|
||||
output = self.common_functions.filterAcceptsRow(row, parent)
|
||||
return output
|
||||
|
||||
def sort_table_columns(self, column):
|
||||
if column == 3:
|
||||
return
|
||||
|
||||
sorting_order = self.sender().sortIndicatorOrder()
|
||||
self.sort(0, sorting_order)
|
||||
self.setSortRole(self.role_dictionary[column])
|
||||
|
||||
|
||||
class ProxyModelsCommonFunctions:
|
||||
def __init__(self, parent_model):
|
||||
|
Reference in New Issue
Block a user