diff options
author | Liang Qi <liang.qi@theqtcompany.com> | 2016-03-21 09:02:57 +0100 |
---|---|---|
committer | Liang Qi <liang.qi@theqtcompany.com> | 2016-03-21 09:02:57 +0100 |
commit | 6cb8121a44ee0f94f2c9fcb075d1d3c802d8c5c7 (patch) | |
tree | 25822898b71068f820d25a9e8372dfb348190ec1 /src/widgets/widgets/qabstractbutton.cpp | |
parent | 96740193e1e0f0608f67660811a44b696924ad4c (diff) | |
parent | 2e02de165115c9d67ac343ff0960ed80f9c09bc8 (diff) |
Merge remote-tracking branch 'origin/5.6' into 5.7
Conflicts:
src/widgets/styles/qgtkstyle_p.cpp
tests/auto/corelib/io/qtextstream/test/test.pro
tests/auto/corelib/plugin/plugin.pro
Change-Id: I512bc1b36acf3933ed2b96c00f476ee3819c1f4b
Diffstat (limited to 'src/widgets/widgets/qabstractbutton.cpp')
-rw-r--r-- | src/widgets/widgets/qabstractbutton.cpp | 137 |
1 files changed, 5 insertions, 132 deletions
diff --git a/src/widgets/widgets/qabstractbutton.cpp b/src/widgets/widgets/qabstractbutton.cpp index 9133664d77..44123d4dda 100644 --- a/src/widgets/widgets/qabstractbutton.cpp +++ b/src/widgets/widgets/qabstractbutton.cpp @@ -37,7 +37,9 @@ ** ****************************************************************************/ -#include "qabstractbutton.h" +#include "private/qabstractbutton_p.h" + +#include "private/qbuttongroup_p.h" #include "qabstractitemview.h" #include "qbuttongroup.h" #include "qabstractbutton_p.h" @@ -177,137 +179,6 @@ QAbstractButtonPrivate::QAbstractButtonPrivate(QSizePolicy::ControlType type) controlType(type) {} -#ifndef QT_NO_BUTTONGROUP - -class QButtonGroupPrivate: public QObjectPrivate -{ - Q_DECLARE_PUBLIC(QButtonGroup) - -public: - QButtonGroupPrivate():exclusive(true){} - QList<QAbstractButton *> buttonList; - QPointer<QAbstractButton> checkedButton; - void detectCheckedButton(); - void notifyChecked(QAbstractButton *button); - bool exclusive; - QHash<QAbstractButton*, int> mapping; -}; - -QButtonGroup::QButtonGroup(QObject *parent) - : QObject(*new QButtonGroupPrivate, parent) -{ -} - -QButtonGroup::~QButtonGroup() -{ - Q_D(QButtonGroup); - for (int i = 0; i < d->buttonList.count(); ++i) - d->buttonList.at(i)->d_func()->group = 0; -} - - -bool QButtonGroup::exclusive() const -{ - Q_D(const QButtonGroup); - return d->exclusive; -} - -void QButtonGroup::setExclusive(bool exclusive) -{ - Q_D(QButtonGroup); - d->exclusive = exclusive; -} - - -void QButtonGroup::addButton(QAbstractButton *button, int id) -{ - Q_D(QButtonGroup); - if (QButtonGroup *previous = button->d_func()->group) - previous->removeButton(button); - 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()); - if (it == d->mapping.cend()) - d->mapping[button] = -2; - else - d->mapping[button] = *it - 1; - } else { - d->mapping[button] = id; - } - - if (d->exclusive && button->isChecked()) - button->d_func()->notifyChecked(); -} - -void QButtonGroup::removeButton(QAbstractButton *button) -{ - Q_D(QButtonGroup); - if (d->checkedButton == button) { - d->detectCheckedButton(); - } - if (button->d_func()->group == this) { - button->d_func()->group = 0; - d->buttonList.removeAll(button); - d->mapping.remove(button); - } -} - -QList<QAbstractButton*> QButtonGroup::buttons() const -{ - Q_D(const QButtonGroup); - return d->buttonList; -} - -QAbstractButton *QButtonGroup::checkedButton() const -{ - Q_D(const QButtonGroup); - return d->checkedButton; -} - -QAbstractButton *QButtonGroup::button(int id) const -{ - Q_D(const QButtonGroup); - return d->mapping.key(id); -} - -void QButtonGroup::setId(QAbstractButton *button, int id) -{ - Q_D(QButtonGroup); - if (button && id != -1) - d->mapping[button] = id; -} - -int QButtonGroup::id(QAbstractButton *button) const -{ - Q_D(const QButtonGroup); - return d->mapping.value(button, -1); -} - -int QButtonGroup::checkedId() const -{ - Q_D(const QButtonGroup); - return d->mapping.value(d->checkedButton, -1); -} - -// detect a checked button other than the current one -void QButtonGroupPrivate::detectCheckedButton() -{ - QAbstractButton *previous = checkedButton; - checkedButton = 0; - if (exclusive) - return; - for (int i = 0; i < buttonList.count(); i++) { - if (buttonList.at(i) != previous && buttonList.at(i)->isChecked()) { - checkedButton = buttonList.at(i); - return; - } - } -} - -#endif // QT_NO_BUTTONGROUP - QList<QAbstractButton *>QAbstractButtonPrivate::queryButtonList() const { #ifndef QT_NO_BUTTONGROUP @@ -1419,3 +1290,5 @@ void QAbstractButton::setIconSize(const QSize &size) QT_END_NAMESPACE + +#include "moc_qabstractbutton.cpp" |