QmlDesigner: Implement basic composition node delegate

Task-number: QDS-10404
Change-Id: Ia456fb96c157d5e8d6206732c90d761c59b27fab
Reviewed-by: Amr Elsayed <amr.elsayed@qt.io>
Reviewed-by: Miikka Heikkinen <miikka.heikkinen@qt.io>
Reviewed-by: Qt CI Patch Build Bot <ci_patchbuild_bot@qt.io>
This commit is contained in:
Mahmoud Badri
2023-08-17 15:59:46 +03:00
parent cf54c2ffcd
commit 85bf537fc0
5 changed files with 85 additions and 50 deletions

View File

@@ -0,0 +1,37 @@
// Copyright (C) 2023 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
import QtQuick
import QtQuick.Controls
import QtQuickDesignerTheme
import HelperWidgets as HelperWidgets
import StudioControls as StudioControls
import StudioTheme 1.0 as StudioTheme
import EffectMakerBackend
HelperWidgets.Section {
id: root
caption: model.nodeName
category: "EffectMaker"
// TODO: implement effect properties
// property var propList: model.props
Column {
anchors.fill: parent
spacing: 2
// Repeater {
// id: effects
// model: effectList
// width: parent.width
// height: parent.height
// delegate: Text {
// width: parent.width
// //height: StudioTheme.Values.checkIndicatorHeight * 2 // TODO: update or remove
// }
// }
}
}

View File

@@ -64,40 +64,18 @@ Item {
}
Column {
Item {
width: scrollView.width
height: categories.height
width: scrollView.width
height: compositionRepeater.height
spacing: 1
Column {
Repeater {
id: categories
width: root.width
model: EffectMakerBackend.effectMakerModel
Repeater {
id: compositionRepeater
delegate: HelperWidgets.Section {
id: effectsSection
width: root.width
caption: model.categoryName
category: "EffectMaker"
width: root.width
model: EffectMakerBackend.effectMakerModel
property var effectList: model.effectNames
onExpandedChanged: {
effects.visible = expanded // TODO: update
}
Repeater {
id: effects
model: effectList
width: parent.width
height: parent.height
delegate: EffectNode {
width: parent.width
//height: StudioTheme.Values.checkIndicatorHeight * 2 // TODO: update or remove
}
}
}
}
delegate: EffectCompositionNode {
width: root.width
}
}
}

View File

@@ -4,9 +4,9 @@
#include "compositionnode.h"
#include <QFileInfo>
#include <QJsonArray>
#include <QJsonDocument>
#include <QJsonObject>
#include <QJsonArray>
namespace QmlDesigner {
@@ -33,14 +33,14 @@ QString CompositionNode::description() const
void CompositionNode::parse(const QString &qenPath)
{
QFile loadFile(qenPath);
QFile qenFile(qenPath);
if (!loadFile.open(QIODevice::ReadOnly)) {
if (!qenFile.open(QIODevice::ReadOnly)) {
qWarning("Couldn't open effect file.");
return;
}
QByteArray loadData = loadFile.readAll();
QByteArray loadData = qenFile.readAll();
QJsonParseError parseError;
QJsonDocument jsonDoc(QJsonDocument::fromJson(loadData, &parseError));
if (parseError.error != QJsonParseError::NoError) {
@@ -51,13 +51,31 @@ void CompositionNode::parse(const QString &qenPath)
return;
}
QJsonObject json = jsonDoc.object();
QFileInfo fi(loadFile);
QJsonObject json = jsonDoc.object().value("QEN").toObject();
// 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
m_name = json.value("name").toString();
// parse properties
QJsonArray properties = json.value("properties").toArray();
for (const auto /*QJsonValueRef*/ &prop : properties) {
QJsonObject propObj = prop.toObject();
propObj.value("name");
propObj.value("type");
propObj.value("defaultValue");
propObj.value("description");
// TODO
}
// parse shaders
QJsonArray vertexCode = json.value("vertexCode").toArray();
if (!vertexCode.isEmpty()) {
// TODO
}
QJsonArray fragmentCode = json.value("fragmentCode").toArray();
if (!fragmentCode.isEmpty()) {
// TODO
}
}
}
} // namespace QmlDesigner

View File

@@ -11,6 +11,8 @@ class CompositionNode : public QObject
{
Q_OBJECT
Q_PROPERTY(QString nodeName MEMBER m_name CONSTANT)
public:
CompositionNode(const QString &qenPath);
@@ -28,4 +30,3 @@ private:
};
} // namespace QmlDesigner

View File

@@ -5,6 +5,8 @@
#include "compositionnode.h"
#include <utils/qtcassert.h>
namespace QmlDesigner {
EffectMakerModel::EffectMakerModel(QObject *parent)
@@ -26,14 +28,12 @@ int EffectMakerModel::rowCount(const QModelIndex &parent) const
return m_nodes.count();
}
QVariant EffectMakerModel::data(const QModelIndex &index, int /*role*/) const
QVariant EffectMakerModel::data(const QModelIndex &index, int role) const
{
if (index.row() < 0 || index.row() >= m_nodes.count())
return {};
QTC_ASSERT(index.isValid() && index.row() < m_nodes.size(), return {});
QTC_ASSERT(roleNames().contains(role), return {});
// TODO
return {};
return m_nodes.values().at(index.row())->property(roleNames().value(role));
}
void EffectMakerModel::resetModel()
@@ -46,9 +46,10 @@ void EffectMakerModel::addNode(const QString &nodeQenPath)
{
static int id = 0;
beginInsertRows({}, m_nodes.size(), m_nodes.size());
auto *node = new CompositionNode(nodeQenPath);
m_nodes.insert(id++, node);
// TODO: update model
endInsertRows();
}
void EffectMakerModel::selectEffect(int idx, bool force)