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);
|
||||
|
||||
QQuickView *view = new QQuickView();
|
||||
{
|
||||
const QUrl url(QStringLiteral("qrc:/doric/qml/view.qml"));
|
||||
view->setSource(url);
|
||||
view->setWidth(450);
|
||||
view->setHeight(800);
|
||||
QColor blue("blue");
|
||||
view->setColor(blue);
|
||||
view->show();
|
||||
}
|
||||
|
||||
DoricPanel *panel = new DoricPanel();
|
||||
panel->setParent(view);
|
||||
panel->setParentItem(view->rootObject());
|
||||
panel->setWidth(450);
|
||||
panel->setHeight(800);
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
@ -1,6 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!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>
|
||||
<data>
|
||||
<variable>EnvironmentId</variable>
|
||||
|
@ -1,13 +1,19 @@
|
||||
#include "DoricShaderPlugin.h"
|
||||
|
||||
#include <QDebug>
|
||||
|
||||
#include "../shader/DoricRootNode.h"
|
||||
#include "DoricShaderPlugin.h"
|
||||
|
||||
void DoricShaderPlugin::render(QJSValue jsValue, QString callbackId) {
|
||||
qDebug() << getContext();
|
||||
getContext()->getDriver()->asyncCall(
|
||||
[this, jsValue] {
|
||||
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);
|
||||
}
|
||||
|
@ -1,8 +1,7 @@
|
||||
<RCC>
|
||||
<qresource prefix="/">
|
||||
<file>main.qml</file>
|
||||
<file>qtquickcontrols2.conf</file>
|
||||
<file>stack.qml</file>
|
||||
<file alias="main.qml">./resources/main.qml</file>
|
||||
<file alias="qtquickcontrols2.conf">./resources/qtquickcontrols2.conf</file>
|
||||
</qresource>
|
||||
<qresource prefix="/doric">
|
||||
<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.es5.js">../../doric-demo/bundle/src/Snake.es5.js</file>
|
||||
</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>
|
||||
|
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() {
|
||||
QQmlComponent component;
|
||||
|
||||
const QUrl url(QStringLiteral("qrc:/stack.qml"));
|
||||
const QUrl url(QStringLiteral("qrc:/doric/qml/stack.qml"));
|
||||
component.loadUrl(url);
|
||||
|
||||
QQuickItem *item = qobject_cast<QQuickItem *>(component.create());
|
||||
|
@ -3,8 +3,7 @@
|
||||
|
||||
#include "DoricGroupNode.h"
|
||||
|
||||
class DoricStackNode : public DoricGroupNode
|
||||
{
|
||||
class DoricStackNode : public DoricGroupNode {
|
||||
public:
|
||||
using DoricGroupNode::DoricGroupNode;
|
||||
|
||||
|
@ -4,11 +4,14 @@
|
||||
#include "DoricViewNode.h"
|
||||
|
||||
class DoricSuperNode : public DoricViewNode {
|
||||
|
||||
protected:
|
||||
void blendSubLayoutConfig(DoricViewNode *viewNode);
|
||||
|
||||
public:
|
||||
using DoricViewNode::DoricViewNode;
|
||||
|
||||
bool mReusable = false;
|
||||
};
|
||||
|
||||
#endif // DORICSUPERNODE_H
|
||||
|
@ -1,5 +1,22 @@
|
||||
#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"
|
||||
|
||||
class DoricSuperNode;
|
||||
|
||||
class DoricViewNode : public DoricContextHolder {
|
||||
|
||||
protected:
|
||||
QQuickItem *mView;
|
||||
|
||||
DoricSuperNode *mSuperNode;
|
||||
|
||||
virtual QQuickItem *build() = 0;
|
||||
|
||||
virtual void blendLayoutConfig();
|
||||
|
||||
void setLayoutConfig(QJSValue layoutConfig);
|
||||
|
||||
private:
|
||||
QString mId;
|
||||
QString mType;
|
||||
|
||||
public:
|
||||
using DoricContextHolder::DoricContextHolder;
|
||||
|
||||
void init(DoricSuperNode *superNode);
|
||||
|
||||
QString getId();
|
||||
|
||||
void setId(QString id);
|
||||
|
||||
void blend(QJSValue jsValue);
|
||||
};
|
||||
#endif // DORICVIEWNODE_H
|
||||
|
@ -20,6 +20,11 @@ public:
|
||||
|
||||
return content;
|
||||
}
|
||||
|
||||
template <typename Base, typename T>
|
||||
static inline bool instanceof (const T *) {
|
||||
return std::is_base_of<Base, T>::value;
|
||||
}
|
||||
};
|
||||
|
||||
#endif // UTILS_H
|
||||
|
Reference in New Issue
Block a user