*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:
parent
2e65bfcce4
commit
04763f50fe
@ -92,6 +92,8 @@ class ListView(NavigationView):
|
|||||||
|
|
||||||
NavigationView.__init__(self, title, dbstate, uistate,
|
NavigationView.__init__(self, title, dbstate, uistate,
|
||||||
get_bookmarks, bm_type)
|
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.filter_class = filter_class
|
||||||
self.renderer = gtk.CellRendererText()
|
self.renderer = gtk.CellRendererText()
|
||||||
@ -234,6 +236,12 @@ class ListView(NavigationView):
|
|||||||
self.list.append_column(column)
|
self.list.append_column(column)
|
||||||
index += 1
|
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):
|
def __build_tree(self):
|
||||||
Utils.profile(self._build_tree)
|
Utils.profile(self._build_tree)
|
||||||
|
|
||||||
@ -657,15 +665,17 @@ class ListView(NavigationView):
|
|||||||
"""
|
"""
|
||||||
Called when an object is added.
|
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()
|
cput = time.clock()
|
||||||
for handle in handle_list:
|
for handle in handle_list:
|
||||||
self.model.add_row_by_handle(handle)
|
self.model.add_row_by_handle(handle)
|
||||||
_LOG.debug(' ' + self.__class__.__name__ + ' row_add ' +
|
_LOG.debug(' ' + self.__class__.__name__ + ' row_add ' +
|
||||||
str(time.clock() - cput) + ' sec')
|
str(time.clock() - cput) + ' sec')
|
||||||
self.uistate.show_filter_results(self.dbstate,
|
if self.active:
|
||||||
self.model.displayed(),
|
self.uistate.show_filter_results(self.dbstate,
|
||||||
self.model.total())
|
self.model.displayed(),
|
||||||
|
self.model.total())
|
||||||
else:
|
else:
|
||||||
self.dirty = True
|
self.dirty = True
|
||||||
|
|
||||||
@ -675,7 +685,8 @@ class ListView(NavigationView):
|
|||||||
"""
|
"""
|
||||||
if self.model:
|
if self.model:
|
||||||
self.model.prev_handle = None
|
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()
|
cput = time.clock()
|
||||||
for handle in handle_list:
|
for handle in handle_list:
|
||||||
self.model.update_row_by_handle(handle)
|
self.model.update_row_by_handle(handle)
|
||||||
@ -691,14 +702,16 @@ class ListView(NavigationView):
|
|||||||
"""
|
"""
|
||||||
Called when an object is deleted.
|
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()
|
cput = time.clock()
|
||||||
map(self.model.delete_row_by_handle, handle_list)
|
map(self.model.delete_row_by_handle, handle_list)
|
||||||
_LOG.debug(' ' + self.__class__.__name__ + ' row_delete ' +
|
_LOG.debug(' ' + self.__class__.__name__ + ' row_delete ' +
|
||||||
str(time.clock() - cput) + ' sec')
|
str(time.clock() - cput) + ' sec')
|
||||||
self.uistate.show_filter_results(self.dbstate,
|
if self.active:
|
||||||
self.model.displayed(),
|
self.uistate.show_filter_results(self.dbstate,
|
||||||
self.model.total())
|
self.model.displayed(),
|
||||||
|
self.model.total())
|
||||||
else:
|
else:
|
||||||
self.dirty = True
|
self.dirty = True
|
||||||
|
|
||||||
@ -709,7 +722,7 @@ class ListView(NavigationView):
|
|||||||
self.dirty = True
|
self.dirty = True
|
||||||
if self.active:
|
if self.active:
|
||||||
self.bookmarks.redraw()
|
self.bookmarks.redraw()
|
||||||
self.build_tree()
|
self.build_tree()
|
||||||
|
|
||||||
def _button_press(self, obj, event):
|
def _button_press(self, obj, event):
|
||||||
"""
|
"""
|
||||||
|
@ -59,6 +59,29 @@ class PageView(DbGUIElement):
|
|||||||
The PageView class is the base class for all Data Views in GRAMPS. All
|
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
|
Views should derive from this class. The ViewManager understands the public
|
||||||
interface of this class
|
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):
|
def __init__(self, title, dbstate, uistate):
|
||||||
@ -76,6 +99,7 @@ class PageView(DbGUIElement):
|
|||||||
self.ui_def = '<ui></ui>'
|
self.ui_def = '<ui></ui>'
|
||||||
self.dirty = True
|
self.dirty = True
|
||||||
self.active = False
|
self.active = False
|
||||||
|
self._dirty_on_change_inactive = True
|
||||||
self.func_list = {}
|
self.func_list = {}
|
||||||
self.category = "Miscellaneous"
|
self.category = "Miscellaneous"
|
||||||
self.translated_category = _("Miscellaneous")
|
self.translated_category = _("Miscellaneous")
|
||||||
|
@ -57,7 +57,7 @@ from gettext import gettext as _
|
|||||||
# PlaceBaseModel
|
# PlaceBaseModel
|
||||||
#
|
#
|
||||||
#-------------------------------------------------------------------------
|
#-------------------------------------------------------------------------
|
||||||
class PlaceBaseModel():
|
class PlaceBaseModel(object):
|
||||||
|
|
||||||
HANDLE_COL = 12
|
HANDLE_COL = 12
|
||||||
|
|
||||||
|
@ -265,6 +265,9 @@ class TreeBaseModel(gtk.GenericTreeModel):
|
|||||||
group_can_have_handle = False):
|
group_can_have_handle = False):
|
||||||
cput = time.clock()
|
cput = time.clock()
|
||||||
gtk.GenericTreeModel.__init__(self)
|
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.__reverse = (order == gtk.SORT_DESCENDING)
|
||||||
self.scol = scol
|
self.scol = scol
|
||||||
@ -571,6 +574,8 @@ class TreeBaseModel(gtk.GenericTreeModel):
|
|||||||
path = self.on_get_path(child_node)
|
path = self.on_get_path(child_node)
|
||||||
node = self.get_iter(path)
|
node = self.get_iter(path)
|
||||||
self.row_inserted(path, node)
|
self.row_inserted(path, node)
|
||||||
|
self.__total += 1
|
||||||
|
self.__displayed += 1
|
||||||
|
|
||||||
if handle:
|
if handle:
|
||||||
self.handle2node[handle] = child_node
|
self.handle2node[handle] = child_node
|
||||||
@ -587,6 +592,9 @@ class TreeBaseModel(gtk.GenericTreeModel):
|
|||||||
str(parent) + ' ' + str(child) + ' ' + sortkey
|
str(parent) + ' ' + str(child) + ' ' + sortkey
|
||||||
if handle:
|
if handle:
|
||||||
node.set_handle(handle)
|
node.set_handle(handle)
|
||||||
|
if not self._in_build:
|
||||||
|
self.__total += 1
|
||||||
|
self.__displayed += 1
|
||||||
|
|
||||||
def remove_node(self, node):
|
def remove_node(self, node):
|
||||||
"""
|
"""
|
||||||
@ -594,12 +602,16 @@ class TreeBaseModel(gtk.GenericTreeModel):
|
|||||||
"""
|
"""
|
||||||
if node.children:
|
if node.children:
|
||||||
node.set_handle(None)
|
node.set_handle(None)
|
||||||
|
self.__displayed -= 1
|
||||||
|
self.__total -= 1
|
||||||
else:
|
else:
|
||||||
path = self.on_get_path(node)
|
path = self.on_get_path(node)
|
||||||
self.nodemap.node(node.parent).remove_child(node, self.nodemap)
|
self.nodemap.node(node.parent).remove_child(node, self.nodemap)
|
||||||
del self.tree[node.ref]
|
del self.tree[node.ref]
|
||||||
self.nodemap.del_node(node)
|
self.nodemap.del_node(node)
|
||||||
del node
|
del node
|
||||||
|
self.__displayed -= 1
|
||||||
|
self.__total -= 1
|
||||||
|
|
||||||
# emit row_deleted signal
|
# emit row_deleted signal
|
||||||
self.row_deleted(path)
|
self.row_deleted(path)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user