From 3b287974abb5713da5dc060051f32440df374ff8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=8B=E5=8A=B2=E9=B9=8F?= Date: Thu, 19 Dec 2019 19:54:58 +0800 Subject: [PATCH] add async result --- doric/async/async_result.h | 49 ++++++++++++++++++++++++++++++++++ doric/async/callback.h | 18 +++++++++++++ doric/doric.pro | 4 +-- doric/main.cpp | 6 +++++ doric/plugin/shader_plugin.cpp | 3 +-- doric/shader/layer.h | 25 ++++++++++++++++- doric/shader/super_node.h | 25 ----------------- doric/shader/view_node.h | 24 ----------------- 8 files changed, 100 insertions(+), 54 deletions(-) create mode 100644 doric/async/async_result.h create mode 100644 doric/async/callback.h delete mode 100644 doric/shader/super_node.h delete mode 100644 doric/shader/view_node.h diff --git a/doric/async/async_result.h b/doric/async/async_result.h new file mode 100644 index 00000000..ffe14871 --- /dev/null +++ b/doric/async/async_result.h @@ -0,0 +1,49 @@ +#ifndef ASYNC_RESULT_H +#define ASYNC_RESULT_H + +#include +#include + +#include "callback.h" + +template +class AsyncResult { + +private: + QVariant result; + Callback *callback; + +public: + AsyncResult() {} + + AsyncResult(R result) { + this->result.setValue(result); + } + + void setResult(R result) { + this->result.setValue(result); + if (callback != nullptr) { + this->callback->onResult(result); + this->callback->onFinish(); + } + } + + void setError(QException *exception) { + this->result->setValue(exception); + if (callback != nullptr) { + this->callback->onError(exception); + this->callback->onFinish(); + } + } + + bool hasResult() { + qDebug() << result.typeName(); + return !QString(result.typeName()).isEmpty(); + } + + R *getResult() { + return static_cast(result.data()); + } +}; + +#endif // ASYNC_RESULT_H diff --git a/doric/async/callback.h b/doric/async/callback.h new file mode 100644 index 00000000..767b9eac --- /dev/null +++ b/doric/async/callback.h @@ -0,0 +1,18 @@ +#ifndef CALLBACK_H +#define CALLBACK_H + +#include + +template +class Callback { + +public: + + virtual void onResult(R result) = 0; + + virtual void onError(QException exception) = 0; + + virtual void onFinish() = 0; +}; + +#endif // CALLBACK_H diff --git a/doric/doric.pro b/doric/doric.pro index a523991c..8f61c351 100644 --- a/doric/doric.pro +++ b/doric/doric.pro @@ -42,6 +42,8 @@ else: unix:!android: target.path = /opt/$${TARGET}/bin !isEmpty(target.path): INSTALLS += target HEADERS += \ + async/async_result.h \ + async/callback.h \ constant.h \ context.h \ context_holder.h \ @@ -56,7 +58,5 @@ HEADERS += \ plugin/shader_plugin.h \ registry.h \ shader/layer.h \ - shader/super_node.h \ - shader/view_node.h \ template/singleton.h \ utility/utility.h diff --git a/doric/main.cpp b/doric/main.cpp index 929bf4bc..994626b7 100644 --- a/doric/main.cpp +++ b/doric/main.cpp @@ -4,6 +4,7 @@ #include #include "context_manager.h" +#include "async/async_result.h" int main(int argc, char *argv[]) { @@ -30,5 +31,10 @@ int main(int argc, char *argv[]) delete source; } + QJsonValue *a = new QJsonValue(); + AsyncResult *result = new AsyncResult(*a); + qDebug() << result->hasResult(); + qDebug() << result->getResult(); + return app.exec(); } diff --git a/doric/plugin/shader_plugin.cpp b/doric/plugin/shader_plugin.cpp index 4c383821..2d813bc1 100644 --- a/doric/plugin/shader_plugin.cpp +++ b/doric/plugin/shader_plugin.cpp @@ -1,7 +1,6 @@ #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); + qDebug() << viewId; } diff --git a/doric/shader/layer.h b/doric/shader/layer.h index ad132aff..3bf73497 100644 --- a/doric/shader/layer.h +++ b/doric/shader/layer.h @@ -1,10 +1,33 @@ #ifndef LAYER_H #define LAYER_H -#include "QWidget" +#include +#include class Layer : public QWidget { + void paintEvent(QPaintEvent *event) override { + QPainter painter(this); + QWidget::paintEvent(event); + } + +public: + + void setShadow(int sdColor, int sdOpacity, int sdRadius, int offsetX, int offsetY) { + + } + + void setBorder(int borderWidth, int borderColor) { + + } + + void setCornerRadius(int corner) { + + } + + void setCornerRadius(int leftTop, int rightTop, int rightBottom, int leftBottom) { + + } }; #endif // LAYER_H diff --git a/doric/shader/super_node.h b/doric/shader/super_node.h deleted file mode 100644 index 3cc3bdb5..00000000 --- a/doric/shader/super_node.h +++ /dev/null @@ -1,25 +0,0 @@ -#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 deleted file mode 100644 index 4441c1e3..00000000 --- a/doric/shader/view_node.h +++ /dev/null @@ -1,24 +0,0 @@ -#ifndef VIEW_NODE_H -#define VIEW_NODE_H - -#include - -#include "context_holder.h" - -class SuperNode; - -template -class ViewNode : public ContextHolder { - -protected: - T view; - -private: - SuperNode *superNode; - QString *id; - -public: - ViewNode(Context *context) : ContextHolder(context) {} -}; - -#endif // VIEW_NODE_H