forked from qt-creator/qt-creator
AssetExport: Add unique identfier to all exported nodes
Task-number: QDS-1556 Change-Id: If70b8dc2e4f02a88ba0835e2fc3a547f1e992ea5 Reviewed-by: Thomas Hartmann <thomas.hartmann@qt.io>
This commit is contained in:
@@ -25,7 +25,6 @@
|
|||||||
#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 "rewriterview.h"
|
||||||
#include "qmlitemnode.h"
|
#include "qmlitemnode.h"
|
||||||
@@ -141,12 +140,9 @@ bool AssetExporter::isBusy() const
|
|||||||
m_currentState == AssetExporter::ParsingState::WritingJson;
|
m_currentState == AssetExporter::ParsingState::WritingJson;
|
||||||
}
|
}
|
||||||
|
|
||||||
Utils::FilePath AssetExporter::exportAsset(const QmlObjectNode &node)
|
Utils::FilePath AssetExporter::exportAsset(const QmlObjectNode &node, const QString &uuid)
|
||||||
{
|
{
|
||||||
// TODO: Use this hash as UUID and add to the node.
|
Utils::FilePath assetPath = m_exportPath.pathAppended(QString("assets/%1.png").arg(uuid));
|
||||||
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);
|
m_assetDumper->dumpAsset(node.toQmlItemNode().instanceRenderPixmap(), assetPath);
|
||||||
return assetPath;
|
return assetPath;
|
||||||
}
|
}
|
||||||
@@ -194,19 +190,13 @@ void AssetExporter::onQmlFileLoaded()
|
|||||||
triggerLoadNextFile();
|
triggerLoadNextFile();
|
||||||
}
|
}
|
||||||
|
|
||||||
QByteArray AssetExporter::addNodeUUID(ModelNode node)
|
QByteArray AssetExporter::generateUuid(const ModelNode &node)
|
||||||
{
|
{
|
||||||
QByteArray uuid = node.auxiliaryData(Constants::UuidTag).toByteArray();
|
QByteArray uuid;
|
||||||
qDebug() << node.id() << "UUID" << uuid;
|
|
||||||
if (uuid.isEmpty()) {
|
|
||||||
// Assign a new hash.
|
|
||||||
do {
|
do {
|
||||||
uuid = generateHash(node.id());
|
uuid = generateHash(node.id());
|
||||||
} while (m_usedHashes.contains(uuid));
|
} while (m_usedHashes.contains(uuid));
|
||||||
m_usedHashes.insert(uuid);
|
m_usedHashes.insert(uuid);
|
||||||
node.setAuxiliaryData(Constants::UuidAuxTag, QString::fromLatin1(uuid));
|
|
||||||
node.model()->rewriterView()->writeAuxiliaryData();
|
|
||||||
}
|
|
||||||
return uuid;
|
return uuid;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -70,7 +70,8 @@ public:
|
|||||||
void cancel();
|
void cancel();
|
||||||
bool isBusy() const;
|
bool isBusy() const;
|
||||||
|
|
||||||
Utils::FilePath exportAsset(const QmlObjectNode& node);
|
Utils::FilePath exportAsset(const QmlObjectNode& node, const QString &uuid);
|
||||||
|
QByteArray generateUuid(const ModelNode &node);
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void stateChanged(ParsingState);
|
void stateChanged(ParsingState);
|
||||||
@@ -87,8 +88,6 @@ private:
|
|||||||
|
|
||||||
void onQmlFileLoaded();
|
void onQmlFileLoaded();
|
||||||
|
|
||||||
QByteArray addNodeUUID(ModelNode node);
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
mutable class State {
|
mutable class State {
|
||||||
public:
|
public:
|
||||||
|
@@ -23,6 +23,8 @@
|
|||||||
**
|
**
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
#include "componentexporter.h"
|
#include "componentexporter.h"
|
||||||
|
#include "assetexporter.h"
|
||||||
|
#include "assetexportpluginconstants.h"
|
||||||
#include "parsers/modelnodeparser.h"
|
#include "parsers/modelnodeparser.h"
|
||||||
|
|
||||||
#include "model.h"
|
#include "model.h"
|
||||||
@@ -102,8 +104,15 @@ QJsonObject Component::nodeToJson(const ModelNode &node)
|
|||||||
{
|
{
|
||||||
QJsonObject jsonObject;
|
QJsonObject jsonObject;
|
||||||
std::unique_ptr<ModelNodeParser> parser(createNodeParser(node));
|
std::unique_ptr<ModelNodeParser> parser(createNodeParser(node));
|
||||||
if (parser)
|
if (parser) {
|
||||||
|
if (parser->uuid().isEmpty()) {
|
||||||
|
// Assign an unique identifier to the node.
|
||||||
|
QByteArray uuid = m_exporter.generateUuid(node);
|
||||||
|
node.setAuxiliaryData(Constants::UuidAuxTag, QString::fromLatin1(uuid));
|
||||||
|
node.model()->rewriterView()->writeAuxiliaryData();
|
||||||
|
}
|
||||||
jsonObject = parser->json(*this);
|
jsonObject = parser->json(*this);
|
||||||
|
}
|
||||||
|
|
||||||
QJsonArray children;
|
QJsonArray children;
|
||||||
for (const ModelNode &childnode : node.directSubModelNodes())
|
for (const ModelNode &childnode : node.directSubModelNodes())
|
||||||
|
@@ -55,8 +55,7 @@ QJsonObject AssetNodeParser::json(Component &component) const
|
|||||||
QJsonObject jsonObject = ItemNodeParser::json(component);
|
QJsonObject jsonObject = ItemNodeParser::json(component);
|
||||||
|
|
||||||
QPixmap asset = objectNode().toQmlItemNode().instanceRenderPixmap();
|
QPixmap asset = objectNode().toQmlItemNode().instanceRenderPixmap();
|
||||||
Utils::FilePath assetPath = component.exporter().exportAsset(objectNode());
|
Utils::FilePath assetPath = component.exporter().exportAsset(objectNode(), uuid());
|
||||||
|
|
||||||
QJsonObject assetData;
|
QJsonObject assetData;
|
||||||
assetData.insert(AssetPathTag, assetPath.toString());
|
assetData.insert(AssetPathTag, assetPath.toString());
|
||||||
jsonObject.insert(AssetDataTag, assetData);
|
jsonObject.insert(AssetDataTag, assetData);
|
||||||
|
@@ -60,6 +60,7 @@ QJsonObject QmlDesigner::ItemNodeParser::json(QmlDesigner::Component &component)
|
|||||||
jsonObject.insert(WidthTag, size.width());
|
jsonObject.insert(WidthTag, size.width());
|
||||||
jsonObject.insert(HeightTag, size.height());
|
jsonObject.insert(HeightTag, size.height());
|
||||||
|
|
||||||
|
jsonObject.insert(UuidTag, uuid());
|
||||||
return jsonObject;
|
return jsonObject;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -23,6 +23,7 @@
|
|||||||
**
|
**
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
#include "modelnodeparser.h"
|
#include "modelnodeparser.h"
|
||||||
|
#include "assetexportpluginconstants.h"
|
||||||
|
|
||||||
namespace QmlDesigner {
|
namespace QmlDesigner {
|
||||||
ModelNodeParser::ModelNodeParser(const QByteArrayList &lineage, const ModelNode &node) :
|
ModelNodeParser::ModelNodeParser(const QByteArrayList &lineage, const ModelNode &node) :
|
||||||
@@ -38,4 +39,9 @@ QVariant ModelNodeParser::propertyValue(const PropertyName &name) const
|
|||||||
return m_objectNode.instanceValue(name);
|
return m_objectNode.instanceValue(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QString ModelNodeParser::uuid() const
|
||||||
|
{
|
||||||
|
return m_node.auxiliaryData(Constants::UuidAuxTag).toString();
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@@ -47,6 +47,7 @@ public:
|
|||||||
const QByteArrayList& lineage() const { return m_lineage; }
|
const QByteArrayList& lineage() const { return m_lineage; }
|
||||||
const QmlObjectNode& objectNode() const { return m_objectNode; }
|
const QmlObjectNode& objectNode() const { return m_objectNode; }
|
||||||
QVariant propertyValue(const PropertyName &name) const;
|
QVariant propertyValue(const PropertyName &name) const;
|
||||||
|
QString uuid() const;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
const ModelNode &m_node;
|
const ModelNode &m_node;
|
||||||
|
Reference in New Issue
Block a user