From ad04078f884d9b652bb1fe647fa21377f9baa4ad Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=8B=E5=8A=B2=E9=B9=8F?= Date: Tue, 17 Dec 2019 17:05:57 +0800 Subject: [PATCH] add super node & view node --- doric/doric.pro | 3 +++ doric/native/native_bridge.cpp | 6 +++++- doric/native/native_empty.cpp | 2 +- doric/native/native_log.cpp | 2 +- doric/native/native_timer.cpp | 2 +- doric/plugin/shader_plugin.cpp | 7 +++++++ doric/plugin/shader_plugin.h | 5 ++--- doric/shader/super_node.h | 25 +++++++++++++++++++++++++ doric/shader/view_node.h | 24 ++++++++++++++++++++++++ 9 files changed, 69 insertions(+), 7 deletions(-) create mode 100644 doric/plugin/shader_plugin.cpp create mode 100644 doric/shader/super_node.h create mode 100644 doric/shader/view_node.h diff --git a/doric/doric.pro b/doric/doric.pro index 7840e88f..3f113457 100644 --- a/doric/doric.pro +++ b/doric/doric.pro @@ -23,6 +23,7 @@ SOURCES += \ native/native_empty.cpp \ native/native_log.cpp \ native/native_timer.cpp \ + plugin/shader_plugin.cpp \ registry.cpp RESOURCES += qml.qrc @@ -52,5 +53,7 @@ HEADERS += \ native/native_timer.h \ plugin/shader_plugin.h \ registry.h \ + shader/super_node.h \ + shader/view_node.h \ template/singleton.h \ utility/utility.h diff --git a/doric/native/native_bridge.cpp b/doric/native/native_bridge.cpp index c198b8d4..a6f5b954 100644 --- a/doric/native/native_bridge.cpp +++ b/doric/native/native_bridge.cpp @@ -14,6 +14,10 @@ Q_INVOKABLE void NativeBridge::function(int contextId, QString module, QString m qDebug() << value; if (value.contains("ShaderPlugin")) { ShaderPlugin shaderPlugin(context); - QMetaObject::invokeMethod(&shaderPlugin, methodName.toStdString().c_str()); + QMetaObject::invokeMethod( + &shaderPlugin, + methodName.toStdString().c_str(), + Qt::AutoConnection, + Q_ARG(QJSValue, jsValue)); } } diff --git a/doric/native/native_empty.cpp b/doric/native/native_empty.cpp index fc60bc1a..06204bb7 100644 --- a/doric/native/native_empty.cpp +++ b/doric/native/native_empty.cpp @@ -2,6 +2,6 @@ #include "native_empty.h" -void NativeEmpty::function() { +Q_INVOKABLE void NativeEmpty::function() { qDebug() << "nativeEmpty"; } diff --git a/doric/native/native_log.cpp b/doric/native/native_log.cpp index 70e7bb72..cce84723 100644 --- a/doric/native/native_log.cpp +++ b/doric/native/native_log.cpp @@ -2,7 +2,7 @@ #include "native_log.h" -void NativeLog::function(QString level, QString content) { +Q_INVOKABLE void NativeLog::function(QString level, QString content) { if (level == 'w') { qWarning() << content; } else if (level == 'd') { diff --git a/doric/native/native_timer.cpp b/doric/native/native_timer.cpp index 2e4ec14d..33eb8040 100644 --- a/doric/native/native_timer.cpp +++ b/doric/native/native_timer.cpp @@ -2,7 +2,7 @@ #include "native_timer.h" -void NativeTimer::setTimer(long timerId, int time, bool repeat) { +Q_INVOKABLE void NativeTimer::setTimer(long timerId, int time, bool repeat) { QTimer *timer = new QTimer(this); timer->setSingleShot(!repeat); connect(timer, &QTimer::timeout, this, [=] () { diff --git a/doric/plugin/shader_plugin.cpp b/doric/plugin/shader_plugin.cpp new file mode 100644 index 00000000..4c383821 --- /dev/null +++ b/doric/plugin/shader_plugin.cpp @@ -0,0 +1,7 @@ +#include "shader_plugin.h" +#include "shader/view_node.h" + +Q_INVOKABLE void ShaderPlugin::render(QJSValue jsValue) { + QString viewId = jsValue.property("id").toString(); + ViewNode *viewNode = new ViewNode(nullptr); +} diff --git a/doric/plugin/shader_plugin.h b/doric/plugin/shader_plugin.h index c774c023..e6fd76a0 100644 --- a/doric/plugin/shader_plugin.h +++ b/doric/plugin/shader_plugin.h @@ -2,6 +2,7 @@ #define SHADER_PLUGIN_H #include +#include #include "context_holder.h" @@ -11,9 +12,7 @@ class ShaderPlugin : public ContextHolder { public: ShaderPlugin(Context *context) : ContextHolder(context) {} - Q_INVOKABLE void render() { - qDebug() << "render"; - } + Q_INVOKABLE void render(QJSValue jsValue); }; #endif // SHADER_PLUGIN_H diff --git a/doric/shader/super_node.h b/doric/shader/super_node.h new file mode 100644 index 00000000..3cc3bdb5 --- /dev/null +++ b/doric/shader/super_node.h @@ -0,0 +1,25 @@ +#ifndef SUPER_NODE_H +#define SUPER_NODE_H + +#include +#include +#include + +#include "view_node.h" + +template +class SuperNode : public ViewNode { + +private: + QMap subNodes; + +protected: + bool reusable = false; + +public: + virtual ~SuperNode() = default; + + virtual ViewNode *getSubNodeById(QString *id) = 0; +}; + +#endif // SUPER_NODE_H diff --git a/doric/shader/view_node.h b/doric/shader/view_node.h new file mode 100644 index 00000000..9e77b493 --- /dev/null +++ b/doric/shader/view_node.h @@ -0,0 +1,24 @@ +#ifndef VIEW_NODE_H +#define VIEW_NODE_H + +#include "context_holder.h" + +using namespace std; + +template +class SuperNode; + +template +class ViewNode : public ContextHolder { + +protected: + T view; + +private: + QString *id; + +public: + ViewNode(Context *context) : ContextHolder(context) {} +}; + +#endif // VIEW_NODE_H