Browse Source

New method: ValueTree::copyPropertiesFrom()

tags/2021-05-28
jules 13 years ago
parent
commit
b6965d2fe5
2 changed files with 24 additions and 0 deletions
  1. +18
    -0
      modules/juce_data_structures/values/juce_ValueTree.cpp
  2. +6
    -0
      modules/juce_data_structures/values/juce_ValueTree.h

+ 18
- 0
modules/juce_data_structures/values/juce_ValueTree.cpp View File

@@ -219,6 +219,16 @@ public:
}
}
void copyPropertiesFrom (const SharedObject& source, UndoManager* const undoManager)
{
for (int i = properties.size(); --i >= 0;)
if (! source.properties.contains (properties.getName (i)))
removeProperty (properties.getName (i), undoManager);
for (int i = 0; i < source.properties.size(); ++i)
setProperty (source.properties.getName(i), source.properties.getValueAt(i), undoManager);
}
ValueTree getChildWithName (const Identifier& typeToMatch) const
{
for (int i = 0; i < children.size(); ++i)
@@ -783,6 +793,14 @@ Identifier ValueTree::getPropertyName (const int index) const
: object->properties.getName (index);
}
void ValueTree::copyPropertiesFrom (const ValueTree& source, UndoManager* const undoManager)
{
if (source.object == nullptr)
removeAllProperties (undoManager);
else if (object != nullptr)
object->copyPropertiesFrom (*(source.object), undoManager);
}
//==============================================================================
class ValueTreePropertyValueSource : public Value::ValueSource,
private ValueTree::Listener


+ 6
- 0
modules/juce_data_structures/values/juce_ValueTree.h View File

@@ -204,6 +204,12 @@ public:
*/
Value getPropertyAsValue (const Identifier& name, UndoManager* undoManager);
/** 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 nodes belonging to this one.
@see getChild


Loading…
Cancel
Save