diff --git a/src/editor/editorelementdata.h b/src/editor/editorelementdata.h index 53ff0f8..598f7b6 100644 --- a/src/editor/editorelementdata.h +++ b/src/editor/editorelementdata.h @@ -2,6 +2,7 @@ #define EDITORELEMENT_H #include #include +#include diff --git a/src/editor/editormodel.cpp b/src/editor/editormodel.cpp index 2637945..8650dcd 100644 --- a/src/editor/editormodel.cpp +++ b/src/editor/editormodel.cpp @@ -1,4 +1,4 @@ -#include "abstractguidededitormodel.h" +#include "editormodel.h" EditorModel::EditorModel(QObject *parent) : QObject(parent) { diff --git a/src/editor/editortreenode.cpp b/src/editor/editortreenode.cpp index 3a6eb27..1504870 100644 --- a/src/editor/editortreenode.cpp +++ b/src/editor/editortreenode.cpp @@ -1,47 +1,52 @@ #include "editortreenode.h" -EditorTreeNode::EditorTreeNode() {} +template +EditorTreeNode::EditorTreeNode() {} -EditorTreeNode::EditorTreeNode(T v) - : value(v) +template +EditorTreeNode::EditorTreeNode(T v) + : val(v) { } -EditorTreeNode::~EditorTreeNode() +template +EditorTreeNode::~EditorTreeNode() { - if (parent != nullptr) { - remove(); + if (parentNode != nullptr) { + this->remove(); } } -const EditorTreeNode* EditorTreeNode::nextSibling() +template +const EditorTreeNode* EditorTreeNode::nextSibling() { if (parent() != nullptr) { uint i = parent()->children().indexOf(this); - if (i + 1 < parent->children().size()) - return parent->children().at(i + 1); //next sibling... + if (i + 1 < parentNode->children().size()) + return parentNode->children().at(i + 1); //next sibling... else return nullptr; } return nullptr; } -const EditorTreeNode* EditorTreeNode::next(TreeWalkStrategy walkStrategy) +template +const EditorTreeNode* 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() != null) // next sibling + if (nextSibling() != nullptr) // next sibling return nextSibling(); else // find next children { - for (auto n : parent->children()) + for (auto n : parentNode->children()) if (n->children().size() > 0) return n->children().first(); - auto siblingOfParent = parent->nextSibling(); + auto siblingOfParent = parentNode->nextSibling(); while (siblingOfParent != nullptr && siblingOfParent->children().size() == 0) { if (siblingOfParent->nextSibling() == nullptr) - siblingOfParent = siblingOfParent->parent(); + siblingOfParent = siblingOfParent->parentNode(); else siblingOfParent = siblingOfParent->nextSibling(); } @@ -51,25 +56,25 @@ const EditorTreeNode* EditorTreeNode::next(TreeWalkStrategy walkStrategy) return nullptr; } } else { - if (children.size() > 0) - return children.first(); + if (childrenNodes.size() > 0) + return childrenNodes.first(); else return nullptr; } else if (walkStrategy == TreeWalkStrategy::depthFirst) if (children().size() > 0) - return children.first(); + return childrenNodes.first(); else { auto node = this; - while (node->nextSibling() == nullptr && node->parent() != nullptr) - node = node->parent(); + while (node->nextSibling() == nullptr && node->parentNode() != nullptr) + node = node->parentNode(); return node->nextSibling(); } else if (walkStrategy == TreeWalkStrategy::breadthFirst) - if (parent != nullptr) { + if (parentNode != nullptr) { auto nextOnLvl = nextOnSameLevel(); if (nextOnLvl == nullptr){ - for (auto n : this->children) + for (auto n : this->childrenNodes) if (n->children().size() > 0) return n->children().first(); } @@ -78,7 +83,8 @@ const EditorTreeNode* EditorTreeNode::next(TreeWalkStrategy walkStrategy) return nullptr; } -const EditorTreeNode* EditorTreeNode::getRoot() +template +const EditorTreeNode* EditorTreeNode::getRoot() { auto node = this; while (node->parent() != nullptr) @@ -86,51 +92,59 @@ const EditorTreeNode* EditorTreeNode::getRoot() return node; } -void EditorTreeNode::move(EditorTreeNode* to) +template +void EditorTreeNode::move(EditorTreeNode* to) { this->parent()->children().removeOne(this); to->children().append(this); } -void EditorTreeNode::moveChildren(EditorTreeNode* to) +template +void EditorTreeNode::moveChildren(EditorTreeNode* to) { - for (auto child : children) + for (auto child : childrenNodes) child->move(to); } -void EditorTreeNode::addChild(EditorTreeNode* child) +template +void EditorTreeNode::addChild(EditorTreeNode* child) { this->children().append(child); child->setParen(this); } -bool EditorTreeNode::removeChild(EditorTreeNode* child) +template +bool EditorTreeNode::removeChild(EditorTreeNode* child) { - this->children().removeOne(child); + return this->children().removeOne(child); } -bool EditorTreeNode::remove() +template +bool EditorTreeNode::remove() { - if (parent != nullptr) { - parent->children().removeOne(this); + bool worked = true; + if (parentNode != nullptr) { + worked &= parentNode->children().removeOne(this); } - if (children.size() > 0) { - for (auto node : children) { - node->remove(); + if (childrenNodes.size() > 0) { + for (auto node : childrenNodes) { + worked &= node->remove(); } } + return worked; } -EditorTreeNode* EditorTreeNode::nextOnSameLevel() +template +EditorTreeNode* EditorTreeNode::nextOnSameLevel() { if (nextSibling() != nullptr) return nextSibling(); uint lvl = 1; - auto node = this->parent(); + auto node = this->parentNode(); auto pnode = this; while (lvl > 0 && node != nullptr) { - if (node != pnode->parent() && node->children() > 0) { + if (node != pnode->parentNode() && node->children() > 0) { node = node->children().first(); --lvl; } else { @@ -138,8 +152,8 @@ EditorTreeNode* EditorTreeNode::nextOnSameLevel() if (node->nextSibling() != nullptr) node = node->nextSibling(); else { - if (node->parent() != nullptr) { - node = node->parent(); + if (node->parentNode() != nullptr) { + node = node->parentNode(); ++lvl; } } diff --git a/src/editor/editortreenode.h b/src/editor/editortreenode.h index 634a2ba..b1dfa43 100644 --- a/src/editor/editortreenode.h +++ b/src/editor/editortreenode.h @@ -9,10 +9,10 @@ enum class TreeWalkStrategy { mixture }; -template +template class EditorTreeNode; -template +template class EditorTreeNode { public: explicit EditorTreeNode(); @@ -20,29 +20,30 @@ public: ~EditorTreeNode(); const EditorTreeNode* nextSibling(); - const EditorTreeNode* parent() { return parent; } - QList*>& children() { return children; } - void setParen(EditorTreeNode* parent) { this->parent = parent; } + const EditorTreeNode* parent() { return parentNode; } + QList*>& children() { return childrenNodes; } + void setParen(EditorTreeNode* parent) { this->parentNode = parent; } - T value() { return value; } + T& value() { return val; } const EditorTreeNode* next(TreeWalkStrategy depth_first = TreeWalkStrategy::depthFirst); const EditorTreeNode* getRoot(); void move(EditorTreeNode* to); // as child! void moveChildren(EditorTreeNode* to); // move all children -signals: + +//signals: void nodeDataChanged(EditorTreeNode* node); void treeChanged(EditorTreeNode* node); -public slots: +//public slots: void addChild(EditorTreeNode* child); bool removeChild(EditorTreeNode* child); bool remove(); - +//*/ private: - T value; - EditorTreeNode* parent = nullptr; - QList*> children; + T val; + EditorTreeNode* parentNode = nullptr; + QList*> childrenNodes; EditorTreeNode* nextOnSameLevel(); }; diff --git a/src/editor/guidededitorelementview.cpp b/src/editor/guidededitorelementview.cpp index e441ba2..6c4cc4d 100644 --- a/src/editor/guidededitorelementview.cpp +++ b/src/editor/guidededitorelementview.cpp @@ -18,7 +18,7 @@ GuidedEditorElementView::GuidedEditorElementView(QWidget* parent) void GuidedEditorElementView::render() { - for (QWidget* w : this->propertyViews->values()) + for (QWidget* w : this->propertyViews.values()) this->layout->removeWidget(w); for (QString prop : this->propertyOrder) { this->layout->addWidget(this->propertyViews[prop]);