forked from qt-creator/qt-creator
Utils: Don't store widgets in BoolAspect
Change-Id: I185dbb32ccae6bff4e222f7a9d9cd6ccd6bdbc69 Reviewed-by: hjk <hjk@qt.io>
This commit is contained in:
@@ -701,10 +701,6 @@ class BoolAspectPrivate
|
|||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
BoolAspect::LabelPlacement m_labelPlacement = BoolAspect::LabelPlacement::AtCheckBox;
|
BoolAspect::LabelPlacement m_labelPlacement = BoolAspect::LabelPlacement::AtCheckBox;
|
||||||
QPointer<QAbstractButton> m_button; // Owned by configuration widget
|
|
||||||
QPointer<QGroupBox> m_groupBox; // For BoolAspects handling GroupBox check boxes
|
|
||||||
bool m_buttonIsAdopted = false;
|
|
||||||
|
|
||||||
UndoableValue<bool> m_undoable;
|
UndoableValue<bool> m_undoable;
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -1725,6 +1721,43 @@ BoolAspect::BoolAspect(AspectContainer *container)
|
|||||||
*/
|
*/
|
||||||
BoolAspect::~BoolAspect() = default;
|
BoolAspect::~BoolAspect() = default;
|
||||||
|
|
||||||
|
void BoolAspect::addToLayoutHelper(Layouting::LayoutItem &parent, QAbstractButton *button)
|
||||||
|
{
|
||||||
|
switch (d->m_labelPlacement) {
|
||||||
|
case LabelPlacement::Compact:
|
||||||
|
button->setText(labelText());
|
||||||
|
parent.addItem(button);
|
||||||
|
break;
|
||||||
|
case LabelPlacement::AtCheckBox:
|
||||||
|
button->setText(labelText());
|
||||||
|
parent.addItem(empty());
|
||||||
|
parent.addItem(button);
|
||||||
|
break;
|
||||||
|
case LabelPlacement::InExtraLabel:
|
||||||
|
addLabeledItem(parent, button);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
connect(button, &QAbstractButton::clicked, this, [button, this] {
|
||||||
|
pushUndo(d->m_undoable.set(button->isChecked()));
|
||||||
|
});
|
||||||
|
|
||||||
|
connect(&d->m_undoable.m_signal, &UndoSignaller::changed, button, [button, this] {
|
||||||
|
button->setChecked(d->m_undoable.get());
|
||||||
|
handleGuiChanged();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
LayoutItem BoolAspect::adoptButton(QAbstractButton *button)
|
||||||
|
{
|
||||||
|
LayoutItem parent;
|
||||||
|
|
||||||
|
addToLayoutHelper(parent, button);
|
||||||
|
|
||||||
|
bufferToGui();
|
||||||
|
return parent;
|
||||||
|
}
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
\reimp
|
\reimp
|
||||||
*/
|
*/
|
||||||
@@ -1732,45 +1765,11 @@ void BoolAspect::addToLayout(Layouting::LayoutItem &parent)
|
|||||||
{
|
{
|
||||||
QTC_ASSERT(m_buffer == m_internal, m_buffer = m_internal);
|
QTC_ASSERT(m_buffer == m_internal, m_buffer = m_internal);
|
||||||
|
|
||||||
if (!d->m_buttonIsAdopted) {
|
QCheckBox *checkBox = createSubWidget<QCheckBox>();
|
||||||
QTC_CHECK(!d->m_button);
|
addToLayoutHelper(parent, checkBox);
|
||||||
d->m_button = createSubWidget<QCheckBox>();
|
|
||||||
}
|
|
||||||
switch (d->m_labelPlacement) {
|
|
||||||
case LabelPlacement::Compact:
|
|
||||||
d->m_button->setText(labelText());
|
|
||||||
parent.addItem(d->m_button.data());
|
|
||||||
break;
|
|
||||||
case LabelPlacement::AtCheckBox:
|
|
||||||
d->m_button->setText(labelText());
|
|
||||||
parent.addItem(empty());
|
|
||||||
parent.addItem(d->m_button.data());
|
|
||||||
break;
|
|
||||||
case LabelPlacement::InExtraLabel:
|
|
||||||
addLabeledItem(parent, d->m_button);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
connect(d->m_button.data(), &QAbstractButton::clicked, this, [this] {
|
|
||||||
pushUndo(d->m_undoable.set(d->m_button->isChecked()));
|
|
||||||
});
|
|
||||||
|
|
||||||
connect(&d->m_undoable.m_signal, &UndoSignaller::changed, d->m_button, [this] {
|
|
||||||
d->m_button->setChecked(d->m_undoable.get());
|
|
||||||
handleGuiChanged();
|
|
||||||
});
|
|
||||||
bufferToGui();
|
bufferToGui();
|
||||||
}
|
}
|
||||||
|
|
||||||
void BoolAspect::adoptButton(QAbstractButton *button)
|
|
||||||
{
|
|
||||||
QTC_ASSERT(button, return);
|
|
||||||
QTC_CHECK(!d->m_button);
|
|
||||||
d->m_button = button;
|
|
||||||
d->m_buttonIsAdopted = true;
|
|
||||||
registerSubWidget(button);
|
|
||||||
}
|
|
||||||
|
|
||||||
std::function<void (QObject *)> BoolAspect::groupChecker()
|
std::function<void (QObject *)> BoolAspect::groupChecker()
|
||||||
{
|
{
|
||||||
return [this](QObject *target) {
|
return [this](QObject *target) {
|
||||||
@@ -1779,14 +1778,13 @@ std::function<void (QObject *)> BoolAspect::groupChecker()
|
|||||||
registerSubWidget(groupBox);
|
registerSubWidget(groupBox);
|
||||||
groupBox->setCheckable(true);
|
groupBox->setCheckable(true);
|
||||||
groupBox->setChecked(value());
|
groupBox->setChecked(value());
|
||||||
d->m_groupBox = groupBox;
|
|
||||||
|
|
||||||
connect(d->m_groupBox.data(), &QGroupBox::clicked, this, [this] {
|
connect(groupBox, &QGroupBox::clicked, this, [groupBox, this] {
|
||||||
pushUndo(d->m_undoable.set(d->m_groupBox->isChecked()));
|
pushUndo(d->m_undoable.set(groupBox->isChecked()));
|
||||||
});
|
});
|
||||||
|
|
||||||
connect(&d->m_undoable.m_signal, &UndoSignaller::changed, d->m_groupBox, [this] {
|
connect(&d->m_undoable.m_signal, &UndoSignaller::changed, groupBox, [groupBox, this] {
|
||||||
d->m_groupBox->setChecked(d->m_undoable.get());
|
groupBox->setChecked(d->m_undoable.get());
|
||||||
handleGuiChanged();
|
handleGuiChanged();
|
||||||
});
|
});
|
||||||
bufferToGui();
|
bufferToGui();
|
||||||
|
|||||||
@@ -438,9 +438,11 @@ public:
|
|||||||
LabelPlacement labelPlacement = LabelPlacement::InExtraLabel);
|
LabelPlacement labelPlacement = LabelPlacement::InExtraLabel);
|
||||||
void setLabelPlacement(LabelPlacement labelPlacement);
|
void setLabelPlacement(LabelPlacement labelPlacement);
|
||||||
|
|
||||||
void adoptButton(QAbstractButton *button);
|
Layouting::LayoutItem adoptButton(QAbstractButton *button);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
void addToLayoutHelper(Layouting::LayoutItem &parent, QAbstractButton *button);
|
||||||
|
|
||||||
void bufferToGui() override;
|
void bufferToGui() override;
|
||||||
bool guiToBuffer() override;
|
bool guiToBuffer() override;
|
||||||
|
|
||||||
|
|||||||
@@ -244,8 +244,6 @@ public:
|
|||||||
QGroupBox *options = nullptr;
|
QGroupBox *options = nullptr;
|
||||||
|
|
||||||
auto predefinedStyleButton = new QRadioButton;
|
auto predefinedStyleButton = new QRadioButton;
|
||||||
s.usePredefinedStyle.adoptButton(predefinedStyleButton);
|
|
||||||
|
|
||||||
auto customizedStyleButton = new QRadioButton(Tr::tr("Use customized style:"));
|
auto customizedStyleButton = new QRadioButton(Tr::tr("Use customized style:"));
|
||||||
|
|
||||||
auto styleButtonGroup = new QButtonGroup;
|
auto styleButtonGroup = new QButtonGroup;
|
||||||
@@ -261,7 +259,7 @@ public:
|
|||||||
auto fallbackBlob = Row { noMargin, Tr::tr("Fallback style:"), s.fallbackStyle }.emerge();
|
auto fallbackBlob = Row { noMargin, Tr::tr("Fallback style:"), s.fallbackStyle }.emerge();
|
||||||
|
|
||||||
auto predefinedBlob = Column { noMargin, s.predefinedStyle, fallbackBlob }.emerge();
|
auto predefinedBlob = Column { noMargin, s.predefinedStyle, fallbackBlob }.emerge();
|
||||||
|
// clang-format off
|
||||||
Column {
|
Column {
|
||||||
Group {
|
Group {
|
||||||
title(Tr::tr("Configuration")),
|
title(Tr::tr("Configuration")),
|
||||||
@@ -274,12 +272,13 @@ public:
|
|||||||
title(Tr::tr("Options")),
|
title(Tr::tr("Options")),
|
||||||
bindTo(&options),
|
bindTo(&options),
|
||||||
Form {
|
Form {
|
||||||
s.usePredefinedStyle, predefinedBlob, br,
|
s.usePredefinedStyle.adoptButton(predefinedStyleButton), predefinedBlob, br,
|
||||||
customizedStyleButton, configurations,
|
customizedStyleButton, configurations,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
st
|
st
|
||||||
}.attachTo(this);
|
}.attachTo(this);
|
||||||
|
// clang-format on
|
||||||
|
|
||||||
if (s.usePredefinedStyle.value())
|
if (s.usePredefinedStyle.value())
|
||||||
predefinedStyleButton->click();
|
predefinedStyleButton->click();
|
||||||
|
|||||||
Reference in New Issue
Block a user