mirror of
https://github.com/wassname/sloth.git
synced 2026-07-23 13:10:07 +08:00
Remove unnecessary iterator function
This commit is contained in:
+22
-25
@@ -574,33 +574,30 @@ class AnnotationModel(QAbstractItemModel):
|
||||
return self._root
|
||||
|
||||
def iterator(self, _class=None, predicate=None, start=None):
|
||||
return model_iterator(self, _class, predicate)
|
||||
# Visit all nodes
|
||||
item = start if start is not None else self.root()
|
||||
while item is not None:
|
||||
# Return item
|
||||
if _class is None or isinstance(item, _class):
|
||||
if predicate is None or predicate(item):
|
||||
yield item
|
||||
|
||||
def model_iterator(model, _class=None, predicate=None, start=None):
|
||||
# Visit all nodes
|
||||
item = start if start is not None else model.root()
|
||||
while item is not None:
|
||||
# Return item
|
||||
if _class is None or isinstance(item, _class):
|
||||
if predicate is None or predicate(item):
|
||||
yield item
|
||||
|
||||
# Get next item
|
||||
if len(item.children()) > 0:
|
||||
item = item.children()[0]
|
||||
else:
|
||||
next_sibling = item.getNextSibling()
|
||||
if next_sibling is not None:
|
||||
item = next_sibling
|
||||
# Get next item
|
||||
if len(item.children()) > 0:
|
||||
item = item.children()[0]
|
||||
else:
|
||||
ancestor = item.parent()
|
||||
item = None
|
||||
while ancestor is not None:
|
||||
ancestor_sibling = ancestor.getNextSibling()
|
||||
if ancestor_sibling is not None:
|
||||
item = ancestor_sibling
|
||||
break
|
||||
ancestor = ancestor.parent()
|
||||
next_sibling = item.getNextSibling()
|
||||
if next_sibling is not None:
|
||||
item = next_sibling
|
||||
else:
|
||||
ancestor = item.parent()
|
||||
item = None
|
||||
while ancestor is not None:
|
||||
ancestor_sibling = ancestor.getNextSibling()
|
||||
if ancestor_sibling is not None:
|
||||
item = ancestor_sibling
|
||||
break
|
||||
ancestor = ancestor.parent()
|
||||
|
||||
|
||||
#######################################################################################
|
||||
|
||||
Reference in New Issue
Block a user