Fix Tag Browser

This commit is contained in:
Kovid Goyal 2010-05-03 08:58:15 -06:00
commit b0dc410f7a
5 changed files with 19 additions and 14 deletions

View File

@ -71,12 +71,16 @@ class TagCategories(QDialog, Ui_TagCategories):
for item,l in enumerate(self.categories[cat]):
key = ':'.join([l[1], l[0]])
t = self.all_items_dict.get(key, None)
if l[1] in self.category_labels:
if t is None:
t = Item(name=l[0], label=l[1], index=len(self.all_items),
icon=category_icons[self.category_labels.index(l[1])], exists=False)
self.all_items.append(t)
self.all_items_dict[key] = t
l[2] = t.index
else:
# remove any references to a category that no longer exists
del self.categories[cat][item]
self.all_items_sorted = sorted(self.all_items, cmp=lambda x,y: cmp(x.name.lower(), y.name.lower()))
self.display_filtered_categories(0)

View File

@ -1077,7 +1077,7 @@ class BooksView(TableView):
def connect_to_restriction_set(self, tv):
QObject.connect(tv, SIGNAL('restriction_set(PyQt_PyObject)'),
self._model.set_search_restriction)
self._model.set_search_restriction) # must be synchronous (not queued)
def connect_to_book_display(self, bd):
QObject.connect(self._model, SIGNAL('new_bookdisplay_data(PyQt_PyObject)'),

View File

@ -64,10 +64,10 @@ class TagsView(QTreeView):
if len(s) == 0:
self.search_restriction = ''
else:
self.search_restriction = unicode(s)
self.search_restriction = 'search:"%s"' % unicode(s).strip()
self.model().set_search_restriction(self.search_restriction)
self.recount()
self.emit(SIGNAL('restriction_set(PyQt_PyObject)'), self.search_restriction)
self.recount() # Must happen after the emission of the restriction_set signal
self.emit(SIGNAL('tags_marked(PyQt_PyObject, PyQt_PyObject)'),
self._model.tokens(), self.match_all)
@ -264,7 +264,7 @@ class TagsModel(QAbstractItemModel):
for c in self.user_categories:
l = []
for (name,label,ign) in self.user_categories[c]:
if name in taglist[label]: # use same node as the complete category
if label in taglist and name in taglist[label]: # use same node as the complete category
l.append(taglist[label][name])
# else: do nothing, to eliminate nodes that have zero counts
if config['sort_by_popularity']:

View File

@ -543,4 +543,4 @@ class ResultCache(SearchQueryParser):
return []
def set_search_restriction(self, s):
self.search_restriction = '' if not s else 'search:"%s"' % (s.strip())
self.search_restriction = s

View File

@ -634,9 +634,9 @@ class LibraryDatabase2(LibraryDatabase, SchemaUpgrade, CustomColumns):
tooltip = self.custom_column_label_map[category]['name']
if ids is None: # no filtering
categories[category] = [Tag(r[1], count=r[2], id=r[0], icon=icon, tooltip = tooltip)
for r in data]
for r in data if r[2] > 0]
else: # filter out zero-count tags
categories[category] = [Tag(r[1], count=r[2], id=r[0], icon=icon)
categories[category] = [Tag(r[1], count=r[2], id=r[0], icon=icon, tooltip = tooltip)
for r in data if r[2] > 0]
categories['format'] = []
for fmt in self.conn.get('SELECT DISTINCT format FROM data'):
@ -644,7 +644,8 @@ class LibraryDatabase2(LibraryDatabase, SchemaUpgrade, CustomColumns):
if ids is not None:
count = self.conn.get('''SELECT COUNT(id)
FROM data
WHERE format="%s" AND books_list_filter(id)'''%fmt,
WHERE format="%s" AND
books_list_filter(book)'''%fmt,
all=False)
else:
count = self.conn.get('''SELECT COUNT(id)