From 7eb534ae884172e105547c38d0c1ca57f5d56c8c Mon Sep 17 00:00:00 2001 From: jules Date: Sun, 1 Jan 2017 11:58:29 +0000 Subject: [PATCH] Added method ValueTree::getRoot() --- .../values/juce_ValueTree.cpp | 20 +++++++++++++------ .../values/juce_ValueTree.h | 9 ++++++++- 2 files changed, 22 insertions(+), 7 deletions(-) diff --git a/modules/juce_data_structures/values/juce_ValueTree.cpp b/modules/juce_data_structures/values/juce_ValueTree.cpp index 96e6938c36..a2f9b14c23 100644 --- a/modules/juce_data_structures/values/juce_ValueTree.cpp +++ b/modules/juce_data_structures/values/juce_ValueTree.cpp @@ -57,6 +57,11 @@ public: } } + SharedObject* getRoot() noexcept + { + return parent == nullptr ? this : parent->getRoot(); + } + template void callListeners (Method method, ValueTree& tree) const { @@ -483,9 +488,8 @@ public: } //============================================================================== - class SetPropertyAction : public UndoableAction + struct SetPropertyAction : public UndoableAction { - public: SetPropertyAction (SharedObject* const so, const Identifier& propertyName, const var& newVal, const var& oldVal, bool isAdding, bool isDeleting, ValueTree::Listener* listenerToExclude = nullptr) @@ -547,9 +551,8 @@ public: }; //============================================================================== - class AddOrRemoveChildAction : public UndoableAction + struct AddOrRemoveChildAction : public UndoableAction { - public: AddOrRemoveChildAction (SharedObject* parentObject, int index, SharedObject* newChild) : target (parentObject), child (newChild != nullptr ? newChild : parentObject->children.getObjectPointer (index)), @@ -600,9 +603,8 @@ public: }; //============================================================================== - class MoveChildAction : public UndoableAction + struct MoveChildAction : public UndoableAction { - public: MoveChildAction (SharedObject* parentObject, int fromIndex, int toIndex) noexcept : parent (parentObject), startIndex (fromIndex), endIndex (toIndex) { @@ -751,6 +753,12 @@ ValueTree ValueTree::getParent() const noexcept : static_cast (nullptr)); } +ValueTree ValueTree::getRoot() const noexcept +{ + return ValueTree (object != nullptr ? object->getRoot() + : static_cast (nullptr)); +} + ValueTree ValueTree::getSibling (const int delta) const noexcept { if (object == nullptr || object->parent == nullptr) diff --git a/modules/juce_data_structures/values/juce_ValueTree.h b/modules/juce_data_structures/values/juce_ValueTree.h index 95f7ac948c..e48a83f3fc 100644 --- a/modules/juce_data_structures/values/juce_ValueTree.h +++ b/modules/juce_data_structures/values/juce_ValueTree.h @@ -320,6 +320,11 @@ public: */ ValueTree getParent() const noexcept; + /** Recusrively finds the highest-level parent node that contains this one. + If the node has no parent, this will return itself. + */ + ValueTree getRoot() const noexcept; + /** Returns one of this node's siblings in its parent's child list. The delta specifies how far to move through the list, so a value of 1 would return the node @@ -486,7 +491,9 @@ public: /** Changes a named property of the node, but will not notify a specified listener of the change. @see setProperty */ - ValueTree& setPropertyExcludingListener (Listener* listenerToExclude, const Identifier& name, const var& newValue, UndoManager* undoManager); + ValueTree& setPropertyExcludingListener (Listener* listenerToExclude, + const Identifier& name, const var& newValue, + UndoManager* undoManager); /** Causes a property-change callback to be triggered for the specified property, calling any listeners that are registered.