JUCE
Public Member Functions | Public Attributes | List of all members
ValueWithDefault Class Reference

This class acts as a wrapper around a property inside a ValueTree. More...

Public Member Functions

 ValueWithDefault ()=default
 Creates an unitialised ValueWithDefault. More...
 
 ValueWithDefault (ValueTree &tree, const Identifier &propertyID, UndoManager *um)
 Creates an ValueWithDefault object. More...
 
 ValueWithDefault (ValueTree &tree, const Identifier &propertyID, UndoManager *um, const var &defaultToUse)
 Creates an ValueWithDefault object. More...
 
 ValueWithDefault (ValueTree &tree, const Identifier &propertyID, UndoManager *um, const var &defaultToUse, StringRef arrayDelimiter)
 Creates an ValueWithDefault object. More...
 
 ValueWithDefault (const ValueWithDefault &other)
 Creates a ValueWithDefault object from another ValueWithDefault object. More...
 
var get () const noexcept
 Returns the current value of the property. More...
 
Value getPropertyAsValue ()
 Returns the current property as a Value object. More...
 
var getDefault () const
 Returns the current default value. More...
 
void setDefault (const var &newDefault)
 Sets the default value to a new var. More...
 
bool isUsingDefault () const
 Returns true if the property does not exist in the referenced ValueTree. More...
 
void resetToDefault () noexcept
 Removes the property from the referenced ValueTree. More...
 
ValueWithDefaultoperator= (const var &newValue)
 Sets the property and returns the new ValueWithDefault. More...
 
void setValue (const var &newValue, UndoManager *undoManagerToUse)
 Sets the property. More...
 
void referTo (ValueTree &tree, const Identifier &property, UndoManager *um)
 Makes the ValueWithDefault refer to the specified property inside the given ValueTree. More...
 
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. More...
 
void referTo (ValueTree &tree, const Identifier &property, UndoManager *um, const var &defaultVal, StringRef arrayDelimiter)
 
ValueTreegetValueTree () noexcept
 Returns a reference to the ValueTree containing the referenced property. More...
 
IdentifiergetPropertyID () noexcept
 Returns the property ID of the referenced property. More...
 
UndoManagergetUndoManager () noexcept
 Returns the UndoManager that is being used. More...
 
ValueWithDefaultoperator= (const ValueWithDefault &other)
 

Public Attributes

std::function< void()> onDefaultChange
 You can assign a lambda to this callback object to have it called when the default value is changed. More...
 

Detailed Description

This class acts as a wrapper around a property inside a ValueTree.

If the property inside the ValueTree is missing the ValueWithDefault will automatically return a default value, which can be specified when initialising the ValueWithDefault.

Constructor & Destructor Documentation

◆ ValueWithDefault() [1/5]

ValueWithDefault::ValueWithDefault ( )
default

Creates an unitialised ValueWithDefault.

Initialise it using one of the referTo() methods.

◆ ValueWithDefault() [2/5]

ValueWithDefault::ValueWithDefault ( ValueTree tree,
const Identifier propertyID,
UndoManager um 
)

Creates an ValueWithDefault object.

The default value will be an empty var.

◆ ValueWithDefault() [3/5]

ValueWithDefault::ValueWithDefault ( ValueTree tree,
const Identifier propertyID,
UndoManager um,
const var defaultToUse 
)

Creates an ValueWithDefault object.

The default value will be defaultToUse.

◆ ValueWithDefault() [4/5]

ValueWithDefault::ValueWithDefault ( ValueTree tree,
const Identifier propertyID,
UndoManager um,
const var defaultToUse,
StringRef  arrayDelimiter 
)

Creates an ValueWithDefault object.

The default value will be defaultToUse.

Use this constructor if the underlying var object being controlled is an array and it will handle the conversion to/from a delimited String that can be written to XML format.

◆ ValueWithDefault() [5/5]

ValueWithDefault::ValueWithDefault ( const ValueWithDefault other)

Creates a ValueWithDefault object from another ValueWithDefault object.

Member Function Documentation

◆ get()

var ValueWithDefault::get ( ) const
noexcept

Returns the current value of the property.

If the property does not exist this returns the default value.

References String::isNotEmpty(), and isUsingDefault().

◆ getPropertyAsValue()

Value ValueWithDefault::getPropertyAsValue ( )

Returns the current property as a Value object.

References ValueTree::getPropertyAsValue().

◆ getDefault()

var ValueWithDefault::getDefault ( ) const

Returns the current default value.

◆ setDefault()

void ValueWithDefault::setDefault ( const var newDefault)

Sets the default value to a new var.

References onDefaultChange.

◆ isUsingDefault()

bool ValueWithDefault::isUsingDefault ( ) const

Returns true if the property does not exist in the referenced ValueTree.

References ValueTree::hasProperty().

Referenced by get().

◆ resetToDefault()

void ValueWithDefault::resetToDefault ( )
noexcept

Removes the property from the referenced ValueTree.

References ValueTree::removeProperty().

◆ operator=() [1/2]

ValueWithDefault& ValueWithDefault::operator= ( const var newValue)

Sets the property and returns the new ValueWithDefault.

This will modify the property in the referenced ValueTree.

References setValue().

◆ setValue()

void ValueWithDefault::setValue ( const var newValue,
UndoManager undoManagerToUse 
)

Sets the property.

This will actually modify the property in the referenced ValueTree.

References var::getArray(), and ValueTree::setProperty().

Referenced by operator=().

◆ referTo() [1/3]

void ValueWithDefault::referTo ( ValueTree tree,
const Identifier property,
UndoManager um 
)

Makes the ValueWithDefault refer to the specified property inside the given ValueTree.

◆ referTo() [2/3]

void ValueWithDefault::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.

◆ referTo() [3/3]

void ValueWithDefault::referTo ( ValueTree tree,
const Identifier property,
UndoManager um,
const var defaultVal,
StringRef  arrayDelimiter 
)

◆ getValueTree()

ValueTree& ValueWithDefault::getValueTree ( )
noexcept

Returns a reference to the ValueTree containing the referenced property.

◆ getPropertyID()

Identifier& ValueWithDefault::getPropertyID ( )
noexcept

Returns the property ID of the referenced property.

◆ getUndoManager()

UndoManager* ValueWithDefault::getUndoManager ( )
noexcept

Returns the UndoManager that is being used.

◆ operator=() [2/2]

ValueWithDefault& ValueWithDefault::operator= ( const ValueWithDefault other)

Member Data Documentation

◆ onDefaultChange

std::function<void()> ValueWithDefault::onDefaultChange

You can assign a lambda to this callback object to have it called when the default value is changed.

Referenced by setDefault().


The documentation for this class was generated from the following file: