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