GH-1223 fix override settings
They now work more like passthrough settings, except not passing through set and reset
This commit is contained in:
@ -15,16 +15,40 @@
|
||||
|
||||
#include "OverrideSetting.h"
|
||||
|
||||
OverrideSetting::OverrideSetting(std::shared_ptr<Setting> other)
|
||||
OverrideSetting::OverrideSetting(std::shared_ptr<Setting> other, std::shared_ptr<Setting> gate)
|
||||
: Setting(other->configKeys(), QVariant())
|
||||
{
|
||||
Q_ASSERT(other);
|
||||
Q_ASSERT(gate);
|
||||
m_other = other;
|
||||
m_gate = gate;
|
||||
}
|
||||
|
||||
bool OverrideSetting::isOverriding() const
|
||||
{
|
||||
return m_gate->get().toBool();
|
||||
}
|
||||
|
||||
QVariant OverrideSetting::defValue() const
|
||||
{
|
||||
if (m_other)
|
||||
return m_other->get();
|
||||
else
|
||||
return QVariant();
|
||||
return m_other->get();
|
||||
}
|
||||
|
||||
QVariant OverrideSetting::get() const
|
||||
{
|
||||
if(isOverriding())
|
||||
{
|
||||
return Setting::get();
|
||||
}
|
||||
return m_other->get();
|
||||
}
|
||||
|
||||
void OverrideSetting::reset()
|
||||
{
|
||||
Setting::reset();
|
||||
}
|
||||
|
||||
void OverrideSetting::set(QVariant value)
|
||||
{
|
||||
Setting::set(value);
|
||||
}
|
||||
|
@ -30,10 +30,17 @@ class OverrideSetting : public Setting
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit OverrideSetting(std::shared_ptr<Setting> other);
|
||||
explicit OverrideSetting(std::shared_ptr<Setting> overriden, std::shared_ptr<Setting> gate);
|
||||
|
||||
virtual QVariant defValue() const;
|
||||
virtual QVariant get() const;
|
||||
virtual void set (QVariant value);
|
||||
virtual void reset();
|
||||
|
||||
private:
|
||||
bool isOverriding() const;
|
||||
|
||||
protected:
|
||||
std::shared_ptr<Setting> m_other;
|
||||
std::shared_ptr<Setting> m_gate;
|
||||
};
|
||||
|
@ -30,7 +30,8 @@ SettingsObject::~SettingsObject()
|
||||
m_settings.clear();
|
||||
}
|
||||
|
||||
std::shared_ptr<Setting> SettingsObject::registerOverride(std::shared_ptr<Setting> original)
|
||||
std::shared_ptr<Setting> SettingsObject::registerOverride(std::shared_ptr<Setting> original,
|
||||
std::shared_ptr<Setting> gate)
|
||||
{
|
||||
if (contains(original->id()))
|
||||
{
|
||||
@ -38,7 +39,7 @@ std::shared_ptr<Setting> SettingsObject::registerOverride(std::shared_ptr<Settin
|
||||
.arg(original->id());
|
||||
return nullptr; // Fail
|
||||
}
|
||||
auto override = std::make_shared<OverrideSetting>(original);
|
||||
auto override = std::make_shared<OverrideSetting>(original, gate);
|
||||
override->m_storage = this;
|
||||
connectSignals(*override);
|
||||
m_settings.insert(override->id(), override);
|
||||
|
@ -62,12 +62,13 @@ public:
|
||||
virtual ~SettingsObject();
|
||||
/*!
|
||||
* Registers an override setting for the given original setting in this settings object
|
||||
* gate decides if the passthrough (true) or the original (false) is used for value
|
||||
*
|
||||
* This will fail if there is already a setting with the same ID as
|
||||
* the one that is being registered.
|
||||
* \return A valid Setting shared pointer if successful.
|
||||
*/
|
||||
std::shared_ptr<Setting> registerOverride(std::shared_ptr<Setting> original);
|
||||
std::shared_ptr<Setting> registerOverride(std::shared_ptr<Setting> original, std::shared_ptr<Setting> gate);
|
||||
|
||||
/*!
|
||||
* Registers a passthorugh setting for the given original setting in this settings object
|
||||
|
Reference in New Issue
Block a user