summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThorbjørn Lindeijer <thorbjorn.lindeijer@nokia.com>2009-03-20 17:01:16 +0100
committerThorbjørn Lindeijer <thorbjorn.lindeijer@nokia.com>2009-03-20 17:04:23 +0100
commitc6d326c0bf2e2b1a7987fbf28f4ac0421ff1766f (patch)
treec9c5279ea353e693333e57d033d00de78014266a
parent71aeac5915880091f024b93869568fbeb2b016a0 (diff)
downloadqt-creator-c6d326c0bf2e2b1a7987fbf28f4ac0421ff1766f.tar.gz
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
-rw-r--r--src/libs/utils/codegeneration.cpp4
-rw-r--r--src/plugins/cppeditor/cppclasswizard.cpp17
2 files changed, 13 insertions, 8 deletions
diff --git a/src/libs/utils/codegeneration.cpp b/src/libs/utils/codegeneration.cpp
index 14448ea4b7..7e019b67c2 100644
--- a/src/libs/utils/codegeneration.cpp
+++ b/src/libs/utils/codegeneration.cpp
@@ -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;
}
diff --git a/src/plugins/cppeditor/cppclasswizard.cpp b/src/plugins/cppeditor/cppclasswizard.cpp
index d56875e213..ad574af51f 100644
--- a/src/plugins/cppeditor/cppclasswizard.cpp
+++ b/src/plugins/cppeditor/cppclasswizard.cpp
@@ -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;
}