Commit c6d326c0 authored by Thorbjørn Lindeijer's avatar Thorbjørn Lindeijer
Browse files

Some fixes to the new class wizard code generation

* Convert dots in filenames to underscores in header guards
* Don't indent closing namespaces in source file
* Consistent empty line placement
parent 71aeac59
......@@ -41,11 +41,14 @@ static QString toAlphaNum(const QString &s)
QString rc;
const int len = s.size();
const QChar underscore = QLatin1Char('_');
const QChar dot = QLatin1Char('.');
for (int i = 0; i < len; i++) {
const QChar c = s.at(i);
if (c == underscore || c.isLetterOrNumber())
rc += c;
else if (c == dot)
rc += underscore;
}
return rc;
}
......@@ -80,7 +83,6 @@ QString writeOpeningNameSpaces(const QStringList &l, const QString &indent,
str << rc << "namespace " << l.at(i) << " {\n";
rc += indent;
}
str << '\n';
}
return rc;
}
......
......@@ -230,19 +230,20 @@ bool CppClassWizard::generateHeaderAndSource(const CppClassWizardParameters &par
// == Header file ==
QTextStream headerStr(header);
headerStr << "#ifndef " << guard
<< "\n#define " << guard << '\n' << '\n';
<< "\n#define " << guard << '\n';
const QRegExp qtClassExpr(QLatin1String("^Q[A-Z3].+"));
QTC_ASSERT(qtClassExpr.isValid(), /**/);
const bool superIsQtClass = qtClassExpr.exactMatch(params.baseClass);
if (superIsQtClass) {
Core::Utils::writeIncludeFileDirective(params.baseClass, true, headerStr);
headerStr << '\n';
Core::Utils::writeIncludeFileDirective(params.baseClass, true, headerStr);
}
const QString namespaceIndent = Core::Utils::writeOpeningNameSpaces(namespaceList, 0, headerStr);
const QString namespaceIndent = Core::Utils::writeOpeningNameSpaces(namespaceList, QString(), headerStr);
// Class declaration
headerStr << '\n';
headerStr << namespaceIndent << "class " << unqualifiedClassName;
if (!params.baseClass.isEmpty())
headerStr << " : public " << params.baseClass << "\n";
......@@ -251,21 +252,23 @@ bool CppClassWizard::generateHeaderAndSource(const CppClassWizardParameters &par
headerStr << namespaceIndent << "{\n";
headerStr << namespaceIndent << "public:\n"
<< namespaceIndent << indent << unqualifiedClassName << "();\n";
headerStr << namespaceIndent << "};\n\n";
headerStr << namespaceIndent << "};\n";
Core::Utils::writeClosingNameSpaces(namespaceList, QString(), headerStr);
Core::Utils::writeClosingNameSpaces(namespaceList, 0, headerStr);
headerStr << '\n';
headerStr << "#endif // "<< guard << '\n';
// == Source file ==
QTextStream sourceStr(source);
Core::Utils::writeIncludeFileDirective(params.headerFile, false, sourceStr);
Core::Utils::writeOpeningNameSpaces(namespaceList, 0, sourceStr);
Core::Utils::writeOpeningNameSpaces(namespaceList, QString(), sourceStr);
// Constructor
sourceStr << '\n' << namespaceIndent << unqualifiedClassName << "::" << unqualifiedClassName << "()\n";
sourceStr << namespaceIndent << "{\n" << namespaceIndent << "}\n";
Core::Utils::writeClosingNameSpaces(namespaceList, indent, sourceStr);
Core::Utils::writeClosingNameSpaces(namespaceList, QString(), sourceStr);
return true;
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment