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) ...@@ -41,11 +41,14 @@ static QString toAlphaNum(const QString &s)
QString rc; QString rc;
const int len = s.size(); const int len = s.size();
const QChar underscore = QLatin1Char('_'); const QChar underscore = QLatin1Char('_');
const QChar dot = QLatin1Char('.');
for (int i = 0; i < len; i++) { for (int i = 0; i < len; i++) {
const QChar c = s.at(i); const QChar c = s.at(i);
if (c == underscore || c.isLetterOrNumber()) if (c == underscore || c.isLetterOrNumber())
rc += c; rc += c;
else if (c == dot)
rc += underscore;
} }
return rc; return rc;
} }
...@@ -80,7 +83,6 @@ QString writeOpeningNameSpaces(const QStringList &l, const QString &indent, ...@@ -80,7 +83,6 @@ QString writeOpeningNameSpaces(const QStringList &l, const QString &indent,
str << rc << "namespace " << l.at(i) << " {\n"; str << rc << "namespace " << l.at(i) << " {\n";
rc += indent; rc += indent;
} }
str << '\n';
} }
return rc; return rc;
} }
......
...@@ -230,19 +230,20 @@ bool CppClassWizard::generateHeaderAndSource(const CppClassWizardParameters &par ...@@ -230,19 +230,20 @@ bool CppClassWizard::generateHeaderAndSource(const CppClassWizardParameters &par
// == Header file == // == Header file ==
QTextStream headerStr(header); QTextStream headerStr(header);
headerStr << "#ifndef " << guard headerStr << "#ifndef " << guard
<< "\n#define " << guard << '\n' << '\n'; << "\n#define " << guard << '\n';
const QRegExp qtClassExpr(QLatin1String("^Q[A-Z3].+")); const QRegExp qtClassExpr(QLatin1String("^Q[A-Z3].+"));
QTC_ASSERT(qtClassExpr.isValid(), /**/); QTC_ASSERT(qtClassExpr.isValid(), /**/);
const bool superIsQtClass = qtClassExpr.exactMatch(params.baseClass); const bool superIsQtClass = qtClassExpr.exactMatch(params.baseClass);
if (superIsQtClass) { if (superIsQtClass) {
Core::Utils::writeIncludeFileDirective(params.baseClass, true, headerStr);
headerStr << '\n'; 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 // Class declaration
headerStr << '\n';
headerStr << namespaceIndent << "class " << unqualifiedClassName; headerStr << namespaceIndent << "class " << unqualifiedClassName;
if (!params.baseClass.isEmpty()) if (!params.baseClass.isEmpty())
headerStr << " : public " << params.baseClass << "\n"; headerStr << " : public " << params.baseClass << "\n";
...@@ -251,21 +252,23 @@ bool CppClassWizard::generateHeaderAndSource(const CppClassWizardParameters &par ...@@ -251,21 +252,23 @@ bool CppClassWizard::generateHeaderAndSource(const CppClassWizardParameters &par
headerStr << namespaceIndent << "{\n"; headerStr << namespaceIndent << "{\n";
headerStr << namespaceIndent << "public:\n" headerStr << namespaceIndent << "public:\n"
<< namespaceIndent << indent << unqualifiedClassName << "();\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'; headerStr << "#endif // "<< guard << '\n';
// == Source file == // == Source file ==
QTextStream sourceStr(source); QTextStream sourceStr(source);
Core::Utils::writeIncludeFileDirective(params.headerFile, false, sourceStr); Core::Utils::writeIncludeFileDirective(params.headerFile, false, sourceStr);
Core::Utils::writeOpeningNameSpaces(namespaceList, 0, sourceStr); Core::Utils::writeOpeningNameSpaces(namespaceList, QString(), sourceStr);
// Constructor // Constructor
sourceStr << '\n' << namespaceIndent << unqualifiedClassName << "::" << unqualifiedClassName << "()\n"; sourceStr << '\n' << namespaceIndent << unqualifiedClassName << "::" << unqualifiedClassName << "()\n";
sourceStr << namespaceIndent << "{\n" << namespaceIndent << "}\n"; sourceStr << namespaceIndent << "{\n" << namespaceIndent << "}\n";
Core::Utils::writeClosingNameSpaces(namespaceList, indent, sourceStr); Core::Utils::writeClosingNameSpaces(namespaceList, QString(), sourceStr);
return true; return true;
} }
Supports Markdown
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