From 89729ad3b058cb47b20e0528c75d781fff2e4509 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Sat, 21 Jan 2012 19:24:04 +0530 Subject: [PATCH] Fix #919584 (sort on startup ignores more that 3 levels) --- src/calibre/gui2/library/views.py | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/src/calibre/gui2/library/views.py b/src/calibre/gui2/library/views.py index cb73b5ddf0..48049b765f 100644 --- a/src/calibre/gui2/library/views.py +++ b/src/calibre/gui2/library/views.py @@ -363,14 +363,15 @@ class BooksView(QTableView): # {{{ history.append([col, order]) return history - def apply_sort_history(self, saved_history): + def apply_sort_history(self, saved_history, max_sort_levels=3): if not saved_history: return - for col, order in reversed(self.cleanup_sort_history(saved_history)[:3]): + for col, order in reversed(self.cleanup_sort_history( + saved_history)[:max_sort_levels]): self.sortByColumn(self.column_map.index(col), Qt.AscendingOrder if order else Qt.DescendingOrder) - def apply_state(self, state): + def apply_state(self, state, max_sort_levels=3): h = self.column_header cmap = {} hidden = state.get('hidden_columns', []) @@ -399,7 +400,8 @@ class BooksView(QTableView): # {{{ sz = h.sectionSizeHint(cmap[col]) h.resizeSection(cmap[col], sz) - self.apply_sort_history(state.get('sort_history', None)) + self.apply_sort_history(state.get('sort_history', None), + max_sort_levels=max_sort_levels) for col, alignment in state.get('column_alignment', {}).items(): self._model.change_alignment(col, alignment) @@ -474,6 +476,7 @@ class BooksView(QTableView): # {{{ old_state = self.get_old_state() if old_state is None: old_state = self.get_default_state() + max_levels = 3 if tweaks['sort_columns_at_startup'] is not None: sh = [] @@ -488,9 +491,10 @@ class BooksView(QTableView): # {{{ import traceback traceback.print_exc() old_state['sort_history'] = sh + max_levels = max(3, len(sh)) self.column_header.blockSignals(True) - self.apply_state(old_state) + self.apply_state(old_state, max_sort_levels=max_levels) self.column_header.blockSignals(False) # Resize all rows to have the correct height