2022-08-19 15:59:36 +02:00
|
|
|
// Copyright (C) 2016 The Qt Company Ltd.
|
|
|
|
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0+ OR GPL-3.0 WITH Qt-GPL-exception-1.0
|
2009-05-04 12:19:22 +02:00
|
|
|
|
|
|
|
#include "qmlproject.h"
|
2019-10-25 09:55:32 +02:00
|
|
|
|
2013-07-11 17:37:02 +02:00
|
|
|
#include "fileformat/qmlprojectfileformat.h"
|
2010-02-16 13:39:13 +01:00
|
|
|
#include "fileformat/qmlprojectitem.h"
|
2011-04-12 12:17:19 +02:00
|
|
|
#include "qmlprojectconstants.h"
|
2017-12-08 14:50:57 +01:00
|
|
|
#include "qmlprojectmanagerconstants.h"
|
2011-08-18 16:46:26 +02:00
|
|
|
#include "qmlprojectnodes.h"
|
2010-02-17 13:37:00 +01:00
|
|
|
|
2019-10-25 09:55:32 +02:00
|
|
|
#include <coreplugin/documentmanager.h>
|
|
|
|
#include <coreplugin/editormanager/documentmodel.h>
|
2021-09-03 14:58:42 +02:00
|
|
|
#include <coreplugin/editormanager/editormanager.h>
|
2019-10-25 09:55:32 +02:00
|
|
|
#include <coreplugin/editormanager/ieditor.h>
|
2017-02-28 16:31:07 +01:00
|
|
|
#include <coreplugin/icontext.h>
|
2010-02-17 13:37:00 +01:00
|
|
|
#include <coreplugin/icore.h>
|
|
|
|
#include <coreplugin/messagemanager.h>
|
2017-03-03 18:16:34 +01:00
|
|
|
|
2017-11-28 15:57:15 +01:00
|
|
|
#include <projectexplorer/deploymentdata.h>
|
2022-04-12 21:01:45 +02:00
|
|
|
#include <projectexplorer/devicesupport/idevice.h>
|
2012-09-03 18:31:44 +02:00
|
|
|
#include <projectexplorer/kitinformation.h>
|
|
|
|
#include <projectexplorer/kitmanager.h>
|
2022-06-22 15:43:33 +02:00
|
|
|
#include <projectexplorer/projectexplorerconstants.h>
|
2022-07-11 15:22:42 +02:00
|
|
|
#include <projectexplorer/session.h>
|
2012-04-24 15:49:09 +02:00
|
|
|
#include <projectexplorer/target.h>
|
2017-03-03 18:16:34 +01:00
|
|
|
|
|
|
|
#include <qtsupport/baseqtversion.h>
|
|
|
|
#include <qtsupport/qtkitinformation.h>
|
2013-03-07 14:02:04 +01:00
|
|
|
#include <qtsupport/qtsupportconstants.h>
|
2019-08-15 08:56:07 +02:00
|
|
|
|
2017-03-03 18:16:34 +01:00
|
|
|
#include <qmljs/qmljsmodelmanagerinterface.h>
|
2011-04-15 15:55:11 +02:00
|
|
|
|
2019-10-25 09:55:32 +02:00
|
|
|
#include <texteditor/textdocument.h>
|
|
|
|
|
2017-03-01 14:26:46 +01:00
|
|
|
#include <utils/algorithm.h>
|
2021-03-23 14:04:04 +01:00
|
|
|
#include <utils/infobar.h>
|
2022-06-22 15:43:33 +02:00
|
|
|
#include <utils/qtcassert.h>
|
2021-08-25 13:50:10 +02:00
|
|
|
#include <utils/qtcprocess.h>
|
2017-03-01 14:26:46 +01:00
|
|
|
|
2012-08-06 13:42:46 +02:00
|
|
|
#include <QDebug>
|
2021-03-09 17:53:36 +01:00
|
|
|
#include <QLoggingCategory>
|
|
|
|
#include <QMessageBox>
|
2019-10-25 09:55:32 +02:00
|
|
|
#include <QRegularExpression>
|
|
|
|
#include <QTextCodec>
|
2021-03-09 17:53:36 +01:00
|
|
|
#include <QTimer>
|
2010-01-19 13:41:02 +01:00
|
|
|
|
2013-09-05 01:52:17 +02:00
|
|
|
using namespace Core;
|
2013-09-10 17:59:34 +02:00
|
|
|
using namespace ProjectExplorer;
|
2019-10-25 09:55:32 +02:00
|
|
|
using namespace QmlProjectManager::Internal;
|
2020-06-26 13:59:38 +02:00
|
|
|
using namespace Utils;
|
2010-01-18 16:32:14 +01:00
|
|
|
|
2020-03-03 12:30:28 +01:00
|
|
|
namespace {
|
|
|
|
Q_LOGGING_CATEGORY(infoLogger, "QmlProjectManager.QmlBuildSystem", QtInfoMsg)
|
|
|
|
}
|
|
|
|
|
2013-09-05 01:52:17 +02:00
|
|
|
namespace QmlProjectManager {
|
2013-03-07 14:02:04 +01:00
|
|
|
|
2021-08-03 16:07:42 +02:00
|
|
|
static int preferedQtTarget(Target *target)
|
|
|
|
{
|
|
|
|
if (target) {
|
|
|
|
const QmlBuildSystem *buildSystem = qobject_cast<QmlBuildSystem *>(target->buildSystem());
|
|
|
|
if (buildSystem && buildSystem->qt6Project())
|
|
|
|
return 6;
|
|
|
|
}
|
|
|
|
return 5;
|
|
|
|
}
|
|
|
|
|
2022-02-03 19:44:07 +01:00
|
|
|
Utils::FilePaths QmlProject::getUiQmlFilesForFolder(const Utils::FilePath &folder)
|
|
|
|
{
|
|
|
|
const Utils::FilePaths uiFiles = files([&](const ProjectExplorer::Node *node) {
|
|
|
|
return node->filePath().completeSuffix() == "ui.qml"
|
|
|
|
&& node->filePath().parentDir() == folder;
|
|
|
|
});
|
|
|
|
return uiFiles;
|
|
|
|
}
|
|
|
|
|
2019-08-15 12:26:14 +02:00
|
|
|
QmlProject::QmlProject(const Utils::FilePath &fileName)
|
|
|
|
: Project(QString::fromLatin1(Constants::QMLPROJECT_MIMETYPE), fileName)
|
2009-05-04 12:19:22 +02:00
|
|
|
{
|
2017-12-08 14:50:57 +01:00
|
|
|
setId(QmlProjectManager::Constants::QML_PROJECT_ID);
|
2017-01-30 14:59:10 +01:00
|
|
|
setProjectLanguages(Context(ProjectExplorer::Constants::QMLJS_LANGUAGE_ID));
|
2021-06-04 07:59:00 +02:00
|
|
|
setDisplayName(fileName.completeBaseName());
|
2019-08-13 12:11:07 +02:00
|
|
|
|
|
|
|
setNeedsBuildConfigurations(false);
|
2019-10-25 09:55:32 +02:00
|
|
|
setBuildSystemCreator([](Target *t) { return new QmlBuildSystem(t); });
|
2021-03-09 17:53:36 +01:00
|
|
|
|
2022-05-06 14:27:58 +03:00
|
|
|
if (QmlProject::isQtDesignStudio()) {
|
2022-07-11 15:22:42 +02:00
|
|
|
|
|
|
|
EditorManager::closeAllDocuments();
|
|
|
|
SessionManager::closeAllProjects();
|
|
|
|
|
2022-02-03 19:44:07 +01:00
|
|
|
m_openFileConnection
|
|
|
|
= connect(this,
|
|
|
|
&QmlProject::anyParsingFinished,
|
|
|
|
this,
|
|
|
|
[this](Target *target, bool success) {
|
|
|
|
if (m_openFileConnection)
|
|
|
|
disconnect(m_openFileConnection);
|
|
|
|
|
|
|
|
if (target && success) {
|
2022-05-10 14:23:51 +02:00
|
|
|
|
|
|
|
auto target = activeTarget();
|
|
|
|
if (!target)
|
|
|
|
return;
|
|
|
|
|
|
|
|
auto qmlBuildSystem = qobject_cast<QmlProjectManager::QmlBuildSystem *>(
|
|
|
|
target->buildSystem());
|
|
|
|
|
|
|
|
const Utils::FilePath mainUiFile = qmlBuildSystem->mainUiFilePath();
|
|
|
|
|
2022-05-18 21:42:04 +02:00
|
|
|
if (mainUiFile.completeSuffix() == "ui.qml" && mainUiFile.exists()) {
|
2022-05-10 14:23:51 +02:00
|
|
|
QTimer::singleShot(1000, [mainUiFile]() {
|
|
|
|
Core::EditorManager::openEditor(mainUiFile,
|
2022-02-03 19:44:07 +01:00
|
|
|
Utils::Id());
|
2022-05-10 14:23:51 +02:00
|
|
|
});
|
|
|
|
} else {
|
|
|
|
Utils::FilePaths uiFiles = getUiQmlFilesForFolder(projectDirectory()
|
|
|
|
+ "/content");
|
|
|
|
if (uiFiles.isEmpty())
|
|
|
|
uiFiles = getUiQmlFilesForFolder(projectDirectory());
|
|
|
|
|
|
|
|
if (!uiFiles.isEmpty()) {
|
|
|
|
Utils::FilePath currentFile;
|
|
|
|
if (auto cd = Core::EditorManager::currentDocument())
|
|
|
|
currentFile = cd->filePath();
|
|
|
|
|
|
|
|
if (currentFile.isEmpty() || !isKnownFile(currentFile))
|
|
|
|
QTimer::singleShot(1000, [uiFiles]() {
|
|
|
|
Core::EditorManager::openEditor(uiFiles.first(),
|
|
|
|
Utils::Id());
|
|
|
|
});
|
|
|
|
}
|
2022-02-03 19:44:07 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
2021-03-09 17:53:36 +01:00
|
|
|
}
|
2019-10-25 09:55:32 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
QmlBuildSystem::QmlBuildSystem(Target *target)
|
|
|
|
: BuildSystem(target)
|
|
|
|
{
|
2021-08-20 13:04:02 +02:00
|
|
|
m_canonicalProjectDir =
|
2021-08-24 07:19:54 +02:00
|
|
|
target->project()->projectFilePath().canonicalPath().normalizedPathName().parentDir();
|
2019-10-25 09:55:32 +02:00
|
|
|
|
|
|
|
connect(target->project(), &Project::projectFileIsDirty,
|
|
|
|
this, &QmlBuildSystem::refreshProjectFile);
|
2019-08-15 12:26:14 +02:00
|
|
|
|
2019-10-25 09:55:32 +02:00
|
|
|
// refresh first - project information is used e.g. to decide the default RC's
|
|
|
|
refresh(Everything);
|
|
|
|
|
|
|
|
// FIXME: Check. Probably bogus after the BuildSystem move.
|
|
|
|
// // addedTarget calls updateEnabled on the runconfigurations
|
|
|
|
// // which needs to happen after refresh
|
|
|
|
// foreach (Target *t, targets())
|
|
|
|
// addedTarget(t);
|
|
|
|
|
|
|
|
connect(target->project(), &Project::activeTargetChanged,
|
|
|
|
this, &QmlBuildSystem::onActiveTargetChanged);
|
|
|
|
updateDeploymentData();
|
2009-05-04 12:19:22 +02:00
|
|
|
}
|
|
|
|
|
2021-12-16 11:39:52 +01:00
|
|
|
QmlBuildSystem::~QmlBuildSystem() = default;
|
2009-05-04 12:19:22 +02:00
|
|
|
|
2019-10-25 09:55:32 +02:00
|
|
|
void QmlBuildSystem::triggerParsing()
|
2012-10-09 16:20:26 +02:00
|
|
|
{
|
2019-10-25 09:55:32 +02:00
|
|
|
refresh(Everything);
|
2012-10-09 16:20:26 +02:00
|
|
|
}
|
|
|
|
|
2019-10-25 09:55:32 +02:00
|
|
|
void QmlBuildSystem::onActiveTargetChanged(Target *)
|
2013-11-06 12:59:04 +01:00
|
|
|
{
|
|
|
|
// make sure e.g. the default qml imports are adapted
|
|
|
|
refresh(Configuration);
|
|
|
|
}
|
|
|
|
|
2019-10-25 09:55:32 +02:00
|
|
|
void QmlBuildSystem::onKitChanged()
|
2013-05-02 15:29:33 +02:00
|
|
|
{
|
|
|
|
// make sure e.g. the default qml imports are adapted
|
|
|
|
refresh(Configuration);
|
|
|
|
}
|
|
|
|
|
2019-10-25 09:55:32 +02:00
|
|
|
Utils::FilePath QmlBuildSystem::canonicalProjectDir() const
|
2009-05-06 16:13:44 +02:00
|
|
|
{
|
2017-11-28 15:57:15 +01:00
|
|
|
return m_canonicalProjectDir;
|
2009-05-06 16:13:44 +02:00
|
|
|
}
|
|
|
|
|
2019-10-25 09:55:32 +02:00
|
|
|
void QmlBuildSystem::parseProject(RefreshOptions options)
|
2009-05-04 12:19:22 +02:00
|
|
|
{
|
|
|
|
if (options & Files) {
|
2010-01-19 13:53:48 +01:00
|
|
|
if (options & ProjectFile)
|
2021-12-16 11:39:52 +01:00
|
|
|
m_projectItem.reset();
|
2010-01-18 16:32:14 +01:00
|
|
|
if (!m_projectItem) {
|
2021-12-16 11:39:52 +01:00
|
|
|
QString errorMessage;
|
|
|
|
m_projectItem.reset(
|
|
|
|
QmlProjectFileFormat::parseProjectFile(projectFilePath(), &errorMessage));
|
|
|
|
if (m_projectItem) {
|
|
|
|
connect(m_projectItem.get(),
|
|
|
|
&QmlProjectItem::qmlFilesChanged,
|
|
|
|
this,
|
|
|
|
&QmlBuildSystem::refreshFiles);
|
|
|
|
|
|
|
|
} else {
|
|
|
|
MessageManager::writeFlashing(
|
|
|
|
tr("Error while loading project file %1.").arg(projectFilePath().toUserOutput()));
|
|
|
|
MessageManager::writeSilently(errorMessage);
|
|
|
|
}
|
2010-01-18 16:32:14 +01:00
|
|
|
}
|
|
|
|
if (m_projectItem) {
|
2021-12-16 11:39:52 +01:00
|
|
|
m_projectItem->setSourceDirectory(canonicalProjectDir().toString());
|
2017-11-28 15:57:15 +01:00
|
|
|
if (m_projectItem->targetDirectory().isEmpty())
|
|
|
|
m_projectItem->setTargetDirectory(canonicalProjectDir().toString());
|
|
|
|
|
2022-06-20 12:35:13 +02:00
|
|
|
if (auto modelManager = QmlJS::ModelManagerInterface::instance()) {
|
|
|
|
QStringList files = m_projectItem->files();
|
|
|
|
Utils::FilePaths filePaths(files.size());
|
|
|
|
std::transform(files.cbegin(),
|
|
|
|
files.cend(),
|
|
|
|
filePaths.begin(),
|
|
|
|
[](const QString &p) { return Utils::FilePath::fromString(p); });
|
|
|
|
modelManager->updateSourceFiles(filePaths, true);
|
|
|
|
}
|
2021-12-16 11:39:52 +01:00
|
|
|
QString mainFilePath = m_projectItem->mainFile();
|
2012-01-02 15:54:51 +01:00
|
|
|
if (!mainFilePath.isEmpty()) {
|
2017-11-28 15:57:15 +01:00
|
|
|
mainFilePath
|
|
|
|
= QDir(canonicalProjectDir().toString()).absoluteFilePath(mainFilePath);
|
2013-01-21 13:54:20 +01:00
|
|
|
Utils::FileReader reader;
|
|
|
|
QString errorMessage;
|
2021-05-18 09:47:07 +02:00
|
|
|
if (!reader.fetch(Utils::FilePath::fromString(mainFilePath), &errorMessage)) {
|
2020-12-17 10:30:03 +01:00
|
|
|
MessageManager::writeFlashing(tr("Warning while loading project file %1.")
|
|
|
|
.arg(projectFilePath().toUserOutput()));
|
|
|
|
MessageManager::writeSilently(errorMessage);
|
2012-01-02 15:54:51 +01:00
|
|
|
}
|
|
|
|
}
|
2010-01-18 16:32:14 +01:00
|
|
|
}
|
2017-03-01 14:26:46 +01:00
|
|
|
generateProjectTree();
|
2009-05-04 12:19:22 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (options & Configuration) {
|
|
|
|
// update configuration
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-05-10 14:23:51 +02:00
|
|
|
bool QmlBuildSystem::setFileSettingInProjectFile(const QString &setting, const Utils::FilePath &mainFilePath, const QString &oldFile)
|
|
|
|
{
|
|
|
|
// make sure to change it also in the qmlproject file
|
|
|
|
const Utils::FilePath qmlProjectFilePath = project()->projectFilePath();
|
|
|
|
Core::FileChangeBlocker fileChangeBlocker(qmlProjectFilePath);
|
|
|
|
const QList<Core::IEditor *> editors = Core::DocumentModel::editorsForFilePath(qmlProjectFilePath);
|
|
|
|
TextEditor::TextDocument *document = nullptr;
|
|
|
|
if (!editors.isEmpty()) {
|
|
|
|
document = qobject_cast<TextEditor::TextDocument*>(editors.first()->document());
|
|
|
|
if (document && document->isModified())
|
|
|
|
if (!Core::DocumentManager::saveDocument(document))
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
QString fileContent;
|
|
|
|
QString error;
|
|
|
|
Utils::TextFileFormat textFileFormat;
|
|
|
|
const QTextCodec *codec = QTextCodec::codecForName("UTF-8"); // qml files are defined to be utf-8
|
|
|
|
if (Utils::TextFileFormat::readFile(qmlProjectFilePath, codec, &fileContent, &textFileFormat, &error)
|
|
|
|
!= Utils::TextFileFormat::ReadSuccess) {
|
|
|
|
qWarning() << "Failed to read file" << qmlProjectFilePath << ":" << error;
|
|
|
|
}
|
|
|
|
|
|
|
|
const QString settingQmlCode = setting + ":";
|
|
|
|
|
2022-07-28 15:59:52 +02:00
|
|
|
const Utils::FilePath projectDir = project()->projectFilePath().parentDir();
|
|
|
|
const QString relativePath = mainFilePath.relativeChildPath(projectDir).path();
|
2022-05-10 14:23:51 +02:00
|
|
|
|
|
|
|
if (fileContent.indexOf(settingQmlCode) < 0) {
|
|
|
|
QString addedText = QString("\n %1 \"%2\"\n").arg(settingQmlCode).arg(relativePath);
|
|
|
|
auto index = fileContent.lastIndexOf("}");
|
|
|
|
fileContent.insert(index, addedText);
|
|
|
|
} else {
|
|
|
|
QString originalFileName = oldFile;
|
|
|
|
originalFileName.replace(".", "\\.");
|
|
|
|
const QRegularExpression expression(QString("%1\\s*\"(%2)\"").arg(settingQmlCode).arg(originalFileName));
|
|
|
|
|
|
|
|
const QRegularExpressionMatch match = expression.match(fileContent);
|
|
|
|
|
|
|
|
fileContent.replace(match.capturedStart(1),
|
|
|
|
match.capturedLength(1),
|
|
|
|
relativePath);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!textFileFormat.writeFile(qmlProjectFilePath, fileContent, &error))
|
|
|
|
qWarning() << "Failed to write file" << qmlProjectFilePath << ":" << error;
|
|
|
|
|
|
|
|
refresh(Everything);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2019-10-25 09:55:32 +02:00
|
|
|
void QmlBuildSystem::refresh(RefreshOptions options)
|
2009-05-04 12:19:22 +02:00
|
|
|
{
|
2019-08-06 14:46:37 +02:00
|
|
|
ParseGuard guard = guardParsingRun();
|
2009-05-04 12:19:22 +02:00
|
|
|
parseProject(options);
|
|
|
|
|
|
|
|
if (options & Files)
|
2017-03-01 14:26:46 +01:00
|
|
|
generateProjectTree();
|
2010-06-22 12:54:19 +02:00
|
|
|
|
2017-03-14 11:18:09 +01:00
|
|
|
auto modelManager = QmlJS::ModelManagerInterface::instance();
|
|
|
|
if (!modelManager)
|
2014-07-24 11:48:30 +02:00
|
|
|
return;
|
|
|
|
|
2012-12-06 17:20:58 +01:00
|
|
|
QmlJS::ModelManagerInterface::ProjectInfo projectInfo =
|
2019-10-25 09:55:32 +02:00
|
|
|
modelManager->defaultProjectInfoForProject(project());
|
2022-05-31 16:42:57 +02:00
|
|
|
const QStringList searchPaths = makeAbsolute(canonicalProjectDir(), customImportPaths());
|
|
|
|
for (const QString &searchPath : searchPaths)
|
2019-05-28 13:49:26 +02:00
|
|
|
projectInfo.importPaths.maybeInsert(Utils::FilePath::fromString(searchPath),
|
2014-07-22 19:06:44 +02:00
|
|
|
QmlJS::Dialect::Qml);
|
2013-01-10 16:12:45 +01:00
|
|
|
|
2019-10-25 09:55:32 +02:00
|
|
|
modelManager->updateProjectInfo(projectInfo, project());
|
2016-10-20 13:18:54 +02:00
|
|
|
|
2019-08-06 14:46:37 +02:00
|
|
|
guard.markAsSuccess();
|
2022-06-13 13:23:12 +02:00
|
|
|
|
|
|
|
emit projectChanged();
|
2009-05-04 12:19:22 +02:00
|
|
|
}
|
|
|
|
|
2019-10-25 09:55:32 +02:00
|
|
|
QString QmlBuildSystem::mainFile() const
|
2010-12-03 17:04:29 +01:00
|
|
|
{
|
|
|
|
if (m_projectItem)
|
2021-12-16 11:39:52 +01:00
|
|
|
return m_projectItem->mainFile();
|
2010-12-03 17:04:29 +01:00
|
|
|
return QString();
|
|
|
|
}
|
|
|
|
|
2022-05-10 14:23:51 +02:00
|
|
|
QString QmlBuildSystem::mainUiFile() const
|
|
|
|
{
|
|
|
|
if (m_projectItem)
|
|
|
|
return m_projectItem->mainUiFile();
|
|
|
|
return QString();
|
|
|
|
}
|
|
|
|
|
2021-03-22 21:15:11 +01:00
|
|
|
Utils::FilePath QmlBuildSystem::mainFilePath() const
|
|
|
|
{
|
|
|
|
return projectDirectory().pathAppended(mainFile());
|
|
|
|
}
|
|
|
|
|
2022-05-10 14:23:51 +02:00
|
|
|
Utils::FilePath QmlBuildSystem::mainUiFilePath() const
|
|
|
|
{
|
|
|
|
return projectDirectory().pathAppended(mainUiFile());
|
|
|
|
}
|
|
|
|
|
|
|
|
bool QmlBuildSystem::setMainFileInProjectFile(const Utils::FilePath &newMainFilePath)
|
|
|
|
{
|
|
|
|
|
|
|
|
return setFileSettingInProjectFile("mainFile", newMainFilePath, mainFile());
|
|
|
|
}
|
|
|
|
|
|
|
|
bool QmlBuildSystem::setMainUiFileInProjectFile(const Utils::FilePath &newMainUiFilePath)
|
|
|
|
{
|
|
|
|
return setMainUiFileInMainFile(newMainUiFilePath)
|
|
|
|
&& setFileSettingInProjectFile("mainUiFile", newMainUiFilePath, mainUiFile());
|
|
|
|
}
|
|
|
|
|
|
|
|
bool QmlBuildSystem::setMainUiFileInMainFile(const Utils::FilePath &newMainUiFilePath)
|
|
|
|
{
|
|
|
|
Core::FileChangeBlocker fileChangeBlocker(mainFilePath());
|
|
|
|
const QList<Core::IEditor *> editors = Core::DocumentModel::editorsForFilePath(mainFilePath());
|
|
|
|
TextEditor::TextDocument *document = nullptr;
|
|
|
|
if (!editors.isEmpty()) {
|
|
|
|
document = qobject_cast<TextEditor::TextDocument*>(editors.first()->document());
|
|
|
|
if (document && document->isModified())
|
|
|
|
if (!Core::DocumentManager::saveDocument(document))
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
QString fileContent;
|
|
|
|
QString error;
|
|
|
|
Utils::TextFileFormat textFileFormat;
|
|
|
|
const QTextCodec *codec = QTextCodec::codecForName("UTF-8"); // qml files are defined to be utf-8
|
|
|
|
if (Utils::TextFileFormat::readFile(mainFilePath(), codec, &fileContent, &textFileFormat, &error)
|
|
|
|
!= Utils::TextFileFormat::ReadSuccess) {
|
|
|
|
qWarning() << "Failed to read file" << mainFilePath() << ":" << error;
|
|
|
|
}
|
|
|
|
|
|
|
|
const QString currentMain = QString("%1 {").arg(mainUiFilePath().baseName());
|
|
|
|
const QString newMain = QString("%1 {").arg(newMainUiFilePath.baseName());
|
|
|
|
|
|
|
|
if (fileContent.contains(currentMain))
|
|
|
|
fileContent.replace(currentMain, newMain);
|
|
|
|
|
|
|
|
if (!textFileFormat.writeFile(mainFilePath(), fileContent, &error))
|
|
|
|
qWarning() << "Failed to write file" << mainFilePath() << ":" << error;
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2020-02-20 14:51:45 +01:00
|
|
|
bool QmlBuildSystem::qtForMCUs() const
|
|
|
|
{
|
|
|
|
if (m_projectItem)
|
2021-12-16 11:39:52 +01:00
|
|
|
return m_projectItem->qtForMCUs();
|
2020-02-20 14:51:45 +01:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2021-07-27 14:18:39 +02:00
|
|
|
bool QmlBuildSystem::qt6Project() const
|
|
|
|
{
|
|
|
|
if (m_projectItem)
|
2021-12-16 11:39:52 +01:00
|
|
|
return m_projectItem->qt6Project();
|
2021-07-27 14:18:39 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2019-10-25 09:55:32 +02:00
|
|
|
void QmlBuildSystem::setMainFile(const QString &mainFilePath)
|
2019-01-18 20:38:48 +01:00
|
|
|
{
|
|
|
|
if (m_projectItem)
|
2021-12-16 11:39:52 +01:00
|
|
|
m_projectItem->setMainFile(mainFilePath);
|
2019-01-18 20:38:48 +01:00
|
|
|
}
|
|
|
|
|
2019-10-25 09:55:32 +02:00
|
|
|
Utils::FilePath QmlBuildSystem::targetDirectory() const
|
2017-11-28 15:57:15 +01:00
|
|
|
{
|
2020-09-07 15:56:18 +02:00
|
|
|
if (DeviceTypeKitAspect::deviceTypeId(kit())
|
2017-11-28 15:57:15 +01:00
|
|
|
== ProjectExplorer::Constants::DESKTOP_DEVICE_TYPE)
|
|
|
|
return canonicalProjectDir();
|
|
|
|
|
2019-05-28 13:49:26 +02:00
|
|
|
return m_projectItem ? Utils::FilePath::fromString(m_projectItem->targetDirectory())
|
|
|
|
: Utils::FilePath();
|
2017-11-28 15:57:15 +01:00
|
|
|
}
|
|
|
|
|
2019-10-25 09:55:32 +02:00
|
|
|
Utils::FilePath QmlBuildSystem::targetFile(const Utils::FilePath &sourceFile) const
|
2017-11-28 15:57:15 +01:00
|
|
|
{
|
|
|
|
const QDir sourceDir(m_projectItem ? m_projectItem->sourceDirectory()
|
|
|
|
: canonicalProjectDir().toString());
|
2019-10-25 09:55:32 +02:00
|
|
|
const QDir targetDir(targetDirectory().toString());
|
2017-11-28 15:57:15 +01:00
|
|
|
const QString relative = sourceDir.relativeFilePath(sourceFile.toString());
|
2019-05-28 13:49:26 +02:00
|
|
|
return Utils::FilePath::fromString(QDir::cleanPath(targetDir.absoluteFilePath(relative)));
|
2017-11-28 15:57:15 +01:00
|
|
|
}
|
|
|
|
|
2019-10-25 09:55:32 +02:00
|
|
|
Utils::EnvironmentItems QmlBuildSystem::environment() const
|
2018-01-29 13:38:41 +01:00
|
|
|
{
|
|
|
|
if (m_projectItem)
|
2021-12-16 11:39:52 +01:00
|
|
|
return m_projectItem->environment();
|
2018-01-29 13:38:41 +01:00
|
|
|
return {};
|
|
|
|
}
|
|
|
|
|
2019-10-25 09:55:32 +02:00
|
|
|
QStringList QmlBuildSystem::customImportPaths() const
|
2010-02-03 09:13:23 +01:00
|
|
|
{
|
|
|
|
if (m_projectItem)
|
2021-12-16 11:39:52 +01:00
|
|
|
return m_projectItem->importPaths();
|
2018-02-24 18:36:58 +01:00
|
|
|
return {};
|
2010-02-03 09:13:23 +01:00
|
|
|
}
|
|
|
|
|
2019-10-25 09:55:32 +02:00
|
|
|
QStringList QmlBuildSystem::customFileSelectors() const
|
2019-04-08 17:02:20 +02:00
|
|
|
{
|
|
|
|
if (m_projectItem)
|
2021-12-16 11:39:52 +01:00
|
|
|
return m_projectItem->fileSelectors();
|
2019-04-08 17:02:20 +02:00
|
|
|
return {};
|
|
|
|
}
|
|
|
|
|
2022-01-19 08:24:14 +02:00
|
|
|
bool QmlBuildSystem::multilanguageSupport() const
|
|
|
|
{
|
|
|
|
if (m_projectItem)
|
|
|
|
return m_projectItem->multilanguageSupport();
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2021-10-11 14:58:11 +02:00
|
|
|
QStringList QmlBuildSystem::supportedLanguages() const
|
|
|
|
{
|
|
|
|
if (m_projectItem)
|
2021-12-16 11:39:52 +01:00
|
|
|
return m_projectItem->supportedLanguages();
|
2021-10-11 14:58:11 +02:00
|
|
|
return {};
|
|
|
|
}
|
|
|
|
|
2021-11-03 16:47:04 +02:00
|
|
|
void QmlBuildSystem::setSupportedLanguages(QStringList languages)
|
|
|
|
{
|
|
|
|
if (m_projectItem)
|
2021-12-16 11:39:52 +01:00
|
|
|
m_projectItem->setSupportedLanguages(languages);
|
2021-11-03 16:47:04 +02:00
|
|
|
}
|
|
|
|
|
2021-10-13 15:50:23 +03:00
|
|
|
QString QmlBuildSystem::primaryLanguage() const
|
|
|
|
{
|
|
|
|
if (m_projectItem)
|
2021-12-16 11:39:52 +01:00
|
|
|
return m_projectItem->primaryLanguage();
|
2021-10-13 15:50:23 +03:00
|
|
|
return {};
|
|
|
|
}
|
|
|
|
|
2021-11-03 16:47:04 +02:00
|
|
|
void QmlBuildSystem::setPrimaryLanguage(QString language)
|
|
|
|
{
|
|
|
|
if (m_projectItem)
|
2021-12-16 11:39:52 +01:00
|
|
|
m_projectItem->setPrimaryLanguage(language);
|
2021-11-03 16:47:04 +02:00
|
|
|
}
|
|
|
|
|
2019-10-25 09:55:32 +02:00
|
|
|
void QmlBuildSystem::refreshProjectFile()
|
2010-01-19 13:53:48 +01:00
|
|
|
{
|
2019-10-25 09:55:32 +02:00
|
|
|
refresh(QmlBuildSystem::ProjectFile | Files);
|
2010-01-19 13:53:48 +01:00
|
|
|
}
|
|
|
|
|
2019-10-25 09:55:32 +02:00
|
|
|
QStringList QmlBuildSystem::makeAbsolute(const Utils::FilePath &path, const QStringList &relativePaths)
|
2018-02-26 14:26:07 +01:00
|
|
|
{
|
|
|
|
if (path.isEmpty())
|
|
|
|
return relativePaths;
|
|
|
|
|
|
|
|
const QDir baseDir(path.toString());
|
|
|
|
return Utils::transform(relativePaths, [&baseDir](const QString &path) {
|
|
|
|
return QDir::cleanPath(baseDir.absoluteFilePath(path));
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2019-10-25 09:55:32 +02:00
|
|
|
void QmlBuildSystem::refreshFiles(const QSet<QString> &/*added*/, const QSet<QString> &removed)
|
2010-01-19 13:53:48 +01:00
|
|
|
{
|
2020-03-03 12:30:28 +01:00
|
|
|
if (m_blockFilesUpdate) {
|
|
|
|
qCDebug(infoLogger) << "Auto files refresh blocked.";
|
|
|
|
return;
|
|
|
|
}
|
2010-01-19 13:53:48 +01:00
|
|
|
refresh(Files);
|
2017-03-14 11:18:09 +01:00
|
|
|
if (!removed.isEmpty()) {
|
2022-06-20 12:35:13 +02:00
|
|
|
if (auto modelManager = QmlJS::ModelManagerInterface::instance()) {
|
|
|
|
Utils::FilePaths pathsRemoved(removed.size());
|
|
|
|
std::transform(removed.cbegin(),
|
|
|
|
removed.cend(),
|
|
|
|
pathsRemoved.begin(),
|
|
|
|
[](const QString &s) { return Utils::FilePath::fromString(s); });
|
|
|
|
modelManager->removeFiles(pathsRemoved);
|
|
|
|
}
|
2017-03-14 11:18:09 +01:00
|
|
|
}
|
2017-11-28 15:57:15 +01:00
|
|
|
refreshTargetDirectory();
|
2010-01-19 13:53:48 +01:00
|
|
|
}
|
|
|
|
|
2019-10-25 09:55:32 +02:00
|
|
|
void QmlBuildSystem::refreshTargetDirectory()
|
2009-05-04 12:19:22 +02:00
|
|
|
{
|
2019-10-25 09:55:32 +02:00
|
|
|
updateDeploymentData();
|
2017-11-28 15:57:15 +01:00
|
|
|
}
|
2012-04-24 15:49:09 +02:00
|
|
|
|
2019-05-27 16:09:44 +02:00
|
|
|
Tasks QmlProject::projectIssues(const Kit *k) const
|
2017-11-28 15:57:15 +01:00
|
|
|
{
|
2019-05-27 16:09:44 +02:00
|
|
|
Tasks result = Project::projectIssues(k);
|
2018-04-18 13:39:05 +02:00
|
|
|
|
2022-01-21 16:06:36 +01:00
|
|
|
const QtSupport::QtVersion *version = QtSupport::QtKitAspect::qtVersion(k);
|
2018-04-18 13:39:05 +02:00
|
|
|
if (!version)
|
|
|
|
result.append(createProjectTask(Task::TaskType::Error, tr("No Qt version set in kit.")));
|
2018-03-08 17:46:20 +01:00
|
|
|
|
2019-02-06 12:50:51 +01:00
|
|
|
IDevice::ConstPtr dev = DeviceKitAspect::device(k);
|
2018-04-18 13:39:05 +02:00
|
|
|
if (dev.isNull())
|
|
|
|
result.append(createProjectTask(Task::TaskType::Error, tr("Kit has no device.")));
|
2018-03-08 17:46:20 +01:00
|
|
|
|
2018-04-18 13:39:05 +02:00
|
|
|
if (version && version->qtVersion() < QtSupport::QtVersionNumber(5, 0, 0))
|
|
|
|
result.append(createProjectTask(Task::TaskType::Error, tr("Qt version is too old.")));
|
|
|
|
|
|
|
|
if (dev.isNull() || !version)
|
|
|
|
return result; // No need to check deeper than this
|
2018-03-08 17:46:20 +01:00
|
|
|
|
|
|
|
if (dev->type() == ProjectExplorer::Constants::DESKTOP_DEVICE_TYPE) {
|
2018-03-08 17:46:51 +01:00
|
|
|
if (version->type() == QtSupport::Constants::DESKTOPQT) {
|
2021-07-13 09:41:26 +02:00
|
|
|
if (version->qmlRuntimeFilePath().isEmpty()) {
|
2018-04-18 13:39:05 +02:00
|
|
|
result.append(createProjectTask(Task::TaskType::Error,
|
2021-07-12 10:38:13 +02:00
|
|
|
tr("Qt version has no QML utility.")));
|
2018-03-08 17:46:20 +01:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
// Non-desktop Qt on a desktop device? We don't support that.
|
2018-04-18 13:39:05 +02:00
|
|
|
result.append(createProjectTask(Task::TaskType::Error,
|
2018-06-08 13:53:51 +02:00
|
|
|
tr("Non-desktop Qt is used with a desktop device.")));
|
2018-03-08 17:46:20 +01:00
|
|
|
}
|
2018-04-18 13:39:05 +02:00
|
|
|
} else {
|
2021-07-12 10:38:13 +02:00
|
|
|
// If not a desktop device, don't check the Qt version for qml runtime binary.
|
|
|
|
// The device is responsible for providing it and we assume qml runtime can be found
|
2018-04-18 13:39:05 +02:00
|
|
|
// in $PATH if it's not explicitly given.
|
2018-03-08 17:46:20 +01:00
|
|
|
}
|
|
|
|
|
2018-04-18 13:39:05 +02:00
|
|
|
return result;
|
2009-05-04 12:19:22 +02:00
|
|
|
}
|
|
|
|
|
2022-02-07 10:06:16 +01:00
|
|
|
bool QmlProject::isEditModePreferred() const
|
|
|
|
{
|
|
|
|
return !isQtDesignStudio();
|
|
|
|
}
|
|
|
|
|
2015-05-18 16:57:29 +02:00
|
|
|
Project::RestoreResult QmlProject::fromMap(const QVariantMap &map, QString *errorMessage)
|
2009-05-04 12:19:22 +02:00
|
|
|
{
|
2015-05-18 16:57:29 +02:00
|
|
|
RestoreResult result = Project::fromMap(map, errorMessage);
|
2015-09-08 17:15:17 +02:00
|
|
|
if (result != RestoreResult::Ok)
|
2015-05-18 16:57:29 +02:00
|
|
|
return result;
|
2009-05-04 12:19:22 +02:00
|
|
|
|
2013-03-07 14:02:04 +01:00
|
|
|
if (!activeTarget()) {
|
|
|
|
// find a kit that matches prerequisites (prefer default one)
|
2021-08-03 16:07:42 +02:00
|
|
|
const QList<Kit *> kits = Utils::filtered(KitManager::kits(), [this](const Kit *k) {
|
|
|
|
return !containsType(projectIssues(k), Task::TaskType::Error)
|
|
|
|
&& DeviceTypeKitAspect::deviceTypeId(k)
|
|
|
|
== ProjectExplorer::Constants::DESKTOP_DEVICE_TYPE;
|
2018-04-18 13:39:05 +02:00
|
|
|
});
|
2013-03-07 14:02:04 +01:00
|
|
|
|
|
|
|
if (!kits.isEmpty()) {
|
2019-08-01 14:58:00 +02:00
|
|
|
if (kits.contains(KitManager::defaultKit()))
|
|
|
|
addTargetForDefaultKit();
|
|
|
|
else
|
|
|
|
addTargetForKit(kits.first());
|
2013-03-07 14:02:04 +01:00
|
|
|
}
|
2021-08-03 16:07:42 +02:00
|
|
|
|
2022-02-04 16:59:04 +01:00
|
|
|
if (QmlProject::isQtDesignStudio()) {
|
2021-08-03 16:07:42 +02:00
|
|
|
auto setKitWithVersion = [&](int qtMajorVersion) {
|
|
|
|
const QList<Kit *> qtVersionkits
|
|
|
|
= Utils::filtered(kits, [qtMajorVersion](const Kit *k) {
|
2022-07-20 18:45:32 +02:00
|
|
|
if (!k->isAutoDetected())
|
|
|
|
return false;
|
|
|
|
if (k->isReplacementKit())
|
|
|
|
return false;
|
2022-01-21 16:06:36 +01:00
|
|
|
QtSupport::QtVersion *version = QtSupport::QtKitAspect::qtVersion(k);
|
2021-08-03 16:07:42 +02:00
|
|
|
return (version && version->qtVersion().majorVersion == qtMajorVersion);
|
|
|
|
});
|
|
|
|
if (!qtVersionkits.isEmpty()) {
|
|
|
|
if (qtVersionkits.contains(KitManager::defaultKit()))
|
|
|
|
addTargetForDefaultKit();
|
|
|
|
else
|
|
|
|
addTargetForKit(qtVersionkits.first());
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
int preferedVersion = preferedQtTarget(activeTarget());
|
|
|
|
|
|
|
|
if (activeTarget())
|
|
|
|
removeTarget(activeTarget());
|
|
|
|
|
|
|
|
setKitWithVersion(preferedVersion);
|
|
|
|
}
|
2013-03-07 14:02:04 +01:00
|
|
|
}
|
2009-05-07 12:27:52 +02:00
|
|
|
|
2015-05-18 16:57:29 +02:00
|
|
|
return RestoreResult::Ok;
|
2009-05-04 12:19:22 +02:00
|
|
|
}
|
|
|
|
|
2022-02-04 16:59:04 +01:00
|
|
|
bool QmlProject::isQtDesignStudio()
|
|
|
|
{
|
|
|
|
QSettings *settings = Core::ICore::settings();
|
|
|
|
const QString qdsStandaloneEntry = "QML/Designer/StandAloneMode";
|
|
|
|
|
|
|
|
return settings->value(qdsStandaloneEntry, false).toBool();
|
|
|
|
}
|
|
|
|
|
2022-02-22 16:33:53 +01:00
|
|
|
bool QmlProject::isQtDesignStudioStartedFromQtC()
|
|
|
|
{
|
|
|
|
return qEnvironmentVariableIsSet(Constants::enviromentLaunchedQDS);
|
|
|
|
}
|
|
|
|
|
2019-04-12 14:49:59 +02:00
|
|
|
ProjectExplorer::DeploymentKnowledge QmlProject::deploymentKnowledge() const
|
|
|
|
{
|
|
|
|
return DeploymentKnowledge::Perfect;
|
|
|
|
}
|
|
|
|
|
2019-10-25 09:55:32 +02:00
|
|
|
void QmlBuildSystem::generateProjectTree()
|
2017-03-01 14:26:46 +01:00
|
|
|
{
|
2017-03-27 12:12:38 +02:00
|
|
|
if (!m_projectItem)
|
|
|
|
return;
|
|
|
|
|
2019-10-25 09:55:32 +02:00
|
|
|
auto newRoot = std::make_unique<QmlProjectNode>(project());
|
2017-03-01 14:26:46 +01:00
|
|
|
|
2020-07-20 16:25:53 +02:00
|
|
|
for (const QString &f : m_projectItem->files()) {
|
2019-05-28 13:49:26 +02:00
|
|
|
const Utils::FilePath fileName = Utils::FilePath::fromString(f);
|
2017-11-23 11:41:35 +01:00
|
|
|
const FileType fileType = (fileName == projectFilePath())
|
|
|
|
? FileType::Project : FileNode::fileTypeForFileName(fileName);
|
2019-02-25 12:08:58 +01:00
|
|
|
newRoot->addNestedNode(std::make_unique<FileNode>(fileName, fileType));
|
2017-03-10 17:30:40 +01:00
|
|
|
}
|
2019-02-25 12:08:58 +01:00
|
|
|
newRoot->addNestedNode(std::make_unique<FileNode>(projectFilePath(), FileType::Project));
|
2017-03-01 14:26:46 +01:00
|
|
|
|
2019-11-20 15:21:54 +01:00
|
|
|
setRootProjectNode(std::move(newRoot));
|
2017-11-28 15:57:15 +01:00
|
|
|
refreshTargetDirectory();
|
2017-03-01 14:26:46 +01:00
|
|
|
}
|
|
|
|
|
2019-10-25 09:55:32 +02:00
|
|
|
void QmlBuildSystem::updateDeploymentData()
|
2017-11-28 15:57:15 +01:00
|
|
|
{
|
|
|
|
if (!m_projectItem)
|
|
|
|
return;
|
|
|
|
|
2020-09-07 15:56:18 +02:00
|
|
|
if (DeviceTypeKitAspect::deviceTypeId(kit())
|
2017-11-28 15:57:15 +01:00
|
|
|
== ProjectExplorer::Constants::DESKTOP_DEVICE_TYPE) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
ProjectExplorer::DeploymentData deploymentData;
|
|
|
|
for (const QString &file : m_projectItem->files()) {
|
|
|
|
deploymentData.addFile(
|
2021-09-13 12:55:01 +02:00
|
|
|
FilePath::fromString(file),
|
2019-10-25 09:55:32 +02:00
|
|
|
targetFile(Utils::FilePath::fromString(file)).parentDir().toString());
|
|
|
|
}
|
|
|
|
|
|
|
|
setDeploymentData(deploymentData);
|
|
|
|
}
|
|
|
|
|
|
|
|
QVariant QmlBuildSystem::additionalData(Id id) const
|
|
|
|
{
|
|
|
|
if (id == Constants::customFileSelectorsData)
|
|
|
|
return customFileSelectors();
|
2021-10-11 14:58:11 +02:00
|
|
|
if (id == Constants::supportedLanguagesData)
|
|
|
|
return supportedLanguages();
|
2021-10-13 15:50:23 +03:00
|
|
|
if (id == Constants::primaryLanguageData)
|
|
|
|
return primaryLanguage();
|
2019-12-06 13:04:17 +02:00
|
|
|
if (id == Constants::customForceFreeTypeData)
|
|
|
|
return forceFreeType();
|
2020-02-20 14:51:45 +01:00
|
|
|
if (id == Constants::customQtForMCUs)
|
|
|
|
return qtForMCUs();
|
2021-07-27 14:18:39 +02:00
|
|
|
if (id == Constants::customQt6Project)
|
|
|
|
return qt6Project();
|
2021-08-16 13:48:26 +02:00
|
|
|
if (id == Constants::mainFilePath)
|
|
|
|
return mainFilePath().toString();
|
|
|
|
if (id == Constants::customImportPaths)
|
|
|
|
return customImportPaths();
|
|
|
|
if (id == Constants::canonicalProjectDir)
|
|
|
|
return canonicalProjectDir().toString();
|
2019-10-25 09:55:32 +02:00
|
|
|
return {};
|
|
|
|
}
|
|
|
|
|
|
|
|
bool QmlBuildSystem::supportsAction(Node *context, ProjectAction action, const Node *node) const
|
|
|
|
{
|
|
|
|
if (dynamic_cast<QmlProjectNode *>(context)) {
|
|
|
|
if (action == AddNewFile || action == EraseFile)
|
|
|
|
return true;
|
|
|
|
QTC_ASSERT(node, return false);
|
|
|
|
|
|
|
|
if (action == Rename && node->asFileNode()) {
|
|
|
|
const FileNode *fileNode = node->asFileNode();
|
|
|
|
QTC_ASSERT(fileNode, return false);
|
|
|
|
return fileNode->fileType() != FileType::Project;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return BuildSystem::supportsAction(context, action, node);
|
|
|
|
}
|
|
|
|
|
|
|
|
QmlProject *QmlBuildSystem::qmlProject() const
|
|
|
|
{
|
|
|
|
return static_cast<QmlProject *>(BuildSystem::project());
|
|
|
|
}
|
|
|
|
|
2019-12-06 13:04:17 +02:00
|
|
|
bool QmlBuildSystem::forceFreeType() const
|
|
|
|
{
|
|
|
|
if (m_projectItem)
|
2021-12-16 11:39:52 +01:00
|
|
|
return m_projectItem->forceFreeType();
|
2019-12-06 13:04:17 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2021-12-07 15:04:04 +02:00
|
|
|
bool QmlBuildSystem::widgetApp() const
|
|
|
|
{
|
|
|
|
if (m_projectItem)
|
2021-12-16 11:39:52 +01:00
|
|
|
return m_projectItem->widgetApp();
|
2021-12-07 15:04:04 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2022-04-01 14:32:20 +03:00
|
|
|
QStringList QmlBuildSystem::shaderToolArgs() const
|
|
|
|
{
|
|
|
|
if (m_projectItem)
|
|
|
|
return m_projectItem->shaderToolArgs();
|
|
|
|
return {};
|
|
|
|
}
|
|
|
|
|
|
|
|
QStringList QmlBuildSystem::shaderToolFiles() const
|
|
|
|
{
|
|
|
|
if (m_projectItem)
|
|
|
|
return m_projectItem->shaderToolFiles();
|
|
|
|
return {};
|
|
|
|
}
|
|
|
|
|
2022-06-13 13:23:12 +02:00
|
|
|
QStringList QmlBuildSystem::importPaths() const
|
|
|
|
{
|
|
|
|
if (m_projectItem)
|
|
|
|
return m_projectItem->importPaths();
|
|
|
|
return {};
|
|
|
|
}
|
|
|
|
|
|
|
|
QStringList QmlBuildSystem::files() const
|
|
|
|
{
|
|
|
|
if (m_projectItem)
|
|
|
|
return m_projectItem->files();
|
|
|
|
return {};
|
|
|
|
}
|
|
|
|
|
2021-07-14 16:49:42 +02:00
|
|
|
bool QmlBuildSystem::addFiles(Node *context, const FilePaths &filePaths, FilePaths *)
|
2019-10-25 09:55:32 +02:00
|
|
|
{
|
|
|
|
if (!dynamic_cast<QmlProjectNode *>(context))
|
|
|
|
return false;
|
|
|
|
|
2021-07-14 16:49:42 +02:00
|
|
|
FilePaths toAdd;
|
|
|
|
for (const FilePath &filePath : filePaths) {
|
2021-12-16 11:39:52 +01:00
|
|
|
if (!m_projectItem->matchesFile(filePath.toString()))
|
2019-10-25 09:55:32 +02:00
|
|
|
toAdd << filePaths;
|
|
|
|
}
|
|
|
|
return toAdd.isEmpty();
|
|
|
|
}
|
|
|
|
|
2021-07-14 16:49:42 +02:00
|
|
|
bool QmlBuildSystem::deleteFiles(Node *context, const FilePaths &filePaths)
|
2019-10-25 09:55:32 +02:00
|
|
|
{
|
|
|
|
if (dynamic_cast<QmlProjectNode *>(context))
|
|
|
|
return true;
|
|
|
|
|
|
|
|
return BuildSystem::deleteFiles(context, filePaths);
|
|
|
|
}
|
|
|
|
|
2021-06-11 14:34:34 +02:00
|
|
|
bool QmlBuildSystem::renameFile(Node * context, const FilePath &oldFilePath, const FilePath &newFilePath)
|
2019-10-25 09:55:32 +02:00
|
|
|
{
|
|
|
|
if (dynamic_cast<QmlProjectNode *>(context)) {
|
2022-05-10 14:23:51 +02:00
|
|
|
if (oldFilePath.endsWith(mainFile()))
|
|
|
|
return setMainFileInProjectFile(newFilePath);
|
|
|
|
if (oldFilePath.endsWith(mainUiFile()))
|
|
|
|
return setMainUiFileInProjectFile(newFilePath);
|
2019-10-25 09:55:32 +02:00
|
|
|
|
|
|
|
return true;
|
2017-11-28 15:57:15 +01:00
|
|
|
}
|
|
|
|
|
2021-06-11 14:34:34 +02:00
|
|
|
return BuildSystem::renameFile(context, oldFilePath, newFilePath);
|
2017-11-28 15:57:15 +01:00
|
|
|
}
|
2019-10-22 14:55:51 +02:00
|
|
|
|
2010-02-16 13:39:13 +01:00
|
|
|
} // namespace QmlProjectManager
|
2009-12-17 09:54:16 +01:00
|
|
|
|