Graph loader can load prototypes stored in the graph

Change-Id: Ib0bbfe5b0257bf355e83cc5287fa52b1e0cc3ed6
Reviewed-by: Mike Krus <mike.krus@kdab.com>
Reviewed-by: Sean Harmer <sean.harmer@kdab.com>
This commit is contained in:
Juan Jose Casafranca 2018-09-03 08:50:14 +02:00 committed by Juan José Casafranca
parent be60b541ad
commit 5474f28c42
3 changed files with 22 additions and 2 deletions

View File

@ -39,6 +39,8 @@
#include "qshadergraphloader_p.h"
#include "qshadernodesloader_p.h"
#include <QtCore/qdebug.h>
#include <QtCore/qiodevice.h>
#include <QtCore/qjsonarray.h>
@ -129,6 +131,19 @@ void QShaderGraphLoader::load()
bool hasError = false;
const auto prototypesValue = root.value(QStringLiteral("prototypes"));
if (!prototypesValue.isUndefined()) {
if (prototypesValue.isObject()) {
QShaderNodesLoader loader;
loader.load(prototypesValue.toObject());
m_prototypes.unite(loader.nodes());
} else {
qWarning() << "Invalid prototypes property, should be an object";
m_status = Error;
return;
}
}
const auto nodes = nodesValue.toArray();
for (const auto &nodeValue : nodes) {
if (!nodeValue.isObject()) {

View File

@ -99,11 +99,15 @@ void QShaderNodesLoader::load()
}
const auto root = document.object();
load(root);
}
void QShaderNodesLoader::load(const QJsonObject &prototypesObject)
{
bool hasError = false;
for (const auto &property : root.keys()) {
const auto nodeValue = root.value(property);
for (const auto &property : prototypesObject.keys()) {
const auto nodeValue = prototypesObject.value(property);
if (!nodeValue.isObject()) {
qWarning() << "Invalid node found";
hasError = true;

View File

@ -78,6 +78,7 @@ public:
Q_GUI_EXPORT void setDevice(QIODevice *device) Q_DECL_NOTHROW;
Q_GUI_EXPORT void load();
Q_GUI_EXPORT void load(const QJsonObject &prototypesObject);
private:
Status m_status;