Utils: Allow a BoolAspect to adopt an external button

This will be used by the apply machinery and allows more
complex setups than the automatically generated internal
CheckBox button.

Change-Id: I237a9283253f11bcb76e0366a0b6c5a0346fdfd8
Reviewed-by: <github-actions-qt-creator@cristianadam.eu>
Reviewed-by: Alessandro Portale <alessandro.portale@qt.io>
This commit is contained in:
hjk
2023-05-12 10:09:52 +02:00
parent 337497d990
commit a21b96f4b6
2 changed files with 16 additions and 2 deletions

View File

@@ -587,6 +587,7 @@ public:
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;
};
class ColorAspectPrivate
@@ -1446,8 +1447,10 @@ BoolAspect::~BoolAspect() = default;
*/
void BoolAspect::addToLayout(Layouting::LayoutItem &parent)
{
if (!d->m_buttonIsAdopted) {
QTC_CHECK(!d->m_button);
d->m_button = createSubWidget<QCheckBox>();
}
switch (d->m_labelPlacement) {
case LabelPlacement::AtCheckBoxWithoutDummyLabel:
d->m_button->setText(labelText());
@@ -1474,6 +1477,15 @@ void BoolAspect::addToLayout(Layouting::LayoutItem &parent)
this, &BoolAspect::volatileValueChanged);
}
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()
{
return [this](QObject *target) {

View File

@@ -240,6 +240,8 @@ public:
LabelPlacement labelPlacement = LabelPlacement::InExtraLabel);
void setLabelPlacement(LabelPlacement labelPlacement);
void adoptButton(QAbstractButton *button);
signals:
void valueChanged(bool newValue);
void volatileValueChanged(bool newValue);