summaryrefslogtreecommitdiffstats
path: root/tests/auto/widgets
diff options
context:
space:
mode:
authorChristian Ehrlicher <ch.ehrlicher@gmx.de>2019-09-25 19:54:49 +0200
committerChristian Ehrlicher <ch.ehrlicher@gmx.de>2019-11-14 19:59:23 +0100
commita4751f8824723acaee4b9d8aa78a59c2aa36cb3e (patch)
treeb5dfe245009cdcd73e3833f812e045ee7bfab8a5 /tests/auto/widgets
parent41702d8455a9e88ac70108e500a10e7bd4df2771 (diff)
QShortcut: add pmf ctor overloads
Provide pointer to member function overloads for the QShortcut ctor. The ctor with two functors but no contexts is not provided since it creates ambiguousness. [ChangeLog][QtWidgets][QShortcut] QShortcut ctor has now pmf overloads Fixes: QTBUG-77816 Change-Id: Ic9a759cde5150dbb94c2fd351b88ee8e447e0852 Reviewed-by: Paul Wicking <paul.wicking@qt.io> Reviewed-by: Samuel Gaist <samuel.gaist@idiap.ch> Reviewed-by: Friedemann Kleint <Friedemann.Kleint@qt.io> Reviewed-by: Richard Moe Gustavsen <richard.gustavsen@qt.io>
Diffstat (limited to 'tests/auto/widgets')
-rw-r--r--tests/auto/widgets/kernel/qshortcut/tst_qshortcut.cpp40
1 files changed, 40 insertions, 0 deletions
diff --git a/tests/auto/widgets/kernel/qshortcut/tst_qshortcut.cpp b/tests/auto/widgets/kernel/qshortcut/tst_qshortcut.cpp
index 82ab9c9c3b..aa687cfc3c 100644
--- a/tests/auto/widgets/kernel/qshortcut/tst_qshortcut.cpp
+++ b/tests/auto/widgets/kernel/qshortcut/tst_qshortcut.cpp
@@ -103,6 +103,7 @@ public slots:
private slots:
void cleanup();
+ void pmf_connect();
void number_data();
void number();
void text_data();
@@ -203,6 +204,45 @@ void tst_QShortcut::cleanup()
QVERIFY(QApplication::topLevelWidgets().size() <= 1); // The data driven tests keep a widget around
}
+void tst_QShortcut::pmf_connect()
+{
+ class MyObject : public QObject
+ {
+ public:
+ using QObject::QObject;
+ void onActivated() { ++activated; }
+ void onAmbiguous() { ++ambiguous; }
+ void reset() { activated = 0; ambiguous = 0; }
+ int activated = 0;
+ int ambiguous = 0;
+ } myObject;
+ QWidget parent;
+
+ auto runCheck = [&myObject](QShortcut *sc, int activated, int ambiguous)
+ {
+ myObject.reset();
+ sc->activated();
+ sc->activatedAmbiguously();
+ delete sc;
+ QCOMPARE(myObject.activated, activated);
+ QCOMPARE(myObject.ambiguous, ambiguous);
+ };
+
+ runCheck(new QShortcut(QKeySequence(), &parent,
+ [&myObject]() { ++myObject.activated; }),
+ 1, 0);
+ runCheck(new QShortcut(QKeySequence(), &parent,
+ &myObject, &MyObject::onActivated),
+ 1, 0);
+ runCheck(new QShortcut(QKeySequence(), &parent,
+ &myObject, &MyObject::onActivated, &MyObject::onAmbiguous),
+ 1, 1);
+ runCheck(new QShortcut(QKeySequence(), &parent, &myObject,
+ &MyObject::onActivated, &myObject, &MyObject::onAmbiguous),
+ 1, 1);
+}
+
+
Qt::KeyboardModifiers tst_QShortcut::toButtons( int key )
{
Qt::KeyboardModifiers result = Qt::NoModifier;