mirror of
https://github.com/juce-framework/JUCE.git
synced 2026-01-10 23:44:24 +00:00
Added the JUCE_DECLARE_WEAK_REFERENCEABLE macro to ValueWithDefault and fixed some places which were potentially accessing a deleted ValueWithDefault object
This commit is contained in:
parent
e786f9c0aa
commit
717cc49382
7 changed files with 38 additions and 11 deletions
|
|
@ -181,6 +181,15 @@ public:
|
|||
/** Returns the property ID of the referenced property. */
|
||||
Identifier& getPropertyID() noexcept { return targetProperty; }
|
||||
|
||||
//==============================================================================
|
||||
ValueWithDefault& operator= (const ValueWithDefault& other)
|
||||
{
|
||||
referToWithDefault (other.targetTree, other.targetProperty, other.undoManager,
|
||||
other.defaultValue, other.delimiter);
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
private:
|
||||
//==============================================================================
|
||||
ValueTree targetTree;
|
||||
|
|
@ -191,7 +200,7 @@ private:
|
|||
String delimiter;
|
||||
|
||||
//==============================================================================
|
||||
void referToWithDefault (ValueTree& v, const Identifier& i, UndoManager* um,
|
||||
void referToWithDefault (const ValueTree& v, const Identifier& i, UndoManager* um,
|
||||
const var& defaultVal, StringRef del)
|
||||
{
|
||||
targetTree = v;
|
||||
|
|
@ -225,6 +234,9 @@ private:
|
|||
|
||||
return arr;
|
||||
}
|
||||
|
||||
//==============================================================================
|
||||
JUCE_DECLARE_WEAK_REFERENCEABLE (ValueWithDefault)
|
||||
};
|
||||
|
||||
} // namespace juce
|
||||
|
|
|
|||
|
|
@ -83,6 +83,9 @@ public:
|
|||
|
||||
var getValue() const override
|
||||
{
|
||||
if (valueWithDefault == nullptr)
|
||||
return {};
|
||||
|
||||
if (valueWithDefault->isUsingDefault())
|
||||
return -1;
|
||||
|
||||
|
|
@ -97,6 +100,9 @@ public:
|
|||
|
||||
void setValue (const var& newValue) override
|
||||
{
|
||||
if (valueWithDefault == nullptr)
|
||||
return;
|
||||
|
||||
auto newValueInt = static_cast<int> (newValue);
|
||||
|
||||
if (newValueInt == -1)
|
||||
|
|
@ -115,7 +121,7 @@ public:
|
|||
private:
|
||||
void valueChanged (Value&) override { sendChangeMessage (true); }
|
||||
|
||||
ValueWithDefault* valueWithDefault = nullptr;
|
||||
WeakReference<ValueWithDefault> valueWithDefault;
|
||||
Value sourceValue;
|
||||
Array<var> mappings;
|
||||
|
||||
|
|
|
|||
|
|
@ -84,7 +84,6 @@ public:
|
|||
default value with an ID of -1.
|
||||
|
||||
@param valueToControl the ValueWithDefault object that contains the Value object that the combo box will read and control.
|
||||
NB: this object must outlive the ChoicePropertyComponent.
|
||||
@param propertyName the name of the property
|
||||
@param choices the list of possible values that the drop-down list will contain
|
||||
@param correspondingValues a list of values corresponding to each item in the 'choices' StringArray.
|
||||
|
|
@ -154,7 +153,7 @@ private:
|
|||
ComboBox comboBox;
|
||||
bool isCustomClass = false;
|
||||
|
||||
ValueWithDefault* valueWithDefault = nullptr;
|
||||
WeakReference<ValueWithDefault> valueWithDefault;
|
||||
|
||||
//==============================================================================
|
||||
JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (ChoicePropertyComponent)
|
||||
|
|
|
|||
|
|
@ -118,6 +118,9 @@ public:
|
|||
|
||||
var getValue() const override
|
||||
{
|
||||
if (valueWithDefault == nullptr)
|
||||
return {};
|
||||
|
||||
auto v = valueWithDefault->get();
|
||||
|
||||
if (auto* arr = v.getArray())
|
||||
|
|
@ -134,6 +137,9 @@ public:
|
|||
|
||||
void setValue (const var& newValue) override
|
||||
{
|
||||
if (valueWithDefault == nullptr)
|
||||
return;
|
||||
|
||||
auto v = valueWithDefault->get();
|
||||
|
||||
OptionalScopedPointer<Array<var>> arrayToControl;
|
||||
|
|
@ -191,7 +197,7 @@ private:
|
|||
}
|
||||
|
||||
//==============================================================================
|
||||
ValueWithDefault* valueWithDefault = nullptr;
|
||||
WeakReference<ValueWithDefault> valueWithDefault;
|
||||
var varToControl;
|
||||
Value sourceValue;
|
||||
|
||||
|
|
|
|||
|
|
@ -67,7 +67,6 @@ public:
|
|||
/** Creates the component using a ValueWithDefault object. This will select the default options.
|
||||
|
||||
@param valueToControl the ValueWithDefault object that contains the Value object that the ToggleButtons will read and control.
|
||||
NB: This object must outlive the MultiChoicePropertyComponent.
|
||||
@param propertyName the name of the property
|
||||
@param choices the list of possible values that will be represented
|
||||
@param correspondingValues a list of values corresponding to each item in the 'choices' StringArray.
|
||||
|
|
@ -119,7 +118,7 @@ private:
|
|||
void lookAndFeelChanged() override;
|
||||
|
||||
//==============================================================================
|
||||
ValueWithDefault* valueWithDefault = nullptr;
|
||||
WeakReference<ValueWithDefault> valueWithDefault;
|
||||
|
||||
int maxHeight = 0;
|
||||
int numHidden = 0;
|
||||
|
|
|
|||
|
|
@ -131,11 +131,17 @@ public:
|
|||
|
||||
var getValue() const override
|
||||
{
|
||||
return valueWithDefault->isUsingDefault() ? var() : valueWithDefault->get();
|
||||
if (valueWithDefault == nullptr || valueWithDefault->isUsingDefault())
|
||||
return {};
|
||||
|
||||
return valueWithDefault->get();
|
||||
}
|
||||
|
||||
void setValue (const var& newValue) override
|
||||
{
|
||||
if (valueWithDefault == nullptr)
|
||||
return;
|
||||
|
||||
if (newValue.toString().isEmpty())
|
||||
valueWithDefault->resetToDefault();
|
||||
else
|
||||
|
|
@ -143,7 +149,7 @@ public:
|
|||
}
|
||||
|
||||
private:
|
||||
ValueWithDefault* valueWithDefault = nullptr;
|
||||
WeakReference<ValueWithDefault> valueWithDefault;
|
||||
|
||||
//==============================================================================
|
||||
JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (RemapperValueSourceWithDefault)
|
||||
|
|
|
|||
|
|
@ -75,7 +75,6 @@ public:
|
|||
/** Creates a text property component with a default value.
|
||||
|
||||
@param valueToControl The ValueWithDefault that is controlled by the TextPropertyComponent.
|
||||
NB: this object must outlive the TextPropertyComponent.
|
||||
@param propertyName The name of the property
|
||||
@param maxNumChars If not zero, then this specifies the maximum allowable length of
|
||||
the string. If zero, then the string will have no length limit.
|
||||
|
|
@ -183,7 +182,7 @@ private:
|
|||
std::unique_ptr<LabelComp> textEditor;
|
||||
ListenerList<Listener> listenerList;
|
||||
|
||||
ValueWithDefault* valueWithDefault = nullptr;
|
||||
WeakReference<ValueWithDefault> valueWithDefault;
|
||||
|
||||
//==============================================================================
|
||||
JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (TextPropertyComponent)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue