aboutsummaryrefslogtreecommitdiffstats
path: root/src/plugins/qmldesigner/assetexporterplugin/dumpers/assetnodedumper.cpp
blob: 0d6c1391cc6d4867a37956e99009104adcb7b7d5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
// Copyright (C) 2020 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0+ OR GPL-3.0 WITH Qt-GPL-exception-1.0

#include "assetnodedumper.h"
#include "assetexportpluginconstants.h"
#include "assetexporter.h"

#include "qmlitemnode.h"
#include "componentexporter.h"

#include "utils/fileutils.h"

#include <QPixmap>

namespace QmlDesigner {
using namespace Constants;
AssetNodeDumper::AssetNodeDumper(const QByteArrayList &lineage, const ModelNode &node) :
    ItemNodeDumper(lineage, node)
{

}

bool AssetNodeDumper::isExportable() const
{
    auto hasType =  [this](const QByteArray &type) {
        return lineage().contains(type);
    };
    return hasType("QtQuick.Image") || hasType("QtQuick.Rectangle");
}

QJsonObject AssetNodeDumper::json(Component &component) const
{
    QJsonObject jsonObject = ItemNodeDumper::json(component);

    AssetExporter &exporter = component.exporter();
    const Utils::FilePath assetPath = exporter.assetPath(m_node, &component);
    exporter.exportAsset(exporter.generateAsset(m_node), assetPath);

    QJsonObject assetData;
    assetData.insert(AssetPathTag, assetPath.toString());
    QJsonObject metadata = jsonObject.value(MetadataTag).toObject();
    metadata.insert(AssetDataTag, assetData);
    jsonObject.insert(MetadataTag, metadata);
    return jsonObject;
}
}