forked from qt-creator/qt-creator
Add QML import path supplied by the kit
Although QUL has merged the QML import paths and the include paths, the convention for C/C++ is to have the headers for a project under a subdirectory of the include path, and do imports relative to the include path. For example: #include <qul/SomeHeader.h> The QML code model doesn't know about this convention, so for the kit has to supply an extra QML import path for this case. Change-Id: I82d4375dd8a1f510180f81b011a715dee8c10d60 Reviewed-by: Alessandro Portale <alessandro.portale@qt.io>
This commit is contained in:
committed by
Erik Verbruggen
parent
95d8734e5f
commit
9d90efee8b
@@ -1188,11 +1188,15 @@ void CMakeBuildSystem::updateQmlJSCodeModel()
|
||||
|
||||
projectInfo.importPaths.clear();
|
||||
|
||||
auto addImports = [&projectInfo](const QString &imports) {
|
||||
foreach (const QString &import, CMakeConfigItem::cmakeSplitValue(imports))
|
||||
projectInfo.importPaths.maybeInsert(FilePath::fromString(import), QmlJS::Dialect::Qml);
|
||||
};
|
||||
|
||||
const CMakeConfig &cm = cmakeBuildConfiguration()->configurationFromCMake();
|
||||
const QString cmakeImports = QString::fromUtf8(CMakeConfigItem::valueOf("QML_IMPORT_PATH", cm));
|
||||
|
||||
foreach (const QString &cmakeImport, CMakeConfigItem::cmakeSplitValue(cmakeImports))
|
||||
projectInfo.importPaths.maybeInsert(FilePath::fromString(cmakeImport), QmlJS::Dialect::Qml);
|
||||
addImports(cmakeImports);
|
||||
addImports(kit()->value(QtSupport::KitQmlImportPath::id()).toString());
|
||||
|
||||
project()->setProjectLanguage(ProjectExplorer::Constants::QMLJS_LANGUAGE_ID,
|
||||
!projectInfo.sourceFiles.isEmpty());
|
||||
|
@@ -29,6 +29,7 @@
|
||||
|
||||
#include <baremetal/baremetalconstants.h>
|
||||
#include <cmakeprojectmanager/cmaketoolmanager.h>
|
||||
#include <cmakeprojectmanager/cmakekitinformation.h>
|
||||
#include <coreplugin/icore.h>
|
||||
#include <coreplugin/helpmanager.h>
|
||||
#include <coreplugin/messagemanager.h>
|
||||
@@ -660,7 +661,8 @@ FilePath McuSupportOptions::qulDirFromSettings()
|
||||
QSettings::UserScope));
|
||||
}
|
||||
|
||||
static void setKitProperties(const QString &kitName, Kit *k, const McuTarget *mcuTarget)
|
||||
static void setKitProperties(const QString &kitName, Kit *k, const McuTarget *mcuTarget,
|
||||
const QString &sdkPath)
|
||||
{
|
||||
using namespace Constants;
|
||||
|
||||
@@ -677,7 +679,12 @@ static void setKitProperties(const QString &kitName, Kit *k, const McuTarget *mc
|
||||
if (mcuTarget->toolChainPackage()->isDesktopToolchain())
|
||||
k->setDeviceTypeForIcon(DEVICE_TYPE);
|
||||
k->setValue(QtSupport::SuppliesQtQuickImportPath::id(), true);
|
||||
QSet<Id> irrelevant = { SysRootKitAspect::id(), QtSupport::SuppliesQtQuickImportPath::id() };
|
||||
k->setValue(QtSupport::KitQmlImportPath::id(), QVariant(sdkPath + "/include/qul"));
|
||||
QSet<Id> irrelevant = {
|
||||
SysRootKitAspect::id(),
|
||||
QtSupport::SuppliesQtQuickImportPath::id(),
|
||||
QtSupport::KitQmlImportPath::id()
|
||||
};
|
||||
if (!kitNeedsQtVersion())
|
||||
irrelevant.insert(QtSupport::QtKitAspect::id());
|
||||
k->setIrrelevantAspects(irrelevant);
|
||||
@@ -874,7 +881,7 @@ Kit *McuSupportOptions::newKit(const McuTarget *mcuTarget, const McuPackage *qtF
|
||||
const auto init = [mcuTarget, qtForMCUsSdk](Kit *k) {
|
||||
KitGuard kitGuard(k);
|
||||
|
||||
setKitProperties(kitName(mcuTarget), k, mcuTarget);
|
||||
setKitProperties(kitName(mcuTarget), k, mcuTarget, qtForMCUsSdk->path());
|
||||
setKitDevice(k, mcuTarget);
|
||||
setKitToolchains(k, mcuTarget->toolChainPackage());
|
||||
setKitDebugger(k, mcuTarget->toolChainPackage());
|
||||
@@ -980,6 +987,24 @@ void McuSupportOptions::fixExistingKits()
|
||||
if (!kit->hasValue(bringsQtQuickImportPath)) {
|
||||
kit->setValue(bringsQtQuickImportPath, true);
|
||||
}
|
||||
|
||||
// Check if the MCU kit supplies its import path.
|
||||
const auto kitQmlImportPath = QtSupport::KitQmlImportPath::id();
|
||||
if (!irrelevantAspects.contains(kitQmlImportPath)) {
|
||||
irrelevantAspects.insert(kitQmlImportPath);
|
||||
kit->setIrrelevantAspects(irrelevantAspects);
|
||||
}
|
||||
if (!kit->hasValue(kitQmlImportPath)) {
|
||||
auto config = CMakeProjectManager::CMakeConfigurationKitAspect::configuration(kit);
|
||||
for (const auto &cfgItem : qAsConst(config)) {
|
||||
if (cfgItem.key == "QUL_GENERATORS") {
|
||||
auto idx = cfgItem.value.indexOf("/lib/cmake/Qul");
|
||||
auto qulDir = cfgItem.value.left(idx);
|
||||
kit->setValue(kitQmlImportPath, QVariant(qulDir + "/include/qul"));
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -469,4 +469,9 @@ Id SuppliesQtQuickImportPath::id()
|
||||
return QtSupport::Constants::FLAGS_SUPPLIES_QTQUICK_IMPORT_PATH;
|
||||
}
|
||||
|
||||
Id KitQmlImportPath::id()
|
||||
{
|
||||
return QtSupport::Constants::KIT_QML_IMPORT_PATH;
|
||||
}
|
||||
|
||||
} // namespace QtSupport
|
||||
|
@@ -89,4 +89,10 @@ public:
|
||||
static Utils::Id id();
|
||||
};
|
||||
|
||||
class QTSUPPORT_EXPORT KitQmlImportPath
|
||||
{
|
||||
public:
|
||||
static Utils::Id id();
|
||||
};
|
||||
|
||||
} // namespace QtSupport
|
||||
|
@@ -57,6 +57,7 @@ const char FEATURE_DESKTOP[] = "QtSupport.Wizards.FeatureDesktop";
|
||||
|
||||
// Kit flags
|
||||
const char FLAGS_SUPPLIES_QTQUICK_IMPORT_PATH[] = "QtSupport.SuppliesQtQuickImportPath";
|
||||
const char KIT_QML_IMPORT_PATH[] = "QtSupport.KitQmlImportPath";
|
||||
|
||||
} // namepsace Constants
|
||||
} // namepsace QtSupport
|
||||
|
Reference in New Issue
Block a user