QButtonGroup: make sure to always auto-assign negative ids
QButtonGroup::addButton() automatically assigns a negative id when no id is given. This logic did not work out when a button with a positive id was added beforehand. Add a check to make sure to always return an auto-assigned negative id. Pick-to: 6.7 6.5 Fixes: QTBUG-129398 Change-Id: Ieadfa44c4b145184a5473713591f4c111a5dafa4 Reviewed-by: Axel Spoerl <axel.spoerl@qt.io> (cherry picked from commit 772d374ce715de9caaae4f026594d49f6da28dec) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
This commit is contained in:
parent
20bf08f012
commit
85af817469
@ -211,12 +211,11 @@ void QButtonGroup::addButton(QAbstractButton *button, int id)
|
||||
button->d_func()->group = this;
|
||||
d->buttonList.append(button);
|
||||
if (id == -1) {
|
||||
const QHash<QAbstractButton*, int>::const_iterator it
|
||||
= std::min_element(d->mapping.cbegin(), d->mapping.cend());
|
||||
const auto it = std::min_element(d->mapping.cbegin(), d->mapping.cend());
|
||||
if (it == d->mapping.cend())
|
||||
d->mapping[button] = -2;
|
||||
else
|
||||
d->mapping[button] = *it - 1;
|
||||
d->mapping[button] = (*it >= 0) ? -2 : (*it - 1);
|
||||
} else {
|
||||
d->mapping[button] = id;
|
||||
}
|
||||
|
@ -539,18 +539,18 @@ void tst_QButtonGroup::autoIncrementId()
|
||||
QRadioButton *radio3 = new QRadioButton(&dlg);
|
||||
radio3->setText("radio3");
|
||||
|
||||
buttons->addButton(radio1);
|
||||
buttons->addButton(radio1, 2);
|
||||
vbox->addWidget(radio1);
|
||||
buttons->addButton(radio2);
|
||||
buttons->addButton(radio2, -1);
|
||||
vbox->addWidget(radio2);
|
||||
buttons->addButton(radio3);
|
||||
vbox->addWidget(radio3);
|
||||
|
||||
radio1->setChecked(true);
|
||||
|
||||
QCOMPARE(buttons->id(radio1), -2);
|
||||
QCOMPARE(buttons->id(radio2), -3);
|
||||
QCOMPARE(buttons->id(radio3), -4);
|
||||
QCOMPARE(buttons->id(radio1), 2);
|
||||
QCOMPARE(buttons->id(radio2), -2);
|
||||
QCOMPARE(buttons->id(radio3), -3);
|
||||
|
||||
dlg.show();
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user