Add "label" as an internal attribute

Setting the "label" internal attribute allows to give a custom
label to replace the node's default label.
This commit is contained in:
Candice Bentéjac 2022-08-02 12:36:11 +02:00
parent 9bc9e2c129
commit 330382ab0c
4 changed files with 31 additions and 1 deletions

View file

@ -524,8 +524,12 @@ class BaseNode(BaseObject):
def getLabel(self):
"""
Returns:
str: the high-level label of this node
str: the user-provided label if it exists, the high-level label of this node otherwise
"""
if self.hasInternalAttribute("label"):
label = self.internalAttribute("label").value.strip()
if label:
return label
return self.nameToLabel(self._name)
@Slot(str, result=str)
@ -856,6 +860,9 @@ class BaseNode(BaseObject):
if self.internalFolder != folder:
self.internalFolderChanged.emit()
def updateInternalAttributes(self):
self.internalAttributesChanged.emit()
@property
def internalFolder(self):
return self._internalFolder.format(**self._cmdVars)
@ -1089,6 +1096,7 @@ class BaseNode(BaseObject):
y = Property(float, lambda self: self._position.y, notify=positionChanged)
attributes = Property(BaseObject, getAttributes, constant=True)
internalAttributes = Property(BaseObject, getInternalAttributes, constant=True)
internalAttributesChanged = Signal()
internalFolderChanged = Signal()
internalFolder = Property(str, internalFolder.fget, notify=internalFolderChanged)
depthChanged = Signal()