diff options
author | Daniel Molkentin <daniel.molkentin@nokia.com> | 2009-05-05 16:50:31 (GMT) |
---|---|---|
committer | Maurice Kalinowski <maurice.kalinowski@nokia.com> | 2009-05-05 16:50:31 (GMT) |
commit | 98d485b54d2da97b83b7ff2379b31039923f922e (patch) | |
tree | 887938de47713a3c48a0c12f753117d4a0d4b9ba /src | |
parent | 2137f41ca0df3c83abce9dd386074e0fd09a33dc (diff) | |
download | Qt-98d485b54d2da97b83b7ff2379b31039923f922e.zip Qt-98d485b54d2da97b83b7ff2379b31039923f922e.tar.gz Qt-98d485b54d2da97b83b7ff2379b31039923f922e.tar.bz2 |
Fix behavior of QButtonGroup::addButton(QAbstractButton, int).
The method did not adhere to the documented behavior nor according to
its precedessor in Qt 3 times. Now, when being passed -1 as argument,
it will automatically assign ids. They will all be negative, starting
from -2.
Reviewed-by: mae <qt-info@nokia.com>
Diffstat (limited to 'src')
-rw-r--r-- | src/gui/widgets/qabstractbutton.cpp | 17 | ||||
-rw-r--r-- | src/gui/widgets/qbuttongroup.cpp | 16 |
2 files changed, 25 insertions, 8 deletions
diff --git a/src/gui/widgets/qabstractbutton.cpp b/src/gui/widgets/qabstractbutton.cpp index f2a9ceb..1900016 100644 --- a/src/gui/widgets/qabstractbutton.cpp +++ b/src/gui/widgets/qabstractbutton.cpp @@ -215,11 +215,8 @@ void QButtonGroup::setExclusive(bool exclusive) d->exclusive = exclusive; } -/*! - Adds the given \a button to the end of the group's internal list of buttons. - \sa removeButton() -*/ +// TODO: Qt 5: Merge with addButton(QAbstractButton *button, int id) void QButtonGroup::addButton(QAbstractButton *button) { addButton(button, -1); @@ -232,8 +229,18 @@ void QButtonGroup::addButton(QAbstractButton *button, int id) previous->removeButton(button); button->d_func()->group = this; d->buttonList.append(button); - if (id != -1) + if (id == -1) { + QList<int> ids = d->mapping.values(); + if (ids.isEmpty()) + d->mapping[button] = -2; + else { + qSort(ids); + d->mapping[button] = ids.first()-1; + } + } else { d->mapping[button] = id; + } + if (d->exclusive && button->isChecked()) button->d_func()->notifyChecked(); } diff --git a/src/gui/widgets/qbuttongroup.cpp b/src/gui/widgets/qbuttongroup.cpp index 06bcf1e..ebfafe3 100644 --- a/src/gui/widgets/qbuttongroup.cpp +++ b/src/gui/widgets/qbuttongroup.cpp @@ -176,11 +176,21 @@ */ /*! - \fn void QButtonGroup::addButton(QAbstractButton *button, int id = -1); + \fn void QButtonGroup::addButton(QAbstractButton *button); + + Adds the given \a button to the end of the group's internal list of buttons. + An \a id will be assigned to the button by this QButtonGroup. Automatically + assigned ids are guaranteed to be negative, starting with -2. If you are also + assigning your own ids, use positive values to avoid conflicts. + + \sa removeButton() buttons() +*/ + +/*! + \fn void QButtonGroup::addButton(QAbstractButton *button, int id); Adds the given \a button to the button group, with the given \a - id. If \a id is -1 (the default), an id will be assigned to the - button by this QButtonGroup. + id. It is recommended to assign only positive ids. \sa removeButton() buttons() */ |