Utils: Rework aspect implementation

This avoids some repetition and could be a step towards
having type storage in (or rather accessible from) the base,
so we can have aspects for more complex data (treemodels...)
that are not easily converted to QVariant.

Change-Id: I9797b3d5646195705212db1830d2b415291ac651
Reviewed-by: Christian Stenger <christian.stenger@qt.io>
This commit is contained in:
hjk
2023-06-26 11:02:42 +02:00
parent 900ea82fd1
commit 379e7f906e
30 changed files with 463 additions and 643 deletions

View File

@@ -40,8 +40,6 @@ class BaseAspectPrivate
{ {
public: public:
Id m_id; Id m_id;
QVariant m_value;
QVariant m_defaultValue;
std::function<QVariant(const QVariant &)> m_toSettings; std::function<QVariant(const QVariant &)> m_toSettings;
std::function<QVariant(const QVariant &)> m_fromSettings; std::function<QVariant(const QVariant &)> m_fromSettings;
@@ -99,7 +97,7 @@ BaseAspect::BaseAspect(AspectContainer *container)
{ {
if (container) if (container)
container->registerAspect(this); container->registerAspect(this);
addDataExtractor(this, &BaseAspect::value, &Data::value); addDataExtractor(this, &BaseAspect::variantValue, &Data::value);
} }
/*! /*!
@@ -120,43 +118,49 @@ void BaseAspect::setId(Id id)
d->m_id = id; d->m_id = id;
} }
QVariant BaseAspect::value() const QVariant BaseAspect::variantValue() const
{ {
return d->m_value; return {};
} }
/*! /*!
Sets \a value. Sets \a value.
Emits \c changed() if the value changed. Prefer the typed setValue() of derived classes.
*/ */
void BaseAspect::setValue(const QVariant &value) void BaseAspect::setVariantValue(const QVariant &value)
{ {
if (setValueQuietly(value)) { Q_UNUSED(value)
emit changed(); QTC_CHECK(false);
emitChangedValue(); }
}
void BaseAspect::setDefaultVariantValue(const QVariant &value)
{
Q_UNUSED(value)
QTC_CHECK(false);
} }
/*! /*!
Sets \a value without emitting \c changed(). \internal
Returns whether the value changed. Sets \a value without emitting signals.
Prefer the typed setValueQuietly() of derived classes.
*/ */
bool BaseAspect::setValueQuietly(const QVariant &value) void BaseAspect::setVariantValueQuietly(const QVariant &value)
{ {
if (d->m_value == value) Q_UNUSED(value)
return false; QTC_CHECK(false);
d->m_value = value;
return true;
} }
QVariant BaseAspect::defaultValue() const QVariant BaseAspect::defaultVariantValue() const
{ {
return d->m_defaultValue; return {};
} }
/*! /*!
\fn TypedAspect::setDefaultValue(const ValueType &value)
Sets a default \a value and the current value for this aspect. Sets a default \a value and the current value for this aspect.
\note The current value will be set silently to the same value. \note The current value will be set silently to the same value.
@@ -165,11 +169,6 @@ QVariant BaseAspect::defaultValue() const
Default values will not be stored in settings. Default values will not be stored in settings.
*/ */
void BaseAspect::setDefaultValue(const QVariant &value)
{
d->m_defaultValue = value;
d->m_value = value;
}
void BaseAspect::setDisplayName(const QString &displayName) void BaseAspect::setDisplayName(const QString &displayName)
{ {
@@ -308,8 +307,12 @@ void BaseAspect::setEnabler(BoolAspect *checker)
{ {
QTC_ASSERT(checker, return); QTC_ASSERT(checker, return);
setEnabled(checker->value()); setEnabled(checker->value());
connect(checker, &BoolAspect::volatileValueChanged, this, &BaseAspect::setEnabled); connect(checker, &BoolAspect::volatileValueChanged, this, [this, checker] {
connect(checker, &BoolAspect::valueChanged, this, &BaseAspect::setEnabled); BaseAspect::setEnabled(checker->volatileValue());
});
connect(checker, &BoolAspect::changed, this, [this, checker] {
BaseAspect::setEnabled(checker->volatileValue());
});
} }
bool BaseAspect::isReadOnly() const bool BaseAspect::isReadOnly() const
@@ -442,15 +445,28 @@ void createItem(Layouting::LayoutItem *item, const BaseAspect *aspect)
/*! /*!
Updates this aspect's value from user-initiated changes in the widget. Updates this aspect's value from user-initiated changes in the widget.
This has only an effect if \c isAutoApply is false. Emits changed() if the value changed.
*/ */
void BaseAspect::apply() void BaseAspect::apply()
{ {
QTC_CHECK(!d->m_autoApply); if (silentApply()) {
if (isDirty()) if (hasAction())
setValue(volatileValue()); emit action()->triggered(variantValue().toBool());
emit changed();
}
} }
/*!
Updates this aspect's value from user-initiated changes in the widget.
\returns whether the value changed. Does not emit signals.
*/
bool BaseAspect::silentApply()
{
guiToInternal();
return internalToExternal();
}
/*! /*!
Discard user changes in the widget and restore widget contents from Discard user changes in the widget and restore widget contents from
aspect's value. aspect's value.
@@ -459,9 +475,8 @@ void BaseAspect::apply()
*/ */
void BaseAspect::cancel() void BaseAspect::cancel()
{ {
QTC_CHECK(!d->m_autoApply); externalToInternal();
if (!d->m_subWidgets.isEmpty()) internalToGui();
setVolatileValue(d->m_value);
} }
void BaseAspect::finish() void BaseAspect::finish()
@@ -476,24 +491,9 @@ bool BaseAspect::hasAction() const
return d->m_action != nullptr; return d->m_action != nullptr;
} }
bool BaseAspect::isDirty() const bool BaseAspect::isDirty()
{ {
QTC_CHECK(!isAutoApply()); return false;
// Aspects that were never shown cannot contain unsaved user changes.
if (d->m_subWidgets.isEmpty())
return false;
return volatileValue() != d->m_value;
}
QVariant BaseAspect::volatileValue() const
{
QTC_CHECK(!isAutoApply());
return {};
}
void BaseAspect::setVolatileValue(const QVariant &val)
{
Q_UNUSED(val);
} }
void BaseAspect::registerSubWidget(QWidget *widget) void BaseAspect::registerSubWidget(QWidget *widget)
@@ -534,8 +534,10 @@ void BaseAspect::saveToMap(QVariantMap &data, const QVariant &value,
*/ */
void BaseAspect::fromMap(const QVariantMap &map) void BaseAspect::fromMap(const QVariantMap &map)
{ {
const QVariant val = map.value(settingsKey(), toSettingsValue(defaultValue())); if (settingsKey().isEmpty())
setValue(fromSettingsValue(val)); return;
const QVariant val = map.value(settingsKey(), toSettingsValue(defaultVariantValue()));
setVariantValue(fromSettingsValue(val));
} }
/*! /*!
@@ -543,7 +545,9 @@ void BaseAspect::fromMap(const QVariantMap &map)
*/ */
void BaseAspect::toMap(QVariantMap &map) const void BaseAspect::toMap(QVariantMap &map) const
{ {
saveToMap(map, toSettingsValue(d->m_value), toSettingsValue(d->m_defaultValue), settingsKey()); if (settingsKey().isEmpty())
return;
saveToMap(map, toSettingsValue(variantValue()), toSettingsValue(defaultVariantValue()), settingsKey());
} }
void BaseAspect::readSettings(const QSettings *settings) void BaseAspect::readSettings(const QSettings *settings)
@@ -551,7 +555,7 @@ void BaseAspect::readSettings(const QSettings *settings)
if (settingsKey().isEmpty()) if (settingsKey().isEmpty())
return; return;
const QVariant &val = settings->value(settingsKey()); const QVariant &val = settings->value(settingsKey());
setValue(val.isValid() ? fromSettingsValue(val) : defaultValue()); setVariantValue(val.isValid() ? fromSettingsValue(val) : defaultVariantValue());
} }
void BaseAspect::writeSettings(QSettings *settings) const void BaseAspect::writeSettings(QSettings *settings) const
@@ -560,8 +564,8 @@ void BaseAspect::writeSettings(QSettings *settings) const
return; return;
QtcSettings::setValueWithDefault(settings, QtcSettings::setValueWithDefault(settings,
settingsKey(), settingsKey(),
toSettingsValue(value()), toSettingsValue(variantValue()),
toSettingsValue(defaultValue())); toSettingsValue(defaultVariantValue()));
} }
void BaseAspect::setFromSettingsTransformation(const SavedValueTransformation &transform) void BaseAspect::setFromSettingsTransformation(const SavedValueTransformation &transform)
@@ -773,9 +777,8 @@ public:
*/ */
StringAspect::StringAspect(AspectContainer *container) StringAspect::StringAspect(AspectContainer *container)
: BaseAspect(container), d(new Internal::StringAspectPrivate) : TypedAspect(container), d(new Internal::StringAspectPrivate)
{ {
setDefaultValue(QString());
setSpan(2, 1); // Default: Label + something setSpan(2, 1); // Default: Label + something
addDataExtractor(this, &StringAspect::value, &Data::value); addDataExtractor(this, &StringAspect::value, &Data::value);
@@ -800,7 +803,7 @@ void StringAspect::setValueAcceptor(StringAspect::ValueAcceptor &&acceptor)
*/ */
QString StringAspect::value() const QString StringAspect::value() const
{ {
return BaseAspect::value().toString(); return TypedAspect::value();
} }
/*! /*!
@@ -816,27 +819,13 @@ void StringAspect::setValue(const QString &val)
if (d->m_valueAcceptor) { if (d->m_valueAcceptor) {
const std::optional<QString> tmp = d->m_valueAcceptor(value(), val); const std::optional<QString> tmp = d->m_valueAcceptor(value(), val);
if (!tmp) { if (!tmp) {
update(); // Make sure the original value is retained in the UI internalToGui(); // Make sure the original value is retained in the UI
return; return;
} }
processedValue = tmp.value(); processedValue = tmp.value();
} }
if (BaseAspect::setValueQuietly(QVariant(processedValue))) { TypedAspect::setValue(processedValue);
update();
emit changed();
emit valueChanged(processedValue);
}
}
QString StringAspect::defaultValue() const
{
return BaseAspect::defaultValue().toString();
}
void StringAspect::setDefaultValue(const QString &val)
{
BaseAspect::setDefaultValue(val);
} }
/*! /*!
@@ -845,7 +834,7 @@ void StringAspect::setDefaultValue(const QString &val)
void StringAspect::fromMap(const QVariantMap &map) void StringAspect::fromMap(const QVariantMap &map)
{ {
if (!settingsKey().isEmpty()) if (!settingsKey().isEmpty())
BaseAspect::setValueQuietly(map.value(settingsKey(), defaultValue())); setValueQuietly(map.value(settingsKey(), defaultValue()).toString());
if (d->m_checker) if (d->m_checker)
d->m_checker->fromMap(map); d->m_checker->fromMap(map);
} }
@@ -900,7 +889,7 @@ PathChooser *StringAspect::pathChooser() const
void StringAspect::setShowToolTipOnLabel(bool show) void StringAspect::setShowToolTipOnLabel(bool show)
{ {
d->m_showToolTipOnLabel = show; d->m_showToolTipOnLabel = show;
update(); internalToGui();
} }
/*! /*!
@@ -1246,79 +1235,48 @@ void StringAspect::addToLayout(LayoutItem &parent)
d->m_checker->addToLayout(parent); d->m_checker->addToLayout(parent);
} }
QVariant StringAspect::volatileValue() const void StringAspect::guiToInternal()
{
switch (d->m_displayStyle) {
case PathChooserDisplay:
QTC_ASSERT(d->m_pathChooserDisplay, return {});
if (d->m_pathChooserDisplay->filePath().isEmpty())
return defaultValue();
return d->m_pathChooserDisplay->filePath().toString();
case LineEditDisplay:
QTC_ASSERT(d->m_lineEditDisplay, return {});
if (d->m_lineEditDisplay->text().isEmpty())
return defaultValue();
return d->m_lineEditDisplay->text();
case TextEditDisplay:
QTC_ASSERT(d->m_textEditDisplay, return {});
if (d->m_textEditDisplay->document()->isEmpty())
return defaultValue();
return d->m_textEditDisplay->document()->toPlainText();
case LabelDisplay:
break;
}
return {};
}
void StringAspect::setVolatileValue(const QVariant &val)
{ {
switch (d->m_displayStyle) { switch (d->m_displayStyle) {
case PathChooserDisplay: case PathChooserDisplay:
if (d->m_pathChooserDisplay) if (d->m_pathChooserDisplay)
d->m_pathChooserDisplay->setFilePath(FilePath::fromVariant(val)); m_internal = d->m_pathChooserDisplay->lineEdit()->text();
break; break;
case LineEditDisplay: case LineEditDisplay:
if (d->m_lineEditDisplay) if (d->m_lineEditDisplay)
d->m_lineEditDisplay->setText(val.toString()); m_internal = d->m_lineEditDisplay->text();
break; break;
case TextEditDisplay: case TextEditDisplay:
if (d->m_textEditDisplay) if (d->m_textEditDisplay)
d->m_textEditDisplay->document()->setPlainText(val.toString()); m_internal = d->m_textEditDisplay->document()->toPlainText();
break;
case LabelDisplay: case LabelDisplay:
break; break;
} }
} }
void StringAspect::emitChangedValue() void StringAspect::internalToGui()
{ {
emit valueChanged(value()); const QString displayed = d->m_displayFilter ? d->m_displayFilter(m_internal) : m_internal;
}
void StringAspect::update()
{
const QString displayedString = d->m_displayFilter ? d->m_displayFilter(value()) : value();
if (d->m_pathChooserDisplay) { if (d->m_pathChooserDisplay) {
d->m_pathChooserDisplay->setFilePath(FilePath::fromUserInput(displayedString)); d->m_pathChooserDisplay->lineEdit()->setText(displayed);
d->updateWidgetFromCheckStatus(this, d->m_pathChooserDisplay.data()); d->updateWidgetFromCheckStatus(this, d->m_pathChooserDisplay.data());
} }
if (d->m_lineEditDisplay) { if (d->m_lineEditDisplay) {
d->m_lineEditDisplay->setTextKeepingActiveCursor(displayedString); d->m_lineEditDisplay->setTextKeepingActiveCursor(displayed);
d->updateWidgetFromCheckStatus(this, d->m_lineEditDisplay.data()); d->updateWidgetFromCheckStatus(this, d->m_lineEditDisplay.data());
} }
if (d->m_textEditDisplay) { if (d->m_textEditDisplay) {
const QString old = d->m_textEditDisplay->document()->toPlainText(); const QString old = d->m_textEditDisplay->document()->toPlainText();
if (displayedString != old) if (displayed != old)
d->m_textEditDisplay->setText(displayedString); d->m_textEditDisplay->setText(displayed);
d->updateWidgetFromCheckStatus(this, d->m_textEditDisplay.data()); d->updateWidgetFromCheckStatus(this, d->m_textEditDisplay.data());
} }
if (d->m_labelDisplay) { if (d->m_labelDisplay) {
d->m_labelDisplay->setText(displayedString); d->m_labelDisplay->setText(displayed);
d->m_labelDisplay->setToolTip(d->m_showToolTipOnLabel ? displayedString : toolTip()); d->m_labelDisplay->setToolTip(d->m_showToolTipOnLabel ? displayed : toolTip());
} }
validateInput(); validateInput();
@@ -1342,11 +1300,11 @@ void StringAspect::makeCheckable(CheckBoxPlacement checkBoxPlacement,
: BoolAspect::LabelPlacement::AtCheckBox); : BoolAspect::LabelPlacement::AtCheckBox);
d->m_checker->setSettingsKey(checkerKey); d->m_checker->setSettingsKey(checkerKey);
connect(d->m_checker.get(), &BoolAspect::changed, this, &StringAspect::update); connect(d->m_checker.get(), &BoolAspect::changed, this, &StringAspect::internalToGui);
connect(d->m_checker.get(), &BoolAspect::changed, this, &StringAspect::changed); connect(d->m_checker.get(), &BoolAspect::changed, this, &StringAspect::changed);
connect(d->m_checker.get(), &BoolAspect::changed, this, &StringAspect::checkedChanged); connect(d->m_checker.get(), &BoolAspect::changed, this, &StringAspect::checkedChanged);
update(); internalToGui();
} }
@@ -1384,12 +1342,10 @@ FilePathAspect::FilePathAspect(AspectContainer *container)
*/ */
ColorAspect::ColorAspect(AspectContainer *container) ColorAspect::ColorAspect(AspectContainer *container)
: BaseAspect(container), d(new Internal::ColorAspectPrivate) : TypedAspect(container), d(new Internal::ColorAspectPrivate)
{ {
setDefaultValue(QColor::fromRgb(0, 0, 0)); setDefaultValue(QColor::fromRgb(0, 0, 0));
setSpan(1, 1); setSpan(1, 1);
addDataExtractor(this, &ColorAspect::value, &Data::value);
} }
ColorAspect::~ColorAspect() = default; ColorAspect::~ColorAspect() = default;
@@ -1408,31 +1364,16 @@ void ColorAspect::addToLayout(Layouting::LayoutItem &parent)
} }
} }
QColor ColorAspect::value() const void ColorAspect::internalToGui()
{ {
return BaseAspect::value().value<QColor>();
}
void ColorAspect::setValue(const QColor &value)
{
if (BaseAspect::setValueQuietly(value))
emit changed();
}
QVariant ColorAspect::volatileValue() const
{
QTC_CHECK(!isAutoApply());
if (d->m_colorButton) if (d->m_colorButton)
return d->m_colorButton->color(); m_internal = d->m_colorButton->color();
QTC_CHECK(false);
return {};
} }
void ColorAspect::setVolatileValue(const QVariant &val) void ColorAspect::guiToInternal()
{ {
QTC_CHECK(!isAutoApply());
if (d->m_colorButton) if (d->m_colorButton)
d->m_colorButton->setColor(val.value<QColor>()); d->m_colorButton->setColor(m_internal);
} }
/*! /*!
@@ -1451,12 +1392,10 @@ void ColorAspect::setVolatileValue(const QVariant &val)
BoolAspect::BoolAspect(AspectContainer *container) BoolAspect::BoolAspect(AspectContainer *container)
: BaseAspect(container), d(new Internal::BoolAspectPrivate) : TypedAspect(container), d(new Internal::BoolAspectPrivate)
{ {
setDefaultValue(false); setDefaultValue(false);
setSpan(2, 1); setSpan(2, 1);
addDataExtractor(this, &BoolAspect::value, &Data::value);
} }
/*! /*!
@@ -1520,8 +1459,8 @@ std::function<void (QObject *)> BoolAspect::groupChecker()
QAction *BoolAspect::action() QAction *BoolAspect::action()
{ {
if (hasAction()) if (hasAction())
return BaseAspect::action(); return TypedAspect::action();
auto act = BaseAspect::action(); // Creates it. auto act = TypedAspect::action(); // Creates it.
act->setCheckable(true); act->setCheckable(true);
act->setChecked(value()); act->setChecked(value());
act->setToolTip(toolTip()); act->setToolTip(toolTip());
@@ -1531,74 +1470,32 @@ QAction *BoolAspect::action()
// in a menu like "Use FakeVim", isAutoApply() is false, and yet this // in a menu like "Use FakeVim", isAutoApply() is false, and yet this
// here can trigger. // here can trigger.
//QTC_CHECK(isAutoApply()); //QTC_CHECK(isAutoApply());
setValue(newValue); m_external = newValue;
externalToInternal();
internalToGui();
}); });
return act; return act;
} }
QVariant BoolAspect::volatileValue() const void BoolAspect::guiToInternal()
{ {
if (d->m_button) if (d->m_button)
return d->m_button->isChecked(); m_internal = d->m_button->isChecked();
if (d->m_groupBox)
return d->m_groupBox->isChecked();
QTC_CHECK(false);
return {};
}
void BoolAspect::setVolatileValue(const QVariant &val)
{
if (d->m_button)
d->m_button->setChecked(val.toBool());
else if (d->m_groupBox) else if (d->m_groupBox)
d->m_groupBox->setChecked(val.toBool()); m_internal = d->m_groupBox->isChecked();
} }
void BoolAspect::emitChangedValue() void BoolAspect::internalToGui()
{ {
emit valueChanged(value()); if (d->m_button)
} d->m_button->setChecked(m_internal);
else if (d->m_groupBox)
d->m_groupBox->setChecked(m_internal);
/*!
Returns the value of the boolean aspect as a boolean value.
*/
bool BoolAspect::value() const
{
return BaseAspect::value().toBool();
}
void BoolAspect::setValue(bool value)
{
if (BaseAspect::setValueQuietly(value)) {
if (d->m_button)
d->m_button->setChecked(value);
//qDebug() << "SetValue: Changing" << labelText() << " to " << value;
emit changed();
//QTC_CHECK(!labelText().isEmpty());
emit valueChanged(value);
//qDebug() << "SetValue: Changed" << labelText() << " to " << value;
if (hasAction()) {
//qDebug() << "SetValue: Triggering " << labelText() << "with" << value;
emit action()->triggered(value);
}
}
}
bool BoolAspect::defaultValue() const
{
return BaseAspect::defaultValue().toBool();
}
void BoolAspect::setDefaultValue(bool val)
{
BaseAspect::setDefaultValue(val);
} }
void BoolAspect::setLabel(const QString &labelText, LabelPlacement labelPlacement) void BoolAspect::setLabel(const QString &labelText, LabelPlacement labelPlacement)
{ {
BaseAspect::setLabelText(labelText); TypedAspect::setLabelText(labelText);
d->m_labelPlacement = labelPlacement; d->m_labelPlacement = labelPlacement;
} }
@@ -1627,7 +1524,7 @@ CheckableDecider BoolAspect::checkableDecider()
*/ */
SelectionAspect::SelectionAspect(AspectContainer *container) SelectionAspect::SelectionAspect(AspectContainer *container)
: BaseAspect(container), d(new Internal::SelectionAspectPrivate) : TypedAspect(container), d(new Internal::SelectionAspectPrivate)
{ {
setSpan(2, 1); setSpan(2, 1);
} }
@@ -1683,25 +1580,26 @@ void SelectionAspect::addToLayout(Layouting::LayoutItem &parent)
} }
} }
QVariant SelectionAspect::volatileValue() const void SelectionAspect::guiToInternal()
{ {
switch (d->m_displayStyle) { switch (d->m_displayStyle) {
case DisplayStyle::RadioButtons: case DisplayStyle::RadioButtons:
QTC_ASSERT(d->m_buttonGroup, return {}); if (d->m_buttonGroup)
return d->m_buttonGroup->checkedId(); m_internal = d->m_buttonGroup->checkedId();
break;
case DisplayStyle::ComboBox: case DisplayStyle::ComboBox:
QTC_ASSERT(d->m_comboBox, return {}); if (d->m_comboBox)
return d->m_comboBox->currentIndex(); m_internal = d->m_comboBox->currentIndex();
break;
} }
return {};
} }
void SelectionAspect::setVolatileValue(const QVariant &val) void SelectionAspect::internalToGui()
{ {
switch (d->m_displayStyle) { switch (d->m_displayStyle) {
case DisplayStyle::RadioButtons: { case DisplayStyle::RadioButtons: {
if (d->m_buttonGroup) { if (d->m_buttonGroup) {
QAbstractButton *button = d->m_buttonGroup->button(val.toInt()); QAbstractButton *button = d->m_buttonGroup->button(m_internal);
QTC_ASSERT(button, return); QTC_ASSERT(button, return);
button->setChecked(true); button->setChecked(true);
} }
@@ -1709,7 +1607,7 @@ void SelectionAspect::setVolatileValue(const QVariant &val)
} }
case DisplayStyle::ComboBox: case DisplayStyle::ComboBox:
if (d->m_comboBox) if (d->m_comboBox)
d->m_comboBox->setCurrentIndex(val.toInt()); d->m_comboBox->setCurrentIndex(m_internal);
break; break;
} }
} }
@@ -1727,22 +1625,6 @@ void SelectionAspect::setDisplayStyle(SelectionAspect::DisplayStyle style)
d->m_displayStyle = style; d->m_displayStyle = style;
} }
int SelectionAspect::value() const
{
return BaseAspect::value().toInt();
}
void SelectionAspect::setValue(int value)
{
if (BaseAspect::setValueQuietly(value)) {
if (d->m_buttonGroup && 0 <= value && value < d->m_buttons.size())
d->m_buttons.at(value)->setChecked(true);
else if (d->m_comboBox)
d->m_comboBox->setCurrentIndex(value);
emit changed();
}
}
void SelectionAspect::setStringValue(const QString &val) void SelectionAspect::setStringValue(const QString &val)
{ {
const int index = indexForDisplay(val); const int index = indexForDisplay(val);
@@ -1750,20 +1632,15 @@ void SelectionAspect::setStringValue(const QString &val)
setValue(index); setValue(index);
} }
int SelectionAspect::defaultValue() const
{
return BaseAspect::defaultValue().toInt();
}
void SelectionAspect::setDefaultValue(int val) void SelectionAspect::setDefaultValue(int val)
{ {
BaseAspect::setDefaultValue(val); TypedAspect::setDefaultValue(val);
} }
// Note: This needs to be set after all options are added. // Note: This needs to be set after all options are added.
void SelectionAspect::setDefaultValue(const QString &val) void SelectionAspect::setDefaultValue(const QString &val)
{ {
BaseAspect::setDefaultValue(indexForDisplay(val)); TypedAspect::setDefaultValue(indexForDisplay(val));
} }
QString SelectionAspect::stringValue() const QString SelectionAspect::stringValue() const
@@ -1830,7 +1707,7 @@ QVariant SelectionAspect::itemValueForIndex(int index) const
*/ */
MultiSelectionAspect::MultiSelectionAspect(AspectContainer *container) MultiSelectionAspect::MultiSelectionAspect(AspectContainer *container)
: BaseAspect(container), d(new Internal::MultiSelectionAspectPrivate(this)) : TypedAspect(container), d(new Internal::MultiSelectionAspectPrivate(this))
{ {
setDefaultValue(QStringList()); setDefaultValue(QStringList());
setSpan(2, 1); setSpan(2, 1);
@@ -1898,23 +1775,27 @@ void MultiSelectionAspect::setDisplayStyle(MultiSelectionAspect::DisplayStyle st
d->m_displayStyle = style; d->m_displayStyle = style;
} }
QStringList MultiSelectionAspect::value() const void MultiSelectionAspect::internalToGui()
{ {
return BaseAspect::value().toStringList(); if (d->m_listView) {
const int n = d->m_listView->count();
QTC_CHECK(n == d->m_allValues.size());
for (int i = 0; i != n; ++i) {
auto item = d->m_listView->item(i);
item->setCheckState(m_internal.contains(item->text()) ? Qt::Checked : Qt::Unchecked);
}
}
} }
void MultiSelectionAspect::setValue(const QStringList &value) void MultiSelectionAspect::guiToInternal()
{ {
if (BaseAspect::setValueQuietly(value)) { if (d->m_listView) {
if (d->m_listView) { m_internal.clear();
const int n = d->m_listView->count(); for (const QString &val : std::as_const(d->m_allValues)) {
QTC_CHECK(n == d->m_allValues.size()); auto item = new QListWidgetItem(val, d->m_listView);
for (int i = 0; i != n; ++i) { item->setFlags(item->flags() | Qt::ItemIsUserCheckable);
auto item = d->m_listView->item(i); if (item->checkState() == Qt::Checked)
item->setCheckState(value.contains(item->text()) ? Qt::Checked : Qt::Unchecked); m_internal.append(item->text());
}
} else {
emit changed();
} }
} }
} }
@@ -1937,12 +1818,9 @@ void MultiSelectionAspect::setValue(const QStringList &value)
// IntegerAspect // IntegerAspect
IntegerAspect::IntegerAspect(AspectContainer *container) IntegerAspect::IntegerAspect(AspectContainer *container)
: BaseAspect(container), d(new Internal::IntegerAspectPrivate) : TypedAspect(container), d(new Internal::IntegerAspectPrivate)
{ {
setDefaultValue(qint64(0));
setSpan(2, 1); setSpan(2, 1);
addDataExtractor(this, &IntegerAspect::value, &Data::value);
} }
/*! /*!
@@ -1974,41 +1852,16 @@ void IntegerAspect::addToLayout(Layouting::LayoutItem &parent)
} }
} }
QVariant IntegerAspect::volatileValue() const void IntegerAspect::guiToInternal()
{ {
QTC_CHECK(!isAutoApply());
QTC_ASSERT(d->m_spinBox, return {});
return d->m_spinBox->value() * d->m_displayScaleFactor;
}
void IntegerAspect::setVolatileValue(const QVariant &val)
{
QTC_CHECK(!isAutoApply());
if (d->m_spinBox) if (d->m_spinBox)
d->m_spinBox->setValue(int(val.toLongLong() / d->m_displayScaleFactor)); m_internal = d->m_spinBox->value() * d->m_displayScaleFactor;
} }
qint64 IntegerAspect::value() const void IntegerAspect::internalToGui()
{ {
return BaseAspect::value().toLongLong(); if (d->m_spinBox)
} d->m_spinBox->setValue(m_internal / d->m_displayScaleFactor);
void IntegerAspect::setValue(qint64 value)
{
if (BaseAspect::setValueQuietly(value)) {
if (d->m_spinBox)
d->m_spinBox->setValue(value / d->m_displayScaleFactor);
//qDebug() << "SetValue: Changing" << labelText() << " to " << value;
emit changed();
//QTC_CHECK(!labelText().isEmpty());
emit valueChanged(value);
//qDebug() << "SetValue: Changed" << labelText() << " to " << value;
}
}
qint64 IntegerAspect::defaultValue() const
{
return BaseAspect::defaultValue().toLongLong();
} }
void IntegerAspect::setRange(qint64 min, qint64 max) void IntegerAspect::setRange(qint64 min, qint64 max)
@@ -2042,11 +1895,6 @@ void IntegerAspect::setDisplayScaleFactor(qint64 factor)
d->m_displayScaleFactor = factor; d->m_displayScaleFactor = factor;
} }
void IntegerAspect::setDefaultValue(qint64 defaultValue)
{
BaseAspect::setDefaultValue(defaultValue);
}
void IntegerAspect::setSpecialValueText(const QString &specialText) void IntegerAspect::setSpecialValueText(const QString &specialText)
{ {
d->m_specialValueText = specialText; d->m_specialValueText = specialText;
@@ -2073,7 +1921,7 @@ void IntegerAspect::setSingleStep(qint64 step)
*/ */
DoubleAspect::DoubleAspect(AspectContainer *container) DoubleAspect::DoubleAspect(AspectContainer *container)
: BaseAspect(container), d(new Internal::DoubleAspectPrivate) : TypedAspect(container), d(new Internal::DoubleAspectPrivate)
{ {
setDefaultValue(double(0)); setDefaultValue(double(0));
setSpan(2, 1); setSpan(2, 1);
@@ -2097,7 +1945,7 @@ void DoubleAspect::addToLayout(LayoutItem &builder)
d->m_spinBox->setSpecialValueText(d->m_specialValueText); d->m_spinBox->setSpecialValueText(d->m_specialValueText);
if (d->m_maximumValue && d->m_maximumValue) if (d->m_maximumValue && d->m_maximumValue)
d->m_spinBox->setRange(d->m_minimumValue.value(), d->m_maximumValue.value()); d->m_spinBox->setRange(d->m_minimumValue.value(), d->m_maximumValue.value());
d->m_spinBox->setValue(value()); // Must happen after setRange()! internalToGui(); // Must happen after setRange()!
addLabeledItem(builder, d->m_spinBox); addLabeledItem(builder, d->m_spinBox);
if (isAutoApply()) { if (isAutoApply()) {
@@ -2106,33 +1954,16 @@ void DoubleAspect::addToLayout(LayoutItem &builder)
} }
} }
QVariant DoubleAspect::volatileValue() const void DoubleAspect::guiToInternal()
{ {
QTC_CHECK(!isAutoApply());
QTC_ASSERT(d->m_spinBox, return {});
return d->m_spinBox->value();
}
void DoubleAspect::setVolatileValue(const QVariant &val)
{
QTC_CHECK(!isAutoApply());
if (d->m_spinBox) if (d->m_spinBox)
d->m_spinBox->setValue(val.toDouble()); m_internal = d->m_spinBox->value();
} }
double DoubleAspect::value() const void DoubleAspect::internalToGui()
{ {
return BaseAspect::value().toDouble(); if (d->m_spinBox)
} d->m_spinBox->setValue(m_internal);
void DoubleAspect::setValue(double value)
{
BaseAspect::setValue(value);
}
double DoubleAspect::defaultValue() const
{
return BaseAspect::defaultValue().toDouble();
} }
void DoubleAspect::setRange(double min, double max) void DoubleAspect::setRange(double min, double max)
@@ -2151,11 +1982,6 @@ void DoubleAspect::setSuffix(const QString &suffix)
d->m_suffix = suffix; d->m_suffix = suffix;
} }
void DoubleAspect::setDefaultValue(double defaultValue)
{
BaseAspect::setDefaultValue(defaultValue);
}
void DoubleAspect::setSpecialValueText(const QString &specialText) void DoubleAspect::setSpecialValueText(const QString &specialText)
{ {
d->m_specialValueText = specialText; d->m_specialValueText = specialText;
@@ -2192,7 +2018,7 @@ TriStateAspect::TriStateAspect(AspectContainer *container,
TriState TriStateAspect::value() const TriState TriStateAspect::value() const
{ {
return TriState::fromVariant(BaseAspect::value()); return TriState::fromInt(SelectionAspect::value());
} }
void TriStateAspect::setValue(TriState value) void TriStateAspect::setValue(TriState value)
@@ -2202,12 +2028,12 @@ void TriStateAspect::setValue(TriState value)
TriState TriStateAspect::defaultValue() const TriState TriStateAspect::defaultValue() const
{ {
return TriState::fromVariant(BaseAspect::defaultValue()); return TriState::fromInt(SelectionAspect::defaultValue());
} }
void TriStateAspect::setDefaultValue(TriState value) void TriStateAspect::setDefaultValue(TriState value)
{ {
BaseAspect::setDefaultValue(value.toVariant()); SelectionAspect::setDefaultValue(value.toInt());
} }
const TriState TriState::Enabled{TriState::EnabledValue}; const TriState TriState::Enabled{TriState::EnabledValue};
@@ -2216,7 +2042,11 @@ const TriState TriState::Default{TriState::DefaultValue};
TriState TriState::fromVariant(const QVariant &variant) TriState TriState::fromVariant(const QVariant &variant)
{ {
int v = variant.toInt(); return fromInt(variant.toInt());
}
TriState TriState::fromInt(int v)
{
QTC_ASSERT(v == EnabledValue || v == DisabledValue || v == DefaultValue, v = DefaultValue); QTC_ASSERT(v == EnabledValue || v == DisabledValue || v == DefaultValue, v = DefaultValue);
return TriState(Value(v)); return TriState(Value(v));
} }
@@ -2231,7 +2061,7 @@ TriState TriState::fromVariant(const QVariant &variant)
*/ */
StringListAspect::StringListAspect(AspectContainer *container) StringListAspect::StringListAspect(AspectContainer *container)
: BaseAspect(container), d(new Internal::StringListAspectPrivate) : TypedAspect(container), d(new Internal::StringListAspectPrivate)
{ {
setDefaultValue(QStringList()); setDefaultValue(QStringList());
} }
@@ -2250,16 +2080,6 @@ void StringListAspect::addToLayout(LayoutItem &parent)
// TODO - when needed. // TODO - when needed.
} }
QStringList StringListAspect::value() const
{
return BaseAspect::value().toStringList();
}
void StringListAspect::setValue(const QStringList &value)
{
BaseAspect::setValue(value);
}
void StringListAspect::appendValue(const QString &s, bool allowDuplicates) void StringListAspect::appendValue(const QString &s, bool allowDuplicates)
{ {
QStringList val = value(); QStringList val = value();
@@ -2303,10 +2123,8 @@ void StringListAspect::removeValues(const QStringList &values)
*/ */
IntegersAspect::IntegersAspect(AspectContainer *container) IntegersAspect::IntegersAspect(AspectContainer *container)
: BaseAspect(container) : TypedAspect(container)
{ {}
setDefaultValue({});
}
/*! /*!
\internal \internal
@@ -2322,33 +2140,6 @@ void IntegersAspect::addToLayout(Layouting::LayoutItem &parent)
// TODO - when needed. // TODO - when needed.
} }
void IntegersAspect::emitChangedValue()
{
emit valueChanged(value());
}
QList<int> IntegersAspect::value() const
{
return transform(BaseAspect::value().toList(),
[](QVariant v) { return v.toInt(); });
}
void IntegersAspect::setValue(const QList<int> &value)
{
BaseAspect::setValue(transform(value, [](int i) { return QVariant::fromValue<int>(i); }));
}
QList<int> IntegersAspect::defaultValue() const
{
return transform(BaseAspect::defaultValue().toList(),
[](QVariant v) { return v.toInt(); });
}
void IntegersAspect::setDefaultValue(const QList<int> &value)
{
BaseAspect::setDefaultValue(transform(value, [](int i) { return QVariant::fromValue<int>(i); }));
}
/*! /*!
\class Utils::TextDisplay \class Utils::TextDisplay
@@ -2576,7 +2367,7 @@ void AspectContainer::finish()
void AspectContainer::reset() void AspectContainer::reset()
{ {
for (BaseAspect *aspect : std::as_const(d->m_items)) for (BaseAspect *aspect : std::as_const(d->m_items))
aspect->setValueQuietly(aspect->defaultValue()); aspect->setVariantValueQuietly(aspect->defaultVariantValue());
} }
void AspectContainer::setAutoApply(bool on) void AspectContainer::setAutoApply(bool on)
@@ -2633,6 +2424,41 @@ BaseAspect::Data::Ptr BaseAspect::extractData() const
return Data::Ptr(data); return Data::Ptr(data);
} }
/*
Mirrors the internal volatile value to the GUI element if they are already
created.
No-op otherwise.
*/
void BaseAspect::internalToGui()
{}
/*
Mirrors the data stored in GUI element if they are already created to
the internal volatile value.
No-op otherwise.
*/
void BaseAspect::guiToInternal()
{}
/*
Mirrors internal volatile value to the externally visible value.
This function is used for \c apply().
\returns whether the value changes.
*/
bool BaseAspect::internalToExternal()
{
return false;
}
/*
Mirrors externally visible value to internal volatile value.
*/
void BaseAspect::externalToInternal()
{}
void BaseAspect::addDataExtractorHelper(const DataExtractor &extractor) const void BaseAspect::addDataExtractorHelper(const DataExtractor &extractor) const
{ {
d->m_dataExtractors.append(extractor); d->m_dataExtractors.append(extractor);

View File

@@ -51,12 +51,12 @@ public:
Id id() const; Id id() const;
void setId(Id id); void setId(Id id);
QVariant value() const; virtual QVariant variantValue() const;
void setValue(const QVariant &value); virtual void setVariantValue(const QVariant &value);
bool setValueQuietly(const QVariant &value); virtual void setVariantValueQuietly(const QVariant &value);
QVariant defaultValue() const; virtual QVariant defaultVariantValue() const;
void setDefaultValue(const QVariant &value); virtual void setDefaultVariantValue(const QVariant &value);
QString settingsKey() const; QString settingsKey() const;
void setSettingsKey(const QString &settingsKey); void setSettingsKey(const QString &settingsKey);
@@ -100,10 +100,6 @@ public:
virtual void addToLayout(Layouting::LayoutItem &parent); virtual void addToLayout(Layouting::LayoutItem &parent);
virtual QVariant volatileValue() const;
virtual void setVolatileValue(const QVariant &val);
virtual void emitChangedValue() {}
virtual void readSettings(const QSettings *settings); virtual void readSettings(const QSettings *settings);
virtual void writeSettings(QSettings *settings) const; virtual void writeSettings(QSettings *settings) const;
@@ -114,9 +110,10 @@ public:
QVariant fromSettingsValue(const QVariant &val) const; QVariant fromSettingsValue(const QVariant &val) const;
virtual void apply(); virtual void apply();
virtual bool silentApply();
virtual void cancel(); virtual void cancel();
virtual void finish(); virtual void finish();
virtual bool isDirty() const; virtual bool isDirty();
bool hasAction() const; bool hasAction() const;
class QTCREATOR_UTILS_EXPORT Data class QTCREATOR_UTILS_EXPORT Data
@@ -164,9 +161,15 @@ public:
signals: signals:
void changed(); void changed();
void volatileValueChanged();
void labelLinkActivated(const QString &link); void labelLinkActivated(const QString &link);
protected: protected:
virtual void internalToGui();
virtual void guiToInternal();
virtual bool internalToExternal();
virtual void externalToInternal();
QLabel *label() const; QLabel *label() const;
void setupLabel(); void setupLabel();
void addLabeledItem(Layouting::LayoutItem &parent, QWidget *widget); void addLabeledItem(Layouting::LayoutItem &parent, QWidget *widget);
@@ -208,7 +211,112 @@ private:
QTCREATOR_UTILS_EXPORT void createItem(Layouting::LayoutItem *item, const BaseAspect &aspect); QTCREATOR_UTILS_EXPORT void createItem(Layouting::LayoutItem *item, const BaseAspect &aspect);
QTCREATOR_UTILS_EXPORT void createItem(Layouting::LayoutItem *item, const BaseAspect *aspect); QTCREATOR_UTILS_EXPORT void createItem(Layouting::LayoutItem *item, const BaseAspect *aspect);
class QTCREATOR_UTILS_EXPORT BoolAspect : public BaseAspect template <typename ValueType>
class TypedAspect : public BaseAspect
{
public:
TypedAspect(AspectContainer *container = nullptr)
: BaseAspect(container)
{
addDataExtractor(this, &TypedAspect::value, &Data::value);
}
struct Data : BaseAspect::Data
{
ValueType value;
};
ValueType operator()() const { return m_external; }
ValueType value() const { return m_external; }
ValueType defaultValue() const { return m_default; }
void setDefaultValue(const ValueType &value)
{
m_default = value;
setValue(value);
}
void setValue(const ValueType &value)
{
m_external = value;
if (isDirty()) {
externalToInternal();
internalToGui();
}
}
void setValueQuietly(const ValueType &value)
{
m_external = value;
if (isDirty()) {
externalToInternal();
internalToGui();
}
}
void setVolatileValue(const ValueType &value)
{
m_internal = value;
internalToGui();
}
ValueType volatileValue() const
{
const_cast<TypedAspect *>(this)->guiToInternal();
return m_internal;
}
protected:
bool isDirty() override
{
guiToInternal();
return m_internal != m_external;
}
bool internalToExternal() override
{
if (m_external == m_internal)
return false;
m_external = m_internal;
return true;
}
void externalToInternal() override
{
m_internal = m_external;
}
QVariant variantValue() const override
{
return QVariant::fromValue<ValueType>(m_external);
}
void setVariantValue(const QVariant &value) override
{
setValue(value.value<ValueType>());
}
void setVariantValueQuietly(const QVariant &value) override
{
setValueQuietly(value.value<ValueType>());
}
QVariant defaultVariantValue() const override
{
return QVariant::fromValue<ValueType>(m_default);
}
void setDefaultVariantValue(const QVariant &value) override
{
m_default = value.value<ValueType>();
}
ValueType m_default{};
ValueType m_external{};
ValueType m_internal{};
};
class QTCREATOR_UTILS_EXPORT BoolAspect : public TypedAspect<bool>
{ {
Q_OBJECT Q_OBJECT
@@ -216,27 +324,12 @@ public:
BoolAspect(AspectContainer *container = nullptr); BoolAspect(AspectContainer *container = nullptr);
~BoolAspect() override; ~BoolAspect() override;
struct Data : BaseAspect::Data
{
bool value;
};
void addToLayout(Layouting::LayoutItem &parent) override; void addToLayout(Layouting::LayoutItem &parent) override;
std::function<void(QObject *)> groupChecker(); std::function<void(QObject *)> groupChecker();
Utils::CheckableDecider checkableDecider(); Utils::CheckableDecider checkableDecider();
QAction *action() override; QAction *action() override;
QVariant volatileValue() const override;
void setVolatileValue(const QVariant &val) override;
void emitChangedValue() override;
bool operator()() const { return value(); }
bool value() const;
void setValue(bool val);
bool defaultValue() const;
void setDefaultValue(bool val);
enum class LabelPlacement { AtCheckBox, AtCheckBoxWithoutDummyLabel, InExtraLabel }; enum class LabelPlacement { AtCheckBox, AtCheckBoxWithoutDummyLabel, InExtraLabel };
void setLabel(const QString &labelText, void setLabel(const QString &labelText,
LabelPlacement labelPlacement = LabelPlacement::InExtraLabel); LabelPlacement labelPlacement = LabelPlacement::InExtraLabel);
@@ -244,15 +337,14 @@ public:
void adoptButton(QAbstractButton *button); void adoptButton(QAbstractButton *button);
signals:
void valueChanged(bool newValue);
void volatileValueChanged(bool newValue);
private: private:
void internalToGui() override;
void guiToInternal() override;
std::unique_ptr<Internal::BoolAspectPrivate> d; std::unique_ptr<Internal::BoolAspectPrivate> d;
}; };
class QTCREATOR_UTILS_EXPORT ColorAspect : public BaseAspect class QTCREATOR_UTILS_EXPORT ColorAspect : public TypedAspect<QColor>
{ {
Q_OBJECT Q_OBJECT
@@ -260,24 +352,16 @@ public:
ColorAspect(AspectContainer *container = nullptr); ColorAspect(AspectContainer *container = nullptr);
~ColorAspect() override; ~ColorAspect() override;
struct Data : BaseAspect::Data
{
QColor value;
};
void addToLayout(Layouting::LayoutItem &parent) override; void addToLayout(Layouting::LayoutItem &parent) override;
QColor value() const;
void setValue(const QColor &val);
QVariant volatileValue() const override;
void setVolatileValue(const QVariant &val) override;
private: private:
void internalToGui() override;
void guiToInternal() override;
std::unique_ptr<Internal::ColorAspectPrivate> d; std::unique_ptr<Internal::ColorAspectPrivate> d;
}; };
class QTCREATOR_UTILS_EXPORT SelectionAspect : public BaseAspect class QTCREATOR_UTILS_EXPORT SelectionAspect : public TypedAspect<int>
{ {
Q_OBJECT Q_OBJECT
@@ -286,20 +370,13 @@ public:
~SelectionAspect() override; ~SelectionAspect() override;
void addToLayout(Layouting::LayoutItem &parent) override; void addToLayout(Layouting::LayoutItem &parent) override;
QVariant volatileValue() const override;
void setVolatileValue(const QVariant &val) override;
void finish() override; void finish() override;
int operator()() const { return value(); }
int value() const;
void setValue(int val);
QString stringValue() const; QString stringValue() const;
void setStringValue(const QString &val); void setStringValue(const QString &val);
int defaultValue() const;
void setDefaultValue(int val);
void setDefaultValue(const QString &val); void setDefaultValue(const QString &val);
void setDefaultValue(int val);
QVariant itemValue() const; QVariant itemValue() const;
@@ -325,14 +402,15 @@ public:
int indexForItemValue(const QVariant &value) const; int indexForItemValue(const QVariant &value) const;
QVariant itemValueForIndex(int index) const; QVariant itemValueForIndex(int index) const;
signals: protected:
void volatileValueChanged(int newValue); void internalToGui() override;
void guiToInternal() override;
private: private:
std::unique_ptr<Internal::SelectionAspectPrivate> d; std::unique_ptr<Internal::SelectionAspectPrivate> d;
}; };
class QTCREATOR_UTILS_EXPORT MultiSelectionAspect : public BaseAspect class QTCREATOR_UTILS_EXPORT MultiSelectionAspect : public TypedAspect<QStringList>
{ {
Q_OBJECT Q_OBJECT
@@ -345,17 +423,18 @@ public:
enum class DisplayStyle { ListView }; enum class DisplayStyle { ListView };
void setDisplayStyle(DisplayStyle style); void setDisplayStyle(DisplayStyle style);
QStringList value() const;
void setValue(const QStringList &val);
QStringList allValues() const; QStringList allValues() const;
void setAllValues(const QStringList &val); void setAllValues(const QStringList &val);
protected:
void internalToGui() override;
void guiToInternal() override;
private: private:
std::unique_ptr<Internal::MultiSelectionAspectPrivate> d; std::unique_ptr<Internal::MultiSelectionAspectPrivate> d;
}; };
class QTCREATOR_UTILS_EXPORT StringAspect : public BaseAspect class QTCREATOR_UTILS_EXPORT StringAspect : public TypedAspect<QString>
{ {
Q_OBJECT Q_OBJECT
@@ -371,21 +450,13 @@ public:
void addToLayout(Layouting::LayoutItem &parent) override; void addToLayout(Layouting::LayoutItem &parent) override;
QVariant volatileValue() const override;
void setVolatileValue(const QVariant &val) override;
void emitChangedValue() override;
// Hook between UI and StringAspect: // Hook between UI and StringAspect:
using ValueAcceptor = std::function<std::optional<QString>(const QString &, const QString &)>; using ValueAcceptor = std::function<std::optional<QString>(const QString &, const QString &)>;
void setValueAcceptor(ValueAcceptor &&acceptor); void setValueAcceptor(ValueAcceptor &&acceptor);
QString operator()() const { return value(); }
QString value() const; QString value() const;
void setValue(const QString &val); void setValue(const QString &val);
QString defaultValue() const;
void setDefaultValue(const QString &val);
void setShowToolTipOnLabel(bool show); void setShowToolTipOnLabel(bool show);
void setDisplayFilter(const std::function<QString (const QString &)> &displayFilter); void setDisplayFilter(const std::function<QString (const QString &)> &displayFilter);
@@ -438,10 +509,10 @@ public:
signals: signals:
void checkedChanged(); void checkedChanged();
void valueChanged(const QString &newValue);
protected: protected:
void update(); void internalToGui() override;
void guiToInternal() override;
std::unique_ptr<Internal::StringAspectPrivate> d; std::unique_ptr<Internal::StringAspectPrivate> d;
}; };
@@ -454,7 +525,7 @@ public:
FilePath operator()() const { return filePath(); } FilePath operator()() const { return filePath(); }
}; };
class QTCREATOR_UTILS_EXPORT IntegerAspect : public BaseAspect class QTCREATOR_UTILS_EXPORT IntegerAspect : public TypedAspect<qint64>
{ {
Q_OBJECT Q_OBJECT
@@ -464,16 +535,6 @@ public:
void addToLayout(Layouting::LayoutItem &parent) override; void addToLayout(Layouting::LayoutItem &parent) override;
QVariant volatileValue() const override;
void setVolatileValue(const QVariant &val) override;
qint64 operator()() const { return value(); }
qint64 value() const;
void setValue(qint64 val);
qint64 defaultValue() const;
void setDefaultValue(qint64 defaultValue);
void setRange(qint64 min, qint64 max); void setRange(qint64 min, qint64 max);
void setLabel(const QString &label); // FIXME: Use setLabelText void setLabel(const QString &label); // FIXME: Use setLabelText
void setPrefix(const QString &prefix); void setPrefix(const QString &prefix);
@@ -485,14 +546,15 @@ public:
struct Data : BaseAspect::Data { qint64 value = 0; }; struct Data : BaseAspect::Data { qint64 value = 0; };
signals: protected:
void valueChanged(int newValue); void internalToGui() override;
void guiToInternal() override;
private: private:
std::unique_ptr<Internal::IntegerAspectPrivate> d; std::unique_ptr<Internal::IntegerAspectPrivate> d;
}; };
class QTCREATOR_UTILS_EXPORT DoubleAspect : public BaseAspect class QTCREATOR_UTILS_EXPORT DoubleAspect : public TypedAspect<double>
{ {
Q_OBJECT Q_OBJECT
@@ -502,22 +564,16 @@ public:
void addToLayout(Layouting::LayoutItem &parent) override; void addToLayout(Layouting::LayoutItem &parent) override;
QVariant volatileValue() const override;
void setVolatileValue(const QVariant &val) override;
double operator()() const { return value(); }
double value() const;
void setValue(double val);
double defaultValue() const;
void setDefaultValue(double defaultValue);
void setRange(double min, double max); void setRange(double min, double max);
void setPrefix(const QString &prefix); void setPrefix(const QString &prefix);
void setSuffix(const QString &suffix); void setSuffix(const QString &suffix);
void setSpecialValueText(const QString &specialText); void setSpecialValueText(const QString &specialText);
void setSingleStep(double step); void setSingleStep(double step);
protected:
void internalToGui() override;
void guiToInternal() override;
private: private:
std::unique_ptr<Internal::DoubleAspectPrivate> d; std::unique_ptr<Internal::DoubleAspectPrivate> d;
}; };
@@ -532,6 +588,7 @@ public:
int toInt() const { return int(m_value); } int toInt() const { return int(m_value); }
QVariant toVariant() const { return int(m_value); } QVariant toVariant() const { return int(m_value); }
static TriState fromInt(int value);
static TriState fromVariant(const QVariant &variant); static TriState fromVariant(const QVariant &variant);
static const TriState Enabled; static const TriState Enabled;
@@ -562,7 +619,7 @@ public:
void setDefaultValue(TriState setting); void setDefaultValue(TriState setting);
}; };
class QTCREATOR_UTILS_EXPORT StringListAspect : public BaseAspect class QTCREATOR_UTILS_EXPORT StringListAspect : public TypedAspect<QStringList>
{ {
Q_OBJECT Q_OBJECT
@@ -572,9 +629,6 @@ public:
void addToLayout(Layouting::LayoutItem &parent) override; void addToLayout(Layouting::LayoutItem &parent) override;
QStringList value() const;
void setValue(const QStringList &val);
void appendValue(const QString &value, bool allowDuplicates = true); void appendValue(const QString &value, bool allowDuplicates = true);
void removeValue(const QString &value); void removeValue(const QString &value);
void appendValues(const QStringList &values, bool allowDuplicates = true); void appendValues(const QStringList &values, bool allowDuplicates = true);
@@ -584,7 +638,7 @@ private:
std::unique_ptr<Internal::StringListAspectPrivate> d; std::unique_ptr<Internal::StringListAspectPrivate> d;
}; };
class QTCREATOR_UTILS_EXPORT IntegersAspect : public BaseAspect class QTCREATOR_UTILS_EXPORT IntegersAspect : public TypedAspect<QList<int>>
{ {
Q_OBJECT Q_OBJECT
@@ -593,17 +647,6 @@ public:
~IntegersAspect() override; ~IntegersAspect() override;
void addToLayout(Layouting::LayoutItem &parent) override; void addToLayout(Layouting::LayoutItem &parent) override;
void emitChangedValue() override;
QList<int> operator()() const { return value(); }
QList<int> value() const;
void setValue(const QList<int> &value);
QList<int> defaultValue() const;
void setDefaultValue(const QList<int> &value);
signals:
void valueChanged(const QList<int> &values);
}; };
class QTCREATOR_UTILS_EXPORT TextDisplay : public BaseAspect class QTCREATOR_UTILS_EXPORT TextDisplay : public BaseAspect

View File

@@ -111,9 +111,9 @@ GTestSettings::GTestSettings(Id settingsId)
return edit && GTestUtils::isValidGTestFilter(edit->text()); return edit && GTestUtils::isValidGTestFilter(edit->text());
}); });
QObject::connect(&groupMode, &SelectionAspect::volatileValueChanged, QObject::connect(&groupMode, &SelectionAspect::volatileValueChanged, &gtestFilter, [this] {
&gtestFilter, [this](int val) { gtestFilter.setEnabled(groupMode.itemValueForIndex(groupMode.volatileValue())
gtestFilter.setEnabled(groupMode.itemValueForIndex(val) == GTest::Constants::GTestFilter); == GTest::Constants::GTestFilter);
}); });
QObject::connect(this, &AspectContainer::applied, this, [] { QObject::connect(this, &AspectContainer::applied, this, [] {

View File

@@ -246,7 +246,7 @@ public:
configurations, predefinedStyleButton] { configurations, predefinedStyleButton] {
const bool predefSelected = styleButtonGroup->checkedButton() == predefinedStyleButton; const bool predefSelected = styleButtonGroup->checkedButton() == predefinedStyleButton;
predefinedBlob->setEnabled(predefSelected); predefinedBlob->setEnabled(predefSelected);
fallbackBlob->setEnabled(predefSelected && s.predefinedStyle.volatileValue().toInt() == 5); // File fallbackBlob->setEnabled(predefSelected && s.predefinedStyle.volatileValue() == 5); // File
configurations->setEnabled(!predefSelected); configurations->setEnabled(!predefSelected);
}; };
updateEnabled(); updateEnabled();

View File

@@ -2114,12 +2114,10 @@ QString CMakeBuildSystem::cmakeBuildType() const
void CMakeBuildSystem::setCMakeBuildType(const QString &cmakeBuildType, bool quiet) void CMakeBuildSystem::setCMakeBuildType(const QString &cmakeBuildType, bool quiet)
{ {
auto aspect = buildConfiguration()->aspect<BuildTypeAspect>(); auto aspect = buildConfiguration()->aspect<BuildTypeAspect>();
if (quiet) { if (quiet)
aspect->setValueQuietly(cmakeBuildType); aspect->setValueQuietly(cmakeBuildType);
aspect->update(); else
} else {
aspect->setValue(cmakeBuildType); aspect->setValue(cmakeBuildType);
}
} }
namespace Internal { namespace Internal {
@@ -2179,7 +2177,7 @@ void InitialCMakeArgumentsAspect::setAllValues(const QString &values, QStringLis
// Display the unknown arguments in "Additional CMake Options" // Display the unknown arguments in "Additional CMake Options"
const QString additionalOptionsValue = ProcessArgs::joinArgs(additionalOptions); const QString additionalOptionsValue = ProcessArgs::joinArgs(additionalOptions);
BaseAspect::setValueQuietly(additionalOptionsValue); setValueQuietly(additionalOptionsValue);
} }
void InitialCMakeArgumentsAspect::setCMakeConfiguration(const CMakeConfig &config) void InitialCMakeArgumentsAspect::setCMakeConfiguration(const CMakeConfig &config)

View File

@@ -135,7 +135,6 @@ class BuildTypeAspect final : public Utils::StringAspect
public: public:
BuildTypeAspect(); BuildTypeAspect();
using Utils::StringAspect::update;
}; };
class ConfigureEnvironmentAspect final: public ProjectExplorer::EnvironmentAspect class ConfigureEnvironmentAspect final: public ProjectExplorer::EnvironmentAspect

View File

@@ -79,10 +79,8 @@ public:
auto updateAuthWidget = [authWidget]() { auto updateAuthWidget = [authWidget]() {
authWidget->updateClient( authWidget->updateClient(
FilePath::fromUserInput( FilePath::fromUserInput(CopilotSettings::instance().nodeJsPath.volatileValue()),
CopilotSettings::instance().nodeJsPath.volatileValue().toString()), FilePath::fromUserInput(CopilotSettings::instance().distPath.volatileValue()));
FilePath::fromUserInput(
CopilotSettings::instance().distPath.volatileValue().toString()));
}; };
connect(CopilotSettings::instance().nodeJsPath.pathChooser(), connect(CopilotSettings::instance().nodeJsPath.pathChooser(),

View File

@@ -142,10 +142,8 @@ void CopilotPlugin::initialize()
requestAction->setEnabled(enabled); requestAction->setEnabled(enabled);
}; };
connect(&CopilotSettings::instance().enableCopilot, connect(&CopilotSettings::instance().enableCopilot, &BaseAspect::changed,
&BoolAspect::valueChanged, this, updateActions);
this,
updateActions);
updateActions(); updateActions();

View File

@@ -92,8 +92,8 @@ CopilotProjectSettings::CopilotProjectSettings(ProjectExplorer::Project *project
QVariantMap map = project->namedSettings(Constants::COPILOT_PROJECT_SETTINGS_ID).toMap(); QVariantMap map = project->namedSettings(Constants::COPILOT_PROJECT_SETTINGS_ID).toMap();
fromMap(map); fromMap(map);
connect(&enableCopilot, &BoolAspect::valueChanged, this, [this, project] { save(project); }); connect(&enableCopilot, &BaseAspect::changed, this, [this, project] { save(project); });
connect(&useGlobalSettings, &BoolAspect::valueChanged, this, [this, project] { save(project); }); connect(&useGlobalSettings, &BaseAspect::changed, this, [this, project] { save(project); });
} }
void CopilotProjectSettings::setUseGlobalSettings(bool useGlobal) void CopilotProjectSettings::setUseGlobalSettings(bool useGlobal)

