summaryrefslogtreecommitdiff
path: root/src/plugins/mcusupport/mcuqmlprojectnode.cpp
diff options
context:
space:
mode:
authorYasser Grimes <yasser.grimes@qt.io>2023-01-19 10:17:21 +0200
committerYasser Grimes <yasser.grimes@qt.io>2023-01-31 13:25:07 +0000
commit862f484af59cea06b99a743316c2ffcc0a252686 (patch)
treeb8c2b2969d602ab0b687f9e06e34c93e931ec33e /src/plugins/mcusupport/mcuqmlprojectnode.cpp
parent3d79244dd5d1ab375faa61f4d96b180985ff06f4 (diff)
downloadqt-creator-862f484af59cea06b99a743316c2ffcc0a252686.tar.gz
McuSupport: Extend CMake targets tree for QtMCUs QmlProject projects
CMake project relies on the CMake's file-api to fill the Project View, QtMCUs 2.4 will be using a different method to read input files (Qml, Fonts, Images, Headers...) using qmlprojectexporter process, that process is still called from CMake thus a CMakeProject is still used in QtMCUs kits, but unlike previous versions add_sources is not called on QtMCUs target making the list of input files read by the file-api empty and as a result an empty Project Tree. This commit extend uses the SessionManager to listen to when the the projects are loaded and then use input.json file to populate QtMCUs projects trees for projects using qmlprojectexporter the same tool generating input.json . Task-number: QTCREATORBUG-28516 Change-Id: I30a9daf1032e727692b8d71d01ab65634d0ae2a6 Reviewed-by: Christian Kandeler <christian.kandeler@qt.io> Reviewed-by: <github-actions-qt-creator@cristianadam.eu> Reviewed-by: hjk <hjk@qt.io>
Diffstat (limited to 'src/plugins/mcusupport/mcuqmlprojectnode.cpp')
-rw-r--r--src/plugins/mcusupport/mcuqmlprojectnode.cpp96
1 files changed, 96 insertions, 0 deletions
diff --git a/src/plugins/mcusupport/mcuqmlprojectnode.cpp b/src/plugins/mcusupport/mcuqmlprojectnode.cpp
new file mode 100644
index 0000000000..9b1c1caf89
--- /dev/null
+++ b/src/plugins/mcusupport/mcuqmlprojectnode.cpp
@@ -0,0 +1,96 @@
+// Copyright (C) 2023 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
+
+#include "mcuqmlprojectnode.h"
+
+#include <projectexplorer/projectnodes.h>
+
+namespace McuSupport::Internal {
+
+using namespace ProjectExplorer;
+using namespace Utils;
+
+McuQmlProjectNode::McuQmlProjectNode(const FilePath &projectFolder, const FilePath &inputsJsonFile)
+ : FolderNode(projectFolder)
+{
+ setDisplayName("QmlProject");
+ setIcon(DirectoryIcon(":/projectexplorer/images/fileoverlay_qml.png"));
+ setIsGenerated(false);
+ setPriority(Node::DefaultProjectPriority);
+ setFilePath(projectFolder);
+ setListInProject(true);
+
+ const expected_str<QByteArray> expectedJsonContent = inputsJsonFile.fileContents();
+ if (!expectedJsonContent)
+ return;
+
+ const QJsonDocument inputDoc = QJsonDocument::fromJson(*expectedJsonContent);
+ const QVariantMap mainProjectObject = inputDoc.object().toVariantMap();
+ const FilePath mainProjectFilePath = FilePath::fromUserInput(
+ mainProjectObject.value("qmlProjectFile", "").toString());
+
+ auto mainFileNode = std::make_unique<FileNode>(mainProjectFilePath,
+ FileNode::fileTypeForFileName(
+ mainProjectFilePath));
+ mainFileNode->setPriority(100);
+ addNestedNode(std::move(mainFileNode));
+
+ this->populateModuleNode(this, mainProjectObject);
+
+ auto modulesNode = std::make_unique<McuQmlProjectFolderNode>(filePath());
+ modulesNode->setDisplayName("QmlProject Modules");
+ modulesNode->setIcon(DirectoryIcon(":/projectexplorer/images/fileoverlay_modules.png"));
+ modulesNode->setPriority(10);
+ for (QVariant moduleVariant : mainProjectObject.value("modulesDependencies", {}).toList()) {
+ const QVariantMap moduleObject = moduleVariant.toMap();
+ auto moduleNode = std::make_unique<McuQmlProjectFolderNode>(filePath());
+ moduleNode->setIcon(DirectoryIcon(":/projectexplorer/images/fileoverlay_qml.png"));
+ moduleNode->setDisplayName(
+ FilePath::fromUserInput(moduleObject.value("qmlProjectFile", "module").toString())
+ .baseName());
+ populateModuleNode(moduleNode.get(), moduleObject);
+ modulesNode->addNode(std::move(moduleNode));
+ }
+ addNode(std::move(modulesNode));
+}
+
+bool McuQmlProjectNode::populateModuleNode(FolderNode *moduleNode, const QVariantMap &moduleObject)
+{
+ if (!moduleNode)
+ return false;
+
+ const static int NODES_COUNT = 6;
+ const static QString nodes[NODES_COUNT] = {"QmlFiles",
+ "ImageFiles",
+ "InterfaceFiles",
+ "FontFiles",
+ "TranslationFiles",
+ "ModuleFiles"};
+ const static QString icons[NODES_COUNT] = {":/projectexplorer/images/fileoverlay_qml.png",
+ ":/projectexplorer/images/fileoverlay_qrc.png",
+ ":/projectexplorer/images/fileoverlay_h.png",
+ ":/projectexplorer/images/fileoverlay_qrc.png",
+ ":/projectexplorer/images/fileoverlay_qrc.png",
+ ":/projectexplorer/images/fileoverlay_qml.png"};
+ const static int priorities[NODES_COUNT] = {70, 60, 50, 40, 30, 20};
+
+ for (int i = 0; i < NODES_COUNT; i++) {
+ const QString &node = nodes[i];
+ const QString &icon = icons[i];
+ const int &p = priorities[i];
+ auto foldernode = std::make_unique<McuQmlProjectFolderNode>(filePath());
+ foldernode->setShowWhenEmpty(false);
+ foldernode->setDisplayName(node);
+ foldernode->setIcon(DirectoryIcon(icon));
+ foldernode->setPriority(p);
+ const auto nodeFiles = moduleObject.value(node, {}).toStringList();
+ for (auto p : nodeFiles) {
+ const FilePath nodePath = FilePath::fromUserInput(p);
+ foldernode->addNestedNode(
+ std::make_unique<FileNode>(nodePath, FileNode::fileTypeForFileName(nodePath)));
+ }
+ moduleNode->addNode(std::move(foldernode));
+ }
+ return true;
+}
+} // namespace McuSupport::Internal