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:
parent
be60b541ad
commit
5474f28c42
@ -39,6 +39,8 @@
|
|||||||
|
|
||||||
#include "qshadergraphloader_p.h"
|
#include "qshadergraphloader_p.h"
|
||||||
|
|
||||||
|
#include "qshadernodesloader_p.h"
|
||||||
|
|
||||||
#include <QtCore/qdebug.h>
|
#include <QtCore/qdebug.h>
|
||||||
#include <QtCore/qiodevice.h>
|
#include <QtCore/qiodevice.h>
|
||||||
#include <QtCore/qjsonarray.h>
|
#include <QtCore/qjsonarray.h>
|
||||||
@ -129,6 +131,19 @@ void QShaderGraphLoader::load()
|
|||||||
|
|
||||||
bool hasError = false;
|
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();
|
const auto nodes = nodesValue.toArray();
|
||||||
for (const auto &nodeValue : nodes) {
|
for (const auto &nodeValue : nodes) {
|
||||||
if (!nodeValue.isObject()) {
|
if (!nodeValue.isObject()) {
|
||||||
|
@ -99,11 +99,15 @@ void QShaderNodesLoader::load()
|
|||||||
}
|
}
|
||||||
|
|
||||||
const auto root = document.object();
|
const auto root = document.object();
|
||||||
|
load(root);
|
||||||
|
}
|
||||||
|
|
||||||
|
void QShaderNodesLoader::load(const QJsonObject &prototypesObject)
|
||||||
|
{
|
||||||
bool hasError = false;
|
bool hasError = false;
|
||||||
|
|
||||||
for (const auto &property : root.keys()) {
|
for (const auto &property : prototypesObject.keys()) {
|
||||||
const auto nodeValue = root.value(property);
|
const auto nodeValue = prototypesObject.value(property);
|
||||||
if (!nodeValue.isObject()) {
|
if (!nodeValue.isObject()) {
|
||||||
qWarning() << "Invalid node found";
|
qWarning() << "Invalid node found";
|
||||||
hasError = true;
|
hasError = true;
|
||||||
|
@ -78,6 +78,7 @@ public:
|
|||||||
Q_GUI_EXPORT void setDevice(QIODevice *device) Q_DECL_NOTHROW;
|
Q_GUI_EXPORT void setDevice(QIODevice *device) Q_DECL_NOTHROW;
|
||||||
|
|
||||||
Q_GUI_EXPORT void load();
|
Q_GUI_EXPORT void load();
|
||||||
|
Q_GUI_EXPORT void load(const QJsonObject &prototypesObject);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Status m_status;
|
Status m_status;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user