From afefdb09a700be9a45775196ee1a86dc1ffb0514 Mon Sep 17 00:00:00 2001 From: Tim G L Lyons Date: Thu, 29 Sep 2011 18:00:58 +0000 Subject: [PATCH] Fixes for database update signal handling for treemodel as used for the citation tree - corrected handing of setting of the handle of a node to 'None' for a non-leaf (heading) node - only insert the citation leaf node if it is not already present. svn: r18220 --- src/gui/views/treemodels/citationtreemodel.py | 13 ++-- src/gui/views/treemodels/treebasemodel.py | 7 ++- src/plugins/view/citationtreeview.py | 63 ++++++++++++++++--- 3 files changed, 68 insertions(+), 15 deletions(-) diff --git a/src/gui/views/treemodels/citationtreemodel.py b/src/gui/views/treemodels/citationtreemodel.py index 0f45fe9c6..818940083 100644 --- a/src/gui/views/treemodels/citationtreemodel.py +++ b/src/gui/views/treemodels/citationtreemodel.py @@ -162,12 +162,13 @@ class CitationTreeModel(CitationBaseModel, TreeBaseModel): for j in i: source_handle_list.append(j) for citation_handle in source_handle_list: -# # add as node: parent, child, sortkey, handle; parent and child are -# # nodes in the treebasemodel, and will be used as iters - citation = self.db.get_citation_from_handle(citation_handle) - citation_page = citation.get_page() - self.add_node(handle, citation_handle, citation_page, - citation_handle, secondary=True) + if self.get_node(citation_handle) is None: + # # add as node: parent, child, sortkey, handle; parent and child are + # # nodes in the treebasemodel, and will be used as iters + citation = self.db.get_citation_from_handle(citation_handle) + citation_page = citation.get_page() + self.add_node(handle, citation_handle, citation_page, + citation_handle, secondary=True) # try: # source_handle = data[COLUMN_SOURCE] # except: diff --git a/src/gui/views/treemodels/treebasemodel.py b/src/gui/views/treemodels/treebasemodel.py index 376203fbe..0ee987620 100644 --- a/src/gui/views/treemodels/treebasemodel.py +++ b/src/gui/views/treemodels/treebasemodel.py @@ -99,7 +99,7 @@ class Node(object): """ Assign the handle of a Gramps object to this node. """ - if not self.handle: + if not self.handle or handle == None: self.handle = handle self.secondary = secondary else: @@ -609,6 +609,7 @@ class TreeBaseModel(gtk.GenericTreeModel): Remove a node from the map. """ if node.children: + del self.handle2node[node.handle] node.set_handle(None) self.__displayed -= 1 self.__total -= 1 @@ -687,6 +688,8 @@ class TreeBaseModel(gtk.GenericTreeModel): _LOG.debug(self.__class__.__name__ + ' add_row_by_handle ' + str(time.clock() - cput) + ' sec') + _LOG.debug("displayed %d / total: %d" % + (self.__displayed, self.__total)) def delete_row_by_handle(self, handle): """ @@ -715,6 +718,8 @@ class TreeBaseModel(gtk.GenericTreeModel): _LOG.debug(self.__class__.__name__ + ' delete_row_by_handle ' + str(time.clock() - cput) + ' sec') + _LOG.debug("displayed %d / total: %d" % + (self.__displayed, self.__total)) def update_row_by_handle(self, handle): """ diff --git a/src/plugins/view/citationtreeview.py b/src/plugins/view/citationtreeview.py index 219593a59..4a709f77b 100644 --- a/src/plugins/view/citationtreeview.py +++ b/src/plugins/view/citationtreeview.py @@ -31,6 +31,7 @@ A view showing all the Sources with child Citations #------------------------------------------------------------------------- import logging LOG = logging.getLogger(".citation") +_LOG = logging.getLogger('.gui.citationtreeview') #------------------------------------------------------------------------- # @@ -116,14 +117,14 @@ class CitationTreeView(ListView): def __init__(self, pdata, dbstate, uistate, nav_group=0): signal_map = { - 'citation-add' : self.row_add, - 'citation-update' : self.row_update, - 'citation-delete' : self.row_delete, - 'citation-rebuild' : self.object_build, - 'source-add' : self.row_add, - 'source-update' : self.row_update, - 'source-delete' : self.row_delete, - 'source-rebuild' : self.object_build, + 'citation-add' : self._citation_row_add, + 'citation-update' : self._citation_row_update, + 'citation-delete' : self._citation_row_delete, + 'citation-rebuild' : self._citation_object_build, + 'source-add' : self._source_row_add, + 'source-update' : self._source_row_update, + 'source-delete' : self._source_row_delete, + 'source-rebuild' : self._source_object_build, } ListView.__init__( @@ -142,6 +143,52 @@ class CitationTreeView(ListView): self.additional_uis.append(self.additional_ui()) + def _print_handles(self, text, handle_list): + for handle in handle_list: + source = self.dbstate.db.get_source_from_handle(handle) + citation = self.dbstate.db.get_citation_from_handle(handle) + _LOG.debug("\n\n\n") + if source: + _LOG.debug("---- %s -- source %s" % + (text, source.get_title())) + elif citation: + _LOG.debug("---- %s -- citation %s" % + (text, citation.get_page())) + else: + _LOG.debug("---- %s -- handle %s" % (text, handle)) + + def _citation_row_add(self, handle_list): + self._print_handles("citation row add", handle_list) + self.row_add(handle_list) + + def _citation_row_update(self, handle_list): + self._print_handles("citation row update", handle_list) + self.row_update(handle_list) + + def _citation_row_delete(self, handle_list): + self._print_handles("citation row delete", handle_list) + self.row_delete(handle_list) + + def _citation_object_build(self, *args): + _LOG.debug("citation object build") + self.object_build(*args) + + def _source_row_add(self, handle_list): + self._print_handles("source row add", handle_list) + self.row_add(handle_list) + + def _source_row_update(self, handle_list): + self._print_handles("source row update", handle_list) + self.row_update(handle_list) + + def _source_row_delete(self, handle_list): + self._print_handles("source row delete", handle_list) + self.row_delete(handle_list) + + def _source_object_build(self, *args): + _LOG.debug("source object build") + self.object_build(*args) + def navigation_type(self): return 'Citation'