Skip to content

Commit af606cc

Browse files
Graph refactoring (#885)
1 parent 35b5d93 commit af606cc

File tree

11 files changed

+237
-157
lines changed

11 files changed

+237
-157
lines changed

engine/includes/editor/viewport/viewport.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ class ENGINE_EXPORT Viewport : public QWidget {
2121
public:
2222
Viewport(QWidget *parent = 0);
2323

24-
void init();
24+
virtual void init();
2525

2626
CameraController *controllder();
2727
void setController(CameraController *ctrl);
@@ -52,6 +52,8 @@ class ENGINE_EXPORT Viewport : public QWidget {
5252
QWindow *rhiWindow() { return m_rhiWindow; }
5353

5454
public slots:
55+
void onInProgressFlag(bool flag);
56+
5557
void onCursorSet(const QCursor &cursor);
5658
void onCursorUnset();
5759

engine/src/editor/viewport/viewport.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -577,6 +577,8 @@ void Viewport::onDraw() {
577577
return;
578578
}
579579

580+
QString name = objectName();
581+
580582
m_frameInProgress = true; // Recursive call protection
581583

582584
if(m_world && m_liveUpdate) {
@@ -695,6 +697,10 @@ void Viewport::setOutlineEnabled(bool enabled) {
695697
m_outlinePass->setEnabled(enabled);
696698
}
697699

700+
void Viewport::onInProgressFlag(bool flag) {
701+
m_frameInProgress = flag;
702+
}
703+
698704
void Viewport::addRenderTask(PipelineTask *task) {
699705
PipelineContext *pipelineContext = m_renderSystem->pipelineContext();
700706
pipelineContext->insertRenderTask(task, pipelineContext->renderTasks().front());

modules/editor/grapheditor/editor/graph/abstractnodegraph.cpp

Lines changed: 15 additions & 118 deletions
Original file line numberDiff line numberDiff line change
@@ -358,7 +358,10 @@ void AbstractNodeGraph::loadGraphV0(const QVariantMap &data) {
358358
GraphNode *node = nodeCreate(type, index);
359359
if(node) {
360360
node->setPosition(Vector2(n[gOldX].toInt(), n[gOldY].toInt()));
361-
loadUserValues(node, n[gOldValues].toMap());
361+
362+
node->blockSignals(true);
363+
node->loadUserData(n[gOldValues].toMap());
364+
node->blockSignals(false);
362365
}
363366
}
364367

@@ -394,49 +397,7 @@ void AbstractNodeGraph::loadGraphV11(const QDomElement &parent) {
394397
QString type = nodeElement.attribute(gType);
395398
GraphNode *node = nodeCreate(type, index);
396399
if(node) {
397-
node->setPosition(Vector2(nodeElement.attribute(gX).toInt(),
398-
nodeElement.attribute(gY).toInt()));
399-
400-
QVariantMap values;
401-
QDomElement valueElement = nodeElement.firstChildElement("value");
402-
while(!valueElement.isNull()) {
403-
QString type = valueElement.attribute(gType);
404-
QString name = valueElement.attribute(gName);
405-
if(type == "bool") {
406-
values[name] = (valueElement.text() == "true");
407-
} else if(type == "int") {
408-
values[name] = valueElement.text().toInt();
409-
} else if(type == "float") {
410-
values[name] = valueElement.text().toFloat();
411-
} else if(type == "string") {
412-
values[name] = valueElement.text();
413-
} else if(type == "Vector2" || type == "Vector3" || type == "Vector4") {
414-
QVariantList list;
415-
list.push_back(type);
416-
for(auto &it : valueElement.text().split(", ")) {
417-
list.push_back(it.toFloat());
418-
}
419-
values[name] = list;
420-
} else if(type == "Template") {
421-
QVariantList list;
422-
list.push_back(type);
423-
for(auto &it : valueElement.text().split(", ")) {
424-
list.push_back(it);
425-
}
426-
values[name] = list;
427-
} else if(type == "Color") {
428-
QVariantList list;
429-
list.push_back(type);
430-
for(auto &it : valueElement.text().split(", ")) {
431-
list.push_back(it);
432-
}
433-
values[name] = list;
434-
}
435-
436-
valueElement = valueElement.nextSiblingElement();
437-
}
438-
439-
loadUserValues(node, values);
400+
node->fromXml(nodeElement);
440401
}
441402

442403
nodeElement = nodeElement.nextSiblingElement();
@@ -474,58 +435,15 @@ void AbstractNodeGraph::onNodesLoaded() {
474435
void AbstractNodeGraph::saveGraph(QDomElement parent, QDomDocument xml) const {
475436
QDomElement graph = xml.createElement(gGraph);
476437

477-
QVariantList nodes;
478438
QVariantList links;
479439

480-
for(GraphNode *it : qAsConst(m_nodes)) {
481-
nodes.push_back(saveNode(it));
482-
links.append(saveLinks(it));
483-
}
484-
485440
QDomElement nodesElement = xml.createElement(gNodes);
486-
for(auto &node : nodes) {
487-
QDomElement nodeElement = xml.createElement(gNode);
441+
for(auto &node : qAsConst(m_nodes)) {
442+
QDomElement nodeElement = node->toXml(xml);
488443

489-
QVariantMap fields = node.toMap();
490-
for(auto &key : fields.keys()) {
491-
if(key.toLower() == gValues) {
492-
QVariantMap values = fields.value(key).toMap();
493-
494-
for(auto &value : values.keys()) {
495-
QDomElement valueElement = xml.createElement("value");
496-
valueElement.setAttribute(gName, value);
497-
498-
QVariant v = values.value(value);
499-
switch(v.type()) {
500-
case QVariant::List: {
501-
QVariantList list = v.toList();
502-
QString type = list.front().toString();
503-
valueElement.setAttribute(gType, type);
504-
list.pop_front();
505-
QString pack;
506-
for(auto &it : list) {
507-
pack += it.toString() + ", ";
508-
}
509-
pack.resize(pack.size() - 2);
510-
valueElement.appendChild(xml.createTextNode(pack));
511-
} break;
512-
default: {
513-
QString type = v.typeName();
514-
if(type == "QString") {
515-
type = "string";
516-
}
517-
valueElement.setAttribute(gType, type);
518-
valueElement.appendChild(xml.createTextNode(v.toString()));
519-
} break;
520-
}
521-
522-
nodeElement.appendChild(valueElement);
523-
}
524-
} else {
525-
nodeElement.setAttribute(key, fields.value(key).toString());
526-
}
527-
}
528444
nodesElement.appendChild(nodeElement);
445+
446+
links.append(saveLinks(node));
529447
}
530448

531449
QDomElement linksElement = xml.createElement(gLinks);
@@ -546,20 +464,6 @@ void AbstractNodeGraph::saveGraph(QDomElement parent, QDomDocument xml) const {
546464
parent.appendChild(graph);
547465
}
548466

549-
QVariantMap AbstractNodeGraph::saveNode(GraphNode *node) const {
550-
QVariantMap result;
551-
result[gType] = node->typeName().c_str();
552-
result[gX] = (int)node->position().x;
553-
result[gY] = (int)node->position().y;
554-
result[gIndex] = AbstractNodeGraph::node(node);
555-
556-
QVariantMap values;
557-
saveUserValues(node, values);
558-
result[gValues] = values;
559-
560-
return result;
561-
}
562-
563467
QVariantList AbstractNodeGraph::saveLinks(GraphNode *node) const {
564468
QVariantList result;
565469

@@ -598,16 +502,6 @@ void AbstractNodeGraph::reportMessage(GraphNode *node, const QString &text) {
598502
emit messageReported(AbstractNodeGraph::node(node), text);
599503
}
600504

601-
void AbstractNodeGraph::loadUserValues(GraphNode *node, const QVariantMap &values) {
602-
node->blockSignals(true);
603-
node->loadUserData(values);
604-
node->blockSignals(false);
605-
}
606-
607-
void AbstractNodeGraph::saveUserValues(GraphNode *node, QVariantMap &values) const {
608-
node->saveUserData(values);
609-
}
610-
611505
void AbstractNodeGraph::createLink(int sender, int oport, int receiver, int iport) {
612506
UndoManager::instance()->push(new CreateLink(sender, oport, receiver, iport, this));
613507
}
@@ -630,7 +524,7 @@ void AbstractNodeGraph::copyNodes(const std::vector<int32_t> &selection) {
630524
GraphNode *node = m_nodes.at(it);
631525

632526
if(node) {
633-
array.push_back(QJsonValue::fromVariant(saveNode(node)));
527+
array.push_back(QJsonValue::fromVariant(node->toVariant()));
634528
}
635529
}
636530

@@ -718,7 +612,7 @@ void DeleteNodes::redo() {
718612

719613
QVariantList nodes;
720614
for(auto it : list) {
721-
nodes.push_back(m_graph->saveNode(it));
615+
nodes.push_back(it->toVariant());
722616
m_graph->nodeDelete(it);
723617
}
724618

@@ -762,7 +656,10 @@ void PasteNodes::redo () {
762656
int deltaX = maxX - n[gX].toInt();
763657
int deltaY = maxY - n[gY].toInt();
764658
node->setPosition(Vector2(m_x + deltaX, m_y + deltaY));
765-
m_graph->loadUserValues(node, n[gValues].toMap());
659+
660+
node->blockSignals(true);
661+
node->loadUserData(n[gValues].toMap());
662+
node->blockSignals(false);
766663

767664
m_list.push_back(index);
768665
}

modules/editor/grapheditor/editor/graph/abstractnodegraph.h

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -85,10 +85,9 @@ class NODEGRAPH_EXPORT AbstractNodeGraph : public QObject {
8585

8686
void messageReported(int node, const QString &text);
8787

88-
protected:
89-
virtual void loadUserValues(GraphNode *node, const QVariantMap &values);
90-
virtual void saveUserValues(GraphNode *node, QVariantMap &values) const;
88+
void menuVisible(bool visible);
9189

90+
protected:
9291
QVariantMap loadXmlMap(const QDomElement &parent);
9392
QVariantList loadXmlList(const QDomElement &parent);
9493

@@ -99,7 +98,6 @@ class NODEGRAPH_EXPORT AbstractNodeGraph : public QObject {
9998

10099
virtual void saveGraph(QDomElement parent, QDomDocument xml) const;
101100

102-
QVariantMap saveNode(GraphNode *node) const;
103101
QVariantList saveLinks(GraphNode *node) const;
104102

105103
friend class PasteNodes;

0 commit comments

Comments
 (0)