View File

@@ -32,7 +32,7 @@ public:
setOnApply([&s] { setOnApply([&s] {
const bool originalPostMortem = s.registerForPostMortem->value(); const bool originalPostMortem = s.registerForPostMortem->value();
const bool currentPostMortem = s.registerForPostMortem->volatileValue().toBool(); const bool currentPostMortem = s.registerForPostMortem->volatileValue();
// explicitly trigger setValue() to override the setValueSilently() and trigger the registration // explicitly trigger setValue() to override the setValueSilently() and trigger the registration
if (originalPostMortem != currentPostMortem) if (originalPostMortem != currentPostMortem)
s.registerForPostMortem->setValue(currentPostMortem); s.registerForPostMortem->setValue(currentPostMortem);

View File

@@ -87,8 +87,8 @@ Console::Console()
m_showDebug.setToolTip(Tr::tr("Show debug, log, and info messages.")); m_showDebug.setToolTip(Tr::tr("Show debug, log, and info messages."));
m_showDebug.setValue(true); m_showDebug.setValue(true);
m_showDebug.action()->setIcon(Utils::Icons::INFO_TOOLBAR.icon()); m_showDebug.action()->setIcon(Utils::Icons::INFO_TOOLBAR.icon());
connect(&m_showDebug, &Utils::BoolAspect::valueChanged, connect(&m_showDebug, &Utils::BoolAspect::changed,
proxyModel, &ConsoleProxyModel::setShowLogs); proxyModel, [this, proxyModel] { proxyModel->setShowLogs(m_showDebug()); });
m_showDebugButton->setDefaultAction(m_showDebug.action()); m_showDebugButton->setDefaultAction(m_showDebug.action());
m_showWarningButton = new QToolButton(m_consoleWidget); m_showWarningButton = new QToolButton(m_consoleWidget);
@@ -100,7 +100,7 @@ Console::Console()
m_showWarning.setValue(true); m_showWarning.setValue(true);
m_showWarning.action()->setIcon(Utils::Icons::WARNING_TOOLBAR.icon()); m_showWarning.action()->setIcon(Utils::Icons::WARNING_TOOLBAR.icon());
connect(m_showWarning.action(), &QAction::toggled, connect(m_showWarning.action(), &QAction::toggled,
proxyModel, &ConsoleProxyModel::setShowWarnings); proxyModel, [this, proxyModel] { proxyModel->setShowWarnings(m_showWarning()); });
m_showWarningButton->setDefaultAction(m_showWarning.action()); m_showWarningButton->setDefaultAction(m_showWarning.action());
m_showErrorButton = new QToolButton(m_consoleWidget); m_showErrorButton = new QToolButton(m_consoleWidget);
@@ -112,7 +112,7 @@ Console::Console()
m_showError.setValue(true); m_showError.setValue(true);
m_showError.action()->setIcon(Utils::Icons::CRITICAL_TOOLBAR.icon()); m_showError.action()->setIcon(Utils::Icons::CRITICAL_TOOLBAR.icon());
connect(m_showError.action(), &QAction::toggled, connect(m_showError.action(), &QAction::toggled,
proxyModel, &ConsoleProxyModel::setShowErrors); proxyModel, [this, proxyModel] { proxyModel->setShowErrors(m_showError()); });
m_showErrorButton->setDefaultAction(m_showError.action()); m_showErrorButton->setDefaultAction(m_showError.action());
m_spacer = new QWidget(m_consoleWidget); m_spacer = new QWidget(m_consoleWidget);

View File

@@ -490,8 +490,8 @@ QString DebuggerSettings::dump()
const int pos = key.indexOf('/'); const int pos = key.indexOf('/');
if (pos >= 0) if (pos >= 0)
key = key.mid(pos); key = key.mid(pos);
const QString current = aspect->value().toString(); const QString current = aspect->variantValue().toString();
const QString default_ = aspect->defaultValue().toString(); const QString default_ = aspect->defaultVariantValue().toString();
QString setting = key + ": " + current + " (default: " + default_ + ')'; QString setting = key + ": " + current + " (default: " + default_ + ')';
if (current != default_) if (current != default_)
setting += " ***"; setting += " ***";

View File

@@ -21,7 +21,7 @@ class SourcePathMapAspectPrivate;
// Syntax: (/home/.*)/KnownSubdir -> /home/my/project // Syntax: (/home/.*)/KnownSubdir -> /home/my/project
using SourcePathMap = QMap<QString, QString>; using SourcePathMap = QMap<QString, QString>;
class SourcePathMapAspect : public Utils::BaseAspect class SourcePathMapAspect : public Utils::TypedAspect<SourcePathMap>
{ {
public: public:
SourcePathMapAspect(); SourcePathMapAspect();
@@ -32,15 +32,13 @@ public:
void addToLayout(Layouting::LayoutItem &parent) override; void addToLayout(Layouting::LayoutItem &parent) override;
QVariant volatileValue() const override;
void setVolatileValue(const QVariant &val) override;
void readSettings(const QSettings *settings) override; void readSettings(const QSettings *settings) override;
void writeSettings(QSettings *settings) const override; void writeSettings(QSettings *settings) const override;
SourcePathMap value() const;
private: private:
void guiToInternal() override;
void internalToGui() override;
SourcePathMapAspectPrivate *d = nullptr; SourcePathMapAspectPrivate *d = nullptr;
}; };

View File

@@ -470,29 +470,22 @@ void SourcePathMapAspect::addToLayout(Layouting::LayoutItem &parent)
parent.addItem(d->m_widget.data()); parent.addItem(d->m_widget.data());
} }
QVariant SourcePathMapAspect::volatileValue() const void SourcePathMapAspect::guiToInternal()
{ {
QTC_CHECK(!isAutoApply()); if (d->m_widget)
QTC_ASSERT(d->m_widget, return {}); m_internal = d->m_widget->sourcePathMap();
return QVariant::fromValue(d->m_widget->sourcePathMap());
} }
void SourcePathMapAspect::setVolatileValue(const QVariant &val) void SourcePathMapAspect::internalToGui()
{ {
QTC_CHECK(!isAutoApply());
if (d->m_widget) if (d->m_widget)
d->m_widget->setSourcePathMap(val.value<SourcePathMap>()); d->m_widget->setSourcePathMap(m_internal);
} }
const char sourcePathMappingArrayNameC[] = "SourcePathMappings"; const char sourcePathMappingArrayNameC[] = "SourcePathMappings";
const char sourcePathMappingSourceKeyC[] = "Source"; const char sourcePathMappingSourceKeyC[] = "Source";
const char sourcePathMappingTargetKeyC[] = "Target"; const char sourcePathMappingTargetKeyC[] = "Target";
SourcePathMap SourcePathMapAspect::value() const
{
return BaseAspect::value().value<SourcePathMap>();
}
void SourcePathMapAspect::writeSettings(QSettings *s) const void SourcePathMapAspect::writeSettings(QSettings *s) const
{ {
const SourcePathMap sourcePathMap = value(); const SourcePathMap sourcePathMap = value();
@@ -528,7 +521,7 @@ void SourcePathMapAspect::readSettings(const QSettings *settings)
} }
} }
s->endArray(); s->endArray();
setValue(QVariant::fromValue(sourcePathMap)); setValue(sourcePathMap);
} }
} // Debugger::Internal } // Debugger::Internal

