forked from qt-creator/qt-creator
QmlProjectManager: Support child nodes in MCU.Config
From Qt for MCUs 2.10, the MCU.Config node can have child nodes, not only properties. The qmlproject<->JSON conversion must also support this to not break MCU qmlproject files. Task-number: QDS-14595 Change-Id: I853fcf8a74f0397df4de6ce8c7861a2751f3bdf4 Reviewed-by: Knud Dollereder <knud.dollereder@qt.io>
This commit is contained in:
@@ -280,6 +280,18 @@ QString moduleUriFromQmlProject(const QString &qmlProjectFilePath)
|
|||||||
return QString();
|
return QString();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QJsonObject nodeToJsonObject(const QmlJS::SimpleReaderNode::Ptr &node)
|
||||||
|
{
|
||||||
|
QJsonObject tObj;
|
||||||
|
for (const QString &childPropName : node->propertyNames())
|
||||||
|
tObj.insert(childPropName, node->property(childPropName).value.toJsonValue());
|
||||||
|
|
||||||
|
for (const auto &childNode : node->children())
|
||||||
|
tObj.insert(childNode->name(), nodeToJsonObject(childNode));
|
||||||
|
|
||||||
|
return tObj;
|
||||||
|
};
|
||||||
|
|
||||||
// Returns a list of qmlproject files in currentSearchPath which are valid modules,
|
// Returns a list of qmlproject files in currentSearchPath which are valid modules,
|
||||||
// with URIs matching the relative path from importPathBase.
|
// with URIs matching the relative path from importPathBase.
|
||||||
QStringList getModuleQmlProjectFiles(const Utils::FilePath &importPath,
|
QStringList getModuleQmlProjectFiles(const Utils::FilePath &importPath,
|
||||||
@@ -356,14 +368,6 @@ QJsonObject qmlProjectTojson(const Utils::FilePath &projectFile)
|
|||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
auto nodeToJsonObject = [](const QmlJS::SimpleReaderNode::Ptr &node) {
|
|
||||||
QJsonObject tObj;
|
|
||||||
for (const QString &childPropName : node->propertyNames())
|
|
||||||
tObj.insert(childPropName, node->property(childPropName).value.toJsonValue());
|
|
||||||
|
|
||||||
return tObj;
|
|
||||||
};
|
|
||||||
|
|
||||||
auto toCamelCase = [](const QString &s) { return QString(s).replace(0, 1, s[0].toLower()); };
|
auto toCamelCase = [](const QString &s) { return QString(s).replace(0, 1, s[0].toLower()); };
|
||||||
|
|
||||||
QJsonObject rootObject; // root object
|
QJsonObject rootObject; // root object
|
||||||
@@ -585,6 +589,15 @@ QString jsonValueToString(const QJsonValue &val, int indentationLevel, bool inde
|
|||||||
return val.toBool() ? QString("true") : QString("false");
|
return val.toBool() ? QString("true") : QString("false");
|
||||||
} else if (val.isDouble()) {
|
} else if (val.isDouble()) {
|
||||||
return QString("%1").arg(val.toDouble());
|
return QString("%1").arg(val.toDouble());
|
||||||
|
} else if (val.isObject()) {
|
||||||
|
QString nodeContent = "{\n";
|
||||||
|
QJsonObject obj = val.toObject();
|
||||||
|
for (QString key : obj.keys()) {
|
||||||
|
QJsonValue val = obj[key];
|
||||||
|
nodeContent += key.append(": ").prepend(QString(" ").repeated((indentationLevel + 1) * 4));
|
||||||
|
nodeContent += jsonValueToString(val, indentationLevel + 1, indented) + "\n";
|
||||||
|
}
|
||||||
|
return nodeContent + QString(" ").repeated(indentationLevel * 4).append("}");
|
||||||
} else {
|
} else {
|
||||||
return val.toString().prepend("\"").append("\"");
|
return val.toString().prepend("\"").append("\"");
|
||||||
}
|
}
|
||||||
|
@@ -35,6 +35,11 @@ Project {
|
|||||||
}
|
}
|
||||||
|
|
||||||
MCU.Config {
|
MCU.Config {
|
||||||
|
ResourceStorageSections: {
|
||||||
|
majorVersion: 1
|
||||||
|
minorVersion: 1
|
||||||
|
name: "QulResources"
|
||||||
|
}
|
||||||
defaultFontFamily: "Roboto"
|
defaultFontFamily: "Roboto"
|
||||||
fontEngine: "Spark"
|
fontEngine: "Spark"
|
||||||
maxResourceCacheSize: [[128,128],[16384,1]]
|
maxResourceCacheSize: [[128,128],[16384,1]]
|
||||||
|
@@ -1,6 +1,6 @@
|
|||||||
import QmlProject 1.3
|
import QmlProject 1.3
|
||||||
|
|
||||||
// This file works with Qt for MCUs 2.6, with the testfile of set-set-mcu-2 used as the module.
|
// This file works with Qt for MCUs 2.10, with the testfile of set-set-mcu-2 used as the module.
|
||||||
// Do not make any changes to this or the expected output before communicating with the MCU team
|
// Do not make any changes to this or the expected output before communicating with the MCU team
|
||||||
|
|
||||||
// The set of properties may not be exhaustive and may not match every supported Qt for MCUs version
|
// The set of properties may not be exhaustive and may not match every supported Qt for MCUs version
|
||||||
@@ -121,6 +121,12 @@ Project {
|
|||||||
[16384, 1]
|
[16384, 1]
|
||||||
]
|
]
|
||||||
|
|
||||||
|
ResourceStorageSections {
|
||||||
|
name: "QulResources"
|
||||||
|
majorVersion: 1
|
||||||
|
minorVersion: 1
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
//END MCU-prefixed node
|
//END MCU-prefixed node
|
||||||
|
|
||||||
|
@@ -213,6 +213,11 @@
|
|||||||
},
|
},
|
||||||
"mcu": {
|
"mcu": {
|
||||||
"config": {
|
"config": {
|
||||||
|
"ResourceStorageSections": {
|
||||||
|
"majorVersion": 1,
|
||||||
|
"minorVersion": 1,
|
||||||
|
"name": "QulResources"
|
||||||
|
},
|
||||||
"defaultFontFamily": "Roboto",
|
"defaultFontFamily": "Roboto",
|
||||||
"fontEngine": "Spark",
|
"fontEngine": "Spark",
|
||||||
"maxResourceCacheSize": [
|
"maxResourceCacheSize": [
|
||||||
|
Reference in New Issue
Block a user