QButtonGroup - add buttonToggled signals
QButtonGroup emits signals on clicked, pressed and released for buttons in the group, but for some (insuffienct) reason it did not emit anything for toggle (the only signal that it didn't emit anything for). This patch changes that, by adding handling of that signal to QButtonGroup. Task-number: QTBUG-14857 Change-Id: I88bcd7b060b78c7ff05ea1adf7baaddfe6d463be Reviewed-by: Friedemann Kleint <Friedemann.Kleint@digia.com> Reviewed-by: Giuseppe D'Angelo <giuseppe.dangelo@kdab.com>bb10
parent
ea94afca56
commit
fd871694e7
|
|
@ -575,6 +575,20 @@ void QAbstractButtonPrivate::emitReleased()
|
|||
#endif
|
||||
}
|
||||
|
||||
void QAbstractButtonPrivate::emitToggled(bool checked)
|
||||
{
|
||||
Q_Q(QAbstractButton);
|
||||
QPointer<QAbstractButton> guard(q);
|
||||
emit q->toggled(checked);
|
||||
#ifndef QT_NO_BUTTONGROUP
|
||||
if (guard && group) {
|
||||
emit group->buttonToggled(group->id(q), checked);
|
||||
if (guard && group)
|
||||
emit group->buttonToggled(q, checked);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
/*!
|
||||
Constructs an abstract button with a \a parent.
|
||||
*/
|
||||
|
|
@ -758,7 +772,7 @@ void QAbstractButton::setChecked(bool checked)
|
|||
if (guard && checked)
|
||||
d->notifyChecked();
|
||||
if (guard)
|
||||
emit toggled(checked);
|
||||
d->emitToggled(checked);
|
||||
|
||||
|
||||
#ifndef QT_NO_ACCESSIBILITY
|
||||
|
|
|
|||
|
|
@ -103,6 +103,7 @@ public:
|
|||
void emitPressed();
|
||||
void emitReleased();
|
||||
void emitClicked();
|
||||
void emitToggled(bool checked);
|
||||
};
|
||||
|
||||
QT_END_NAMESPACE
|
||||
|
|
|
|||
|
|
@ -173,6 +173,27 @@
|
|||
\sa QAbstractButton::released()
|
||||
*/
|
||||
|
||||
/*!
|
||||
\fn void QButtonGroup::buttonToggled(QAbstractButton *button, bool checked)
|
||||
\since 5.2
|
||||
|
||||
This signal is emitted when the given \a button is toggled.
|
||||
\a checked is true if the button is checked, or false if the button is unchecked.
|
||||
|
||||
\sa QAbstractButton::toggled()
|
||||
*/
|
||||
|
||||
/*!
|
||||
\fn void QButtonGroup::buttonToggled(int id, bool checked)
|
||||
\since 5.2
|
||||
|
||||
This signal is emitted when a button with the given \a id is toggled.
|
||||
\a checked is true if the button is checked, or false if the button is unchecked.
|
||||
|
||||
\sa QAbstractButton::toggled()
|
||||
*/
|
||||
|
||||
|
||||
/*!
|
||||
\fn void QButtonGroup::addButton(QAbstractButton *button, int id = -1);
|
||||
|
||||
|
|
|
|||
|
|
@ -85,7 +85,8 @@ Q_SIGNALS:
|
|||
void buttonPressed(int);
|
||||
void buttonReleased(QAbstractButton *);
|
||||
void buttonReleased(int);
|
||||
|
||||
void buttonToggled(QAbstractButton *, bool);
|
||||
void buttonToggled(int, bool);
|
||||
|
||||
private:
|
||||
Q_DISABLE_COPY(QButtonGroup)
|
||||
|
|
|
|||
|
|
@ -490,6 +490,12 @@ void tst_QAbstractButton::toggled()
|
|||
|
||||
QTest::mouseRelease( testWidget, Qt::LeftButton );
|
||||
QVERIFY( click_count == 1 );
|
||||
|
||||
testWidget->setCheckable(true);
|
||||
testWidget->toggle();
|
||||
testWidget->toggle();
|
||||
QCOMPARE(int(toggle_count), 2);
|
||||
testWidget->setCheckable(false);
|
||||
}
|
||||
|
||||
void tst_QAbstractButton::setShortcut()
|
||||
|
|
|
|||
|
|
@ -359,6 +359,26 @@ void tst_QButtonGroup::testSignals()
|
|||
QCOMPARE(releasedSpy.count(), 1);
|
||||
QCOMPARE(releasedIdSpy.count(), 1);
|
||||
QVERIFY(releasedIdSpy.takeFirst().at(0).toInt() == 23);
|
||||
|
||||
|
||||
QSignalSpy toggledSpy(&buttons, SIGNAL(buttonToggled(QAbstractButton*, bool)));
|
||||
QSignalSpy toggledIdSpy(&buttons, SIGNAL(buttonToggled(int, bool)));
|
||||
|
||||
pb1.setCheckable(true);
|
||||
pb2.setCheckable(true);
|
||||
pb1.toggle();
|
||||
QCOMPARE(toggledSpy.count(), 1);
|
||||
QCOMPARE(toggledIdSpy.count(), 1);
|
||||
|
||||
pb2.toggle();
|
||||
QCOMPARE(toggledSpy.count(), 3); // equals 3 since pb1 and pb2 are both toggled
|
||||
QCOMPARE(toggledIdSpy.count(), 3);
|
||||
|
||||
pb1.setCheckable(false);
|
||||
pb2.setCheckable(false);
|
||||
pb1.toggle();
|
||||
QCOMPARE(toggledSpy.count(), 3);
|
||||
QCOMPARE(toggledIdSpy.count(), 3);
|
||||
}
|
||||
|
||||
void tst_QButtonGroup::task106609()
|
||||
|
|
|
|||
Loading…
Reference in New Issue