forked from qt-creator/qt-creator
Utils: Consolidate more aspect functionality
The concepts of 'value', 'defaultValue' and changed signals are present in a few aspects, with varying implementations. Time to get things sorted out. The values are stored now as QVariant in the base, with typed accessors in the derived classes, keeping the user visible interface the same. Change-Id: I4d37ef5c7a9795f46ce1bbbabc6a251222b1d54e Reviewed-by: Christian Stenger <christian.stenger@qt.io>
This commit is contained in:
@@ -54,6 +54,9 @@ class BaseAspectPrivate
|
|||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
Utils::Id m_id;
|
Utils::Id m_id;
|
||||||
|
QVariant m_value;
|
||||||
|
QVariant m_defaultValue;
|
||||||
|
|
||||||
QString m_displayName;
|
QString m_displayName;
|
||||||
QString m_settingsKey; // Name of data in settings.
|
QString m_settingsKey; // Name of data in settings.
|
||||||
QString m_tooltip;
|
QString m_tooltip;
|
||||||
@@ -107,6 +110,50 @@ void BaseAspect::setId(Id id)
|
|||||||
d->m_id = id;
|
d->m_id = id;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QVariant BaseAspect::value() const
|
||||||
|
{
|
||||||
|
return d->m_value;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*!
|
||||||
|
Sets value.
|
||||||
|
|
||||||
|
Emits changed() if the value changed.
|
||||||
|
*/
|
||||||
|
void BaseAspect::setValue(const QVariant &value)
|
||||||
|
{
|
||||||
|
if (setValueQuietly(value))
|
||||||
|
emit changed();
|
||||||
|
}
|
||||||
|
|
||||||
|
/*!
|
||||||
|
Sets value without emitting changed()
|
||||||
|
|
||||||
|
Returns whether the value changed.
|
||||||
|
*/
|
||||||
|
bool BaseAspect::setValueQuietly(const QVariant &value)
|
||||||
|
{
|
||||||
|
if (d->m_value == value)
|
||||||
|
return false;
|
||||||
|
d->m_value = value;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
QVariant BaseAspect::defaultValue() const
|
||||||
|
{
|
||||||
|
return d->m_defaultValue;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*!
|
||||||
|
Sets a default value for this aspect.
|
||||||
|
|
||||||
|
Default values will not be stored in settings.
|
||||||
|
*/
|
||||||
|
void BaseAspect::setDefaultValue(const QVariant &value)
|
||||||
|
{
|
||||||
|
d->m_defaultValue = value;
|
||||||
|
}
|
||||||
|
|
||||||
void BaseAspect::setDisplayName(const QString &displayName)
|
void BaseAspect::setDisplayName(const QString &displayName)
|
||||||
{
|
{
|
||||||
d->m_displayName = displayName;
|
d->m_displayName = displayName;
|
||||||
@@ -256,19 +303,19 @@ void BaseAspect::saveToMap(QVariantMap &data, const QVariant &value,
|
|||||||
|
|
||||||
/*!
|
/*!
|
||||||
Retrieves the internal value of this BaseAspect from a \c QVariantMap.
|
Retrieves the internal value of this BaseAspect from a \c QVariantMap.
|
||||||
|
|
||||||
This base implementation does nothing.
|
|
||||||
*/
|
*/
|
||||||
void BaseAspect::fromMap(const QVariantMap &)
|
void BaseAspect::fromMap(const QVariantMap &map)
|
||||||
{}
|
{
|
||||||
|
setValue(map.value(settingsKey(), defaultValue()).toBool());
|
||||||
|
}
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
Stores the internal value of this BaseAspect into a \c QVariantMap.
|
Stores the internal value of this BaseAspect into a \c QVariantMap.
|
||||||
|
|
||||||
This base implementation does nothing.
|
|
||||||
*/
|
*/
|
||||||
void BaseAspect::toMap(QVariantMap &) const
|
void BaseAspect::toMap(QVariantMap &map) const
|
||||||
{}
|
{
|
||||||
|
saveToMap(map, d->m_value, d->m_defaultValue);
|
||||||
|
}
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
\internal
|
\internal
|
||||||
@@ -334,8 +381,6 @@ class BoolAspectPrivate
|
|||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
BoolAspect::LabelPlacement m_labelPlacement = BoolAspect::LabelPlacement::AtCheckBox;
|
BoolAspect::LabelPlacement m_labelPlacement = BoolAspect::LabelPlacement::AtCheckBox;
|
||||||
bool m_value = false;
|
|
||||||
bool m_defaultValue = false;
|
|
||||||
QString m_labelText;
|
QString m_labelText;
|
||||||
QPointer<QCheckBox> m_checkBox; // Owned by configuration widget
|
QPointer<QCheckBox> m_checkBox; // Owned by configuration widget
|
||||||
QPointer<QLabel> m_label; // Owned by configuration widget
|
QPointer<QLabel> m_label; // Owned by configuration widget
|
||||||
@@ -344,8 +389,6 @@ public:
|
|||||||
class SelectionAspectPrivate
|
class SelectionAspectPrivate
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
int m_value = 0;
|
|
||||||
int m_defaultValue = 0;
|
|
||||||
SelectionAspect::DisplayStyle m_displayStyle
|
SelectionAspect::DisplayStyle m_displayStyle
|
||||||
= SelectionAspect::DisplayStyle::RadioButtons;
|
= SelectionAspect::DisplayStyle::RadioButtons;
|
||||||
struct Option { QString displayName; QString tooltip; };
|
struct Option { QString displayName; QString tooltip; };
|
||||||
@@ -361,7 +404,11 @@ public:
|
|||||||
class MultiSelectionAspectPrivate
|
class MultiSelectionAspectPrivate
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
QStringList m_value;
|
explicit MultiSelectionAspectPrivate(MultiSelectionAspect *q) : q(q) {}
|
||||||
|
|
||||||
|
bool setValueSelectedHelper(const QString &value, bool on);
|
||||||
|
|
||||||
|
MultiSelectionAspect *q;
|
||||||
QStringList m_allValues;
|
QStringList m_allValues;
|
||||||
MultiSelectionAspect::DisplayStyle m_displayStyle
|
MultiSelectionAspect::DisplayStyle m_displayStyle
|
||||||
= MultiSelectionAspect::DisplayStyle::ListView;
|
= MultiSelectionAspect::DisplayStyle::ListView;
|
||||||
@@ -370,9 +417,6 @@ public:
|
|||||||
// These are all owned by the configuration widget.
|
// These are all owned by the configuration widget.
|
||||||
QPointer<QListWidget> m_listView;
|
QPointer<QListWidget> m_listView;
|
||||||
QPointer<QLabel> m_label;
|
QPointer<QLabel> m_label;
|
||||||
|
|
||||||
void updateListView();
|
|
||||||
bool setValueSelectedHelper(const QString &value, bool on);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
class StringAspectPrivate
|
class StringAspectPrivate
|
||||||
@@ -387,7 +431,6 @@ public:
|
|||||||
std::function<QString(const QString &)> m_displayFilter;
|
std::function<QString(const QString &)> m_displayFilter;
|
||||||
std::unique_ptr<BoolAspect> m_checker;
|
std::unique_ptr<BoolAspect> m_checker;
|
||||||
|
|
||||||
QString m_value;
|
|
||||||
QString m_placeHolderText;
|
QString m_placeHolderText;
|
||||||
QString m_historyCompleterKey;
|
QString m_historyCompleterKey;
|
||||||
PathChooser::Kind m_expectedKind = PathChooser::File;
|
PathChooser::Kind m_expectedKind = PathChooser::File;
|
||||||
@@ -421,8 +464,6 @@ public:
|
|||||||
class IntegerAspectPrivate
|
class IntegerAspectPrivate
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
qint64 m_value = 0;
|
|
||||||
qint64 m_defaultValue = 0;
|
|
||||||
QVariant m_minimumValue;
|
QVariant m_minimumValue;
|
||||||
QVariant m_maximumValue;
|
QVariant m_maximumValue;
|
||||||
int m_displayIntegerBase = 10;
|
int m_displayIntegerBase = 10;
|
||||||
@@ -437,7 +478,6 @@ public:
|
|||||||
class StringListAspectPrivate
|
class StringListAspectPrivate
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
QStringList m_value;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
class AspectContainerPrivate
|
class AspectContainerPrivate
|
||||||
@@ -526,21 +566,21 @@ void StringAspect::setValueAcceptor(StringAspect::ValueAcceptor &&acceptor)
|
|||||||
*/
|
*/
|
||||||
QString StringAspect::value() const
|
QString StringAspect::value() const
|
||||||
{
|
{
|
||||||
return d->m_value;
|
return BaseAspect::value().toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
Sets the \a value of this StringAspect from an ordinary \c QString.
|
Sets the \a value of this StringAspect from an ordinary \c QString.
|
||||||
*/
|
*/
|
||||||
void StringAspect::setValue(const QString &value)
|
void StringAspect::setValue(const QString &val)
|
||||||
{
|
{
|
||||||
const bool isSame = value == d->m_value;
|
const bool isSame = val == value();
|
||||||
if (isSame)
|
if (isSame)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
QString processedValue = value;
|
QString processedValue = val;
|
||||||
if (d->m_valueAcceptor) {
|
if (d->m_valueAcceptor) {
|
||||||
const Utils::optional<QString> tmp = d->m_valueAcceptor(d->m_value, value);
|
const Utils::optional<QString> tmp = d->m_valueAcceptor(value(), val);
|
||||||
if (!tmp) {
|
if (!tmp) {
|
||||||
update(); // Make sure the original value is retained in the UI
|
update(); // Make sure the original value is retained in the UI
|
||||||
return;
|
return;
|
||||||
@@ -548,9 +588,10 @@ void StringAspect::setValue(const QString &value)
|
|||||||
processedValue = tmp.value();
|
processedValue = tmp.value();
|
||||||
}
|
}
|
||||||
|
|
||||||
d->m_value = processedValue;
|
if (BaseAspect::setValueQuietly(QVariant(processedValue))) {
|
||||||
update();
|
update();
|
||||||
emit changed();
|
emit changed();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
@@ -559,7 +600,7 @@ void StringAspect::setValue(const QString &value)
|
|||||||
void StringAspect::fromMap(const QVariantMap &map)
|
void StringAspect::fromMap(const QVariantMap &map)
|
||||||
{
|
{
|
||||||
if (!settingsKey().isEmpty())
|
if (!settingsKey().isEmpty())
|
||||||
d->m_value = map.value(settingsKey()).toString();
|
BaseAspect::setValueQuietly(map.value(settingsKey()));
|
||||||
if (d->m_checker)
|
if (d->m_checker)
|
||||||
d->m_checker->fromMap(map);
|
d->m_checker->fromMap(map);
|
||||||
}
|
}
|
||||||
@@ -569,7 +610,7 @@ void StringAspect::fromMap(const QVariantMap &map)
|
|||||||
*/
|
*/
|
||||||
void StringAspect::toMap(QVariantMap &map) const
|
void StringAspect::toMap(QVariantMap &map) const
|
||||||
{
|
{
|
||||||
saveToMap(map, d->m_value, QString());
|
saveToMap(map, value(), QString());
|
||||||
if (d->m_checker)
|
if (d->m_checker)
|
||||||
d->m_checker->toMap(map);
|
d->m_checker->toMap(map);
|
||||||
}
|
}
|
||||||
@@ -583,7 +624,7 @@ void StringAspect::toMap(QVariantMap &map) const
|
|||||||
*/
|
*/
|
||||||
FilePath StringAspect::filePath() const
|
FilePath StringAspect::filePath() const
|
||||||
{
|
{
|
||||||
return FilePath::fromUserInput(d->m_value);
|
return FilePath::fromUserInput(value());
|
||||||
}
|
}
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
@@ -839,10 +880,7 @@ void StringAspect::addToLayout(LayoutBuilder &builder)
|
|||||||
useMacroExpander(d->m_textEditDisplay);
|
useMacroExpander(d->m_textEditDisplay);
|
||||||
connect(d->m_textEditDisplay, &QTextEdit::textChanged, this, [this] {
|
connect(d->m_textEditDisplay, &QTextEdit::textChanged, this, [this] {
|
||||||
const QString value = d->m_textEditDisplay->document()->toPlainText();
|
const QString value = d->m_textEditDisplay->document()->toPlainText();
|
||||||
if (value != d->m_value) {
|
setValue(value);
|
||||||
d->m_value = value;
|
|
||||||
emit changed();
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
builder.addItem(d->m_textEditDisplay.data());
|
builder.addItem(d->m_textEditDisplay.data());
|
||||||
break;
|
break;
|
||||||
@@ -863,8 +901,7 @@ void StringAspect::addToLayout(LayoutBuilder &builder)
|
|||||||
|
|
||||||
void StringAspect::update()
|
void StringAspect::update()
|
||||||
{
|
{
|
||||||
const QString displayedString = d->m_displayFilter ? d->m_displayFilter(d->m_value)
|
const QString displayedString = d->m_displayFilter ? d->m_displayFilter(value()) : value();
|
||||||
: d->m_value;
|
|
||||||
|
|
||||||
if (d->m_pathChooserDisplay) {
|
if (d->m_pathChooserDisplay) {
|
||||||
d->m_pathChooserDisplay->setFilePath(FilePath::fromString(displayedString));
|
d->m_pathChooserDisplay->setFilePath(FilePath::fromString(displayedString));
|
||||||
@@ -938,6 +975,7 @@ void StringAspect::makeCheckable(CheckBoxPlacement checkBoxPlacement,
|
|||||||
BoolAspect::BoolAspect(const QString &settingsKey)
|
BoolAspect::BoolAspect(const QString &settingsKey)
|
||||||
: d(new Internal::BoolAspectPrivate)
|
: d(new Internal::BoolAspectPrivate)
|
||||||
{
|
{
|
||||||
|
setDefaultValue(false);
|
||||||
setSettingsKey(settingsKey);
|
setSettingsKey(settingsKey);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -966,54 +1004,29 @@ void BoolAspect::addToLayout(LayoutBuilder &builder)
|
|||||||
builder.addItem(d->m_label.data());
|
builder.addItem(d->m_label.data());
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
d->m_checkBox->setChecked(d->m_value);
|
d->m_checkBox->setChecked(value());
|
||||||
builder.addItem(d->m_checkBox.data());
|
builder.addItem(d->m_checkBox.data());
|
||||||
connect(d->m_checkBox.data(), &QAbstractButton::clicked, this, [this] {
|
connect(d->m_checkBox.data(), &QAbstractButton::clicked, this, [this] {
|
||||||
d->m_value = d->m_checkBox->isChecked();
|
setValue(d->m_checkBox->isChecked());
|
||||||
emit changed();
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
\reimp
|
\reimp
|
||||||
*/
|
*/
|
||||||
void BoolAspect::fromMap(const QVariantMap &map)
|
|
||||||
{
|
|
||||||
d->m_value = map.value(settingsKey(), d->m_defaultValue).toBool();
|
|
||||||
}
|
|
||||||
|
|
||||||
/*!
|
|
||||||
\reimp
|
|
||||||
*/
|
|
||||||
void BoolAspect::toMap(QVariantMap &data) const
|
|
||||||
{
|
|
||||||
saveToMap(data, d->m_value, d->m_defaultValue);
|
|
||||||
}
|
|
||||||
|
|
||||||
bool BoolAspect::defaultValue() const
|
|
||||||
{
|
|
||||||
return d->m_defaultValue;
|
|
||||||
}
|
|
||||||
|
|
||||||
void BoolAspect::setDefaultValue(bool defaultValue)
|
|
||||||
{
|
|
||||||
d->m_defaultValue = defaultValue;
|
|
||||||
d->m_value = defaultValue;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool BoolAspect::value() const
|
bool BoolAspect::value() const
|
||||||
{
|
{
|
||||||
return d->m_value;
|
return BaseAspect::value().toBool();
|
||||||
}
|
}
|
||||||
|
|
||||||
void BoolAspect::setValue(bool value)
|
void BoolAspect::setValue(bool value)
|
||||||
{
|
{
|
||||||
if (d->m_value == value)
|
if (BaseAspect::setValueQuietly(value)) {
|
||||||
return;
|
|
||||||
d->m_value = value;
|
|
||||||
if (d->m_checkBox)
|
if (d->m_checkBox)
|
||||||
d->m_checkBox->setChecked(d->m_value);
|
d->m_checkBox->setChecked(value);
|
||||||
emit changed();
|
emit changed();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void BoolAspect::setLabel(const QString &labelText, LabelPlacement labelPlacement)
|
void BoolAspect::setLabel(const QString &labelText, LabelPlacement labelPlacement)
|
||||||
@@ -1058,16 +1071,13 @@ void SelectionAspect::addToLayout(LayoutBuilder &builder)
|
|||||||
for (int i = 0, n = d->m_options.size(); i < n; ++i) {
|
for (int i = 0, n = d->m_options.size(); i < n; ++i) {
|
||||||
const Internal::SelectionAspectPrivate::Option &option = d->m_options.at(i);
|
const Internal::SelectionAspectPrivate::Option &option = d->m_options.at(i);
|
||||||
auto button = new QRadioButton(option.displayName);
|
auto button = new QRadioButton(option.displayName);
|
||||||
button->setChecked(i == d->m_value);
|
button->setChecked(i == value());
|
||||||
button->setToolTip(option.tooltip);
|
button->setToolTip(option.tooltip);
|
||||||
builder.addItems({{}, button});
|
builder.addItems({{}, button});
|
||||||
d->m_buttons.append(button);
|
d->m_buttons.append(button);
|
||||||
d->m_buttonGroup->addButton(button);
|
d->m_buttonGroup->addButton(button);
|
||||||
connect(button, &QAbstractButton::clicked, this, [this, i] {
|
connect(button, &QAbstractButton::clicked, this, [this, i] {
|
||||||
if (d->m_value != i) {
|
setValue(i);
|
||||||
d->m_value = i;
|
|
||||||
emit changed();
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
@@ -1076,35 +1086,14 @@ void SelectionAspect::addToLayout(LayoutBuilder &builder)
|
|||||||
d->m_comboBox = createSubWidget<QComboBox>();
|
d->m_comboBox = createSubWidget<QComboBox>();
|
||||||
for (int i = 0, n = d->m_options.size(); i < n; ++i)
|
for (int i = 0, n = d->m_options.size(); i < n; ++i)
|
||||||
d->m_comboBox->addItem(d->m_options.at(i).displayName);
|
d->m_comboBox->addItem(d->m_options.at(i).displayName);
|
||||||
connect(d->m_comboBox.data(), QOverload<int>::of(&QComboBox::activated), this,
|
connect(d->m_comboBox.data(), QOverload<int>::of(&QComboBox::activated),
|
||||||
[this](int index) {
|
this, &SelectionAspect::setValue);
|
||||||
if (d->m_value != index) {
|
d->m_comboBox->setCurrentIndex(value());
|
||||||
d->m_value = index;
|
|
||||||
emit changed();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
d->m_comboBox->setCurrentIndex(d->m_value);
|
|
||||||
builder.addItems({d->m_label.data(), d->m_comboBox.data()});
|
builder.addItems({d->m_label.data(), d->m_comboBox.data()});
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*!
|
|
||||||
\reimp
|
|
||||||
*/
|
|
||||||
void SelectionAspect::fromMap(const QVariantMap &map)
|
|
||||||
{
|
|
||||||
d->m_value = map.value(settingsKey(), d->m_defaultValue).toInt();
|
|
||||||
}
|
|
||||||
|
|
||||||
/*!
|
|
||||||
\reimp
|
|
||||||
*/
|
|
||||||
void SelectionAspect::toMap(QVariantMap &data) const
|
|
||||||
{
|
|
||||||
saveToMap(data, d->m_value, d->m_defaultValue);
|
|
||||||
}
|
|
||||||
|
|
||||||
void SelectionAspect::setVisibleDynamic(bool visible)
|
void SelectionAspect::setVisibleDynamic(bool visible)
|
||||||
{
|
{
|
||||||
if (d->m_label)
|
if (d->m_label)
|
||||||
@@ -1115,16 +1104,6 @@ void SelectionAspect::setVisibleDynamic(bool visible)
|
|||||||
button->setVisible(visible);
|
button->setVisible(visible);
|
||||||
}
|
}
|
||||||
|
|
||||||
int SelectionAspect::defaultValue() const
|
|
||||||
{
|
|
||||||
return d->m_defaultValue;
|
|
||||||
}
|
|
||||||
|
|
||||||
void SelectionAspect::setDefaultValue(int defaultValue)
|
|
||||||
{
|
|
||||||
d->m_defaultValue = defaultValue;
|
|
||||||
}
|
|
||||||
|
|
||||||
void SelectionAspect::setDisplayStyle(SelectionAspect::DisplayStyle style)
|
void SelectionAspect::setDisplayStyle(SelectionAspect::DisplayStyle style)
|
||||||
{
|
{
|
||||||
d->m_displayStyle = style;
|
d->m_displayStyle = style;
|
||||||
@@ -1132,22 +1111,23 @@ void SelectionAspect::setDisplayStyle(SelectionAspect::DisplayStyle style)
|
|||||||
|
|
||||||
int SelectionAspect::value() const
|
int SelectionAspect::value() const
|
||||||
{
|
{
|
||||||
return d->m_value;
|
return BaseAspect::value().toInt();
|
||||||
}
|
}
|
||||||
|
|
||||||
void SelectionAspect::setValue(int value)
|
void SelectionAspect::setValue(int value)
|
||||||
{
|
{
|
||||||
d->m_value = value;
|
if (BaseAspect::setValueQuietly(value)) {
|
||||||
if (d->m_buttonGroup && 0 <= value && value < d->m_buttons.size())
|
if (d->m_buttonGroup && 0 <= value && value < d->m_buttons.size())
|
||||||
d->m_buttons.at(value)->setChecked(true);
|
d->m_buttons.at(value)->setChecked(true);
|
||||||
else if (d->m_comboBox) {
|
else if (d->m_comboBox)
|
||||||
d->m_comboBox->setCurrentIndex(value);
|
d->m_comboBox->setCurrentIndex(value);
|
||||||
|
emit changed();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
QString SelectionAspect::stringValue() const
|
QString SelectionAspect::stringValue() const
|
||||||
{
|
{
|
||||||
return d->m_options.at(d->m_value).displayName;
|
return d->m_options.at(value()).displayName;
|
||||||
}
|
}
|
||||||
|
|
||||||
void SelectionAspect::addOption(const QString &displayName, const QString &toolTip)
|
void SelectionAspect::addOption(const QString &displayName, const QString &toolTip)
|
||||||
@@ -1167,8 +1147,10 @@ void SelectionAspect::addOption(const QString &displayName, const QString &toolT
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
MultiSelectionAspect::MultiSelectionAspect()
|
MultiSelectionAspect::MultiSelectionAspect()
|
||||||
: d(new Internal::MultiSelectionAspectPrivate)
|
: d(new Internal::MultiSelectionAspectPrivate(this))
|
||||||
{}
|
{
|
||||||
|
setDefaultValue(QStringList());
|
||||||
|
}
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
\reimp
|
\reimp
|
||||||
@@ -1188,10 +1170,10 @@ void MultiSelectionAspect::addToLayout(LayoutBuilder &builder)
|
|||||||
case DisplayStyle::ListView:
|
case DisplayStyle::ListView:
|
||||||
d->m_label = createSubWidget<QLabel>(d->m_labelText);
|
d->m_label = createSubWidget<QLabel>(d->m_labelText);
|
||||||
d->m_listView = createSubWidget<QListWidget>();
|
d->m_listView = createSubWidget<QListWidget>();
|
||||||
for (const QString &value : qAsConst(d->m_allValues)) {
|
for (const QString &val : qAsConst(d->m_allValues)) {
|
||||||
auto item = new QListWidgetItem(value, d->m_listView);
|
auto item = new QListWidgetItem(val, d->m_listView);
|
||||||
item->setFlags(item->flags() | Qt::ItemIsUserCheckable);
|
item->setFlags(item->flags() | Qt::ItemIsUserCheckable);
|
||||||
item->setCheckState(d->m_value.contains(item->text()) ? Qt::Checked : Qt::Unchecked);
|
item->setCheckState(value().contains(item->text()) ? Qt::Checked : Qt::Unchecked);
|
||||||
}
|
}
|
||||||
connect(d->m_listView, &QListWidget::itemChanged, this,
|
connect(d->m_listView, &QListWidget::itemChanged, this,
|
||||||
[this](QListWidgetItem *item) {
|
[this](QListWidgetItem *item) {
|
||||||
@@ -1202,14 +1184,17 @@ void MultiSelectionAspect::addToLayout(LayoutBuilder &builder)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Internal::MultiSelectionAspectPrivate::setValueSelectedHelper(const QString &value, bool on)
|
bool Internal::MultiSelectionAspectPrivate::setValueSelectedHelper(const QString &val, bool on)
|
||||||
{
|
{
|
||||||
if (on && !m_value.contains(value)) {
|
QStringList list = q->value();
|
||||||
m_value.append(value);
|
if (on && !list.contains(val)) {
|
||||||
|
list.append(val);
|
||||||
|
q->setValue(list);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
if (!on && m_value.contains(value)) {
|
if (!on && list.contains(val)) {
|
||||||
m_value.removeOne(value);
|
list.removeOne(val);
|
||||||
|
q->setValue(list);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
@@ -1230,34 +1215,6 @@ void MultiSelectionAspect::setLabelText(const QString &labelText)
|
|||||||
d->m_labelText = labelText;
|
d->m_labelText = labelText;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Internal::MultiSelectionAspectPrivate::updateListView()
|
|
||||||
{
|
|
||||||
if (!m_listView)
|
|
||||||
return;
|
|
||||||
const int n = m_listView->count();
|
|
||||||
QTC_CHECK(n == m_allValues.size());
|
|
||||||
for (int i = 0; i != n; ++i) {
|
|
||||||
auto item = m_listView->item(i);
|
|
||||||
item->setCheckState(m_value.contains(item->text()) ? Qt::Checked : Qt::Unchecked);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/*!
|
|
||||||
\reimp
|
|
||||||
*/
|
|
||||||
void MultiSelectionAspect::fromMap(const QVariantMap &map)
|
|
||||||
{
|
|
||||||
d->m_value = map.value(settingsKey(), QStringList()).toStringList();
|
|
||||||
}
|
|
||||||
|
|
||||||
/*!
|
|
||||||
\reimp
|
|
||||||
*/
|
|
||||||
void MultiSelectionAspect::toMap(QVariantMap &data) const
|
|
||||||
{
|
|
||||||
saveToMap(data, d->m_value, QStringList());
|
|
||||||
}
|
|
||||||
|
|
||||||
void MultiSelectionAspect::setVisibleDynamic(bool visible)
|
void MultiSelectionAspect::setVisibleDynamic(bool visible)
|
||||||
{
|
{
|
||||||
if (d->m_label)
|
if (d->m_label)
|
||||||
@@ -1273,16 +1230,23 @@ void MultiSelectionAspect::setDisplayStyle(MultiSelectionAspect::DisplayStyle st
|
|||||||
|
|
||||||
QStringList MultiSelectionAspect::value() const
|
QStringList MultiSelectionAspect::value() const
|
||||||
{
|
{
|
||||||
return d->m_value;
|
return BaseAspect::value().toStringList();
|
||||||
}
|
}
|
||||||
|
|
||||||
void MultiSelectionAspect::setValue(const QStringList &value)
|
void MultiSelectionAspect::setValue(const QStringList &value)
|
||||||
{
|
{
|
||||||
if (d->m_value == value)
|
if (BaseAspect::setValueQuietly(value)) {
|
||||||
return;
|
if (d->m_listView) {
|
||||||
d->m_value = value;
|
const int n = d->m_listView->count();
|
||||||
d->updateListView();
|
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);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
emit changed();
|
emit changed();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -1304,7 +1268,9 @@ void MultiSelectionAspect::setValue(const QStringList &value)
|
|||||||
|
|
||||||
IntegerAspect::IntegerAspect()
|
IntegerAspect::IntegerAspect()
|
||||||
: d(new Internal::IntegerAspectPrivate)
|
: d(new Internal::IntegerAspectPrivate)
|
||||||
{}
|
{
|
||||||
|
setDefaultValue(qint64(0));
|
||||||
|
}
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
\reimp
|
\reimp
|
||||||
@@ -1321,7 +1287,7 @@ void IntegerAspect::addToLayout(LayoutBuilder &builder)
|
|||||||
|
|
||||||
QTC_CHECK(!d->m_spinBox);
|
QTC_CHECK(!d->m_spinBox);
|
||||||
d->m_spinBox = createSubWidget<QSpinBox>();
|
d->m_spinBox = createSubWidget<QSpinBox>();
|
||||||
d->m_spinBox->setValue(int(d->m_value / d->m_displayScaleFactor));
|
d->m_spinBox->setValue(int(value() / d->m_displayScaleFactor));
|
||||||
d->m_spinBox->setDisplayIntegerBase(d->m_displayIntegerBase);
|
d->m_spinBox->setDisplayIntegerBase(d->m_displayIntegerBase);
|
||||||
d->m_spinBox->setPrefix(d->m_prefix);
|
d->m_spinBox->setPrefix(d->m_prefix);
|
||||||
d->m_spinBox->setSuffix(d->m_suffix);
|
d->m_spinBox->setSuffix(d->m_suffix);
|
||||||
@@ -1332,37 +1298,22 @@ void IntegerAspect::addToLayout(LayoutBuilder &builder)
|
|||||||
builder.addItems({d->m_label.data(), d->m_spinBox.data()});
|
builder.addItems({d->m_label.data(), d->m_spinBox.data()});
|
||||||
connect(d->m_spinBox.data(), QOverload<int>::of(&QSpinBox::valueChanged),
|
connect(d->m_spinBox.data(), QOverload<int>::of(&QSpinBox::valueChanged),
|
||||||
this, [this](int value) {
|
this, [this](int value) {
|
||||||
d->m_value = value * d->m_displayScaleFactor;
|
setValue(value * d->m_displayScaleFactor);
|
||||||
emit changed();
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
/*!
|
|
||||||
\reimp
|
|
||||||
*/
|
|
||||||
void IntegerAspect::fromMap(const QVariantMap &map)
|
|
||||||
{
|
|
||||||
d->m_value = map.value(settingsKey(), d->m_defaultValue).toLongLong();
|
|
||||||
}
|
|
||||||
|
|
||||||
/*!
|
|
||||||
\reimp
|
|
||||||
*/
|
|
||||||
void IntegerAspect::toMap(QVariantMap &data) const
|
|
||||||
{
|
|
||||||
saveToMap(data, d->m_value, d->m_defaultValue);
|
|
||||||
}
|
|
||||||
|
|
||||||
qint64 IntegerAspect::value() const
|
qint64 IntegerAspect::value() const
|
||||||
{
|
{
|
||||||
return d->m_value;
|
return BaseAspect::value().toLongLong();
|
||||||
}
|
}
|
||||||
|
|
||||||
void IntegerAspect::setValue(qint64 value)
|
void IntegerAspect::setValue(qint64 value)
|
||||||
{
|
{
|
||||||
d->m_value = value;
|
if (setValueQuietly(value)) {
|
||||||
if (d->m_spinBox)
|
if (d->m_spinBox)
|
||||||
d->m_spinBox->setValue(int(d->m_value / d->m_displayScaleFactor));
|
d->m_spinBox->setValue(int(value / d->m_displayScaleFactor));
|
||||||
|
emit changed();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void IntegerAspect::setRange(qint64 min, qint64 max)
|
void IntegerAspect::setRange(qint64 min, qint64 max)
|
||||||
@@ -1400,7 +1351,7 @@ void IntegerAspect::setDisplayScaleFactor(qint64 factor)
|
|||||||
|
|
||||||
void IntegerAspect::setDefaultValue(qint64 defaultValue)
|
void IntegerAspect::setDefaultValue(qint64 defaultValue)
|
||||||
{
|
{
|
||||||
d->m_defaultValue = defaultValue;
|
BaseAspect::setDefaultValue(defaultValue);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
@@ -1455,7 +1406,9 @@ TriState TriState::fromVariant(const QVariant &variant)
|
|||||||
|
|
||||||
StringListAspect::StringListAspect()
|
StringListAspect::StringListAspect()
|
||||||
: d(new Internal::StringListAspectPrivate)
|
: d(new Internal::StringListAspectPrivate)
|
||||||
{}
|
{
|
||||||
|
setDefaultValue(QStringList());
|
||||||
|
}
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
\reimp
|
\reimp
|
||||||
@@ -1471,30 +1424,14 @@ void StringListAspect::addToLayout(LayoutBuilder &builder)
|
|||||||
// TODO - when needed.
|
// TODO - when needed.
|
||||||
}
|
}
|
||||||
|
|
||||||
/*!
|
|
||||||
\reimp
|
|
||||||
*/
|
|
||||||
void StringListAspect::fromMap(const QVariantMap &map)
|
|
||||||
{
|
|
||||||
d->m_value = map.value(settingsKey()).toStringList();
|
|
||||||
}
|
|
||||||
|
|
||||||
/*!
|
|
||||||
\reimp
|
|
||||||
*/
|
|
||||||
void StringListAspect::toMap(QVariantMap &data) const
|
|
||||||
{
|
|
||||||
saveToMap(data, d->m_value, QStringList());
|
|
||||||
}
|
|
||||||
|
|
||||||
QStringList StringListAspect::value() const
|
QStringList StringListAspect::value() const
|
||||||
{
|
{
|
||||||
return d->m_value;
|
return BaseAspect::value().toStringList();
|
||||||
}
|
}
|
||||||
|
|
||||||
void StringListAspect::setValue(const QStringList &value)
|
void StringListAspect::setValue(const QStringList &value)
|
||||||
{
|
{
|
||||||
d->m_value = value;
|
BaseAspect::setValue(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
|
@@ -63,6 +63,13 @@ public:
|
|||||||
Utils::Id id() const;
|
Utils::Id id() const;
|
||||||
void setId(Utils::Id id);
|
void setId(Utils::Id id);
|
||||||
|
|
||||||
|
QVariant value() const;
|
||||||
|
void setValue(const QVariant &value);
|
||||||
|
bool setValueQuietly(const QVariant &value);
|
||||||
|
|
||||||
|
QVariant defaultValue() const;
|
||||||
|
void setDefaultValue(const QVariant &value);
|
||||||
|
|
||||||
QString settingsKey() const;
|
QString settingsKey() const;
|
||||||
void setSettingsKey(const QString &settingsKey);
|
void setSettingsKey(const QString &settingsKey);
|
||||||
void setSettingsKey(const QString &group, const QString &key);
|
void setSettingsKey(const QString &group, const QString &key);
|
||||||
@@ -84,8 +91,8 @@ public:
|
|||||||
void setConfigWidgetCreator(const ConfigWidgetCreator &configWidgetCreator);
|
void setConfigWidgetCreator(const ConfigWidgetCreator &configWidgetCreator);
|
||||||
QWidget *createConfigWidget() const;
|
QWidget *createConfigWidget() const;
|
||||||
|
|
||||||
virtual void fromMap(const QVariantMap &);
|
virtual void fromMap(const QVariantMap &map);
|
||||||
virtual void toMap(QVariantMap &) const;
|
virtual void toMap(QVariantMap &map) const;
|
||||||
virtual void acquaintSiblings(const BaseAspects &);
|
virtual void acquaintSiblings(const BaseAspects &);
|
||||||
|
|
||||||
virtual void addToLayout(LayoutBuilder &builder);
|
virtual void addToLayout(LayoutBuilder &builder);
|
||||||
@@ -170,16 +177,10 @@ public:
|
|||||||
bool value() const;
|
bool value() const;
|
||||||
void setValue(bool val);
|
void setValue(bool val);
|
||||||
|
|
||||||
bool defaultValue() const;
|
|
||||||
void setDefaultValue(bool defaultValue);
|
|
||||||
|
|
||||||
enum class LabelPlacement { AtCheckBox, AtCheckBoxWithoutDummyLabel, InExtraLabel };
|
enum class LabelPlacement { AtCheckBox, AtCheckBoxWithoutDummyLabel, InExtraLabel };
|
||||||
void setLabel(const QString &labelText,
|
void setLabel(const QString &labelText,
|
||||||
LabelPlacement labelPlacement = LabelPlacement::InExtraLabel);
|
LabelPlacement labelPlacement = LabelPlacement::InExtraLabel);
|
||||||
|
|
||||||
void fromMap(const QVariantMap &map) override;
|
|
||||||
void toMap(QVariantMap &map) const override;
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::unique_ptr<Internal::BoolAspectPrivate> d;
|
std::unique_ptr<Internal::BoolAspectPrivate> d;
|
||||||
};
|
};
|
||||||
@@ -199,17 +200,11 @@ public:
|
|||||||
|
|
||||||
QString stringValue() const;
|
QString stringValue() const;
|
||||||
|
|
||||||
int defaultValue() const;
|
|
||||||
void setDefaultValue(int defaultValue);
|
|
||||||
|
|
||||||
enum class DisplayStyle { RadioButtons, ComboBox };
|
enum class DisplayStyle { RadioButtons, ComboBox };
|
||||||
void setDisplayStyle(DisplayStyle style);
|
void setDisplayStyle(DisplayStyle style);
|
||||||
|
|
||||||
void addOption(const QString &displayName, const QString &toolTip = {});
|
void addOption(const QString &displayName, const QString &toolTip = {});
|
||||||
|
|
||||||
void fromMap(const QVariantMap &map) override;
|
|
||||||
void toMap(QVariantMap &map) const override;
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void setVisibleDynamic(bool visible) override;
|
void setVisibleDynamic(bool visible) override;
|
||||||
|
|
||||||
@@ -238,9 +233,6 @@ public:
|
|||||||
|
|
||||||
void setLabelText(const QString &labelText);
|
void setLabelText(const QString &labelText);
|
||||||
|
|
||||||
void fromMap(const QVariantMap &map) override;
|
|
||||||
void toMap(QVariantMap &map) const override;
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void setVisibleDynamic(bool visible) override;
|
void setVisibleDynamic(bool visible) override;
|
||||||
|
|
||||||
@@ -335,9 +327,6 @@ public:
|
|||||||
void setDisplayScaleFactor(qint64 factor);
|
void setDisplayScaleFactor(qint64 factor);
|
||||||
void setDefaultValue(qint64 defaultValue);
|
void setDefaultValue(qint64 defaultValue);
|
||||||
|
|
||||||
void fromMap(const QVariantMap &map) override;
|
|
||||||
void toMap(QVariantMap &map) const override;
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::unique_ptr<Internal::IntegerAspectPrivate> d;
|
std::unique_ptr<Internal::IntegerAspectPrivate> d;
|
||||||
};
|
};
|
||||||
@@ -390,9 +379,6 @@ public:
|
|||||||
QStringList value() const;
|
QStringList value() const;
|
||||||
void setValue(const QStringList &val);
|
void setValue(const QStringList &val);
|
||||||
|
|
||||||
void fromMap(const QVariantMap &map) override;
|
|
||||||
void toMap(QVariantMap &map) const override;
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::unique_ptr<Internal::StringListAspectPrivate> d;
|
std::unique_ptr<Internal::StringListAspectPrivate> d;
|
||||||
};
|
};
|
||||||
|
@@ -84,6 +84,7 @@ ConanInstallStep::ConanInstallStep(BuildStepList *bsl, Id id)
|
|||||||
buildMissing->setSettingsKey("ConanPackageManager.InstallStep.BuildMissing");
|
buildMissing->setSettingsKey("ConanPackageManager.InstallStep.BuildMissing");
|
||||||
buildMissing->setLabel("Build missing:", BoolAspect::LabelPlacement::InExtraLabel);
|
buildMissing->setLabel("Build missing:", BoolAspect::LabelPlacement::InExtraLabel);
|
||||||
buildMissing->setDefaultValue(true);
|
buildMissing->setDefaultValue(true);
|
||||||
|
buildMissing->setValue(true);
|
||||||
|
|
||||||
setCommandLineProvider([=] {
|
setCommandLineProvider([=] {
|
||||||
BuildConfiguration::BuildType bt = buildConfiguration()->buildType();
|
BuildConfiguration::BuildType bt = buildConfiguration()->buildType();
|
||||||
|
@@ -408,6 +408,7 @@ IosQmakeBuildConfiguration::IosQmakeBuildConfiguration(Target *target, Utils::Id
|
|||||||
|
|
||||||
m_autoManagedSigning = addAspect<BoolAspect>();
|
m_autoManagedSigning = addAspect<BoolAspect>();
|
||||||
m_autoManagedSigning->setDefaultValue(true);
|
m_autoManagedSigning->setDefaultValue(true);
|
||||||
|
m_autoManagedSigning->setValue(true);
|
||||||
m_autoManagedSigning->setSettingsKey(autoManagedSigningKey);
|
m_autoManagedSigning->setSettingsKey(autoManagedSigningKey);
|
||||||
|
|
||||||
connect(m_signingIdentifier,
|
connect(m_signingIdentifier,
|
||||||
@@ -506,6 +507,7 @@ IosCMakeBuildConfiguration::IosCMakeBuildConfiguration(Target *target, Id id)
|
|||||||
|
|
||||||
m_autoManagedSigning = addAspect<BoolAspect>();
|
m_autoManagedSigning = addAspect<BoolAspect>();
|
||||||
m_autoManagedSigning->setDefaultValue(true);
|
m_autoManagedSigning->setDefaultValue(true);
|
||||||
|
m_autoManagedSigning->setValue(true);
|
||||||
m_autoManagedSigning->setSettingsKey(autoManagedSigningKey);
|
m_autoManagedSigning->setSettingsKey(autoManagedSigningKey);
|
||||||
|
|
||||||
connect(m_signingIdentifier,
|
connect(m_signingIdentifier,
|
||||||
|
Reference in New Issue
Block a user