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()) {
|
if (!data.previewData.name.isEmpty()) {
|
||||||
QVariantHash msgData;
|
QVariantHash msgData;
|
||||||
msgData.insert("name", data.previewData.name);
|
msgData.insert("name", data.previewData.name);
|
||||||
|
msgData.insert("qmlName", data.previewData.qmlName);
|
||||||
msgData.insert("folder", data.previewData.folderName);
|
msgData.insert("folder", data.previewData.folderName);
|
||||||
m_nodeInstanceView->view3DAction(View3DActionType::Import3dAddPreviewModel, msgData);
|
m_nodeInstanceView->view3DAction(View3DActionType::Import3dAddPreviewModel, msgData);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -290,11 +290,13 @@ bool ItemLibraryAssetImporter::preParseQuick3DAsset(const QString &file, ParseDa
|
|||||||
currentChar = QLatin1Char('_');
|
currentChar = QLatin1Char('_');
|
||||||
}
|
}
|
||||||
const QChar firstChar = pd.assetName[0];
|
const QChar firstChar = pd.assetName[0];
|
||||||
if (firstChar.isDigit())
|
if (firstChar.isDigit()) {
|
||||||
pd.assetName[0] = QLatin1Char('_');
|
// Match quick3d importer logic on starting digit
|
||||||
if (firstChar.isLower())
|
pd.assetName.prepend("Node");
|
||||||
|
} else if (firstChar.isLower()) {
|
||||||
pd.assetName[0] = firstChar.toUpper();
|
pd.assetName[0] = firstChar.toUpper();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
pd.targetDirPath = pd.targetDir.filePath(pd.assetName);
|
pd.targetDirPath = pd.targetDir.filePath(pd.assetName);
|
||||||
|
|
||||||
@@ -401,6 +403,8 @@ void ItemLibraryAssetImporter::postParseQuick3DAsset(ParseData &pd)
|
|||||||
while (qmlIt.hasNext()) {
|
while (qmlIt.hasNext()) {
|
||||||
qmlIt.next();
|
qmlIt.next();
|
||||||
QFileInfo fi = QFileInfo(qmlIt.filePath());
|
QFileInfo fi = QFileInfo(qmlIt.filePath());
|
||||||
|
if (pd.importedQmlName.isEmpty())
|
||||||
|
pd.importedQmlName = fi.baseName();
|
||||||
qmlInfo.append(fi.baseName());
|
qmlInfo.append(fi.baseName());
|
||||||
qmlInfo.append(' ');
|
qmlInfo.append(' ');
|
||||||
qmlInfo.append(version);
|
qmlInfo.append(version);
|
||||||
@@ -661,6 +665,7 @@ void ItemLibraryAssetImporter::postImport()
|
|||||||
PreviewData data;
|
PreviewData data;
|
||||||
data.name = pd.assetName;
|
data.name = pd.assetName;
|
||||||
data.folderName = pd.outDir.dirName();
|
data.folderName = pd.outDir.dirName();
|
||||||
|
data.qmlName = pd.importedQmlName;
|
||||||
data.renderedOptions = pd.options;
|
data.renderedOptions = pd.options;
|
||||||
data.currentOptions = pd.options;
|
data.currentOptions = pd.options;
|
||||||
data.optionsIndex = pd.optionsIndex;
|
data.optionsIndex = pd.optionsIndex;
|
||||||
|
|||||||
@@ -56,6 +56,7 @@ public:
|
|||||||
QJsonObject currentOptions;
|
QJsonObject currentOptions;
|
||||||
QString name;
|
QString name;
|
||||||
QString folderName;
|
QString folderName;
|
||||||
|
QString qmlName;
|
||||||
QString type;
|
QString type;
|
||||||
qint64 size;
|
qint64 size;
|
||||||
};
|
};
|
||||||
@@ -81,6 +82,7 @@ private:
|
|||||||
QFileInfo sourceInfo;
|
QFileInfo sourceInfo;
|
||||||
QString assetName;
|
QString assetName;
|
||||||
QString originalAssetName;
|
QString originalAssetName;
|
||||||
|
QString importedQmlName;
|
||||||
qint64 assetSize;
|
qint64 assetSize;
|
||||||
int importId = -1;
|
int importId = -1;
|
||||||
int optionsIndex = -1;
|
int optionsIndex = -1;
|
||||||
|
|||||||
@@ -115,6 +115,7 @@ void Qt5Import3dNodeInstanceServer::view3DAction([[maybe_unused]] const View3DAc
|
|||||||
case View3DActionType::Import3dAddPreviewModel: {
|
case View3DActionType::Import3dAddPreviewModel: {
|
||||||
const QVariantHash cmd = command.value().toHash();
|
const QVariantHash cmd = command.value().toHash();
|
||||||
const QString name = cmd["name"].toString();
|
const QString name = cmd["name"].toString();
|
||||||
|
const QString qmlName = cmd["qmlName"].toString();
|
||||||
const QString folder = cmd["folder"].toString();
|
const QString folder = cmd["folder"].toString();
|
||||||
|
|
||||||
bool isUpdate = m_previewData.contains(name);
|
bool isUpdate = m_previewData.contains(name);
|
||||||
@@ -136,7 +137,7 @@ void Qt5Import3dNodeInstanceServer::view3DAction([[maybe_unused]] const View3DAc
|
|||||||
}
|
}
|
||||||
|
|
||||||
QFileInfo fi(fileUrl().toLocalFile());
|
QFileInfo fi(fileUrl().toLocalFile());
|
||||||
QString compPath = fi.absolutePath() + '/' + folder + '/' + name + ".qml";
|
QString compPath = fi.absolutePath() + '/' + folder + '/' + qmlName + ".qml";
|
||||||
QQmlComponent comp(engine(), compPath, QQmlComponent::PreferSynchronous);
|
QQmlComponent comp(engine(), compPath, QQmlComponent::PreferSynchronous);
|
||||||
data.node = qobject_cast<QQuick3DNode *>(comp.create(context()));
|
data.node = qobject_cast<QQuick3DNode *>(comp.create(context()));
|
||||||
if (data.node) {
|
if (data.node) {
|
||||||
|
|||||||
Reference in New Issue
Block a user