From a1915419145fc92ed6abde73ba0583a65353ab3c Mon Sep 17 00:00:00 2001 From: Charles Haley <> Date: Sun, 8 Aug 2010 22:32:29 +0100 Subject: [PATCH] 1) Fix sorting problems in manage_authors. Changing the value in the currently-sorted column moved the selection, making multiple edits difficult. Changed to use 'sort' buttons. 2) Sorting collections by title doesn't work, because title_sort is always non. Change database2 to add title_sort to the metainformation structure so it is added to the JSON cache so it can be used to sort. --- .../gui2/dialogs/edit_authors_dialog.py | 26 ++++++-- .../gui2/dialogs/edit_authors_dialog.ui | 59 +++++++++++++++---- src/calibre/library/database2.py | 3 + 3 files changed, 72 insertions(+), 16 deletions(-) diff --git a/src/calibre/gui2/dialogs/edit_authors_dialog.py b/src/calibre/gui2/dialogs/edit_authors_dialog.py index 4c749a79d0..aab8a46c25 100644 --- a/src/calibre/gui2/dialogs/edit_authors_dialog.py +++ b/src/calibre/gui2/dialogs/edit_authors_dialog.py @@ -50,15 +50,35 @@ class EditAuthorsDialog(QDialog, Ui_EditAuthorsDialog): # set up the signal after the table is filled self.table.cellChanged.connect(self.cell_changed) + self.sort_by_author.setCheckable(True) + self.sort_by_author.setChecked(False) + self.sort_by_author.clicked.connect(self.do_sort_by_author) + self.author_order = 1 - self.table.setSortingEnabled(True) self.table.sortByColumn(1, Qt.AscendingOrder) + self.sort_by_author_sort.clicked.connect(self.do_sort_by_author_sort) + self.sort_by_author_sort.setCheckable(True) + self.sort_by_author_sort.setChecked(True) + self.author_sort_order = 1 + if select_item is not None: self.table.setCurrentItem(select_item) self.table.editItem(select_item) else: self.table.setCurrentCell(0, 0) + def do_sort_by_author(self): + self.author_order = 1 if self.author_order == 0 else 0 + self.table.sortByColumn(0, self.author_order) + self.sort_by_author.setChecked(True) + self.sort_by_author_sort.setChecked(False) + + def do_sort_by_author_sort(self): + self.author_sort_order = 1 if self.author_sort_order == 0 else 0 + self.table.sortByColumn(1, self.author_sort_order) + self.sort_by_author.setChecked(False) + self.sort_by_author_sort.setChecked(True) + def accepted(self): self.result = [] for row in range(0,self.table.rowCount()): @@ -79,8 +99,4 @@ class EditAuthorsDialog(QDialog, Ui_EditAuthorsDialog): else: item = self.table.item(row, 1) self.table.setCurrentItem(item) - # disable and reenable sorting to force the sort now, so we can scroll - # to the item after it moves - self.table.setSortingEnabled(False) - self.table.setSortingEnabled(True) self.table.scrollToItem(item) diff --git a/src/calibre/gui2/dialogs/edit_authors_dialog.ui b/src/calibre/gui2/dialogs/edit_authors_dialog.ui index d124f1498d..2352508540 100644 --- a/src/calibre/gui2/dialogs/edit_authors_dialog.ui +++ b/src/calibre/gui2/dialogs/edit_authors_dialog.ui @@ -34,17 +34,54 @@ - - - Qt::Horizontal - - - QDialogButtonBox::Cancel|QDialogButtonBox::Ok - - - true - - + + + + + Sort by author + + + + + + + Sort by author sort + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + 0 + 0 + + + + Qt::Horizontal + + + QDialogButtonBox::Cancel|QDialogButtonBox::Ok + + + false + + + + diff --git a/src/calibre/library/database2.py b/src/calibre/library/database2.py index d2cf05681e..7fe7deee5c 100644 --- a/src/calibre/library/database2.py +++ b/src/calibre/library/database2.py @@ -317,6 +317,8 @@ class LibraryDatabase2(LibraryDatabase, SchemaUpgrade, CustomColumns): 'title', 'timestamp', 'uuid', 'pubdate'): setattr(self, prop, functools.partial(get_property, loc=self.FIELD_MAP['comments' if prop == 'comment' else prop])) + setattr(self, 'title_sort', functools.partial(get_property, + loc=self.FIELD_MAP['sort'])) def initialize_database(self): metadata_sqlite = open(P('metadata_sqlite.sql'), 'rb').read() @@ -494,6 +496,7 @@ class LibraryDatabase2(LibraryDatabase, SchemaUpgrade, CustomColumns): mi.timestamp = self.timestamp(idx, index_is_id=index_is_id) mi.pubdate = self.pubdate(idx, index_is_id=index_is_id) mi.uuid = self.uuid(idx, index_is_id=index_is_id) + mi.title_sort = self.title_sort(idx, index_is_id=index_is_id) tags = self.tags(idx, index_is_id=index_is_id) if tags: mi.tags = [i.strip() for i in tags.split(',')]