aboutsummaryrefslogtreecommitdiffstats
path: root/src/plugins/qmldesigner/assetexporterplugin
diff options
context:
space:
mode:
authorVikas Pachdha <vikas.pachdha@qt.io>2020-06-25 17:17:05 +0200
committerVikas Pachdha <vikas.pachdha@qt.io>2020-06-26 10:26:56 +0000
commit3fde0a19ecb6be05eadb54cdc30d540d32372bc5 (patch)
treed9ccf937da97f04b4c6a743e2cfeeb44625ca383 /src/plugins/qmldesigner/assetexporterplugin
parent9daf5c130da6edb0f03b9f7f61c34c368d4cca56 (diff)
AssetExport: Add generated UUID to qml
This will enable the merge when importing back from Photoshop Task-number: QDS-1555 Change-Id: I411ad65af1a33a80fcea80206aef93e2d1afa357 Reviewed-by: Thomas Hartmann <thomas.hartmann@qt.io>
Diffstat (limited to 'src/plugins/qmldesigner/assetexporterplugin')
-rw-r--r--src/plugins/qmldesigner/assetexporterplugin/assetexporter.cpp30
-rw-r--r--src/plugins/qmldesigner/assetexporterplugin/assetexporter.h2
-rw-r--r--src/plugins/qmldesigner/assetexporterplugin/assetexporterview.cpp11
-rw-r--r--src/plugins/qmldesigner/assetexporterplugin/assetexporterview.h1
-rw-r--r--src/plugins/qmldesigner/assetexporterplugin/assetexportpluginconstants.h1
5 files changed, 38 insertions, 7 deletions
diff --git a/src/plugins/qmldesigner/assetexporterplugin/assetexporter.cpp b/src/plugins/qmldesigner/assetexporterplugin/assetexporter.cpp
index 49d763f6b4..26e2d2c455 100644
--- a/src/plugins/qmldesigner/assetexporterplugin/assetexporter.cpp
+++ b/src/plugins/qmldesigner/assetexporterplugin/assetexporter.cpp
@@ -25,7 +25,9 @@
#include "assetexporter.h"
#include "componentexporter.h"
#include "exportnotification.h"
+#include "assetexportpluginconstants.h"
+#include "rewriterview.h"
#include "qmlitemnode.h"
#include "qmlobjectnode.h"
#include "utils/qtcassert.h"
@@ -142,12 +144,7 @@ bool AssetExporter::isBusy() const
Utils::FilePath AssetExporter::exportAsset(const QmlObjectNode &node)
{
// TODO: Use this hash as UUID and add to the node.
- QByteArray hash;
- do {
- hash = generateHash(node.id());
- } while (m_usedHashes.contains(hash));
- m_usedHashes.insert(hash);
-
+ QByteArray hash = addNodeUUID(node.modelNode());
Utils::FilePath assetPath = m_exportPath.pathAppended(QString("assets/%1.png")
.arg(QString::fromLatin1(hash)));
m_assetDumper->dumpAsset(node.toQmlItemNode().instanceRenderPixmap(), assetPath);
@@ -189,9 +186,30 @@ void AssetExporter::onQmlFileLoaded()
QTC_ASSERT(m_view && m_view->model(), qCDebug(loggerError) << "Null model"; return);
qCDebug(loggerInfo) << "Qml file load done" << m_view->model()->fileUrl();
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));
+ }
triggerLoadNextFile();
}
+QByteArray AssetExporter::addNodeUUID(ModelNode node)
+{
+ QByteArray uuid = node.auxiliaryData(Constants::UuidTag).toByteArray();
+ qDebug() << node.id() << "UUID" << uuid;
+ if (uuid.isEmpty()) {
+ // Assign a new hash.
+ do {
+ uuid = generateHash(node.id());
+ } while (m_usedHashes.contains(uuid));
+ m_usedHashes.insert(uuid);
+ node.setAuxiliaryData(Constants::UuidAuxTag, QString::fromLatin1(uuid));
+ node.model()->rewriterView()->writeAuxiliaryData();
+ }
+ return uuid;
+}
+
void AssetExporter::triggerLoadNextFile()
{
QTimer::singleShot(0, this, &AssetExporter::loadNextFile);
diff --git a/src/plugins/qmldesigner/assetexporterplugin/assetexporter.h b/src/plugins/qmldesigner/assetexporterplugin/assetexporter.h
index a4d6df23c0..2aa238fb32 100644
--- a/src/plugins/qmldesigner/assetexporterplugin/assetexporter.h
+++ b/src/plugins/qmldesigner/assetexporterplugin/assetexporter.h
@@ -87,6 +87,8 @@ private:
void onQmlFileLoaded();
+ QByteArray addNodeUUID(ModelNode node);
+
private:
mutable class State {
public:
diff --git a/src/plugins/qmldesigner/assetexporterplugin/assetexporterview.cpp b/src/plugins/qmldesigner/assetexporterplugin/assetexporterview.cpp
index 1e47632c8e..fbb4173249 100644
--- a/src/plugins/qmldesigner/assetexporterplugin/assetexporterview.cpp
+++ b/src/plugins/qmldesigner/assetexporterplugin/assetexporterview.cpp
@@ -62,7 +62,7 @@ bool AssetExporterView::loadQmlFile(const Utils::FilePath &path, uint timeoutSec
setState(LoadState::Busy);
m_retryCount = std::max(MinRetry, static_cast<int>((timeoutSecs * 1000) / RetryIntervalMs));
- Core::EditorManager::openEditor(path.toString(), Core::Id(),
+ m_currentEditor = Core::EditorManager::openEditor(path.toString(), Core::Id(),
Core::EditorManager::DoNotMakeVisible);
Core::ModeManager::activateMode(Core::Constants::MODE_DESIGN);
Core::ModeManager::setFocusToCurrentMode();
@@ -70,6 +70,15 @@ bool AssetExporterView::loadQmlFile(const Utils::FilePath &path, uint timeoutSec
return true;
}
+bool AssetExporterView::saveQmlFile(QString *error) const
+{
+ if (!m_currentEditor) {
+ qCDebug(loggerWarn) << "Saving QML file failed. No editor.";
+ return false;
+ }
+ return m_currentEditor->document()->save(error);
+}
+
void AssetExporterView::modelAttached(Model *model)
{
if (model->rewriterView() && model->rewriterView()->inErrorState())
diff --git a/src/plugins/qmldesigner/assetexporterplugin/assetexporterview.h b/src/plugins/qmldesigner/assetexporterplugin/assetexporterview.h
index 2fb45d7865..46c2c77071 100644
--- a/src/plugins/qmldesigner/assetexporterplugin/assetexporterview.h
+++ b/src/plugins/qmldesigner/assetexporterplugin/assetexporterview.h
@@ -54,6 +54,7 @@ public:
AssetExporterView(QObject *parent = nullptr);
bool loadQmlFile(const Utils::FilePath &path, uint timeoutSecs = 10);
+ bool saveQmlFile(QString *error) const;
void modelAttached(Model *model) override;
void instanceInformationsChanged(const QMultiHash<ModelNode, InformationName> &informationChangeHash) override;
diff --git a/src/plugins/qmldesigner/assetexporterplugin/assetexportpluginconstants.h b/src/plugins/qmldesigner/assetexporterplugin/assetexportpluginconstants.h
index 2e9ba7a56d..1937c7126e 100644
--- a/src/plugins/qmldesigner/assetexporterplugin/assetexportpluginconstants.h
+++ b/src/plugins/qmldesigner/assetexporterplugin/assetexportpluginconstants.h
@@ -30,6 +30,7 @@ namespace Constants {
const char EXPORT_QML[] = "Designer.ExportPlugin.ExportQml";
const char TASK_CATEGORY_ASSET_EXPORT[] = "AssetExporter.Export";
+const char UuidAuxTag[] = "uuid";
//***************************************************************************
// Metadata tags