removed 'editortreenode'
This commit is contained in:
parent
bfbdfe82cd
commit
a47213104c
|
@ -1,165 +0,0 @@
|
|||
#include "editortreenode.h"
|
||||
|
||||
template <typename T>
|
||||
EditorTreeNode<T>::EditorTreeNode() {
|
||||
parentNode = nullptr;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
EditorTreeNode<T>::EditorTreeNode(T v)
|
||||
: val(v)
|
||||
{
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
EditorTreeNode<T>::~EditorTreeNode()
|
||||
{
|
||||
if (parentNode != nullptr) {
|
||||
this->remove();
|
||||
}
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
const std::shared_ptr<EditorTreeNode<T> > EditorTreeNode<T>::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 <typename T>
|
||||
const std::shared_ptr<EditorTreeNode<T>> EditorTreeNode<T>::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 <typename T>
|
||||
const std::shared_ptr<EditorTreeNode<T>> EditorTreeNode<T>::getRoot()
|
||||
{
|
||||
auto node = std::shared_ptr<EditorTreeNode<T>>(this);
|
||||
while (node->parent() != nullptr)
|
||||
node = node->parent();
|
||||
return node;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
void EditorTreeNode<T>::move(std::shared_ptr<EditorTreeNode<T>> to)
|
||||
{
|
||||
this->parent()->children().removeOne(this);
|
||||
to->children().append(this);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
void EditorTreeNode<T>::moveChildren(std::shared_ptr<EditorTreeNode<T>> to)
|
||||
{
|
||||
for (auto child : childrenNodes)
|
||||
child->move(to);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
void EditorTreeNode<T>::addChild(std::shared_ptr<EditorTreeNode<T>> child)
|
||||
{
|
||||
this->children().append(child);
|
||||
child->setParen(this);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
bool EditorTreeNode<T>::removeChild(std::shared_ptr<EditorTreeNode<T>> child)
|
||||
{
|
||||
return this->children().removeOne(child);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
bool EditorTreeNode<T>::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 <typename T>
|
||||
std::shared_ptr<EditorTreeNode<T>> EditorTreeNode<T>::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;
|
||||
}
|
|
@ -1,56 +0,0 @@
|
|||
#ifndef EDITORTREENODE_H
|
||||
#define EDITORTREENODE_H
|
||||
|
||||
#include <QList>
|
||||
#include <memory>
|
||||
#include <functional>
|
||||
|
||||
|
||||
template <typename T>
|
||||
class EditorTreeNode;
|
||||
|
||||
template <typename T>
|
||||
class EditorTreeNode {
|
||||
public:
|
||||
explicit EditorTreeNode();
|
||||
explicit EditorTreeNode(T v);
|
||||
virtual ~EditorTreeNode();
|
||||
|
||||
|
||||
const std::shared_ptr<EditorTreeNode<T>> nextSibling();
|
||||
const std::shared_ptr<EditorTreeNode<T>> parent() { return parentNode; }
|
||||
QList<std::shared_ptr<EditorTreeNode<T>>>& children() { return childrenNodes; }
|
||||
void setParen(std::shared_ptr<EditorTreeNode<T>> parent) { this->parentNode = parent; }
|
||||
|
||||
T& value() { return val; }
|
||||
void setValue(const T &val);
|
||||
|
||||
const std::shared_ptr<EditorTreeNode<T>> next(TreeWalkStrategy depth_first = TreeWalkStrategy::depthFirst);
|
||||
const std::shared_ptr<EditorTreeNode<T>> getRoot();
|
||||
void move(std::shared_ptr<EditorTreeNode<T>> to); // as child!
|
||||
void moveChildren(std::shared_ptr<EditorTreeNode<T>> to); // move all children
|
||||
|
||||
void addChild(std::shared_ptr<EditorTreeNode<T>> child);
|
||||
bool removeChild(std::shared_ptr<EditorTreeNode<T>> child);
|
||||
bool remove();
|
||||
|
||||
void setDataChangedSignal(std::function<void(std::shared_ptr<EditorTreeNode<T>>)> f)
|
||||
{
|
||||
nodeDataChanged = f;
|
||||
}
|
||||
void setTreeChangedSignal(std::function<void(std::shared_ptr<EditorTreeNode<T>>)> f)
|
||||
{
|
||||
treeChanged = f;
|
||||
}
|
||||
|
||||
private:
|
||||
//signal callbacks only set in the root node
|
||||
std::function<void(std::shared_ptr<EditorTreeNode<T>>)> nodeDataChanged;
|
||||
std::function<void(std::shared_ptr<EditorTreeNode<T>>)> treeChanged;
|
||||
T val;
|
||||
std::shared_ptr<EditorTreeNode<T>> parentNode = nullptr;
|
||||
QList<std::shared_ptr<EditorTreeNode<T>>> childrenNodes;
|
||||
std::shared_ptr<EditorTreeNode<T>> nextOnSameLevel();
|
||||
};
|
||||
|
||||
#endif // EDITORTREENODE_H
|
Reference in New Issue