From 2bd40c53ef54ff2c11ddb3b3acbd443a6429a8db Mon Sep 17 00:00:00 2001 From: Olivier Goffart Date: Wed, 21 Aug 2013 11:29:14 +0200 Subject: moc: Fix related objects containing itself This may happen when we have namespaces and the qualified name is used to scope an enum. Task-number: QTBUG-32933 Change-Id: Ic4923bbfb138387bae1e3694172661ace8342089 Reviewed-by: Alan Alpert Reviewed-by: Thiago Macieira --- src/tools/moc/generator.cpp | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) (limited to 'src/tools/moc') diff --git a/src/tools/moc/generator.cpp b/src/tools/moc/generator.cpp index 4757fdad93..3302d23ad4 100644 --- a/src/tools/moc/generator.cpp +++ b/src/tools/moc/generator.cpp @@ -184,6 +184,18 @@ bool Generator::registerableMetaType(const QByteArray &propertyType) return false; } +/* returns true if name and qualifiedName refers to the same name. + * If qualified name is "A::B::C", it returns true for "C", "B::C" or "A::B::C" */ +static bool qualifiedNameEquals(const QByteArray &qualifiedName, const QByteArray &name) +{ + if (qualifiedName == name) + return true; + int index = qualifiedName.indexOf("::"); + if (index == -1) + return false; + return qualifiedNameEquals(qualifiedName.mid(index+2), name); +} + void Generator::generateCode() { bool isQt = (cdef->classname == "Qt"); @@ -431,7 +443,7 @@ void Generator::generateCode() int s = p.type.lastIndexOf("::"); if (s > 0) { QByteArray scope = p.type.left(s); - if (scope != "Qt" && scope != cdef->classname && !extraList.contains(scope)) + if (scope != "Qt" && !qualifiedNameEquals(cdef->qualified, scope) && !extraList.contains(scope)) extraList += scope; } } @@ -446,7 +458,7 @@ void Generator::generateCode() int s = enumKey.lastIndexOf("::"); if (s > 0) { QByteArray scope = enumKey.left(s); - if (scope != "Qt" && scope != cdef->classname && !extraList.contains(scope)) + if (scope != "Qt" && !qualifiedNameEquals(cdef->qualified, scope) && !extraList.contains(scope)) extraList += scope; } } -- cgit v1.2.3