Fix #919584 (sort on startup ignores more that 3 levels)

This commit is contained in:
Kovid Goyal 2012-01-21 19:24:04 +05:30
parent c96112fada
commit 89729ad3b0

View File

@ -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