1) Make drag & drop of composite columns work.

2) Various fixes to manage user categories to accommodate  the above, and to show the existing custom categories.
This commit is contained in:
Charles Haley 2011-03-18 11:44:00 +00:00
parent 584137aa82
commit 56cf0d6559
2 changed files with 47 additions and 23 deletions

View File

@ -59,14 +59,24 @@ class TagCategories(QDialog, Ui_TagCategories):
]
category_names = ['', _('Authors'), _('Series'), _('Publishers'), _('Tags')]
cc_map = self.db.custom_column_label_map
for cc in cc_map:
if cc_map[cc]['datatype'] in ['text', 'series']:
self.category_labels.append(db.field_metadata.label_to_key(cc))
cvals = {}
for key,cc in self.db.custom_field_metadata().iteritems():
if cc['datatype'] in ['text', 'series', 'enumeration']:
self.category_labels.append(key)
category_icons.append(cc_icon)
category_values.append(lambda col=cc: self.db.all_custom(label=col))
category_names.append(cc_map[cc]['name'])
category_values.append(lambda col=cc['label']: self.db.all_custom(label=col))
category_names.append(cc['name'])
elif cc['datatype'] == 'composite' and \
cc['display'].get('make_category', False):
self.category_labels.append(key)
category_icons.append(cc_icon)
category_names.append(cc['name'])
dex = cc['rec_index']
cvals = set()
for book in db.data.iterall():
if book[dex]:
cvals.add(book[dex])
category_values.append(lambda s=list(cvals): s)
self.all_items = []
self.all_items_dict = {}
for idx,label in enumerate(self.category_labels):
@ -88,7 +98,8 @@ class TagCategories(QDialog, Ui_TagCategories):
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)
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
@ -108,13 +119,16 @@ class TagCategories(QDialog, Ui_TagCategories):
self.add_category_button.clicked.connect(self.add_category)
self.rename_category_button.clicked.connect(self.rename_category)
self.category_box.currentIndexChanged[int].connect(self.select_category)
self.category_filter_box.currentIndexChanged[int].connect(self.display_filtered_categories)
self.category_filter_box.currentIndexChanged[int].connect(
self.display_filtered_categories)
self.delete_category_button.clicked.connect(self.del_category)
if islinux:
self.available_items_box.itemDoubleClicked.connect(self.apply_tags)
else:
self.connect(self.available_items_box, SIGNAL('itemActivated(QListWidgetItem*)'), self.apply_tags)
self.connect(self.applied_items_box, SIGNAL('itemActivated(QListWidgetItem*)'), self.unapply_tags)
self.connect(self.available_items_box,
SIGNAL('itemActivated(QListWidgetItem*)'), self.apply_tags)
self.connect(self.applied_items_box,
SIGNAL('itemActivated(QListWidgetItem*)'), self.unapply_tags)
self.populate_category_list()
if on_category is not None:
@ -129,6 +143,7 @@ class TagCategories(QDialog, Ui_TagCategories):
n = item.name if item.exists else item.name + _(' (not on any book)')
w = QListWidgetItem(item.icon, n)
w.setData(Qt.UserRole, item.index)
w.setToolTip(_('Category lookup name: ') + item.label)
return w
def display_filtered_categories(self, idx):

View File

@ -510,9 +510,11 @@ class TagsView(QTreeView): # {{{
if hasattr(md, 'column_name'):
fm_src = self.db.metadata_for_field(md.column_name)
if md.column_name in ['authors', 'publisher', 'series'] or \
(fm_src['is_custom'] and
fm_src['datatype'] in ['series', 'text'] and
not fm_src['is_multiple']):
(fm_src['is_custom'] and (
(fm_src['datatype'] in ['series', 'text', 'enumeration'] and
not fm_src['is_multiple']) or
(fm_src['datatype'] == 'composite' and
fm_src['display'].get('make_category', False)))):
self.setDropIndicatorShown(True)
def clear(self):
@ -976,8 +978,11 @@ class TagsModel(QAbstractItemModel): # {{{
fm = self.db.metadata_for_field(node.tag.category)
if node.tag.category in \
('tags', 'series', 'authors', 'rating', 'publisher') or \
(fm['is_custom'] and \
fm['datatype'] in ['text', 'rating', 'series']):
(fm['is_custom'] and (
fm['datatype'] in ['text', 'rating', 'series',
'enumeration'] or
(fm['datatype'] == 'composite' and
fm['display'].get('make_category', False)))):
mime = 'application/calibre+from_library'
ids = list(map(int, str(md.data(mime)).split()))
self.handle_drop(node, ids)
@ -987,9 +992,11 @@ class TagsModel(QAbstractItemModel): # {{{
if fm_dest['kind'] == 'user':
fm_src = self.db.metadata_for_field(md.column_name)
if md.column_name in ['authors', 'publisher', 'series'] or \
(fm_src['is_custom'] and
fm_src['datatype'] in ['series', 'text'] and
not fm_src['is_multiple']):
(fm_src['is_custom'] and (
(fm_src['datatype'] in ['series', 'text', 'enumeration'] and
not fm_src['is_multiple']))or
(fm_src['datatype'] == 'composite' and
fm_src['display'].get('make_category', False))):
mime = 'application/calibre+from_library'
ids = list(map(int, str(md.data(mime)).split()))
self.handle_user_category_drop(node, ids, md.column_name)
@ -1019,19 +1026,21 @@ class TagsModel(QAbstractItemModel): # {{{
value = self.db.series(id, index_is_id=True)
else:
items = self.db.get_custom_items_with_ids(label=label)
if fm_src['datatype'] != 'composite':
value = self.db.get_custom(id, label=label, index_is_id=True)
else:
value = self.db.get_property(id, loc=fm_src['rec_index'],
index_is_id=True)
if value is None:
return
if not isinstance(value, list):
value = [value]
for v in items:
vmap[v[1]] = v[0]
for val in value:
for (v, c, id) in category:
if v == val and c == column:
break
else:
category.append([val, column, vmap[val]])
category.append([val, column, 0])
categories[on_node.category_key[1:]] = category
self.db.prefs.set('user_categories', categories)
self.tags_view.recount()