forked from qt-creator/qt-creator
Support for QML module mapping
QUL uses module mapping for theming of QtQuick.Controls: during code-generation the compiler is pointed to the Controls implementation it should use. This is done by rewriting any import of QtQuick.Controls with the given module name. The CMake build scripts will write a file for each target to the directory "qml_module_mappings" in the build dir, and those files will contain the mappings used. Fixes: QTCREATORBUG-25356 Change-Id: I3f74897836dde7717b03bd6dffa46dcc0689ffdd Reviewed-by: Fawzi Mohamed <fawzi.mohamed@qt.io>
This commit is contained in:
committed by
Erik Verbruggen
parent
98dc428c69
commit
5ad724a3ac
@@ -685,7 +685,22 @@ void CMakeBuildSystem::updateProjectData()
|
||||
const bool mergedHeaderPathsAndQmlImportPaths = kit()->value(
|
||||
QtSupport::KitHasMergedHeaderPathsWithQmlImportPaths::id(), false).toBool();
|
||||
QStringList extraHeaderPaths;
|
||||
QList<QByteArray> moduleMappings;
|
||||
for (const RawProjectPart &rpp : qAsConst(rpps)) {
|
||||
FilePath moduleMapFile = cmakeBuildConfiguration()->buildDirectory()
|
||||
.pathAppended("/qml_module_mappings/" + rpp.buildSystemTarget);
|
||||
if (moduleMapFile.exists()) {
|
||||
QFile mmf(moduleMapFile.toString());
|
||||
if (mmf.open(QFile::ReadOnly)) {
|
||||
QByteArray content = mmf.readAll();
|
||||
auto lines = content.split('\n');
|
||||
for (const auto &line : lines) {
|
||||
if (!line.isEmpty())
|
||||
moduleMappings.append(line.simplified());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (mergedHeaderPathsAndQmlImportPaths) {
|
||||
for (const auto &headerPath : rpp.headerPaths) {
|
||||
if (headerPath.type == HeaderPathType::User)
|
||||
@@ -693,7 +708,7 @@ void CMakeBuildSystem::updateProjectData()
|
||||
}
|
||||
}
|
||||
}
|
||||
updateQmlJSCodeModel(extraHeaderPaths);
|
||||
updateQmlJSCodeModel(extraHeaderPaths, moduleMappings);
|
||||
}
|
||||
emit cmakeBuildConfiguration()->buildTypeChanged();
|
||||
|
||||
@@ -1187,8 +1202,10 @@ QList<ProjectExplorer::ExtraCompiler *> CMakeBuildSystem::findExtraCompilers()
|
||||
return extraCompilers;
|
||||
}
|
||||
|
||||
void CMakeBuildSystem::updateQmlJSCodeModel(const QStringList &extraHeaderPaths)
|
||||
void CMakeBuildSystem::updateQmlJSCodeModel(const QStringList &extraHeaderPaths,
|
||||
const QList<QByteArray> &moduleMappings)
|
||||
{
|
||||
qDebug()<<"cmake: module mappings:"<<moduleMappings;
|
||||
QmlJS::ModelManagerInterface *modelManager = QmlJS::ModelManagerInterface::instance();
|
||||
|
||||
if (!modelManager)
|
||||
@@ -1214,6 +1231,24 @@ void CMakeBuildSystem::updateQmlJSCodeModel(const QStringList &extraHeaderPaths)
|
||||
projectInfo.importPaths.maybeInsert(FilePath::fromString(extraHeaderPath),
|
||||
QmlJS::Dialect::Qml);
|
||||
|
||||
for (const QByteArray &mm : moduleMappings) {
|
||||
auto kvPair = mm.split('=');
|
||||
if (kvPair.size() != 2)
|
||||
continue;
|
||||
QString from = QString::fromUtf8(kvPair.at(0).trimmed());
|
||||
QString to = QString::fromUtf8(kvPair.at(1).trimmed());
|
||||
if (!from.isEmpty() && !to.isEmpty() && from != to) {
|
||||
// The QML code-model does not support sub-projects, so if there are multiple mappings for a single module,
|
||||
// choose the shortest one.
|
||||
if (projectInfo.moduleMappings.contains(from)) {
|
||||
if (to.size() < projectInfo.moduleMappings.value(from).size())
|
||||
projectInfo.moduleMappings.insert(from, to);
|
||||
} else {
|
||||
projectInfo.moduleMappings.insert(from, to);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
project()->setProjectLanguage(ProjectExplorer::Constants::QMLJS_LANGUAGE_ID,
|
||||
!projectInfo.sourceFiles.isEmpty());
|
||||
modelManager->updateProjectInfo(projectInfo, p);
|
||||
|
||||
@@ -140,7 +140,8 @@ private:
|
||||
void updateProjectData();
|
||||
void updateFallbackProjectData();
|
||||
QList<ProjectExplorer::ExtraCompiler *> findExtraCompilers();
|
||||
void updateQmlJSCodeModel(const QStringList &extraHeaderPaths);
|
||||
void updateQmlJSCodeModel(const QStringList &extraHeaderPaths,
|
||||
const QList<QByteArray> &moduleMappings);
|
||||
|
||||
void handleParsingSucceeded();
|
||||
void handleParsingFailed(const QString &msg);
|
||||
|
||||
Reference in New Issue
Block a user