AssetExport: Notify QML parsing errors

QML can not be exported if the document have parsing errors

Task-number: QDS-2667
Change-Id: I22075789cfa5853b1607c45e2b49bb761836c0d6
Reviewed-by: Leena Miettinen <riitta-leena.miettinen@qt.io>
This commit is contained in:
Vikas Pachdha
2020-08-31 11:08:41 +02:00
parent f43b81ae6f
commit 4473769bc4

View File

@@ -26,6 +26,8 @@
#include "componentexporter.h" #include "componentexporter.h"
#include "exportnotification.h" #include "exportnotification.h"
#include "designdocument.h"
#include "qmldesignerplugin.h"
#include "rewriterview.h" #include "rewriterview.h"
#include "qmlitemnode.h" #include "qmlitemnode.h"
#include "qmlobjectnode.h" #include "qmlobjectnode.h"
@@ -163,7 +165,6 @@ void AssetExporter::exportComponent(const ModelNode &rootNode)
Component exporter(*this, rootNode); Component exporter(*this, rootNode);
exporter.exportComponent(); exporter.exportComponent();
m_components.append(exporter.json()); m_components.append(exporter.json());
notifyProgress((m_totalFileCount - m_exportFiles.count()) * 0.8 / m_totalFileCount);
} }
void AssetExporter::notifyLoadError(AssetExporterView::LoadState state) void AssetExporter::notifyLoadError(AssetExporterView::LoadState state)
@@ -192,12 +193,22 @@ void AssetExporter::onQmlFileLoaded()
{ {
QTC_ASSERT(m_view && m_view->model(), qCDebug(loggerError) << "Null model"; return); QTC_ASSERT(m_view && m_view->model(), qCDebug(loggerError) << "Null model"; return);
qCDebug(loggerInfo) << "Qml file load done" << m_view->model()->fileUrl(); qCDebug(loggerInfo) << "Qml file load done" << m_view->model()->fileUrl();
exportComponent(m_view->rootModelNode());
QString error; QmlDesigner::DesignDocument *designDocument = QmlDesigner::QmlDesignerPlugin::instance()
if (!m_view->saveQmlFile(&error)) { ->documentManager()
ExportNotification::addError(tr("Error saving QML file. %1") .currentDesignDocument();
.arg(error.isEmpty()? tr("Unknown") : error)); if (designDocument->hasQmlParseErrors()) {
ExportNotification::addError(tr("Cannot export QML. Document \"%1\" have parsing errors.")
.arg(designDocument->displayName()));
} else {
exportComponent(m_view->rootModelNode());
QString error;
if (!m_view->saveQmlFile(&error)) {
ExportNotification::addError(tr("Error saving QML file. %1")
.arg(error.isEmpty()? tr("Unknown") : error));
}
} }
notifyProgress((m_totalFileCount - m_exportFiles.count()) * 0.8 / m_totalFileCount);
triggerLoadNextFile(); triggerLoadNextFile();
} }