forked from qt-creator/qt-creator
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:
@@ -40,8 +40,6 @@ class BaseAspectPrivate
|
||||
{
|
||||
public:
|
||||
Id m_id;
|
||||
QVariant m_value;
|
||||
QVariant m_defaultValue;
|
||||
std::function<QVariant(const QVariant &)> m_toSettings;
|
||||
std::function<QVariant(const QVariant &)> m_fromSettings;
|
||||
|
||||
@@ -99,7 +97,7 @@ BaseAspect::BaseAspect(AspectContainer *container)
|
||||
{
|
||||
if (container)
|
||||
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;
|
||||
}
|
||||
|
||||
QVariant BaseAspect::value() const
|
||||
QVariant BaseAspect::variantValue() const
|
||||
{
|
||||
return d->m_value;
|
||||
return {};
|
||||
}
|
||||
|
||||
/*!
|
||||
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)) {
|
||||
emit changed();
|
||||
emitChangedValue();
|
||||
Q_UNUSED(value)
|
||||
QTC_CHECK(false);
|
||||
}
|
||||
|
||||
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)
|
||||
return false;
|
||||
d->m_value = value;
|
||||
return true;
|
||||
Q_UNUSED(value)
|
||||
QTC_CHECK(false);
|
||||
}
|
||||
|
||||
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.
|
||||
|
||||
\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.
|
||||
*/
|
||||
void BaseAspect::setDefaultValue(const QVariant &value)
|
||||
{
|
||||
d->m_defaultValue = value;
|
||||
d->m_value = value;
|
||||
}
|
||||
|
||||
void BaseAspect::setDisplayName(const QString &displayName)
|
||||
{
|
||||
@@ -308,8 +307,12 @@ void BaseAspect::setEnabler(BoolAspect *checker)
|
||||
{
|
||||
QTC_ASSERT(checker, return);
|
||||
setEnabled(checker->value());
|
||||
connect(checker, &BoolAspect::volatileValueChanged, this, &BaseAspect::setEnabled);
|
||||
connect(checker, &BoolAspect::valueChanged, this, &BaseAspect::setEnabled);
|
||||
connect(checker, &BoolAspect::volatileValueChanged, this, [this, checker] {
|
||||
BaseAspect::setEnabled(checker->volatileValue());
|
||||
});
|
||||
connect(checker, &BoolAspect::changed, this, [this, checker] {
|
||||
BaseAspect::setEnabled(checker->volatileValue());
|
||||
});
|
||||
}
|
||||
|
||||
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.
|
||||
|
||||
This has only an effect if \c isAutoApply is false.
|
||||
Emits changed() if the value changed.
|
||||
*/
|
||||
void BaseAspect::apply()
|
||||
{
|
||||
QTC_CHECK(!d->m_autoApply);
|
||||
if (isDirty())
|
||||
setValue(volatileValue());
|
||||
if (silentApply()) {
|
||||
if (hasAction())
|
||||
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
|
||||
aspect's value.
|
||||
@@ -459,9 +475,8 @@ void BaseAspect::apply()
|
||||
*/
|
||||
void BaseAspect::cancel()
|
||||
{
|
||||
QTC_CHECK(!d->m_autoApply);
|
||||
if (!d->m_subWidgets.isEmpty())
|
||||
setVolatileValue(d->m_value);
|
||||
externalToInternal();
|
||||
internalToGui();
|
||||
}
|
||||
|
||||
void BaseAspect::finish()
|
||||
@@ -476,24 +491,9 @@ bool BaseAspect::hasAction() const
|
||||
return d->m_action != nullptr;
|
||||
}
|
||||
|
||||
bool BaseAspect::isDirty() const
|
||||
bool BaseAspect::isDirty()
|
||||
{
|
||||
QTC_CHECK(!isAutoApply());
|
||||
// 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)
|
||||
@@ -534,8 +534,10 @@ void BaseAspect::saveToMap(QVariantMap &data, const QVariant &value,
|
||||
*/
|
||||
void BaseAspect::fromMap(const QVariantMap &map)
|
||||
{
|
||||
const QVariant val = map.value(settingsKey(), toSettingsValue(defaultValue()));
|
||||
setValue(fromSettingsValue(val));
|
||||
if (settingsKey().isEmpty())
|
||||
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
|
||||
{
|
||||
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)
|
||||
@@ -551,7 +555,7 @@ void BaseAspect::readSettings(const QSettings *settings)
|
||||
if (settingsKey().isEmpty())
|
||||
return;
|
||||
const QVariant &val = settings->value(settingsKey());
|
||||
setValue(val.isValid() ? fromSettingsValue(val) : defaultValue());
|
||||
setVariantValue(val.isValid() ? fromSettingsValue(val) : defaultVariantValue());
|
||||
}
|
||||
|
||||
void BaseAspect::writeSettings(QSettings *settings) const
|
||||
@@ -560,8 +564,8 @@ void BaseAspect::writeSettings(QSettings *settings) const
|
||||
return;
|
||||
QtcSettings::setValueWithDefault(settings,
|
||||
settingsKey(),
|
||||
toSettingsValue(value()),
|
||||
toSettingsValue(defaultValue()));
|
||||
toSettingsValue(variantValue()),
|
||||
toSettingsValue(defaultVariantValue()));
|
||||
}
|
||||
|
||||
void BaseAspect::setFromSettingsTransformation(const SavedValueTransformation &transform)
|
||||
@@ -773,9 +777,8 @@ public:
|
||||
*/
|
||||
|
||||
StringAspect::StringAspect(AspectContainer *container)
|
||||
: BaseAspect(container), d(new Internal::StringAspectPrivate)
|
||||
: TypedAspect(container), d(new Internal::StringAspectPrivate)
|
||||
{
|
||||
setDefaultValue(QString());
|
||||
setSpan(2, 1); // Default: Label + something
|
||||
|
||||
addDataExtractor(this, &StringAspect::value, &Data::value);
|
||||
@@ -800,7 +803,7 @@ void StringAspect::setValueAcceptor(StringAspect::ValueAcceptor &&acceptor)
|
||||
*/
|
||||
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) {
|
||||
const std::optional<QString> tmp = d->m_valueAcceptor(value(), val);
|
||||
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;
|
||||
}
|
||||
processedValue = tmp.value();
|
||||
}
|
||||
|
||||
if (BaseAspect::setValueQuietly(QVariant(processedValue))) {
|
||||
update();
|
||||
emit changed();
|
||||
emit valueChanged(processedValue);
|
||||
}
|
||||
}
|
||||
|
||||
QString StringAspect::defaultValue() const
|
||||
{
|
||||
return BaseAspect::defaultValue().toString();
|
||||
}
|
||||
|
||||
void StringAspect::setDefaultValue(const QString &val)
|
||||
{
|
||||
BaseAspect::setDefaultValue(val);
|
||||
TypedAspect::setValue(processedValue);
|
||||
}
|
||||
|
||||
/*!
|
||||
@@ -845,7 +834,7 @@ void StringAspect::setDefaultValue(const QString &val)
|
||||
void StringAspect::fromMap(const QVariantMap &map)
|
||||
{
|
||||
if (!settingsKey().isEmpty())
|
||||
BaseAspect::setValueQuietly(map.value(settingsKey(), defaultValue()));
|
||||
setValueQuietly(map.value(settingsKey(), defaultValue()).toString());
|
||||
if (d->m_checker)
|
||||
d->m_checker->fromMap(map);
|
||||
}
|
||||
@@ -900,7 +889,7 @@ PathChooser *StringAspect::pathChooser() const
|
||||
void StringAspect::setShowToolTipOnLabel(bool show)
|
||||
{
|
||||
d->m_showToolTipOnLabel = show;
|
||||
update();
|
||||
internalToGui();
|
||||
}
|
||||
|
||||
/*!
|
||||
@@ -1246,79 +1235,48 @@ void StringAspect::addToLayout(LayoutItem &parent)
|
||||
d->m_checker->addToLayout(parent);
|
||||
}
|
||||
|
||||
QVariant StringAspect::volatileValue() const
|
||||
{
|
||||
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)
|
||||
void StringAspect::guiToInternal()
|
||||
{
|
||||
switch (d->m_displayStyle) {
|
||||
case PathChooserDisplay:
|
||||
if (d->m_pathChooserDisplay)
|
||||
d->m_pathChooserDisplay->setFilePath(FilePath::fromVariant(val));
|
||||
m_internal = d->m_pathChooserDisplay->lineEdit()->text();
|
||||
break;
|
||||
case LineEditDisplay:
|
||||
if (d->m_lineEditDisplay)
|
||||
d->m_lineEditDisplay->setText(val.toString());
|
||||
m_internal = d->m_lineEditDisplay->text();
|
||||
break;
|
||||
case TextEditDisplay:
|
||||
if (d->m_textEditDisplay)
|
||||
d->m_textEditDisplay->document()->setPlainText(val.toString());
|
||||
break;
|
||||
m_internal = d->m_textEditDisplay->document()->toPlainText();
|
||||
case LabelDisplay:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void StringAspect::emitChangedValue()
|
||||
void StringAspect::internalToGui()
|
||||
{
|
||||
emit valueChanged(value());
|
||||
}
|
||||
|
||||
void StringAspect::update()
|
||||
{
|
||||
const QString displayedString = d->m_displayFilter ? d->m_displayFilter(value()) : value();
|
||||
|
||||
const QString displayed = d->m_displayFilter ? d->m_displayFilter(m_internal) : m_internal;
|
||||
if (d->m_pathChooserDisplay) {
|
||||
d->m_pathChooserDisplay->setFilePath(FilePath::fromUserInput(displayedString));
|
||||
d->m_pathChooserDisplay->lineEdit()->setText(displayed);
|
||||
d->updateWidgetFromCheckStatus(this, d->m_pathChooserDisplay.data());
|
||||
}
|
||||
|
||||
if (d->m_lineEditDisplay) {
|
||||
d->m_lineEditDisplay->setTextKeepingActiveCursor(displayedString);
|
||||
d->m_lineEditDisplay->setTextKeepingActiveCursor(displayed);
|
||||
d->updateWidgetFromCheckStatus(this, d->m_lineEditDisplay.data());
|
||||
}
|
||||
|
||||
if (d->m_textEditDisplay) {
|
||||
const QString old = d->m_textEditDisplay->document()->toPlainText();
|
||||
if (displayedString != old)
|
||||
d->m_textEditDisplay->setText(displayedString);
|
||||
if (displayed != old)
|
||||
d->m_textEditDisplay->setText(displayed);
|
||||
d->updateWidgetFromCheckStatus(this, d->m_textEditDisplay.data());
|
||||
}
|
||||
|
||||
if (d->m_labelDisplay) {
|
||||
d->m_labelDisplay->setText(displayedString);
|
||||
d->m_labelDisplay->setToolTip(d->m_showToolTipOnLabel ? displayedString : toolTip());
|
||||
d->m_labelDisplay->setText(displayed);
|
||||
d->m_labelDisplay->setToolTip(d->m_showToolTipOnLabel ? displayed : toolTip());
|
||||
}
|
||||
|
||||
validateInput();
|
||||
@@ -1342,11 +1300,11 @@ void StringAspect::makeCheckable(CheckBoxPlacement checkBoxPlacement,
|
||||
: BoolAspect::LabelPlacement::AtCheckBox);
|
||||
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::checkedChanged);
|
||||
|
||||
update();
|
||||
internalToGui();
|
||||
}
|
||||
|
||||
|
||||
@@ -1384,12 +1342,10 @@ FilePathAspect::FilePathAspect(AspectContainer *container)
|
||||
*/
|
||||
|
||||
ColorAspect::ColorAspect(AspectContainer *container)
|
||||
: BaseAspect(container), d(new Internal::ColorAspectPrivate)
|
||||
: TypedAspect(container), d(new Internal::ColorAspectPrivate)
|
||||
{
|
||||
setDefaultValue(QColor::fromRgb(0, 0, 0));
|
||||
setSpan(1, 1);
|
||||
|
||||
addDataExtractor(this, &ColorAspect::value, &Data::value);
|
||||
}
|
||||
|
||||
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)
|
||||
return d->m_colorButton->color();
|
||||
QTC_CHECK(false);
|
||||
return {};
|
||||
m_internal = d->m_colorButton->color();
|
||||
}
|
||||
|
||||
void ColorAspect::setVolatileValue(const QVariant &val)
|
||||
void ColorAspect::guiToInternal()
|
||||
{
|
||||
QTC_CHECK(!isAutoApply());
|
||||
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)
|
||||
: BaseAspect(container), d(new Internal::BoolAspectPrivate)
|
||||
: TypedAspect(container), d(new Internal::BoolAspectPrivate)
|
||||
{
|
||||
setDefaultValue(false);
|
||||
setSpan(2, 1);
|
||||
|
||||
addDataExtractor(this, &BoolAspect::value, &Data::value);
|
||||
}
|
||||
|
||||
/*!
|
||||
@@ -1520,8 +1459,8 @@ std::function<void (QObject *)> BoolAspect::groupChecker()
|
||||
QAction *BoolAspect::action()
|
||||
{
|
||||
if (hasAction())
|
||||
return BaseAspect::action();
|
||||
auto act = BaseAspect::action(); // Creates it.
|
||||
return TypedAspect::action();
|
||||
auto act = TypedAspect::action(); // Creates it.
|
||||
act->setCheckable(true);
|
||||
act->setChecked(value());
|
||||
act->setToolTip(toolTip());
|
||||
@@ -1531,74 +1470,32 @@ QAction *BoolAspect::action()
|
||||
// in a menu like "Use FakeVim", isAutoApply() is false, and yet this
|
||||
// here can trigger.
|
||||
//QTC_CHECK(isAutoApply());
|
||||
setValue(newValue);
|
||||
m_external = newValue;
|
||||
externalToInternal();
|
||||
internalToGui();
|
||||
});
|
||||
return act;
|
||||
}
|
||||
|
||||
QVariant BoolAspect::volatileValue() const
|
||||
void BoolAspect::guiToInternal()
|
||||
{
|
||||
if (d->m_button)
|
||||
return 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());
|
||||
m_internal = d->m_button->isChecked();
|
||||
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());
|
||||
}
|
||||
|
||||
|
||||
/*!
|
||||
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);
|
||||
d->m_button->setChecked(m_internal);
|
||||
else if (d->m_groupBox)
|
||||
d->m_groupBox->setChecked(m_internal);
|
||||
}
|
||||
|
||||
void BoolAspect::setLabel(const QString &labelText, LabelPlacement labelPlacement)
|
||||
{
|
||||
BaseAspect::setLabelText(labelText);
|
||||
TypedAspect::setLabelText(labelText);
|
||||
d->m_labelPlacement = labelPlacement;
|
||||
}
|
||||
|
||||
@@ -1627,7 +1524,7 @@ CheckableDecider BoolAspect::checkableDecider()
|
||||
*/
|
||||
|
||||
SelectionAspect::SelectionAspect(AspectContainer *container)
|
||||
: BaseAspect(container), d(new Internal::SelectionAspectPrivate)
|
||||
: TypedAspect(container), d(new Internal::SelectionAspectPrivate)
|
||||
{
|
||||
setSpan(2, 1);
|
||||
}
|
||||
@@ -1683,25 +1580,26 @@ void SelectionAspect::addToLayout(Layouting::LayoutItem &parent)
|
||||
}
|
||||
}
|
||||
|
||||
QVariant SelectionAspect::volatileValue() const
|
||||
void SelectionAspect::guiToInternal()
|
||||
{
|
||||
switch (d->m_displayStyle) {
|
||||
case DisplayStyle::RadioButtons:
|
||||
QTC_ASSERT(d->m_buttonGroup, return {});
|
||||
return d->m_buttonGroup->checkedId();
|
||||
if (d->m_buttonGroup)
|
||||
m_internal = d->m_buttonGroup->checkedId();
|
||||
break;
|
||||
case DisplayStyle::ComboBox:
|
||||
QTC_ASSERT(d->m_comboBox, return {});
|
||||
return d->m_comboBox->currentIndex();
|
||||
if (d->m_comboBox)
|
||||
m_internal = d->m_comboBox->currentIndex();
|
||||
break;
|
||||
}
|
||||
return {};
|
||||
}
|
||||
|
||||
void SelectionAspect::setVolatileValue(const QVariant &val)
|
||||
void SelectionAspect::internalToGui()
|
||||
{
|
||||
switch (d->m_displayStyle) {
|
||||
case DisplayStyle::RadioButtons: {
|
||||
if (d->m_buttonGroup) {
|
||||
QAbstractButton *button = d->m_buttonGroup->button(val.toInt());
|
||||
QAbstractButton *button = d->m_buttonGroup->button(m_internal);
|
||||
QTC_ASSERT(button, return);
|
||||
button->setChecked(true);
|
||||
}
|
||||
@@ -1709,7 +1607,7 @@ void SelectionAspect::setVolatileValue(const QVariant &val)
|
||||
}
|
||||
case DisplayStyle::ComboBox:
|
||||
if (d->m_comboBox)
|
||||
d->m_comboBox->setCurrentIndex(val.toInt());
|
||||
d->m_comboBox->setCurrentIndex(m_internal);
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -1727,22 +1625,6 @@ void SelectionAspect::setDisplayStyle(SelectionAspect::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)
|
||||
{
|
||||
const int index = indexForDisplay(val);
|
||||
@@ -1750,20 +1632,15 @@ void SelectionAspect::setStringValue(const QString &val)
|
||||
setValue(index);
|
||||
}
|
||||
|
||||
int SelectionAspect::defaultValue() const
|
||||
{
|
||||
return BaseAspect::defaultValue().toInt();
|
||||
}
|
||||
|
||||
void SelectionAspect::setDefaultValue(int val)
|
||||
{
|
||||
BaseAspect::setDefaultValue(val);
|
||||
TypedAspect::setDefaultValue(val);
|
||||
}
|
||||
|
||||
// Note: This needs to be set after all options are added.
|
||||
void SelectionAspect::setDefaultValue(const QString &val)
|
||||
{
|
||||
BaseAspect::setDefaultValue(indexForDisplay(val));
|
||||
TypedAspect::setDefaultValue(indexForDisplay(val));
|
||||
}
|
||||
|
||||
QString SelectionAspect::stringValue() const
|
||||
@@ -1830,7 +1707,7 @@ QVariant SelectionAspect::itemValueForIndex(int index) const
|
||||
*/
|
||||
|
||||
MultiSelectionAspect::MultiSelectionAspect(AspectContainer *container)
|
||||
: BaseAspect(container), d(new Internal::MultiSelectionAspectPrivate(this))
|
||||
: TypedAspect(container), d(new Internal::MultiSelectionAspectPrivate(this))
|
||||
{
|
||||
setDefaultValue(QStringList());
|
||||
setSpan(2, 1);
|
||||
@@ -1898,23 +1775,27 @@ void MultiSelectionAspect::setDisplayStyle(MultiSelectionAspect::DisplayStyle st
|
||||
d->m_displayStyle = style;
|
||||
}
|
||||
|
||||
QStringList MultiSelectionAspect::value() const
|
||||
void MultiSelectionAspect::internalToGui()
|
||||
{
|
||||
return BaseAspect::value().toStringList();
|
||||
}
|
||||
|
||||
void MultiSelectionAspect::setValue(const QStringList &value)
|
||||
{
|
||||
if (BaseAspect::setValueQuietly(value)) {
|
||||
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(value.contains(item->text()) ? Qt::Checked : Qt::Unchecked);
|
||||
item->setCheckState(m_internal.contains(item->text()) ? Qt::Checked : Qt::Unchecked);
|
||||
}
|
||||
} else {
|
||||
emit changed();
|
||||
}
|
||||
}
|
||||
|
||||
void MultiSelectionAspect::guiToInternal()
|
||||
{
|
||||
if (d->m_listView) {
|
||||
m_internal.clear();
|
||||
for (const QString &val : std::as_const(d->m_allValues)) {
|
||||
auto item = new QListWidgetItem(val, d->m_listView);
|
||||
item->setFlags(item->flags() | Qt::ItemIsUserCheckable);
|
||||
if (item->checkState() == Qt::Checked)
|
||||
m_internal.append(item->text());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1937,12 +1818,9 @@ void MultiSelectionAspect::setValue(const QStringList &value)
|
||||
// IntegerAspect
|
||||
|
||||
IntegerAspect::IntegerAspect(AspectContainer *container)
|
||||
: BaseAspect(container), d(new Internal::IntegerAspectPrivate)
|
||||
: TypedAspect(container), d(new Internal::IntegerAspectPrivate)
|
||||
{
|
||||
setDefaultValue(qint64(0));
|
||||
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)
|
||||
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();
|
||||
}
|
||||
|
||||
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();
|
||||
d->m_spinBox->setValue(m_internal / d->m_displayScaleFactor);
|
||||
}
|
||||
|
||||
void IntegerAspect::setRange(qint64 min, qint64 max)
|
||||
@@ -2042,11 +1895,6 @@ void IntegerAspect::setDisplayScaleFactor(qint64 factor)
|
||||
d->m_displayScaleFactor = factor;
|
||||
}
|
||||
|
||||
void IntegerAspect::setDefaultValue(qint64 defaultValue)
|
||||
{
|
||||
BaseAspect::setDefaultValue(defaultValue);
|
||||
}
|
||||
|
||||
void IntegerAspect::setSpecialValueText(const QString &specialText)
|
||||
{
|
||||
d->m_specialValueText = specialText;
|
||||
@@ -2073,7 +1921,7 @@ void IntegerAspect::setSingleStep(qint64 step)
|
||||
*/
|
||||
|
||||
DoubleAspect::DoubleAspect(AspectContainer *container)
|
||||
: BaseAspect(container), d(new Internal::DoubleAspectPrivate)
|
||||
: TypedAspect(container), d(new Internal::DoubleAspectPrivate)
|
||||
{
|
||||
setDefaultValue(double(0));
|
||||
setSpan(2, 1);
|
||||
@@ -2097,7 +1945,7 @@ void DoubleAspect::addToLayout(LayoutItem &builder)
|
||||
d->m_spinBox->setSpecialValueText(d->m_specialValueText);
|
||||
if (d->m_maximumValue && d->m_maximumValue)
|
||||
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);
|
||||
|
||||
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)
|
||||
d->m_spinBox->setValue(val.toDouble());
|
||||
m_internal = d->m_spinBox->value();
|
||||
}
|
||||
|
||||
double DoubleAspect::value() const
|
||||
void DoubleAspect::internalToGui()
|
||||
{
|
||||
return BaseAspect::value().toDouble();
|
||||
}
|
||||
|
||||
void DoubleAspect::setValue(double value)
|
||||
{
|
||||
BaseAspect::setValue(value);
|
||||
}
|
||||
|
||||
double DoubleAspect::defaultValue() const
|
||||
{
|
||||
return BaseAspect::defaultValue().toDouble();
|
||||
if (d->m_spinBox)
|
||||
d->m_spinBox->setValue(m_internal);
|
||||
}
|
||||
|
||||
void DoubleAspect::setRange(double min, double max)
|
||||
@@ -2151,11 +1982,6 @@ void DoubleAspect::setSuffix(const QString &suffix)
|
||||
d->m_suffix = suffix;
|
||||
}
|
||||
|
||||
void DoubleAspect::setDefaultValue(double defaultValue)
|
||||
{
|
||||
BaseAspect::setDefaultValue(defaultValue);
|
||||
}
|
||||
|
||||
void DoubleAspect::setSpecialValueText(const QString &specialText)
|
||||
{
|
||||
d->m_specialValueText = specialText;
|
||||
@@ -2192,7 +2018,7 @@ TriStateAspect::TriStateAspect(AspectContainer *container,
|
||||
|
||||
TriState TriStateAspect::value() const
|
||||
{
|
||||
return TriState::fromVariant(BaseAspect::value());
|
||||
return TriState::fromInt(SelectionAspect::value());
|
||||
}
|
||||
|
||||
void TriStateAspect::setValue(TriState value)
|
||||
@@ -2202,12 +2028,12 @@ void TriStateAspect::setValue(TriState value)
|
||||
|
||||
TriState TriStateAspect::defaultValue() const
|
||||
{
|
||||
return TriState::fromVariant(BaseAspect::defaultValue());
|
||||
return TriState::fromInt(SelectionAspect::defaultValue());
|
||||
}
|
||||
|
||||
void TriStateAspect::setDefaultValue(TriState value)
|
||||
{
|
||||
BaseAspect::setDefaultValue(value.toVariant());
|
||||
SelectionAspect::setDefaultValue(value.toInt());
|
||||
}
|
||||
|
||||
const TriState TriState::Enabled{TriState::EnabledValue};
|
||||
@@ -2216,7 +2042,11 @@ const TriState TriState::Default{TriState::DefaultValue};
|
||||
|
||||
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);
|
||||
return TriState(Value(v));
|
||||
}
|
||||
@@ -2231,7 +2061,7 @@ TriState TriState::fromVariant(const QVariant &variant)
|
||||
*/
|
||||
|
||||
StringListAspect::StringListAspect(AspectContainer *container)
|
||||
: BaseAspect(container), d(new Internal::StringListAspectPrivate)
|
||||
: TypedAspect(container), d(new Internal::StringListAspectPrivate)
|
||||
{
|
||||
setDefaultValue(QStringList());
|
||||
}
|
||||
@@ -2250,16 +2080,6 @@ void StringListAspect::addToLayout(LayoutItem &parent)
|
||||
// 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)
|
||||
{
|
||||
QStringList val = value();
|
||||
@@ -2303,10 +2123,8 @@ void StringListAspect::removeValues(const QStringList &values)
|
||||
*/
|
||||
|
||||
IntegersAspect::IntegersAspect(AspectContainer *container)
|
||||
: BaseAspect(container)
|
||||
{
|
||||
setDefaultValue({});
|
||||
}
|
||||
: TypedAspect(container)
|
||||
{}
|
||||
|
||||
/*!
|
||||
\internal
|
||||
@@ -2322,33 +2140,6 @@ void IntegersAspect::addToLayout(Layouting::LayoutItem &parent)
|
||||
// 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
|
||||
@@ -2576,7 +2367,7 @@ void AspectContainer::finish()
|
||||
void AspectContainer::reset()
|
||||
{
|
||||
for (BaseAspect *aspect : std::as_const(d->m_items))
|
||||
aspect->setValueQuietly(aspect->defaultValue());
|
||||
aspect->setVariantValueQuietly(aspect->defaultVariantValue());
|
||||
}
|
||||
|
||||
void AspectContainer::setAutoApply(bool on)
|
||||
@@ -2633,6 +2424,41 @@ BaseAspect::Data::Ptr BaseAspect::extractData() const
|
||||
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
|
||||
{
|
||||
d->m_dataExtractors.append(extractor);
|
||||
|
@@ -51,12 +51,12 @@ public:
|
||||
Id id() const;
|
||||
void setId(Id id);
|
||||
|
||||
QVariant value() const;
|
||||
void setValue(const QVariant &value);
|
||||
bool setValueQuietly(const QVariant &value);
|
||||
virtual QVariant variantValue() const;
|
||||
virtual void setVariantValue(const QVariant &value);
|
||||
virtual void setVariantValueQuietly(const QVariant &value);
|
||||
|
||||
QVariant defaultValue() const;
|
||||
void setDefaultValue(const QVariant &value);
|
||||
virtual QVariant defaultVariantValue() const;
|
||||
virtual void setDefaultVariantValue(const QVariant &value);
|
||||
|
||||
QString settingsKey() const;
|
||||
void setSettingsKey(const QString &settingsKey);
|
||||
@@ -100,10 +100,6 @@ public:
|
||||
|
||||
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 writeSettings(QSettings *settings) const;
|
||||
|
||||
@@ -114,9 +110,10 @@ public:
|
||||
QVariant fromSettingsValue(const QVariant &val) const;
|
||||
|
||||
virtual void apply();
|
||||
virtual bool silentApply();
|
||||
virtual void cancel();
|
||||
virtual void finish();
|
||||
virtual bool isDirty() const;
|
||||
virtual bool isDirty();
|
||||
bool hasAction() const;
|
||||
|
||||
class QTCREATOR_UTILS_EXPORT Data
|
||||
@@ -164,9 +161,15 @@ public:
|
||||
|
||||
signals:
|
||||
void changed();
|
||||
void volatileValueChanged();
|
||||
void labelLinkActivated(const QString &link);
|
||||
|
||||
protected:
|
||||
virtual void internalToGui();
|
||||
virtual void guiToInternal();
|
||||
virtual bool internalToExternal();
|
||||
virtual void externalToInternal();
|
||||
|
||||
QLabel *label() const;
|
||||
void setupLabel();
|
||||
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);
|
||||
|
||||
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
|
||||
|
||||
@@ -216,27 +324,12 @@ public:
|
||||
BoolAspect(AspectContainer *container = nullptr);
|
||||
~BoolAspect() override;
|
||||
|
||||
struct Data : BaseAspect::Data
|
||||
{
|
||||
bool value;
|
||||
};
|
||||
|
||||
void addToLayout(Layouting::LayoutItem &parent) override;
|
||||
std::function<void(QObject *)> groupChecker();
|
||||
Utils::CheckableDecider checkableDecider();
|
||||
|
||||
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 };
|
||||
void setLabel(const QString &labelText,
|
||||
LabelPlacement labelPlacement = LabelPlacement::InExtraLabel);
|
||||
@@ -244,15 +337,14 @@ public:
|
||||
|
||||
void adoptButton(QAbstractButton *button);
|
||||
|
||||
signals:
|
||||
void valueChanged(bool newValue);
|
||||
void volatileValueChanged(bool newValue);
|
||||
|
||||
private:
|
||||
void internalToGui() override;
|
||||
void guiToInternal() override;
|
||||
|
||||
std::unique_ptr<Internal::BoolAspectPrivate> d;
|
||||
};
|
||||
|
||||
class QTCREATOR_UTILS_EXPORT ColorAspect : public BaseAspect
|
||||
class QTCREATOR_UTILS_EXPORT ColorAspect : public TypedAspect<QColor>
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
@@ -260,24 +352,16 @@ public:
|
||||
ColorAspect(AspectContainer *container = nullptr);
|
||||
~ColorAspect() override;
|
||||
|
||||
struct Data : BaseAspect::Data
|
||||
{
|
||||
QColor value;
|
||||
};
|
||||
|
||||
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:
|
||||
void internalToGui() override;
|
||||
void guiToInternal() override;
|
||||
|
||||
std::unique_ptr<Internal::ColorAspectPrivate> d;
|
||||
};
|
||||
|
||||
class QTCREATOR_UTILS_EXPORT SelectionAspect : public BaseAspect
|
||||
class QTCREATOR_UTILS_EXPORT SelectionAspect : public TypedAspect<int>
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
@@ -286,20 +370,13 @@ public:
|
||||
~SelectionAspect() override;
|
||||
|
||||
void addToLayout(Layouting::LayoutItem &parent) override;
|
||||
QVariant volatileValue() const override;
|
||||
void setVolatileValue(const QVariant &val) override;
|
||||
void finish() override;
|
||||
|
||||
int operator()() const { return value(); }
|
||||
int value() const;
|
||||
void setValue(int val);
|
||||
|
||||
QString stringValue() const;
|
||||
void setStringValue(const QString &val);
|
||||
|
||||
int defaultValue() const;
|
||||
void setDefaultValue(int val);
|
||||
void setDefaultValue(const QString &val);
|
||||
void setDefaultValue(int val);
|
||||
|
||||
QVariant itemValue() const;
|
||||
|
||||
@@ -325,14 +402,15 @@ public:
|
||||
int indexForItemValue(const QVariant &value) const;
|
||||
QVariant itemValueForIndex(int index) const;
|
||||
|
||||
signals:
|
||||
void volatileValueChanged(int newValue);
|
||||
protected:
|
||||
void internalToGui() override;
|
||||
void guiToInternal() override;
|
||||
|
||||
private:
|
||||
std::unique_ptr<Internal::SelectionAspectPrivate> d;
|
||||
};
|
||||
|
||||
class QTCREATOR_UTILS_EXPORT MultiSelectionAspect : public BaseAspect
|
||||
class QTCREATOR_UTILS_EXPORT MultiSelectionAspect : public TypedAspect<QStringList>
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
@@ -345,17 +423,18 @@ public:
|
||||
enum class DisplayStyle { ListView };
|
||||
void setDisplayStyle(DisplayStyle style);
|
||||
|
||||
QStringList value() const;
|
||||
void setValue(const QStringList &val);
|
||||
|
||||
QStringList allValues() const;
|
||||
void setAllValues(const QStringList &val);
|
||||
|
||||
protected:
|
||||
void internalToGui() override;
|
||||
void guiToInternal() override;
|
||||
|
||||
private:
|
||||
std::unique_ptr<Internal::MultiSelectionAspectPrivate> d;
|
||||
};
|
||||
|
||||
class QTCREATOR_UTILS_EXPORT StringAspect : public BaseAspect
|
||||
class QTCREATOR_UTILS_EXPORT StringAspect : public TypedAspect<QString>
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
@@ -371,21 +450,13 @@ public:
|
||||
|
||||
void addToLayout(Layouting::LayoutItem &parent) override;
|
||||
|
||||
QVariant volatileValue() const override;
|
||||
void setVolatileValue(const QVariant &val) override;
|
||||
void emitChangedValue() override;
|
||||
|
||||
// Hook between UI and StringAspect:
|
||||
using ValueAcceptor = std::function<std::optional<QString>(const QString &, const QString &)>;
|
||||
void setValueAcceptor(ValueAcceptor &&acceptor);
|
||||
|
||||
QString operator()() const { return value(); }
|
||||
QString value() const;
|
||||
void setValue(const QString &val);
|
||||
|
||||
QString defaultValue() const;
|
||||
void setDefaultValue(const QString &val);
|
||||
|
||||
void setShowToolTipOnLabel(bool show);
|
||||
|
||||
void setDisplayFilter(const std::function<QString (const QString &)> &displayFilter);
|
||||
@@ -438,10 +509,10 @@ public:
|
||||
|
||||
signals:
|
||||
void checkedChanged();
|
||||
void valueChanged(const QString &newValue);
|
||||
|
||||
protected:
|
||||
void update();
|
||||
void internalToGui() override;
|
||||
void guiToInternal() override;
|
||||
|
||||
std::unique_ptr<Internal::StringAspectPrivate> d;
|
||||
};
|
||||
@@ -454,7 +525,7 @@ public:
|
||||
FilePath operator()() const { return filePath(); }
|
||||
};
|
||||
|
||||
class QTCREATOR_UTILS_EXPORT IntegerAspect : public BaseAspect
|
||||
class QTCREATOR_UTILS_EXPORT IntegerAspect : public TypedAspect<qint64>
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
@@ -464,16 +535,6 @@ public:
|
||||
|
||||
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 setLabel(const QString &label); // FIXME: Use setLabelText
|
||||
void setPrefix(const QString &prefix);
|
||||
@@ -485,14 +546,15 @@ public:
|
||||
|
||||
struct Data : BaseAspect::Data { qint64 value = 0; };
|
||||
|
||||
signals:
|
||||
void valueChanged(int newValue);
|
||||
protected:
|
||||
void internalToGui() override;
|
||||
void guiToInternal() override;
|
||||
|
||||
private:
|
||||
std::unique_ptr<Internal::IntegerAspectPrivate> d;
|
||||
};
|
||||
|
||||
class QTCREATOR_UTILS_EXPORT DoubleAspect : public BaseAspect
|
||||
class QTCREATOR_UTILS_EXPORT DoubleAspect : public TypedAspect<double>
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
@@ -502,22 +564,16 @@ public:
|
||||
|
||||
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 setPrefix(const QString &prefix);
|
||||
void setSuffix(const QString &suffix);
|
||||
void setSpecialValueText(const QString &specialText);
|
||||
void setSingleStep(double step);
|
||||
|
||||
protected:
|
||||
void internalToGui() override;
|
||||
void guiToInternal() override;
|
||||
|
||||
private:
|
||||
std::unique_ptr<Internal::DoubleAspectPrivate> d;
|
||||
};
|
||||
@@ -532,6 +588,7 @@ public:
|
||||
|
||||
int toInt() const { return int(m_value); }
|
||||
QVariant toVariant() const { return int(m_value); }
|
||||
static TriState fromInt(int value);
|
||||
static TriState fromVariant(const QVariant &variant);
|
||||
|
||||
static const TriState Enabled;
|
||||
@@ -562,7 +619,7 @@ public:
|
||||
void setDefaultValue(TriState setting);
|
||||
};
|
||||
|
||||
class QTCREATOR_UTILS_EXPORT StringListAspect : public BaseAspect
|
||||
class QTCREATOR_UTILS_EXPORT StringListAspect : public TypedAspect<QStringList>
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
@@ -572,9 +629,6 @@ public:
|
||||
|
||||
void addToLayout(Layouting::LayoutItem &parent) override;
|
||||
|
||||
QStringList value() const;
|
||||
void setValue(const QStringList &val);
|
||||
|
||||
void appendValue(const QString &value, bool allowDuplicates = true);
|
||||
void removeValue(const QString &value);
|
||||
void appendValues(const QStringList &values, bool allowDuplicates = true);
|
||||
@@ -584,7 +638,7 @@ private:
|
||||
std::unique_ptr<Internal::StringListAspectPrivate> d;
|
||||
};
|
||||
|
||||
class QTCREATOR_UTILS_EXPORT IntegersAspect : public BaseAspect
|
||||
class QTCREATOR_UTILS_EXPORT IntegersAspect : public TypedAspect<QList<int>>
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
@@ -593,17 +647,6 @@ public:
|
||||
~IntegersAspect() 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
|
||||
|
@@ -111,9 +111,9 @@ GTestSettings::GTestSettings(Id settingsId)
|
||||
return edit && GTestUtils::isValidGTestFilter(edit->text());
|
||||
});
|
||||
|
||||
QObject::connect(&groupMode, &SelectionAspect::volatileValueChanged,
|
||||
>estFilter, [this](int val) {
|
||||
gtestFilter.setEnabled(groupMode.itemValueForIndex(val) == GTest::Constants::GTestFilter);
|
||||
QObject::connect(&groupMode, &SelectionAspect::volatileValueChanged, >estFilter, [this] {
|
||||
gtestFilter.setEnabled(groupMode.itemValueForIndex(groupMode.volatileValue())
|
||||
== GTest::Constants::GTestFilter);
|
||||
});
|
||||
|
||||
QObject::connect(this, &AspectContainer::applied, this, [] {
|
||||
|
@@ -246,7 +246,7 @@ public:
|
||||
configurations, predefinedStyleButton] {
|
||||
const bool predefSelected = styleButtonGroup->checkedButton() == predefinedStyleButton;
|
||||
predefinedBlob->setEnabled(predefSelected);
|
||||
fallbackBlob->setEnabled(predefSelected && s.predefinedStyle.volatileValue().toInt() == 5); // File
|
||||
fallbackBlob->setEnabled(predefSelected && s.predefinedStyle.volatileValue() == 5); // File
|
||||
configurations->setEnabled(!predefSelected);
|
||||
};
|
||||
updateEnabled();
|
||||
|
@@ -2114,13 +2114,11 @@ QString CMakeBuildSystem::cmakeBuildType() const
|
||||
void CMakeBuildSystem::setCMakeBuildType(const QString &cmakeBuildType, bool quiet)
|
||||
{
|
||||
auto aspect = buildConfiguration()->aspect<BuildTypeAspect>();
|
||||
if (quiet) {
|
||||
if (quiet)
|
||||
aspect->setValueQuietly(cmakeBuildType);
|
||||
aspect->update();
|
||||
} else {
|
||||
else
|
||||
aspect->setValue(cmakeBuildType);
|
||||
}
|
||||
}
|
||||
|
||||
namespace Internal {
|
||||
|
||||
@@ -2179,7 +2177,7 @@ void InitialCMakeArgumentsAspect::setAllValues(const QString &values, QStringLis
|
||||
|
||||
// Display the unknown arguments in "Additional CMake Options"
|
||||
const QString additionalOptionsValue = ProcessArgs::joinArgs(additionalOptions);
|
||||
BaseAspect::setValueQuietly(additionalOptionsValue);
|
||||
setValueQuietly(additionalOptionsValue);
|
||||
}
|
||||
|
||||
void InitialCMakeArgumentsAspect::setCMakeConfiguration(const CMakeConfig &config)
|
||||
|
@@ -135,7 +135,6 @@ class BuildTypeAspect final : public Utils::StringAspect
|
||||
|
||||
public:
|
||||
BuildTypeAspect();
|
||||
using Utils::StringAspect::update;
|
||||
};
|
||||
|
||||
class ConfigureEnvironmentAspect final: public ProjectExplorer::EnvironmentAspect
|
||||
|
@@ -79,10 +79,8 @@ public:
|
||||
|
||||
auto updateAuthWidget = [authWidget]() {
|
||||
authWidget->updateClient(
|
||||
FilePath::fromUserInput(
|
||||
CopilotSettings::instance().nodeJsPath.volatileValue().toString()),
|
||||
FilePath::fromUserInput(
|
||||
CopilotSettings::instance().distPath.volatileValue().toString()));
|
||||
FilePath::fromUserInput(CopilotSettings::instance().nodeJsPath.volatileValue()),
|
||||
FilePath::fromUserInput(CopilotSettings::instance().distPath.volatileValue()));
|
||||
};
|
||||
|
||||
connect(CopilotSettings::instance().nodeJsPath.pathChooser(),
|
||||
|
@@ -142,10 +142,8 @@ void CopilotPlugin::initialize()
|
||||
requestAction->setEnabled(enabled);
|
||||
};
|
||||
|
||||
connect(&CopilotSettings::instance().enableCopilot,
|
||||
&BoolAspect::valueChanged,
|
||||
this,
|
||||
updateActions);
|
||||
connect(&CopilotSettings::instance().enableCopilot, &BaseAspect::changed,
|
||||
this, updateActions);
|
||||
|
||||
updateActions();
|
||||
|
||||
|
@@ -92,8 +92,8 @@ CopilotProjectSettings::CopilotProjectSettings(ProjectExplorer::Project *project
|
||||
QVariantMap map = project->namedSettings(Constants::COPILOT_PROJECT_SETTINGS_ID).toMap();
|
||||
fromMap(map);
|
||||
|
||||
connect(&enableCopilot, &BoolAspect::valueChanged, this, [this, project] { save(project); });
|
||||
connect(&useGlobalSettings, &BoolAspect::valueChanged, this, [this, project] { save(project); });
|
||||
connect(&enableCopilot, &BaseAspect::changed, this, [this, project] { save(project); });
|
||||
connect(&useGlobalSettings, &BaseAspect::changed, this, [this, project] { save(project); });
|
||||
}
|
||||
|
||||
void CopilotProjectSettings::setUseGlobalSettings(bool useGlobal)
|
||||
|
@@ -32,7 +32,7 @@ public:
|
||||
|
||||
setOnApply([&s] {
|
||||
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
|
||||
if (originalPostMortem != currentPostMortem)
|
||||
s.registerForPostMortem->setValue(currentPostMortem);
|
||||
|
@@ -87,8 +87,8 @@ Console::Console()
|
||||
m_showDebug.setToolTip(Tr::tr("Show debug, log, and info messages."));
|
||||
m_showDebug.setValue(true);
|
||||
m_showDebug.action()->setIcon(Utils::Icons::INFO_TOOLBAR.icon());
|
||||
connect(&m_showDebug, &Utils::BoolAspect::valueChanged,
|
||||
proxyModel, &ConsoleProxyModel::setShowLogs);
|
||||
connect(&m_showDebug, &Utils::BoolAspect::changed,
|
||||
proxyModel, [this, proxyModel] { proxyModel->setShowLogs(m_showDebug()); });
|
||||
m_showDebugButton->setDefaultAction(m_showDebug.action());
|
||||
|
||||
m_showWarningButton = new QToolButton(m_consoleWidget);
|
||||
@@ -100,7 +100,7 @@ Console::Console()
|
||||
m_showWarning.setValue(true);
|
||||
m_showWarning.action()->setIcon(Utils::Icons::WARNING_TOOLBAR.icon());
|
||||
connect(m_showWarning.action(), &QAction::toggled,
|
||||
proxyModel, &ConsoleProxyModel::setShowWarnings);
|
||||
proxyModel, [this, proxyModel] { proxyModel->setShowWarnings(m_showWarning()); });
|
||||
m_showWarningButton->setDefaultAction(m_showWarning.action());
|
||||
|
||||
m_showErrorButton = new QToolButton(m_consoleWidget);
|
||||
@@ -112,7 +112,7 @@ Console::Console()
|
||||
m_showError.setValue(true);
|
||||
m_showError.action()->setIcon(Utils::Icons::CRITICAL_TOOLBAR.icon());
|
||||
connect(m_showError.action(), &QAction::toggled,
|
||||
proxyModel, &ConsoleProxyModel::setShowErrors);
|
||||
proxyModel, [this, proxyModel] { proxyModel->setShowErrors(m_showError()); });
|
||||
m_showErrorButton->setDefaultAction(m_showError.action());
|
||||
|
||||
m_spacer = new QWidget(m_consoleWidget);
|
||||
|
@@ -490,8 +490,8 @@ QString DebuggerSettings::dump()
|
||||
const int pos = key.indexOf('/');
|
||||
if (pos >= 0)
|
||||
key = key.mid(pos);
|
||||
const QString current = aspect->value().toString();
|
||||
const QString default_ = aspect->defaultValue().toString();
|
||||
const QString current = aspect->variantValue().toString();
|
||||
const QString default_ = aspect->defaultVariantValue().toString();
|
||||
QString setting = key + ": " + current + " (default: " + default_ + ')';
|
||||
if (current != default_)
|
||||
setting += " ***";
|
||||
|
@@ -21,7 +21,7 @@ class SourcePathMapAspectPrivate;
|
||||
// Syntax: (/home/.*)/KnownSubdir -> /home/my/project
|
||||
using SourcePathMap = QMap<QString, QString>;
|
||||
|
||||
class SourcePathMapAspect : public Utils::BaseAspect
|
||||
class SourcePathMapAspect : public Utils::TypedAspect<SourcePathMap>
|
||||
{
|
||||
public:
|
||||
SourcePathMapAspect();
|
||||
@@ -32,15 +32,13 @@ public:
|
||||
|
||||
void addToLayout(Layouting::LayoutItem &parent) override;
|
||||
|
||||
QVariant volatileValue() const override;
|
||||
void setVolatileValue(const QVariant &val) override;
|
||||
|
||||
void readSettings(const QSettings *settings) override;
|
||||
void writeSettings(QSettings *settings) const override;
|
||||
|
||||
SourcePathMap value() const;
|
||||
|
||||
private:
|
||||
void guiToInternal() override;
|
||||
void internalToGui() override;
|
||||
|
||||
SourcePathMapAspectPrivate *d = nullptr;
|
||||
};
|
||||
|
||||
|
@@ -470,29 +470,22 @@ void SourcePathMapAspect::addToLayout(Layouting::LayoutItem &parent)
|
||||
parent.addItem(d->m_widget.data());
|
||||
}
|
||||
|
||||
QVariant SourcePathMapAspect::volatileValue() const
|
||||
void SourcePathMapAspect::guiToInternal()
|
||||
{
|
||||
QTC_CHECK(!isAutoApply());
|
||||
QTC_ASSERT(d->m_widget, return {});
|
||||
return QVariant::fromValue(d->m_widget->sourcePathMap());
|
||||
if (d->m_widget)
|
||||
m_internal = d->m_widget->sourcePathMap();
|
||||
}
|
||||
|
||||
void SourcePathMapAspect::setVolatileValue(const QVariant &val)
|
||||
void SourcePathMapAspect::internalToGui()
|
||||
{
|
||||
QTC_CHECK(!isAutoApply());
|
||||
if (d->m_widget)
|
||||
d->m_widget->setSourcePathMap(val.value<SourcePathMap>());
|
||||
d->m_widget->setSourcePathMap(m_internal);
|
||||
}
|
||||
|
||||
const char sourcePathMappingArrayNameC[] = "SourcePathMappings";
|
||||
const char sourcePathMappingSourceKeyC[] = "Source";
|
||||
const char sourcePathMappingTargetKeyC[] = "Target";
|
||||
|
||||
SourcePathMap SourcePathMapAspect::value() const
|
||||
{
|
||||
return BaseAspect::value().value<SourcePathMap>();
|
||||
}
|
||||
|
||||
void SourcePathMapAspect::writeSettings(QSettings *s) const
|
||||
{
|
||||
const SourcePathMap sourcePathMap = value();
|
||||
@@ -528,7 +521,7 @@ void SourcePathMapAspect::readSettings(const QSettings *settings)
|
||||
}
|
||||
}
|
||||
s->endArray();
|
||||
setValue(QVariant::fromValue(sourcePathMap));
|
||||
setValue(sourcePathMap);
|
||||
}
|
||||
|
||||
} // Debugger::Internal
|
||||
|
@@ -46,7 +46,7 @@ void RegisterPostMortemAction::registerNow(bool value)
|
||||
|
||||
RegisterPostMortemAction::RegisterPostMortemAction()
|
||||
{
|
||||
connect(this, &BoolAspect::valueChanged, this, &RegisterPostMortemAction::registerNow);
|
||||
connect(this, &BaseAspect::changed, this, [this] { registerNow(value()); });
|
||||
}
|
||||
|
||||
void RegisterPostMortemAction::readSettings(const QSettings *)
|
||||
|
@@ -28,30 +28,6 @@ using namespace Utils;
|
||||
namespace FakeVim::Internal {
|
||||
|
||||
#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)
|
||||
{
|
||||
@@ -294,7 +270,7 @@ QString FakeVimSettings::trySetValue(const QString &name, const QString &value)
|
||||
return Tr::tr("Argument must be positive: %1=%2")
|
||||
.arg(name).arg(value);
|
||||
}
|
||||
aspect->setValue(value);
|
||||
aspect->setVariantValue(value);
|
||||
return QString();
|
||||
}
|
||||
|
||||
@@ -305,7 +281,7 @@ void FakeVimSettings::setup(FvBaseAspect *aspect,
|
||||
const QString &labelText)
|
||||
{
|
||||
aspect->setSettingsKey("FakeVim", settingsKey);
|
||||
aspect->setDefaultValue(value);
|
||||
aspect->setDefaultVariantValue(value);
|
||||
#ifndef FAKEVIM_STANDALONE
|
||||
aspect->setLabelText(labelText);
|
||||
aspect->setAutoApply(false);
|
||||
|
@@ -19,13 +19,14 @@ namespace FakeVim::Internal {
|
||||
class FvBaseAspect
|
||||
{
|
||||
public:
|
||||
FvBaseAspect();
|
||||
virtual ~FvBaseAspect() {}
|
||||
FvBaseAspect() = default;
|
||||
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);
|
||||
QString settingsKey() const;
|
||||
void setCheckable(bool) {}
|
||||
@@ -33,32 +34,41 @@ public:
|
||||
void setToolTip(const QString &) {}
|
||||
|
||||
private:
|
||||
QVariant m_value;
|
||||
QVariant m_defaultValue;
|
||||
QString m_settingsGroup;
|
||||
QString m_settingsKey;
|
||||
};
|
||||
|
||||
class FvBoolAspect : public FvBaseAspect
|
||||
template <class ValueType>
|
||||
class FvTypedAspect : public FvBaseAspect
|
||||
{
|
||||
public:
|
||||
bool value() const { return FvBaseAspect::value().toBool(); }
|
||||
bool operator()() const { return value(); }
|
||||
void setVariantValue(const QVariant &value) override
|
||||
{
|
||||
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
|
||||
{
|
||||
public:
|
||||
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(); }
|
||||
};
|
||||
using FvBoolAspect = FvTypedAspect<bool>;
|
||||
using FvIntegerAspect = FvTypedAspect<qint64>;
|
||||
using FvStringAspect = FvTypedAspect<QString>;
|
||||
|
||||
class FvAspectContainer : public FvBaseAspect
|
||||
{
|
||||
|
@@ -6139,13 +6139,13 @@ bool FakeVimHandler::Private::handleExSetCommand(const ExCommand &cmd)
|
||||
FvBaseAspect *act = s.item(optionName);
|
||||
if (!act) {
|
||||
showMessage(MessageError, Tr::tr("Unknown option:") + ' ' + cmd.args);
|
||||
} else if (act->defaultValue().type() == QVariant::Bool) {
|
||||
bool oldValue = act->value().toBool();
|
||||
} else if (act->defaultVariantValue().type() == QVariant::Bool) {
|
||||
bool oldValue = act->variantValue().toBool();
|
||||
if (printOption) {
|
||||
showMessage(MessageInfo, QLatin1String(oldValue ? "" : "no")
|
||||
+ act->settingsKey().toLower());
|
||||
} else if (toggleOption || negateOption == oldValue) {
|
||||
act->setValue(!oldValue);
|
||||
act->setVariantValue(!oldValue);
|
||||
}
|
||||
} else if (negateOption && !printOption) {
|
||||
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);
|
||||
} else {
|
||||
showMessage(MessageInfo, act->settingsKey().toLower() + "="
|
||||
+ act->value().toString());
|
||||
+ act->variantValue().toString());
|
||||
}
|
||||
}
|
||||
updateEditor();
|
||||
|
@@ -1089,16 +1089,16 @@ void FakeVimPluginPrivate::initialize()
|
||||
this, &FakeVimPluginPrivate::documentRenamed);
|
||||
|
||||
FakeVimSettings &s = settings();
|
||||
connect(&s.useFakeVim, &FvBoolAspect::valueChanged,
|
||||
this, &FakeVimPluginPrivate::setUseFakeVim);
|
||||
connect(&s.useFakeVim, &FvBoolAspect::changed,
|
||||
this, [this, &s] { setUseFakeVim(s.useFakeVim()); });
|
||||
connect(&s.readVimRc, &FvBaseAspect::changed,
|
||||
this, &FakeVimPluginPrivate::maybeReadVimRc);
|
||||
connect(&s.vimRcPath, &FvBaseAspect::changed,
|
||||
this, &FakeVimPluginPrivate::maybeReadVimRc);
|
||||
connect(&s.relativeNumber, &FvBoolAspect::valueChanged,
|
||||
this, &FakeVimPluginPrivate::setShowRelativeLineNumbers);
|
||||
connect(&s.blinkingCursor, &FvBoolAspect::valueChanged,
|
||||
this, &FakeVimPluginPrivate::setCursorBlinking);
|
||||
connect(&s.relativeNumber, &FvBoolAspect::changed,
|
||||
this, [this, &s] { setShowRelativeLineNumbers(s.relativeNumber()); });
|
||||
connect(&s.blinkingCursor, &FvBoolAspect::changed,
|
||||
this, [this, &s] { setCursorBlinking(s.blinkingCursor()); });
|
||||
|
||||
// Delayed operations.
|
||||
connect(this, &FakeVimPluginPrivate::delayedQuitRequested,
|
||||
|
@@ -1466,9 +1466,8 @@ void GitPluginPrivate::setupInstantBlame()
|
||||
forceInstantBlame();
|
||||
};
|
||||
|
||||
connect(&settings().instantBlame, &BoolAspect::valueChanged, this,
|
||||
[this, setupBlameForEditor](bool enabled) {
|
||||
if (enabled)
|
||||
connect(&settings().instantBlame, &BaseAspect::changed, this, [this, setupBlameForEditor] {
|
||||
if (settings().instantBlame())
|
||||
setupBlameForEditor(EditorManager::currentEditor());
|
||||
else
|
||||
stopInstantBlame();
|
||||
|
@@ -146,8 +146,8 @@ GitSettings::GitSettings()
|
||||
st
|
||||
};
|
||||
});
|
||||
connect(&binaryPath, &StringAspect::valueChanged, this, [this] { tryResolve = true; });
|
||||
connect(&path, &StringAspect::valueChanged, this, [this] { tryResolve = true; });
|
||||
connect(&binaryPath, &BaseAspect::changed, this, [this] { tryResolve = true; });
|
||||
connect(&path, &BaseAspect::changed, this, [this] { tryResolve = true; });
|
||||
}
|
||||
|
||||
FilePath GitSettings::gitExecutable(bool *ok, QString *errorMessage) const
|
||||
|
@@ -42,9 +42,10 @@ public:
|
||||
NimPluginPrivate()
|
||||
{
|
||||
Suggest::NimSuggestCache::instance().setExecutablePath(settings.nimSuggestPath.value());
|
||||
QObject::connect(&settings.nimSuggestPath, &StringAspect::valueChanged,
|
||||
&Suggest::NimSuggestCache::instance(),
|
||||
&Suggest::NimSuggestCache::setExecutablePath);
|
||||
QObject::connect(&settings.nimSuggestPath, &StringAspect::changed,
|
||||
&Suggest::NimSuggestCache::instance(), [this] {
|
||||
Suggest::NimSuggestCache::instance().setExecutablePath(settings.nimSuggestPath.value());
|
||||
});
|
||||
}
|
||||
|
||||
NimSettings settings;
|
||||
|
@@ -109,8 +109,7 @@ PerforceSettings::PerforceSettings()
|
||||
errorLabel->setType(InfoLabel::Information);
|
||||
errorLabel->setText(Tr::tr("Testing..."));
|
||||
|
||||
const FilePath p4Bin = FilePath::fromUserInput(
|
||||
p4BinaryPath.volatileValue().toString());
|
||||
const FilePath p4Bin = FilePath::fromUserInput(p4BinaryPath.volatileValue());
|
||||
checker->start(p4Bin, {}, commonP4Arguments_volatile(), 10000);
|
||||
});
|
||||
|
||||
@@ -166,14 +165,14 @@ QStringList PerforceSettings::commonP4Arguments() const
|
||||
QStringList PerforceSettings::commonP4Arguments_volatile() const
|
||||
{
|
||||
QStringList lst;
|
||||
if (customEnv.volatileValue().toBool()) {
|
||||
auto p4C = p4Client.volatileValue().toString();
|
||||
if (customEnv.volatileValue()) {
|
||||
const QString p4C = p4Client.volatileValue();
|
||||
if (!p4C.isEmpty())
|
||||
lst << "-c" << p4C;
|
||||
auto p4P = p4Port.volatileValue().toString();
|
||||
const QString p4P = p4Port.volatileValue();
|
||||
if (!p4P.isEmpty())
|
||||
lst << "-p" << p4P;
|
||||
auto p4U = p4User.volatileValue().toString();
|
||||
const QString p4U = p4User.volatileValue();
|
||||
if (!p4U.isEmpty())
|
||||
lst << "-u" << p4U;
|
||||
}
|
||||
|
@@ -58,8 +58,8 @@ PerfSettings::PerfSettings(ProjectExplorer::Target *target)
|
||||
extraArguments.setLabelText(Tr::tr("Additional arguments:"));
|
||||
extraArguments.setSpan(4);
|
||||
|
||||
connect(&callgraphMode, &SelectionAspect::volatileValueChanged, this, [this](int index) {
|
||||
stackSize.setEnabled(index == 0);
|
||||
connect(&callgraphMode, &SelectionAspect::volatileValueChanged, this, [this] {
|
||||
stackSize.setEnabled(callgraphMode.volatileValue() == 0);
|
||||
});
|
||||
|
||||
readGlobalSettings();
|
||||
|
@@ -59,10 +59,12 @@ BuildPropertiesSettings::BuildPropertiesSettings()
|
||||
qtQuickCompiler.setSettingsKey("ProjectExplorer/Settings/QtQuickCompiler");
|
||||
qtQuickCompiler.setLabelText(Tr::tr("Use qmlcachegen:"));
|
||||
|
||||
QObject::connect(&showQtSettings, &BoolAspect::valueChanged,
|
||||
&qmlDebugging, &BaseAspect::setVisible);
|
||||
QObject::connect(&showQtSettings, &BoolAspect::valueChanged,
|
||||
&qtQuickCompiler, &BaseAspect::setVisible);
|
||||
QObject::connect(&showQtSettings, &BaseAspect::changed, &qmlDebugging, [this] {
|
||||
qmlDebugging.setVisible(showQtSettings());
|
||||
});
|
||||
QObject::connect(&showQtSettings, &BaseAspect::changed, &qtQuickCompiler, [this] {
|
||||
qtQuickCompiler.setVisible(showQtSettings());
|
||||
});
|
||||
}
|
||||
|
||||
QString BuildPropertiesSettings::defaultBuildDirectoryTemplate()
|
||||
|
@@ -109,8 +109,8 @@ PythonWizardPage::PythonWizardPage(const QList<QPair<QString, QVariant>> &pySide
|
||||
m_stateLabel->setWordWrap(true);
|
||||
m_stateLabel->setFilled(true);
|
||||
m_stateLabel->setType(InfoLabel::Error);
|
||||
connect(&m_venvPath, &StringAspect::valueChanged, this, &PythonWizardPage::updateStateLabel);
|
||||
connect(&m_createVenv, &BoolAspect::valueChanged, this, &PythonWizardPage::updateStateLabel);
|
||||
connect(&m_venvPath, &BaseAspect::changed, this, &PythonWizardPage::updateStateLabel);
|
||||
connect(&m_createVenv, &BaseAspect::changed, this, &PythonWizardPage::updateStateLabel);
|
||||
|
||||
Grid {
|
||||
m_pySideVersion, br,
|
||||
|
@@ -87,7 +87,8 @@ SquishSettings::SquishSettings()
|
||||
minimizeIDE.setToolTip(Tr::tr("Minimize IDE automatically while running or recording test cases."));
|
||||
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);
|
||||
serverPort.setEnabled(!checked);
|
||||
});
|
||||
|
@@ -923,13 +923,12 @@ void MemcheckToolPrivate::updateFromSettings()
|
||||
m_filterProjectAction->setChecked(!m_settings->filterExternalIssues());
|
||||
m_errorView->settingsChanged(m_settings);
|
||||
|
||||
connect(&m_settings->visibleErrorKinds, &IntegersAspect::valueChanged,
|
||||
&m_errorProxyModel, &MemcheckErrorFilterProxyModel::setAcceptedKinds);
|
||||
connect(&m_settings->visibleErrorKinds, &BaseAspect::changed, &m_errorProxyModel, [this] {
|
||||
m_errorProxyModel.setAcceptedKinds(m_settings->visibleErrorKinds());
|
||||
|
||||
connect(&m_settings->filterExternalIssues, &BoolAspect::valueChanged,
|
||||
&m_errorProxyModel, &MemcheckErrorFilterProxyModel::setFilterExternalIssues);
|
||||
});
|
||||
connect(&m_settings->filterExternalIssues, &BaseAspect::changed, &m_errorProxyModel, [this] {
|
||||
m_errorProxyModel.setFilterExternalIssues(m_settings->filterExternalIssues());
|
||||
});
|
||||
}
|
||||
|
||||
void MemcheckToolPrivate::maybeActiveRunConfigurationChanged()
|
||||
|
@@ -108,7 +108,7 @@ void SuppressionAspectPrivate::slotSuppressionSelectionChanged()
|
||||
//
|
||||
|
||||
SuppressionAspect::SuppressionAspect(AspectContainer *container, bool global)
|
||||
: BaseAspect(container)
|
||||
: TypedAspect(container)
|
||||
{
|
||||
d = new SuppressionAspectPrivate(this, global);
|
||||
setSettingsKey("Analyzer.Valgrind.SuppressionFiles");
|
||||
@@ -119,16 +119,6 @@ SuppressionAspect::~SuppressionAspect()
|
||||
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)
|
||||
{
|
||||
QTC_CHECK(!d->addEntry);
|
||||
@@ -157,8 +147,6 @@ void SuppressionAspect::addToLayout(Layouting::LayoutItem &parent)
|
||||
Column { d->addEntry.data(), d->removeEntry.data(), st }
|
||||
};
|
||||
parent.addItem(Span { 2, group });
|
||||
|
||||
setVolatileValue(BaseAspect::value());
|
||||
}
|
||||
|
||||
void SuppressionAspect::fromMap(const QVariantMap &map)
|
||||
@@ -171,22 +159,18 @@ void SuppressionAspect::toMap(QVariantMap &map) const
|
||||
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)
|
||||
ret << d->m_model.item(i)->text();
|
||||
|
||||
return ret;
|
||||
m_internal.append(FilePath::fromUserInput(d->m_model.item(i)->text()));
|
||||
}
|
||||
|
||||
void SuppressionAspect::setVolatileValue(const QVariant &val)
|
||||
void SuppressionAspect::internalToGui()
|
||||
{
|
||||
const QStringList files = val.toStringList();
|
||||
d->m_model.clear();
|
||||
for (const QString &file : files)
|
||||
d->m_model.appendRow(new QStandardItem(file));
|
||||
for (const FilePath &file : m_internal)
|
||||
d->m_model.appendRow(new QStandardItem(file.toUserOutput()));
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////
|
||||
@@ -388,7 +372,7 @@ QVariantMap ValgrindBaseSettings::defaultSettings() const
|
||||
{
|
||||
QVariantMap defaults;
|
||||
forEachAspect([&defaults](BaseAspect *aspect) {
|
||||
defaults.insert(aspect->settingsKey(), aspect->defaultValue());
|
||||
defaults.insert(aspect->settingsKey(), aspect->defaultVariantValue());
|
||||
});
|
||||
return defaults;
|
||||
}
|
||||
|
@@ -12,7 +12,7 @@ const char ANALYZER_VALGRIND_SETTINGS[] = "Analyzer.Valgrind.Settings";
|
||||
|
||||
class SuppressionAspectPrivate;
|
||||
|
||||
class SuppressionAspect final : public Utils::BaseAspect
|
||||
class SuppressionAspect final : public Utils::TypedAspect<Utils::FilePaths>
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
@@ -20,21 +20,17 @@ public:
|
||||
SuppressionAspect(Utils::AspectContainer *container, bool global);
|
||||
~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 fromMap(const QVariantMap &map) final;
|
||||
void toMap(QVariantMap &map) const final;
|
||||
|
||||
QVariant volatileValue() const final;
|
||||
void setVolatileValue(const QVariant &val) final;
|
||||
|
||||
void addSuppressionFile(const Utils::FilePath &suppressionFile);
|
||||
|
||||
private:
|
||||
void internalToGui() override;
|
||||
void guiToInternal() override;
|
||||
|
||||
friend class ValgrindBaseSettings;
|
||||
SuppressionAspectPrivate *d = nullptr;
|
||||
};
|
||||
|
Reference in New Issue
Block a user