Commit 0c60770f authored by Jarek Kobus's avatar Jarek Kobus
Browse files

Include namespaces inside header guard

Task: QTCREATORBUG-2724
RevBy: Friedemann Kleint <qtc-committer@nokia.com>
parent 11c6ca71
......@@ -58,10 +58,18 @@ QTCREATOR_UTILS_EXPORT QString fileNameToCppIdentifier(const QString &s)
QTCREATOR_UTILS_EXPORT QString headerGuard(const QString &file)
{
return headerGuard(file, QStringList());
}
QTCREATOR_UTILS_EXPORT QString headerGuard(const QString &file, const QStringList &namespaceList)
{
const QChar underscore = QLatin1Char('_');
QString rc;
for (int i = 0; i < namespaceList.count(); i++)
rc += namespaceList.at(i).toUpper() + underscore;
const QFileInfo fi(file);
QString rc = fileNameToCppIdentifier(fi.completeBaseName()).toUpper();
rc += QLatin1Char('_');
rc += fileNameToCppIdentifier(fi.suffix()).toUpper();
rc += fileNameToCppIdentifier(fi.fileName()).toUpper();
return rc;
}
......
......@@ -49,6 +49,7 @@ namespace Utils {
QTCREATOR_UTILS_EXPORT QString fileNameToCppIdentifier(const QString &s);
QTCREATOR_UTILS_EXPORT QString headerGuard(const QString &file);
QTCREATOR_UTILS_EXPORT QString headerGuard(const QString &file, const QStringList &namespaceList);
QTCREATOR_UTILS_EXPORT
void writeIncludeFileDirective(const QString &file,
......
......@@ -225,7 +225,7 @@ bool CppClassWizard::generateHeaderAndSource(const CppClassWizardParameters &par
params.className);
const QString unqualifiedClassName = namespaceList.takeLast();
const QString guard = Utils::headerGuard(params.headerFile);
const QString guard = Utils::headerGuard(params.headerFile, namespaceList);
// == Header file ==
QTextStream headerStr(header);
......
......@@ -149,7 +149,7 @@ bool QtDesignerFormClassCodeGenerator::generateCpp(const FormClassWizardParamete
const QString sourceLicense =
CppTools::AbstractEditorSupport::licenseTemplate(parameters.sourceFile, parameters.className);
// Include guards
const QString guard = Utils::headerGuard(parameters.headerFile);
const QString guard = Utils::headerGuard(parameters.headerFile, namespaceList);
QString uiInclude = QLatin1String("ui_");
uiInclude += QFileInfo(parameters.uiFile).completeBaseName();
......
......@@ -74,8 +74,15 @@ void LibraryParameters::generateCode(QtProjectParameters:: Type t,
const QString indent = QString(indentation, QLatin1Char(' '));
// Do we have namespaces?
QStringList namespaceList = className.split(QLatin1String("::"));
if (namespaceList.empty()) // Paranoia!
return;
const QString unqualifiedClassName = namespaceList.takeLast();
// 1) Header
const QString guard = Utils::headerGuard(headerFileName);
const QString guard = Utils::headerGuard(headerFileName, namespaceList);
headerStr << "#ifndef " << guard
<< "\n#define " << guard << '\n' << '\n';
......@@ -94,14 +101,6 @@ void LibraryParameters::generateCode(QtProjectParameters:: Type t,
headerStr << '\n';
}
// Do we have namespaces?
QStringList namespaceList = className.split(QLatin1String("::"));
if (namespaceList.empty()) // Paranoia!
return;
const QString unqualifiedClassName = namespaceList.back();
namespaceList.pop_back();
const QString namespaceIndent = Utils::writeOpeningNameSpaces(namespaceList, indent, headerStr);
// Class declaraction
......
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