56 referTo (tree, propertyID, um);
68 referTo (tree, propertyID, um, defaultToUse);
85 referTo (tree, propertyID, um, defaultToUse, arrayDelimiter);
91 referToWithDefault (other.targetTree,
101 defaultValue.removeListener (
this);
111 if (isUsingDefault())
114 if (delimiter.isNotEmpty())
115 return delimitedStringToVarArray (targetTree[targetProperty].toString(), delimiter);
117 return targetTree[targetProperty];
130 bool isUsingDefault()
const {
return ! targetTree.hasProperty (targetProperty); }
133 void resetToDefault() noexcept { targetTree.removeProperty (targetProperty,
nullptr); }
149 setValue (newValue, undoManager);
159 if (
auto* array = newValue.
getArray())
160 targetTree.setProperty (targetProperty, varArrayToDelimitedString (*array, delimiter), undoManagerToUse);
162 targetTree.setProperty (targetProperty, newValue, undoManagerToUse);
175 referToWithDefault (tree,
178 Value (
new SynchronousValueSource (
var())),
192 referToWithDefault (tree,
195 Value (
new SynchronousValueSource (defaultVal)),
210 referToWithDefault (tree,
213 Value (
new SynchronousValueSource (defaultVal)),
230 referToWithDefault (other.targetTree,
231 other.targetProperty,
241 class SynchronousValueSource :
public Value::ValueSource
244 explicit SynchronousValueSource (
const var& initialValue)
245 : value (initialValue)
249 var getValue()
const override
254 void setValue (
const var& newValue)
override
256 if (! newValue.equalsWithSameType (value))
259 sendChangeMessage (
true);
270 static String varArrayToDelimitedString (
const Array<var>& input, StringRef delim)
276 StringArray elements;
278 for (
auto& v : input)
281 return elements.joinIntoString (delim);
284 static Array<var> delimitedStringToVarArray (StringRef input, StringRef delim)
288 for (
auto t : StringArray::fromTokens (input, delim, {}))
296 NullCheckedInvocation::invoke (onDefaultChange);
299 void referToWithDefault (ValueTree v,
302 const Value& defaultVal,
308 defaultValue.referTo (defaultVal);
311 defaultValue.addListener (
this);
315 ValueTree targetTree;
316 Identifier targetProperty;
317 UndoManager* undoManager =
nullptr;
328 "This declaration is here for backwards compatibility and new "
329 "code should use the new class name.")]]
330 = ValueTreePropertyWithDefault;
Represents a string identifier, designed for accessing properties by name.
A simple class for holding temporary references to a string literal or String.
Manages a list of undo/redo commands.
This class acts as a wrapper around a property inside a ValueTree.
ValueTree & getValueTree() noexcept
Returns a reference to the ValueTree containing the referenced property.
ValueTreePropertyWithDefault(ValueTree &tree, const Identifier &propertyID, UndoManager *um, var defaultToUse, StringRef arrayDelimiter)
Creates a ValueTreePropertyWithDefault object for the specified property.
Value getPropertyAsValue()
Returns the current property as a Value object.
~ValueTreePropertyWithDefault() override
Destructor.
bool isUsingDefault() const
Returns true if the property does not exist in the referenced ValueTree.
void referTo(ValueTree tree, const Identifier &property, UndoManager *um, var defaultVal, StringRef arrayDelimiter)
Makes the ValueTreePropertyWithDefault refer to the specified property inside the given ValueTree.
var getDefault() const
Returns the current default value.
void setValue(const var &newValue, UndoManager *undoManagerToUse)
Sets the property.
std::function< void()> onDefaultChange
You can assign a lambda to this callback and it will called when the default value is changed.
void referTo(ValueTree tree, const Identifier &property, UndoManager *um, var defaultVal)
Makes the ValueTreePropertyWithDefault refer to the specified property inside the given ValueTree.
UndoManager * getUndoManager() noexcept
Returns the UndoManager that is being used.
ValueTreePropertyWithDefault(const ValueTreePropertyWithDefault &other)
Creates a ValueTreePropertyWithDefault object from another ValueTreePropertyWithDefault object.
ValueTreePropertyWithDefault()=default
Creates an uninitialised ValueTreePropertyWithDefault object.
ValueTreePropertyWithDefault(ValueTree &tree, const Identifier &propertyID, UndoManager *um, var defaultToUse)
Creates an ValueTreePropertyWithDefault object for the specified property.
void setDefault(const var &newDefault)
Sets the default value to a new var.
Identifier & getPropertyID() noexcept
Returns the property ID of the referenced property.
ValueTreePropertyWithDefault(ValueTree &tree, const Identifier &propertyID, UndoManager *um)
Creates a ValueTreePropertyWithDefault object for the specified property.
void resetToDefault() noexcept
Removes the property from the referenced ValueTree.
void referTo(ValueTree tree, const Identifier &property, UndoManager *um)
Makes the ValueTreePropertyWithDefault refer to the specified property inside the given ValueTree.
var get() const noexcept
Returns the current value of the property.
A powerful tree structure that can be used to hold free-form data, and which can handle its own undo ...
Receives callbacks when a Value object changes.
Represents a shared variant value.
A variant class, that can be used to hold a range of primitive values.
Array< var > * getArray() const noexcept
If this variant holds an array, this provides access to it.
#define JUCE_LEAK_DETECTOR(OwnerClass)
This macro lets you embed a leak-detecting object inside a class.
@ del
The command ID that should be used to send a "Delete" command.
@ valueChanged
Indicates that the UI element's value has changed.
Type unalignedPointerCast(void *ptr) noexcept
Casts a pointer to another type via void*, which suppresses the cast-align warning which sometimes ar...
std::u16string toString(NumberT value)
convert an number to an UTF-16 string