forked from qt-creator/qt-creator
Utils: Add defaultValue getter for Aspects
Does the variant conversion based on the aspect type. Change-Id: I2127a5a4202c3a60b946492b90a78beabaa11aed Reviewed-by: <github-actions-qt-creator@cristianadam.eu> Reviewed-by: hjk <hjk@qt.io> Reviewed-by: Eike Ziller <eike.ziller@qt.io>
This commit is contained in:
@@ -799,6 +799,11 @@ void StringAspect::setValue(const QString &val)
|
||||
}
|
||||
}
|
||||
|
||||
QString StringAspect::defaultValue() const
|
||||
{
|
||||
return BaseAspect::defaultValue().toString();
|
||||
}
|
||||
|
||||
void StringAspect::setDefaultValue(const QString &val)
|
||||
{
|
||||
BaseAspect::setDefaultValue(val);
|
||||
@@ -1066,7 +1071,7 @@ void StringAspect::addToLayout(LayoutBuilder &builder)
|
||||
d->m_pathChooserDisplay->setBaseDirectory(d->m_baseFileName);
|
||||
d->m_pathChooserDisplay->setOpenTerminalHandler(d->m_openTerminal);
|
||||
if (defaultValue() == value())
|
||||
d->m_pathChooserDisplay->setDefaultValue(defaultValue().toString());
|
||||
d->m_pathChooserDisplay->setDefaultValue(defaultValue());
|
||||
else
|
||||
d->m_pathChooserDisplay->setFilePath(FilePath::fromUserInput(displayedString));
|
||||
// do not override default value with placeholder, but use placeholder if default is empty
|
||||
@@ -1129,7 +1134,7 @@ void StringAspect::addToLayout(LayoutBuilder &builder)
|
||||
auto resetButton = createSubWidget<QPushButton>(tr("Reset"));
|
||||
resetButton->setEnabled(d->m_lineEditDisplay->text() != defaultValue());
|
||||
connect(resetButton, &QPushButton::clicked, this, [this] {
|
||||
d->m_lineEditDisplay->setText(defaultValue().toString());
|
||||
d->m_lineEditDisplay->setText(defaultValue());
|
||||
});
|
||||
connect(d->m_lineEditDisplay, &QLineEdit::textChanged, this, [this, resetButton] {
|
||||
resetButton->setEnabled(d->m_lineEditDisplay->text() != defaultValue());
|
||||
@@ -1177,17 +1182,17 @@ QVariant StringAspect::volatileValue() const
|
||||
case PathChooserDisplay:
|
||||
QTC_ASSERT(d->m_pathChooserDisplay, return {});
|
||||
if (d->m_pathChooserDisplay->filePath().isEmpty())
|
||||
return defaultValue().toString();
|
||||
return defaultValue();
|
||||
return d->m_pathChooserDisplay->filePath().toString();
|
||||
case LineEditDisplay:
|
||||
QTC_ASSERT(d->m_lineEditDisplay, return {});
|
||||
if (d->m_lineEditDisplay->text().isEmpty())
|
||||
return defaultValue().toString();
|
||||
return defaultValue();
|
||||
return d->m_lineEditDisplay->text();
|
||||
case TextEditDisplay:
|
||||
QTC_ASSERT(d->m_textEditDisplay, return {});
|
||||
if (d->m_textEditDisplay->document()->isEmpty())
|
||||
return defaultValue().toString();
|
||||
return defaultValue();
|
||||
return d->m_textEditDisplay->document()->toPlainText();
|
||||
case LabelDisplay:
|
||||
break;
|
||||
@@ -1408,6 +1413,11 @@ void BoolAspect::setValue(bool value)
|
||||
}
|
||||
}
|
||||
|
||||
bool BoolAspect::defaultValue() const
|
||||
{
|
||||
return BaseAspect::defaultValue().toBool();
|
||||
}
|
||||
|
||||
void BoolAspect::setDefaultValue(bool val)
|
||||
{
|
||||
BaseAspect::setDefaultValue(val);
|
||||
@@ -1567,6 +1577,11 @@ void SelectionAspect::setStringValue(const QString &val)
|
||||
setValue(index);
|
||||
}
|
||||
|
||||
int SelectionAspect::defaultValue() const
|
||||
{
|
||||
return BaseAspect::defaultValue().toInt();
|
||||
}
|
||||
|
||||
void SelectionAspect::setDefaultValue(int val)
|
||||
{
|
||||
BaseAspect::setDefaultValue(val);
|
||||
@@ -1816,6 +1831,11 @@ void IntegerAspect::setValue(qint64 value)
|
||||
}
|
||||
}
|
||||
|
||||
qint64 IntegerAspect::defaultValue() const
|
||||
{
|
||||
return BaseAspect::defaultValue().toLongLong();
|
||||
}
|
||||
|
||||
void IntegerAspect::setRange(qint64 min, qint64 max)
|
||||
{
|
||||
d->m_minimumValue = min;
|
||||
@@ -1935,6 +1955,11 @@ void DoubleAspect::setValue(double value)
|
||||
BaseAspect::setValue(value);
|
||||
}
|
||||
|
||||
double DoubleAspect::defaultValue() const
|
||||
{
|
||||
return BaseAspect::defaultValue().toDouble();
|
||||
}
|
||||
|
||||
void DoubleAspect::setRange(double min, double max)
|
||||
{
|
||||
d->m_minimumValue = min;
|
||||
@@ -1997,6 +2022,11 @@ void TriStateAspect::setValue(TriState value)
|
||||
SelectionAspect::setValue(value.toInt());
|
||||
}
|
||||
|
||||
TriState TriStateAspect::defaultValue() const
|
||||
{
|
||||
return TriState::fromVariant(BaseAspect::defaultValue());
|
||||
}
|
||||
|
||||
void TriStateAspect::setDefaultValue(TriState value)
|
||||
{
|
||||
BaseAspect::setDefaultValue(value.toVariant());
|
||||
@@ -2128,6 +2158,12 @@ void IntegersAspect::setValue(const QList<int> &value)
|
||||
BaseAspect::setValue(transform(value, &QVariant::fromValue<int>));
|
||||
}
|
||||
|
||||
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, &QVariant::fromValue<int>));
|
||||
|
@@ -226,6 +226,7 @@ public:
|
||||
|
||||
bool value() const;
|
||||
void setValue(bool val);
|
||||
bool defaultValue() const;
|
||||
void setDefaultValue(bool val);
|
||||
|
||||
enum class LabelPlacement { AtCheckBox, AtCheckBoxWithoutDummyLabel, InExtraLabel };
|
||||
@@ -257,11 +258,14 @@ public:
|
||||
|
||||
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);
|
||||
|
||||
QString stringValue() const;
|
||||
QVariant itemValue() const;
|
||||
|
||||
enum class DisplayStyle { RadioButtons, ComboBox };
|
||||
@@ -341,6 +345,8 @@ public:
|
||||
void setValueAcceptor(ValueAcceptor &&acceptor);
|
||||
QString value() const;
|
||||
void setValue(const QString &val);
|
||||
|
||||
QString defaultValue() const;
|
||||
void setDefaultValue(const QString &val);
|
||||
|
||||
void setShowToolTipOnLabel(bool show);
|
||||
@@ -413,6 +419,8 @@ public:
|
||||
|
||||
qint64 value() const;
|
||||
void setValue(qint64 val);
|
||||
|
||||
qint64 defaultValue() const;
|
||||
void setDefaultValue(qint64 defaultValue);
|
||||
|
||||
void setRange(qint64 min, qint64 max);
|
||||
@@ -448,6 +456,8 @@ public:
|
||||
|
||||
double value() const;
|
||||
void setValue(double val);
|
||||
|
||||
double defaultValue() const;
|
||||
void setDefaultValue(double defaultValue);
|
||||
|
||||
void setRange(double min, double max);
|
||||
@@ -494,6 +504,8 @@ public:
|
||||
|
||||
TriState value() const;
|
||||
void setValue(TriState setting);
|
||||
|
||||
TriState defaultValue() const;
|
||||
void setDefaultValue(TriState setting);
|
||||
};
|
||||
|
||||
@@ -532,6 +544,8 @@ public:
|
||||
|
||||
QList<int> value() const;
|
||||
void setValue(const QList<int> &value);
|
||||
|
||||
QList<int> defaultValue() const;
|
||||
void setDefaultValue(const QList<int> &value);
|
||||
|
||||
signals:
|
||||
|
Reference in New Issue
Block a user