62template <
typename Type>
97 UndoManager* undoManager,
const Type& defaultToUse);
105 operator Type() const noexcept {
return cachedValue; }
110 Type
get() const noexcept {
return cachedValue; }
123 template <
typename OtherType>
124 bool operator== (
const OtherType& other)
const {
return cachedValue == other; }
129 template <
typename OtherType>
130 bool operator!= (
const OtherType& other)
const {
return cachedValue != other; }
162 void setDefault (
const Type& value) { defaultValue = value; }
201 Type getTypedValue()
const;
203 void valueTreePropertyChanged (
ValueTree& changedTree,
const Identifier& changedProperty)
override;
212template <
typename Type>
215template <
typename Type>
217 : targetTree (v), targetProperty (i), undoManager (um),
218 defaultValue(), cachedValue (getTypedValue())
223template <
typename Type>
225 : targetTree (v), targetProperty (i), undoManager (um),
226 defaultValue (defaultToUse), cachedValue (getTypedValue())
231template <
typename Type>
234 return targetTree.getPropertyAsValue (targetProperty, undoManager);
237template <
typename Type>
240 return ! targetTree.hasProperty (targetProperty);
243template <
typename Type>
246 setValue (newValue, undoManager);
250template <
typename Type>
253 if (cachedValue != newValue || isUsingDefault())
255 cachedValue = newValue;
260template <
typename Type>
263 resetToDefault (undoManager);
266template <
typename Type>
269 targetTree.removeProperty (targetProperty, undoManagerToUse);
270 forceUpdateOfCachedValue();
273template <
typename Type>
276 referToWithDefault (v, i, um, Type());
279template <
typename Type>
282 referToWithDefault (v, i, um, defaultVal);
285template <
typename Type>
288 cachedValue = getTypedValue();
291template <
typename Type>
294 targetTree.removeListener (
this);
298 defaultValue = defaultVal;
299 cachedValue = getTypedValue();
300 targetTree.addListener (
this);
303template <
typename Type>
304inline Type CachedValue<Type>::getTypedValue()
const
306 if (
const var* property = targetTree.getPropertyPointer (targetProperty))
307 return VariantConverter<Type>::fromVar (*property);
312template <
typename Type>
313inline void CachedValue<Type>::valueTreePropertyChanged (ValueTree& changedTree,
const Identifier& changedProperty)
315 if (changedProperty == targetProperty && targetTree == changedTree)
316 forceUpdateOfCachedValue();
This class acts as a typed wrapper around a property inside a ValueTree.
bool isUsingDefault() const
Returns true if the current property does not exist and the CachedValue is using the fallback default...
Type * operator->() noexcept
Dereference operator.
Type getDefault() const
Returns the current fallback default value.
CachedValue()
Default constructor.
ValueTree & getValueTree() noexcept
Returns a reference to the ValueTree containing the referenced property.
const Identifier & getPropertyID() const noexcept
Returns the property ID of the referenced property.
CachedValue & operator=(const Type &newValue)
Sets the property.
void forceUpdateOfCachedValue()
Force an update in case the referenced property has been changed from elsewhere.
void setValue(const Type &newValue, UndoManager *undoManagerToUse)
Sets the property.
UndoManager * getUndoManager() noexcept
Returns the UndoManager that is being used.
void resetToDefault()
Removes the property from the referenced ValueTree and makes the CachedValue return the fallback defa...
void referTo(ValueTree &tree, const Identifier &property, UndoManager *um)
Makes the CachedValue refer to the specified property inside the given ValueTree.
Value getPropertyAsValue()
Returns the current property as a Value object.
bool operator==(const OtherType &other) const
Returns true if the current value of the property (or the fallback value) is equal to other.
void setDefault(const Type &value)
Resets the fallback default value.
bool operator!=(const OtherType &other) const
Returns true if the current value of the property (or the fallback value) is not equal to other.
Type get() const noexcept
Returns the current value of the property.
Type & operator*() noexcept
Dereference operator.
Represents a string identifier, designed for accessing properties by name.
Manages a list of undo/redo commands.
Listener class for events that happen to a ValueTree.
A powerful tree structure that can be used to hold free-form data, and which can handle its own undo ...
void addListener(Listener *listener)
Adds a listener to receive callbacks when this tree is changed in some way.
Represents a shared variant value.
This template-overloaded class can be used to convert between var and custom types.