QmlProjectManager: Add initial support for multiple qmlproject files

This patch adds read-only support for sub MCU projects.

Task-number: QDS-12575
Change-Id: I0dc3b6ff37731f30875c03a3896bbabc4867c4fc
Reviewed-by: Marco Bubke <marco.bubke@qt.io>
This commit is contained in:
Burak Hancerli
2024-04-29 13:19:39 +02:00
parent a7fd0a78d1
commit dd20f54207
5 changed files with 118 additions and 19 deletions

View File

@@ -0,0 +1,50 @@
Language: Cpp
AccessModifierOffset: -4
AlignEscapedNewlines: DontAlign
AllowShortFunctionsOnASingleLine: Inline
AlwaysBreakTemplateDeclarations: true # use with clang 19
BinPackArguments: false
BinPackParameters: false
BraceWrapping:
AfterClass: true
AfterFunction: true
AfterStruct: true
SplitEmptyFunction: false
SplitEmptyRecord: false
SplitEmptyNamespace: false
BreakBeforeBinaryOperators: All
BreakBeforeBraces: Custom
BreakConstructorInitializers: BeforeComma
BreakInheritanceList: AfterComma
# BreakTemplateDeclarations: Yes # use with clang 19
ColumnLimit: 100
IncludeCategories:
- Regex: 'Q.*'
Priority: 8
CaseSensitive: true
IndentPPDirectives: AfterHash
IndentWidth: 4
KeepEmptyLinesAtTheStartOfBlocks: false
# Do not add QT_BEGIN_NAMESPACE/QT_END_NAMESPACE as this will indent lines in between.
ObjCBlockIndentWidth: 4
PPIndentWidth: 2
PackConstructorInitializers: Never
PenaltyBreakAssignment: 500
PenaltyBreakBeforeFirstCallParameter: 150
PenaltyBreakComment: 500
PenaltyBreakFirstLessLess: 400
PenaltyBreakString: 600
PenaltyExcessCharacter: 7
PenaltyReturnTypeOnItsOwnLine: 300
QualifierAlignment: Custom
QualifierOrder: ['friend', 'inline', 'static', 'constexpr', 'const', 'type']
ReferenceAlignment: Right
ReflowComments: false
SeparateDefinitionBlocks: Always
SortUsingDeclarations: Lexicographic
SpaceAfterCStyleCast: true
SpaceAfterTemplateKeyword: false
SpaceBeforeParens: ControlStatementsExceptControlMacros
SpacesInContainerLiterals: false
StatementAttributeLikeMacros: [emit]
TabWidth: 4

View File

@@ -79,7 +79,7 @@ void QmlProjectItem::setupFileFilters()
connect(fileFilterItem.get(),
&FileFilterItem::filesChanged,
this,
&QmlProjectItem::qmlFilesChanged);
&QmlProjectItem::filesChanged);
#endif
m_content.push_back(std::move(fileFilterItem));
};
@@ -105,10 +105,7 @@ void QmlProjectItem::setupFileFilters()
fileFilterItem->setDefaultDirectory(m_projectFile.parentDir().toString());
fileFilterItem->setDirectory(groupDir.toString());
#ifndef TESTS_ENABLED_QMLPROJECTITEM
connect(fileFilterItem.get(),
&FileFilterItem::filesChanged,
this,
&QmlProjectItem::qmlFilesChanged);
connect(fileFilterItem.get(), &FileFilterItem::filesChanged, this, &QmlProjectItem::filesChanged);
#endif
m_content.push_back(std::move(fileFilterItem));
};

View File

@@ -92,7 +92,7 @@ public:
void setEnableCMakeGeneration(bool enable);
signals:
void qmlFilesChanged(const QSet<QString> &, const QSet<QString> &);
void filesChanged(const QSet<QString> &, const QSet<QString> &);
private:
typedef QSharedPointer<QmlProjectItem> ShrdPtrQPI;

View File

