From 2906d72aeef1000b2530533bb0fdedfd7e131294 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?L=C3=A9a=20Saviot?= Date: Tue, 26 Jun 2018 17:32:22 +0200 Subject: [PATCH] MoveLeft is working --- cursor.h | 4 ++++ test.cpp | 6 ++++++ tree_node.cpp | 14 +++++++++----- tree_node.h | 1 + 4 files changed, 20 insertions(+), 5 deletions(-) diff --git a/cursor.h b/cursor.h index e5dab3537..6085509d7 100644 --- a/cursor.h +++ b/cursor.h @@ -8,6 +8,10 @@ class Cursor { template friend class TreeReference; public: + TreeReference treeReference() { return m_treeReference; } + int treeReferenceIdentifier() { return m_treeReference.identifier(); } + void setTreeReference(TreeReference t) { m_treeReference = t; } + void setTreeNode(TreeNode * t) { m_treeReference = TreeReference(t); } bool isDefined() const { return m_treeReference.isDefined(); } protected: Cursor(TreeNode * node) : m_treeReference(node) {} diff --git a/test.cpp b/test.cpp index 00da8a0ef..9207edbf4 100644 --- a/test.cpp +++ b/test.cpp @@ -31,6 +31,12 @@ int main() { TreePool::sharedPool()->log(); LayoutCursor cursor = h.childAtIndex(1).cursor(); + LayoutCursor cursor2 = aChar.cursor(); + cursor.log(); + bool recompute = false; + cursor.moveLeft(&recompute); + cursor.log(); + cursor.moveLeft(&recompute); cursor.log(); /*cursor.log(); diff --git a/tree_node.cpp b/tree_node.cpp index 13c116acb..605cc43a2 100644 --- a/tree_node.cpp +++ b/tree_node.cpp @@ -99,14 +99,11 @@ TreeNode * TreeNode::childTreeAtIndex(int i) const { return child; } -int TreeNode::indexOfChild(const TreeNode * child) const { - if (child == nullptr) { - return -1; - } +int TreeNode::indexOfChildByIdentifier(int childID) const { int childrenCount = numberOfChildren(); TreeNode * childAtIndexi = next(); for (int i = 0; i < childrenCount; i++) { - if (childAtIndexi == child) { + if (childAtIndexi->identifier() == childID) { return i; } childAtIndexi = childAtIndexi->nextSibling(); @@ -114,6 +111,13 @@ int TreeNode::indexOfChild(const TreeNode * child) const { return -1; } +int TreeNode::indexOfChild(const TreeNode * child) const { + if (child == nullptr) { + return -1; + } + return indexOfChildByIdentifier(child->identifier()); +} + bool TreeNode::hasChild(const TreeNode * child) const { if (child == nullptr) { return false; diff --git a/tree_node.h b/tree_node.h index f241952d4..4e16b0a0c 100644 --- a/tree_node.h +++ b/tree_node.h @@ -45,6 +45,7 @@ public: virtual int numberOfChildren() const = 0; int numberOfDescendants(bool includeSelf) const; TreeNode * childTreeAtIndex(int i) const; + int indexOfChildByIdentifier(int childID) const; int indexOfChild(const TreeNode * child) const; bool hasChild(const TreeNode * child) const; bool hasAncestor(const TreeNode * node, bool includeSelf) const;