/*! Converts the list of keys \a keys to their combined integer value. \sa isSetType(), valueToKey(), keysToValue() */ int QMetaProperty::keysToValue( const QStrList& keys ) const { if ( !isEnumType() ) return -1; int value = 0; for ( QStrListIterator it( keys ); it.current(); ++it ) { value |= keyToValue( it.current() ); } return value; }
int DesignerMetaFlags::parseFlags(const QString &s, bool *ok) const { if (s.isEmpty()) { if (ok) *ok = true; return 0; } uint flags = 0; bool valueOk = true; QStringList keys = s.split(QString(QLatin1Char('|'))); const QStringList::iterator cend = keys.end(); for (QStringList::iterator it = keys.begin(); it != cend; ++it) { const uint flagValue = keyToValue(*it, &valueOk); if (!valueOk) { flags = 0; break; } flags |= flagValue; } if (ok) *ok = valueOk; return static_cast<int>(flags); }
void QShaderGraphLoader::load() { if (m_status == Error) return; auto error = QJsonParseError(); const auto document = QJsonDocument::fromJson(m_device->readAll(), &error); if (error.error != QJsonParseError::NoError) { qWarning() << "Invalid JSON document:" << error.errorString(); m_status = Error; return; } if (document.isEmpty() || !document.isObject()) { qWarning() << "Invalid JSON document, root should be an object"; m_status = Error; return; } const auto root = document.object(); const auto nodesValue = root.value(QStringLiteral("nodes")); if (!nodesValue.isArray()) { qWarning() << "Invalid nodes property, should be an array"; m_status = Error; return; } const auto edgesValue = root.value(QStringLiteral("edges")); if (!edgesValue.isArray()) { qWarning() << "Invalid edges property, should be an array"; m_status = Error; return; } bool hasError = false; const auto nodes = nodesValue.toArray(); for (const auto &nodeValue : nodes) { if (!nodeValue.isObject()) { qWarning() << "Invalid node found"; hasError = true; continue; } const auto nodeObject = nodeValue.toObject(); const auto uuidString = nodeObject.value(QStringLiteral("uuid")).toString(); const auto uuid = QUuid(uuidString); if (uuid.isNull()) { qWarning() << "Invalid UUID found in node:" << uuidString; hasError = true; continue; } const auto type = nodeObject.value(QStringLiteral("type")).toString(); if (!m_prototypes.contains(type)) { qWarning() << "Unsupported node type found:" << type; hasError = true; continue; } const auto layersArray = nodeObject.value(QStringLiteral("layers")).toArray(); auto layers = QStringList(); for (const auto &layerValue : layersArray) { layers.append(layerValue.toString()); } auto node = m_prototypes.value(type); node.setUuid(uuid); node.setLayers(layers); const auto parametersValue = nodeObject.value(QStringLiteral("parameters")); if (parametersValue.isObject()) { const auto parametersObject = parametersValue.toObject(); for (const auto ¶meterName : parametersObject.keys()) { const auto parameterValue = parametersObject.value(parameterName); if (parameterValue.isObject()) { const auto parameterObject = parameterValue.toObject(); const auto type = parameterObject.value(QStringLiteral("type")).toString(); const auto typeId = QMetaType::type(type.toUtf8()); const auto value = parameterObject.value(QStringLiteral("value")).toString(); auto variant = QVariant(value); if (QMetaType::typeFlags(typeId) & QMetaType::IsEnumeration) { const auto metaObject = QMetaType::metaObjectForType(typeId); const auto className = metaObject->className(); const auto enumName = type.mid(static_cast<int>(qstrlen(className)) + 2).toUtf8(); const auto metaEnum = metaObject->enumerator(metaObject->indexOfEnumerator(enumName)); const auto enumValue = metaEnum.keyToValue(value.toUtf8()); variant = QVariant(enumValue); variant.convert(typeId); } else { variant.convert(typeId); } node.setParameter(parameterName, variant); } else { node.setParameter(parameterName, parameterValue.toVariant()); } } } m_graph.addNode(node); } const auto edges = edgesValue.toArray(); for (const auto &edgeValue : edges) { if (!edgeValue.isObject()) { qWarning() << "Invalid edge found"; hasError = true; continue; } const auto edgeObject = edgeValue.toObject(); const auto sourceUuidString = edgeObject.value(QStringLiteral("sourceUuid")).toString(); const auto sourceUuid = QUuid(sourceUuidString); if (sourceUuid.isNull()) { qWarning() << "Invalid source UUID found in edge:" << sourceUuidString; hasError = true; continue; } const auto sourcePort = edgeObject.value(QStringLiteral("sourcePort")).toString(); const auto targetUuidString = edgeObject.value(QStringLiteral("targetUuid")).toString(); const auto targetUuid = QUuid(targetUuidString); if (targetUuid.isNull()) { qWarning() << "Invalid target UUID found in edge:" << targetUuidString; hasError = true; continue; } const auto targetPort = edgeObject.value(QStringLiteral("targetPort")).toString(); const auto layersArray = edgeObject.value(QStringLiteral("layers")).toArray(); auto layers = QStringList(); for (const auto &layerValue : layersArray) { layers.append(layerValue.toString()); } auto edge = QShaderGraph::Edge(); edge.sourceNodeUuid = sourceUuid; edge.sourcePortName = sourcePort; edge.targetNodeUuid = targetUuid; edge.targetPortName = targetPort; edge.layers = layers; m_graph.addEdge(edge); } if (hasError) { m_status = Error; m_graph = QShaderGraph(); } else { m_status = Ready; } }