Skip to content

Commit

Permalink
QButtonGroup: remove deprecated signals
Browse files Browse the repository at this point in the history
Task-number: QTBUG-80906
Change-Id: I6f697b0a070ba4c401117fe7cdf02429b47d9a11
Reviewed-by: Christian Ehrlicher <[email protected]>
  • Loading branch information
Vitaly Fanaskov committed Feb 2, 2020
1 parent 511cb76 commit 0b32560
Show file tree
Hide file tree
Showing 7 changed files with 22 additions and 132 deletions.
2 changes: 1 addition & 1 deletion examples/widgets/animation/easing/window.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ Window::Window(QWidget *parent)

connect(m_ui.easingCurvePicker, &QListWidget::currentRowChanged,
this, &Window::curveChanged);
connect(m_ui.buttonGroup, QOverload<QAbstractButton *>::of(&QButtonGroup::buttonClicked),
connect(m_ui.buttonGroup, &QButtonGroup::buttonClicked,
this, &Window::pathChanged);
connect(m_ui.periodSpinBox, QOverload<double>::of(&QDoubleSpinBox::valueChanged),
this, &Window::periodChanged);
Expand Down
11 changes: 6 additions & 5 deletions examples/widgets/widgets/icons/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -172,23 +172,24 @@ void MainWindow::changeStyle(bool checked)
//! [4]

//! [5]
void MainWindow::changeSize(int id, bool checked)
void MainWindow::changeSize(QAbstractButton *button, bool checked)
{
if (!checked)
return;

const bool other = id == int(OtherSize);
const int index = sizeButtonGroup->id(button);
const bool other = index == int(OtherSize);
const int extent = other
? otherSpinBox->value()
: QApplication::style()->pixelMetric(static_cast<QStyle::PixelMetric>(id));
: QApplication::style()->pixelMetric(static_cast<QStyle::PixelMetric>(index));

previewArea->setSize(QSize(extent, extent));
otherSpinBox->setEnabled(other);
}

void MainWindow::triggerChangeSize()
{
changeSize(sizeButtonGroup->checkedId(), true);
changeSize(sizeButtonGroup->checkedButton(), true);
}
//! [5]

Expand Down Expand Up @@ -372,7 +373,7 @@ QWidget *MainWindow::createIconSizeGroupBox()
sizeButtonGroup = new QButtonGroup(this);
sizeButtonGroup->setExclusive(true);

connect(sizeButtonGroup, QOverload<int, bool>::of(&QButtonGroup::buttonToggled),
connect(sizeButtonGroup, &QButtonGroup::buttonToggled,
this, &MainWindow::changeSize);

QRadioButton *smallRadioButton = new QRadioButton;
Expand Down
3 changes: 2 additions & 1 deletion examples/widgets/widgets/icons/mainwindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ class QActionGroup;
class QLabel;
class QButtonGroup;
class QTableWidget;
class QAbstractButton;
QT_END_NAMESPACE
class IconPreviewArea;
class IconSizeSpinBox;
Expand All @@ -81,7 +82,7 @@ class MainWindow : public QMainWindow
private slots:
void about();
void changeStyle(bool checked);
void changeSize(int, bool);
void changeSize(QAbstractButton *button, bool);
void triggerChangeSize();
void changeIcon();
void addSampleImages();
Expand Down
48 changes: 8 additions & 40 deletions src/widgets/widgets/qabstractbutton.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -413,16 +413,8 @@ void QAbstractButtonPrivate::emitClicked()
QPointer<QAbstractButton> guard(q);
emit q->clicked(checked);
#if QT_CONFIG(buttongroup)
if (guard && group) {
#if QT_DEPRECATED_SINCE(5, 15)
QT_WARNING_PUSH
QT_WARNING_DISABLE_DEPRECATED
emit group->buttonClicked(group->id(q));
if (guard && group)
QT_WARNING_POP
#endif
emit group->buttonClicked(q);
}
if (guard && group)
emit group->buttonClicked(q);
#endif
}

Expand All @@ -432,16 +424,8 @@ void QAbstractButtonPrivate::emitPressed()
QPointer<QAbstractButton> guard(q);
emit q->pressed();
#if QT_CONFIG(buttongroup)
if (guard && group) {
#if QT_DEPRECATED_SINCE(5, 15)
QT_WARNING_PUSH
QT_WARNING_DISABLE_DEPRECATED
emit group->buttonPressed(group->id(q));
if (guard && group)
QT_WARNING_POP
#endif
emit group->buttonPressed(q);
}
if (guard && group)
emit group->buttonPressed(q);
#endif
}

