mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
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:
parent
584137aa82
commit
56cf0d6559
@ -59,14 +59,24 @@ class TagCategories(QDialog, Ui_TagCategories):
|
|||||||
]
|
]
|
||||||
category_names = ['', _('Authors'), _('Series'), _('Publishers'), _('Tags')]
|
category_names = ['', _('Authors'), _('Series'), _('Publishers'), _('Tags')]
|
||||||
|
|
||||||
cc_map = self.db.custom_column_label_map
|
cvals = {}
|
||||||
for cc in cc_map:
|
for key,cc in self.db.custom_field_metadata().iteritems():
|
||||||
if cc_map[cc]['datatype'] in ['text', 'series']:
|
if cc['datatype'] in ['text', 'series', 'enumeration']:
|
||||||
self.category_labels.append(db.field_metadata.label_to_key(cc))
|
self.category_labels.append(key)
|
||||||
category_icons.append(cc_icon)
|
category_icons.append(cc_icon)
|
||||||
category_values.append(lambda col=cc: self.db.all_custom(label=col))
|
category_values.append(lambda col=cc['label']: self.db.all_custom(label=col))
|
||||||
category_names.append(cc_map[cc]['name'])
|
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 = []
|
||||||
self.all_items_dict = {}
|
self.all_items_dict = {}
|
||||||
for idx,label in enumerate(self.category_labels):
|
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 l[1] in self.category_labels:
|
||||||
if t is None:
|
if t is None:
|
||||||
t = Item(name=l[0], label=l[1], index=len(self.all_items),
|
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.append(t)
|
||||||
self.all_items_dict[key] = t
|
self.all_items_dict[key] = t
|
||||||
l[2] = t.index
|
l[2] = t.index
|
||||||
@ -108,13 +119,16 @@ class TagCategories(QDialog, Ui_TagCategories):
|
|||||||
self.add_category_button.clicked.connect(self.add_category)
|
self.add_category_button.clicked.connect(self.add_category)
|
||||||
self.rename_category_button.clicked.connect(self.rename_category)
|
self.rename_category_button.clicked.connect(self.rename_category)
|
||||||
self.category_box.currentIndexChanged[int].connect(self.select_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)
|
self.delete_category_button.clicked.connect(self.del_category)
|
||||||
if islinux:
|
if islinux:
|
||||||
self.available_items_box.itemDoubleClicked.connect(self.apply_tags)
|
self.available_items_box.itemDoubleClicked.connect(self.apply_tags)
|
||||||
else:
|
else:
|
||||||
self.connect(self.available_items_box, SIGNAL('itemActivated(QListWidgetItem*)'), self.apply_tags)
|
self.connect(self.available_items_box,
|
||||||
self.connect(self.applied_items_box, SIGNAL('itemActivated(QListWidgetItem*)'), self.unapply_tags)
|
SIGNAL('itemActivated(QListWidgetItem*)'), self.apply_tags)
|
||||||
|
self.connect(self.applied_items_box,
|
||||||
|
SIGNAL('itemActivated(QListWidgetItem*)'), self.unapply_tags)
|
||||||
|
|
||||||
self.populate_category_list()
|
self.populate_category_list()
|
||||||
if on_category is not None:
|
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)')
|
n = item.name if item.exists else item.name + _(' (not on any book)')
|
||||||
w = QListWidgetItem(item.icon, n)
|
w = QListWidgetItem(item.icon, n)
|
||||||
w.setData(Qt.UserRole, item.index)
|
w.setData(Qt.UserRole, item.index)
|
||||||
|
w.setToolTip(_('Category lookup name: ') + item.label)
|
||||||
return w
|
return w
|
||||||
|
|
||||||
def display_filtered_categories(self, idx):
|
def display_filtered_categories(self, idx):
|
||||||
|
@ -510,9 +510,11 @@ class TagsView(QTreeView): # {{{
|
|||||||
if hasattr(md, 'column_name'):
|
if hasattr(md, 'column_name'):
|
||||||
fm_src = self.db.metadata_for_field(md.column_name)
|
fm_src = self.db.metadata_for_field(md.column_name)
|
||||||
if md.column_name in ['authors', 'publisher', 'series'] or \
|
if md.column_name in ['authors', 'publisher', 'series'] or \
|
||||||
(fm_src['is_custom'] and
|
(fm_src['is_custom'] and (
|
||||||
fm_src['datatype'] in ['series', 'text'] and
|
(fm_src['datatype'] in ['series', 'text', 'enumeration'] and
|
||||||
not fm_src['is_multiple']):
|
not fm_src['is_multiple']) or
|
||||||
|
(fm_src['datatype'] == 'composite' and
|
||||||
|
fm_src['display'].get('make_category', False)))):
|
||||||
self.setDropIndicatorShown(True)
|
self.setDropIndicatorShown(True)
|
||||||
|
|
||||||
def clear(self):
|
def clear(self):
|
||||||
@ -976,8 +978,11 @@ class TagsModel(QAbstractItemModel): # {{{
|
|||||||
fm = self.db.metadata_for_field(node.tag.category)
|
fm = self.db.metadata_for_field(node.tag.category)
|
||||||
if node.tag.category in \
|
if node.tag.category in \
|
||||||
('tags', 'series', 'authors', 'rating', 'publisher') or \
|
('tags', 'series', 'authors', 'rating', 'publisher') or \
|
||||||
(fm['is_custom'] and \
|
(fm['is_custom'] and (
|
||||||
fm['datatype'] in ['text', 'rating', 'series']):
|
fm['datatype'] in ['text', 'rating', 'series',
|
||||||
|
'enumeration'] or
|
||||||
|
(fm['datatype'] == 'composite' and
|
||||||
|
fm['display'].get('make_category', False)))):
|
||||||
mime = 'application/calibre+from_library'
|
mime = 'application/calibre+from_library'
|
||||||
ids = list(map(int, str(md.data(mime)).split()))
|
ids = list(map(int, str(md.data(mime)).split()))
|
||||||
self.handle_drop(node, ids)
|
self.handle_drop(node, ids)
|
||||||
@ -987,9 +992,11 @@ class TagsModel(QAbstractItemModel): # {{{
|
|||||||
if fm_dest['kind'] == 'user':
|
if fm_dest['kind'] == 'user':
|
||||||
fm_src = self.db.metadata_for_field(md.column_name)
|
fm_src = self.db.metadata_for_field(md.column_name)
|
||||||
if md.column_name in ['authors', 'publisher', 'series'] or \
|
if md.column_name in ['authors', 'publisher', 'series'] or \
|
||||||
(fm_src['is_custom'] and
|
(fm_src['is_custom'] and (
|
||||||
fm_src['datatype'] in ['series', 'text'] and
|
(fm_src['datatype'] in ['series', 'text', 'enumeration'] and
|
||||||
not fm_src['is_multiple']):
|
not fm_src['is_multiple']))or
|
||||||
|
(fm_src['datatype'] == 'composite' and
|
||||||
|
fm_src['display'].get('make_category', False))):
|
||||||
mime = 'application/calibre+from_library'
|
mime = 'application/calibre+from_library'
|
||||||
ids = list(map(int, str(md.data(mime)).split()))
|
ids = list(map(int, str(md.data(mime)).split()))
|
||||||
self.handle_user_category_drop(node, ids, md.column_name)
|
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)
|
value = self.db.series(id, index_is_id=True)
|
||||||
else:
|
else:
|
||||||
items = self.db.get_custom_items_with_ids(label=label)
|
items = self.db.get_custom_items_with_ids(label=label)
|
||||||
value = self.db.get_custom(id, label=label, index_is_id=True)
|
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:
|
if value is None:
|
||||||
return
|
return
|
||||||
if not isinstance(value, list):
|
if not isinstance(value, list):
|
||||||
value = [value]
|
value = [value]
|
||||||
for v in items:
|
|
||||||
vmap[v[1]] = v[0]
|
|
||||||
for val in value:
|
for val in value:
|
||||||
for (v, c, id) in category:
|
for (v, c, id) in category:
|
||||||
if v == val and c == column:
|
if v == val and c == column:
|
||||||
break
|
break
|
||||||
else:
|
else:
|
||||||
category.append([val, column, vmap[val]])
|
category.append([val, column, 0])
|
||||||
categories[on_node.category_key[1:]] = category
|
categories[on_node.category_key[1:]] = category
|
||||||
self.db.prefs.set('user_categories', categories)
|
self.db.prefs.set('user_categories', categories)
|
||||||
self.tags_view.recount()
|
self.tags_view.recount()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user