diff --git a/share/qtcreator/templates/wizards/classes/cpp/wizard.json b/share/qtcreator/templates/wizards/classes/cpp/wizard.json index ae466ba7ed1..85218814836 100644 --- a/share/qtcreator/templates/wizards/classes/cpp/wizard.json +++ b/share/qtcreator/templates/wizards/classes/cpp/wizard.json @@ -18,7 +18,10 @@ { "key": "Base", "value": "%{JS: value('BaseCB') === '' ? value('BaseEdit') : value('BaseCB')}" }, { "key": "isQObject", "value": "%{JS: [ 'QObject', 'QWidget', 'QMainWindow', 'QDeclarativeItem', 'QQuickItem'].indexOf(value('Base')) >= 0 }" }, { "key": "GUARD", "value": "%{JS: Cpp.classToHeaderGuard(value('Class'), Util.suffix(value('HdrFileName')))}" }, - { "key": "SharedDataInit", "value": "%{JS: (value('IncludeQSharedData')) ? 'data(new %{CN}Data)' : '' }" } + { "key": "SharedDataInit", "value": "%{JS: (value('IncludeQSharedData')) ? 'data(new %{CN}Data)' : '' }" }, + { "key": "Dependencies", "value": "%{JS: '' + (value('IncludeQObject') || value('IncludeQSharedData') || value('BaseCB') === 'QObject' ? ':Qt.core' : '') + + (value('IncludeQWidget') || value('IncludeQMainWindow') || value('BaseCB') === 'QWidget' || value('BaseCB') === 'QMainWindow' ? ':Qt.widgets' : '') + + (value('IncludeQQuickItem') || value('BaseCB') === 'QQuickItem' ? ':Qt.quick' : '')}"} ], "pages": diff --git a/src/plugins/projectexplorer/jsonwizard/jsonsummarypage.cpp b/src/plugins/projectexplorer/jsonwizard/jsonsummarypage.cpp index 9f9844c01e6..14072fd3198 100644 --- a/src/plugins/projectexplorer/jsonwizard/jsonsummarypage.cpp +++ b/src/plugins/projectexplorer/jsonwizard/jsonsummarypage.cpp @@ -206,6 +206,10 @@ void JsonSummaryPage::addToProject(const JsonWizard::GeneratorFiles &files) nativeFilePaths.join(QLatin1String(", ")))); return; } + const QStringList dependencies = m_wizard->stringValue("Dependencies") + .split(':', QString::SkipEmptyParts); + if (!dependencies.isEmpty()) + folder->addDependencies(dependencies); } return; } diff --git a/src/plugins/projectexplorer/projectnodes.cpp b/src/plugins/projectexplorer/projectnodes.cpp index f8747e529cf..cad8be108b3 100644 --- a/src/plugins/projectexplorer/projectnodes.cpp +++ b/src/plugins/projectexplorer/projectnodes.cpp @@ -737,6 +737,13 @@ bool FolderNode::renameFile(const QString &filePath, const QString &newFilePath) return false; } +bool FolderNode::addDependencies(const QStringList &dependencies) +{ + if (ProjectNode * const pn = managingProject()) + return pn->addDependencies(dependencies); + return false; +} + FolderNode::AddNewInformation FolderNode::addNewInformation(const QStringList &files, Node *context) const { Q_UNUSED(files); @@ -868,6 +875,12 @@ bool ProjectNode::renameFile(const QString &filePath, const QString &newFilePath return false; } +bool ProjectNode::addDependencies(const QStringList &dependencies) +{ + Q_UNUSED(dependencies) + return false; +} + bool ProjectNode::supportsAction(ProjectAction, const Node *) const { return false; diff --git a/src/plugins/projectexplorer/projectnodes.h b/src/plugins/projectexplorer/projectnodes.h index 8660080a2b3..2795f1a8fbd 100644 --- a/src/plugins/projectexplorer/projectnodes.h +++ b/src/plugins/projectexplorer/projectnodes.h @@ -267,6 +267,7 @@ public: virtual bool deleteFiles(const QStringList &filePaths); virtual bool canRenameFile(const QString &filePath, const QString &newFilePath); virtual bool renameFile(const QString &filePath, const QString &newFilePath); + virtual bool addDependencies(const QStringList &dependencies); class AddNewInformation { @@ -342,6 +343,7 @@ public: bool deleteFiles(const QStringList &filePaths) override; bool canRenameFile(const QString &filePath, const QString &newFilePath) override; bool renameFile(const QString &filePath, const QString &newFilePath) override; + bool addDependencies(const QStringList &dependencies) override; bool supportsAction(ProjectAction action, const Node *node) const override; // by default returns false diff --git a/src/plugins/qmakeprojectmanager/qmakenodes.cpp b/src/plugins/qmakeprojectmanager/qmakenodes.cpp index 9370519f39b..1716077db00 100644 --- a/src/plugins/qmakeprojectmanager/qmakenodes.cpp +++ b/src/plugins/qmakeprojectmanager/qmakenodes.cpp @@ -219,6 +219,13 @@ bool QmakePriFileNode::renameFile(const QString &filePath, const QString &newFil return pri ? pri->renameFile(filePath, newFilePath) : false; } +bool QmakePriFileNode::addDependencies(const QStringList &dependencies) +{ + if (QmakePriFile * const pri = priFile()) + return pri->addDependencies(dependencies); + return false; +} + FolderNode::AddNewInformation QmakePriFileNode::addNewInformation(const QStringList &files, Node *context) const { Q_UNUSED(files) diff --git a/src/plugins/qmakeprojectmanager/qmakenodes.h b/src/plugins/qmakeprojectmanager/qmakenodes.h index b7432bcc14d..55ae8aaad1e 100644 --- a/src/plugins/qmakeprojectmanager/qmakenodes.h +++ b/src/plugins/qmakeprojectmanager/qmakenodes.h @@ -60,6 +60,7 @@ public: bool deleteFiles(const QStringList &filePaths) override; bool canRenameFile(const QString &filePath, const QString &newFilePath) override; bool renameFile(const QString &filePath, const QString &newFilePath) override; + bool addDependencies(const QStringList &dependencies) override; AddNewInformation addNewInformation(const QStringList &files, Node *context) const override; bool deploysFolder(const QString &folder) const override; diff --git a/src/plugins/qmakeprojectmanager/qmakeparsernodes.cpp b/src/plugins/qmakeprojectmanager/qmakeparsernodes.cpp index c9fce5bb9ad..c646513e688 100644 --- a/src/plugins/qmakeprojectmanager/qmakeparsernodes.cpp +++ b/src/plugins/qmakeprojectmanager/qmakeparsernodes.cpp @@ -632,6 +632,52 @@ bool QmakePriFile::renameFile(const QString &filePath, const QString &newFilePat return changeProFileOptional; } +bool QmakePriFile::addDependencies(const QStringList &dependencies) +{ + if (dependencies.isEmpty()) + return true; + if (!prepareForChange()) + return false; + + QStringList qtDependencies = filtered(dependencies, [](const QString &dep) { + return dep.length() > 3 && dep.startsWith("Qt."); + }); + qtDependencies = transform(qtDependencies, [](const QString &dep) { + return dep.mid(3); + }); + qtDependencies.removeOne("core"); + if (qtDependencies.isEmpty()) + return true; + + const QPair pair = readProFile(filePath().toString()); + ProFile * const includeFile = pair.first; + if (!includeFile) + return false; + QStringList lines = pair.second; + + const QString indent = continuationIndent(); + const ProWriter::PutFlags appendFlags(ProWriter::AppendValues | ProWriter::AppendOperator); + if (!proFile()->variableValue(Variable::Config).contains("qt")) { + if (lines.removeAll("CONFIG -= qt") == 0) { + ProWriter::putVarValues(includeFile, &lines, {"qt"}, "CONFIG", appendFlags, + QString(), indent); + } + } + + const QStringList currentQtDependencies = proFile()->variableValue(Variable::Qt); + qtDependencies = filtered(qtDependencies, [currentQtDependencies](const QString &dep) { + return !currentQtDependencies.contains(dep); + }); + if (!qtDependencies.isEmpty()) { + ProWriter::putVarValues(includeFile, &lines, qtDependencies, "QT", appendFlags, + QString(), indent); + } + + save(lines); + includeFile->deref(); + return true; +} + bool QmakePriFile::saveModifiedEditors() { Core::IDocument *document diff --git a/src/plugins/qmakeprojectmanager/qmakeparsernodes.h b/src/plugins/qmakeprojectmanager/qmakeparsernodes.h index 3827957d576..1387760145d 100644 --- a/src/plugins/qmakeprojectmanager/qmakeparsernodes.h +++ b/src/plugins/qmakeprojectmanager/qmakeparsernodes.h @@ -151,6 +151,7 @@ public: bool deleteFiles(const QStringList &filePaths); bool canRenameFile(const QString &filePath, const QString &newFilePath); bool renameFile(const QString &filePath, const QString &newFilePath); + bool addDependencies(const QStringList &dependencies); bool setProVariable(const QString &var, const QStringList &values, const QString &scope = QString(),