Expand All @@ -451,16 +435,8 @@ void QAbstractButtonPrivate::emitReleased()
QPointer<QAbstractButton> guard(q);
emit q->released();
#if QT_CONFIG(buttongroup)
if (guard && group) {
#if QT_DEPRECATED_SINCE(5, 15)
QT_WARNING_PUSH
QT_WARNING_DISABLE_DEPRECATED
emit group->buttonReleased(group->id(q));
if (guard && group)
QT_WARNING_POP
#endif
emit group->buttonReleased(q);
}
if (guard && group)
emit group->buttonReleased(q);
#endif
}

Expand All @@ -470,16 +446,8 @@ void QAbstractButtonPrivate::emitToggled(bool checked)
QPointer<QAbstractButton> guard(q);
emit q->toggled(checked);
#if QT_CONFIG(buttongroup)
if (guard && group) {
#if QT_DEPRECATED_SINCE(5, 15)
QT_WARNING_PUSH
QT_WARNING_DISABLE_DEPRECATED
emit group->buttonToggled(group->id(q), checked);
if (guard && group)
QT_WARNING_POP
#endif
emit group->buttonToggled(q, checked);
}
if (guard && group)
emit group->buttonToggled(q, checked);
#endif
}

Expand Down
43 changes: 0 additions & 43 deletions src/widgets/widgets/qbuttongroup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -162,16 +162,6 @@ void QButtonGroup::setExclusive(bool exclusive)
\sa checkedButton(), QAbstractButton::clicked()
*/

/*!
\fn void QButtonGroup::buttonClicked(int id)
\obsolete
This signal is emitted when a button with the given \a id is
clicked.
\sa checkedButton(), QAbstractButton::clicked()
*/

/*!
\fn void QButtonGroup::buttonPressed(QAbstractButton *button)
\since 4.2
Expand All @@ -181,17 +171,6 @@ void QButtonGroup::setExclusive(bool exclusive)
\sa QAbstractButton::pressed()
*/

/*!
\fn void QButtonGroup::buttonPressed(int id)
\since 4.2
\obsolete
This signal is emitted when a button with the given \a id is
pressed down.
\sa QAbstractButton::pressed()
*/

/*!
\fn void QButtonGroup::buttonReleased(QAbstractButton *button)
\since 4.2
Expand All @@ -201,17 +180,6 @@ void QButtonGroup::setExclusive(bool exclusive)
\sa QAbstractButton::released()
*/

/*!
\fn void QButtonGroup::buttonReleased(int id)
\since 4.2
\obsolete
This signal is emitted when a button with the given \a id is
released.
\sa QAbstractButton::released()
*/

/*!
\fn void QButtonGroup::buttonToggled(QAbstractButton *button, bool checked)
\since 5.2
Expand All @@ -222,17 +190,6 @@ void QButtonGroup::setExclusive(bool exclusive)
\sa QAbstractButton::toggled()
*/

/*!
\fn void QButtonGroup::buttonToggled(int id, bool checked)
\since 5.2
\obsolete
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()
*/


