From 94a4ddcbb11e7c0f3f89d85d3de5cf6e6dd2384e Mon Sep 17 00:00:00 2001 From: Mika Fischer Date: Wed, 13 Jul 2011 17:29:09 +0200 Subject: [PATCH] Support limiting the depth that the model iterator is allowed to descend --- sloth/annotations/model.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/sloth/annotations/model.py b/sloth/annotations/model.py index a1dbca6..68cd91a 100644 --- a/sloth/annotations/model.py +++ b/sloth/annotations/model.py @@ -685,8 +685,9 @@ class AnnotationModel(QAbstractItemModel): return index.internalPointer() return self._root - def iterator(self, _class=None, predicate=None, start=None): + def iterator(self, _class=None, predicate=None, start=None, maxlevels=10000): # Visit all nodes + level = 0 item = start if start is not None else self.root() while item is not None: # Return item @@ -695,13 +696,15 @@ class AnnotationModel(QAbstractItemModel): yield item # Get next item - if item.rowCount() > 0: + if item.rowCount() > 0 and level < maxlevels: + level += 1 item = item.childAt(0) else: next_sibling = item.getNextSibling() if next_sibling is not None: item = next_sibling else: + level -= 1 ancestor = item.parent() item = None while ancestor is not None: @@ -709,6 +712,7 @@ class AnnotationModel(QAbstractItemModel): if ancestor_sibling is not None: item = ancestor_sibling break + level -= 1 ancestor = ancestor.parent()