53 targetProperty (propertyID),
61 const var& defaultToUse)
63 targetProperty (propertyID),
65 defaultValue (defaultToUse)
78 targetProperty (propertyID),
80 defaultValue (defaultToUse),
81 delimiter (arrayDelimiter)
87 : targetTree (other.targetTree),
88 targetProperty (other.targetProperty),
89 undoManager (other.undoManager),
90 defaultValue (other.defaultValue),
91 delimiter (other.delimiter)
99 var get()
const noexcept
105 return delimitedStringToVarArray (targetTree[targetProperty].toString());
107 return targetTree[targetProperty];
119 if (defaultValue != newDefault)
121 defaultValue = newDefault;
154 if (
auto* array = newValue.
getArray())
155 targetTree.
setProperty (targetProperty, varArrayToDelimitedString (*array), undoManagerToUse);
157 targetTree.
setProperty (targetProperty, newValue, undoManagerToUse);
164 referToWithDefault (tree, property, um,
var(), {});
172 referToWithDefault (tree, property, um, defaultVal, {});
178 referToWithDefault (tree, property, um, defaultVal, arrayDelimiter);
194 referToWithDefault (other.targetTree, other.targetProperty, other.undoManager,
195 other.defaultValue, other.delimiter);
216 defaultValue = defaultVal;
229 for (
auto& v : input)
230 elements.
add (v.toString());
232 return elements.joinIntoString (delimiter);
ValueTree & getValueTree() noexcept
Returns a reference to the ValueTree containing the referenced property.
A powerful tree structure that can be used to hold free-form data, and which can handle its own undo ...
bool isNotEmpty() const noexcept
Returns true if the string contains at least one character.
UndoManager * getUndoManager() noexcept
Returns the UndoManager that is being used.
Value getPropertyAsValue(const Identifier &name, UndoManager *undoManager, bool shouldUpdateSynchronously=false)
Returns a Value object that can be used to control and respond to one of the tree's properties...
Value getPropertyAsValue()
Returns the current property as a Value object.
Represents a string identifier, designed for accessing properties by name.
A simple class for holding temporary references to a string literal or String.
A variant class, that can be used to hold a range of primitive values.
void add(const ElementType &newElement)
Appends a new element at the end of the array.
void referTo(ValueTree &tree, const Identifier &property, UndoManager *um)
Makes the ValueWithDefault refer to the specified property inside the given ValueTree.
void setDefault(const var &newDefault)
Sets the default value to a new var.
A special array for holding a list of strings.
ValueWithDefault(const ValueWithDefault &other)
Creates a ValueWithDefault object from another ValueWithDefault object.
ValueWithDefault(ValueTree &tree, const Identifier &propertyID, UndoManager *um, const var &defaultToUse)
Creates an ValueWithDefault object.
var getDefault() const
Returns the current default value.
std::function< void()> onDefaultChange
You can assign a lambda to this callback object to have it called when the default value is changed...
Identifier & getPropertyID() noexcept
Returns the property ID of the referenced property.
ValueWithDefault(ValueTree &tree, const Identifier &propertyID, UndoManager *um, const var &defaultToUse, StringRef arrayDelimiter)
Creates an ValueWithDefault object.
void resetToDefault() noexcept
Removes the property from the referenced ValueTree.
ValueWithDefault(ValueTree &tree, const Identifier &propertyID, UndoManager *um)
Creates an ValueWithDefault object.
void setValue(const var &newValue, UndoManager *undoManagerToUse)
Sets the property.
ValueTree & setProperty(const Identifier &name, const var &newValue, UndoManager *undoManager)
Changes a named property of the tree.
Array< var > * getArray() const noexcept
If this variant holds an array, this provides access to it.
bool isUsingDefault() const
Returns true if the property does not exist in the referenced ValueTree.
void referTo(ValueTree &tree, const Identifier &property, UndoManager *um, const var &defaultVal)
Makes the ValueWithDefault refer to the specified property inside the given ValueTree, and specifies a default value to use.
static StringArray fromTokens(StringRef stringToTokenise, bool preserveQuotedStrings)
Returns an array containing the tokens in a given string.
Represents a shared variant value.
Holds a resizable array of primitive or copy-by-value objects.
ValueWithDefault & operator=(const var &newValue)
Sets the property and returns the new ValueWithDefault.
ValueWithDefault()=default
Creates an unitialised ValueWithDefault.
Manages a list of undo/redo commands.
void removeProperty(const Identifier &name, UndoManager *undoManager)
Removes a property from the tree.
This class acts as a wrapper around a property inside a ValueTree.
bool hasProperty(const Identifier &name) const noexcept
Returns true if the tree contains a named property.
void add(String stringToAdd)
Appends a string at the end of the array.