mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-07 18:24:30 -04:00
As sent to Kovid bis
This commit is contained in:
parent
00ff61a76a
commit
4afed97a42
@ -543,8 +543,10 @@ class TagsView(QTreeView): # {{{
|
|||||||
return self.isExpanded(idx)
|
return self.isExpanded(idx)
|
||||||
|
|
||||||
def recount(self, *args):
|
def recount(self, *args):
|
||||||
from calibre.utils.mem import memory
|
'''
|
||||||
print 'start of recount:', memory()
|
Rebuild the category tree, expand any categories that were expanded,
|
||||||
|
reset the search states, and reselect the current node.
|
||||||
|
'''
|
||||||
if self.disable_recounting or not self.pane_is_visible:
|
if self.disable_recounting or not self.pane_is_visible:
|
||||||
return
|
return
|
||||||
self.refresh_signal_processed = True
|
self.refresh_signal_processed = True
|
||||||
@ -557,15 +559,18 @@ class TagsView(QTreeView): # {{{
|
|||||||
for category in expanded_categories:
|
for category in expanded_categories:
|
||||||
self.expand(self.model().index_for_category(category))
|
self.expand(self.model().index_for_category(category))
|
||||||
self._model.show_item_at_path(path)
|
self._model.show_item_at_path(path)
|
||||||
print 'end of recount:', memory()
|
|
||||||
|
|
||||||
def item_expanded(self, idx):
|
def item_expanded(self, idx):
|
||||||
|
'''
|
||||||
|
Called by the expanded signal
|
||||||
|
'''
|
||||||
self.setCurrentIndex(idx)
|
self.setCurrentIndex(idx)
|
||||||
|
|
||||||
# If the number of user categories changed, if custom columns have come or
|
|
||||||
# gone, or if columns have been hidden or restored, we must rebuild the
|
|
||||||
# model. Reason: it is much easier than reconstructing the browser tree.
|
|
||||||
def set_new_model(self, filter_categories_by=None, state_map={}):
|
def set_new_model(self, filter_categories_by=None, state_map={}):
|
||||||
|
'''
|
||||||
|
There are cases where we need to rebuild the category tree without
|
||||||
|
attempting to reposition the current node.
|
||||||
|
'''
|
||||||
try:
|
try:
|
||||||
old = getattr(self, '_model', None)
|
old = getattr(self, '_model', None)
|
||||||
if old is not None:
|
if old is not None:
|
||||||
@ -784,11 +789,10 @@ class TagsModel(QAbstractItemModel): # {{{
|
|||||||
self.filter_categories_by = filter_categories_by
|
self.filter_categories_by = filter_categories_by
|
||||||
self.collapse_model = collapse_model
|
self.collapse_model = collapse_model
|
||||||
|
|
||||||
# get_category_nodes cannot return None here, because row_map is empty.
|
# Note that _get_category_nodes can indirectly change the
|
||||||
# Note that get_category_nodes can indirectly change the user_categories
|
# user_categories dict.
|
||||||
# dict.
|
|
||||||
|
|
||||||
data = self.get_category_nodes(config['sort_tags_by'])
|
data = self._get_category_nodes(config['sort_tags_by'])
|
||||||
gst = db.prefs.get('grouped_search_terms', {})
|
gst = db.prefs.get('grouped_search_terms', {})
|
||||||
self.root_item = TagTreeItem(icon_map=self.icon_state_map)
|
self.root_item = TagTreeItem(icon_map=self.icon_state_map)
|
||||||
self.category_nodes = []
|
self.category_nodes = []
|
||||||
@ -853,7 +857,7 @@ class TagsModel(QAbstractItemModel): # {{{
|
|||||||
category_node_map[key] = node
|
category_node_map[key] = node
|
||||||
last_category_node = node
|
last_category_node = node
|
||||||
self.category_nodes.append(node)
|
self.category_nodes.append(node)
|
||||||
self.create_node_tree(data, state_map)
|
self._create_node_tree(data, state_map)
|
||||||
|
|
||||||
def break_cycles(self):
|
def break_cycles(self):
|
||||||
self.root_item.break_cycles()
|
self.root_item.break_cycles()
|
||||||
@ -1130,8 +1134,10 @@ class TagsModel(QAbstractItemModel): # {{{
|
|||||||
def set_search_restriction(self, s):
|
def set_search_restriction(self, s):
|
||||||
self.search_restriction = s
|
self.search_restriction = s
|
||||||
|
|
||||||
def get_category_nodes(self, sort):
|
def _get_category_nodes(self, sort):
|
||||||
old_row_map_len = len(self.row_map)
|
'''
|
||||||
|
Called by __init__. Do not directly call this method.
|
||||||
|
'''
|
||||||
self.row_map = []
|
self.row_map = []
|
||||||
self.categories = {}
|
self.categories = {}
|
||||||
|
|
||||||
@ -1185,23 +1191,25 @@ class TagsModel(QAbstractItemModel): # {{{
|
|||||||
if category in data: # The search category can come and go
|
if category in data: # The search category can come and go
|
||||||
self.row_map.append(category)
|
self.row_map.append(category)
|
||||||
self.categories[category] = tb_categories[category]['name']
|
self.categories[category] = tb_categories[category]['name']
|
||||||
|
|
||||||
if old_row_map_len != 0 and old_row_map_len != len(self.row_map):
|
|
||||||
# A category has been added or removed. We must force a rebuild of
|
|
||||||
# the model
|
|
||||||
return None
|
|
||||||
return data
|
return data
|
||||||
|
|
||||||
def refresh(self, data=None):
|
def refresh(self, data=None):
|
||||||
print 'refresh called'
|
'''
|
||||||
|
Here to trap usages of refresh in the old architecture. Can eventually
|
||||||
|
be removed.
|
||||||
|
'''
|
||||||
|
print 'TagsModel: refresh called!'
|
||||||
traceback.print_stack()
|
traceback.print_stack()
|
||||||
return False
|
return False
|
||||||
|
|
||||||
def create_node_tree(self, data, state_map):
|
def _create_node_tree(self, data, state_map):
|
||||||
|
'''
|
||||||
|
Called by __init__. Do not directly call this method.
|
||||||
|
'''
|
||||||
sort_by = config['sort_tags_by']
|
sort_by = config['sort_tags_by']
|
||||||
|
|
||||||
if data is None:
|
if data is None:
|
||||||
print 'NO DATA!!!!'
|
print '_create_node_tree: no data!'
|
||||||
traceback.print_stack()
|
traceback.print_stack()
|
||||||
return
|
return
|
||||||
|
|
||||||
@ -1369,11 +1377,7 @@ class TagsModel(QAbstractItemModel): # {{{
|
|||||||
# }}}
|
# }}}
|
||||||
|
|
||||||
for category in self.category_nodes:
|
for category in self.category_nodes:
|
||||||
if len(category.children) > 0:
|
|
||||||
print 'HAS CHILDREN!!!'
|
|
||||||
continue
|
|
||||||
process_one_node(category, state_map.get(category.py_name, {}))
|
process_one_node(category, state_map.get(category.py_name, {}))
|
||||||
return True
|
|
||||||
|
|
||||||
def get_state(self):
|
def get_state(self):
|
||||||
state_map = {}
|
state_map = {}
|
||||||
@ -1802,19 +1806,22 @@ class TagsModel(QAbstractItemModel): # {{{
|
|||||||
return v
|
return v
|
||||||
return None
|
return None
|
||||||
|
|
||||||
def show_item_at_path(self, path, box=False):
|
def show_item_at_path(self, path, box=False,
|
||||||
|
position=QTreeView.PositionAtCenter):
|
||||||
'''
|
'''
|
||||||
Scroll the browser and open categories to show the item referenced by
|
Scroll the browser and open categories to show the item referenced by
|
||||||
path. If possible, the item is placed in the center. If box=True, a
|
path. If possible, the item is placed in the center. If box=True, a
|
||||||
box is drawn around the item.
|
box is drawn around the item.
|
||||||
'''
|
'''
|
||||||
if path:
|
if path:
|
||||||
self.show_item_at_index(self.index_for_path(path), box)
|
self.show_item_at_index(self.index_for_path(path), box=box,
|
||||||
|
position=position)
|
||||||
|
|
||||||
def show_item_at_index(self, idx, box=False):
|
def show_item_at_index(self, idx, box=False,
|
||||||
|
position=QTreeView.PositionAtCenter):
|
||||||
if idx.isValid():
|
if idx.isValid():
|
||||||
self.tags_view.setCurrentIndex(idx)
|
self.tags_view.setCurrentIndex(idx)
|
||||||
self.tags_view.scrollTo(idx, QTreeView.PositionAtCenter)
|
self.tags_view.scrollTo(idx, position)
|
||||||
if box:
|
if box:
|
||||||
tag_item = idx.internalPointer()
|
tag_item = idx.internalPointer()
|
||||||
tag_item.boxed = True
|
tag_item.boxed = True
|
||||||
|
Loading…
x
Reference in New Issue
Block a user