forked from qt-creator/qt-creator
QmlProjectItem: ability to extend existing qml module list
Task-number: QDS-13811 Change-Id: I63be5d7c8640df340d266b57924cb46b3b23bdc3 Reviewed-by: Sivert Krøvel <sivert.krovel@qt.io> Reviewed-by: Thomas Hartmann <thomas.hartmann@qt.io>
This commit is contained in:
@@ -530,6 +530,7 @@ QJsonObject qmlProjectTojson(const Utils::FilePath &projectFile)
|
|||||||
QStringList qmlProjectDependencies;
|
QStringList qmlProjectDependencies;
|
||||||
qmlProjectDependencies.append(qmlprojectsFromImportPaths(importPaths, projectRootPath));
|
qmlProjectDependencies.append(qmlprojectsFromImportPaths(importPaths, projectRootPath));
|
||||||
qmlProjectDependencies.append(qmlprojectsFromFilesNodes(fileGroupsObject, projectRootPath));
|
qmlProjectDependencies.append(qmlprojectsFromFilesNodes(fileGroupsObject, projectRootPath));
|
||||||
|
qmlProjectDependencies.removeDuplicates();
|
||||||
qmlProjectDependencies.sort();
|
qmlProjectDependencies.sort();
|
||||||
rootObject.insert("qmlprojectDependencies", QJsonArray::fromStringList(qmlProjectDependencies));
|
rootObject.insert("qmlprojectDependencies", QJsonArray::fromStringList(qmlProjectDependencies));
|
||||||
|
|
||||||
|
@@ -238,6 +238,28 @@ QStringList QmlProjectItem::qmlProjectModules() const
|
|||||||
return m_project["qmlprojectDependencies"].toVariant().toStringList();
|
return m_project["qmlprojectDependencies"].toVariant().toStringList();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void QmlProjectItem::setQmlProjectModules(const QStringList &paths)
|
||||||
|
{
|
||||||
|
if (qmlProjectModules() == paths)
|
||||||
|
return;
|
||||||
|
|
||||||
|
auto jsonArray = QJsonArray::fromStringList(paths);
|
||||||
|
updateFileGroup("Module", "files", jsonArray);
|
||||||
|
insertAndUpdateProjectFile("qmlprojectDependencies", jsonArray);
|
||||||
|
}
|
||||||
|
|
||||||
|
void QmlProjectItem::addQmlProjectModule(const QString &modulePath)
|
||||||
|
{
|
||||||
|
QJsonArray qmlModules = m_project["qmlprojectDependencies"].toArray();
|
||||||
|
|
||||||
|
if (qmlModules.contains(modulePath))
|
||||||
|
return;
|
||||||
|
|
||||||
|
qmlModules.append(modulePath);
|
||||||
|
updateFileGroup("Module", "files", qmlModules);
|
||||||
|
insertAndUpdateProjectFile("qmlprojectDependencies", qmlModules);
|
||||||
|
}
|
||||||
|
|
||||||
QStringList QmlProjectItem::fileSelectors() const
|
QStringList QmlProjectItem::fileSelectors() const
|
||||||
{
|
{
|
||||||
return m_project["runConfig"].toObject()["fileSelectors"].toVariant().toStringList();
|
return m_project["runConfig"].toObject()["fileSelectors"].toVariant().toStringList();
|
||||||
@@ -444,10 +466,35 @@ void QmlProjectItem::addShaderToolFile(const QString &file)
|
|||||||
void QmlProjectItem::insertAndUpdateProjectFile(const QString &key, const QJsonValue &value)
|
void QmlProjectItem::insertAndUpdateProjectFile(const QString &key, const QJsonValue &value)
|
||||||
{
|
{
|
||||||
m_project[key] = value;
|
m_project[key] = value;
|
||||||
|
|
||||||
if (!m_skipRewrite)
|
if (!m_skipRewrite)
|
||||||
m_projectFile.writeFileContents(Converters::jsonToQmlProject(m_project).toUtf8());
|
m_projectFile.writeFileContents(Converters::jsonToQmlProject(m_project).toUtf8());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void QmlProjectItem::updateFileGroup(const QString &groupType,
|
||||||
|
const QString &property,
|
||||||
|
const QJsonValue &value)
|
||||||
|
{
|
||||||
|
auto arr = m_project["fileGroups"].toArray();
|
||||||
|
auto found = std::find_if(arr.begin(), arr.end(), [groupType](const QJsonValue &elem) {
|
||||||
|
return elem["type"].toString() == groupType;
|
||||||
|
});
|
||||||
|
if (found == arr.end()) {
|
||||||
|
qWarning() << "fileGroups - unable to find group:" << groupType;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
auto obj = found->toObject();
|
||||||
|
obj[property] = value;
|
||||||
|
|
||||||
|
arr.removeAt(std::distance(arr.begin(), found));
|
||||||
|
arr.append(obj);
|
||||||
|
m_project["fileGroups"] = arr;
|
||||||
|
|
||||||
|
m_content.clear();
|
||||||
|
setupFileFilters();
|
||||||
|
}
|
||||||
|
|
||||||
bool QmlProjectItem::enableCMakeGeneration() const
|
bool QmlProjectItem::enableCMakeGeneration() const
|
||||||
{
|
{
|
||||||
return m_project["deployment"].toObject()["enableCMakeGeneration"].toBool();
|
return m_project["deployment"].toObject()["enableCMakeGeneration"].toBool();
|
||||||
|
@@ -50,6 +50,8 @@ public:
|
|||||||
void setMockImports(const QStringList &paths);
|
void setMockImports(const QStringList &paths);
|
||||||
|
|
||||||
QStringList qmlProjectModules() const;
|
QStringList qmlProjectModules() const;
|
||||||
|
void setQmlProjectModules(const QStringList &paths);
|
||||||
|
void addQmlProjectModule(const QString &modulePath);
|
||||||
|
|
||||||
QStringList fileSelectors() const;
|
QStringList fileSelectors() const;
|
||||||
void setFileSelectors(const QStringList &selectors);
|
void setFileSelectors(const QStringList &selectors);
|
||||||
@@ -121,6 +123,7 @@ private:
|
|||||||
|
|
||||||
// file update functions
|
// file update functions
|
||||||
void insertAndUpdateProjectFile(const QString &key, const QJsonValue &value);
|
void insertAndUpdateProjectFile(const QString &key, const QJsonValue &value);
|
||||||
|
void updateFileGroup(const QString &groupType, const QString &property, const QJsonValue &value);
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace QmlProjectManager
|
} // namespace QmlProjectManager
|
||||||
|
@@ -446,6 +446,11 @@ QmlBuildSystem *QmlBuildSystem::getStartupBuildSystem()
|
|||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void QmlBuildSystem::addQmlProjectModule(const Utils::FilePath &path)
|
||||||
|
{
|
||||||
|
m_projectItem->addQmlProjectModule(path.toFSPathString());
|
||||||
|
}
|
||||||
|
|
||||||
Utils::FilePath QmlBuildSystem::mainFilePath() const
|
Utils::FilePath QmlBuildSystem::mainFilePath() const
|
||||||
{
|
{
|
||||||
const QString fileName = mainFile();
|
const QString fileName = mainFile();
|
||||||
@@ -727,6 +732,11 @@ QStringList QmlBuildSystem::importPaths() const
|
|||||||
return m_projectItem->importPaths();
|
return m_projectItem->importPaths();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void QmlBuildSystem::addImportPath(const Utils::FilePath &path)
|
||||||
|
{
|
||||||
|
m_projectItem->addImportPath(path.toFSPathString());
|
||||||
|
}
|
||||||
|
|
||||||
QStringList QmlBuildSystem::mockImports() const
|
QStringList QmlBuildSystem::mockImports() const
|
||||||
{
|
{
|
||||||
return m_projectItem->mockImports();
|
return m_projectItem->mockImports();
|
||||||
|
@@ -74,12 +74,14 @@ public:
|
|||||||
Utils::EnvironmentItems environment() const;
|
Utils::EnvironmentItems environment() const;
|
||||||
|
|
||||||
QStringList allImports() const;
|
QStringList allImports() const;
|
||||||
QStringList importPaths() const;
|
|
||||||
QStringList mockImports() const;
|
QStringList mockImports() const;
|
||||||
QStringList absoluteImportPaths() const;
|
QStringList absoluteImportPaths() const;
|
||||||
QStringList targetImportPaths() const;
|
QStringList targetImportPaths() const;
|
||||||
QStringList fileSelectors() const;
|
QStringList fileSelectors() const;
|
||||||
|
|
||||||
|
QStringList importPaths() const;
|
||||||
|
void addImportPath(const Utils::FilePath &path);
|
||||||
|
|
||||||
bool multilanguageSupport() const;
|
bool multilanguageSupport() const;
|
||||||
QStringList supportedLanguages() const;
|
QStringList supportedLanguages() const;
|
||||||
void setSupportedLanguages(QStringList languages);
|
void setSupportedLanguages(QStringList languages);
|
||||||
@@ -115,6 +117,8 @@ public:
|
|||||||
|
|
||||||
static QmlBuildSystem *getStartupBuildSystem();
|
static QmlBuildSystem *getStartupBuildSystem();
|
||||||
|
|
||||||
|
void addQmlProjectModule(const Utils::FilePath &path);
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void projectChanged();
|
void projectChanged();
|
||||||
|
|
||||||
|
@@ -762,6 +762,38 @@ TEST_F(QmlProjectItem, qmlproject_modules)
|
|||||||
"../converter/test-set-mcu-2/testfile.qmlproject"));
|
"../converter/test-set-mcu-2/testfile.qmlproject"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TEST_F(QmlProjectItem, set_empty_qmlproject_modules)
|
||||||
|
{
|
||||||
|
projectItemSetters->setQmlProjectModules({});
|
||||||
|
|
||||||
|
auto qmlProjectModules = projectItemSetters->qmlProjectModules();
|
||||||
|
|
||||||
|
ASSERT_THAT(qmlProjectModules, IsEmpty());
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_F(QmlProjectItem, set_qmlproject_modules)
|
||||||
|
{
|
||||||
|
projectItemSetters->setQmlProjectModules({"testModule.qmlproject", "testModule2.qmlproject"});
|
||||||
|
|
||||||
|
auto qmlProjectModules = projectItemSetters->qmlProjectModules();
|
||||||
|
|
||||||
|
ASSERT_THAT(qmlProjectModules,
|
||||||
|
UnorderedElementsAre("testModule.qmlproject", "testModule2.qmlproject"));
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_F(QmlProjectItem, add_qmlproject_module)
|
||||||
|
{
|
||||||
|
auto currentModules = projectItemSetters->qmlProjectModules();
|
||||||
|
projectItemSetters->addQmlProjectModule("test.qmlproject");
|
||||||
|
projectItemSetters->addQmlProjectModule("test2.qmlproject");
|
||||||
|
|
||||||
|
auto qmlProjectModules = projectItemSetters->qmlProjectModules();
|
||||||
|
|
||||||
|
ASSERT_THAT(qmlProjectModules,
|
||||||
|
UnorderedElementsAreArray(currentModules
|
||||||
|
+ QStringList{"test.qmlproject", "test2.qmlproject"}));
|
||||||
|
}
|
||||||
|
|
||||||
TEST_F(QmlProjectItem, no_qmlproject_modules)
|
TEST_F(QmlProjectItem, no_qmlproject_modules)
|
||||||
{
|
{
|
||||||
auto qmlProjectModules = projectItemEmpty->qmlProjectModules();
|
auto qmlProjectModules = projectItemEmpty->qmlProjectModules();
|
||||||
|
Reference in New Issue
Block a user