@@ -37,6 +37,8 @@
#include "projectnode/qmlprojectnodes.h"
#include "utils/algorithm.h"
#include "utils/filepath.h"
#include "utils/filesystemwatcher.h"
#include "utils/qtcassert.h"
#include "texteditor/textdocument.h"
@@ -220,17 +222,56 @@ void QmlBuildSystem::refresh(RefreshOptions options)
void QmlBuildSystem::initProjectItem()
{
m_projectItem.reset(new QmlProjectItem{projectFilePath()});
connect(m_projectItem.get(),
&QmlProjectItem::qmlFilesChanged,
this,
&QmlBuildSystem::refreshFiles);
connect(m_projectItem.get(),
&QmlProjectItem::qmlFilesChanged,
connect(m_projectItem.data(), &QmlProjectItem::filesChanged, this, &QmlBuildSystem::refreshFiles);
connect(m_projectItem.data(),
&QmlProjectItem::filesChanged,
m_cmakeGen,
&GenerateCmake::CMakeGenerator::update);
m_cmakeGen->setEnabled(m_projectItem->enableCMakeGeneration());
initMcuProjectItems();
}
void QmlBuildSystem::initMcuProjectItems()
{
m_mcuProjectItems.clear();
m_mcuProjectFilesWatcher.clear();
Utils::FilePath projectDir = projectFilePath().parentDir();
// traverse the project dir and find all other mcu projects (.qmlproject files) in the project tree
// and add them to the m_mcuProjectItems vector
QDirIterator it(projectDir.toString(), QDir::Files, QDirIterator::Subdirectories);
while (it.hasNext()) {
it.next();
if (it.fileInfo().suffix() == "qmlproject" && it.filePath() != projectFilePath().toString()) {
auto qmlProjectItem = QSharedPointer<QmlProjectItem>(
new QmlProjectItem{Utils::FilePath::fromString(it.filePath())});
m_mcuProjectItems.append(qmlProjectItem);
connect(qmlProjectItem.data(),
&QmlProjectItem::filesChanged,
this,
&QmlBuildSystem::refreshFiles);
connect(qmlProjectItem.data(),
&QmlProjectItem::filesChanged,
m_cmakeGen,
&GenerateCmake::CMakeGenerator::update);
m_mcuProjectFilesWatcher.addFile(it.filePath(),
Utils::FileSystemWatcher::WatchModifiedDate);
connect(&m_mcuProjectFilesWatcher,
&Utils::FileSystemWatcher::fileChanged,
this,
[this](const QString &file) {
Q_UNUSED(file)
initMcuProjectItems();
refresh(RefreshOptions::Files);
});
}
}
}
void QmlBuildSystem::parseProjectFiles()
@@ -239,7 +280,6 @@ void QmlBuildSystem::parseProjectFiles()
modelManager->updateSourceFiles(m_projectItem->files(), true);
}
const QString mainFileName = m_projectItem->mainFile();
if (!mainFileName.isEmpty()) {
Utils::FilePath mainFilePath = canonicalProjectDir().resolvePath(mainFileName);
@@ -265,6 +305,16 @@ void QmlBuildSystem::generateProjectTree()
: FileNode::fileTypeForFileName(file);
newRoot->addNestedNode(std::make_unique<FileNode>(file, fileType));
}
for (const auto &mcuProjectItem : m_mcuProjectItems) {
for (const auto &file : mcuProjectItem->files()) {
// newRoot->addNestedNode(std::make_unique<FileNode>(file, FileType::Project));
const FileType fileType = (file == projectFilePath())
? FileType::Project
: FileNode::fileTypeForFileName(file);
newRoot->addNestedNode(std::make_unique<FileNode>(file, fileType));
}
}
newRoot->addNestedNode(std::make_unique<FileNode>(projectFilePath(), FileType::Project));
setRootProjectNode(std::move(newRoot));
@@ -692,11 +742,6 @@ QStringList QmlBuildSystem::absoluteImportPaths()
});
}
Utils::FilePaths QmlBuildSystem::files() const
{
return m_projectItem->files();
}
QString QmlBuildSystem::versionQt() const
{
return m_projectItem->versionQt();

View File

@@ -7,9 +7,12 @@
#include "../qmlprojectmanager_global.h"
#include <projectexplorer/buildsystem.h>
#include <QtCore/qfilesystemwatcher.h>
#include "qmlprojectmanager/cmakegen/cmakegenerator.h"
#include "utils/filesystemwatcher.h"
namespace QmlProjectManager {
class QmlProject;
@@ -91,7 +94,6 @@ public:
QStringList shaderToolArgs() const;
QStringList shaderToolFiles() const;
Utils::FilePaths files() const;
QString versionQt() const;
QString versionQtQuick() const;
@@ -117,10 +119,15 @@ private:
const Utils::FilePath &mainFilePath,
const QString &oldFile);
// this is the main project item
QSharedPointer<QmlProjectItem> m_projectItem;
// these are the mcu project items which can be found in the project tree
QVector<QSharedPointer<QmlProjectItem>> m_mcuProjectItems;
Utils::FileSystemWatcher m_mcuProjectFilesWatcher;
bool m_blockFilesUpdate = false;
void initProjectItem();
void initMcuProjectItems();
void parseProjectFiles();
void generateProjectTree();