forked from qt-creator/qt-creator
QmlDesigner: Fix import preview generation crashes
Asset name sanitizing logic is more complex on quick3d importer than we have on designer side, which leads to asset name sometimes differing from actual generated qml file name. Since there's always a risk of sanitizing logic changing, added qml name as separate data item from asset name so that preview generation knows to always load correct qml. Fixes: QDS-13168 Change-Id: I1705619a6b30ebbe8ca44a00cfdad1a5122ca964 Reviewed-by: Mahmoud Badri <mahmoud.badri@qt.io>
This commit is contained in:
@@ -1288,6 +1288,7 @@ void ItemLibraryAssetImportDialog::onImportReadyForPreview(
|
||||
if (!data.previewData.name.isEmpty()) {
|
||||
QVariantHash msgData;
|
||||
msgData.insert("name", data.previewData.name);
|
||||
msgData.insert("qmlName", data.previewData.qmlName);
|
||||
msgData.insert("folder", data.previewData.folderName);
|
||||
m_nodeInstanceView->view3DAction(View3DActionType::Import3dAddPreviewModel, msgData);
|
||||
}
|
||||
|
||||
@@ -290,10 +290,12 @@ bool ItemLibraryAssetImporter::preParseQuick3DAsset(const QString &file, ParseDa
|
||||
currentChar = QLatin1Char('_');
|
||||
}
|
||||
const QChar firstChar = pd.assetName[0];
|
||||
if (firstChar.isDigit())
|
||||
pd.assetName[0] = QLatin1Char('_');
|
||||
if (firstChar.isLower())
|
||||
if (firstChar.isDigit()) {
|
||||
// Match quick3d importer logic on starting digit
|
||||
pd.assetName.prepend("Node");
|
||||
} else if (firstChar.isLower()) {
|
||||
pd.assetName[0] = firstChar.toUpper();
|
||||
}
|
||||
}
|
||||
|
||||
pd.targetDirPath = pd.targetDir.filePath(pd.assetName);
|
||||
@@ -401,6 +403,8 @@ void ItemLibraryAssetImporter::postParseQuick3DAsset(ParseData &pd)
|
||||
while (qmlIt.hasNext()) {
|
||||
qmlIt.next();
|
||||
QFileInfo fi = QFileInfo(qmlIt.filePath());
|
||||
if (pd.importedQmlName.isEmpty())
|
||||
pd.importedQmlName = fi.baseName();
|
||||
qmlInfo.append(fi.baseName());
|
||||
qmlInfo.append(' ');
|
||||
qmlInfo.append(version);
|
||||
@@ -661,6 +665,7 @@ void ItemLibraryAssetImporter::postImport()
|
||||
PreviewData data;
|
||||
data.name = pd.assetName;
|
||||
data.folderName = pd.outDir.dirName();
|
||||
data.qmlName = pd.importedQmlName;
|
||||
data.renderedOptions = pd.options;
|
||||
data.currentOptions = pd.options;
|
||||
data.optionsIndex = pd.optionsIndex;
|
||||
|
||||
@@ -56,6 +56,7 @@ public:
|
||||
QJsonObject currentOptions;
|
||||
QString name;
|
||||
QString folderName;
|
||||
QString qmlName;
|
||||
QString type;
|
||||
qint64 size;
|
||||
};
|
||||
@@ -81,6 +82,7 @@ private:
|
||||
QFileInfo sourceInfo;
|
||||
QString assetName;
|
||||
QString originalAssetName;
|
||||
QString importedQmlName;
|
||||
qint64 assetSize;
|
||||
int importId = -1;
|
||||
int optionsIndex = -1;
|
||||
|
||||
@@ -115,6 +115,7 @@ void Qt5Import3dNodeInstanceServer::view3DAction([[maybe_unused]] const View3DAc
|
||||
case View3DActionType::Import3dAddPreviewModel: {
|
||||
const QVariantHash cmd = command.value().toHash();
|
||||
const QString name = cmd["name"].toString();
|
||||
const QString qmlName = cmd["qmlName"].toString();
|
||||
const QString folder = cmd["folder"].toString();
|
||||
|
||||
bool isUpdate = m_previewData.contains(name);
|
||||
@@ -136,7 +137,7 @@ void Qt5Import3dNodeInstanceServer::view3DAction([[maybe_unused]] const View3DAc
|
||||
}
|
||||
|
||||
QFileInfo fi(fileUrl().toLocalFile());
|
||||
QString compPath = fi.absolutePath() + '/' + folder + '/' + name + ".qml";
|
||||
QString compPath = fi.absolutePath() + '/' + folder + '/' + qmlName + ".qml";
|
||||
QQmlComponent comp(engine(), compPath, QQmlComponent::PreferSynchronous);
|
||||
data.node = qobject_cast<QQuick3DNode *>(comp.create(context()));
|
||||
if (data.node) {
|
||||
|
||||
Reference in New Issue
Block a user