Workaround for sortByColumn being partially broken in Qt 5.13.0

Fixes #1834989 [Qt 5.13 seems to break sorting the book list](https://bugs.launchpad.net/calibre/+bug/1834989)
This commit is contained in:
Kovid Goyal 2019-07-02 16:18:16 +05:30
parent a48220a182
commit 8088902fa8
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C
5 changed files with 10 additions and 9 deletions

View File

@ -17,7 +17,7 @@ class MatchBookAction(InterfaceAction):
action_spec = (_('Match book to library'), 'book.png', action_spec = (_('Match book to library'), 'book.png',
_('Match this book to a book in the library'), _('Match this book to a book in the library'),
()) ())
dont_add_to = frozenset(['menubar', 'toolbar', 'context-menu', 'toolbar-child', 'context-menu-cover-browser']) dont_add_to = frozenset(('menubar', 'toolbar', 'context-menu', 'toolbar-child', 'context-menu-cover-browser'))
action_type = 'current' action_type = 'current'
def genesis(self): def genesis(self):

View File

@ -97,7 +97,6 @@ class EditAuthorsDialog(QDialog, Ui_EditAuthorsDialog):
self.sort_by_author.clicked.connect(self.do_sort_by_author) self.sort_by_author.clicked.connect(self.do_sort_by_author)
self.author_order = 1 self.author_order = 1
self.table.sortByColumn(1, Qt.AscendingOrder)
self.sort_by_author_sort.clicked.connect(self.do_sort_by_author_sort) self.sort_by_author_sort.clicked.connect(self.do_sort_by_author_sort)
self.sort_by_author_sort.setCheckable(True) self.sort_by_author_sort.setCheckable(True)
self.sort_by_author_sort.setChecked(True) self.sort_by_author_sort.setChecked(True)
@ -139,6 +138,7 @@ class EditAuthorsDialog(QDialog, Ui_EditAuthorsDialog):
self.table.setContextMenuPolicy(Qt.CustomContextMenu) self.table.setContextMenuPolicy(Qt.CustomContextMenu)
self.table.customContextMenuRequested .connect(self.show_context_menu) self.table.customContextMenuRequested .connect(self.show_context_menu)
self.do_sort_by_author_sort()
def save_state(self): def save_state(self):
self.table_column_widths = [] self.table_column_widths = []

View File

@ -500,7 +500,7 @@ class BooksModel(QAbstractTableModel): # {{{
self.searched.emit(True) self.searched.emit(True)
self.search_done.emit() self.search_done.emit()
def sort(self, col, order, reset=True): def sort(self, col, order=Qt.AscendingOrder, reset=True):
if not self.db: if not self.db:
return return
if not isinstance(order, bool): if not isinstance(order, bool):

View File

@ -511,17 +511,18 @@ class BooksView(QTableView): # {{{
ch.blockSignals(False) ch.blockSignals(False)
def sort_by_column_and_order(self, col, ascending): def sort_by_column_and_order(self, col, ascending):
order = Qt.AscendingOrder if ascending else Qt.DescendingOrder
self.column_header.blockSignals(True) self.column_header.blockSignals(True)
self.sortByColumn(col, Qt.AscendingOrder if ascending else Qt.DescendingOrder) self.column_header.setSortIndicator(col, order)
self.column_header.blockSignals(False) self.column_header.blockSignals(False)
self.model().sort(col, order)
if self.is_library_view: if self.is_library_view:
self.set_sort_indicator(col, ascending) self.set_sort_indicator(col, ascending)
def user_sort_requested(self, col, order=Qt.AscendingOrder): def user_sort_requested(self, col, order=Qt.AscendingOrder):
if col >= len(self.column_map) or col < 0: if 0 <= col < len(self.column_map):
return QTableView.sortByColumn(self, col) field = self.column_map[col]
field = self.column_map[col] self.intelligent_sort(field, order == Qt.AscendingOrder)
self.intelligent_sort(field, order == Qt.AscendingOrder)
def pin_view_user_sort_requested(self, col, order=Qt.AscendingOrder): def pin_view_user_sort_requested(self, col, order=Qt.AscendingOrder):
if col < len(self.column_map) and col >= 0: if col < len(self.column_map) and col >= 0:

View File

@ -1055,7 +1055,7 @@ class SpellCheck(Dialog):
if self.words_model.sort_on[0] == 0: if self.words_model.sort_on[0] == 0:
with self: with self:
hh = self.words_view.horizontalHeader() hh = self.words_view.horizontalHeader()
self.words_view.sortByColumn(hh.sortIndicatorSection(), hh.sortIndicatorOrder()) self.words_view.model().sort(hh.sortIndicatorSection(), hh.sortIndicatorOrder())
def search_type_changed(self): def search_type_changed(self):
tprefs['spell_check_case_sensitive_search'] = bool(self.case_sensitive_search.isChecked()) tprefs['spell_check_case_sensitive_search'] = bool(self.case_sensitive_search.isChecked())