Fix sort restoring on fields not present as columns not working

Book list: Fix sorting on fields that are not viewable as columns not
being restored on calibre restart. Also fix sorting on the Title field
via the right click menu not being restored.
This commit is contained in:
Kovid Goyal 2013-12-31 11:39:08 +05:30
parent 78911d6077
commit 84219dcf6b
2 changed files with 12 additions and 9 deletions

View File

@ -63,10 +63,8 @@ class SortByAction(InterfaceAction):
self._sactions = []
for name in sorted(name_map, key=sort_key):
key = name_map[name]
if key in {'title', 'series_sort', 'formats', 'path'}:
if key in {'sort', 'series_sort', 'formats', 'path'}:
continue
if key == 'sort':
name = _('Title')
if key == 'ondevice' and self.gui.device_connected is None:
continue
ascending = None

View File

@ -474,7 +474,7 @@ class BooksView(QTableView): # {{{
state['last_modified_injected'] = True
state['languages_injected'] = True
state['sort_history'] = \
self.cleanup_sort_history(self.model().sort_history)
self.cleanup_sort_history(self.model().sort_history, ignore_column_map=self.is_library_view)
state['column_positions'] = {}
state['column_sizes'] = {}
state['column_alignment'] = self._model.alignment_map
@ -499,11 +499,11 @@ class BooksView(QTableView): # {{{
def cleanup_sort_history(self, sort_history, ignore_column_map=False):
history = []
for col, order in sort_history:
if not isinstance(order, bool):
continue
if col == 'date':
col = 'timestamp'
col = {'date':'timestamp', 'sort':'title'}.get(col, col)
if ignore_column_map or col in self.column_map:
if (not history or history[-1][0] != col):
history.append([col, order])
@ -512,9 +512,14 @@ class BooksView(QTableView): # {{{
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)[:max_sort_levels]):
self.sort_by_column_and_order(self.column_map.index(col), order)
if self.is_library_view:
for col, order in reversed(self.cleanup_sort_history(
saved_history, ignore_column_map=True)[:max_sort_levels]):
self.sort_by_named_field(col, order)
else:
for col, order in reversed(self.cleanup_sort_history(
saved_history)[:max_sort_levels]):
self.sort_by_column_and_order(self.column_map.index(col), order)
def apply_state(self, state, max_sort_levels=3):
h = self.column_header