mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Bug #1996559: Saved Search: Renamed saved search oddities
Changed saved search nodes generated by walking a hierarchy to do nothing when clicked and to have an appropriate tooltip. Also removed the search icon for these saved search nodes, since they aren't searches.
This commit is contained in:
parent
708155f2d6
commit
088e9b1b47
@ -146,6 +146,8 @@ class TagTreeItem: # {{{
|
|||||||
def average_rating(self):
|
def average_rating(self):
|
||||||
if self.type != self.TAG:
|
if self.type != self.TAG:
|
||||||
return 0
|
return 0
|
||||||
|
if self.tag.category == 'search':
|
||||||
|
return None
|
||||||
if not self.tag.is_hierarchical:
|
if not self.tag.is_hierarchical:
|
||||||
return self.tag.avg_rating
|
return self.tag.avg_rating
|
||||||
if not self.children:
|
if not self.children:
|
||||||
@ -217,6 +219,11 @@ class TagTreeItem: # {{{
|
|||||||
return self.icon_state_map[tag.state]
|
return self.icon_state_map[tag.state]
|
||||||
if role == Qt.ItemDataRole.ToolTipRole:
|
if role == Qt.ItemDataRole.ToolTipRole:
|
||||||
if gprefs['tag_browser_show_tooltips']:
|
if gprefs['tag_browser_show_tooltips']:
|
||||||
|
if self.type == self.TAG and tag.category == 'search':
|
||||||
|
if tag.search_expression is None:
|
||||||
|
return _('{} is not a saved search').format(tag.original_name)
|
||||||
|
return (f'search:{tag.original_name}\n' +
|
||||||
|
_('Search expression:') + ' ' + tag.search_expression)
|
||||||
tt = [self.tooltip] if self.tooltip else []
|
tt = [self.tooltip] if self.tooltip else []
|
||||||
if tag.original_categories:
|
if tag.original_categories:
|
||||||
tt.append('{}:{}'.format(','.join(tag.original_categories), tag.original_name))
|
tt.append('{}:{}'.format(','.join(tag.original_categories), tag.original_name))
|
||||||
@ -225,11 +232,9 @@ class TagTreeItem: # {{{
|
|||||||
ar = self.average_rating
|
ar = self.average_rating
|
||||||
if ar:
|
if ar:
|
||||||
tt.append(_('Average rating for books in this category: %.1f') % ar)
|
tt.append(_('Average rating for books in this category: %.1f') % ar)
|
||||||
elif self.type == self.TAG and ar is not None and self.tag.category != 'search':
|
elif self.type == self.TAG and ar is not None:
|
||||||
tt.append(_('Books in this category are unrated'))
|
tt.append(_('Books in this category are unrated'))
|
||||||
if self.type == self.TAG and self.tag.category == 'search':
|
if self.type == self.TAG and tag.category != 'search':
|
||||||
tt.append(_('Search expression:') + ' ' + self.tag.search_expression)
|
|
||||||
if self.type == self.TAG and self.tag.category != 'search':
|
|
||||||
tt.append(_('Number of books: %s') % self.item_count)
|
tt.append(_('Number of books: %s') % self.item_count)
|
||||||
return '\n'.join(tt)
|
return '\n'.join(tt)
|
||||||
return None
|
return None
|
||||||
@ -262,24 +267,25 @@ class TagTreeItem: # {{{
|
|||||||
'''
|
'''
|
||||||
set_to: None => advance the state, otherwise a value from TAG_SEARCH_STATES
|
set_to: None => advance the state, otherwise a value from TAG_SEARCH_STATES
|
||||||
'''
|
'''
|
||||||
|
tag = self.tag
|
||||||
if set_to is None:
|
if set_to is None:
|
||||||
while True:
|
while True:
|
||||||
tag_search_order_graph = gprefs.get('tb_search_order')
|
tag_search_order_graph = gprefs.get('tb_search_order')
|
||||||
# JSON dumps converts integer keys to strings, so do it explicitly
|
# JSON dumps converts integer keys to strings, so do it explicitly
|
||||||
self.tag.state = tag_search_order_graph[str(self.tag.state)]
|
tag.state = tag_search_order_graph[str(tag.state)]
|
||||||
if self.tag.state == TAG_SEARCH_STATES['mark_plus'] or \
|
if tag.state == TAG_SEARCH_STATES['mark_plus'] or \
|
||||||
self.tag.state == TAG_SEARCH_STATES['mark_minus']:
|
tag.state == TAG_SEARCH_STATES['mark_minus']:
|
||||||
if self.tag.is_searchable:
|
if tag.is_searchable:
|
||||||
break
|
break
|
||||||
elif self.tag.state == TAG_SEARCH_STATES['mark_plusplus'] or\
|
elif tag.state == TAG_SEARCH_STATES['mark_plusplus'] or\
|
||||||
self.tag.state == TAG_SEARCH_STATES['mark_minusminus']:
|
tag.state == TAG_SEARCH_STATES['mark_minusminus']:
|
||||||
if self.tag.is_searchable and len(self.children) and \
|
if tag.is_searchable and len(self.children) and \
|
||||||
self.tag.is_hierarchical == '5state':
|
tag.is_hierarchical == '5state':
|
||||||
break
|
break
|
||||||
else:
|
else:
|
||||||
break
|
break
|
||||||
else:
|
else:
|
||||||
self.tag.state = set_to
|
tag.state = set_to
|
||||||
|
|
||||||
def all_children(self):
|
def all_children(self):
|
||||||
res = []
|
res = []
|
||||||
@ -756,6 +762,7 @@ class TagsModel(QAbstractItemModel): # {{{
|
|||||||
t.is_editable = False
|
t.is_editable = False
|
||||||
else:
|
else:
|
||||||
t.is_searchable = t.is_editable = False
|
t.is_searchable = t.is_editable = False
|
||||||
|
t.search_expression = None
|
||||||
intermediate_nodes[original_name,child_key] = t
|
intermediate_nodes[original_name,child_key] = t
|
||||||
else:
|
else:
|
||||||
t = tag
|
t = tag
|
||||||
@ -1658,6 +1665,9 @@ class TagsModel(QAbstractItemModel): # {{{
|
|||||||
if not index.isValid():
|
if not index.isValid():
|
||||||
return False
|
return False
|
||||||
item = self.get_node(index)
|
item = self.get_node(index)
|
||||||
|
tag = item.tag
|
||||||
|
if tag.category == 'search' and tag.search_expression is None:
|
||||||
|
return False
|
||||||
item.toggle(set_to=set_to)
|
item.toggle(set_to=set_to)
|
||||||
if exclusive:
|
if exclusive:
|
||||||
self.reset_all_states(except_=item.tag)
|
self.reset_all_states(except_=item.tag)
|
||||||
|
@ -112,7 +112,8 @@ class TagDelegate(QStyledItemDelegate): # {{{
|
|||||||
style = QApplication.style() if widget is None else widget.style()
|
style = QApplication.style() if widget is None else widget.style()
|
||||||
self.initStyleOption(option, index)
|
self.initStyleOption(option, index)
|
||||||
item = index.data(Qt.ItemDataRole.UserRole)
|
item = index.data(Qt.ItemDataRole.UserRole)
|
||||||
self.draw_icon(style, painter, option, widget)
|
if item.type != TagTreeItem.TAG or item.tag.category != 'search' or item.tag.search_expression:
|
||||||
|
self.draw_icon(style, painter, option, widget)
|
||||||
painter.save()
|
painter.save()
|
||||||
self.draw_text(style, painter, option, widget, index, item)
|
self.draw_text(style, painter, option, widget, index, item)
|
||||||
painter.restore()
|
painter.restore()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user