From 93fb4983e50048b330f62f302791e5ea5cd5c40d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=8B=E5=8A=B2=E9=B9=8F?= Date: Mon, 31 May 2021 17:53:27 +0800 Subject: [PATCH] add slider child render --- doric-Qt/example/doric/resources/slider.qml | 8 ---- .../doric/shader/slider/DoricSliderNode.cpp | 40 +++++++++++++++---- 2 files changed, 32 insertions(+), 16 deletions(-) diff --git a/doric-Qt/example/doric/resources/slider.qml b/doric-Qt/example/doric/resources/slider.qml index 11c991ac..e6a0a4fb 100644 --- a/doric-Qt/example/doric/resources/slider.qml +++ b/doric-Qt/example/doric/resources/slider.qml @@ -40,12 +40,4 @@ SwipeView { onBorderColorChanged: { bg.border.color = borderColor } - - MouseArea { - anchors.fill: parent - onClicked: { - console.log(tag, uuid + " wrapper: " + wrapper) - mouseAreaBridge.onClick(wrapper) - } - } } diff --git a/doric-Qt/example/doric/shader/slider/DoricSliderNode.cpp b/doric-Qt/example/doric/shader/slider/DoricSliderNode.cpp index b387710d..de07f779 100644 --- a/doric-Qt/example/doric/shader/slider/DoricSliderNode.cpp +++ b/doric-Qt/example/doric/shader/slider/DoricSliderNode.cpp @@ -1,5 +1,7 @@ #include "DoricSliderNode.h" +#include + QQuickItem *DoricSliderNode::build() { QQmlComponent component(getContext()->getQmlEngine()); @@ -17,18 +19,19 @@ QQuickItem *DoricSliderNode::build() { return item; } -DoricViewNode *DoricSliderNode::getSubNodeById(QString id) { return nullptr; } +DoricViewNode *DoricSliderNode::getSubNodeById(QString id) { + for (int i = 0; i != childNodes.size(); i++) { + if (childNodes.at(i)->getId() == id) { + return childNodes.at(i); + } + } +} void DoricSliderNode::blendSubNode(QJsonValue subProperties) { QString viewId = subProperties["id"].toString(); DoricViewNode *node = getSubNodeById(viewId); if (node != nullptr) { node->blend(subProperties["props"]); - } else { - QJsonValue oldModel = getSubModel(viewId); - if (oldModel != QJsonValue::Undefined) { - DoricSuperNode::recursiveMixin(subProperties, oldModel); - } } } @@ -58,7 +61,28 @@ void DoricSliderNode::afterBlended(QJsonValue prop) { args.append(this->itemCount); std::shared_ptr asyncResult = this->pureCallJSResponse("renderBunchedItems", args); - QString result = asyncResult->waitUntilResult(); - qDebug() << result; + QString jsValueString = asyncResult->waitUntilResult(); + + QJsonDocument document = QJsonDocument::fromJson(jsValueString.toUtf8()); + QJsonArray jsValue = document.array(); + + for (int i = 0; i != jsValue.size(); i++) { + QJsonValue model = jsValue.at(i); + QString id = model["id"].toString(); + QString type = model["type"].toString(); + DoricViewNode *newNode = DoricViewNode::create(getContext(), type); + if (newNode != nullptr) { + newNode->setId(id); + newNode->init(this); + + this->childNodes.append((DoricSlideItemNode *)newNode); + newNode->getNodeView()->setParentItem(mView); + + newNode->blend(model["props"]); + } + } + + int size = childNodes.size(); + qDebug() << size; } }