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 "componentexporter.h"
|
||||
#include "exportnotification.h"
|
||||
#include "assetexportpluginconstants.h"
|
||||
|
||||
#include "rewriterview.h"
|
||||
#include "qmlitemnode.h"
|
||||
@@ -141,12 +140,9 @@ bool AssetExporter::isBusy() const
|
||||
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.
|
||||
QByteArray hash = addNodeUUID(node.modelNode());
|
||||
Utils::FilePath assetPath = m_exportPath.pathAppended(QString("assets/%1.png")
|
||||
.arg(QString::fromLatin1(hash)));
|
||||
Utils::FilePath assetPath = m_exportPath.pathAppended(QString("assets/%1.png").arg(uuid));
|
||||
m_assetDumper->dumpAsset(node.toQmlItemNode().instanceRenderPixmap(), assetPath);
|
||||
return assetPath;
|
||||
}
|
||||
@@ -194,19 +190,13 @@ void AssetExporter::onQmlFileLoaded()
|
||||
triggerLoadNextFile();
|
||||
}
|
||||
|
||||
QByteArray AssetExporter::addNodeUUID(ModelNode node)
|
||||
QByteArray AssetExporter::generateUuid(const 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();
|
||||
}
|
||||
QByteArray uuid;
|
||||
do {
|
||||
uuid = generateHash(node.id());
|
||||
} while (m_usedHashes.contains(uuid));
|
||||
m_usedHashes.insert(uuid);
|
||||
return uuid;
|
||||
}
|
||||
|
||||
|
@@ -70,7 +70,8 @@ public:
|
||||
void cancel();
|
||||
bool isBusy() const;
|
||||
|
||||
Utils::FilePath exportAsset(const QmlObjectNode& node);
|
||||
Utils::FilePath exportAsset(const QmlObjectNode& node, const QString &uuid);
|
||||
QByteArray generateUuid(const ModelNode &node);
|
||||
|
||||
signals:
|
||||
void stateChanged(ParsingState);
|
||||
@@ -87,8 +88,6 @@ private:
|
||||
|
||||
void onQmlFileLoaded();
|
||||
|
||||
QByteArray addNodeUUID(ModelNode node);
|
||||
|
||||
private:
|
||||
mutable class State {
|
||||
public:
|
||||
|
@@ -23,6 +23,8 @@
|
||||
**
|
||||
****************************************************************************/
|
||||
#include "componentexporter.h"
|
||||
#include "assetexporter.h"
|
||||
#include "assetexportpluginconstants.h"
|
||||
#include "parsers/modelnodeparser.h"
|
||||
|
||||
#include "model.h"
|
||||
@@ -102,8 +104,15 @@ QJsonObject Component::nodeToJson(const ModelNode &node)
|
||||
{
|
||||
QJsonObject jsonObject;
|
||||
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);
|
||||
}
|
||||
|
||||
QJsonArray children;
|
||||
for (const ModelNode &childnode : node.directSubModelNodes())
|
||||
|
@@ -55,8 +55,7 @@ QJsonObject AssetNodeParser::json(Component &component) const
|
||||
QJsonObject jsonObject = ItemNodeParser::json(component);
|
||||
|
||||
QPixmap asset = objectNode().toQmlItemNode().instanceRenderPixmap();
|
||||
Utils::FilePath assetPath = component.exporter().exportAsset(objectNode());
|
||||
|
||||
Utils::FilePath assetPath = component.exporter().exportAsset(objectNode(), uuid());
|
||||
QJsonObject assetData;
|
||||
assetData.insert(AssetPathTag, assetPath.toString());
|
||||
jsonObject.insert(AssetDataTag, assetData);
|
||||
|
@@ -60,6 +60,7 @@ QJsonObject QmlDesigner::ItemNodeParser::json(QmlDesigner::Component &component)
|
||||
jsonObject.insert(WidthTag, size.width());
|
||||
jsonObject.insert(HeightTag, size.height());
|
||||
|
||||
jsonObject.insert(UuidTag, uuid());
|
||||
return jsonObject;
|
||||
}
|
||||
}
|
||||
|
@@ -23,6 +23,7 @@
|
||||
**
|
||||
****************************************************************************/
|
||||
#include "modelnodeparser.h"
|
||||
#include "assetexportpluginconstants.h"
|
||||
|
||||
namespace QmlDesigner {
|
||||
ModelNodeParser::ModelNodeParser(const QByteArrayList &lineage, const ModelNode &node) :
|
||||
@@ -38,4 +39,9 @@ QVariant ModelNodeParser::propertyValue(const PropertyName &name) const
|
||||
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 QmlObjectNode& objectNode() const { return m_objectNode; }
|
||||
QVariant propertyValue(const PropertyName &name) const;
|
||||
QString uuid() const;
|
||||
|
||||
protected:
|
||||
const ModelNode &m_node;
|
||||
|
Reference in New Issue
Block a user