diff options
author | Nikolai Kosjar <nikolai.kosjar@theqtcompany.com> | 2015-02-17 17:47:41 +0100 |
---|---|---|
committer | Erik Verbruggen <erik.verbruggen@theqtcompany.com> | 2015-02-20 13:11:17 +0000 |
commit | 21e9893b4b04938e9341eedf2166f2dbf409a1dc (patch) | |
tree | a15c324bf0d1fcf254aa62c0138805398eab39b7 /src/plugins/cpptools/cppcompletion_test.cpp | |
parent | f3a2795c3bfc892695a46621e6bc97a2742d8766 (diff) | |
download | qt-creator-21e9893b4b04938e9341eedf2166f2dbf409a1dc.tar.gz |
CppTools: Fix completing qt5 style signals/slots in connect()
* Fix qualifying the member function, take namespace into account
* Fallback to usual completion if we cannot provide anything
* Ensure that the completion is not triggered outside connect() calls
* Change to a two step process:
1. connect(obj, & // offer class name completion
2. connect(obj, &N::Foo:: // offer signal completions
...same for the 4th. argument.
Change-Id: Ifa4c74cde1b96ec7c544daaeefc47c4efdd8294a
Reviewed-by: Erik Verbruggen <erik.verbruggen@theqtcompany.com>
Diffstat (limited to 'src/plugins/cpptools/cppcompletion_test.cpp')
-rw-r--r-- | src/plugins/cpptools/cppcompletion_test.cpp | 79 |
1 files changed, 55 insertions, 24 deletions
diff --git a/src/plugins/cpptools/cppcompletion_test.cpp b/src/plugins/cpptools/cppcompletion_test.cpp index e901021513..dd5bbe2ecd 100644 --- a/src/plugins/cpptools/cppcompletion_test.cpp +++ b/src/plugins/cpptools/cppcompletion_test.cpp @@ -2174,6 +2174,8 @@ void CppToolsPlugin::test_completion_data() "#define slots\n" "#define Q_OBJECT virtual const QMetaObject *metaObject() const;" "\n" + "namespace N {\n" + "\n" "class Base : public QObject\n" "{\n" " Q_OBJECT\n" @@ -2204,9 +2206,11 @@ void CppToolsPlugin::test_completion_data() " void derivedSlot2(int newValue);\n" "};\n" "\n" + "} // namespace N\n" + "\n" "void client()\n" "{\n" - " Derived *myObject = new Derived;\n" + " N::Derived *myObject = new N::Derived;\n" " @\n" "}\n"; @@ -2227,33 +2231,60 @@ void CppToolsPlugin::test_completion_data() << QLatin1String("derivedSlot1()") << QLatin1String("derivedSlot2(int)")); - QTest::newRow("Qt5 signal") + QTest::newRow("Qt5 signals: complete class after & at 2nd connect arg") << commonSignalSlotCompletionTestCode << _("connect(myObject, &") << (QStringList() - << QLatin1String("Base::baseSignal1") - << QLatin1String("Base::baseSignal2") - << QLatin1String("Base::hiddenSignal") - << QLatin1String("Derived::derivedSignal1") - << QLatin1String("Derived::derivedSignal2") - << QLatin1String("Derived::hiddenSignal")); // OK, hidden signal - - QTest::newRow("Qt5 slot") + << QLatin1String("N::Derived")); + + QTest::newRow("Qt5 signals: complete class after & at 4th connect arg") << commonSignalSlotCompletionTestCode << _("connect(myObject, &MyObject::timeout, myObject, &") << (QStringList() - << QLatin1String("Base::baseSignal1") - << QLatin1String("Base::baseSignal2") - << QLatin1String("Base::baseSlot1") - << QLatin1String("Base::baseSlot2") - << QLatin1String("Base::baseFunction") - << QLatin1String("Base::hiddenFunction") - << QLatin1String("Base::hiddenSignal") - << QLatin1String("Derived::derivedFunction") - << QLatin1String("Derived::derivedSignal1") - << QLatin1String("Derived::derivedSignal2") - << QLatin1String("Derived::derivedSlot1") - << QLatin1String("Derived::derivedSlot2") - << QLatin1String("Derived::hiddenFunction") - << QLatin1String("Derived::hiddenSignal")); + << QLatin1String("N::Derived")); + + QTest::newRow("Qt5 signals: complete signals") + << commonSignalSlotCompletionTestCode + << _("connect(myObject, &N::Derived::") << (QStringList() + << QLatin1String("baseSignal1") + << QLatin1String("baseSignal2") + << QLatin1String("hiddenSignal") + << QLatin1String("derivedSignal1") + << QLatin1String("derivedSignal2")); + + QTest::newRow("Qt5 slots") + << commonSignalSlotCompletionTestCode + << _("connect(myObject, &N::Derived, myObject, &N::Derived::") << (QStringList() + << QLatin1String("baseFunction") + << QLatin1String("baseSignal1") + << QLatin1String("baseSignal2") + << QLatin1String("baseSlot1") + << QLatin1String("baseSlot2") + << QLatin1String("derivedFunction") + << QLatin1String("derivedSignal1") + << QLatin1String("derivedSignal2") + << QLatin1String("derivedSlot1") + << QLatin1String("derivedSlot2") + << QLatin1String("hiddenFunction") + << QLatin1String("hiddenSignal")); + + QTest::newRow("Qt5 signals: no class name completion if not after 'connect(' 1") + << commonSignalSlotCompletionTestCode + << _("foo(myObject, &") << (QStringList()); + + QTest::newRow("Qt5 signals/slots: no class name completion if not after 'connect(' 2") + << commonSignalSlotCompletionTestCode + << _("&") << (QStringList()); + + QTest::newRow("Qt5 signals: fallback to scope completion") + << commonSignalSlotCompletionTestCode + << _("connect(myObject, &N::") << (QStringList() + << QLatin1String("Base") + << QLatin1String("Derived")); + + QTest::newRow("Qt5 slots: fallback to scope completion") + << commonSignalSlotCompletionTestCode + << _("connect(myObject, &N::Derived, myObject, &N::") << (QStringList() + << QLatin1String("Base") + << QLatin1String("Derived")); QTest::newRow("signals_hide_QPrivateSignal") << _( "#define SIGNAL(a) #a\n" |