QmlDesigner: Create effect node entity members

The EffectNode entity members and initial implementation for loading effect resources

Task-number: QDS-10402
Change-Id: I36913731f15fdc89e7bbaa1a7b40088a817e3086
Reviewed-by: Mahmoud Badri <mahmoud.badri@qt.io>
Reviewed-by: Qt CI Patch Build Bot <ci_patchbuild_bot@qt.io>
This commit is contained in:
Amr Essam
2023-08-14 11:12:04 +03:00
committed by Amr Elsayed
parent 56303d62a6
commit a4fbbb2463
3 changed files with 92 additions and 9 deletions

View File

@@ -87,11 +87,7 @@ void EffectMakerNodesModel::loadModel()
QDirIterator itEffects(categoryPath.toString(), {"*.qen"}, QDir::Files); QDirIterator itEffects(categoryPath.toString(), {"*.qen"}, QDir::Files);
while (itEffects.hasNext()) { while (itEffects.hasNext()) {
itEffects.next(); itEffects.next();
QString fileName = QFileInfo(itEffects.fileName()).baseName(); effects.push_back(new EffectNode(itEffects.filePath()));
QString iconPath = m_nodesPath.path() + '/' + catName + "/icon/" + fileName + ".svg";
if (!QFileInfo::exists(iconPath))
iconPath = m_nodesPath.path() + "/placeholder.svg";
effects.push_back(new EffectNode(fileName, iconPath));
} }
catName[0] = catName[0].toUpper(); // capitalize first letter catName[0] = catName[0].toUpper(); // capitalize first letter

View File

@@ -3,10 +3,71 @@
#include "effectnode.h" #include "effectnode.h"
#include <QDir>
#include <QFileInfo>
namespace QmlDesigner { namespace QmlDesigner {
EffectNode::EffectNode(const QString &name, const QString &iconPath) EffectNode::EffectNode(const QString &qenPath)
: m_name(name) : m_qenPath(qenPath)
, m_iconPath(QUrl::fromLocalFile(iconPath)) {} {
parse(qenPath);
}
QString EffectNode::qenPath() const
{
return m_qenPath;
}
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 } // namespace QmlDesigner

View File

@@ -16,10 +16,36 @@ class EffectNode : public QObject
Q_PROPERTY(QUrl nodeIcon MEMBER m_iconPath CONSTANT) Q_PROPERTY(QUrl nodeIcon MEMBER m_iconPath CONSTANT)
public: public:
EffectNode(const QString &name, const QString &iconPath); 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: private:
void parse(const QString &qenPath);
QString m_qenPath;
QString m_name; QString m_name;
int m_nodeId = -1;
QString m_fragmentCode;
QString m_vertexCode;
QString m_qmlCode;
QString m_description;
QUrl m_iconPath; QUrl m_iconPath;
}; };