Walk tree to get category data.

This commit is contained in:
Charles Haley 2011-07-31 21:14:30 +01:00
parent 7a69120f4f
commit 5383af193f
2 changed files with 12 additions and 5 deletions

View File

@ -500,6 +500,7 @@ class TagsModel(QAbstractItemModel): # {{{
if i < len(components)-1:
t = copy.copy(tag)
t.original_name = '.'.join(components[:i+1])
t.count = 0
if key != 'search':
# This 'manufactured' intermediate node can
# be searched, but cannot be edited.
@ -524,6 +525,12 @@ class TagsModel(QAbstractItemModel): # {{{
for category in self.category_nodes:
process_one_node(category, state_map.get(category.category_key, {}))
def get_category_editor_data(self, category):
for cat in self.root_item.children:
if cat.category_key == category:
return [(t.tag.id, t.tag.original_name, t.tag.count)
for t in cat.child_tags() if t.tag.count > 0]
# Drag'n Drop {{{
def mimeTypes(self):
return ["application/calibre+from_library",

View File

@ -196,11 +196,10 @@ class TagBrowserMixin(object): # {{{
Open the 'manage_X' dialog where X == category. If tag is not None, the
dialog will position the editor on that item.
'''
db=self.library_view.model().db
cats = db.get_categories(sort='name', icon_map=None)
if category in cats:
result = [(t.id, t.name, t.count) for t in cats[category]]
else:
tags_model = self.tags_view.model()
result = tags_model.get_category_editor_data(category)
if result is None:
return
if category == 'series':
@ -208,6 +207,7 @@ class TagBrowserMixin(object): # {{{
else:
key = sort_key
db=self.library_view.model().db
d = TagListEditor(self, cat_name=db.field_metadata[category]['name'],
tag_to_match=tag, data=result, sorter=key)
d.exec_()