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)
|
void StringAspect::setDefaultValue(const QString &val)
|
||||||
{
|
{
|
||||||
BaseAspect::setDefaultValue(val);
|
BaseAspect::setDefaultValue(val);
|
||||||
@@ -1066,7 +1071,7 @@ void StringAspect::addToLayout(LayoutBuilder &builder)
|
|||||||
d->m_pathChooserDisplay->setBaseDirectory(d->m_baseFileName);
|
d->m_pathChooserDisplay->setBaseDirectory(d->m_baseFileName);
|
||||||
d->m_pathChooserDisplay->setOpenTerminalHandler(d->m_openTerminal);
|
d->m_pathChooserDisplay->setOpenTerminalHandler(d->m_openTerminal);
|
||||||
if (defaultValue() == value())
|
if (defaultValue() == value())
|
||||||
d->m_pathChooserDisplay->setDefaultValue(defaultValue().toString());
|
d->m_pathChooserDisplay->setDefaultValue(defaultValue());
|
||||||
else
|
else
|
||||||
d->m_pathChooserDisplay->setFilePath(FilePath::fromUserInput(displayedString));
|
d->m_pathChooserDisplay->setFilePath(FilePath::fromUserInput(displayedString));
|
||||||
// do not override default value with placeholder, but use placeholder if default is empty
|
// 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"));
|
auto resetButton = createSubWidget<QPushButton>(tr("Reset"));
|
||||||
resetButton->setEnabled(d->m_lineEditDisplay->text() != defaultValue());
|
resetButton->setEnabled(d->m_lineEditDisplay->text() != defaultValue());
|
||||||
connect(resetButton, &QPushButton::clicked, this, [this] {
|
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] {
|
connect(d->m_lineEditDisplay, &QLineEdit::textChanged, this, [this, resetButton] {
|
||||||
resetButton->setEnabled(d->m_lineEditDisplay->text() != defaultValue());
|
resetButton->setEnabled(d->m_lineEditDisplay->text() != defaultValue());
|
||||||
@@ -1177,17 +1182,17 @@ QVariant StringAspect::volatileValue() const
|
|||||||
case PathChooserDisplay:
|
case PathChooserDisplay:
|
||||||
QTC_ASSERT(d->m_pathChooserDisplay, return {});
|
QTC_ASSERT(d->m_pathChooserDisplay, return {});
|
||||||
if (d->m_pathChooserDisplay->filePath().isEmpty())
|
if (d->m_pathChooserDisplay->filePath().isEmpty())
|
||||||
return defaultValue().toString();
|
return defaultValue();
|
||||||
return d->m_pathChooserDisplay->filePath().toString();
|
return d->m_pathChooserDisplay->filePath().toString();
|
||||||
case LineEditDisplay:
|
case LineEditDisplay:
|
||||||
QTC_ASSERT(d->m_lineEditDisplay, return {});
|
QTC_ASSERT(d->m_lineEditDisplay, return {});
|
||||||
if (d->m_lineEditDisplay->text().isEmpty())
|
if (d->m_lineEditDisplay->text().isEmpty())
|
||||||
return defaultValue().toString();
|
return defaultValue();
|
||||||
return d->m_lineEditDisplay->text();
|
return d->m_lineEditDisplay->text();
|
||||||
case TextEditDisplay:
|
case TextEditDisplay:
|
||||||
QTC_ASSERT(d->m_textEditDisplay, return {});
|
QTC_ASSERT(d->m_textEditDisplay, return {});
|
||||||
if (d->m_textEditDisplay->document()->isEmpty())
|
if (d->m_textEditDisplay->document()->isEmpty())
|
||||||
return defaultValue().toString();
|
return defaultValue();
|
||||||
return d->m_textEditDisplay->document()->toPlainText();
|
return d->m_textEditDisplay->document()->toPlainText();
|
||||||
case LabelDisplay:
|
case LabelDisplay:
|
||||||
break;
|
break;
|
||||||
@@ -1408,6 +1413,11 @@ void BoolAspect::setValue(bool value)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool BoolAspect::defaultValue() const
|
||||||
|
{
|
||||||
|
return BaseAspect::defaultValue().toBool();
|
||||||
|
}
|
||||||
|
|
||||||
void BoolAspect::setDefaultValue(bool val)
|
void BoolAspect::setDefaultValue(bool val)
|
||||||
{
|
{
|
||||||
BaseAspect::setDefaultValue(val);
|
BaseAspect::setDefaultValue(val);
|
||||||
@@ -1567,6 +1577,11 @@ 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);
|
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)
|
void IntegerAspect::setRange(qint64 min, qint64 max)
|
||||||
{
|
{
|
||||||
d->m_minimumValue = min;
|
d->m_minimumValue = min;
|
||||||
@@ -1935,6 +1955,11 @@ void DoubleAspect::setValue(double value)
|
|||||||
BaseAspect::setValue(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)
|
||||||
{
|
{
|
||||||
d->m_minimumValue = min;
|
d->m_minimumValue = min;
|
||||||
@@ -1997,6 +2022,11 @@ void TriStateAspect::setValue(TriState value)
|
|||||||
SelectionAspect::setValue(value.toInt());
|
SelectionAspect::setValue(value.toInt());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TriState TriStateAspect::defaultValue() const
|
||||||
|
{
|
||||||
|
return TriState::fromVariant(BaseAspect::defaultValue());
|
||||||
|
}
|
||||||
|
|
||||||
void TriStateAspect::setDefaultValue(TriState value)
|
void TriStateAspect::setDefaultValue(TriState value)
|
||||||
{
|
{
|
||||||
BaseAspect::setDefaultValue(value.toVariant());
|
BaseAspect::setDefaultValue(value.toVariant());
|
||||||
@@ -2128,6 +2158,12 @@ void IntegersAspect::setValue(const QList<int> &value)
|
|||||||
BaseAspect::setValue(transform(value, &QVariant::fromValue<int>));
|
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)
|
void IntegersAspect::setDefaultValue(const QList<int> &value)
|
||||||
{
|
{
|
||||||
BaseAspect::setDefaultValue(transform(value, &QVariant::fromValue<int>));
|
BaseAspect::setDefaultValue(transform(value, &QVariant::fromValue<int>));
|
||||||
|
@@ -226,6 +226,7 @@ public:
|
|||||||
|
|
||||||
bool value() const;
|
bool value() const;
|
||||||
void setValue(bool val);
|
void setValue(bool val);
|
||||||
|
bool defaultValue() const;
|
||||||
void setDefaultValue(bool val);
|
void setDefaultValue(bool val);
|
||||||
|
|
||||||
enum class LabelPlacement { AtCheckBox, AtCheckBoxWithoutDummyLabel, InExtraLabel };
|
enum class LabelPlacement { AtCheckBox, AtCheckBoxWithoutDummyLabel, InExtraLabel };
|
||||||
@@ -257,11 +258,14 @@ public:
|
|||||||
|
|
||||||
int value() const;
|
int value() const;
|
||||||
void setValue(int val);
|
void setValue(int val);
|
||||||
|
|
||||||
|
QString stringValue() const;
|
||||||
void setStringValue(const QString &val);
|
void setStringValue(const QString &val);
|
||||||
|
|
||||||
|
int defaultValue() const;
|
||||||
void setDefaultValue(int val);
|
void setDefaultValue(int val);
|
||||||
void setDefaultValue(const QString &val);
|
void setDefaultValue(const QString &val);
|
||||||
|
|
||||||
QString stringValue() const;
|
|
||||||
QVariant itemValue() const;
|
QVariant itemValue() const;
|
||||||
|
|
||||||
enum class DisplayStyle { RadioButtons, ComboBox };
|
enum class DisplayStyle { RadioButtons, ComboBox };
|
||||||
@@ -341,6 +345,8 @@ public:
|
|||||||
void setValueAcceptor(ValueAcceptor &&acceptor);
|
void setValueAcceptor(ValueAcceptor &&acceptor);
|
||||||
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 setDefaultValue(const QString &val);
|
||||||
|
|
||||||
void setShowToolTipOnLabel(bool show);
|
void setShowToolTipOnLabel(bool show);
|
||||||
@@ -413,6 +419,8 @@ public:
|
|||||||
|
|
||||||
qint64 value() const;
|
qint64 value() const;
|
||||||
void setValue(qint64 val);
|
void setValue(qint64 val);
|
||||||
|
|
||||||
|
qint64 defaultValue() const;
|
||||||
void setDefaultValue(qint64 defaultValue);
|
void setDefaultValue(qint64 defaultValue);
|
||||||
|
|
||||||
void setRange(qint64 min, qint64 max);
|
void setRange(qint64 min, qint64 max);
|
||||||
@@ -448,6 +456,8 @@ public:
|
|||||||
|
|
||||||
double value() const;
|
double value() const;
|
||||||
void setValue(double val);
|
void setValue(double val);
|
||||||
|
|
||||||
|
double defaultValue() const;
|
||||||
void setDefaultValue(double defaultValue);
|
void setDefaultValue(double defaultValue);
|
||||||
|
|
||||||
void setRange(double min, double max);
|
void setRange(double min, double max);
|
||||||
@@ -494,6 +504,8 @@ public:
|
|||||||
|
|
||||||
TriState value() const;
|
TriState value() const;
|
||||||
void setValue(TriState setting);
|
void setValue(TriState setting);
|
||||||
|
|
||||||
|
TriState defaultValue() const;
|
||||||
void setDefaultValue(TriState setting);
|
void setDefaultValue(TriState setting);
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -532,6 +544,8 @@ public:
|
|||||||
|
|
||||||
QList<int> value() const;
|
QList<int> value() const;
|
||||||
void setValue(const QList<int> &value);
|
void setValue(const QList<int> &value);
|
||||||
|
|
||||||
|
QList<int> defaultValue() const;
|
||||||
void setDefaultValue(const QList<int> &value);
|
void setDefaultValue(const QList<int> &value);
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
|
Reference in New Issue
Block a user