forked from qt-creator/qt-creator
QmlDesigner: Fix crash on bundle export
- Make sure tem dir stays around until icon is generated. - Handle the case of empty id. - Few more smaller tweaks. Change-Id: I807b1258cf2cb5c4a6714454f840d50d14bde17c Reviewed-by: Ali Kianian <ali.kianian@qt.io> Reviewed-by: Shrief Gabr <shrief.gabr@qt.io> Reviewed-by: Miikka Heikkinen <miikka.heikkinen@qt.io>
This commit is contained in:
@@ -884,8 +884,8 @@ void ContentLibraryView::addLib3DItem(const ModelNode &node)
|
|||||||
|
|
||||||
QString ContentLibraryView::getExportPath(const ModelNode &node) const
|
QString ContentLibraryView::getExportPath(const ModelNode &node) const
|
||||||
{
|
{
|
||||||
QString defaultFileName = node.hasId() ? node.id() : "component";
|
QString defaultName = node.hasId() ? node.id() : "component";
|
||||||
QString defaultExportFileName = QLatin1String("%1.%2").arg(defaultFileName, Constants::BUNDLE_SUFFIX);
|
QString defaultExportFileName = QLatin1String("%1.%2").arg(defaultName, Constants::BUNDLE_SUFFIX);
|
||||||
Utils::FilePath projectFP = DocumentManager::currentProjectDirPath();
|
Utils::FilePath projectFP = DocumentManager::currentProjectDirPath();
|
||||||
if (projectFP.isEmpty()) {
|
if (projectFP.isEmpty()) {
|
||||||
projectFP = QmlDesignerPlugin::instance()->documentManager()
|
projectFP = QmlDesignerPlugin::instance()->documentManager()
|
||||||
@@ -919,17 +919,17 @@ void ContentLibraryView::exportLib3DItem(const ModelNode &node, const QPixmap &i
|
|||||||
|
|
||||||
// targetPath is a temp path for collecting and zipping assets, actual export target is where
|
// targetPath is a temp path for collecting and zipping assets, actual export target is where
|
||||||
// the user chose to export (i.e. exportPath)
|
// the user chose to export (i.e. exportPath)
|
||||||
QTemporaryDir tempDir;
|
m_tempDir = std::make_unique<QTemporaryDir>();
|
||||||
QTC_ASSERT(tempDir.isValid(), return);
|
QTC_ASSERT(m_tempDir->isValid(), return);
|
||||||
auto targetPath = Utils::FilePath::fromString(tempDir.path());
|
auto targetPath = Utils::FilePath::fromString(m_tempDir->path());
|
||||||
|
|
||||||
m_zipWriter = std::make_unique<ZipWriter>(exportPath);
|
m_zipWriter = std::make_unique<ZipWriter>(exportPath);
|
||||||
|
|
||||||
QString name = node.variantProperty("objectName").value().toString();
|
QString name = node.variantProperty("objectName").value().toString();
|
||||||
if (name.isEmpty())
|
if (name.isEmpty())
|
||||||
name = node.id();
|
name = node.hasId() ? node.id() : "component";
|
||||||
|
|
||||||
auto [qml, icon] = m_widget->userModel()->getUniqueLibItemNames(node.id());
|
auto [qml, icon] = m_widget->userModel()->getUniqueLibItemNames(name);
|
||||||
|
|
||||||
// generate and save Qml file
|
// generate and save Qml file
|
||||||
auto [qmlString, depAssets] = modelNodeToQmlString(node);
|
auto [qmlString, depAssets] = modelNodeToQmlString(node);
|
||||||
@@ -976,6 +976,7 @@ void ContentLibraryView::exportLib3DItem(const ModelNode &node, const QPixmap &i
|
|||||||
|
|
||||||
m_zipWriter->addFile("icons/" + m_iconSavePath.fileName(), iconByteArray);
|
m_zipWriter->addFile("icons/" + m_iconSavePath.fileName(), iconByteArray);
|
||||||
m_zipWriter->close();
|
m_zipWriter->close();
|
||||||
|
m_tempDir.reset();
|
||||||
};
|
};
|
||||||
|
|
||||||
m_iconSavePath = targetPath.pathAppended(iconPath);
|
m_iconSavePath = targetPath.pathAppended(iconPath);
|
||||||
|
@@ -13,9 +13,11 @@
|
|||||||
#include <QObject>
|
#include <QObject>
|
||||||
#include <QPointer>
|
#include <QPointer>
|
||||||
|
|
||||||
|
class ZipWriter;
|
||||||
|
|
||||||
QT_FORWARD_DECLARE_CLASS(QImage)
|
QT_FORWARD_DECLARE_CLASS(QImage)
|
||||||
QT_FORWARD_DECLARE_CLASS(QPixmap)
|
QT_FORWARD_DECLARE_CLASS(QPixmap)
|
||||||
QT_FORWARD_DECLARE_CLASS(ZipWriter)
|
QT_FORWARD_DECLARE_CLASS(QTemporaryDir)
|
||||||
|
|
||||||
namespace QmlDesigner {
|
namespace QmlDesigner {
|
||||||
|
|
||||||
@@ -99,6 +101,7 @@ private:
|
|||||||
CreateTexture m_createTexture;
|
CreateTexture m_createTexture;
|
||||||
Utils::FilePath m_iconSavePath;
|
Utils::FilePath m_iconSavePath;
|
||||||
std::unique_ptr<ZipWriter> m_zipWriter;
|
std::unique_ptr<ZipWriter> m_zipWriter;
|
||||||
|
std::unique_ptr<QTemporaryDir> m_tempDir;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace QmlDesigner
|
} // namespace QmlDesigner
|
||||||
|
Reference in New Issue
Block a user