17 using ElementList = std::list<Element *>;
20 OrderedSet<Element *> parents_, childs_;
23 Element::Element() : d_ptr(std::make_unique<ElementPrivate>()) {}
32 return d->childs_.order();
35 void Element::addChild(
Element *child) {
36 addEdge(
this, child,
nullptr,
nullptr);
38 void Element::addParent(
Element *parent) {
39 addEdge(parent,
this,
nullptr,
nullptr);
44 return d->childs_.contains(const_cast<Element *>(element));
48 return d->parents_.contains(const_cast<Element *>(element));
53 return d->parents_.order();
56 void Element::removeChild(
Element *child) { removeEdge(
this, child); }
58 void Element::removeParent(
Element *parent) { removeEdge(parent,
this); }
61 addEdge(
this, child, before,
nullptr);
65 addEdge(parent,
this,
nullptr, before);
71 if (parent->d_func()->childs_.contains(child)) {
74 removeEdge(parent, child);
75 parent->d_func()->childs_.insert(beforeChild, child);
76 child->d_func()->parents_.insert(beforeParent, parent);
80 parent->d_func()->childs_.remove(child);
81 child->d_func()->parents_.remove(parent);
84 void Element::removeAllParent() {
85 while (!parents().empty()) {
86 removeParent(parents().front());
90 void Element::removeAllChild() {
91 while (!childs().empty()) {
92 childs().front()->removeParent(
this);
Utility class that provides a hierarchy between multiple objects.
const std::list< Element * > & parents() const
List all parents.
bool isParent(const Element *element) const
Enable query between different elements.
const std::list< Element * > & childs() const
List all childs.
bool isChild(const Element *element) const
Enable query between different elements.
Base class that can be used for UI composition or graph.