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>
This commit is contained in:
parent
28e0c938bf
commit
7a7023b7b1
@ -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);
|
||||
}
|
||||
|
@ -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();
|
||||
|
Loading…
x
Reference in New Issue
Block a user