add option to show only category in current library

This commit is contained in:
un-pogaz 2025-01-29 22:55:50 +01:00
parent 2c68207773
commit 01610583cf
2 changed files with 29 additions and 9 deletions

View File

@ -288,6 +288,8 @@ class TbIconRulesTab(LazyConfigWidgetBase, Ui_Form):
r('tag_browser_show_category_icons', gprefs)
r('tag_browser_show_value_icons', gprefs)
self.show_only_current_library.setChecked(gprefs.get('tag_browser_rules_show_only_current_library', False))
self.rules_table.setSelectionBehavior(QAbstractItemView.SelectionBehavior.SelectItems)
self.rules_table.setColumnCount(HEADER_SECTION_COUNT)
self.rules_table.setHorizontalHeaderLabels(('', _('Category'), _('Value'), '',
@ -330,6 +332,7 @@ class TbIconRulesTab(LazyConfigWidgetBase, Ui_Form):
self.delete_button.clicked.connect(self.delete_rule)
self.edit_button.clicked.connect(self.edit_column)
self.undo_button.clicked.connect(self.undo_changes)
self.show_only_current_library.stateChanged.connect(self.change_filter_library)
self.tb_icon_rules_groupbox.setContentsMargins(0, 0, 0, 0)
self.tb_icon_rules_gridlayout.setContentsMargins(2, 2, 2, 2)
@ -340,19 +343,28 @@ class TbIconRulesTab(LazyConfigWidgetBase, Ui_Form):
pass
def lazy_initialize(self):
self.rules_table.setItemDelegateForColumn(ICON_COLUMN, IconColumnDelegate(self, self.rules_table, self.changed_signal))
self.rules_table.setItemDelegateForColumn(FOR_CHILDREN_COLUMN,
ChildrenColumnDelegate(self, self.rules_table, self.changed_signal))
self.populate_content()
self.section_order = [0, 1, 1, 0, 0, 0, 0]
self.do_sort(VALUE_COLUMN)
self.do_sort(CATEGORY_COLUMN)
def populate_content(self):
field_metadata = self.gui.current_db.field_metadata
category_icons = self.gui.tags_view.model().category_custom_icons
v = gprefs['tags_browser_value_icons']
row = 0
t = self.rules_table
t.setItemDelegateForColumn(ICON_COLUMN, IconColumnDelegate(self, self.rules_table, self.changed_signal))
t.setItemDelegateForColumn(FOR_CHILDREN_COLUMN,
ChildrenColumnDelegate(self, self.rules_table, self.changed_signal))
t.clearContents()
for category,vdict in v.items():
if category in field_metadata:
display_name = field_metadata[category]['name']
elif self.show_only_current_library.isChecked():
continue
else:
display_name = category.removeprefix('#')
for item_value in vdict:
@ -369,10 +381,6 @@ class TbIconRulesTab(LazyConfigWidgetBase, Ui_Form):
t.setItem(row, FOR_CHILDREN_COLUMN, item)
row += 1
self.section_order = [0, 1, 1, 0, 0, 0, 0]
self.do_sort(VALUE_COLUMN)
self.do_sort(CATEGORY_COLUMN)
def show_context_menu(self, point):
item = self.rules_table.itemAt(point)
if item is None:
@ -416,6 +424,10 @@ class TbIconRulesTab(LazyConfigWidgetBase, Ui_Form):
return
return super().keyPressEvent(ev)
def change_filter_library(self, state):
gprefs['tag_browser_rules_show_only_current_library'] = self.show_only_current_library.isChecked()
self.populate_content()
def undo_changes(self):
idx = self.rules_table.currentIndex()
if idx.isValid():
@ -484,6 +496,7 @@ class TbIconRulesTab(LazyConfigWidgetBase, Ui_Form):
else:
self.rules_table.setColumnWidth(c, w)
self.table_column_widths.append(self.rules_table.columnWidth(c))
gprefs['tag_browser_rules_dialog_table_widths'] = self.table_column_widths
def do_sort(self, section):

View File

@ -51,10 +51,17 @@ are defined per-user, not per-library.&lt;/p&gt;</string>
</property>
</widget>
</item>
<item row="1" column="1">
<item row="1" column="0" colspan="2">
<widget class="QCheckBox" name="show_only_current_library">
<property name="text">
<string>Show only category available in the current library</string>
</property>
</widget>
</item>
<item row="2" column="1">
<widget class="QTableWidget" name="rules_table"/>
</item>
<item row="1" column="0">
<item row="2" column="0">
<layout class="QVBoxLayout">
<item>
<widget class="QToolButton" name="delete_button">