diff --git a/doric-Qt/example/doric/doric.pro b/doric-Qt/example/doric/doric.pro index 91e1c170..f0328e89 100644 --- a/doric-Qt/example/doric/doric.pro +++ b/doric-Qt/example/doric/doric.pro @@ -60,6 +60,7 @@ SOURCES += \ shader/DoricTextNode.cpp \ shader/DoricVLayoutNode.cpp \ shader/DoricViewNode.cpp \ + shader/list/DoricListAdapter.cpp \ shader/list/DoricListItemNode.cpp \ shader/list/DoricListNode.cpp \ shader/slider/DoricSlideItemNode.cpp \ @@ -156,6 +157,7 @@ HEADERS += \ shader/DoricTextNode.h \ shader/DoricVLayoutNode.h \ shader/DoricViewNode.h \ + shader/list/DoricListAdapter.h \ shader/list/DoricListItemNode.h \ shader/list/DoricListNode.h \ shader/slider/DoricSlideItemNode.h \ diff --git a/doric-Qt/example/doric/resources/list-item.qml b/doric-Qt/example/doric/resources/list-item.qml index 709a4d1e..53a13ac2 100644 --- a/doric-Qt/example/doric/resources/list-item.qml +++ b/doric-Qt/example/doric/resources/list-item.qml @@ -1,6 +1,6 @@ import QtQuick 2.12 import QtQuick.Controls 2.5 -import QtQuick.Layouts 1.15 +import QtQuick.Layouts 1.14 import QtGraphicalEffects 1.12 import "util.mjs" as Util diff --git a/doric-Qt/example/doric/resources/list.qml b/doric-Qt/example/doric/resources/list.qml index acf7d963..6618e90c 100644 --- a/doric-Qt/example/doric/resources/list.qml +++ b/doric-Qt/example/doric/resources/list.qml @@ -47,7 +47,7 @@ ListView { delegate: Rectangle { Component.onCompleted: { -// listBridge.getItemModel(index) + listBridge.bind(wrapper, this, index) } } } diff --git a/doric-Qt/example/doric/shader/list/DoricListAdapter.cpp b/doric-Qt/example/doric/shader/list/DoricListAdapter.cpp new file mode 100644 index 00000000..5f393db9 --- /dev/null +++ b/doric-Qt/example/doric/shader/list/DoricListAdapter.cpp @@ -0,0 +1,9 @@ +#include "DoricListAdapter.h" + +#include + +DoricListAdapter::DoricListAdapter() {} + +void DoricListAdapter::bind(QVariant rectangle, int position) { + qDebug() << "==========" << rectangle << " " << position; +} diff --git a/doric-Qt/example/doric/shader/list/DoricListAdapter.h b/doric-Qt/example/doric/shader/list/DoricListAdapter.h new file mode 100644 index 00000000..84ce1edc --- /dev/null +++ b/doric-Qt/example/doric/shader/list/DoricListAdapter.h @@ -0,0 +1,13 @@ +#ifndef DORICLISTADAPTER_H +#define DORICLISTADAPTER_H + +#include + +class DoricListAdapter { +public: + DoricListAdapter(); + + void bind(QVariant rectangle, int position); +}; + +#endif // DORICLISTADAPTER_H diff --git a/doric-Qt/example/doric/shader/list/DoricListNode.cpp b/doric-Qt/example/doric/shader/list/DoricListNode.cpp index d96c70a7..05851f01 100644 --- a/doric-Qt/example/doric/shader/list/DoricListNode.cpp +++ b/doric-Qt/example/doric/shader/list/DoricListNode.cpp @@ -21,6 +21,19 @@ DoricViewNode *DoricListNode::getSubNodeById(QString id) {} void DoricListNode::blendSubNode(QJsonValue subProperties) {} -void DoricListNode::blend(QQuickItem *view, QString name, QJsonValue prop) {} +void DoricListNode::blend(QQuickItem *view, QString name, QJsonValue prop) { + if (name == "itemCount") { + this->itemCount = prop.toInt(); + } else { + DoricSuperNode::blend(view, name, prop); + } +} -void DoricListNode::afterBlended(QJsonValue prop) {} +void DoricListNode::afterBlended(QJsonValue prop) { + mView->setProperty("model", this->itemCount); +} + +// adapter method +void DoricListNode::bind(QVariant rectangle, int position) { + listAdapter.bind(rectangle, position); +} diff --git a/doric-Qt/example/doric/shader/list/DoricListNode.h b/doric-Qt/example/doric/shader/list/DoricListNode.h index 1b23dbdf..e2bb4e39 100644 --- a/doric-Qt/example/doric/shader/list/DoricListNode.h +++ b/doric-Qt/example/doric/shader/list/DoricListNode.h @@ -5,6 +5,7 @@ #include "DoricListItemNode.h" #include "shader/DoricSuperNode.h" +#include "DoricListAdapter.h" class DORIC_EXPORT DoricListNode : public DoricSuperNode { @@ -17,7 +18,7 @@ private: QString loadMoreViewId; QString onScrollFuncId; QString onScrollEndFuncId; - QList childNodes; + DoricListAdapter listAdapter; public: using DoricSuperNode::DoricSuperNode; @@ -31,6 +32,8 @@ public: virtual void blend(QQuickItem *view, QString name, QJsonValue prop) override; virtual void afterBlended(QJsonValue prop) override; + + void bind(QVariant rectangle, int position); }; #endif // DORICLISTNODE_H diff --git a/doric-Qt/example/doric/utils/DoricListBridge.cpp b/doric-Qt/example/doric/utils/DoricListBridge.cpp index 55cb73f3..bab9d7a1 100644 --- a/doric-Qt/example/doric/utils/DoricListBridge.cpp +++ b/doric-Qt/example/doric/utils/DoricListBridge.cpp @@ -1,3 +1,10 @@ #include "DoricListBridge.h" +#include "shader/list/DoricListNode.h" DoricListBridge::DoricListBridge(QObject *parent) : QObject(parent) {} + +void DoricListBridge::bind(QString pointer, QVariant rectangle, int position) { + QObject *object = (QObject *)(pointer.toULongLong()); + DoricListNode *listNode = dynamic_cast(object); + listNode->bind(rectangle, position); +} diff --git a/doric-Qt/example/doric/utils/DoricListBridge.h b/doric-Qt/example/doric/utils/DoricListBridge.h index 85e81cd4..627dab84 100644 --- a/doric-Qt/example/doric/utils/DoricListBridge.h +++ b/doric-Qt/example/doric/utils/DoricListBridge.h @@ -10,6 +10,9 @@ class DORIC_EXPORT DoricListBridge : public QObject { Q_OBJECT public: explicit DoricListBridge(QObject *parent = nullptr); + + Q_INVOKABLE + void bind(QString pointer, QVariant rectangle, int position); }; #endif // DORICLISTBRIDGE_H