Skip to content

Commit 4fc3d4a

Browse files
committed
[core] Add dedicated flatStaticChildren property for GroupAttributes
Rename `getFlattenedChildren` into `getFlatStaticChildren` and have a default version for all the Attributes, as well as a dedicated one for GroupAttributes. Children of ListAttributes are currently not taken into account when gathering the list of children.
1 parent cb64945 commit 4fc3d4a

File tree

2 files changed

+37
-28
lines changed

2 files changed

+37
-28
lines changed

meshroom/core/attribute.py

Lines changed: 33 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -413,32 +413,12 @@ def updateInternals(self):
413413
# Emit if the enable status has changed
414414
self.setEnabled(self.getEnabled())
415415

416-
def getFlattenedChildren(self):
416+
def getFlatStaticChildren(self):
417417
""" Return a list of all the attributes that refer to this instance as their parent through
418418
the 'root' property. If no such attribute exist, return an empty list. The depth difference is not
419419
taken into account in the list, which is thus always flat. """
420-
attributes = ListModel(parent=self)
421-
if isinstance(self._value, str):
422-
# String/File attributes are iterable but cannot have children: immediately rule that case out
423-
return attributes
424-
425-
try:
426-
# If self._value is not iterable, then it is not an attribute that can have children
427-
iter(self._value)
428-
except TypeError:
429-
return attributes
430-
431-
for attribute in self._value:
432-
if not isinstance(attribute, Attribute):
433-
# Handle ChoiceParam values, which contained in a list hence iterable, but are string
434-
continue
435-
attributes.add(attribute)
436-
if isinstance(attribute, ListAttribute) or isinstance(attribute, GroupAttribute):
437-
# Handle nested ListAttributes and GroupAttributes
438-
flattened = attribute.getFlattenedChildren()
439-
for i in flattened:
440-
attributes.add(i)
441-
return attributes
420+
# For all attributes but GroupAttributes, there cannot be any child
421+
return ListModel(parent=self)
442422

443423
name = Property(str, getName, constant=True)
444424
fullName = Property(str, getFullName, constant=True)
@@ -483,7 +463,7 @@ def getFlattenedChildren(self):
483463
validValue = Property(bool, getValidValue, setValidValue, notify=validValueChanged)
484464
root = Property(BaseObject, root.fget, constant=True)
485465
depth = Property(int, getDepth, constant=True)
486-
flattenedChildren = Property(BaseObject, getFlattenedChildren, constant=True)
466+
flatStaticChildren = Property(BaseObject, getFlatStaticChildren, constant=True)
487467

488468

489469
def raiseIfLink(func):
@@ -836,10 +816,39 @@ def updateInternals(self):
836816
for attr in self._value:
837817
attr.updateInternals()
838818

819+
def getFlatStaticChildren(self):
820+
""" Return a list of all the attributes that refer to this instance of GroupAttribute as their parent
821+
through the 'root' property. In the case of GroupAttributes, any attribute within said group will be
822+
a child. The depth difference is not taken into account when generating the list, which is thus always
823+
flat. """
824+
attributes = ListModel(parent=self)
825+
if isinstance(self._value, str):
826+
# String/File attributes are iterable but cannot have children: immediately rule that case out
827+
return attributes
828+
829+
try:
830+
# If self._value is not iterable, then it is not an attribute that can have children
831+
iter(self._value)
832+
except TypeError:
833+
return attributes
834+
835+
for attribute in self._value:
836+
if not isinstance(attribute, Attribute):
837+
# Handle ChoiceParam values, which are contained in a list hence iterable, but are string
838+
continue
839+
attributes.append(attribute)
840+
if isinstance(attribute, GroupAttribute):
841+
# Handle nested GroupAttributes
842+
flattened = attribute.getFlatStaticChildren()
843+
for i in flattened:
844+
attributes.append(i)
845+
return attributes
846+
839847
@Slot(str, result=bool)
840848
def matchText(self, text):
841849
return super().matchText(text) or any(c.matchText(text) for c in self._value)
842850

843851
# Override value property
844852
value = Property(Variant, Attribute._get_value, _set_value, notify=Attribute.valueChanged)
845853
isDefault = Property(bool, _isDefault, notify=Attribute.valueChanged)
854+
flatStaticChildren = Property(BaseObject, getFlatStaticChildren, constant=True)

meshroom/ui/qml/GraphEditor/Node.qml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -153,10 +153,10 @@ Item {
153153
parentPins.set(attr.name, false)
154154
}
155155

156-
for (let j = 0; j < attr.flattenedChildren.count; ++j) {
157-
attributes.push(attr.flattenedChildren.at(j))
158-
if (attr.flattenedChildren.at(j).type === "GroupAttribute") {
159-
parentPins.set(attr.flattenedChildren.at(j).name, false)
156+
for (let j = 0; j < attr.flatStaticChildren.count; ++j) {
157+
attributes.push(attr.flatStaticChildren.at(j))
158+
if (attr.flatStaticChildren.at(j).type === "GroupAttribute") {
159+
parentPins.set(attr.flatStaticChildren.at(j).name, false)
160160
}
161161
}
162162
}

0 commit comments

Comments
 (0)