Enhancement: add restricting to the current VL in the tag browser category editor. See https://www.mobileread.com/forums/showthread.php?t=315414

This commit is contained in:
Charles Haley 2019-02-23 14:11:53 +00:00
parent 306959fd4a
commit a0f92e9fbb
3 changed files with 48 additions and 22 deletions

View File

@ -91,7 +91,7 @@ class EditColumnDelegate(QItemDelegate):
class TagListEditor(QDialog, Ui_TagListEditor):
def __init__(self, window, cat_name, tag_to_match, data, sorter):
def __init__(self, window, cat_name, tag_to_match, get_book_ids, sorter):
QDialog.__init__(self, window)
Ui_TagListEditor.__init__(self)
self.setupUi(self)
@ -113,15 +113,9 @@ class TagListEditor(QDialog, Ui_TagListEditor):
pass
# initialization
self.to_rename = {}
self.to_delete = set([])
self.all_tags = {}
self.original_names = {}
for k,v,count in data:
self.all_tags[v] = {'key': k, 'count': count, 'cur_name': v, 'is_deleted': False}
self.original_names[k] = v
self.ordered_tags = sorted(self.all_tags.keys(), key=sorter)
self.ordered_tags = []
self.sorter = sorter
self.get_book_ids = get_book_ids
# Set up the column headings
self.down_arrow_icon = QIcon(I('arrow-down.png'))
@ -140,7 +134,7 @@ class TagListEditor(QDialog, Ui_TagListEditor):
self.table.setItemDelegate(EditColumnDelegate(self.table))
# Add the data
select_item = self.fill_in_table(self.ordered_tags, tag_to_match)
select_item = self.fill_in_table(None, tag_to_match)
# Scroll to the selected item if there is one
if select_item is not None:
@ -160,6 +154,8 @@ class TagListEditor(QDialog, Ui_TagListEditor):
self.search_button.clicked.connect(self.all_matching_clicked)
self.search_button.setDefault(True)
self.apply_vl_checkbox.clicked.connect(self.vl_box_changed)
self.table.setEditTriggers(QTableWidget.EditKeyPressed)
try:
@ -171,7 +167,23 @@ class TagListEditor(QDialog, Ui_TagListEditor):
except:
pass
def vl_box_changed(self):
self.fill_in_table(None, None)
def fill_in_table(self, tags, tag_to_match):
self.to_rename = {}
self.to_delete = set([])
self.all_tags = {}
self.original_names = {}
data = self.get_book_ids(self.apply_vl_checkbox.isChecked())
for k,v,count in data:
self.all_tags[v] = {'key': k, 'count': count, 'cur_name': v, 'is_deleted': False}
self.original_names[k] = v
self.ordered_tags = sorted(self.all_tags.keys(), key=self.sorter)
if tags is None:
tags = self.ordered_tags
select_item = None
self.table.blockSignals(True)
self.table.clear()
@ -220,7 +232,7 @@ class TagListEditor(QDialog, Ui_TagListEditor):
self.all_tags[tag]['is_deleted'] = item.is_deleted
search_for = icu_lower(unicode(self.search_box.text()))
if len(search_for) == 0:
self.fill_in_table(self.ordered_tags, None)
self.fill_in_table(None, None)
result = []
for k in self.ordered_tags:
if search_for in icu_lower(unicode(self.all_tags[k]['cur_name'])):

View File

@ -59,7 +59,19 @@
</item>
</layout>
</item>
<item row="1" column="0">
<item row="1" column="0" colspan="3">
<widget class="QCheckBox" name="apply_vl_checkbox">
<property name="toolTip">
<string>&lt;p&gt;Show items in the Available items box only if they appear in the
current virtual library. Applied items not in the VL will be marked
&quot;not on any book&quot;.&lt;/p&gt;</string>
</property>
<property name="text">
<string>&amp;Show only available items in current virtual library</string>
</property>
</widget>
</item>
<item row="2" column="0">
<layout class="QVBoxLayout" name="verticalLayout_2">
<item>
<widget class="QToolButton" name="delete_button">
@ -132,7 +144,7 @@
</item>
</layout>
</item>
<item row="1" column="1">
<item row="2" column="1">
<widget class="QTableWidget" name="table">
<property name="alternatingRowColors">
<bool>true</bool>

View File

@ -237,13 +237,15 @@ class TagBrowserMixin(object): # {{{
'''
db = self.current_db
data = db.new_api.get_categories()
if category in data:
result = [(t.id, t.original_name, t.count) for t in data[category] if t.count > 0]
else:
result = None
if result is None:
return
def get_book_ids(use_virtual_library):
book_ids = None if not use_virtual_library else self.tags_view.model().get_book_ids_to_use()
data = db.new_api.get_categories(book_ids=book_ids)
if category in data:
result = [(t.id, t.original_name, t.count) for t in data[category] if t.count > 0]
else:
result = None
return result
if category == 'series':
key = lambda x:sort_key(title_sort(x))
@ -251,7 +253,7 @@ class TagBrowserMixin(object): # {{{
key = sort_key
d = TagListEditor(self, cat_name=db.field_metadata[category]['name'],
tag_to_match=tag, data=result, sorter=key)
tag_to_match=tag, get_book_ids=get_book_ids, sorter=key)
d.exec_()
if d.result() == d.Accepted:
to_rename = d.to_rename # dict of old id to new name