View File

@@ -46,7 +46,7 @@ void RegisterPostMortemAction::registerNow(bool value)
RegisterPostMortemAction::RegisterPostMortemAction() RegisterPostMortemAction::RegisterPostMortemAction()
{ {
connect(this, &BoolAspect::valueChanged, this, &RegisterPostMortemAction::registerNow); connect(this, &BaseAspect::changed, this, [this] { registerNow(value()); });
} }
void RegisterPostMortemAction::readSettings(const QSettings *) void RegisterPostMortemAction::readSettings(const QSettings *)

View File

@@ -28,30 +28,6 @@ using namespace Utils;
namespace FakeVim::Internal { namespace FakeVim::Internal {
#ifdef FAKEVIM_STANDALONE #ifdef FAKEVIM_STANDALONE
FvBaseAspect::FvBaseAspect()
{
}
void FvBaseAspect::setValue(const QVariant &value)
{
m_value = value;
}
QVariant FvBaseAspect::value() const
{
return m_value;
}
void FvBaseAspect::setDefaultValue(const QVariant &value)
{
m_defaultValue = value;
m_value = value;
}
QVariant FvBaseAspect::defaultValue() const
{
return m_defaultValue;
}
void FvBaseAspect::setSettingsKey(const QString &group, const QString &key) void FvBaseAspect::setSettingsKey(const QString &group, const QString &key)
{ {
@@ -294,7 +270,7 @@ QString FakeVimSettings::trySetValue(const QString &name, const QString &value)
return Tr::tr("Argument must be positive: %1=%2") return Tr::tr("Argument must be positive: %1=%2")
.arg(name).arg(value); .arg(name).arg(value);
} }
aspect->setValue(value); aspect->setVariantValue(value);
return QString(); return QString();
} }
@@ -305,7 +281,7 @@ void FakeVimSettings::setup(FvBaseAspect *aspect,
const QString &labelText) const QString &labelText)
{ {
aspect->setSettingsKey("FakeVim", settingsKey); aspect->setSettingsKey("FakeVim", settingsKey);
aspect->setDefaultValue(value); aspect->setDefaultVariantValue(value);
#ifndef FAKEVIM_STANDALONE #ifndef FAKEVIM_STANDALONE
aspect->setLabelText(labelText); aspect->setLabelText(labelText);
aspect->setAutoApply(false); aspect->setAutoApply(false);

View File

@@ -19,13 +19,14 @@ namespace FakeVim::Internal {
class FvBaseAspect class FvBaseAspect
{ {
public: public:
FvBaseAspect(); FvBaseAspect() = default;
virtual ~FvBaseAspect() {} virtual ~FvBaseAspect() = default;
virtual void setVariantValue(const QVariant &value) = 0;
virtual void setDefaultVariantValue(const QVariant &value) = 0;
virtual QVariant variantValue() const = 0;
virtual QVariant defaultVariantValue() const = 0;
void setValue(const QVariant &value);
QVariant value() const;
void setDefaultValue(const QVariant &value);
QVariant defaultValue() const;
void setSettingsKey(const QString &group, const QString &key); void setSettingsKey(const QString &group, const QString &key);
QString settingsKey() const; QString settingsKey() const;
void setCheckable(bool) {} void setCheckable(bool) {}
@@ -33,32 +34,41 @@ public:
void setToolTip(const QString &) {} void setToolTip(const QString &) {}
private: private:
QVariant m_value;
QVariant m_defaultValue;
QString m_settingsGroup; QString m_settingsGroup;
QString m_settingsKey; QString m_settingsKey;
}; };
class FvBoolAspect : public FvBaseAspect template <class ValueType>
class FvTypedAspect : public FvBaseAspect
{ {
public: public:
bool value() const { return FvBaseAspect::value().toBool(); } void setVariantValue(const QVariant &value) override
bool operator()() const { return value(); } {
m_value = value.value<ValueType>();
}
void setDefaultVariantValue(const QVariant &value) override
{
m_defaultValue = value.value<ValueType>();
}
QVariant variantValue() const override
{
return QVariant::fromValue<ValueType>(m_value);
}
QVariant defaultVariantValue() const override
{
return QVariant::fromValue<ValueType>(m_defaultValue);
}
ValueType value() const { return m_value; }
ValueType operator()() const { return m_value; }
ValueType m_value;
ValueType m_defaultValue;
}; };
class FvIntegerAspect : public FvBaseAspect using FvBoolAspect = FvTypedAspect<bool>;
{ using FvIntegerAspect = FvTypedAspect<qint64>;
public: using FvStringAspect = FvTypedAspect<QString>;
qint64 value() const { return FvBaseAspect::value().toLongLong(); }
qint64 operator()() const { return value(); }
};
class FvStringAspect : public FvBaseAspect
{
public:
QString value() const { return FvBaseAspect::value().toString(); }
QString operator()() const { return value(); }
};
class FvAspectContainer : public FvBaseAspect class FvAspectContainer : public FvBaseAspect
{ {

View File

@@ -6139,13 +6139,13 @@ bool FakeVimHandler::Private::handleExSetCommand(const ExCommand &cmd)
FvBaseAspect *act = s.item(optionName); FvBaseAspect *act = s.item(optionName);
if (!act) { if (!act) {
showMessage(MessageError, Tr::tr("Unknown option:") + ' ' + cmd.args); showMessage(MessageError, Tr::tr("Unknown option:") + ' ' + cmd.args);
} else if (act->defaultValue().type() == QVariant::Bool) { } else if (act->defaultVariantValue().type() == QVariant::Bool) {
bool oldValue = act->value().toBool(); bool oldValue = act->variantValue().toBool();
if (printOption) { if (printOption) {
showMessage(MessageInfo, QLatin1String(oldValue ? "" : "no") showMessage(MessageInfo, QLatin1String(oldValue ? "" : "no")
+ act->settingsKey().toLower()); + act->settingsKey().toLower());
} else if (toggleOption || negateOption == oldValue) { } else if (toggleOption || negateOption == oldValue) {
act->setValue(!oldValue); act->setVariantValue(!oldValue);
} }
} else if (negateOption && !printOption) { } else if (negateOption && !printOption) {
showMessage(MessageError, Tr::tr("Invalid argument:") + ' ' + cmd.args); showMessage(MessageError, Tr::tr("Invalid argument:") + ' ' + cmd.args);
@@ -6153,7 +6153,7 @@ bool FakeVimHandler::Private::handleExSetCommand(const ExCommand &cmd)
showMessage(MessageError, Tr::tr("Trailing characters:") + ' ' + cmd.args); showMessage(MessageError, Tr::tr("Trailing characters:") + ' ' + cmd.args);
} else { } else {
showMessage(MessageInfo, act->settingsKey().toLower() + "=" showMessage(MessageInfo, act->settingsKey().toLower() + "="
+ act->value().toString()); + act->variantValue().toString());
} }
} }
updateEditor(); updateEditor();

View File

@@ -1089,16 +1089,16 @@ void FakeVimPluginPrivate::initialize()
this, &FakeVimPluginPrivate::documentRenamed); this, &FakeVimPluginPrivate::documentRenamed);
FakeVimSettings &s = settings(); FakeVimSettings &s = settings();
connect(&s.useFakeVim, &FvBoolAspect::valueChanged, connect(&s.useFakeVim, &FvBoolAspect::changed,
this, &FakeVimPluginPrivate::setUseFakeVim); this, [this, &s] { setUseFakeVim(s.useFakeVim()); });
connect(&s.readVimRc, &FvBaseAspect::changed, connect(&s.readVimRc, &FvBaseAspect::changed,
this, &FakeVimPluginPrivate::maybeReadVimRc); this, &FakeVimPluginPrivate::maybeReadVimRc);
connect(&s.vimRcPath, &FvBaseAspect::changed, connect(&s.vimRcPath, &FvBaseAspect::changed,
this, &FakeVimPluginPrivate::maybeReadVimRc); this, &FakeVimPluginPrivate::maybeReadVimRc);
connect(&s.relativeNumber, &FvBoolAspect::valueChanged, connect(&s.relativeNumber, &FvBoolAspect::changed,
this, &FakeVimPluginPrivate::setShowRelativeLineNumbers); this, [this, &s] { setShowRelativeLineNumbers(s.relativeNumber()); });
connect(&s.blinkingCursor, &FvBoolAspect::valueChanged, connect(&s.blinkingCursor, &FvBoolAspect::changed,
this, &FakeVimPluginPrivate::setCursorBlinking); this, [this, &s] { setCursorBlinking(s.blinkingCursor()); });
// Delayed operations. // Delayed operations.
connect(this, &FakeVimPluginPrivate::delayedQuitRequested, connect(this, &FakeVimPluginPrivate::delayedQuitRequested,

View File

@@ -1466,9 +1466,8 @@ void GitPluginPrivate::setupInstantBlame()
forceInstantBlame(); forceInstantBlame();
}; };
connect(&settings().instantBlame, &BoolAspect::valueChanged, this, connect(&settings().instantBlame, &BaseAspect::changed, this, [this, setupBlameForEditor] {
[this, setupBlameForEditor](bool enabled) { if (settings().instantBlame())
if (enabled)
setupBlameForEditor(EditorManager::currentEditor()); setupBlameForEditor(EditorManager::currentEditor());
else else
stopInstantBlame(); stopInstantBlame();

View File

@@ -146,8 +146,8 @@ GitSettings::GitSettings()
st st
}; };
}); });
connect(&binaryPath, &StringAspect::valueChanged, this, [this] { tryResolve = true; }); connect(&binaryPath, &BaseAspect::changed, this, [this] { tryResolve = true; });
connect(&path, &StringAspect::valueChanged, this, [this] { tryResolve = true; }); connect(&path, &BaseAspect::changed, this, [this] { tryResolve = true; });
} }
FilePath GitSettings::gitExecutable(bool *ok, QString *errorMessage) const FilePath GitSettings::gitExecutable(bool *ok, QString *errorMessage) const

