Commit 7ab30d8a authored by Friedemann Kleint's avatar Friedemann Kleint

C++-Settings/License template: Add %FILENAME%, %CLASS% placeholders.

... for doxygen. Change logic for known empty keywords to be replaced
by an empty string.

Task-number: QTCREATORBUG-1854
parent 934a9590
...@@ -233,14 +233,19 @@ bool CppClassWizard::generateHeaderAndSource(const CppClassWizardParameters &par ...@@ -233,14 +233,19 @@ bool CppClassWizard::generateHeaderAndSource(const CppClassWizardParameters &par
if (namespaceList.empty()) // Paranoia! if (namespaceList.empty()) // Paranoia!
return false; return false;
const QString license = CppTools::AbstractEditorSupport::licenseTemplate(); const QString headerLicense =
CppTools::AbstractEditorSupport::licenseTemplate(params.headerFile,
params.className);
const QString sourceLicense =
CppTools::AbstractEditorSupport::licenseTemplate(params.sourceFile,
params.className);
const QString unqualifiedClassName = namespaceList.takeLast(); const QString unqualifiedClassName = namespaceList.takeLast();
const QString guard = Utils::headerGuard(params.headerFile); const QString guard = Utils::headerGuard(params.headerFile);
// == Header file == // == Header file ==
QTextStream headerStr(header); QTextStream headerStr(header);
headerStr << license << "#ifndef " << guard headerStr << headerLicense << "#ifndef " << guard
<< "\n#define " << guard << '\n'; << "\n#define " << guard << '\n';
const QRegExp qtClassExpr(QLatin1String("^Q[A-Z3].+")); const QRegExp qtClassExpr(QLatin1String("^Q[A-Z3].+"));
...@@ -328,7 +333,7 @@ bool CppClassWizard::generateHeaderAndSource(const CppClassWizardParameters &par ...@@ -328,7 +333,7 @@ bool CppClassWizard::generateHeaderAndSource(const CppClassWizardParameters &par
// == Source file == // == Source file ==
QTextStream sourceStr(source); QTextStream sourceStr(source);
sourceStr << license; sourceStr << sourceLicense;
Utils::writeIncludeFileDirective(params.headerFile, false, sourceStr); Utils::writeIncludeFileDirective(params.headerFile, false, sourceStr);
if (params.classType == Utils::NewClassWidget::SharedDataClass) if (params.classType == Utils::NewClassWidget::SharedDataClass)
Utils::writeIncludeFileDirective(QLatin1String("QSharedData"), true, sourceStr); Utils::writeIncludeFileDirective(QLatin1String("QSharedData"), true, sourceStr);
......
...@@ -68,10 +68,9 @@ Core::GeneratedFiles CppFileWizard::generateFilesFromPath(const QString &path, ...@@ -68,10 +68,9 @@ Core::GeneratedFiles CppFileWizard::generateFilesFromPath(const QString &path,
QString CppFileWizard::fileContents(FileType type, const QString &fileName) const QString CppFileWizard::fileContents(FileType type, const QString &fileName) const
{ {
const QString baseName = QFileInfo(fileName).completeBaseName();
QString contents; QString contents;
QTextStream str(&contents); QTextStream str(&contents);
str << CppTools::AbstractEditorSupport::licenseTemplate(); str << CppTools::AbstractEditorSupport::licenseTemplate(fileName);
switch (type) { switch (type) {
case Header: { case Header: {
const QString guard = Utils::headerGuard(fileName); const QString guard = Utils::headerGuard(fileName);
......
...@@ -92,9 +92,9 @@ QString AbstractEditorSupport::functionAt(const CppModelManagerInterface *modelM ...@@ -92,9 +92,9 @@ QString AbstractEditorSupport::functionAt(const CppModelManagerInterface *modelM
return QString(); return QString();
} }
QString AbstractEditorSupport::licenseTemplate() QString AbstractEditorSupport::licenseTemplate(const QString &file, const QString &className)
{ {
return Internal::CppFileSettings::licenseTemplate(); return Internal::CppFileSettings::licenseTemplate(file, className);
} }
} }
...@@ -41,6 +41,7 @@ ...@@ -41,6 +41,7 @@
#include <QtCore/QSettings> #include <QtCore/QSettings>
#include <QtCore/QDebug> #include <QtCore/QDebug>
#include <QtCore/QFile> #include <QtCore/QFile>
#include <QtCore/QFileInfo>
#include <QtCore/QCoreApplication> #include <QtCore/QCoreApplication>
#include <QtCore/QDate> #include <QtCore/QDate>
#include <QtCore/QLocale> #include <QtCore/QLocale>
...@@ -106,10 +107,22 @@ bool CppFileSettings::equals(const CppFileSettings &rhs) const ...@@ -106,10 +107,22 @@ bool CppFileSettings::equals(const CppFileSettings &rhs) const
} }
// Replacements of special license template keywords. // Replacements of special license template keywords.
static QString keyWordReplacement(const QString &keyWord) static bool keyWordReplacement(const QString &keyWord,
const QString &file,
const QString &className,
QString *value)
{ {
if (keyWord == QLatin1String("%YEAR%")) { if (keyWord == QLatin1String("%YEAR%")) {
return QString::number(QDate::currentDate().year()); *value = QString::number(QDate::currentDate().year());
return true;
}
if (keyWord == QLatin1String("%CLASS%")) {
*value = className;
return true;
}
if (keyWord == QLatin1String("%FILENAME%")) {
*value = QFileInfo(file).fileName();
return true;
} }
if (keyWord == QLatin1String("%DATE%")) { if (keyWord == QLatin1String("%DATE%")) {
static QString format; static QString format;
...@@ -121,26 +134,29 @@ static QString keyWordReplacement(const QString &keyWord) ...@@ -121,26 +134,29 @@ static QString keyWordReplacement(const QString &keyWord)
if (format.count(ypsilon) == 2) if (format.count(ypsilon) == 2)
format.insert(format.indexOf(ypsilon), QString(2, ypsilon)); format.insert(format.indexOf(ypsilon), QString(2, ypsilon));
} }
return QDate::currentDate().toString(format); *value = QDate::currentDate().toString(format);
return true;
} }
if (keyWord == QLatin1String("%USER%")) { if (keyWord == QLatin1String("%USER%")) {
#ifdef Q_OS_WIN #ifdef Q_OS_WIN
return QString::fromLocal8Bit(qgetenv("USERNAME")); *value = QString::fromLocal8Bit(qgetenv("USERNAME"));
#else #else
return QString::fromLocal8Bit(qgetenv("USER")); *value = QString::fromLocal8Bit(qgetenv("USER"));
#endif #endif
return true;
} }
// Environment variables (for example '%$EMAIL%'). // Environment variables (for example '%$EMAIL%').
if (keyWord.startsWith(QLatin1String("%$"))) { if (keyWord.startsWith(QLatin1String("%$"))) {
const QString varName = keyWord.mid(2, keyWord.size() - 3); const QString varName = keyWord.mid(2, keyWord.size() - 3);
return QString::fromLocal8Bit(qgetenv(varName.toLocal8Bit())); *value = QString::fromLocal8Bit(qgetenv(varName.toLocal8Bit()));
return true;
} }
return QString(); return false;
} }
// Parse a license template, scan for %KEYWORD% and replace if known. // Parse a license template, scan for %KEYWORD% and replace if known.
// Replace '%%' by '%'. // Replace '%%' by '%'.
static void parseLicenseTemplatePlaceholders(QString *t) static void parseLicenseTemplatePlaceholders(QString *t, const QString &file, const QString &className)
{ {
int pos = 0; int pos = 0;
const QChar placeHolder = QLatin1Char('%'); const QChar placeHolder = QLatin1Char('%');
...@@ -156,19 +172,20 @@ static void parseLicenseTemplatePlaceholders(QString *t) ...@@ -156,19 +172,20 @@ static void parseLicenseTemplatePlaceholders(QString *t)
pos = placeHolderPos + 1; pos = placeHolderPos + 1;
} else { } else {
const QString keyWord = t->mid(placeHolderPos, endPlaceHolderPos + 1 - placeHolderPos); const QString keyWord = t->mid(placeHolderPos, endPlaceHolderPos + 1 - placeHolderPos);
const QString replacement = keyWordReplacement(keyWord); QString replacement;
if (replacement.isEmpty()) { if (keyWordReplacement(keyWord, file, className, &replacement)) {
pos = endPlaceHolderPos + 1;
} else {
t->replace(placeHolderPos, keyWord.size(), replacement); t->replace(placeHolderPos, keyWord.size(), replacement);
pos = placeHolderPos + replacement.size(); pos = placeHolderPos + replacement.size();
} else {
// Leave invalid keywords as is.
pos = endPlaceHolderPos + 1;
} }
} }
} while (pos < t->size()); } while (pos < t->size());
} }
// Convenience that returns the formatted license template. // Convenience that returns the formatted license template.
QString CppFileSettings::licenseTemplate() QString CppFileSettings::licenseTemplate(const QString &fileName, const QString &className)
{ {
const QSettings *s = Core::ICore::instance()->settings(); const QSettings *s = Core::ICore::instance()->settings();
...@@ -184,7 +201,7 @@ QString CppFileSettings::licenseTemplate() ...@@ -184,7 +201,7 @@ QString CppFileSettings::licenseTemplate()
return QString(); return QString();
} }
QString license = QString::fromUtf8(file.readAll()); QString license = QString::fromUtf8(file.readAll());
parseLicenseTemplatePlaceholders(&license); parseLicenseTemplatePlaceholders(&license, fileName, className);
// Ensure exactly one additional new line separating stuff // Ensure exactly one additional new line separating stuff
const QChar newLine = QLatin1Char('\n'); const QChar newLine = QLatin1Char('\n');
if (!license.endsWith(newLine)) if (!license.endsWith(newLine))
......
...@@ -60,7 +60,7 @@ struct CppFileSettings ...@@ -60,7 +60,7 @@ struct CppFileSettings
// Convenience to return a license template completely formatted. // Convenience to return a license template completely formatted.
// Currently made public in // Currently made public in
static QString licenseTemplate(); static QString licenseTemplate(const QString &file = QString(), const QString &className = QString());
bool equals(const CppFileSettings &rhs) const; bool equals(const CppFileSettings &rhs) const;
}; };
......
...@@ -170,7 +170,7 @@ public: ...@@ -170,7 +170,7 @@ public:
const QString &fileName, const QString &fileName,
int line, int column); int line, int column);
static QString licenseTemplate(); static QString licenseTemplate(const QString &file = QString(), const QString &className = QString());
private: private:
CppModelManagerInterface *m_modelmanager; CppModelManagerInterface *m_modelmanager;
......
...@@ -341,7 +341,10 @@ bool FormClassWizardParametersPrivate::generateCpp(const FormClassWizardGenerati ...@@ -341,7 +341,10 @@ bool FormClassWizardParametersPrivate::generateCpp(const FormClassWizardGenerati
const QString unqualifiedClassName = namespaceList.takeLast(); const QString unqualifiedClassName = namespaceList.takeLast();
const QString license = CppTools::AbstractEditorSupport::licenseTemplate(); const QString headerLicense =
CppTools::AbstractEditorSupport::licenseTemplate(headerFile, className);
const QString sourceLicense =
CppTools::AbstractEditorSupport::licenseTemplate(sourceFile, className);
// Include guards // Include guards
const QString guard = Utils::headerGuard(headerFile); const QString guard = Utils::headerGuard(headerFile);
...@@ -351,7 +354,7 @@ bool FormClassWizardParametersPrivate::generateCpp(const FormClassWizardGenerati ...@@ -351,7 +354,7 @@ bool FormClassWizardParametersPrivate::generateCpp(const FormClassWizardGenerati
// 1) Header file // 1) Header file
QTextStream headerStr(header); QTextStream headerStr(header);
headerStr << license << "#ifndef " << guard headerStr << headerLicense << "#ifndef " << guard
<< "\n#define " << guard << '\n' << '\n'; << "\n#define " << guard << '\n' << '\n';
// Include 'ui_' // Include 'ui_'
...@@ -409,7 +412,7 @@ bool FormClassWizardParametersPrivate::generateCpp(const FormClassWizardGenerati ...@@ -409,7 +412,7 @@ bool FormClassWizardParametersPrivate::generateCpp(const FormClassWizardGenerati
// 2) Source file // 2) Source file
QTextStream sourceStr(source); QTextStream sourceStr(source);
sourceStr << license; sourceStr << sourceLicense;
Utils::writeIncludeFileDirective(headerFile, false, sourceStr); Utils::writeIncludeFileDirective(headerFile, false, sourceStr);
if (embedding == FormClassWizardGenerationParameters::PointerAggregatedUiClass) if (embedding == FormClassWizardGenerationParameters::PointerAggregatedUiClass)
Utils::writeIncludeFileDirective(uiInclude, false, sourceStr); Utils::writeIncludeFileDirective(uiInclude, false, sourceStr);
......
...@@ -33,7 +33,6 @@ ...@@ -33,7 +33,6 @@
#include "pluginoptions.h" #include "pluginoptions.h"
#include "filenamingparameters.h" #include "filenamingparameters.h"
#include <cpptools/cppmodelmanagerinterface.h>
#include <projectexplorer/projectexplorerconstants.h> #include <projectexplorer/projectexplorerconstants.h>
#include <QtGui/QIcon> #include <QtGui/QIcon>
...@@ -71,7 +70,6 @@ Core::GeneratedFiles CustomWidgetWizard::generateFiles(const QWizard *w, ...@@ -71,7 +70,6 @@ Core::GeneratedFiles CustomWidgetWizard::generateFiles(const QWizard *w,
GenerationParameters p; GenerationParameters p;
p.fileName = cw->projectName(); p.fileName = cw->projectName();
p.path = cw->path(); p.path = cw->path();
p.license = CppTools::AbstractEditorSupport::licenseTemplate();
p.templatePath = QtWizard::templateDir(); p.templatePath = QtWizard::templateDir();
p.templatePath += QLatin1String("/customwidgetwizard"); p.templatePath += QLatin1String("/customwidgetwizard");
return PluginGenerator::generatePlugin(p, *(cw->pluginOptions()), errorMessage); return PluginGenerator::generatePlugin(p, *(cw->pluginOptions()), errorMessage);
......
...@@ -32,6 +32,8 @@ ...@@ -32,6 +32,8 @@
#include <coreplugin/basefilewizard.h> #include <coreplugin/basefilewizard.h>
#include <cpptools/cppmodelmanagerinterface.h>
#include <QtCore/QFileInfo> #include <QtCore/QFileInfo>
#include <QtCore/QDir> #include <QtCore/QDir>
#include <QtCore/QSet> #include <QtCore/QSet>
...@@ -103,7 +105,8 @@ QList<Core::GeneratedFile> PluginGenerator::generatePlugin(const GenerationPara ...@@ -103,7 +105,8 @@ QList<Core::GeneratedFile> PluginGenerator::generatePlugin(const GenerationPara
if (pluginHeaderContents.isEmpty()) if (pluginHeaderContents.isEmpty())
return QList<Core::GeneratedFile>(); return QList<Core::GeneratedFile>();
Core::GeneratedFile pluginHeader(baseDir + wo.pluginHeaderFile); Core::GeneratedFile pluginHeader(baseDir + wo.pluginHeaderFile);
pluginHeader.setContents(p.license + pluginHeaderContents); pluginHeader.setContents(CppTools::AbstractEditorSupport::licenseTemplate(wo.pluginHeaderFile, wo.pluginClassName)
+ pluginHeaderContents);
rc.push_back(pluginHeader); rc.push_back(pluginHeader);
sm.remove(QLatin1String("SINGLE_INCLUDE_GUARD")); sm.remove(QLatin1String("SINGLE_INCLUDE_GUARD"));
...@@ -134,7 +137,8 @@ QList<Core::GeneratedFile> PluginGenerator::generatePlugin(const GenerationPara ...@@ -134,7 +137,8 @@ QList<Core::GeneratedFile> PluginGenerator::generatePlugin(const GenerationPara
if (pluginSourceContents.isEmpty()) if (pluginSourceContents.isEmpty())
return QList<Core::GeneratedFile>(); return QList<Core::GeneratedFile>();
Core::GeneratedFile pluginSource(baseDir + wo.pluginSourceFile); Core::GeneratedFile pluginSource(baseDir + wo.pluginSourceFile);
pluginSource.setContents(p.license + pluginSourceContents); pluginSource.setContents(CppTools::AbstractEditorSupport::licenseTemplate(wo.pluginSourceFile, wo.pluginClassName)
+ pluginSourceContents);
if (i == 0 && widgetCount == 1) // Open first widget unless collection if (i == 0 && widgetCount == 1) // Open first widget unless collection
pluginSource.setAttributes(Core::GeneratedFile::OpenEditorAttribute); pluginSource.setAttributes(Core::GeneratedFile::OpenEditorAttribute);
rc.push_back(pluginSource); rc.push_back(pluginSource);
...@@ -179,7 +183,8 @@ QList<Core::GeneratedFile> PluginGenerator::generatePlugin(const GenerationPara ...@@ -179,7 +183,8 @@ QList<Core::GeneratedFile> PluginGenerator::generatePlugin(const GenerationPara
if (widgetHeaderContents.isEmpty()) if (widgetHeaderContents.isEmpty())
return QList<Core::GeneratedFile>(); return QList<Core::GeneratedFile>();
Core::GeneratedFile widgetHeader(baseDir + wo.widgetHeaderFile); Core::GeneratedFile widgetHeader(baseDir + wo.widgetHeaderFile);
widgetHeader.setContents(p.license + widgetHeaderContents); widgetHeader.setContents(CppTools::AbstractEditorSupport::licenseTemplate(wo.widgetHeaderFile, wo.widgetClassName)
+ widgetHeaderContents);
rc.push_back(widgetHeader); rc.push_back(widgetHeader);
sm.remove(QLatin1String("WIDGET_INCLUDE_GUARD")); sm.remove(QLatin1String("WIDGET_INCLUDE_GUARD"));
...@@ -188,7 +193,8 @@ QList<Core::GeneratedFile> PluginGenerator::generatePlugin(const GenerationPara ...@@ -188,7 +193,8 @@ QList<Core::GeneratedFile> PluginGenerator::generatePlugin(const GenerationPara
if (widgetSourceContents.isEmpty()) if (widgetSourceContents.isEmpty())
return QList<Core::GeneratedFile>(); return QList<Core::GeneratedFile>();
Core::GeneratedFile widgetSource(baseDir + wo.widgetSourceFile); Core::GeneratedFile widgetSource(baseDir + wo.widgetSourceFile);
widgetSource.setContents(p.license + widgetSourceContents); widgetSource.setContents(CppTools::AbstractEditorSupport::licenseTemplate(wo.widgetSourceFile, wo.widgetClassName)
+ widgetSourceContents);
rc.push_back(widgetSource); rc.push_back(widgetSource);
} }
} }
...@@ -221,7 +227,8 @@ QList<Core::GeneratedFile> PluginGenerator::generatePlugin(const GenerationPara ...@@ -221,7 +227,8 @@ QList<Core::GeneratedFile> PluginGenerator::generatePlugin(const GenerationPara
if (collectionHeaderContents.isEmpty()) if (collectionHeaderContents.isEmpty())
return QList<Core::GeneratedFile>(); return QList<Core::GeneratedFile>();
Core::GeneratedFile collectionHeader(baseDir + options.collectionHeaderFile); Core::GeneratedFile collectionHeader(baseDir + options.collectionHeaderFile);
collectionHeader.setContents(p.license + collectionHeaderContents); collectionHeader.setContents(CppTools::AbstractEditorSupport::licenseTemplate(options.collectionHeaderFile, options.collectionClassName)
+ collectionHeaderContents);
rc.push_back(collectionHeader); rc.push_back(collectionHeader);
sm.remove(QLatin1String("COLLECTION_INCLUDE_GUARD")); sm.remove(QLatin1String("COLLECTION_INCLUDE_GUARD"));
...@@ -241,7 +248,8 @@ QList<Core::GeneratedFile> PluginGenerator::generatePlugin(const GenerationPara ...@@ -241,7 +248,8 @@ QList<Core::GeneratedFile> PluginGenerator::generatePlugin(const GenerationPara
if (collectionSourceFileContents.isEmpty()) if (collectionSourceFileContents.isEmpty())
return QList<Core::GeneratedFile>(); return QList<Core::GeneratedFile>();
Core::GeneratedFile collectionSource(baseDir + options.collectionSourceFile); Core::GeneratedFile collectionSource(baseDir + options.collectionSourceFile);
collectionSource.setContents(p.license + collectionSourceFileContents); collectionSource.setContents(CppTools::AbstractEditorSupport::licenseTemplate(options.collectionSourceFile, options.collectionClassName)
+ collectionSourceFileContents);
collectionSource.setAttributes(Core::GeneratedFile::OpenEditorAttribute); collectionSource.setAttributes(Core::GeneratedFile::OpenEditorAttribute);
rc.push_back(collectionSource); rc.push_back(collectionSource);
......
...@@ -51,7 +51,6 @@ struct PluginOptions; ...@@ -51,7 +51,6 @@ struct PluginOptions;
struct GenerationParameters { struct GenerationParameters {
QString path; QString path;
QString fileName; QString fileName;
QString license;
QString templatePath; QString templatePath;
}; };
......
...@@ -81,13 +81,12 @@ Core::GeneratedFiles ...@@ -81,13 +81,12 @@ Core::GeneratedFiles
const ConsoleAppWizardDialog *wizard = qobject_cast< const ConsoleAppWizardDialog *>(w); const ConsoleAppWizardDialog *wizard = qobject_cast< const ConsoleAppWizardDialog *>(w);
const QtProjectParameters params = wizard->parameters(); const QtProjectParameters params = wizard->parameters();
const QString projectPath = params.projectPath(); const QString projectPath = params.projectPath();
const QString license = CppTools::AbstractEditorSupport::licenseTemplate();
// Create files: Source // Create files: Source
const QString sourceFileName = Core::BaseFileWizard::buildFileName(projectPath, QLatin1String(mainSourceFileC), sourceSuffix()); const QString sourceFileName = Core::BaseFileWizard::buildFileName(projectPath, QLatin1String(mainSourceFileC), sourceSuffix());
Core::GeneratedFile source(sourceFileName); Core::GeneratedFile source(sourceFileName);
source.setContents(license + QLatin1String(mainCppC)); source.setContents(CppTools::AbstractEditorSupport::licenseTemplate(sourceFileName) + QLatin1String(mainCppC));
source.setAttributes(Core::GeneratedFile::OpenEditorAttribute); source.setAttributes(Core::GeneratedFile::OpenEditorAttribute);
// Create files: Profile // Create files: Profile
const QString profileName = Core::BaseFileWizard::buildFileName(projectPath, params.fileName, profileSuffix()); const QString profileName = Core::BaseFileWizard::buildFileName(projectPath, params.fileName, profileSuffix());
......
...@@ -165,7 +165,8 @@ Core::GeneratedFiles GuiAppWizard::generateFiles(const QWizard *w, ...@@ -165,7 +165,8 @@ Core::GeneratedFiles GuiAppWizard::generateFiles(const QWizard *w,
Core::GeneratedFile mainSource(mainSourceFileName); Core::GeneratedFile mainSource(mainSourceFileName);
if (!parametrizeTemplate(templatePath, QLatin1String("main.cpp"), params, &contents, errorMessage)) if (!parametrizeTemplate(templatePath, QLatin1String("main.cpp"), params, &contents, errorMessage))
return Core::GeneratedFiles(); return Core::GeneratedFiles();
mainSource.setContents(license + contents); mainSource.setContents(CppTools::AbstractEditorSupport::licenseTemplate(mainSourceFileName)
+ contents);
// Create files: form source with or without form // Create files: form source with or without form
const QString formSourceFileName = buildFileName(projectPath, params.sourceFileName, sourceSuffix()); const QString formSourceFileName = buildFileName(projectPath, params.sourceFileName, sourceSuffix());
const QString formHeaderName = buildFileName(projectPath, params.headerFileName, headerSuffix()); const QString formHeaderName = buildFileName(projectPath, params.headerFileName, headerSuffix());
...@@ -187,13 +188,15 @@ Core::GeneratedFiles GuiAppWizard::generateFiles(const QWizard *w, ...@@ -187,13 +188,15 @@ Core::GeneratedFiles GuiAppWizard::generateFiles(const QWizard *w,
const QString formSourceTemplate = QLatin1String("mywidget.cpp"); const QString formSourceTemplate = QLatin1String("mywidget.cpp");
if (!parametrizeTemplate(templatePath, formSourceTemplate, params, &contents, errorMessage)) if (!parametrizeTemplate(templatePath, formSourceTemplate, params, &contents, errorMessage))
return Core::GeneratedFiles(); return Core::GeneratedFiles();
formSource.setContents(license + contents); formSource.setContents(CppTools::AbstractEditorSupport::licenseTemplate(formSourceFileName)
+ contents);
formSource.setAttributes(Core::GeneratedFile::OpenEditorAttribute); formSource.setAttributes(Core::GeneratedFile::OpenEditorAttribute);
// Create files: form header // Create files: form header
const QString formHeaderTemplate = QLatin1String("mywidget.h"); const QString formHeaderTemplate = QLatin1String("mywidget.h");
if (!parametrizeTemplate(templatePath, formHeaderTemplate, params, &contents, errorMessage)) if (!parametrizeTemplate(templatePath, formHeaderTemplate, params, &contents, errorMessage))
return Core::GeneratedFiles(); return Core::GeneratedFiles();
formHeader.setContents(license + contents); formHeader.setContents(CppTools::AbstractEditorSupport::licenseTemplate(formHeaderName)
+ contents);
} }
// Create files: profile // Create files: profile
const QString profileName = buildFileName(projectPath, projectParams.fileName, profileSuffix()); const QString profileName = buildFileName(projectPath, projectParams.fileName, profileSuffix());
......
...@@ -82,7 +82,6 @@ Core::GeneratedFiles LibraryWizard::generateFiles(const QWizard *w, ...@@ -82,7 +82,6 @@ Core::GeneratedFiles LibraryWizard::generateFiles(const QWizard *w,
const QtProjectParameters projectParams = dialog->parameters(); const QtProjectParameters projectParams = dialog->parameters();
const QString projectPath = projectParams.projectPath(); const QString projectPath = projectParams.projectPath();
const LibraryParameters params = dialog->libraryParameters(); const LibraryParameters params = dialog->libraryParameters();
const QString license = CppTools::AbstractEditorSupport::licenseTemplate();
const QString sharedLibExportMacro = QtProjectParameters::exportMacro(projectParams.fileName); const QString sharedLibExportMacro = QtProjectParameters::exportMacro(projectParams.fileName);
...@@ -102,7 +101,8 @@ Core::GeneratedFiles LibraryWizard::generateFiles(const QWizard *w, ...@@ -102,7 +101,8 @@ Core::GeneratedFiles LibraryWizard::generateFiles(const QWizard *w,
const QString globalHeaderName = buildFileName(projectPath, projectParams.fileName + QLatin1String(sharedHeaderPostfixC), headerSuffix()); const QString globalHeaderName = buildFileName(projectPath, projectParams.fileName + QLatin1String(sharedHeaderPostfixC), headerSuffix());
Core::GeneratedFile globalHeader(globalHeaderName); Core::GeneratedFile globalHeader(globalHeaderName);
globalHeaderFileName = QFileInfo(globalHeader.path()).fileName(); globalHeaderFileName = QFileInfo(globalHeader.path()).fileName();
globalHeader.setContents(license + LibraryParameters::generateSharedHeader(globalHeaderFileName, projectParams.fileName, sharedLibExportMacro)); globalHeader.setContents(CppTools::AbstractEditorSupport::licenseTemplate(globalHeaderFileName)
+ LibraryParameters::generateSharedHeader(globalHeaderFileName, projectParams.fileName, sharedLibExportMacro));
rc.push_back(globalHeader); rc.push_back(globalHeader);
} }
...@@ -112,8 +112,10 @@ Core::GeneratedFiles LibraryWizard::generateFiles(const QWizard *w, ...@@ -112,8 +112,10 @@ Core::GeneratedFiles LibraryWizard::generateFiles(const QWizard *w,
globalHeaderFileName, sharedLibExportMacro, globalHeaderFileName, sharedLibExportMacro,
/* indentation*/ 4, &headerContents, &sourceContents); /* indentation*/ 4, &headerContents, &sourceContents);
source.setContents(license + sourceContents); source.setContents(CppTools::AbstractEditorSupport::licenseTemplate(sourceFileName, params.className)
header.setContents(license + headerContents); + sourceContents);
header.setContents(CppTools::AbstractEditorSupport::licenseTemplate(headerFileFullName, params.className)
+ headerContents);
rc.push_back(source); rc.push_back(source);
rc.push_back(header); rc.push_back(header);
// Create files: profile // Create files: profile
......
...@@ -96,7 +96,7 @@ static QString generateTestCode(const TestWizardParameters &testParams, ...@@ -96,7 +96,7 @@ static QString generateTestCode(const TestWizardParameters &testParams,
const QString indent = QString(4, QLatin1Char(' ')); const QString indent = QString(4, QLatin1Char(' '));
QTextStream str(&rc); QTextStream str(&rc);
// Includes // Includes
str << CppTools::AbstractEditorSupport::licenseTemplate() str << CppTools::AbstractEditorSupport::licenseTemplate(testParams.fileName, testParams.className)
<< "#include <QtCore/QString>\n#include <QtTest/QtTest>\n"; << "#include <QtCore/QString>\n#include <QtTest/QtTest>\n";
if (testParams.requiresQApplication) if (testParams.requiresQApplication)
str << "#include <QtCore/QCoreApplication>\n"; str << "#include <QtCore/QCoreApplication>\n";
......
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