diff options
author | Tang Haixiang <tanghaixiang@uniontech.com> | 2022-01-24 18:11:14 +0800 |
---|---|---|
committer | Tang Haixiang <tanghaixiang@uniontech.com> | 2022-04-13 11:36:34 +0800 |
commit | 7a7023b7b1693ceaafcbafb30d41fb3a4c820a90 (patch) | |
tree | 7b794000c4963e618bb09e1d7f73e053aab888c7 /examples/widgets/graphicsview/chip | |
parent | 28e0c938bfabf582f2650d9ab1bc6190a2783a6e (diff) |
Chip example: fix an accidental bool->int conversion when using PMF connections
The example was refactored to use the PMF connection syntax.
However this introduced a problem: when connecting a QAbstractButton
to a slot that has a default parameter, the semantics of the connection
change between string-based connections and PMF.
Specifically: when connecting the
QAbstractButton::clicked(bool checked = false)
signal to a slot like
View::zoomIn(int level = 1)
then a string-based connection like
connect(button, SIGNAL(clicked()), this, SLOT(zoomIn()))
would call zoomIn without carrying the signal's parameter over.
In other words, zoomIn's parameter is defaulted. The same connection
using PFM instead is
connect(button, &QAbstractButton::clicked,
this, &View::zoomIn)
which would "connect" the arguments. This makes emissions that pass
false as clicked's parameter result in a zoomIn by 0.
Fix it by avoiding the default parameter of zoomIn -- just split
the function in two (zoomIn and zoomInBy).
Amends 8cf812231405e011b422a1505d9a219618fe5cee.
Pick-to: 5.15 6.2 6.3
Fixes: QTBUG-100135
Done-with: Giuseppe D'Angelo <giuseppe.dangelo@kdab.com>
Change-Id: I10c150c648034449e3154140108de2d64326d965
Reviewed-by: Giuseppe D'Angelo <giuseppe.dangelo@kdab.com>
Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
Diffstat (limited to 'examples/widgets/graphicsview/chip')
-rw-r--r-- | examples/widgets/graphicsview/chip/view.cpp | 18 | ||||
-rw-r--r-- | examples/widgets/graphicsview/chip/view.h | 6 |
2 files changed, 18 insertions, 6 deletions
diff --git a/examples/widgets/graphicsview/chip/view.cpp b/examples/widgets/graphicsview/chip/view.cpp index 186b24655b..736c9b6570 100644 --- a/examples/widgets/graphicsview/chip/view.cpp +++ b/examples/widgets/graphicsview/chip/view.cpp @@ -65,9 +65,9 @@ void GraphicsView::wheelEvent(QWheelEvent *e) { if (e->modifiers() & Qt::ControlModifier) { if (e->angleDelta().y() > 0) - view->zoomIn(6); + view->zoomInBy(6); else - view->zoomOut(6); + view->zoomOutBy(6); e->accept(); } else { QGraphicsView::wheelEvent(e); @@ -253,12 +253,22 @@ void View::print() #endif } -void View::zoomIn(int level) +void View::zoomIn() +{ + zoomSlider->setValue(zoomSlider->value() + 1); +} + +void View::zoomOut() +{ + zoomSlider->setValue(zoomSlider->value() - 1); +} + +void View::zoomInBy(int level) { zoomSlider->setValue(zoomSlider->value() + level); } -void View::zoomOut(int level) +void View::zoomOutBy(int level) { zoomSlider->setValue(zoomSlider->value() - level); } diff --git a/examples/widgets/graphicsview/chip/view.h b/examples/widgets/graphicsview/chip/view.h index b780702c34..5a200fa4f7 100644 --- a/examples/widgets/graphicsview/chip/view.h +++ b/examples/widgets/graphicsview/chip/view.h @@ -86,8 +86,10 @@ public: QGraphicsView *view() const; public slots: - void zoomIn(int level = 1); - void zoomOut(int level = 1); + void zoomIn(); + void zoomOut(); + void zoomInBy(int level); + void zoomOutBy(int level); private slots: void resetView(); |