This commit is contained in:
Charles Haley 2011-04-15 13:22:46 +01:00
parent 8157ad817c
commit 00937e80c4

View File

@ -250,7 +250,8 @@ class BooksView(QTableView): # {{{
def multisort(self, fields, reset=True, only_if_different=False): def multisort(self, fields, reset=True, only_if_different=False):
if len(fields) == 0: if len(fields) == 0:
return return
sh = self.cleanup_sort_history(self._model.sort_history) sh = self.cleanup_sort_history(self._model.sort_history,
ignore_column_map=True)
if only_if_different and len(sh) >= len(fields): if only_if_different and len(sh) >= len(fields):
ret=True ret=True
for i,t in enumerate(fields): for i,t in enumerate(fields):
@ -263,7 +264,7 @@ class BooksView(QTableView): # {{{
for n,d in reversed(fields): for n,d in reversed(fields):
if n in self._model.db.field_metadata.keys(): if n in self._model.db.field_metadata.keys():
sh.insert(0, (n, d)) sh.insert(0, (n, d))
sh = self.cleanup_sort_history(sh) sh = self.cleanup_sort_history(sh, ignore_column_map=True)
self._model.sort_history = [tuple(x) for x in sh] self._model.sort_history = [tuple(x) for x in sh]
self._model.resort(reset=reset) self._model.resort(reset=reset)
col = fields[0][0] col = fields[0][0]
@ -319,14 +320,14 @@ class BooksView(QTableView): # {{{
state = self.get_state() state = self.get_state()
self.write_state(state) self.write_state(state)
def cleanup_sort_history(self, sort_history): def cleanup_sort_history(self, sort_history, ignore_column_map=False):
history = [] history = []
for col, order in sort_history: for col, order in sort_history:
if not isinstance(order, bool): if not isinstance(order, bool):
continue continue
if col == 'date': if col == 'date':
col = 'timestamp' col = 'timestamp'
if col in self.column_map: if ignore_column_map or col in self.column_map:
if (not history or history[-1][0] != col): if (not history or history[-1][0] != col):
history.append([col, order]) history.append([col, order])
return history return history