bool CashPointInRadius::fromJson(const QJsonObject &json) { const QJsonValue radius = json["radius"]; const QJsonValue latitude = json["latitude"]; const QJsonValue longitude = json["longitude"]; const QJsonValue filter = json["filter"]; const QJsonValue topLeft = json["topLeft"]; const QJsonValue botRight = json["bottomRight"]; if (!radius.isDouble() || !latitude.isDouble() || !longitude.isDouble() || !(filter.isObject() || filter.isUndefined())) { return false; } if (!topLeft.isObject() || !botRight.isObject()) { return false; } data["longitude"] = longitude; data["latitude"] = latitude; data["radius"] = radius; data["topLeft"] = topLeft; data["bottomRight"] = botRight; if (filter.isObject()) { data["filter"] = filter; } return true; }
QStringList JSONBreakableMarshal::toStringList(const QJsonValue& jsonValue, const QString& keypath) { // setup the string list that will hold our result QStringList result; // figure out what type of value this is so we know how to act on it if (jsonValue.isObject()) { QJsonObject jsonObject = jsonValue.toObject(); // enumerate the keys of the QJsonObject foreach(const QString& key, jsonObject.keys()) { QJsonValue childValue = jsonObject[key]; // setup the keypath for this key QString valueKeypath = (keypath.isEmpty() ? "" : keypath + ".") + key; if (childValue.isObject() || childValue.isArray()) { // recursion is required since the value is a QJsonObject or QJsonArray result << toStringList(childValue, valueKeypath); } else { // no recursion required, call our toString method to get the string representation // append the QStringList resulting from that to our QStringList result << toString(childValue, valueKeypath); } } } else if (jsonValue.isArray()) {
Schema *MessageFacade::defineSchema(QJsonObject *root, ControllerNode *pControllerNode){ QJsonValue jsonValue = root->value(SCHEMA); if (!jsonValue.isUndefined() && jsonValue.isObject()){ QJsonObject schema= jsonValue.toObject(); QJsonValue strings =schema.value(STRING_TYPE); QJsonValue ints =schema.value(INT_TYPE); QJsonValue primaryKey = schema.value(PRIMARY_KEY); if (!strings.isUndefined() && strings.isArray() &&!ints.isUndefined() && ints.isArray() && !primaryKey.isUndefined() && primaryKey.isObject()){ QJsonArray columnaStringType = strings.toArray(); QJsonArray columnaIntsType = ints.toArray(); QJsonObject columnaPrimaryKey = primaryKey.toObject(); bool success = true; QJsonObject currentObject; for (int x = 0; x < columnaStringType.size(); x++){ currentObject =columnaStringType.at(x).toObject(); success = success && currentObject.value(currentObject.keys().at(0)).isDouble(); } for (int x = 0; x < columnaIntsType.size(); x++)success = success && columnaIntsType.at(x).isString(); QString primaryKeyName =columnaPrimaryKey.keys().at(0); qDebug() << "validando...."; if (success && validatingPrimaryKey(primaryKeyName,&columnaPrimaryKey)){ qDebug() << "validacion completa el JSON es valido"; Schema *dataSchema = StorageblockFacade::getInstance()->createSchema(1+columnaIntsType.size()+columnaStringType.size()); unsigned int sizeOfBytes = 0; QJsonObject primaryKeyScheme; primaryKeyScheme = columnaPrimaryKey.value(primaryKeyName).toObject(); if (primaryKeyName.compare(INT_TYPE) == 0)sizeOfBytes = sizeof(int); else sizeOfBytes = primaryKeyScheme.value(primaryKeyScheme.keys().at(0)).toInt()*sizeof(char); dataSchema->setSchemaOverColumn(0,primaryKeyScheme.keys().at(0).toStdString(),sizeOfBytes, (primaryKeyName.compare(INT_TYPE) == 0)?SchemeRow::INT_TYPE:SchemeRow::STRING_TYPE); int place= 1; for (int x = 0; x < columnaIntsType.size(); x++){ currentObject =columnaIntsType.at(x).toObject(); dataSchema->setSchemaOverColumn(x+(place++),columnaIntsType.at(x).toString().toStdString(),sizeof(int),SchemeRow::INT_TYPE); } for (int x = 0; x < columnaStringType.size(); x++){ currentObject =columnaStringType.at(x).toObject(); currentObject.value(currentObject.keys().at(0)).toString(); dataSchema->setSchemaOverColumn(x+place,currentObject.keys().at(0).toStdString(),sizeof(char)*currentObject.value(currentObject.keys().at(0)).toInt(),SchemeRow::STRING_TYPE); } SchemeRow row; QString type; for(int x = 0; x < dataSchema->getLenght();x++){ row = (*dataSchema)[x]; type= (row.getTypeRestrictor()==SchemeRow::INT_TYPE)?"int ":"string"; qDebug() << "| type: "<< type<< "\t| name: " << row.toString().c_str() << "\t\t| size: \t"<< row.getByteSize(); } return dataSchema; } } } return 0; }
Nuria::JsonMetaObjectReader::Error Nuria::JsonMetaObjectReader::parse (const QJsonObject &root) { Error error = NoError; auto it = root.constBegin (); auto end = root.constEnd (); for (; it != end && error == NoError; ++it) { QString fileName = it.key (); QJsonValue fileValue = *it; MetaObjectMap metaObjectMap; if (!fileValue.isObject ()) { error = FileIsNotAnObject; break; } error = parseTypesObject (fileValue.toObject (), metaObjectMap); // Store this->d_ptr->objects.insert (fileName, metaObjectMap); } // if (error != NoError) { this->d_ptr->clearData (); } return error; }
//==== SYSCACHE ==== RestOutputStruct::ExitCode WebSocket::EvaluateSyscacheRequest(const QJsonValue in_args, QJsonObject *out){ //syscache only needs a list of sub-commands at the moment (might change later) QStringList in_req; //Parse the input arguments structure if(in_args.isArray()){ in_req = JsonArrayToStringList(in_args.toArray()); } else if(in_args.isObject()){ QStringList keys = in_args.toObject().keys(); for(int i=0; i<keys.length(); i++){ in_req << JsonValueToString(in_args.toObject().value(keys[i])); } }else{ return RestOutputStruct::BADREQUEST; } //Run the Request (should be one value for each in_req) QStringList values = SysCacheClient::parseInputs(in_req); while(values.length() < in_req.length()){ values << "[ERROR]"; } //ensure lists are same length //Format the result for(int i=0; i<values.length(); i++){ if(values[i].contains(SCLISTDELIM)){ //This is an array of values from syscache QStringList vals = values[i].split(SCLISTDELIM); vals.removeAll(""); QJsonArray arr; for(int j=0; j<vals.length(); j++){ arr.append(vals[j]); } out->insert(in_req[i],arr); }else{ out->insert(in_req[i],values[i]); } } //Return Success return RestOutputStruct::OK; }
static Nuria::JsonMetaObjectReader::Error parseEnumObject (const QString &name, const QJsonObject &enumObj, Nuria::RuntimeMetaObject *metaObject) { using namespace Nuria; QJsonValue annotationsValue = enumObj.value (QStringLiteral("annotations")); QJsonValue valuesValue = enumObj.value (QStringLiteral("values")); // Type check if (!annotationsValue.isArray ()) return JsonMetaObjectReader::AnnotationsIsNotAnArray; if (!valuesValue.isObject ()) return JsonMetaObjectReader::EnumValuesIsNotAnObject; // Parse annotations JsonMetaObjectReader::Error error; RuntimeMetaObject::AnnotationMap annotations; error = parseAnnotationsArray (annotationsValue.toArray (), annotations); if (error != JsonMetaObjectReader::NoError) return error; // Parse values QMap< QByteArray, int > keyValueMap; error = parseEnumValues (valuesValue.toObject (), keyValueMap); if (error != JsonMetaObjectReader::NoError) return error; // Store and done. metaObject->addEnum (name.toLatin1 (), annotations, keyValueMap); return JsonMetaObjectReader::NoError; }
bool QJsonValueProto::isObject() const { QJsonValue *item = qscriptvalue_cast<QJsonValue*>(thisObject()); if (item) return item->isObject(); return false; }
void initSwitchValue(const QJsonObject &object, const QLatin1String &keyName, SwitcherConfig::SwitchValue &value) { value.m_IsOn = false; value.m_Threshold = 0; QJsonValue propertiesObjectValue = object[keyName]; if (propertiesObjectValue.isObject()) { QJsonObject propertiesObject = propertiesObjectValue.toObject(); bool switchValue = false; if (tryGetBool(propertiesObject, VALUE_KEY, switchValue)) { value.m_IsOn = switchValue; } double threshold = 0.0; if (tryGetThresholdValue(propertiesObject, threshold)) { int intThreshold = (int)threshold; Q_ASSERT((0 <= intThreshold) && (intThreshold <= 100)); if ((0 <= intThreshold) && (intThreshold <= 100)) { value.m_Threshold = intThreshold; } } else { // allowed by default value.m_Threshold = 100; } } }
QMap<QString, QMap<QString, QString>> Info::getServiceServerAddressMeta() { QString filename = getAddressMetaFilename(); QByteArray json("[]"); if(Filesystem::fileExist(filename)){ json = Filesystem::fileGetContents(filename); } QJsonParseError parserError; QJsonDocument doc = QJsonDocument::fromJson(json, &parserError); QMap<QString, QMap<QString, QString>> ret; if(parserError.error == QJsonParseError::NoError){ QJsonArray array = doc.array(); QJsonArray::const_iterator ait = array.constBegin(); QJsonArray::const_iterator aendmarker = array.constEnd(); while(ait != aendmarker){ QJsonValue v = *ait; if(v.isObject()){ QJsonObject item = v.toObject(); QJsonObject::const_iterator oit = item.constBegin(); QJsonObject::const_iterator oendmarker = item.constEnd(); QMap<QString, QString> dataItem; while(oit != oendmarker){ dataItem.insert(oit.key(), oit.value().toString()); oit++; } ret.insert(dataItem.value("key"), dataItem); } ait++; } } return ret; }
JsonObject JsonObject::object(const QString& key) const { checkContains(key); QJsonValue value = o.value(key); if ( ! value.isObject()) wrongType("object", key); return JsonObject(value.toObject()); }
bool Parser::ParseGoodsMap(const QString &str, QHash<QString, Goods *> &pGoodsMap) { QJsonDocument doc = QJsonDocument::fromJson(str.toUtf8()); if (doc.isNull()) { return false; } // json array containing all goods info QJsonArray jGoodsArray = doc.array(); if (jGoodsArray.isEmpty()) { // no goods info or error json data return false; } // parse each goods info for (int i = 0; i < jGoodsArray.size(); ++i) { QJsonValue jValue = jGoodsArray.at(i); if (jValue.isObject()) { QJsonObject jGoods = jValue.toObject(); // json of goods info // get goods info Goods *pGoods = ParseGoods(jGoods); if (pGoods) { pGoodsMap.insert(pGoods->GetBarcode(), pGoods); } } } return (pGoodsMap.size() > 0); }
//==== SYSADM -- Update ==== RestOutputStruct::ExitCode WebSocket::EvaluateSysadmUpdateRequest(const QJsonValue in_args, QJsonObject *out){ if(in_args.isObject()){ QStringList keys = in_args.toObject().keys(); bool ok = false; if(keys.contains("action")){ QString act = JsonValueToString(in_args.toObject().value("action")); if(act=="checkupdates"){ ok = true; out->insert("checkupdates", sysadm::Update::checkUpdates()); } if(act=="listbranches"){ ok = true; out->insert("listbranches", sysadm::Update::listBranches()); } } //end of "action" key usage //If nothing done - return the proper code if(!ok){ return RestOutputStruct::BADREQUEST; } }else{ // if(in_args.isArray()){ return RestOutputStruct::BADREQUEST; } return RestOutputStruct::OK; }
AnimNode::Pointer AnimNodeLoader::load(const QByteArray& contents, const QUrl& jsonUrl) { // convert string into a json doc QJsonParseError error; auto doc = QJsonDocument::fromJson(contents, &error); if (error.error != QJsonParseError::NoError) { qCCritical(animation) << "AnimNodeLoader, failed to parse json, error =" << error.errorString(); return nullptr; } QJsonObject obj = doc.object(); // version QJsonValue versionVal = obj.value("version"); if (!versionVal.isString()) { qCCritical(animation) << "AnimNodeLoader, bad string \"version\""; return nullptr; } QString version = versionVal.toString(); // check version // AJT: TODO version check if (version != "1.0" && version != "1.1") { qCCritical(animation) << "AnimNodeLoader, bad version number" << version << "expected \"1.0\""; return nullptr; } // root QJsonValue rootVal = obj.value("root"); if (!rootVal.isObject()) { qCCritical(animation) << "AnimNodeLoader, bad object \"root\""; return nullptr; } return loadNode(rootVal.toObject(), jsonUrl); }
void DomainServerSettingsManager::recurseJSONObjectAndOverwriteSettings(const QJsonObject& postedObject, QVariantMap& settingsVariant, QJsonObject descriptionObject) { foreach(const QString& key, postedObject.keys()) { QJsonValue rootValue = postedObject[key]; // we don't continue if this key is not present in our descriptionObject if (descriptionObject.contains(key)) { if (rootValue.isString()) { settingsVariant[key] = rootValue.toString(); } else if (rootValue.isBool()) { settingsVariant[key] = rootValue.toBool(); } else if (rootValue.isObject()) { // there's a JSON Object to explore, so attempt to recurse into it QJsonObject nextDescriptionObject = descriptionObject[key].toObject(); if (nextDescriptionObject.contains(DESCRIPTION_SETTINGS_KEY)) { if (!settingsVariant.contains(key)) { // we don't have a map below this key yet, so set it up now settingsVariant[key] = QVariantMap(); } recurseJSONObjectAndOverwriteSettings(rootValue.toObject(), *reinterpret_cast<QVariantMap*>(settingsVariant[key].data()), nextDescriptionObject[DESCRIPTION_SETTINGS_KEY].toObject()); } } } } }
//==== SYSADM -- iocage ==== RestOutputStruct::ExitCode WebSocket::EvaluateSysadmIocageRequest(const QJsonValue in_args, QJsonObject *out){ if(in_args.isObject()){ QStringList keys = in_args.toObject().keys(); bool ok = false; if(keys.contains("action")){ QString act = JsonValueToString(in_args.toObject().value("action")); if(act=="getdefaultsettings"){ ok = true; out->insert("getdefaultsettings", sysadm::Iocage::getDefaultSettings()); } if(act=="getjailsettings"){ ok = true; out->insert("getjailsettings", sysadm::Iocage::getJailSettings(in_args.toObject())); } if(act=="listjails"){ ok = true; out->insert("listjails", sysadm::Iocage::listJails()); } } //end of "action" key usage //If nothing done - return the proper code if(!ok){ return RestOutputStruct::BADREQUEST; } }else{ // if(in_args.isArray()){ return RestOutputStruct::BADREQUEST; } return RestOutputStruct::OK; }
bool RuleListModel::realDeserializeData() { QSettings setting("Ray Fung", "Excel JSON"); QByteArray json = setting.value("rule_list", QByteArray("[]")).toByteArray(); QJsonDocument doc = QJsonDocument::fromJson(json); ruleList.clear(); if(doc.isArray() == false) return false; QJsonArray array = doc.array(); int count = array.size(); for(int i = 0; i < count; ++i) { QJsonValue val = array.at(i); if(val.isObject() == false) return false; QJsonObject data = val.toObject(); RuleData rule; RuleItem item; rule.isEnabled = data.value("enable").toBool(true); rule.excelPath = data.value("excel_path").toString(); rule.jsonPath = data.value("json_path").toString(); item.setRule(rule); ruleList.append(item); } return true; }
bool Parser::ParseOfferMap(const QString &str, QHash<QString, ItemOffer *> &pOfferMap, const QHash<QString, Goods *> &pGoodsMap) { QJsonDocument doc = QJsonDocument::fromJson(str.toUtf8()); if (doc.isNull()) { return false; } // json array containing all offer info QJsonArray jOfferArray = doc.array(); if (jOfferArray.isEmpty()) { // no offer info or error json data return false; } // parse each offer info for (int i = 0; i < jOfferArray.size(); ++i) { QJsonValue jValue = jOfferArray.at(i); if (jValue.isObject()) { QJsonObject jOffer = jValue.toObject(); // json of offer info // get offer info ItemOffer *pOffer = ParseOffer(jOffer, pGoodsMap); if (pOffer) { pOfferMap.insert(pOffer->GetType(), pOffer); } } } return (pOfferMap.size() > 0); }
void protoObject::fromJSON(QJsonObject &obj) { //TODO: internal id check //qDebug() << obj; QMap<QString, QMap<int, protoObject* >* > bufferMap; QMap<int, protoObject* >* tmp_bufferMap; int length = obj.size(); int i; protoObject* tmp_obj; QStringList keys = obj.keys(); QJsonValue value; QJsonObject json_obj; QJsonObject json_info; for (i = 0; i < length; i++) { value = obj.value(keys.at(i)); if (value.isArray()) { QJsonArray tmp_arr = value.toArray(); QList< QSharedPointer<protoObject> > list; int length = tmp_arr.count(), j; for (j = 0; j < length; j++) { tmp_obj = new protoObject(this); value = tmp_arr.at(j); if (value.isObject()) { json_obj = value.toObject(); tmp_obj->fromJSON(json_obj); }; list.append(QSharedPointer<protoObject >(tmp_obj)); }; qDebug() << list; this->setProperty(keys.at(i).toLatin1(), QVariant::fromValue(list)); }; if (value.isObject()) { tmp_obj = new protoObject(this); json_obj = value.toObject(); tmp_obj->fromJSON(json_obj); QVariant variant = QVariant::fromValue(QSharedPointer<protoObject>(tmp_obj)); this->setProperty(keys.at(i).toLatin1(), variant); }; if (value.isString()) this->setProperty(keys.at(i).toLatin1(), value.toString()); if (value.isDouble()) this->setProperty(keys.at(i).toLatin1(), value.toDouble()); if (value.isBool()) this->setProperty(keys.at(i).toLatin1(), value.toBool()); }; }
bool PulseFilter::parseParameters(const QJsonValue& parameters) { static const QString JSON_INTERVAL = QStringLiteral("interval"); static const QString JSON_RESET = QStringLiteral("resetOnZero"); if (parameters.isObject()) { auto obj = parameters.toObject(); if (obj.contains(JSON_RESET)) { _resetOnZero = obj[JSON_RESET].toBool(); } } return parseSingleFloatParameter(parameters, JSON_INTERVAL, _interval); }
bool mergeJsonObjects (const QJsonObject &objectMergeFrom, QJsonObject &objectMergeTo, CompareValuesJson &comparer) { LOG_DEBUG << "#"; QStringList keysMergeFrom = objectMergeFrom.keys(); int keysSize = keysMergeFrom.size(); bool anyError = false; for (int i = 0; i < keysSize; i++) { const QString &keyFrom = keysMergeFrom.at(i); if (objectMergeTo.contains(keyFrom)) { QJsonValue valueTo = objectMergeTo[keyFrom]; QJsonValue valueFrom = objectMergeFrom[keyFrom]; if (valueTo.type() != valueFrom.type()) { LOG_WARNING << "Types of Json Values do not match at key:" << keyFrom; continue; } if (valueTo.isObject()) { QJsonObject objectTo = valueTo.toObject(); QJsonObject objectFrom = valueFrom.toObject(); if (mergeJsonObjects(objectFrom, objectTo, comparer)) { valueTo = objectTo; } else { anyError = true; break; } } else if (valueTo.isArray()) { QJsonArray arrayTo = valueTo.toArray(); QJsonArray arrayFrom = valueFrom.toArray(); if (mergeJsonArrays(arrayFrom, arrayTo, comparer)) { valueTo = arrayTo; } else { anyError = true; break; } } else { valueTo = valueFrom; } objectMergeTo[keyFrom] = valueTo; } else { objectMergeTo[keyFrom] = objectMergeFrom[keyFrom]; // insert if doesn't contain } } bool mergeResult = !anyError; return mergeResult; }
QJsonObject Utils::getSubJsonObject(const QString &key, const QJsonObject &obj) { QJsonObject o; if (obj.contains(key)) { QJsonValue value = obj.value(key); if (value.isObject()) { o = value.toObject(); } } return o; }
bool BlockInfoData::readMetaData(const QJsonObject &metaData) { QJsonValue value; value = metaData.value("IID"); if (!value.isString()) { qWarning() << "Not a plugin (no IID found)"; return false; } value = metaData.value("MetaData"); if (!value.isObject()) { qWarning() << "Plugin meta data not found"; return false; } QJsonObject pluginInfo = value.toObject(); value = pluginInfo.value("provides"); if (!value.isString()) { qWarning() << "Plugin doesn't provide anything (check \"provides\" field)"; return false; } provides = BlockVersion(value.toString()); if (!provides.isValid()) { qWarning() << "Plugin provides invalid version"; return false; } value = pluginInfo.value("provides_compat"); if (!value.isString()) { qWarning() << "Plugin doesn't provide compatibility version " "(check \"provides_compat\" field)"; return false; } provides_compat = BlockVersion(value.toString()); if (!provides_compat.isValid()) { qWarning() << "Plugin provides invalid version"; return false; } value = pluginInfo.value("needs"); if (value.isArray()) { QJsonArray deps = value.toArray(); foreach(const QJsonValue &d, deps) { if (d.isString()) { BlockVersion version(d.toString()); if (version.isValid()) needs.append(version); } } }
// === SYSCACHE REQUEST INTERACTION === void WebSocket::EvaluateBackendRequest(QString name, const QJsonValue args, QJsonObject *out){ QJsonObject obj; //output object if(args.isObject()){ //For the moment: all arguments are full syscache DB calls - no special ones QStringList reqs = args.toObject().keys(); if(!reqs.isEmpty()){ if(DEBUG){ qDebug() << "Parsing Inputs:" << reqs; } for(int r=0; r<reqs.length(); r++){ QString req = JsonValueToString(args.toObject().value(reqs[r])); if(DEBUG){ qDebug() << " ["+reqs[r]+"]="+req; } QStringList values; if(name.toLower()=="syscache"){values = SysCacheClient::parseInputs( QStringList() << req ); } else if(name.toLower()=="dispatcher"){values = DispatcherClient::parseInputs( QStringList() << req, AUTHSYSTEM); } values.removeAll(""); //Quick check if a list of outputs was returned if(values.length()==1 && name.toLower()=="syscache"){ values = values[0].split(SCLISTDELIM); //split up the return list (if necessary) values.removeAll(""); } if(DEBUG){ qDebug() << " - Returns:" << values; } if(values.length()<2){ out->insert(req, QJsonValue(values.join("")) ); } else{ //This is an array of outputs QJsonArray arr; for(int i=0; i<values.length(); i++){ arr.append(values[i]); } out->insert(req,arr); } } } //end of special "request" objects }else if(args.isArray()){ QStringList inputs = JsonArrayToStringList(args.toArray()); if(DEBUG){ qDebug() << "Parsing Array inputs:" << inputs; } QStringList values; if(name.toLower()=="syscache"){values = SysCacheClient::parseInputs( inputs ); } else if(name.toLower()=="dispatcher"){values = DispatcherClient::parseInputs( inputs , AUTHSYSTEM); } if(DEBUG){ qDebug() << " - Returns:" << values; } for(int i=0; i<values.length(); i++){ if(name.toLower()=="syscache" && values[i].contains(SCLISTDELIM)){ //This is an array of values from syscache QStringList vals = values[i].split(SCLISTDELIM); vals.removeAll(""); QJsonArray arr; for(int j=0; j<vals.length(); j++){ arr.append(vals[j]); } out->insert(inputs[i],arr); }else{ out->insert(inputs[i],values[i]); } } } //end array of inputs }
MarkedString::MarkedString(const QJsonValue &value) { if (value.isArray()) { emplace<QList<MarkedLanguageString>>( LanguageClientArray<MarkedLanguageString>(value).toList()); } else if (value.isObject()) { const QJsonObject &object = value.toObject(); MarkedLanguageString markedLanguageString(object); if (markedLanguageString.isValid(nullptr)) emplace<MarkedLanguageString>(markedLanguageString); else emplace<MarkupContent>(MarkupContent(object)); } }
static MetaDataResult::Tag tryReadPluginMetaDataFromCacheFile(const QString& canonicalPluginPath, RawPluginMetaData& result) { QJsonDocument jsonDocument; if (readMetaDataFromCacheFile(jsonDocument) != ReadResult::Success) return MetaDataResult::NotAvailable; QJsonArray array = jsonDocument.array(); QDateTime pluginLastModified = QFileInfo(canonicalPluginPath).lastModified(); for (QJsonArray::const_iterator i = array.constBegin(); i != array.constEnd(); ++i) { QJsonValue item = *i; if (!item.isObject()) { cacheFile()->remove(); return MetaDataResult::NotAvailable; } QJsonObject object = item.toObject(); if (object.value(QStringLiteral("path")).toString() == canonicalPluginPath) { QString timestampString = object.value(QStringLiteral("timestamp")).toString(); if (timestampString.isEmpty()) { cacheFile()->remove(); return MetaDataResult::NotAvailable; } QDateTime timestamp = QDateTime::fromString(timestampString); if (timestamp < pluginLastModified) { // Out of date data for this plugin => remove it from the file. array.removeAt(i.i); writeToCacheFile(array); return MetaDataResult::NotAvailable; } if (object.contains(QLatin1String("unloadable"))) return MetaDataResult::Unloadable; // Match. result.name = object.value(QStringLiteral("name")).toString(); result.description = object.value(QStringLiteral("description")).toString(); result.mimeDescription = object.value(QStringLiteral("mimeDescription")).toString(); if (result.mimeDescription.isEmpty()) { // Only the mime description is mandatory. // Don't trust in the cache file if it is empty. cacheFile()->remove(); return MetaDataResult::NotAvailable; } return MetaDataResult::Available; } } return MetaDataResult::NotAvailable; }
void WzConfig::beginGroup(const QString &prefix) { mObjNameStack.append(prefix); mObjStack.append(mObj); mName = prefix; if (mWarning == ReadAndWrite) { mObj = QJsonObject(); return; } ASSERT(mWarning == ReadAndWrite || contains(prefix), "beginGroup() on non-existing key %s", prefix.toUtf8().constData()); QJsonValue value = mObj.value(prefix); ASSERT(value.isObject(), "beginGroup() on non-object key %s", prefix.toUtf8().constData()); mObj = value.toObject(); }
ServerConfig::ServerConfig(const QJsonValue& value) : _networkType(ServerConfig::NetworkType::disabled) { if (!value.isUndefined()) // else: take default values { if (!value.isObject()) throw new InvalidFieldException(entity_name, ""); QJsonObject o = value.toObject(); QJsonValue networkType = o[network_type_field]; if (networkType.isString()) _networkType = deserializeNetworkType(networkType.toString()); else throw InvalidFieldException(entity_name, network_type_field); } }
GotoResult::GotoResult(const QJsonValue &value) { if (value.isArray()) { QList<Location> locations; for (auto arrayValue : value.toArray()) { if (arrayValue.isObject()) locations.append(Location(arrayValue.toObject())); } emplace<QList<Location>>(locations); } else if (value.isObject()) { emplace<Location>(value.toObject()); } else { emplace<std::nullptr_t>(nullptr); } }
static Nuria::JsonMetaObjectReader::Error parseFieldsObject (const QJsonObject &fields, Nuria::RuntimeMetaObject *metaObject) { Nuria::JsonMetaObjectReader::Error error = Nuria::JsonMetaObjectReader::NoError; auto it = fields.constBegin (); auto end = fields.constEnd (); for (; it != end && error == Nuria::JsonMetaObjectReader::NoError; ++it) { QString name = it.key (); QJsonValue value = *it; if (!value.isObject ()) return Nuria::JsonMetaObjectReader::FieldIsNotAnObject; error = parseFieldObject (name, value.toObject (), metaObject); } // return error; }
Transform Transform::fromJson(const QJsonValue& json) { if (!json.isObject()) { return Transform(); } QJsonObject obj = json.toObject(); Transform result; if (obj.contains(JSON_ROTATION)) { result.setRotation(quatFromJsonValue(obj[JSON_ROTATION])); } if (obj.contains(JSON_TRANSLATION)) { result.setTranslation(vec3FromJsonValue(obj[JSON_TRANSLATION])); } if (obj.contains(JSON_SCALE)) { result.setScale(vec3FromJsonValue(obj[JSON_TRANSLATION])); } return result; }