From 7e59150831984e91b1eef943b6b473bd310c77f6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=8B=E5=8A=B2=E9=B9=8F?= Date: Fri, 2 Apr 2021 20:47:15 +0800 Subject: [PATCH] snake build on v8 success --- doric-Qt/doric/demo/DoricDemoBridge.cpp | 8 ++-- .../doric/engine/DoricBridgeExtension.cpp | 2 +- doric-Qt/doric/plugin/DoricShaderPlugin.cpp | 11 +++-- doric-Qt/doric/plugin/DoricShaderPlugin.h | 2 +- doric-Qt/doric/qml.qrc | 12 ++--- doric-Qt/doric/resources/main.qml | 8 ++-- doric-Qt/doric/shader/DoricGroupNode.cpp | 27 ++++++----- doric-Qt/doric/shader/DoricGroupNode.h | 6 +-- doric-Qt/doric/shader/DoricHLayoutNode.cpp | 2 +- doric-Qt/doric/shader/DoricHLayoutNode.h | 2 +- doric-Qt/doric/shader/DoricStackNode.cpp | 10 ++-- doric-Qt/doric/shader/DoricStackNode.h | 2 +- doric-Qt/doric/shader/DoricSuperNode.cpp | 39 ++++++++------- doric-Qt/doric/shader/DoricSuperNode.h | 18 ++++--- doric-Qt/doric/shader/DoricTextNode.cpp | 6 +-- doric-Qt/doric/shader/DoricTextNode.h | 2 +- doric-Qt/doric/shader/DoricVLayoutNode.cpp | 2 +- doric-Qt/doric/shader/DoricVLayoutNode.h | 2 +- doric-Qt/doric/shader/DoricViewNode.cpp | 47 +++++++++---------- doric-Qt/doric/shader/DoricViewNode.h | 12 +++-- doric-Qt/doric/utils/DoricConstant.cpp | 4 +- 21 files changed, 119 insertions(+), 105 deletions(-) diff --git a/doric-Qt/doric/demo/DoricDemoBridge.cpp b/doric-Qt/doric/demo/DoricDemoBridge.cpp index 79313892..e70afbb0 100644 --- a/doric-Qt/doric/demo/DoricDemoBridge.cpp +++ b/doric-Qt/doric/demo/DoricDemoBridge.cpp @@ -13,16 +13,16 @@ void DoricDemoBridge::navigate(QVariant route) { QString name; switch (route.toInt()) { case 0: - name = "Counter.es5.js"; + name = "Counter.js"; break; case 1: - name = "Gobang.es5.js"; + name = "Gobang.js"; break; case 2: - name = "SimpleDemo.es5.js"; + name = "SimpleDemo.js"; break; case 3: - name = "Snake.es5.js"; + name = "Snake.js"; break; } QString script = DoricUtils::readAssetFile("/doric/bundles", name); diff --git a/doric-Qt/doric/engine/DoricBridgeExtension.cpp b/doric-Qt/doric/engine/DoricBridgeExtension.cpp index b967b8ec..d5d7cd61 100644 --- a/doric-Qt/doric/engine/DoricBridgeExtension.cpp +++ b/doric-Qt/doric/engine/DoricBridgeExtension.cpp @@ -21,7 +21,7 @@ void DoricBridgeExtension::callNative(QString contextId, QString module, QObject *plugin = context->obtainPlugin(module); QMetaObject::invokeMethod(plugin, methodName.toUtf8(), Qt::DirectConnection, QGenericReturnArgument(), - Q_ARG(QJsonObject, jsValue), + Q_ARG(QJsonObject *, &jsValue), Q_ARG(QString, callbackId)); } qDebug() << "contextId: " + contextId << "module: " + module diff --git a/doric-Qt/doric/plugin/DoricShaderPlugin.cpp b/doric-Qt/doric/plugin/DoricShaderPlugin.cpp index 721390e0..a7a7641e 100644 --- a/doric-Qt/doric/plugin/DoricShaderPlugin.cpp +++ b/doric-Qt/doric/plugin/DoricShaderPlugin.cpp @@ -1,23 +1,24 @@ #include +#include #include "../shader/DoricRootNode.h" #include "DoricShaderPlugin.h" -void DoricShaderPlugin::render(QJSValue jsValue, QString callbackId) { +void DoricShaderPlugin::render(QJsonObject *jsValue, QString callbackId) { getContext()->getDriver()->asyncCall( [this, jsValue] { try { - QString viewId = jsValue.property("id").toString(); + QString viewId = jsValue->value("id").toString(); DoricRootNode *rootNode = getContext()->getRootNode(); if (rootNode->getId().isEmpty() && - jsValue.property("type").toString() == "Root") { + jsValue->value("type").toString() == "Root") { rootNode->setId(viewId); - rootNode->blend(jsValue.property("props")); + rootNode->blend(jsValue->value("props")); } else { DoricViewNode *viewNode = getContext()->targetViewNode(viewId); if (viewNode != nullptr) { - viewNode->blend(jsValue.property("props")); + viewNode->blend(jsValue->value("props")); } } } catch (...) { diff --git a/doric-Qt/doric/plugin/DoricShaderPlugin.h b/doric-Qt/doric/plugin/DoricShaderPlugin.h index 3dd33f90..0bd7f00c 100644 --- a/doric-Qt/doric/plugin/DoricShaderPlugin.h +++ b/doric-Qt/doric/plugin/DoricShaderPlugin.h @@ -11,7 +11,7 @@ class DoricShaderPlugin : public DoricNativePlugin { public: using DoricNativePlugin::DoricNativePlugin; - Q_INVOKABLE void render(QJSValue jsValue, QString callbackId); + Q_INVOKABLE void render(QJsonObject *jsValue, QString callbackId); }; #endif // SHADERPLUGIN_H diff --git a/doric-Qt/doric/qml.qrc b/doric-Qt/doric/qml.qrc index c3930386..4213423f 100644 --- a/doric-Qt/doric/qml.qrc +++ b/doric-Qt/doric/qml.qrc @@ -4,14 +4,14 @@ resources/qtquickcontrols2.conf - ../../doric-js/bundle/doric-sandbox.es5.js - ../../doric-js/bundle/doric-lib.es5.js + ../../doric-js/bundle/doric-sandbox.js + ../../doric-js/bundle/doric-lib.js - ../../doric-demo/bundle/src/Counter.es5.js - ../../doric-demo/bundle/src/Gobang.es5.js - ../../doric-demo/bundle/src/SimpleDemo.es5.js - ../../doric-demo/bundle/src/Snake.es5.js + ../../doric-demo/bundle/src/Counter.js + ../../doric-demo/bundle/src/Gobang.js + ../../doric-demo/bundle/src/SimpleDemo.js + ../../doric-demo/bundle/src/Snake.js resources/Flex.qml diff --git a/doric-Qt/doric/resources/main.qml b/doric-Qt/doric/resources/main.qml index b2b00d8b..a75d0494 100644 --- a/doric-Qt/doric/resources/main.qml +++ b/doric-Qt/doric/resources/main.qml @@ -20,13 +20,13 @@ ApplicationWindow { text: { switch (index) { case 0: - return "Counter.es5.js" + return "Counter.js" case 1: - return "Gobang.es5.js" + return "Gobang.js" case 2: - return "SimpleDemo.es5.js" + return "SimpleDemo.js" case 3: - return "Snake.es5.js" + return "Snake.js" } } } diff --git a/doric-Qt/doric/shader/DoricGroupNode.cpp b/doric-Qt/doric/shader/DoricGroupNode.cpp index 65d26f23..d363cd3f 100644 --- a/doric-Qt/doric/shader/DoricGroupNode.cpp +++ b/doric-Qt/doric/shader/DoricGroupNode.cpp @@ -1,12 +1,13 @@ #include "DoricGroupNode.h" -void DoricGroupNode::blend(QQuickItem *view, QString name, QJSValue prop) { +void DoricGroupNode::blend(QQuickItem *view, QString name, QJsonValue prop) { if (name == "children") { mChildViewIds.clear(); if (prop.isArray()) { - const int length = prop.property("length").toInt(); + QJsonArray array = prop.toArray(); + const int length = array.size(); for (int i = 0; i < length; ++i) { - QJSValue value = prop.property(i); + QJsonValue value = array.at(i); if (value.isString()) { mChildViewIds.append(value.toString()); } @@ -17,7 +18,7 @@ void DoricGroupNode::blend(QQuickItem *view, QString name, QJSValue prop) { } } -void DoricGroupNode::blend(QJSValue jsValue) { +void DoricGroupNode::blend(QJsonValue jsValue) { DoricViewNode::blend(jsValue); configChildNode(); } @@ -31,13 +32,13 @@ void DoricGroupNode::configChildNode() { } for (int idx = 0; idx < mChildViewIds.size(); idx++) { QString id = mChildViewIds.at(idx); - QJSValue model = getSubModel(id); + QJsonValue model = getSubModel(id); if (model.isUndefined()) { DoricRegistry *registry = getContext()->getDriver()->getRegistry(); qCritical() << "model.isUndefined()"; continue; } - QString type = model.property("type").toString(); + QString type = model["type"].toString(); if (idx < mChildNodes.size()) { DoricViewNode *oldNode = mChildNodes.at(idx); if (id == oldNode->getId()) { @@ -47,7 +48,7 @@ void DoricGroupNode::configChildNode() { if (oldNode->getType() == type) { // Same type,can be reused oldNode->setId(id); - oldNode->blend(model.property("props")); + oldNode->blend(model["props"]); } else { // Replace this view mChildNodes.remove(idx); @@ -70,7 +71,7 @@ void DoricGroupNode::configChildNode() { parent->childItems().at(idx)); } - newNode->blend(model.property("props")); + newNode->blend(model["props"]); } } } else { @@ -105,7 +106,7 @@ void DoricGroupNode::configChildNode() { parent->childItems().at(idx)); } - newNode->blend(model.property("props")); + newNode->blend(model["props"]); } } } @@ -126,7 +127,7 @@ void DoricGroupNode::configChildNode() { newNode->getNodeView()->stackBefore(parent->childItems().at(idx)); } - newNode->blend(model.property("props")); + newNode->blend(model["props"]); } } } @@ -141,11 +142,11 @@ void DoricGroupNode::configChildNode() { } } -void DoricGroupNode::blendSubNode(QJSValue subProperties) { - QString subNodeId = subProperties.property("id").toString(); +void DoricGroupNode::blendSubNode(QJsonValue subProperties) { + QString subNodeId = subProperties["id"].toString(); for (DoricViewNode *node : mChildNodes) { if (subNodeId == node->getId()) { - node->blend(subProperties.property("props")); + node->blend(subProperties["props"]); break; } } diff --git a/doric-Qt/doric/shader/DoricGroupNode.h b/doric-Qt/doric/shader/DoricGroupNode.h index 0e4d6315..8d37031a 100644 --- a/doric-Qt/doric/shader/DoricGroupNode.h +++ b/doric-Qt/doric/shader/DoricGroupNode.h @@ -7,9 +7,9 @@ class DoricGroupNode : public DoricSuperNode { public: using DoricSuperNode::DoricSuperNode; - virtual void blend(QQuickItem *view, QString name, QJSValue prop) override; + virtual void blend(QQuickItem *view, QString name, QJsonValue prop) override; - virtual void blend(QJSValue jsValue) override; + virtual void blend(QJsonValue jsValue) override; protected: QList mChildNodes; @@ -18,7 +18,7 @@ protected: void configChildNode(); - virtual void blendSubNode(QJSValue subProperties) override; + virtual void blendSubNode(QJsonValue subProperties) override; }; #endif // DORICGROUPNODE_H diff --git a/doric-Qt/doric/shader/DoricHLayoutNode.cpp b/doric-Qt/doric/shader/DoricHLayoutNode.cpp index d2b00585..00c70f74 100644 --- a/doric-Qt/doric/shader/DoricHLayoutNode.cpp +++ b/doric-Qt/doric/shader/DoricHLayoutNode.cpp @@ -15,7 +15,7 @@ QQuickItem *DoricHLayoutNode::build() { return item; } -void DoricHLayoutNode::blend(QQuickItem *view, QString name, QJSValue prop) { +void DoricHLayoutNode::blend(QQuickItem *view, QString name, QJsonValue prop) { if (name == "space") { view->childItems().at(1)->setProperty("spacing", prop.toInt()); } else if (name == "gravity") { diff --git a/doric-Qt/doric/shader/DoricHLayoutNode.h b/doric-Qt/doric/shader/DoricHLayoutNode.h index a166d8e6..7fdb7ef7 100644 --- a/doric-Qt/doric/shader/DoricHLayoutNode.h +++ b/doric-Qt/doric/shader/DoricHLayoutNode.h @@ -10,7 +10,7 @@ public: QQuickItem *build() override; - virtual void blend(QQuickItem *view, QString name, QJSValue prop) override; + virtual void blend(QQuickItem *view, QString name, QJsonValue prop) override; }; #endif // DORICHLAYOUTNODE_H diff --git a/doric-Qt/doric/shader/DoricStackNode.cpp b/doric-Qt/doric/shader/DoricStackNode.cpp index 70a43229..277e5cdf 100644 --- a/doric-Qt/doric/shader/DoricStackNode.cpp +++ b/doric-Qt/doric/shader/DoricStackNode.cpp @@ -15,12 +15,12 @@ QQuickItem *DoricStackNode::build() { return item; } -void DoricStackNode::blendLayoutConfig(QJSValue jsValue) { +void DoricStackNode::blendLayoutConfig(QJsonValue jsValue) { DoricViewNode::blendLayoutConfig(jsValue); - QJSValue maxWidth = jsValue.property("maxWidth"); - if (maxWidth.isNumber()) { + QJsonValue maxWidth = jsValue["maxWidth"]; + if (maxWidth.isDouble()) { } - QJSValue maxHeight = jsValue.property("maxHeight"); - if (maxHeight.isNumber()) { + QJsonValue maxHeight = jsValue["maxHeight"]; + if (maxHeight.isDouble()) { } } diff --git a/doric-Qt/doric/shader/DoricStackNode.h b/doric-Qt/doric/shader/DoricStackNode.h index c990e82a..4b37203e 100644 --- a/doric-Qt/doric/shader/DoricStackNode.h +++ b/doric-Qt/doric/shader/DoricStackNode.h @@ -9,7 +9,7 @@ public: QQuickItem *build() override; - void blendLayoutConfig(QJSValue jsValue) override; + void blendLayoutConfig(QJsonValue jsValue) override; }; #endif // DORICSTACKNODE_H diff --git a/doric-Qt/doric/shader/DoricSuperNode.cpp b/doric-Qt/doric/shader/DoricSuperNode.cpp index 8a1e8269..f23192da 100644 --- a/doric-Qt/doric/shader/DoricSuperNode.cpp +++ b/doric-Qt/doric/shader/DoricSuperNode.cpp @@ -2,12 +2,13 @@ #include "DoricSuperNode.h" -void DoricSuperNode::blend(QQuickItem *view, QString name, QJSValue prop) { +void DoricSuperNode::blend(QQuickItem *view, QString name, QJsonValue prop) { if (name == "subviews") { if (prop.isArray()) { - const int length = prop.property("length").toInt(); + QJsonArray array = prop.toArray(); + const int length = array.size(); for (int i = 0; i < length; ++i) { - QJSValue subNode = prop.property(i); + QJsonValue subNode = array.at(i); mixinSubNode(subNode); blendSubNode(subNode); } @@ -17,8 +18,8 @@ void DoricSuperNode::blend(QQuickItem *view, QString name, QJSValue prop) { } } -void DoricSuperNode::mixinSubNode(QJSValue subNode) { - QString id = subNode.property("id").toString(); +void DoricSuperNode::mixinSubNode(QJsonValue subNode) { + QString id = subNode["id"].toString(); QList keys = subNodes.keys(); if (!keys.contains(id)) { subNodes.insert(id, subNode); @@ -27,30 +28,36 @@ void DoricSuperNode::mixinSubNode(QJSValue subNode) { } } -void DoricSuperNode::mixin(QJSValue src, QJSValue target) { - QJSValue srcProps = src.property("props"); - QJSValue targetProps = target.property("props"); - QJSValueIterator it(srcProps); - while (it.hasNext()) { - it.next(); +void DoricSuperNode::mixin(QJsonValue src, QJsonValue target) { + QJsonValue srcProps = src["props"]; + QJsonValue targetProps = target["props"]; - if (it.name() == "subviews" && it.value().isArray()) { + foreach (const QString &key, srcProps.toObject().keys()) { + QJsonValue value = srcProps[key]; + if (key == "subviews" && value.isArray()) { } else { - targetProps.setProperty(it.name(), it.value()); + targetProps.toObject().insert(key, value); } } } -QJSValue DoricSuperNode::getSubModel(QString id) { +QJsonValue DoricSuperNode::getSubModel(QString id) { if (subNodes.keys().contains(id)) { return subNodes.value(id); } else { - return QJSValue::UndefinedValue; + return QJsonValue::Undefined; } } void DoricSuperNode::blendSubLayoutConfig(DoricViewNode *viewNode, - QJSValue jsValue) { + QJsonValue jsValue) { viewNode->blendLayoutConfig(jsValue); } + +QJsonValue DoricSuperNode::generateDefaultLayoutConfig() { + QJsonObject layoutConfig; + layoutConfig.insert("widthSpec", 0); + layoutConfig.insert("heightSpec", 0); + return layoutConfig; +} diff --git a/doric-Qt/doric/shader/DoricSuperNode.h b/doric-Qt/doric/shader/DoricSuperNode.h index 22b92d8e..5f3d7754 100644 --- a/doric-Qt/doric/shader/DoricSuperNode.h +++ b/doric-Qt/doric/shader/DoricSuperNode.h @@ -1,30 +1,34 @@ #ifndef DORICSUPERNODE_H #define DORICSUPERNODE_H +#include + #include "DoricViewNode.h" class DoricSuperNode : public DoricViewNode { private: - QMap subNodes; + QMap subNodes; protected: - virtual void blend(QQuickItem *view, QString name, QJSValue prop) override; + virtual void blend(QQuickItem *view, QString name, QJsonValue prop) override; - virtual void blendSubNode(QJSValue subProperties) = 0; + virtual void blendSubNode(QJsonValue subProperties) = 0; public: using DoricViewNode::DoricViewNode; bool mReusable = false; - QJSValue getSubModel(QString id); + QJsonValue getSubModel(QString id); - void blendSubLayoutConfig(DoricViewNode *viewNode, QJSValue jsValue); + void blendSubLayoutConfig(DoricViewNode *viewNode, QJsonValue jsValue); + + QJsonValue generateDefaultLayoutConfig(); private: - void mixinSubNode(QJSValue subNode); + void mixinSubNode(QJsonValue subNode); - void mixin(QJSValue src, QJSValue target); + void mixin(QJsonValue src, QJsonValue target); }; #endif // DORICSUPERNODE_H diff --git a/doric-Qt/doric/shader/DoricTextNode.cpp b/doric-Qt/doric/shader/DoricTextNode.cpp index 8e3a8737..d6287565 100644 --- a/doric-Qt/doric/shader/DoricTextNode.cpp +++ b/doric-Qt/doric/shader/DoricTextNode.cpp @@ -16,15 +16,15 @@ QQuickItem *DoricTextNode::build() { return item; } -void DoricTextNode::blend(QQuickItem *view, QString name, QJSValue prop) { +void DoricTextNode::blend(QQuickItem *view, QString name, QJsonValue prop) { if (name == "text") { view->childItems().at(0)->setProperty("text", prop.toString()); } else if (name == "textColor") { - QString color = DoricUtils::doricColor(prop.toNumber()).name(); + QString color = DoricUtils::doricColor(prop.toInt()).name(); view->childItems().at(0)->setProperty("color", color); } else if (name == "textSize") { QFont font = view->childItems().at(0)->property("font").value(); - font.setPixelSize(prop.toNumber()); + font.setPixelSize(prop.toInt()); view->childItems().at(0)->setProperty("font", QVariant(font)); } else if (name == "textAlignment") { view->childItems().at(0)->setProperty("textAlignment", prop.toInt()); diff --git a/doric-Qt/doric/shader/DoricTextNode.h b/doric-Qt/doric/shader/DoricTextNode.h index c53bf714..19c0ab3e 100644 --- a/doric-Qt/doric/shader/DoricTextNode.h +++ b/doric-Qt/doric/shader/DoricTextNode.h @@ -9,7 +9,7 @@ public: QQuickItem *build() override; - virtual void blend(QQuickItem *view, QString name, QJSValue prop) override; + virtual void blend(QQuickItem *view, QString name, QJsonValue prop) override; }; #endif // DORICTEXTNODE_H diff --git a/doric-Qt/doric/shader/DoricVLayoutNode.cpp b/doric-Qt/doric/shader/DoricVLayoutNode.cpp index bd79d4ec..98f1e63f 100644 --- a/doric-Qt/doric/shader/DoricVLayoutNode.cpp +++ b/doric-Qt/doric/shader/DoricVLayoutNode.cpp @@ -15,7 +15,7 @@ QQuickItem *DoricVLayoutNode::build() { return item; } -void DoricVLayoutNode::blend(QQuickItem *view, QString name, QJSValue prop) { +void DoricVLayoutNode::blend(QQuickItem *view, QString name, QJsonValue prop) { if (name == "space") { view->childItems().at(1)->setProperty("spacing", prop.toInt()); } else if (name == "gravity") { diff --git a/doric-Qt/doric/shader/DoricVLayoutNode.h b/doric-Qt/doric/shader/DoricVLayoutNode.h index b6055b22..8b21d601 100644 --- a/doric-Qt/doric/shader/DoricVLayoutNode.h +++ b/doric-Qt/doric/shader/DoricVLayoutNode.h @@ -9,7 +9,7 @@ public: QQuickItem *build() override; - virtual void blend(QQuickItem *view, QString name, QJSValue prop) override; + virtual void blend(QQuickItem *view, QString name, QJsonValue prop) override; }; #endif // DORICVLAYOUTNODE_H diff --git a/doric-Qt/doric/shader/DoricViewNode.cpp b/doric-Qt/doric/shader/DoricViewNode.cpp index 0731180e..5527d3b8 100644 --- a/doric-Qt/doric/shader/DoricViewNode.cpp +++ b/doric-Qt/doric/shader/DoricViewNode.cpp @@ -1,18 +1,16 @@ -#include - +#include "DoricViewNode.h" #include "../utils/DoricConstant.h" #include "../utils/DoricUtils.h" #include "DoricSuperNode.h" -#include "DoricViewNode.h" -void DoricViewNode::blendLayoutConfig(QJSValue jsObject) { +void DoricViewNode::blendLayoutConfig(QJsonValue jsObject) { this->mLayoutConfig = jsObject; - QJSValue margin = jsObject.property("margin"); - QJSValue widthSpec = jsObject.property("widthSpec"); - QJSValue heightSpec = jsObject.property("heightSpec"); + QJsonValue margin = jsObject["margin"]; + QJsonValue widthSpec = jsObject["widthSpec"]; + QJsonValue heightSpec = jsObject["heightSpec"]; - if (widthSpec.isNumber()) { + if (widthSpec.isDouble()) { switch (widthSpec.toInt()) { case 0: mView->setProperty("widthSpec", 0); @@ -26,7 +24,7 @@ void DoricViewNode::blendLayoutConfig(QJSValue jsObject) { } } - if (heightSpec.isNumber()) { + if (heightSpec.isDouble()) { switch (heightSpec.toInt()) { case 0: mView->setProperty("heightSpec", 0); @@ -41,7 +39,7 @@ void DoricViewNode::blendLayoutConfig(QJSValue jsObject) { } } -void DoricViewNode::setLayoutConfig(QJSValue layoutConfig) { +void DoricViewNode::setLayoutConfig(QJsonValue layoutConfig) { if (mSuperNode != nullptr) { mSuperNode->blendSubLayoutConfig(this, layoutConfig); } else { @@ -55,6 +53,7 @@ void DoricViewNode::init(DoricSuperNode *superNode) { thiz->mReusable = superNode->mReusable; } this->mSuperNode = superNode; + this->mLayoutConfig = superNode->generateDefaultLayoutConfig(); this->mView = build(); } @@ -66,49 +65,49 @@ QString DoricViewNode::getType() { return mType; } QQuickItem *DoricViewNode::getNodeView() { return mView; } -void DoricViewNode::blend(QJSValue jsValue) { - QJSValue value = jsValue.property("layoutConfig"); +void DoricViewNode::blend(QJsonValue jsValue) { + QJsonValue value = jsValue["layoutConfig"]; if (value.isObject()) { setLayoutConfig(value); } - QJSValueIterator it(jsValue); - while (it.hasNext()) { - it.next(); - blend(mView, it.name(), it.value()); + + foreach (const QString &key, jsValue.toObject().keys()) { + QJsonValue value = jsValue[key]; + blend(mView, key, value); } } -void DoricViewNode::blend(QQuickItem *view, QString name, QJSValue prop) { +void DoricViewNode::blend(QQuickItem *view, QString name, QJsonValue prop) { if (name == "width") { - if (!prop.isNumber()) { + if (!prop.isDouble()) { return; } if (this->mLayoutConfig.isUndefined()) { view->setWidth(prop.toInt()); } else { - QJSValue widthSpec = this->mLayoutConfig.property("widthSpec"); - if (widthSpec.isNumber()) { + QJsonValue widthSpec = this->mLayoutConfig["widthSpec"]; + if (widthSpec.isDouble()) { if (widthSpec.toInt() == 0) { view->setWidth(prop.toInt()); } } } } else if (name == "height") { - if (!prop.isNumber()) { + if (!prop.isDouble()) { return; } if (this->mLayoutConfig.isUndefined()) { view->setHeight(prop.toInt()); } else { - QJSValue heightSpec = this->mLayoutConfig.property("heightSpec"); - if (heightSpec.isNumber()) { + QJsonValue heightSpec = this->mLayoutConfig["heightSpec"]; + if (heightSpec.isDouble()) { if (heightSpec.toInt() == 0) { view->setHeight(prop.toInt()); } } } } else if (name == "backgroundColor") { - QString color = DoricUtils::doricColor(prop.toNumber()).name(); + QString color = DoricUtils::doricColor(prop.toInt()).name(); view->setProperty("color", color); } else if (name == "x") { view->setProperty("x", prop.toInt()); diff --git a/doric-Qt/doric/shader/DoricViewNode.h b/doric-Qt/doric/shader/DoricViewNode.h index d5d720db..f2c2fae8 100644 --- a/doric-Qt/doric/shader/DoricViewNode.h +++ b/doric-Qt/doric/shader/DoricViewNode.h @@ -2,6 +2,8 @@ #define DORICVIEWNODE_H #include +#include +#include #include "../utils/DoricContextHolder.h" @@ -16,12 +18,12 @@ protected: virtual QQuickItem *build() = 0; - void setLayoutConfig(QJSValue layoutConfig); + void setLayoutConfig(QJsonValue layoutConfig); private: QString mId; - QJSValue mLayoutConfig; + QJsonValue mLayoutConfig; QList getIdList(); @@ -57,11 +59,11 @@ public: QQuickItem *getNodeView(); - virtual void blend(QJSValue jsValue); + virtual void blend(QJsonValue jsValue); - virtual void blend(QQuickItem *view, QString name, QJSValue prop); + virtual void blend(QQuickItem *view, QString name, QJsonValue prop); - virtual void blendLayoutConfig(QJSValue jsObject); + virtual void blendLayoutConfig(QJsonValue jsObject); void onClick(); diff --git a/doric-Qt/doric/utils/DoricConstant.cpp b/doric-Qt/doric/utils/DoricConstant.cpp index 926d39a2..d36cf750 100644 --- a/doric-Qt/doric/utils/DoricConstant.cpp +++ b/doric-Qt/doric/utils/DoricConstant.cpp @@ -1,7 +1,7 @@ #include "DoricConstant.h" -const QString DoricConstant::DORIC_BUNDLE_SANDBOX = "doric-sandbox.es5.js"; -const QString DoricConstant::DORIC_BUNDLE_LIB = "doric-lib.es5.js"; +const QString DoricConstant::DORIC_BUNDLE_SANDBOX = "doric-sandbox.js"; +const QString DoricConstant::DORIC_BUNDLE_LIB = "doric-lib.js"; const QString DoricConstant::DORIC_MODULE_LIB = "doric"; const QString DoricConstant::INJECT_ENVIRONMENT = "Environment";