From 85bf537fc0f73b3ab02d1ebdedeccb8da5d13968 Mon Sep 17 00:00:00 2001 From: Mahmoud Badri Date: Thu, 17 Aug 2023 15:59:46 +0300 Subject: [PATCH] QmlDesigner: Implement basic composition node delegate Task-number: QDS-10404 Change-Id: Ia456fb96c157d5e8d6206732c90d761c59b27fab Reviewed-by: Amr Elsayed Reviewed-by: Miikka Heikkinen Reviewed-by: Qt CI Patch Build Bot --- .../EffectCompositionNode.qml | 37 +++++++++++++++++ .../effectMakerQmlSources/EffectMaker.qml | 40 +++++-------------- .../effectmaker/compositionnode.cpp | 40 ++++++++++++++----- .../components/effectmaker/compositionnode.h | 3 +- .../effectmaker/effectmakermodel.cpp | 15 +++---- 5 files changed, 85 insertions(+), 50 deletions(-) create mode 100644 share/qtcreator/qmldesigner/effectMakerQmlSources/EffectCompositionNode.qml diff --git a/share/qtcreator/qmldesigner/effectMakerQmlSources/EffectCompositionNode.qml b/share/qtcreator/qmldesigner/effectMakerQmlSources/EffectCompositionNode.qml new file mode 100644 index 00000000000..0cb84e8c89c --- /dev/null +++ b/share/qtcreator/qmldesigner/effectMakerQmlSources/EffectCompositionNode.qml @@ -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 + // } + // } + } +} + diff --git a/share/qtcreator/qmldesigner/effectMakerQmlSources/EffectMaker.qml b/share/qtcreator/qmldesigner/effectMakerQmlSources/EffectMaker.qml index 299f8672329..ee3992cac51 100644 --- a/share/qtcreator/qmldesigner/effectMakerQmlSources/EffectMaker.qml +++ b/share/qtcreator/qmldesigner/effectMakerQmlSources/EffectMaker.qml @@ -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 } } } diff --git a/src/plugins/qmldesigner/components/effectmaker/compositionnode.cpp b/src/plugins/qmldesigner/components/effectmaker/compositionnode.cpp index ce686bc3fd6..7fc4694b718 100644 --- a/src/plugins/qmldesigner/components/effectmaker/compositionnode.cpp +++ b/src/plugins/qmldesigner/components/effectmaker/compositionnode.cpp @@ -4,9 +4,9 @@ #include "compositionnode.h" #include +#include #include #include -#include 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 diff --git a/src/plugins/qmldesigner/components/effectmaker/compositionnode.h b/src/plugins/qmldesigner/components/effectmaker/compositionnode.h index 0d16dbc5dc7..cc878a428c9 100644 --- a/src/plugins/qmldesigner/components/effectmaker/compositionnode.h +++ b/src/plugins/qmldesigner/components/effectmaker/compositionnode.h @@ -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 - diff --git a/src/plugins/qmldesigner/components/effectmaker/effectmakermodel.cpp b/src/plugins/qmldesigner/components/effectmaker/effectmakermodel.cpp index cc34926f027..db0754bed4d 100644 --- a/src/plugins/qmldesigner/components/effectmaker/effectmakermodel.cpp +++ b/src/plugins/qmldesigner/components/effectmaker/effectmakermodel.cpp @@ -5,6 +5,8 @@ #include "compositionnode.h" +#include + 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)