From cb332cdfb5749a89042e53e837f5e401af8c37b6 Mon Sep 17 00:00:00 2001 From: Charles Haley <> Date: Mon, 7 Jun 2010 20:49:51 +0100 Subject: [PATCH] Series ordering fix and bug #5744 --- src/calibre/gui2/tag_view.py | 8 +++++++- src/calibre/library/database2.py | 6 ++++-- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/src/calibre/gui2/tag_view.py b/src/calibre/gui2/tag_view.py index 7fa374baca..24e83376aa 100644 --- a/src/calibre/gui2/tag_view.py +++ b/src/calibre/gui2/tag_view.py @@ -185,11 +185,17 @@ class TagsView(QTreeView): # {{{ if self.model(): self.model().clear_state() + def is_visible(self, idx): + item = idx.internalPointer() + if item.type == TagTreeItem.TAG: + idx = idx.parent() + return self.isExpanded(idx) + def recount(self, *args): ci = self.currentIndex() if not ci.isValid(): ci = self.indexAt(QPoint(10, 10)) - path = self.model().path_for_index(ci) + path = self.model().path_for_index(ci) if self.is_visible(ci) else None try: self.model().refresh() except: #Database connection could be closed if an integrity check is happening diff --git a/src/calibre/library/database2.py b/src/calibre/library/database2.py index f4791c929c..e639643e68 100644 --- a/src/calibre/library/database2.py +++ b/src/calibre/library/database2.py @@ -1049,8 +1049,10 @@ class LibraryDatabase2(LibraryDatabase, SchemaUpgrade, CustomColumns): # new series index to each of the books. # Get the list of books where we must update the series index - books = self.conn.get('''SELECT book from books_series_link - WHERE series=?''', (old_id,)) + books = self.conn.get('''SELECT books.id + FROM books, books_series_link as lt + WHERE books.id = lt.book AND lt.series=? + ORDER BY books.series_index''', (old_id,)) # Get the next series index index = self.get_next_series_num_for(new_name) # Now update the link table