2023-08-16 11:35:10 +03:00
|
|
|
// Copyright (C) 2023 The Qt Company Ltd.
|
|
|
|
|
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
|
|
|
|
|
|
|
|
|
|
#include "compositionnode.h"
|
|
|
|
|
|
2023-08-18 15:39:40 +03:00
|
|
|
#include "effectutils.h"
|
2023-08-17 18:38:40 +03:00
|
|
|
#include "uniform.h"
|
|
|
|
|
|
2023-08-16 11:35:10 +03:00
|
|
|
#include <QFileInfo>
|
2023-08-17 15:59:46 +03:00
|
|
|
#include <QJsonArray>
|
2023-08-16 11:35:10 +03:00
|
|
|
#include <QJsonDocument>
|
|
|
|
|
#include <QJsonObject>
|
|
|
|
|
|
|
|
|
|
namespace QmlDesigner {
|
|
|
|
|
|
|
|
|
|
CompositionNode::CompositionNode(const QString &qenPath)
|
|
|
|
|
{
|
|
|
|
|
parse(qenPath);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QString CompositionNode::fragmentCode() const
|
|
|
|
|
{
|
|
|
|
|
return m_fragmentCode;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QString CompositionNode::vertexCode() const
|
|
|
|
|
{
|
|
|
|
|
return m_vertexCode;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QString CompositionNode::description() const
|
|
|
|
|
{
|
|
|
|
|
return m_description;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void CompositionNode::parse(const QString &qenPath)
|
|
|
|
|
{
|
|
|
|
|
|
2023-08-17 15:59:46 +03:00
|
|
|
QFile qenFile(qenPath);
|
2023-08-16 11:35:10 +03:00
|
|
|
|
2023-08-17 15:59:46 +03:00
|
|
|
if (!qenFile.open(QIODevice::ReadOnly)) {
|
2023-08-16 11:35:10 +03:00
|
|
|
qWarning("Couldn't open effect file.");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2023-08-17 15:59:46 +03:00
|
|
|
QByteArray loadData = qenFile.readAll();
|
2023-08-16 11:35:10 +03:00
|
|
|
QJsonParseError parseError;
|
|
|
|
|
QJsonDocument jsonDoc(QJsonDocument::fromJson(loadData, &parseError));
|
|
|
|
|
if (parseError.error != QJsonParseError::NoError) {
|
|
|
|
|
QString error = QString("Error parsing the effect node: %1:").arg(qenPath);
|
|
|
|
|
QString errorDetails = QString("%1: %2").arg(parseError.offset).arg(parseError.errorString());
|
|
|
|
|
qWarning() << qPrintable(error);
|
|
|
|
|
qWarning() << qPrintable(errorDetails);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2023-08-17 15:59:46 +03:00
|
|
|
QJsonObject json = jsonDoc.object().value("QEN").toObject();
|
2023-08-16 11:35:10 +03:00
|
|
|
|
2023-08-17 18:38:40 +03:00
|
|
|
int version = -1;
|
|
|
|
|
if (json.contains("version"))
|
|
|
|
|
version = json["version"].toInt(-1);
|
|
|
|
|
if (version != 1) {
|
|
|
|
|
QString error = QString("Error: Unknown effect version (%1)").arg(version);
|
|
|
|
|
qWarning() << qPrintable(error);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2023-08-18 15:39:40 +03:00
|
|
|
m_name = json.value("name").toString();
|
2023-08-17 18:38:40 +03:00
|
|
|
m_description = json.value("description").toString();
|
2023-08-18 15:39:40 +03:00
|
|
|
m_fragmentCode = EffectUtils::codeFromJsonArray(json.value("fragmentCode").toArray());
|
|
|
|
|
m_vertexCode = EffectUtils::codeFromJsonArray(json.value("vertexCode").toArray());
|
2023-08-17 15:59:46 +03:00
|
|
|
|
|
|
|
|
// parse properties
|
|
|
|
|
QJsonArray properties = json.value("properties").toArray();
|
|
|
|
|
for (const auto /*QJsonValueRef*/ &prop : properties) {
|
|
|
|
|
QJsonObject propObj = prop.toObject();
|
2023-08-17 18:38:40 +03:00
|
|
|
Uniform *u = new Uniform(propObj);
|
|
|
|
|
Q_UNUSED(u)
|
|
|
|
|
|
|
|
|
|
// TODO
|
2023-08-17 15:59:46 +03:00
|
|
|
propObj.value("name");
|
|
|
|
|
propObj.value("type");
|
|
|
|
|
propObj.value("defaultValue");
|
|
|
|
|
propObj.value("description");
|
|
|
|
|
}
|
2023-08-17 18:38:40 +03:00
|
|
|
}
|
2023-08-16 11:35:10 +03:00
|
|
|
|
2023-08-17 15:59:46 +03:00
|
|
|
} // namespace QmlDesigner
|