12void QButtonGroupPrivate::detectCheckedButton()
14 QAbstractButton *previous = checkedButton;
15 checkedButton =
nullptr;
18 for (
int i = 0; i < buttonList.size(); i++) {
19 if (buttonList.at(i) != previous && buttonList.at(i)->isChecked()) {
20 checkedButton = buttonList.at(i);
207void QButtonGroup::addButton(QAbstractButton *button,
int id)
210 if (QButtonGroup *previous = button->d_func()->group)
211 previous->removeButton(button);
212 button->d_func()->group =
this;
213 d->buttonList.append(button);
215 const auto it = std::min_element(d->mapping.cbegin(), d->mapping.cend());
216 if (it == d->mapping.cend())
217 d->mapping[button] = -2;
219 d->mapping[button] = (*it >= 0) ? -2 : (*it - 1);
221 d->mapping[button] = id;
224 if (d->exclusive && button->isChecked())
225 button->d_func()->notifyChecked();
233void QButtonGroup::removeButton(QAbstractButton *button)
236 if (d->checkedButton == button) {
237 d->detectCheckedButton();
239 if (button->d_func()->group ==
this) {
240 button->d_func()->group =
nullptr;
241 d->buttonList.removeAll(button);
242 d->mapping.remove(button);