diff --git a/src/editor/editortreenode.cpp b/src/editor/editortreenode.cpp deleted file mode 100644 index f27c072..0000000 --- a/src/editor/editortreenode.cpp +++ /dev/null @@ -1,165 +0,0 @@ -#include "editortreenode.h" - -template -EditorTreeNode::EditorTreeNode() { - parentNode = nullptr; -} - -template -EditorTreeNode::EditorTreeNode(T v) - : val(v) -{ -} - -template -EditorTreeNode::~EditorTreeNode() -{ - if (parentNode != nullptr) { - this->remove(); - } -} - -template -const std::shared_ptr > EditorTreeNode::nextSibling() -{ - if (parent() != nullptr) { - uint i = parent()->children().indexOf(this); - if (i + 1 < parentNode->children().size()) - return parentNode->children().at(i + 1); //next sibling... - else - return nullptr; - } - return nullptr; -} - -template -const std::shared_ptr> EditorTreeNode::next(TreeWalkStrategy walkStrategy) -{ - if (walkStrategy == TreeWalkStrategy::mixture) - // choose node, work through all siblings, choose next node, but don't change branches more than one parent away, except branch is at an end. - if (parent() != nullptr) { - if (nextSibling() != nullptr) // next sibling - return nextSibling(); - else // find next children - { - for (auto n : parentNode->children()) - if (n->children().size() > 0) - return n->children().first(); - auto siblingOfParent = parentNode->nextSibling(); - while (siblingOfParent != nullptr && siblingOfParent->children().size() == 0) { - if (siblingOfParent->nextSibling() == nullptr) - siblingOfParent = siblingOfParent->parentNode(); - else - siblingOfParent = siblingOfParent->nextSibling(); - } - if (siblingOfParent != nullptr) - return siblingOfParent->children().first(); - else - return nullptr; - } - } else { - if (childrenNodes.size() > 0) - return childrenNodes.first(); - else - return nullptr; - } - else if (walkStrategy == TreeWalkStrategy::depthFirst) - if (children().size() > 0) - return childrenNodes.first(); - else { - auto node = this; - while (node->nextSibling() == nullptr && node->parentNode() != nullptr) - node = node->parentNode(); - return node->nextSibling(); - } - else if (walkStrategy == TreeWalkStrategy::breadthFirst) - if (parentNode != nullptr) { - auto nextOnLvl = nextOnSameLevel(); - if (nextOnLvl == nullptr){ - for (auto n : this->childrenNodes) - if (n->children().size() > 0) - return n->children().first(); - } - else return nextOnLvl; - } - return nullptr; -} - -template -const std::shared_ptr> EditorTreeNode::getRoot() -{ - auto node = std::shared_ptr>(this); - while (node->parent() != nullptr) - node = node->parent(); - return node; -} - -template -void EditorTreeNode::move(std::shared_ptr> to) -{ - this->parent()->children().removeOne(this); - to->children().append(this); -} - -template -void EditorTreeNode::moveChildren(std::shared_ptr> to) -{ - for (auto child : childrenNodes) - child->move(to); -} - -template -void EditorTreeNode::addChild(std::shared_ptr> child) -{ - this->children().append(child); - child->setParen(this); -} - -template -bool EditorTreeNode::removeChild(std::shared_ptr> child) -{ - return this->children().removeOne(child); -} - -template -bool EditorTreeNode::remove() -{ - bool worked = true; - if (parentNode != nullptr) { - worked &= parentNode->children().removeOne(this); - } - - if (childrenNodes.size() > 0) { - for (auto node : childrenNodes) { - worked &= node->remove(); - } - } - return worked; -} - -template -std::shared_ptr> EditorTreeNode::nextOnSameLevel() -{ - if (nextSibling() != nullptr) - return nextSibling(); - uint lvl = 1; - auto node = this->parentNode(); - auto pnode = this; - while (lvl > 0 && node != nullptr) { - if (node != pnode->parentNode() && node->children() > 0) { - node = node->children().first(); - --lvl; - } else { - pnode = node; - if (node->nextSibling() != nullptr) - node = node->nextSibling(); - else { - if (node->parentNode() != nullptr) { - node = node->parentNode(); - ++lvl; - } - } - } - } - return node; -} diff --git a/src/editor/editortreenode.h b/src/editor/editortreenode.h deleted file mode 100644 index 49c3198..0000000 --- a/src/editor/editortreenode.h +++ /dev/null @@ -1,56 +0,0 @@ -#ifndef EDITORTREENODE_H -#define EDITORTREENODE_H - -#include -#include -#include - - -template -class EditorTreeNode; - -template -class EditorTreeNode { -public: - explicit EditorTreeNode(); - explicit EditorTreeNode(T v); - virtual ~EditorTreeNode(); - - - const std::shared_ptr> nextSibling(); - const std::shared_ptr> parent() { return parentNode; } - QList>>& children() { return childrenNodes; } - void setParen(std::shared_ptr> parent) { this->parentNode = parent; } - - T& value() { return val; } - void setValue(const T &val); - - const std::shared_ptr> next(TreeWalkStrategy depth_first = TreeWalkStrategy::depthFirst); - const std::shared_ptr> getRoot(); - void move(std::shared_ptr> to); // as child! - void moveChildren(std::shared_ptr> to); // move all children - - void addChild(std::shared_ptr> child); - bool removeChild(std::shared_ptr> child); - bool remove(); - - void setDataChangedSignal(std::function>)> f) - { - nodeDataChanged = f; - } - void setTreeChangedSignal(std::function>)> f) - { - treeChanged = f; - } - -private: - //signal callbacks only set in the root node - std::function>)> nodeDataChanged; - std::function>)> treeChanged; - T val; - std::shared_ptr> parentNode = nullptr; - QList>> childrenNodes; - std::shared_ptr> nextOnSameLevel(); -}; - -#endif // EDITORTREENODE_H