View File

@@ -42,9 +42,10 @@ public:
NimPluginPrivate() NimPluginPrivate()
{ {
Suggest::NimSuggestCache::instance().setExecutablePath(settings.nimSuggestPath.value()); Suggest::NimSuggestCache::instance().setExecutablePath(settings.nimSuggestPath.value());
QObject::connect(&settings.nimSuggestPath, &StringAspect::valueChanged, QObject::connect(&settings.nimSuggestPath, &StringAspect::changed,
&Suggest::NimSuggestCache::instance(), &Suggest::NimSuggestCache::instance(), [this] {
&Suggest::NimSuggestCache::setExecutablePath); Suggest::NimSuggestCache::instance().setExecutablePath(settings.nimSuggestPath.value());
});
} }
NimSettings settings; NimSettings settings;

View File

@@ -109,8 +109,7 @@ PerforceSettings::PerforceSettings()
errorLabel->setType(InfoLabel::Information); errorLabel->setType(InfoLabel::Information);
errorLabel->setText(Tr::tr("Testing...")); errorLabel->setText(Tr::tr("Testing..."));
const FilePath p4Bin = FilePath::fromUserInput( const FilePath p4Bin = FilePath::fromUserInput(p4BinaryPath.volatileValue());
p4BinaryPath.volatileValue().toString());
checker->start(p4Bin, {}, commonP4Arguments_volatile(), 10000); checker->start(p4Bin, {}, commonP4Arguments_volatile(), 10000);
}); });
@@ -166,14 +165,14 @@ QStringList PerforceSettings::commonP4Arguments() const
QStringList PerforceSettings::commonP4Arguments_volatile() const QStringList PerforceSettings::commonP4Arguments_volatile() const
{ {
QStringList lst; QStringList lst;
if (customEnv.volatileValue().toBool()) { if (customEnv.volatileValue()) {
auto p4C = p4Client.volatileValue().toString(); const QString p4C = p4Client.volatileValue();
if (!p4C.isEmpty()) if (!p4C.isEmpty())
lst << "-c" << p4C; lst << "-c" << p4C;
auto p4P = p4Port.volatileValue().toString(); const QString p4P = p4Port.volatileValue();
if (!p4P.isEmpty()) if (!p4P.isEmpty())
lst << "-p" << p4P; lst << "-p" << p4P;
auto p4U = p4User.volatileValue().toString(); const QString p4U = p4User.volatileValue();
if (!p4U.isEmpty()) if (!p4U.isEmpty())
lst << "-u" << p4U; lst << "-u" << p4U;
} }

View File

@@ -58,8 +58,8 @@ PerfSettings::PerfSettings(ProjectExplorer::Target *target)
extraArguments.setLabelText(Tr::tr("Additional arguments:")); extraArguments.setLabelText(Tr::tr("Additional arguments:"));
extraArguments.setSpan(4); extraArguments.setSpan(4);
connect(&callgraphMode, &SelectionAspect::volatileValueChanged, this, [this](int index) { connect(&callgraphMode, &SelectionAspect::volatileValueChanged, this, [this] {
stackSize.setEnabled(index == 0); stackSize.setEnabled(callgraphMode.volatileValue() == 0);
}); });
readGlobalSettings(); readGlobalSettings();

View File

@@ -59,10 +59,12 @@ BuildPropertiesSettings::BuildPropertiesSettings()
qtQuickCompiler.setSettingsKey("ProjectExplorer/Settings/QtQuickCompiler"); qtQuickCompiler.setSettingsKey("ProjectExplorer/Settings/QtQuickCompiler");
qtQuickCompiler.setLabelText(Tr::tr("Use qmlcachegen:")); qtQuickCompiler.setLabelText(Tr::tr("Use qmlcachegen:"));
QObject::connect(&showQtSettings, &BoolAspect::valueChanged, QObject::connect(&showQtSettings, &BaseAspect::changed, &qmlDebugging, [this] {
&qmlDebugging, &BaseAspect::setVisible); qmlDebugging.setVisible(showQtSettings());
QObject::connect(&showQtSettings, &BoolAspect::valueChanged, });
&qtQuickCompiler, &BaseAspect::setVisible); QObject::connect(&showQtSettings, &BaseAspect::changed, &qtQuickCompiler, [this] {
qtQuickCompiler.setVisible(showQtSettings());
});
} }
QString BuildPropertiesSettings::defaultBuildDirectoryTemplate() QString BuildPropertiesSettings::defaultBuildDirectoryTemplate()

