forked from qt-creator/qt-creator
QmlDesigner: Create the CompositionNode class
This one is used to represent an effect with its attributes while editing the current composition. Also some refactoring to remove the composition properties from EffectNode. Change-Id: Idd0137db98cb608f3ead49ba3208e4480a185e88 Reviewed-by: Mahmoud Badri <mahmoud.badri@qt.io>
This commit is contained in:
@@ -715,6 +715,7 @@ extend_qtc_plugin(QmlDesigner
|
||||
effectmakernodesmodel.cpp effectmakernodesmodel.h
|
||||
effectnode.cpp effectnode.h
|
||||
effectnodescategory.cpp effectnodescategory.h
|
||||
compositionnode.cpp compositionnode.h
|
||||
)
|
||||
|
||||
extend_qtc_plugin(QmlDesigner
|
||||
|
||||
@@ -0,0 +1,63 @@
|
||||
// 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"
|
||||
|
||||
#include <QFileInfo>
|
||||
#include <QJsonDocument>
|
||||
#include <QJsonObject>
|
||||
#include <QJsonArray>
|
||||
|
||||
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)
|
||||
{
|
||||
|
||||
QFile loadFile(qenPath);
|
||||
|
||||
if (!loadFile.open(QIODevice::ReadOnly)) {
|
||||
qWarning("Couldn't open effect file.");
|
||||
return;
|
||||
}
|
||||
|
||||
QByteArray loadData = loadFile.readAll();
|
||||
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;
|
||||
}
|
||||
|
||||
QJsonObject json = jsonDoc.object();
|
||||
QFileInfo fi(loadFile);
|
||||
|
||||
// TODO: QDS-10467
|
||||
// Parse the effect from QEN file
|
||||
// The process from the older implementation has the concept of `project`
|
||||
// and it contains source & dest nodes that we don't need
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
// Copyright (C) 2023 The Qt Company Ltd.
|
||||
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <QObject>
|
||||
|
||||
namespace QmlDesigner {
|
||||
|
||||
class CompositionNode : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
CompositionNode(const QString &qenPath);
|
||||
|
||||
QString fragmentCode() const;
|
||||
QString vertexCode() const;
|
||||
QString description() const;
|
||||
|
||||
private:
|
||||
void parse(const QString &qenPath);
|
||||
|
||||
QString m_name;
|
||||
QString m_fragmentCode;
|
||||
QString m_vertexCode;
|
||||
QString m_description;
|
||||
};
|
||||
|
||||
} // namespace QmlDesigner
|
||||
|
||||
@@ -11,7 +11,17 @@ namespace QmlDesigner {
|
||||
EffectNode::EffectNode(const QString &qenPath)
|
||||
: m_qenPath(qenPath)
|
||||
{
|
||||
parse(qenPath);
|
||||
const QFileInfo fileInfo = QFileInfo(qenPath);
|
||||
m_name = fileInfo.baseName();
|
||||
|
||||
QString iconPath = QStringLiteral("%1/icon/%2.svg").arg(fileInfo.absolutePath(), m_name);
|
||||
if (!QFileInfo::exists(iconPath)) {
|
||||
QDir parentDir = QDir(fileInfo.absolutePath());
|
||||
parentDir.cdUp();
|
||||
|
||||
iconPath = QStringLiteral("%1/%2").arg(parentDir.path(), "placeholder.svg");
|
||||
}
|
||||
m_iconPath = QUrl::fromLocalFile(iconPath);
|
||||
}
|
||||
|
||||
QString EffectNode::qenPath() const
|
||||
@@ -24,50 +34,9 @@ QString EffectNode::name() const
|
||||
return m_name;
|
||||
}
|
||||
|
||||
int EffectNode::nodeId() const
|
||||
{
|
||||
return m_nodeId;
|
||||
}
|
||||
|
||||
QString EffectNode::fragmentCode() const
|
||||
{
|
||||
return m_fragmentCode;
|
||||
}
|
||||
|
||||
QString EffectNode::vertexCode() const
|
||||
{
|
||||
return m_vertexCode;
|
||||
}
|
||||
|
||||
QString EffectNode::qmlCode() const
|
||||
{
|
||||
return m_qmlCode;
|
||||
}
|
||||
|
||||
QString EffectNode::description() const
|
||||
{
|
||||
return m_description;
|
||||
}
|
||||
|
||||
void EffectNode::parse(const QString &qenPath)
|
||||
{
|
||||
const QFileInfo fileInfo = QFileInfo(qenPath);
|
||||
m_name = fileInfo.baseName();
|
||||
|
||||
QString iconPath = QStringLiteral("%1/icon/%2.svg").arg(fileInfo.absolutePath(), m_name);
|
||||
if (!QFileInfo::exists(iconPath)) {
|
||||
QDir parentDir = QDir(fileInfo.absolutePath());
|
||||
parentDir.cdUp();
|
||||
|
||||
iconPath = QStringLiteral("%1/%2").arg(parentDir.path(), "placeholder.svg");
|
||||
}
|
||||
m_iconPath = QUrl::fromLocalFile(iconPath);
|
||||
|
||||
// TODO: QDS-10467
|
||||
// Parse the effect from QEN file
|
||||
// The process from the older implementation has the concept of `project`
|
||||
// and it contains source & dest nodes that we don't need
|
||||
}
|
||||
|
||||
|
||||
} // namespace QmlDesigner
|
||||
|
||||
@@ -19,32 +19,12 @@ public:
|
||||
EffectNode(const QString &qenPath);
|
||||
|
||||
QString qenPath() const;
|
||||
|
||||
QString name() const;
|
||||
int nodeId() const;
|
||||
QString fragmentCode() const;
|
||||
QString vertexCode() const;
|
||||
QString qmlCode() const;
|
||||
QString description() const;
|
||||
|
||||
bool operator==(const EffectNode &rhs) const noexcept
|
||||
{
|
||||
return this->m_nodeId == rhs.m_nodeId;
|
||||
}
|
||||
bool operator!=(const EffectNode &rhs) const noexcept
|
||||
{
|
||||
return !operator==(rhs);
|
||||
}
|
||||
|
||||
private:
|
||||
void parse(const QString &qenPath);
|
||||
|
||||
QString m_qenPath;
|
||||
QString m_name;
|
||||
int m_nodeId = -1;
|
||||
QString m_fragmentCode;
|
||||
QString m_vertexCode;
|
||||
QString m_qmlCode;
|
||||
QString m_description;
|
||||
QUrl m_iconPath;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user