/*!
Adds the given \a button to the button group. If \a id is -1,
Expand Down
10 changes: 0 additions & 10 deletions src/widgets/widgets/qbuttongroup.h
Original file line number Diff line number Diff line change
Expand Up @@ -81,16 +81,6 @@ class Q_WIDGETS_EXPORT QButtonGroup : public QObject
void buttonPressed(QAbstractButton *);
void buttonReleased(QAbstractButton *);
void buttonToggled(QAbstractButton *, bool);
#if QT_DEPRECATED_SINCE(5, 15)
QT_DEPRECATED_VERSION_X_5_15("Use QButtonGroup::buttonClicked(QAbstractButton *) instead")
void buttonClicked(int);
QT_DEPRECATED_VERSION_X_5_15("Use QButtonGroup::buttonPressed(QAbstractButton *) instead")
void buttonPressed(int);
QT_DEPRECATED_VERSION_X_5_15("Use QButtonGroup::buttonReleased(QAbstractButton *) instead")
void buttonReleased(int);
QT_DEPRECATED_VERSION_X_5_15("Use QButtonGroup::buttonToggled(QAbstractButton *, bool) instead")
void buttonToggled(int, bool);
#endif

private:
Q_DISABLE_COPY(QButtonGroup)
Expand Down
37 changes: 5 additions & 32 deletions tests/auto/widgets/widgets/qbuttongroup/tst_qbuttongroup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -280,67 +280,43 @@ void tst_QButtonGroup::testSignals()

qRegisterMetaType<QAbstractButton *>("QAbstractButton *");
QSignalSpy clickedSpy(&buttons, SIGNAL(buttonClicked(QAbstractButton*)));
QSignalSpy clickedIdSpy(&buttons, SIGNAL(buttonClicked(int)));
QSignalSpy pressedSpy(&buttons, SIGNAL(buttonPressed(QAbstractButton*)));
QSignalSpy pressedIdSpy(&buttons, SIGNAL(buttonPressed(int)));
QSignalSpy releasedSpy(&buttons, SIGNAL(buttonReleased(QAbstractButton*)));
QSignalSpy releasedIdSpy(&buttons, SIGNAL(buttonReleased(int)));

pb1.animateClick();
QTestEventLoop::instance().enterLoop(1);

QCOMPARE(clickedSpy.count(), 1);
QCOMPARE(clickedIdSpy.count(), 1);

int expectedId = -2;

QCOMPARE(clickedIdSpy.takeFirst().at(0).toInt(), expectedId);
QCOMPARE(pressedSpy.count(), 1);
QCOMPARE(pressedIdSpy.count(), 1);
QCOMPARE(pressedIdSpy.takeFirst().at(0).toInt(), expectedId);
QCOMPARE(releasedSpy.count(), 1);
QCOMPARE(releasedIdSpy.count(), 1);
QCOMPARE(releasedIdSpy.takeFirst().at(0).toInt(), expectedId);

clickedSpy.clear();
clickedIdSpy.clear();
pressedSpy.clear();
pressedIdSpy.clear();
releasedSpy.clear();
releasedIdSpy.clear();

pb2.animateClick();
QTestEventLoop::instance().enterLoop(1);

QCOMPARE(clickedSpy.count(), 1);
QCOMPARE(clickedIdSpy.count(), 1);
QCOMPARE(clickedIdSpy.takeFirst().at(0).toInt(), 23);
QCOMPARE(pressedSpy.count(), 1);
QCOMPARE(pressedIdSpy.count(), 1);
QCOMPARE(pressedIdSpy.takeFirst().at(0).toInt(), 23);
QCOMPARE(releasedSpy.count(), 1);
QCOMPARE(releasedIdSpy.count(), 1);
QCOMPARE(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()
Expand Down Expand Up @@ -372,7 +348,6 @@ void tst_QButtonGroup::task106609()

qRegisterMetaType<QAbstractButton*>("QAbstractButton*");
QSignalSpy spy1(buttons, SIGNAL(buttonClicked(QAbstractButton*)));
QSignalSpy spy2(buttons, SIGNAL(buttonClicked(int)));

QApplication::setActiveWindow(&dlg);
QTRY_COMPARE(QApplication::activeWindow(), static_cast<QWidget*>(&dlg));
Expand All @@ -381,8 +356,6 @@ void tst_QButtonGroup::task106609()
radio1->setChecked(true);
QTestEventLoop::instance().enterLoop(1);

//qDebug() << "int:" << spy2.count() << "QAbstractButton*:" << spy1.count();
QCOMPARE(spy2.count(), 2);
QCOMPARE(spy1.count(), 2);
}

Expand Down Expand Up @@ -427,11 +400,12 @@ class task209485_ButtonDeleter : public QObject
: group(group)
, deleteButton(deleteButton)
{
connect(group, SIGNAL(buttonClicked(int)), SLOT(buttonClicked(int)));
connect(group, &QButtonGroup::buttonClicked,
this, &task209485_ButtonDeleter::buttonClicked);
}

private slots:
void buttonClicked(int)
void buttonClicked()
{
if (deleteButton)
group->removeButton(group->buttons().first());
Expand All @@ -447,7 +421,7 @@ void tst_QButtonGroup::task209485_removeFromGroupInEventHandler_data()
QTest::addColumn<bool>("deleteButton");
QTest::addColumn<int>("signalCount");
QTest::newRow("buttonPress 1") << true << 1;
QTest::newRow("buttonPress 2") << false << 2;
QTest::newRow("buttonPress 2") << false << 1;
}

void tst_QButtonGroup::task209485_removeFromGroupInEventHandler()
Expand All @@ -463,12 +437,11 @@ void tst_QButtonGroup::task209485_removeFromGroupInEventHandler()
task209485_ButtonDeleter buttonDeleter(&group, deleteButton);

QSignalSpy spy1(&group, SIGNAL(buttonClicked(QAbstractButton*)));
QSignalSpy spy2(&group, SIGNAL(buttonClicked(int)));

// NOTE: Reintroducing the bug of this task will cause the following line to crash:
QTest::mouseClick(button, Qt::LeftButton);

QCOMPARE(spy1.count() + spy2.count(), signalCount);
QCOMPARE(spy1.count(), signalCount);
}

void tst_QButtonGroup::autoIncrementId()
Expand Down

0 comments on commit 0b32560

Please sign in to comment.