Widgets/QCheckBox: change signature of stateChanged() for Qt7

Change the signature of stateChanged(int) to emit Qt::CheckState
instead. This was forgotten during Qt6 porting so we have to wait for
Qt7.

Task-number: QTBUG-104688
Change-Id: Ica2504e5b9ae68612de81524faed0f31c9b10402
Reviewed-by: Friedemann Kleint <Friedemann.Kleint@qt.io>
Reviewed-by: Richard Moe Gustavsen <richard.gustavsen@qt.io>
This commit is contained in:
Christian Ehrlicher 2023-03-19 20:35:37 +01:00
parent 9020034b3b
commit 37b47ebf94
3 changed files with 34 additions and 14 deletions

View File

@ -28,7 +28,7 @@ public:
uint tristate : 1;
uint noChange : 1;
uint hovering : 1;
uint publishedState : 2;
Qt::CheckState publishedState : 2;
void init();
};
@ -89,6 +89,7 @@ public:
\sa QAbstractButton, QRadioButton
*/
#if QT_VERSION < QT_VERSION_CHECK(7, 0, 0)
/*!
\fn void QCheckBox::stateChanged(int state)
@ -97,6 +98,16 @@ public:
\a state contains the checkbox's new Qt::CheckState.
*/
#else
/*!
\fn void QCheckBox::stateChanged(Qt::CheckState state)
This signal is emitted whenever the checkbox's state changes, i.e.,
whenever the user checks or unchecks it.
\a state contains the checkbox's new Qt::CheckState.
*/
#endif
/*!
\property QCheckBox::tristate
@ -224,7 +235,7 @@ void QCheckBox::setCheckState(Qt::CheckState state)
setChecked(state != Qt::Unchecked);
d->blockRefresh = false;
d->refresh();
if ((uint)state != d->publishedState) {
if (state != d->publishedState) {
d->publishedState = state;
emit stateChanged(state);
}
@ -319,7 +330,7 @@ void QCheckBox::checkStateSet()
Q_D(QCheckBox);
d->noChange = false;
Qt::CheckState state = checkState();
if ((uint)state != d->publishedState) {
if (state != d->publishedState) {
d->publishedState = state;
emit stateChanged(state);
}

View File

@ -36,7 +36,11 @@ public:
void setCheckState(Qt::CheckState state);
Q_SIGNALS:
#if QT_VERSION < QT_VERSION_CHECK(7, 0, 0)
void stateChanged(int);
#else
void stateChanged(Qt::CheckState);
#endif
protected:
bool event(QEvent *e) override;

View File

@ -191,24 +191,29 @@ void tst_QCheckBox::toggled()
void tst_QCheckBox::stateChanged()
{
QCheckBox testWidget;
int cur_state = -1;
QCOMPARE(testWidget.checkState(), Qt::Unchecked);
Qt::CheckState cur_state = Qt::Unchecked;
QSignalSpy stateChangedSpy(&testWidget, &QCheckBox::stateChanged);
connect(&testWidget, &QCheckBox::stateChanged, this, [&](int state) { ++cur_state = state; });
connect(&testWidget, &QCheckBox::stateChanged, this, [&](auto state) { cur_state = Qt::CheckState(state); });
testWidget.setChecked(true);
QCoreApplication::processEvents();
QCOMPARE(cur_state, 2);
QVERIFY(QTest::qWaitFor([&]() { return stateChangedSpy.size() == 1; }));
QCOMPARE(stateChangedSpy.size(), 1);
QCOMPARE(cur_state, Qt::Checked);
QCOMPARE(testWidget.checkState(), Qt::Checked);
cur_state = -1;
testWidget.setChecked(false);
QCoreApplication::processEvents();
QCOMPARE(cur_state, 0);
QVERIFY(QTest::qWaitFor([&]() { return stateChangedSpy.size() == 2; }));
QCOMPARE(stateChangedSpy.size(), 2);
QCOMPARE(cur_state, Qt::Unchecked);
QCOMPARE(testWidget.checkState(), Qt::Unchecked);
cur_state = -1;
testWidget.setCheckState(Qt::PartiallyChecked);
QCoreApplication::processEvents();
QCOMPARE(cur_state, 1);
QVERIFY(QTest::qWaitFor([&]() { return stateChangedSpy.size() == 3; }));
QCOMPARE(stateChangedSpy.size(), 3);
QCOMPARE(cur_state, Qt::PartiallyChecked);
QCOMPARE(testWidget.checkState(), Qt::PartiallyChecked);
testWidget.setCheckState(Qt::PartiallyChecked);
QCoreApplication::processEvents();
QCOMPARE(stateChangedSpy.size(), 3);