mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
This time, really fix the sorting problem.
This commit is contained in:
parent
ced43993b7
commit
f69f6a3dae
@ -7,4 +7,4 @@ __docformat__ = 'restructuredtext en'
|
|||||||
|
|
||||||
from PyQt4.Qt import Qt
|
from PyQt4.Qt import Qt
|
||||||
|
|
||||||
DEFAULT_SORT = ('timestamp', Qt.DescendingOrder)
|
DEFAULT_SORT = ('timestamp', False)
|
||||||
|
@ -247,12 +247,13 @@ class BooksModel(QAbstractTableModel): # {{{
|
|||||||
if not self.db:
|
if not self.db:
|
||||||
return
|
return
|
||||||
self.about_to_be_sorted.emit(self.db.id)
|
self.about_to_be_sorted.emit(self.db.id)
|
||||||
ascending = order == Qt.AscendingOrder
|
if not isinstance(order, bool):
|
||||||
|
order = order == Qt.AscendingOrder
|
||||||
label = self.column_map[col]
|
label = self.column_map[col]
|
||||||
self.db.sort(label, ascending)
|
self.db.sort(label, order)
|
||||||
if reset:
|
if reset:
|
||||||
self.reset()
|
self.reset()
|
||||||
self.sorted_on = (label, order == Qt.AscendingOrder)
|
self.sorted_on = (label, order)
|
||||||
self.sort_history.insert(0, self.sorted_on)
|
self.sort_history.insert(0, self.sorted_on)
|
||||||
self.sorting_done.emit(self.db.index)
|
self.sorting_done.emit(self.db.index)
|
||||||
|
|
||||||
|
@ -165,7 +165,7 @@ class BooksView(QTableView): # {{{
|
|||||||
partial(self.column_header_context_handler,
|
partial(self.column_header_context_handler,
|
||||||
action='descending', column=col))
|
action='descending', column=col))
|
||||||
if self._model.sorted_on[0] == col:
|
if self._model.sorted_on[0] == col:
|
||||||
ac = a if self._model.sorted_on[1] == Qt.AscendingOrder else d
|
ac = a if self._model.sorted_on[1] else d
|
||||||
ac.setCheckable(True)
|
ac.setCheckable(True)
|
||||||
ac.setChecked(True)
|
ac.setChecked(True)
|
||||||
if col not in ('ondevice', 'rating', 'inlibrary') and \
|
if col not in ('ondevice', 'rating', 'inlibrary') and \
|
||||||
@ -282,13 +282,13 @@ class BooksView(QTableView): # {{{
|
|||||||
def cleanup_sort_history(self, sort_history):
|
def cleanup_sort_history(self, sort_history):
|
||||||
history = []
|
history = []
|
||||||
for col, order in sort_history:
|
for col, order in sort_history:
|
||||||
|
if not isinstance(order, bool):
|
||||||
|
continue
|
||||||
if col == 'date':
|
if col == 'date':
|
||||||
col = 'timestamp'
|
col = 'timestamp'
|
||||||
if col in self.column_map:
|
if col in self.column_map:
|
||||||
if (not history or history[0][0] != col):
|
if (not history or history[-1][0] != col):
|
||||||
history.append([col, order])
|
history.append([col, order])
|
||||||
elif isinstance(order, bool) and history[0][1] != order:
|
|
||||||
history[0][1] = order
|
|
||||||
return history
|
return history
|
||||||
|
|
||||||
def apply_sort_history(self, saved_history):
|
def apply_sort_history(self, saved_history):
|
||||||
|
@ -669,6 +669,9 @@ class ResultCache(SearchQueryParser): # {{{
|
|||||||
fields = [('timestamp', False)]
|
fields = [('timestamp', False)]
|
||||||
|
|
||||||
keyg = SortKeyGenerator(fields, self.field_metadata, self._data)
|
keyg = SortKeyGenerator(fields, self.field_metadata, self._data)
|
||||||
|
# For efficiency, the key generator returns a plain value if only one
|
||||||
|
# field is in the sort field list. Because the normal cmp function will
|
||||||
|
# always assume asc, we must deal with asc/desc here.
|
||||||
if len(fields) == 1:
|
if len(fields) == 1:
|
||||||
self._map.sort(key=keyg, reverse=not fields[0][1])
|
self._map.sort(key=keyg, reverse=not fields[0][1])
|
||||||
else:
|
else:
|
||||||
@ -697,7 +700,7 @@ class SortKeyGenerator(object):
|
|||||||
def __init__(self, fields, field_metadata, data):
|
def __init__(self, fields, field_metadata, data):
|
||||||
from calibre.utils.icu import sort_key
|
from calibre.utils.icu import sort_key
|
||||||
self.field_metadata = field_metadata
|
self.field_metadata = field_metadata
|
||||||
self.orders = [-1 if x[1] else 1 for x in fields]
|
self.orders = [1 if x[1] else -1 for x in fields]
|
||||||
self.entries = [(x[0], field_metadata[x[0]]) for x in fields]
|
self.entries = [(x[0], field_metadata[x[0]]) for x in fields]
|
||||||
self.library_order = tweaks['title_series_sorting'] == 'library_order'
|
self.library_order = tweaks['title_series_sorting'] == 'library_order'
|
||||||
self.data = data
|
self.data = data
|
||||||
|
Loading…
x
Reference in New Issue
Block a user