Skip to content

Commit

Permalink
CppEditor: Fix ConvertQt4Connect for different namespace
Browse files Browse the repository at this point in the history
Change-Id: I152d7cda02bb034bf817eeeb4b467667e1188b2f
Reviewed-by: Nikolai Kosjar <[email protected]>
  • Loading branch information
orgads committed Dec 15, 2015
1 parent 7bb2d83 commit e99aaf2
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/plugins/cppeditor/cppeditorplugin.h
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ private slots:
void test_quickfix_ConvertQt4Connect_connectOutOfClass();
void test_quickfix_ConvertQt4Connect_connectWithinClass_data();
void test_quickfix_ConvertQt4Connect_connectWithinClass();
void test_quickfix_ConvertQt4Connect_differentNamespace();

void test_quickfix_InsertDefFromDecl_afterClass();
void test_quickfix_InsertDefFromDecl_headerSource_basic1();
Expand Down
33 changes: 33 additions & 0 deletions src/plugins/cppeditor/cppquickfix_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4796,5 +4796,38 @@ void CppEditorPlugin::test_quickfix_ConvertQt4Connect_connectWithinClass()
QuickFixOperationTest(testDocuments, &factory);
}

void CppEditorPlugin::test_quickfix_ConvertQt4Connect_differentNamespace()
{
const QByteArray prefix =
"namespace NsA {\n"
"class ClassA : public QObject\n"
"{\n"
" static ClassA *instance();\n"
"signals:\n"
" void sig();\n"
"};\n"
"}\n"
"\n"
"namespace NsB {\n"
"class ClassB : public QObject\n"
"{\n"
" void slot();\n"
" void connector() {\n";

const QByteArray suffix = " }\n};\n}";

const QByteArray original = "co@nnect(NsA::ClassA::instance(), SIGNAL(sig()),\n"
" this, SLOT(slot()));\n";
const QByteArray expected = "connect(NsA::ClassA::instance(), &NsA::ClassA::sig,\n"
" this, &ClassB::slot);\n";
QList<QuickFixTestDocument::Ptr> testDocuments;
testDocuments << QuickFixTestDocument::create("file.cpp",
prefix + original + suffix,
prefix + expected + suffix);

ConvertQt4Connect factory;
QuickFixOperationTest(testDocuments, &factory);
}

} // namespace Internal
} // namespace CppEditor
5 changes: 4 additions & 1 deletion src/plugins/cppeditor/cppquickfixes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5783,7 +5783,10 @@ Class *senderOrReceiverClass(const CppQuickFixInterface &interface,
QTC_ASSERT(objectType, return 0);

ClassOrNamespace *objectClassCON = context.lookupType(objectType->name(), objectPointerScope);
QTC_ASSERT(objectClassCON, return 0);
if (!objectClassCON) {
objectClassCON = objectPointerExpressions.first().binding();
QTC_ASSERT(objectClassCON, return 0);
}
QTC_ASSERT(!objectClassCON->symbols().isEmpty(), return 0);

Symbol *objectClassSymbol = skipForwardDeclarations(objectClassCON->symbols());
Expand Down

0 comments on commit e99aaf2

Please sign in to comment.