[poincare] Allow construction of a TreeRef from nullptr node

This commit is contained in:
Léa Saviot
2018-09-06 10:10:54 +02:00
parent 2c164aecc7
commit 970554f9b8
4 changed files with 13 additions and 16 deletions

View File

@@ -83,8 +83,14 @@ public:
TreeByReference treeRefChild = TreeByReference::childAtIndex(i);
return LayoutReference(static_cast<LayoutNode *>(treeRefChild.node()));
}
LayoutReference root() const;
LayoutReference parent() const { return isUninitialized() ? LayoutReference() : LayoutReference(node()->parent()); }
LayoutReference root() const {
assert(!isUninitialized());
return LayoutReference(node()->root());
}
LayoutReference parent() const {
assert(!isUninitialized());
return LayoutReference(node()->parent());
}
// Tree modification
//Add

View File

@@ -88,9 +88,10 @@ public:
protected:
/* Constructor */
TreeByReference(const TreeNode * node) {
assert(node != nullptr);
setIdentifierAndRetain(node->identifier());
TreeByReference(const TreeNode * node) : TreeByReference() {
if (node != nullptr) {
setIdentifierAndRetain(node->identifier());
}
}
TreeByReference(int nodeIndentifier = TreePool::NoNodeIdentifier) : m_identifier(nodeIndentifier) {}
void setIdentifierAndRetain(int newId) {

View File

@@ -228,12 +228,8 @@ void LayoutNode::scoreCursorInDescendantsVertically (
}
bool LayoutNode::changeGreySquaresOfAllMatrixAncestors(bool add) {
LayoutNode * p = parent();
if (p == nullptr) {
return false;
}
bool changedSquares = false;
LayoutRef currentAncestor = LayoutRef(p);
LayoutRef currentAncestor = LayoutRef(parent());
while (!currentAncestor.isUninitialized()) {
if (currentAncestor.isMatrix()) {
if (add) {

View File

@@ -19,12 +19,6 @@ LayoutCursor LayoutReference::equivalentCursor(LayoutCursor * cursor) {
return node()->equivalentCursor(cursor);
}
LayoutReference LayoutReference::root() const {
assert(!isUninitialized());
LayoutNode * r = node()->root();
return r == nullptr ? LayoutReference() : LayoutReference(r);
}
// Tree modification
void LayoutReference::replaceChild(LayoutRef oldChild, LayoutRef newChild, LayoutCursor * cursor, bool force) {