mirror of
https://github.com/juce-framework/JUCE.git
synced 2026-01-10 23:44:24 +00:00
Added method ValueTree::copyPropertiesAndChildrenFrom()
This commit is contained in:
parent
2c12212b96
commit
eb093411fc
2 changed files with 43 additions and 19 deletions
|
|
@ -665,6 +665,28 @@ ValueTree ValueTree::createCopy() const
|
||||||
return ValueTree (createCopyIfNotNull (object.get()));
|
return ValueTree (createCopyIfNotNull (object.get()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ValueTree::copyPropertiesFrom (const ValueTree& source, UndoManager* undoManager)
|
||||||
|
{
|
||||||
|
jassert (object != nullptr || source.object == nullptr); // Trying to add properties to a null ValueTree will fail!
|
||||||
|
|
||||||
|
if (source.object == nullptr)
|
||||||
|
removeAllProperties (undoManager);
|
||||||
|
else if (object != nullptr)
|
||||||
|
object->copyPropertiesFrom (*(source.object), undoManager);
|
||||||
|
}
|
||||||
|
|
||||||
|
void ValueTree::copyPropertiesAndChildrenFrom (const ValueTree& source, UndoManager* undoManager)
|
||||||
|
{
|
||||||
|
jassert (object != nullptr || source.object == nullptr); // Trying to copy to a null ValueTree will fail!
|
||||||
|
|
||||||
|
copyPropertiesFrom (source, undoManager);
|
||||||
|
removeAllChildren (undoManager);
|
||||||
|
|
||||||
|
if (object != nullptr && source.object != nullptr)
|
||||||
|
for (auto& child : source.object->children)
|
||||||
|
object->addChild (createCopyIfNotNull (child), -1, undoManager);
|
||||||
|
}
|
||||||
|
|
||||||
bool ValueTree::hasType (const Identifier& typeName) const noexcept
|
bool ValueTree::hasType (const Identifier& typeName) const noexcept
|
||||||
{
|
{
|
||||||
return object != nullptr && object->type == typeName;
|
return object != nullptr && object->type == typeName;
|
||||||
|
|
@ -769,16 +791,6 @@ Identifier ValueTree::getPropertyName (int index) const noexcept
|
||||||
: object->properties.getName (index);
|
: object->properties.getName (index);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ValueTree::copyPropertiesFrom (const ValueTree& source, UndoManager* undoManager)
|
|
||||||
{
|
|
||||||
jassert (object != nullptr || source.object == nullptr); // Trying to add properties to a null ValueTree will fail!
|
|
||||||
|
|
||||||
if (source.object == nullptr)
|
|
||||||
removeAllProperties (undoManager);
|
|
||||||
else if (object != nullptr)
|
|
||||||
object->copyPropertiesFrom (*(source.object), undoManager);
|
|
||||||
}
|
|
||||||
|
|
||||||
int ValueTree::getReferenceCount() const noexcept
|
int ValueTree::getReferenceCount() const noexcept
|
||||||
{
|
{
|
||||||
return object != nullptr ? object->getReferenceCount() : 0;
|
return object != nullptr ? object->getReferenceCount() : 0;
|
||||||
|
|
|
||||||
|
|
@ -134,12 +134,17 @@ public:
|
||||||
/** Creates a reference to another ValueTree. */
|
/** Creates a reference to another ValueTree. */
|
||||||
ValueTree (const ValueTree&) noexcept;
|
ValueTree (const ValueTree&) noexcept;
|
||||||
|
|
||||||
/** Changes this object to be a reference to the given tree. */
|
|
||||||
ValueTree& operator= (const ValueTree&);
|
|
||||||
|
|
||||||
/** Move constructor */
|
/** Move constructor */
|
||||||
ValueTree (ValueTree&&) noexcept;
|
ValueTree (ValueTree&&) noexcept;
|
||||||
|
|
||||||
|
/** Changes this object to be a reference to the given tree.
|
||||||
|
Note that calling this just points this at the new object and invokes the
|
||||||
|
Listener::valueTreeRedirected callback, but it's not an undoable operation. If
|
||||||
|
you're trying to replace an entire tree in an undoable way, you probably want
|
||||||
|
to use copyPropertiesAndChildren() instead.
|
||||||
|
*/
|
||||||
|
ValueTree& operator= (const ValueTree&);
|
||||||
|
|
||||||
/** Destructor. */
|
/** Destructor. */
|
||||||
~ValueTree();
|
~ValueTree();
|
||||||
|
|
||||||
|
|
@ -172,6 +177,19 @@ public:
|
||||||
/** Returns a deep copy of this tree and all its sub-trees. */
|
/** Returns a deep copy of this tree and all its sub-trees. */
|
||||||
ValueTree createCopy() const;
|
ValueTree createCopy() const;
|
||||||
|
|
||||||
|
/** Overwrites all the properties in this tree with the properties of the source tree.
|
||||||
|
Any properties that already exist will be updated; and new ones will be added, and
|
||||||
|
any that are not present in the source tree will be removed.
|
||||||
|
@see copyPropertiesAndChildrenFrom
|
||||||
|
*/
|
||||||
|
void copyPropertiesFrom (const ValueTree& source, UndoManager* undoManager);
|
||||||
|
|
||||||
|
/** Replaces all children and properties of this object with copies of those from
|
||||||
|
the source object.
|
||||||
|
@see copyPropertiesFrom
|
||||||
|
*/
|
||||||
|
void copyPropertiesAndChildrenFrom (const ValueTree& source, UndoManager* undoManager);
|
||||||
|
|
||||||
//==============================================================================
|
//==============================================================================
|
||||||
/** Returns the type of this tree.
|
/** Returns the type of this tree.
|
||||||
The type is specified when the ValueTree is created.
|
The type is specified when the ValueTree is created.
|
||||||
|
|
@ -261,12 +279,6 @@ public:
|
||||||
Value getPropertyAsValue (const Identifier& name, UndoManager* undoManager,
|
Value getPropertyAsValue (const Identifier& name, UndoManager* undoManager,
|
||||||
bool shouldUpdateSynchronously = false);
|
bool shouldUpdateSynchronously = false);
|
||||||
|
|
||||||
/** Overwrites all the properties in this tree with the properties of the source tree.
|
|
||||||
Any properties that already exist will be updated; and new ones will be added, and
|
|
||||||
any that are not present in the source tree will be removed.
|
|
||||||
*/
|
|
||||||
void copyPropertiesFrom (const ValueTree& source, UndoManager* undoManager);
|
|
||||||
|
|
||||||
//==============================================================================
|
//==============================================================================
|
||||||
/** Returns the number of child trees inside this one.
|
/** Returns the number of child trees inside this one.
|
||||||
@see getChild
|
@see getChild
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue