add view node reg; add node create & mix
This commit is contained in:
parent
6371b3fd82
commit
535d21e8c4
@ -1,11 +1,20 @@
|
|||||||
#include "DoricRegistry.h"
|
#include "DoricRegistry.h"
|
||||||
|
|
||||||
#include "plugin/DoricShaderPlugin.h"
|
#include "plugin/DoricShaderPlugin.h"
|
||||||
|
#include "shader/DoricRootNode.h"
|
||||||
|
#include "shader/DoricStackNode.h"
|
||||||
|
|
||||||
DoricRegistry::DoricRegistry() {
|
DoricRegistry::DoricRegistry() {
|
||||||
registerNativePlugin<DoricShaderPlugin>("shader");
|
registerNativePlugin<DoricShaderPlugin>("shader");
|
||||||
|
|
||||||
|
registerViewNode<DoricRootNode>("Root");
|
||||||
|
registerViewNode<DoricStackNode>("Stack");
|
||||||
}
|
}
|
||||||
|
|
||||||
bool DoricRegistry::acquirePluginInfo(QString name) {
|
bool DoricRegistry::acquirePluginInfo(QString name) {
|
||||||
return plugins.acquireClass(name);
|
return plugins.acquireClass(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool DoricRegistry::acquireNodeInfo(QString name) {
|
||||||
|
return nodes.acquireClass(name);
|
||||||
|
}
|
||||||
|
@ -21,6 +21,8 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
bool acquirePluginInfo(QString name);
|
bool acquirePluginInfo(QString name);
|
||||||
|
|
||||||
|
bool acquireNodeInfo(QString name);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // REGISTRY_H
|
#endif // REGISTRY_H
|
||||||
|
@ -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-20T15:28:06. -->
|
<!-- Written by QtCreator 4.14.0, 2021-02-22T16:31:33. -->
|
||||||
<qtcreator>
|
<qtcreator>
|
||||||
<data>
|
<data>
|
||||||
<variable>EnvironmentId</variable>
|
<variable>EnvironmentId</variable>
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
import QtQuick 2.12
|
import QtQuick 2.12
|
||||||
import QtQuick.Controls 2.5
|
import QtQuick.Controls 2.5
|
||||||
|
|
||||||
StackView {
|
Rectangle {
|
||||||
|
color: 'red'
|
||||||
}
|
}
|
||||||
|
@ -29,6 +29,7 @@ void DoricGroupNode::configChildNode() {
|
|||||||
QJSValue model = getSubModel(id);
|
QJSValue model = getSubModel(id);
|
||||||
if (model.isUndefined()) {
|
if (model.isUndefined()) {
|
||||||
DoricRegistry *registry = getContext()->getDriver()->getRegistry();
|
DoricRegistry *registry = getContext()->getDriver()->getRegistry();
|
||||||
|
qCritical() << "model.isUndefined()";
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
QString type = model.property("type").toString();
|
QString type = model.property("type").toString();
|
||||||
@ -37,7 +38,77 @@ void DoricGroupNode::configChildNode() {
|
|||||||
if (id == oldNode->getId()) {
|
if (id == oldNode->getId()) {
|
||||||
// The same, skip
|
// The same, skip
|
||||||
if (mReusable) {
|
if (mReusable) {
|
||||||
|
if (oldNode->getType() == type) {
|
||||||
|
oldNode->setId(id);
|
||||||
|
oldNode->blend(model.property("props"));
|
||||||
|
} else {
|
||||||
|
mChildNodes.remove(idx);
|
||||||
|
oldNode->getNodeView()->setParent(nullptr);
|
||||||
|
oldNode->getNodeView()->setParentItem(nullptr);
|
||||||
|
oldNode->getNodeView()->deleteLater();
|
||||||
|
|
||||||
|
DoricViewNode *newNode = DoricViewNode::create(getContext(), type);
|
||||||
|
if (newNode != nullptr) {
|
||||||
|
newNode->setId(id);
|
||||||
|
newNode->init(this);
|
||||||
|
newNode->blend(model.property("props"));
|
||||||
|
mChildNodes.insert(idx, newNode);
|
||||||
|
|
||||||
|
int minIndex = qMin(idx, mView->childItems().size());
|
||||||
|
newNode->getNodeView()->setParentItem(mView);
|
||||||
|
newNode->getNodeView()->stackBefore(
|
||||||
|
mView->childItems().at(minIndex));
|
||||||
|
}
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
|
// Find in remain nodes
|
||||||
|
int position = -1;
|
||||||
|
for (int start = idx + 1; start < mChildNodes.size(); start++) {
|
||||||
|
DoricViewNode *node = mChildNodes.at(start);
|
||||||
|
if (id == node->getId()) {
|
||||||
|
// Found
|
||||||
|
position = start;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if (position >= 0) {
|
||||||
|
// Found swap idx,position
|
||||||
|
DoricViewNode *reused = mChildNodes.at(position);
|
||||||
|
mChildNodes.removeAt(position);
|
||||||
|
|
||||||
|
DoricViewNode *abandoned = mChildNodes.at(idx);
|
||||||
|
mChildNodes.insert(idx, reused);
|
||||||
|
mChildNodes.insert(position, abandoned);
|
||||||
|
|
||||||
|
// View swap index
|
||||||
|
reused->getNodeView()->setParent(nullptr);
|
||||||
|
reused->getNodeView()->setParentItem(nullptr);
|
||||||
|
int minIndex = qMin(idx, mView->childItems().size());
|
||||||
|
reused->getNodeView()->setParentItem(mView);
|
||||||
|
reused->getNodeView()->stackBefore(
|
||||||
|
mView->childItems().at(minIndex));
|
||||||
|
|
||||||
|
abandoned->getNodeView()->setParent(nullptr);
|
||||||
|
abandoned->getNodeView()->setParentItem(nullptr);
|
||||||
|
abandoned->getNodeView()->setParentItem(mView);
|
||||||
|
abandoned->getNodeView()->stackBefore(
|
||||||
|
mView->childItems().at(position));
|
||||||
|
} else {
|
||||||
|
// Not found,insert
|
||||||
|
DoricViewNode *newNode =
|
||||||
|
DoricViewNode::create(getContext(), type);
|
||||||
|
if (newNode != nullptr) {
|
||||||
|
newNode->setId(id);
|
||||||
|
newNode->init(this);
|
||||||
|
newNode->blend(model.property("props"));
|
||||||
|
mChildNodes.insert(idx, newNode);
|
||||||
|
|
||||||
|
int minIndex = qMin(idx, mView->childItems().size());
|
||||||
|
newNode->getNodeView()->setParentItem(mView);
|
||||||
|
newNode->getNodeView()->stackBefore(
|
||||||
|
mView->childItems().at(minIndex));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
@ -22,7 +22,7 @@ void DoricSuperNode::mixinSubNode(QJSValue subNode) {
|
|||||||
QString id = subNode.property("id").toString();
|
QString id = subNode.property("id").toString();
|
||||||
qCritical() << id;
|
qCritical() << id;
|
||||||
QList<QString> keys = subNodes.keys();
|
QList<QString> keys = subNodes.keys();
|
||||||
if (keys.contains(id)) {
|
if (!keys.contains(id)) {
|
||||||
subNodes.insert(id, subNode);
|
subNodes.insert(id, subNode);
|
||||||
} else {
|
} else {
|
||||||
mixin(subNode, subNodes.value(id));
|
mixin(subNode, subNodes.value(id));
|
||||||
|
@ -21,26 +21,24 @@ QString DoricViewNode::getId() { return mId; }
|
|||||||
|
|
||||||
void DoricViewNode::setId(QString id) { mId = id; }
|
void DoricViewNode::setId(QString id) { mId = id; }
|
||||||
|
|
||||||
|
QString DoricViewNode::getType() { return mType; }
|
||||||
|
|
||||||
|
QQuickItem *DoricViewNode::getNodeView() { return mView; }
|
||||||
|
|
||||||
void DoricViewNode::blend(QJSValue jsValue) {
|
void DoricViewNode::blend(QJSValue jsValue) {
|
||||||
QJSValueIterator it(jsValue);
|
QJSValueIterator it(jsValue);
|
||||||
QMap<QString, QJSValue> values;
|
|
||||||
while (it.hasNext()) {
|
while (it.hasNext()) {
|
||||||
it.next();
|
it.next();
|
||||||
values.insert(it.name(), it.value());
|
blend(mView, it.name(), it.value());
|
||||||
}
|
|
||||||
|
|
||||||
auto keys = values.keys();
|
|
||||||
for (const QString &key : keys) {
|
|
||||||
qCritical() << key << ": " << values.value(key).toString();
|
|
||||||
qCritical() << mView;
|
|
||||||
blend(mView, key, values.value(key));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void DoricViewNode::blend(QQuickItem *view, QString name, QJSValue prop) {
|
void DoricViewNode::blend(QQuickItem *view, QString name, QJSValue prop) {
|
||||||
qCritical() << "view node blend";
|
qCritical() << "view node blend";
|
||||||
if (name == "width") {
|
if (name == "width") {
|
||||||
|
view->setWidth(100);
|
||||||
} else if (name == "height") {
|
} else if (name == "height") {
|
||||||
|
view->setHeight(100);
|
||||||
|
} else if (name == "backgroundColor") {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -29,10 +29,29 @@ public:
|
|||||||
|
|
||||||
void init(DoricSuperNode *superNode);
|
void init(DoricSuperNode *superNode);
|
||||||
|
|
||||||
|
static DoricViewNode *create(DoricContext *context, QString type) {
|
||||||
|
bool classRegistered =
|
||||||
|
context->getDriver()->getRegistry()->acquireNodeInfo(type);
|
||||||
|
if (classRegistered) {
|
||||||
|
QObject *node =
|
||||||
|
context->getDriver()->getRegistry()->nodes.createObject(type);
|
||||||
|
DoricViewNode *castNode = dynamic_cast<DoricViewNode *>(node);
|
||||||
|
castNode->setContext(context);
|
||||||
|
castNode->mType = type;
|
||||||
|
return castNode;
|
||||||
|
} else {
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
QString getId();
|
QString getId();
|
||||||
|
|
||||||
void setId(QString id);
|
void setId(QString id);
|
||||||
|
|
||||||
|
QString getType();
|
||||||
|
|
||||||
|
QQuickItem *getNodeView();
|
||||||
|
|
||||||
virtual void blend(QJSValue jsValue);
|
virtual void blend(QJSValue jsValue);
|
||||||
|
|
||||||
virtual void blend(QQuickItem *view, QString name, QJSValue prop);
|
virtual void blend(QQuickItem *view, QString name, QJSValue prop);
|
||||||
|
Reference in New Issue
Block a user