mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Fix #919584 (sort on startup ignores more that 3 levels)
This commit is contained in:
parent
c96112fada
commit
89729ad3b0
@ -363,14 +363,15 @@ class BooksView(QTableView): # {{{
|
|||||||
history.append([col, order])
|
history.append([col, order])
|
||||||
return history
|
return history
|
||||||
|
|
||||||
def apply_sort_history(self, saved_history):
|
def apply_sort_history(self, saved_history, max_sort_levels=3):
|
||||||
if not saved_history:
|
if not saved_history:
|
||||||
return
|
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),
|
self.sortByColumn(self.column_map.index(col),
|
||||||
Qt.AscendingOrder if order else Qt.DescendingOrder)
|
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
|
h = self.column_header
|
||||||
cmap = {}
|
cmap = {}
|
||||||
hidden = state.get('hidden_columns', [])
|
hidden = state.get('hidden_columns', [])
|
||||||
@ -399,7 +400,8 @@ class BooksView(QTableView): # {{{
|
|||||||
sz = h.sectionSizeHint(cmap[col])
|
sz = h.sectionSizeHint(cmap[col])
|
||||||
h.resizeSection(cmap[col], sz)
|
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():
|
for col, alignment in state.get('column_alignment', {}).items():
|
||||||
self._model.change_alignment(col, alignment)
|
self._model.change_alignment(col, alignment)
|
||||||
@ -474,6 +476,7 @@ class BooksView(QTableView): # {{{
|
|||||||
old_state = self.get_old_state()
|
old_state = self.get_old_state()
|
||||||
if old_state is None:
|
if old_state is None:
|
||||||
old_state = self.get_default_state()
|
old_state = self.get_default_state()
|
||||||
|
max_levels = 3
|
||||||
|
|
||||||
if tweaks['sort_columns_at_startup'] is not None:
|
if tweaks['sort_columns_at_startup'] is not None:
|
||||||
sh = []
|
sh = []
|
||||||
@ -488,9 +491,10 @@ class BooksView(QTableView): # {{{
|
|||||||
import traceback
|
import traceback
|
||||||
traceback.print_exc()
|
traceback.print_exc()
|
||||||
old_state['sort_history'] = sh
|
old_state['sort_history'] = sh
|
||||||
|
max_levels = max(3, len(sh))
|
||||||
|
|
||||||
self.column_header.blockSignals(True)
|
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)
|
self.column_header.blockSignals(False)
|
||||||
|
|
||||||
# Resize all rows to have the correct height
|
# Resize all rows to have the correct height
|
||||||
|
Loading…
x
Reference in New Issue
Block a user