add list bind function

This commit is contained in:
王劲鹏 2021-06-29 10:29:36 +08:00 committed by osborn
parent f191910cb6
commit 35b9d67de6
9 changed files with 55 additions and 5 deletions

View File

@ -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 \

View File

@ -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

View File

@ -47,7 +47,7 @@ ListView {
delegate: Rectangle {
Component.onCompleted: {
// listBridge.getItemModel(index)
listBridge.bind(wrapper, this, index)
}
}
}

View File

@ -0,0 +1,9 @@
#include "DoricListAdapter.h"
#include <QDebug>
DoricListAdapter::DoricListAdapter() {}
void DoricListAdapter::bind(QVariant rectangle, int position) {
qDebug() << "==========" << rectangle << " " << position;
}

View File

@ -0,0 +1,13 @@
#ifndef DORICLISTADAPTER_H
#define DORICLISTADAPTER_H
#include <QVariant>
class DoricListAdapter {
public:
DoricListAdapter();
void bind(QVariant rectangle, int position);
};
#endif // DORICLISTADAPTER_H

View File

@ -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);
}

View File

@ -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<DoricListItemNode *> 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

View File

@ -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<DoricListNode *>(object);
listNode->bind(rectangle, position);
}

View File

@ -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