forked from qt-creator/qt-creator
Utils: Make BoolAspects also notify their changed values
... when triggered via base class setValue(). The pattern would probably be useful for other aspects, too, but e.g. for actions in a menu (like switching on/off FakeVim) this already covers most cases. Change-Id: I7886f4b845883edb6d337df0fa53f989ae893f65 Reviewed-by: David Schulz <david.schulz@qt.io>
This commit is contained in:
@@ -137,8 +137,10 @@ QVariant BaseAspect::value() const
|
||||
*/
|
||||
void BaseAspect::setValue(const QVariant &value)
|
||||
{
|
||||
if (setValueQuietly(value))
|
||||
if (setValueQuietly(value)) {
|
||||
emit changed();
|
||||
emitChangedValue();
|
||||
}
|
||||
}
|
||||
|
||||
/*!
|
||||
@@ -1218,6 +1220,10 @@ void BoolAspect::addToLayout(LayoutBuilder &builder)
|
||||
break;
|
||||
}
|
||||
d->m_checkBox->setChecked(value());
|
||||
builder.addItem(d->m_checkBox.data());
|
||||
connect(d->m_checkBox.data(), &QAbstractButton::clicked, this, [this] {
|
||||
setValue(d->m_checkBox->isChecked());
|
||||
});
|
||||
if (isAutoApply()) {
|
||||
connect(d->m_checkBox.data(), &QAbstractButton::clicked,
|
||||
this, [this](bool val) { setValue(val); });
|
||||
@@ -1252,6 +1258,12 @@ void BoolAspect::setVolatileValue(const QVariant &val)
|
||||
d->m_checkBox->setChecked(val.toBool());
|
||||
}
|
||||
|
||||
void BoolAspect::emitChangedValue()
|
||||
{
|
||||
emit valueChanged(value());
|
||||
}
|
||||
|
||||
|
||||
/*!
|
||||
\reimp
|
||||
*/
|
||||
|
@@ -115,6 +115,7 @@ public:
|
||||
|
||||
virtual QVariant volatileValue() const;
|
||||
virtual void setVolatileValue(const QVariant &val);
|
||||
virtual void emitChangedValue() {}
|
||||
|
||||
virtual void readSettings(const QSettings *settings);
|
||||
virtual void writeSettings(QSettings *settings) const;
|
||||
@@ -210,6 +211,7 @@ public:
|
||||
|
||||
QVariant volatileValue() const override;
|
||||
void setVolatileValue(const QVariant &val) override;
|
||||
void emitChangedValue() override;
|
||||
|
||||
bool value() const;
|
||||
void setValue(bool val);
|
||||
|
Reference in New Issue
Block a user