View File

@@ -109,8 +109,8 @@ PythonWizardPage::PythonWizardPage(const QList<QPair<QString, QVariant>> &pySide
m_stateLabel->setWordWrap(true); m_stateLabel->setWordWrap(true);
m_stateLabel->setFilled(true); m_stateLabel->setFilled(true);
m_stateLabel->setType(InfoLabel::Error); m_stateLabel->setType(InfoLabel::Error);
connect(&m_venvPath, &StringAspect::valueChanged, this, &PythonWizardPage::updateStateLabel); connect(&m_venvPath, &BaseAspect::changed, this, &PythonWizardPage::updateStateLabel);
connect(&m_createVenv, &BoolAspect::valueChanged, this, &PythonWizardPage::updateStateLabel); connect(&m_createVenv, &BaseAspect::changed, this, &PythonWizardPage::updateStateLabel);
Grid { Grid {
m_pySideVersion, br, m_pySideVersion, br,

View File

@@ -87,7 +87,8 @@ SquishSettings::SquishSettings()
minimizeIDE.setToolTip(Tr::tr("Minimize IDE automatically while running or recording test cases.")); minimizeIDE.setToolTip(Tr::tr("Minimize IDE automatically while running or recording test cases."));
minimizeIDE.setDefaultValue(true); minimizeIDE.setDefaultValue(true);
connect(&local, &BoolAspect::volatileValueChanged, this, [this](bool checked) { connect(&local, &BoolAspect::volatileValueChanged, this, [this] {
const bool checked = local.volatileValue();
serverHost.setEnabled(!checked); serverHost.setEnabled(!checked);
serverPort.setEnabled(!checked); serverPort.setEnabled(!checked);
}); });

View File

@@ -923,13 +923,12 @@ void MemcheckToolPrivate::updateFromSettings()
m_filterProjectAction->setChecked(!m_settings->filterExternalIssues()); m_filterProjectAction->setChecked(!m_settings->filterExternalIssues());
m_errorView->settingsChanged(m_settings); m_errorView->settingsChanged(m_settings);
connect(&m_settings->visibleErrorKinds, &IntegersAspect::valueChanged, connect(&m_settings->visibleErrorKinds, &BaseAspect::changed, &m_errorProxyModel, [this] {
&m_errorProxyModel, &MemcheckErrorFilterProxyModel::setAcceptedKinds); m_errorProxyModel.setAcceptedKinds(m_settings->visibleErrorKinds());
m_errorProxyModel.setAcceptedKinds(m_settings->visibleErrorKinds()); });
connect(&m_settings->filterExternalIssues, &BaseAspect::changed, &m_errorProxyModel, [this] {
connect(&m_settings->filterExternalIssues, &BoolAspect::valueChanged, m_errorProxyModel.setFilterExternalIssues(m_settings->filterExternalIssues());
&m_errorProxyModel, &MemcheckErrorFilterProxyModel::setFilterExternalIssues); });
m_errorProxyModel.setFilterExternalIssues(m_settings->filterExternalIssues());
} }
void MemcheckToolPrivate::maybeActiveRunConfigurationChanged() void MemcheckToolPrivate::maybeActiveRunConfigurationChanged()

View File

@@ -108,7 +108,7 @@ void SuppressionAspectPrivate::slotSuppressionSelectionChanged()
// //
SuppressionAspect::SuppressionAspect(AspectContainer *container, bool global) SuppressionAspect::SuppressionAspect(AspectContainer *container, bool global)
: BaseAspect(container) : TypedAspect(container)
{ {
d = new SuppressionAspectPrivate(this, global); d = new SuppressionAspectPrivate(this, global);
setSettingsKey("Analyzer.Valgrind.SuppressionFiles"); setSettingsKey("Analyzer.Valgrind.SuppressionFiles");
@@ -119,16 +119,6 @@ SuppressionAspect::~SuppressionAspect()
delete d; delete d;
} }
FilePaths SuppressionAspect::value() const
{
return FileUtils::toFilePathList(BaseAspect::value().toStringList());
}
void SuppressionAspect::setValue(const FilePaths &val)
{
BaseAspect::setValue(Utils::transform<QStringList>(val, &FilePath::toString));
}
void SuppressionAspect::addToLayout(Layouting::LayoutItem &parent) void SuppressionAspect::addToLayout(Layouting::LayoutItem &parent)
{ {
QTC_CHECK(!d->addEntry); QTC_CHECK(!d->addEntry);
@@ -157,8 +147,6 @@ void SuppressionAspect::addToLayout(Layouting::LayoutItem &parent)
Column { d->addEntry.data(), d->removeEntry.data(), st } Column { d->addEntry.data(), d->removeEntry.data(), st }
}; };
parent.addItem(Span { 2, group }); parent.addItem(Span { 2, group });
setVolatileValue(BaseAspect::value());
} }
void SuppressionAspect::fromMap(const QVariantMap &map) void SuppressionAspect::fromMap(const QVariantMap &map)
@@ -171,22 +159,18 @@ void SuppressionAspect::toMap(QVariantMap &map) const
BaseAspect::toMap(map); BaseAspect::toMap(map);
} }
QVariant SuppressionAspect::volatileValue() const void SuppressionAspect::guiToInternal()
{ {
QStringList ret; m_internal.clear();
for (int i = 0; i < d->m_model.rowCount(); ++i) for (int i = 0; i < d->m_model.rowCount(); ++i)
ret << d->m_model.item(i)->text(); m_internal.append(FilePath::fromUserInput(d->m_model.item(i)->text()));
return ret;
} }
void SuppressionAspect::setVolatileValue(const QVariant &val) void SuppressionAspect::internalToGui()
{ {
const QStringList files = val.toStringList();
d->m_model.clear(); d->m_model.clear();
for (const QString &file : files) for (const FilePath &file : m_internal)
d->m_model.appendRow(new QStandardItem(file)); d->m_model.appendRow(new QStandardItem(file.toUserOutput()));
} }
////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////
@@ -388,7 +372,7 @@ QVariantMap ValgrindBaseSettings::defaultSettings() const
{ {
QVariantMap defaults; QVariantMap defaults;
forEachAspect([&defaults](BaseAspect *aspect) { forEachAspect([&defaults](BaseAspect *aspect) {
defaults.insert(aspect->settingsKey(), aspect->defaultValue()); defaults.insert(aspect->settingsKey(), aspect->defaultVariantValue());
}); });
return defaults; return defaults;
} }

