forked from qt-creator/qt-creator
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>
This commit is contained in:
@@ -25,7 +25,9 @@
|
|||||||
#include "assetexporter.h"
|
#include "assetexporter.h"
|
||||||
#include "componentexporter.h"
|
#include "componentexporter.h"
|
||||||
#include "exportnotification.h"
|
#include "exportnotification.h"
|
||||||
|
#include "assetexportpluginconstants.h"
|
||||||
|
|
||||||
|
#include "rewriterview.h"
|
||||||
#include "qmlitemnode.h"
|
#include "qmlitemnode.h"
|
||||||
#include "qmlobjectnode.h"
|
#include "qmlobjectnode.h"
|
||||||
#include "utils/qtcassert.h"
|
#include "utils/qtcassert.h"
|
||||||
@@ -142,12 +144,7 @@ bool AssetExporter::isBusy() const
|
|||||||
Utils::FilePath AssetExporter::exportAsset(const QmlObjectNode &node)
|
Utils::FilePath AssetExporter::exportAsset(const QmlObjectNode &node)
|
||||||
{
|
{
|
||||||
// TODO: Use this hash as UUID and add to the node.
|
// TODO: Use this hash as UUID and add to the node.
|
||||||
QByteArray hash;
|
QByteArray hash = addNodeUUID(node.modelNode());
|
||||||
do {
|
|
||||||
hash = generateHash(node.id());
|
|
||||||
} while (m_usedHashes.contains(hash));
|
|
||||||
m_usedHashes.insert(hash);
|
|
||||||
|
|
||||||
Utils::FilePath assetPath = m_exportPath.pathAppended(QString("assets/%1.png")
|
Utils::FilePath assetPath = m_exportPath.pathAppended(QString("assets/%1.png")
|
||||||
.arg(QString::fromLatin1(hash)));
|
.arg(QString::fromLatin1(hash)));
|
||||||
m_assetDumper->dumpAsset(node.toQmlItemNode().instanceRenderPixmap(), assetPath);
|
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);
|
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());
|
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();
|
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()
|
void AssetExporter::triggerLoadNextFile()
|
||||||
{
|
{
|
||||||
QTimer::singleShot(0, this, &AssetExporter::loadNextFile);
|
QTimer::singleShot(0, this, &AssetExporter::loadNextFile);
|
||||||
|
@@ -87,6 +87,8 @@ private:
|
|||||||
|
|
||||||
void onQmlFileLoaded();
|
void onQmlFileLoaded();
|
||||||
|
|
||||||
|
QByteArray addNodeUUID(ModelNode node);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
mutable class State {
|
mutable class State {
|
||||||
public:
|
public:
|
||||||
|
@@ -62,7 +62,7 @@ bool AssetExporterView::loadQmlFile(const Utils::FilePath &path, uint timeoutSec
|
|||||||
|
|
||||||
setState(LoadState::Busy);
|
setState(LoadState::Busy);
|
||||||
m_retryCount = std::max(MinRetry, static_cast<int>((timeoutSecs * 1000) / RetryIntervalMs));
|
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::EditorManager::DoNotMakeVisible);
|
||||||
Core::ModeManager::activateMode(Core::Constants::MODE_DESIGN);
|
Core::ModeManager::activateMode(Core::Constants::MODE_DESIGN);
|
||||||
Core::ModeManager::setFocusToCurrentMode();
|
Core::ModeManager::setFocusToCurrentMode();
|
||||||
@@ -70,6 +70,15 @@ bool AssetExporterView::loadQmlFile(const Utils::FilePath &path, uint timeoutSec
|
|||||||
return true;
|
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)
|
void AssetExporterView::modelAttached(Model *model)
|
||||||
{
|
{
|
||||||
if (model->rewriterView() && model->rewriterView()->inErrorState())
|
if (model->rewriterView() && model->rewriterView()->inErrorState())
|
||||||
|
@@ -54,6 +54,7 @@ public:
|
|||||||
AssetExporterView(QObject *parent = nullptr);
|
AssetExporterView(QObject *parent = nullptr);
|
||||||
|
|
||||||
bool loadQmlFile(const Utils::FilePath &path, uint timeoutSecs = 10);
|
bool loadQmlFile(const Utils::FilePath &path, uint timeoutSecs = 10);
|
||||||
|
bool saveQmlFile(QString *error) const;
|
||||||
|
|
||||||
void modelAttached(Model *model) override;
|
void modelAttached(Model *model) override;
|
||||||
void instanceInformationsChanged(const QMultiHash<ModelNode, InformationName> &informationChangeHash) override;
|
void instanceInformationsChanged(const QMultiHash<ModelNode, InformationName> &informationChangeHash) override;
|
||||||
|
@@ -30,6 +30,7 @@ namespace Constants {
|
|||||||
const char EXPORT_QML[] = "Designer.ExportPlugin.ExportQml";
|
const char EXPORT_QML[] = "Designer.ExportPlugin.ExportQml";
|
||||||
|
|
||||||
const char TASK_CATEGORY_ASSET_EXPORT[] = "AssetExporter.Export";
|
const char TASK_CATEGORY_ASSET_EXPORT[] = "AssetExporter.Export";
|
||||||
|
const char UuidAuxTag[] = "uuid";
|
||||||
|
|
||||||
//***************************************************************************
|
//***************************************************************************
|
||||||
// Metadata tags
|
// Metadata tags
|
||||||
|
Reference in New Issue
Block a user