forked from qt-creator/qt-creator
New class wizard: Add Qt module dependencies, if necessary
Provide general infrastrucure and implementation for qmake. Fixes: QTCREATORBUG-16067 Change-Id: I8c6368fe2724c9450dcbc3410b6ca459bbbdc043 Reviewed-by: hjk <hjk@qt.io>
This commit is contained in:
@@ -18,7 +18,10 @@
|
|||||||
{ "key": "Base", "value": "%{JS: value('BaseCB') === '' ? value('BaseEdit') : value('BaseCB')}" },
|
{ "key": "Base", "value": "%{JS: value('BaseCB') === '' ? value('BaseEdit') : value('BaseCB')}" },
|
||||||
{ "key": "isQObject", "value": "%{JS: [ 'QObject', 'QWidget', 'QMainWindow', 'QDeclarativeItem', 'QQuickItem'].indexOf(value('Base')) >= 0 }" },
|
{ "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": "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":
|
"pages":
|
||||||
|
@@ -206,6 +206,10 @@ void JsonSummaryPage::addToProject(const JsonWizard::GeneratorFiles &files)
|
|||||||
nativeFilePaths.join(QLatin1String(", "))));
|
nativeFilePaths.join(QLatin1String(", "))));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
const QStringList dependencies = m_wizard->stringValue("Dependencies")
|
||||||
|
.split(':', QString::SkipEmptyParts);
|
||||||
|
if (!dependencies.isEmpty())
|
||||||
|
folder->addDependencies(dependencies);
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@@ -737,6 +737,13 @@ bool FolderNode::renameFile(const QString &filePath, const QString &newFilePath)
|
|||||||
return false;
|
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
|
FolderNode::AddNewInformation FolderNode::addNewInformation(const QStringList &files, Node *context) const
|
||||||
{
|
{
|
||||||
Q_UNUSED(files);
|
Q_UNUSED(files);
|
||||||
@@ -868,6 +875,12 @@ bool ProjectNode::renameFile(const QString &filePath, const QString &newFilePath
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool ProjectNode::addDependencies(const QStringList &dependencies)
|
||||||
|
{
|
||||||
|
Q_UNUSED(dependencies)
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
bool ProjectNode::supportsAction(ProjectAction, const Node *) const
|
bool ProjectNode::supportsAction(ProjectAction, const Node *) const
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
|
@@ -267,6 +267,7 @@ public:
|
|||||||
virtual bool deleteFiles(const QStringList &filePaths);
|
virtual bool deleteFiles(const QStringList &filePaths);
|
||||||
virtual bool canRenameFile(const QString &filePath, const QString &newFilePath);
|
virtual bool canRenameFile(const QString &filePath, const QString &newFilePath);
|
||||||
virtual bool renameFile(const QString &filePath, const QString &newFilePath);
|
virtual bool renameFile(const QString &filePath, const QString &newFilePath);
|
||||||
|
virtual bool addDependencies(const QStringList &dependencies);
|
||||||
|
|
||||||
class AddNewInformation
|
class AddNewInformation
|
||||||
{
|
{
|
||||||
@@ -342,6 +343,7 @@ public:
|
|||||||
bool deleteFiles(const QStringList &filePaths) override;
|
bool deleteFiles(const QStringList &filePaths) override;
|
||||||
bool canRenameFile(const QString &filePath, const QString &newFilePath) override;
|
bool canRenameFile(const QString &filePath, const QString &newFilePath) override;
|
||||||
bool renameFile(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;
|
bool supportsAction(ProjectAction action, const Node *node) const override;
|
||||||
|
|
||||||
// by default returns false
|
// by default returns false
|
||||||
|
@@ -219,6 +219,13 @@ bool QmakePriFileNode::renameFile(const QString &filePath, const QString &newFil
|
|||||||
return pri ? pri->renameFile(filePath, newFilePath) : false;
|
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
|
FolderNode::AddNewInformation QmakePriFileNode::addNewInformation(const QStringList &files, Node *context) const
|
||||||
{
|
{
|
||||||
Q_UNUSED(files)
|
Q_UNUSED(files)
|
||||||
|
@@ -60,6 +60,7 @@ public:
|
|||||||
bool deleteFiles(const QStringList &filePaths) override;
|
bool deleteFiles(const QStringList &filePaths) override;
|
||||||
bool canRenameFile(const QString &filePath, const QString &newFilePath) override;
|
bool canRenameFile(const QString &filePath, const QString &newFilePath) override;
|
||||||
bool renameFile(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;
|
AddNewInformation addNewInformation(const QStringList &files, Node *context) const override;
|
||||||
|
|
||||||
bool deploysFolder(const QString &folder) const override;
|
bool deploysFolder(const QString &folder) const override;
|
||||||
|
@@ -632,6 +632,52 @@ bool QmakePriFile::renameFile(const QString &filePath, const QString &newFilePat
|
|||||||
return changeProFileOptional;
|
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<ProFile *, QStringList> 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()
|
bool QmakePriFile::saveModifiedEditors()
|
||||||
{
|
{
|
||||||
Core::IDocument *document
|
Core::IDocument *document
|
||||||
|
@@ -151,6 +151,7 @@ public:
|
|||||||
bool deleteFiles(const QStringList &filePaths);
|
bool deleteFiles(const QStringList &filePaths);
|
||||||
bool canRenameFile(const QString &filePath, const QString &newFilePath);
|
bool canRenameFile(const QString &filePath, const QString &newFilePath);
|
||||||
bool renameFile(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,
|
bool setProVariable(const QString &var, const QStringList &values,
|
||||||
const QString &scope = QString(),
|
const QString &scope = QString(),
|
||||||
|
Reference in New Issue
Block a user