Skip to content

parent_child_ref

freecad.datamanager_wb.domain.parent_child_ref

Typed parent/child references for list widget selections.

The UI stores these objects in QListWidgetItem user data to preserve a structured representation of parent.child identifiers.

ParentChildRef(parent, child) dataclass

Structured identifier of a parent.child reference.

This type is used as a stable representation of list items in the UI (VarSet variables and Spreadsheet aliases). The UI often renders items as a string but needs to retain the structured parts for querying and mutations.

Attributes:

Name Type Description
parent str

The parent container name (e.g. VarSet name, Spreadsheet name).

child str

The child identifier within the parent (e.g. variable/alias).

child instance-attribute

parent instance-attribute

text property

Return the canonical parent.child string form.

normalize_parent_child_items(items)

Normalize a list of selection items to their parent.child string form.

Source code in freecad/datamanager_wb/domain/parent_child_ref.py
def normalize_parent_child_items(items: list[ParentChildRef] | list[str]) -> list[str]:
    """Normalize a list of selection items to their `parent.child` string form."""
    normalized: list[str] = []
    for item in items:
        if isinstance(item, ParentChildRef):
            normalized.append(item.text)
        else:
            normalized.append(item)
    return normalized

parse_parent_child_ref(text)

Parse a parent.child string into a :class:ParentChildRef.

Parameters:

Name Type Description Default
text str

A string expected to contain exactly one dot separating parent and child.

required

Returns:

Name Type Description
A ParentChildRef | None

class:ParentChildRef when parsing succeeds, otherwise None.

Source code in freecad/datamanager_wb/domain/parent_child_ref.py
def parse_parent_child_ref(text: str) -> ParentChildRef | None:
    """Parse a `parent.child` string into a :class:`ParentChildRef`.

    Args:
        text: A string expected to contain exactly one dot separating parent
            and child.

    Returns:
        A :class:`ParentChildRef` when parsing succeeds, otherwise ``None``.
    """

    if "." not in text:
        return None
    parent, child = text.split(".", 1)
    if not parent or not child:
        return None
    return ParentChildRef(parent=parent, child=child)