forked from qt-creator/qt-creator
AssetExport: Refactor to accommodate asset generation
Change-Id: I57b33dc06819b3f0d1269eae10bd1131c5cb911d Reviewed-by: Thomas Hartmann <thomas.hartmann@qt.io>
This commit is contained in:
@@ -88,9 +88,9 @@ bool AssetExporter::isBusy() const
|
||||
void AssetExporter::exportComponent(const ModelNode &rootNode)
|
||||
{
|
||||
qCDebug(loggerInfo) << "Exporting component" << rootNode.id();
|
||||
ComponentExporter exporter(rootNode);
|
||||
QJsonObject json = exporter.exportComponent();
|
||||
m_components.append(json);
|
||||
Component exporter(*this, rootNode);
|
||||
exporter.exportComponent();
|
||||
m_components.append(exporter.json());
|
||||
}
|
||||
|
||||
void AssetExporter::notifyLoadError(AssetExporterView::LoadState state)
|
||||
|
@@ -51,20 +51,31 @@ static void populateLineage(const QmlDesigner::ModelNode &node, QByteArrayList &
|
||||
|
||||
namespace QmlDesigner {
|
||||
|
||||
std::vector<std::unique_ptr<Internal::NodeParserCreatorBase>> ComponentExporter::m_readers;
|
||||
ComponentExporter::ComponentExporter(const ModelNode &rootNode):
|
||||
std::vector<std::unique_ptr<Internal::NodeParserCreatorBase>> Component::m_readers;
|
||||
Component::Component(AssetExporter &exporter, const ModelNode &rootNode):
|
||||
m_exporter(exporter),
|
||||
m_rootNode(rootNode)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
QJsonObject ComponentExporter::exportComponent() const
|
||||
QJsonObject Component::json() const
|
||||
{
|
||||
QTC_ASSERT(m_rootNode.isValid(), return {});
|
||||
return nodeToJson(m_rootNode);
|
||||
return m_json;
|
||||
}
|
||||
|
||||
ModelNodeParser *ComponentExporter::createNodeParser(const ModelNode &node) const
|
||||
AssetExporter &Component::exporter()
|
||||
{
|
||||
return m_exporter;
|
||||
}
|
||||
|
||||
void Component::exportComponent()
|
||||
{
|
||||
QTC_ASSERT(m_rootNode.isValid(), return);
|
||||
m_json = nodeToJson(m_rootNode);
|
||||
}
|
||||
|
||||
ModelNodeParser *Component::createNodeParser(const ModelNode &node) const
|
||||
{
|
||||
QByteArrayList lineage;
|
||||
populateLineage(node, lineage);
|
||||
@@ -80,18 +91,19 @@ ModelNodeParser *ComponentExporter::createNodeParser(const ModelNode &node) cons
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!reader) {
|
||||
|
||||
if (!reader)
|
||||
qCDebug(loggerInfo()) << "No parser for node" << node;
|
||||
}
|
||||
|
||||
return reader.release();
|
||||
}
|
||||
|
||||
QJsonObject ComponentExporter::nodeToJson(const ModelNode &node) const
|
||||
QJsonObject Component::nodeToJson(const ModelNode &node)
|
||||
{
|
||||
QJsonObject jsonObject;
|
||||
std::unique_ptr<ModelNodeParser> parser(createNodeParser(node));
|
||||
if (parser)
|
||||
jsonObject = parser->json();
|
||||
jsonObject = parser->json(*this);
|
||||
|
||||
QJsonArray children;
|
||||
for (const ModelNode &childnode : node.directSubModelNodes())
|
||||
|
@@ -24,11 +24,9 @@
|
||||
****************************************************************************/
|
||||
#pragma once
|
||||
|
||||
#include <QJsonValue>
|
||||
#include <QPointer>
|
||||
#include <QJsonObject>
|
||||
#include <QByteArrayList>
|
||||
|
||||
#include <vector>
|
||||
#include <memory>
|
||||
|
||||
#include "utils/qtcassert.h"
|
||||
@@ -38,9 +36,9 @@ class QJsonArray;
|
||||
QT_END_NAMESPACE
|
||||
|
||||
namespace QmlDesigner {
|
||||
class Model;
|
||||
class AssetExporter;
|
||||
class ModelNode;
|
||||
class ComponentExporter;
|
||||
class Component;
|
||||
class ModelNodeParser;
|
||||
|
||||
namespace Internal {
|
||||
@@ -50,7 +48,7 @@ public:
|
||||
virtual ~NodeParserCreatorBase() {}
|
||||
protected:
|
||||
virtual ModelNodeParser *instance(const QByteArrayList &, const ModelNode &) const = 0;
|
||||
friend class QmlDesigner::ComponentExporter;
|
||||
friend class QmlDesigner::Component;
|
||||
};
|
||||
|
||||
template<class T>
|
||||
@@ -67,12 +65,15 @@ protected:
|
||||
};
|
||||
} //Internal
|
||||
|
||||
class ComponentExporter
|
||||
class Component
|
||||
{
|
||||
public:
|
||||
ComponentExporter(const ModelNode &rootNode);
|
||||
Component(AssetExporter& exporter, const ModelNode &rootNode);
|
||||
|
||||
QJsonObject exportComponent() const;
|
||||
void exportComponent();
|
||||
QJsonObject json() const;
|
||||
|
||||
AssetExporter &exporter();
|
||||
|
||||
template<typename T> static void addNodeParser()
|
||||
{
|
||||
@@ -81,10 +82,12 @@ public:
|
||||
}
|
||||
private:
|
||||
ModelNodeParser* createNodeParser(const ModelNode &node) const;
|
||||
QJsonObject nodeToJson(const ModelNode &node) const;
|
||||
QJsonObject nodeToJson(const ModelNode &node);
|
||||
|
||||
private:
|
||||
AssetExporter& m_exporter;
|
||||
const ModelNode &m_rootNode;
|
||||
QJsonObject m_json;
|
||||
static std::vector<std::unique_ptr<Internal::NodeParserCreatorBase>> m_readers;
|
||||
};
|
||||
}
|
||||
|
@@ -30,7 +30,8 @@
|
||||
|
||||
namespace QmlDesigner {
|
||||
using namespace Constants;
|
||||
ItemNodeParser::ItemNodeParser(const QByteArrayList &lineage, const ModelNode &node) :
|
||||
ItemNodeParser::ItemNodeParser(const QByteArrayList &lineage,
|
||||
const ModelNode &node) :
|
||||
ModelNodeParser(lineage, node)
|
||||
{
|
||||
|
||||
@@ -41,8 +42,9 @@ bool QmlDesigner::ItemNodeParser::isExportable() const
|
||||
return lineage().contains("QtQuick.Item");
|
||||
}
|
||||
|
||||
QJsonObject QmlDesigner::ItemNodeParser::json() const
|
||||
QJsonObject QmlDesigner::ItemNodeParser::json(QmlDesigner::Component &component) const
|
||||
{
|
||||
Q_UNUSED(component);
|
||||
const QmlObjectNode &qmlObjectNode = objectNode();
|
||||
QJsonObject jsonObject;
|
||||
jsonObject.insert(QmlIdTag, qmlObjectNode.id());
|
||||
|
@@ -28,6 +28,7 @@
|
||||
|
||||
namespace QmlDesigner {
|
||||
class ModelNode;
|
||||
class Component;
|
||||
|
||||
class ItemNodeParser : public ModelNodeParser
|
||||
{
|
||||
@@ -38,6 +39,6 @@ public:
|
||||
|
||||
int priority() const override { return 100; }
|
||||
bool isExportable() const override;
|
||||
QJsonObject json() const override;
|
||||
QJsonObject json(Component &component) const override;
|
||||
};
|
||||
}
|
||||
|
@@ -30,6 +30,7 @@
|
||||
#include <QByteArrayList>
|
||||
|
||||
namespace QmlDesigner {
|
||||
class Component;
|
||||
class ModelNode;
|
||||
|
||||
class ModelNodeParser
|
||||
@@ -41,14 +42,16 @@ public:
|
||||
|
||||
virtual int priority() const = 0;
|
||||
virtual bool isExportable() const = 0;
|
||||
virtual QJsonObject json() const = 0;
|
||||
virtual QJsonObject json(Component& component) const = 0;
|
||||
|
||||
const QByteArrayList& lineage() const { return m_lineage; }
|
||||
const QmlObjectNode& objectNode() const { return m_objectNode; }
|
||||
QVariant propertyValue(const PropertyName &name) const;
|
||||
|
||||
private:
|
||||
protected:
|
||||
const ModelNode &m_node;
|
||||
|
||||
private:
|
||||
QmlObjectNode m_objectNode;
|
||||
QByteArrayList m_lineage;
|
||||
};
|
||||
|
@@ -61,9 +61,10 @@ bool TextNodeParser::isExportable() const
|
||||
return lineage().contains("QtQuick.Text");
|
||||
}
|
||||
|
||||
QJsonObject TextNodeParser::json() const
|
||||
QJsonObject TextNodeParser::json(Component &component) const
|
||||
{
|
||||
QJsonObject jsonObject = ItemNodeParser::json();
|
||||
Q_UNUSED(component);
|
||||
QJsonObject jsonObject = ItemNodeParser::json(component);
|
||||
|
||||
QJsonObject textDetails;
|
||||
textDetails.insert(TextContentTag, propertyValue("text").toString());
|
||||
|
@@ -27,6 +27,8 @@
|
||||
#include "modelitemnodeparser.h"
|
||||
|
||||
namespace QmlDesigner {
|
||||
class Component;
|
||||
|
||||
class TextNodeParser : public ItemNodeParser
|
||||
{
|
||||
public:
|
||||
@@ -35,7 +37,7 @@ public:
|
||||
|
||||
bool isExportable() const override;
|
||||
int priority() const override { return 200; }
|
||||
QJsonObject json() const override;
|
||||
QJsonObject json(Component &component) const override;
|
||||
};
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user