View File

@@ -12,7 +12,7 @@ const char ANALYZER_VALGRIND_SETTINGS[] = "Analyzer.Valgrind.Settings";
class SuppressionAspectPrivate; class SuppressionAspectPrivate;
class SuppressionAspect final : public Utils::BaseAspect class SuppressionAspect final : public Utils::TypedAspect<Utils::FilePaths>
{ {
Q_OBJECT Q_OBJECT
@@ -20,21 +20,17 @@ public:
SuppressionAspect(Utils::AspectContainer *container, bool global); SuppressionAspect(Utils::AspectContainer *container, bool global);
~SuppressionAspect() final; ~SuppressionAspect() final;
Utils::FilePaths operator()() const { return value(); }
Utils::FilePaths value() const;
void setValue(const Utils::FilePaths &val);
void addToLayout(Layouting::LayoutItem &parent) final; void addToLayout(Layouting::LayoutItem &parent) final;
void fromMap(const QVariantMap &map) final; void fromMap(const QVariantMap &map) final;
void toMap(QVariantMap &map) const final; void toMap(QVariantMap &map) const final;
QVariant volatileValue() const final;
void setVolatileValue(const QVariant &val) final;
void addSuppressionFile(const Utils::FilePath &suppressionFile); void addSuppressionFile(const Utils::FilePath &suppressionFile);
private: private:
void internalToGui() override;
void guiToInternal() override;
friend class ValgrindBaseSettings; friend class ValgrindBaseSettings;
SuppressionAspectPrivate *d = nullptr; SuppressionAspectPrivate *d = nullptr;
}; };