*fix displayed/total on views, so they are correct on updates

*listviews don't become dirty from add/delete/update signals while
 they are not active. This should improve performance on large trees
 now that these actions are cheap in all views after rework of the views


svn: r14020
This commit is contained in:
Benny Malengier 2010-01-10 15:00:15 +00:00
parent 2e65bfcce4
commit 04763f50fe
4 changed files with 62 additions and 13 deletions

View File

@ -92,7 +92,9 @@ class ListView(NavigationView):
NavigationView.__init__(self, title, dbstate, uistate,
get_bookmarks, bm_type)
#default is listviews keep themself in sync with database
self._dirty_on_change_inactive = False
self.filter_class = filter_class
self.renderer = gtk.CellRendererText()
self.renderer.set_property('ellipsize', pango.ELLIPSIZE_END)
@ -234,6 +236,12 @@ class ListView(NavigationView):
self.list.append_column(column)
index += 1
def set_active(self):
NavigationView.set_active(self)
self.uistate.show_filter_results(self.dbstate,
self.model.displayed(),
self.model.total())
def __build_tree(self):
Utils.profile(self._build_tree)
@ -657,15 +665,17 @@ class ListView(NavigationView):
"""
Called when an object is added.
"""
if self.active:
if self.active or \
(not self.dirty and not self._dirty_on_change_inactive):
cput = time.clock()
for handle in handle_list:
self.model.add_row_by_handle(handle)
_LOG.debug(' ' + self.__class__.__name__ + ' row_add ' +
str(time.clock() - cput) + ' sec')
self.uistate.show_filter_results(self.dbstate,
self.model.displayed(),
self.model.total())
if self.active:
self.uistate.show_filter_results(self.dbstate,
self.model.displayed(),
self.model.total())
else:
self.dirty = True
@ -675,7 +685,8 @@ class ListView(NavigationView):
"""
if self.model:
self.model.prev_handle = None
if self.active:
if self.active or \
(not self.dirty and not self._dirty_on_change_inactive):
cput = time.clock()
for handle in handle_list:
self.model.update_row_by_handle(handle)
@ -691,14 +702,16 @@ class ListView(NavigationView):
"""
Called when an object is deleted.
"""
if self.active:
if self.active or \
(not self.dirty and not self._dirty_on_change_inactive):
cput = time.clock()
map(self.model.delete_row_by_handle, handle_list)
_LOG.debug(' ' + self.__class__.__name__ + ' row_delete ' +
str(time.clock() - cput) + ' sec')
self.uistate.show_filter_results(self.dbstate,
self.model.displayed(),
self.model.total())
if self.active:
self.uistate.show_filter_results(self.dbstate,
self.model.displayed(),
self.model.total())
else:
self.dirty = True
@ -709,7 +722,7 @@ class ListView(NavigationView):
self.dirty = True
if self.active:
self.bookmarks.redraw()
self.build_tree()
self.build_tree()
def _button_press(self, obj, event):
"""

View File

@ -59,6 +59,29 @@ class PageView(DbGUIElement):
The PageView class is the base class for all Data Views in GRAMPS. All
Views should derive from this class. The ViewManager understands the public
interface of this class
The following attributes are available
..attribute:: active
is the view active at the moment (visible in Gramps as the main view)
..attribute:: dirty
bool, is the view current with the database or not. A dirty view triggers
a rebuild when it becomes active
..attribute:: _dirty_on_change_inactive
read/write bool by inheriting classes.
Views can behave two ways to signals:
1. if the view is inactive, set it dirty, and rebuild the view when
it becomes active. In this case, this method returns True
2. if the view is inactive, try to stay in sync with database. Only
rebuild or other large changes make view dirty
..attribute:: title
title of the view
..attribute:: dbstate
the dbstate
..attribute:: uistate
the displaystate
..attribute:: category
the category to which the view belongs. Views in the same category are
placed behind the same button in the sidebar
"""
def __init__(self, title, dbstate, uistate):
@ -76,6 +99,7 @@ class PageView(DbGUIElement):
self.ui_def = '<ui></ui>'
self.dirty = True
self.active = False
self._dirty_on_change_inactive = True
self.func_list = {}
self.category = "Miscellaneous"
self.translated_category = _("Miscellaneous")

View File

@ -57,7 +57,7 @@ from gettext import gettext as _
# PlaceBaseModel
#
#-------------------------------------------------------------------------
class PlaceBaseModel():
class PlaceBaseModel(object):
HANDLE_COL = 12

View File

@ -265,6 +265,9 @@ class TreeBaseModel(gtk.GenericTreeModel):
group_can_have_handle = False):
cput = time.clock()
gtk.GenericTreeModel.__init__(self)
#two unused attributes pesent to correspond to flatbasemodel
self.prev_handle = None
self.prev_data = None
self.__reverse = (order == gtk.SORT_DESCENDING)
self.scol = scol
@ -571,6 +574,8 @@ class TreeBaseModel(gtk.GenericTreeModel):
path = self.on_get_path(child_node)
node = self.get_iter(path)
self.row_inserted(path, node)
self.__total += 1
self.__displayed += 1
if handle:
self.handle2node[handle] = child_node
@ -587,19 +592,26 @@ class TreeBaseModel(gtk.GenericTreeModel):
str(parent) + ' ' + str(child) + ' ' + sortkey
if handle:
node.set_handle(handle)
if not self._in_build:
self.__total += 1
self.__displayed += 1
def remove_node(self, node):
"""
Remove a node from the map.
"""
if node.children:
node.set_handle(None)
self.__displayed -= 1
self.__total -= 1
else:
path = self.on_get_path(node)
self.nodemap.node(node.parent).remove_child(node, self.nodemap)
del self.tree[node.ref]
self.nodemap.del_node(node)
del node
self.__displayed -= 1
self.__total -= 1
# emit row_deleted signal
self.row_deleted(path)