add quick item to quick view dynamically
This commit is contained in:
parent
df8b98bc6c
commit
7ced952a57
@ -14,17 +14,32 @@ void DoricDemoBridge::navigate(QVariant route) {
|
|||||||
QString script = DoricUtils::readAssetFile("/doric/bundles", name);
|
QString script = DoricUtils::readAssetFile("/doric/bundles", name);
|
||||||
|
|
||||||
QQuickView *view = new QQuickView();
|
QQuickView *view = new QQuickView();
|
||||||
view->setWidth(450);
|
{
|
||||||
view->setHeight(800);
|
const QUrl url(QStringLiteral("qrc:/doric/qml/view.qml"));
|
||||||
QColor blue("blue");
|
view->setSource(url);
|
||||||
view->setColor(blue);
|
view->setWidth(450);
|
||||||
view->show();
|
view->setHeight(800);
|
||||||
|
}
|
||||||
|
|
||||||
DoricPanel *panel = new DoricPanel();
|
DoricPanel *panel = new DoricPanel();
|
||||||
panel->setParent(view);
|
panel->setParentItem(view->rootObject());
|
||||||
panel->setWidth(450);
|
panel->setWidth(450);
|
||||||
panel->setHeight(800);
|
panel->setHeight(800);
|
||||||
panel->config(script, name, NULL);
|
panel->config(script, name, NULL);
|
||||||
|
|
||||||
|
QQmlEngine *engine = view->engine();
|
||||||
|
QQmlComponent component(engine);
|
||||||
|
const QUrl empty(QStringLiteral("qrc:/doric/qml/panel.qml"));
|
||||||
|
component.loadUrl(empty);
|
||||||
|
QQuickItem *childItem = qobject_cast<QQuickItem *>(component.create());
|
||||||
|
|
||||||
|
if (childItem == nullptr) {
|
||||||
|
qCritical() << component.errorString();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
childItem->setParentItem(view->rootObject());
|
||||||
|
|
||||||
|
view->show();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<!DOCTYPE QtCreatorProject>
|
<!DOCTYPE QtCreatorProject>
|
||||||
<!-- Written by QtCreator 4.14.0, 2021-02-19T10:48:54. -->
|
<!-- Written by QtCreator 4.14.0, 2021-02-19T15:04:39. -->
|
||||||
<qtcreator>
|
<qtcreator>
|
||||||
<data>
|
<data>
|
||||||
<variable>EnvironmentId</variable>
|
<variable>EnvironmentId</variable>
|
||||||
|
@ -1,13 +1,19 @@
|
|||||||
#include "DoricShaderPlugin.h"
|
|
||||||
|
|
||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
|
|
||||||
|
#include "../shader/DoricRootNode.h"
|
||||||
|
#include "DoricShaderPlugin.h"
|
||||||
|
|
||||||
void DoricShaderPlugin::render(QJSValue jsValue, QString callbackId) {
|
void DoricShaderPlugin::render(QJSValue jsValue, QString callbackId) {
|
||||||
qDebug() << getContext();
|
qDebug() << getContext();
|
||||||
getContext()->getDriver()->asyncCall(
|
getContext()->getDriver()->asyncCall(
|
||||||
[this, jsValue] {
|
[this, jsValue] {
|
||||||
QString viewId = jsValue.property("id").toString();
|
QString viewId = jsValue.property("id").toString();
|
||||||
getContext()->getDriver();
|
DoricRootNode *rootNode = getContext()->getRootNode();
|
||||||
|
|
||||||
|
if (rootNode->getId().isEmpty() && jsValue.property("type").toString() == "Root") {
|
||||||
|
rootNode->setId(viewId);
|
||||||
|
rootNode->blend(jsValue.property("props"));
|
||||||
|
}
|
||||||
},
|
},
|
||||||
DoricThreadMode::UI);
|
DoricThreadMode::UI);
|
||||||
}
|
}
|
||||||
|
@ -1,8 +1,7 @@
|
|||||||
<RCC>
|
<RCC>
|
||||||
<qresource prefix="/">
|
<qresource prefix="/">
|
||||||
<file>main.qml</file>
|
<file alias="main.qml">./resources/main.qml</file>
|
||||||
<file>qtquickcontrols2.conf</file>
|
<file alias="qtquickcontrols2.conf">./resources/qtquickcontrols2.conf</file>
|
||||||
<file>stack.qml</file>
|
|
||||||
</qresource>
|
</qresource>
|
||||||
<qresource prefix="/doric">
|
<qresource prefix="/doric">
|
||||||
<file alias="doric-sandbox.js">../../doric-js/bundle/doric-sandbox.js</file>
|
<file alias="doric-sandbox.js">../../doric-js/bundle/doric-sandbox.js</file>
|
||||||
@ -14,4 +13,9 @@
|
|||||||
<file alias="Snake.js">../../doric-demo/bundle/src/Snake.js</file>
|
<file alias="Snake.js">../../doric-demo/bundle/src/Snake.js</file>
|
||||||
<file alias="Snake.es5.js">../../doric-demo/bundle/src/Snake.es5.js</file>
|
<file alias="Snake.es5.js">../../doric-demo/bundle/src/Snake.es5.js</file>
|
||||||
</qresource>
|
</qresource>
|
||||||
|
<qresource prefix="/doric/qml">
|
||||||
|
<file alias="view.qml">./resources/view.qml</file>
|
||||||
|
<file alias="panel.qml">./resources/panel.qml</file>
|
||||||
|
<file alias="stack.qml">./resources/stack.qml</file>
|
||||||
|
</qresource>
|
||||||
</RCC>
|
</RCC>
|
||||||
|
8
doric-Qt/doric/resources/panel.qml
Normal file
8
doric-Qt/doric/resources/panel.qml
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
import QtQuick 2.12
|
||||||
|
import QtQuick.Controls 2.5
|
||||||
|
|
||||||
|
Rectangle {
|
||||||
|
width: 100
|
||||||
|
height: 100
|
||||||
|
color: 'red'
|
||||||
|
}
|
6
doric-Qt/doric/resources/view.qml
Normal file
6
doric-Qt/doric/resources/view.qml
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
import QtQuick 2.12
|
||||||
|
import QtQuick.Controls 2.5
|
||||||
|
|
||||||
|
StackView {
|
||||||
|
|
||||||
|
}
|
@ -3,7 +3,7 @@
|
|||||||
QQuickItem *DoricStackNode::build() {
|
QQuickItem *DoricStackNode::build() {
|
||||||
QQmlComponent component;
|
QQmlComponent component;
|
||||||
|
|
||||||
const QUrl url(QStringLiteral("qrc:/stack.qml"));
|
const QUrl url(QStringLiteral("qrc:/doric/qml/stack.qml"));
|
||||||
component.loadUrl(url);
|
component.loadUrl(url);
|
||||||
|
|
||||||
QQuickItem *item = qobject_cast<QQuickItem *>(component.create());
|
QQuickItem *item = qobject_cast<QQuickItem *>(component.create());
|
||||||
|
@ -3,14 +3,13 @@
|
|||||||
|
|
||||||
#include "DoricGroupNode.h"
|
#include "DoricGroupNode.h"
|
||||||
|
|
||||||
class DoricStackNode : public DoricGroupNode
|
class DoricStackNode : public DoricGroupNode {
|
||||||
{
|
|
||||||
public:
|
public:
|
||||||
using DoricGroupNode::DoricGroupNode;
|
using DoricGroupNode::DoricGroupNode;
|
||||||
|
|
||||||
QQuickItem *build() override;
|
QQuickItem *build() override;
|
||||||
|
|
||||||
void blendLayoutConfig() override;
|
void blendLayoutConfig() override;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // DORICSTACKNODE_H
|
#endif // DORICSTACKNODE_H
|
||||||
|
@ -4,11 +4,14 @@
|
|||||||
#include "DoricViewNode.h"
|
#include "DoricViewNode.h"
|
||||||
|
|
||||||
class DoricSuperNode : public DoricViewNode {
|
class DoricSuperNode : public DoricViewNode {
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void blendSubLayoutConfig(DoricViewNode *viewNode);
|
void blendSubLayoutConfig(DoricViewNode *viewNode);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
using DoricViewNode::DoricViewNode;
|
using DoricViewNode::DoricViewNode;
|
||||||
|
|
||||||
|
bool mReusable = false;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // DORICSUPERNODE_H
|
#endif // DORICSUPERNODE_H
|
||||||
|
@ -1,5 +1,22 @@
|
|||||||
#include "DoricViewNode.h"
|
#include "DoricViewNode.h"
|
||||||
|
#include "../utils/DoricUtils.h"
|
||||||
|
#include "DoricSuperNode.h"
|
||||||
|
|
||||||
void DoricViewNode::blendLayoutConfig(){
|
void DoricViewNode::blendLayoutConfig() {}
|
||||||
|
|
||||||
|
void DoricViewNode::setLayoutConfig(QJSValue layoutConfig) {}
|
||||||
|
|
||||||
|
void DoricViewNode::init(DoricSuperNode *superNode) {
|
||||||
|
if (DoricUtils:: instanceof <DoricSuperNode *>(this)) {
|
||||||
|
DoricSuperNode *thiz = dynamic_cast<DoricSuperNode *>(this);
|
||||||
|
thiz->mReusable = superNode->mReusable;
|
||||||
|
}
|
||||||
|
this->mSuperNode = superNode;
|
||||||
|
this->mView = build();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QString DoricViewNode::getId() { return mId; }
|
||||||
|
|
||||||
|
void DoricViewNode::setId(QString id) { mId = id; }
|
||||||
|
|
||||||
|
void DoricViewNode::blend(QJSValue jsValue) { qDebug() << jsValue.toString(); }
|
||||||
|
@ -5,20 +5,34 @@
|
|||||||
|
|
||||||
#include "../utils/DoricContextHolder.h"
|
#include "../utils/DoricContextHolder.h"
|
||||||
|
|
||||||
|
class DoricSuperNode;
|
||||||
|
|
||||||
class DoricViewNode : public DoricContextHolder {
|
class DoricViewNode : public DoricContextHolder {
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
QQuickItem *mView;
|
QQuickItem *mView;
|
||||||
|
|
||||||
|
DoricSuperNode *mSuperNode;
|
||||||
|
|
||||||
virtual QQuickItem *build() = 0;
|
virtual QQuickItem *build() = 0;
|
||||||
|
|
||||||
virtual void blendLayoutConfig();
|
virtual void blendLayoutConfig();
|
||||||
|
|
||||||
|
void setLayoutConfig(QJSValue layoutConfig);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QString mId;
|
QString mId;
|
||||||
QString mType;
|
QString mType;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
using DoricContextHolder::DoricContextHolder;
|
using DoricContextHolder::DoricContextHolder;
|
||||||
|
|
||||||
|
void init(DoricSuperNode *superNode);
|
||||||
|
|
||||||
|
QString getId();
|
||||||
|
|
||||||
|
void setId(QString id);
|
||||||
|
|
||||||
|
void blend(QJSValue jsValue);
|
||||||
};
|
};
|
||||||
#endif // DORICVIEWNODE_H
|
#endif // DORICVIEWNODE_H
|
||||||
|
@ -20,6 +20,11 @@ public:
|
|||||||
|
|
||||||
return content;
|
return content;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template <typename Base, typename T>
|
||||||
|
static inline bool instanceof (const T *) {
|
||||||
|
return std::is_base_of<Base, T>::value;
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // UTILS_H
|
#endif // UTILS_H
|
||||||
|
Reference in New Issue
Block a user