62 template <
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;
212 template <
typename Type>
215 template <
typename Type>
217 : targetTree (v), targetProperty (i), undoManager (um),
218 defaultValue(), cachedValue (getTypedValue())
223 template <
typename Type>
225 : targetTree (v), targetProperty (i), undoManager (um),
226 defaultValue (defaultToUse), cachedValue (getTypedValue())
231 template <
typename Type>
234 return targetTree.getPropertyAsValue (targetProperty, undoManager);
237 template <
typename Type>
240 return ! targetTree.hasProperty (targetProperty);
243 template <
typename Type>
246 setValue (newValue, undoManager);
250 template <
typename Type>
253 if (cachedValue != newValue || isUsingDefault())
255 cachedValue = newValue;
260 template <
typename Type>
263 resetToDefault (undoManager);
266 template <
typename Type>
269 targetTree.removeProperty (targetProperty, undoManagerToUse);
270 forceUpdateOfCachedValue();
273 template <
typename Type>
276 referToWithDefault (v, i, um, Type());
279 template <
typename Type>
282 referToWithDefault (v, i, um, defaultVal);
285 template <
typename Type>
288 cachedValue = getTypedValue();
291 template <
typename Type>
294 targetTree.removeListener (
this);
298 defaultValue = defaultVal;
299 cachedValue = getTypedValue();
300 targetTree.addListener (
this);
303 template <
typename Type>
304 inline Type CachedValue<Type>::getTypedValue()
const
306 if (
const var* property = targetTree.getPropertyPointer (targetProperty))
307 return VariantConverter<Type>::fromVar (*property);
312 template <
typename Type>
313 inline 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.
UndoManager * getUndoManager() noexcept
Returns the UndoManager that is being used.
bool isUsingDefault() const
Returns true if the current property does not exist and the CachedValue is using the fallback default...
Type getDefault() const
Returns the current fallback default value.
CachedValue()
Default constructor.
Type * operator->() noexcept
Dereference operator.
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.
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.
Type & operator*() noexcept
Dereference operator.
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.
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.
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.