コード例 #1
0
ファイル: qv8jsonwrapper.cpp プロジェクト: ghjinlei/qt5
v8::Handle<v8::Value> QV8JsonWrapper::fromJsonValue(const QJsonValue &value)
{
    if (value.isString())
        return QJSConverter::toString(value.toString());
    else if (value.isDouble())
        return v8::Number::New(value.toDouble());
    else if (value.isBool())
        return value.toBool() ? v8::True() : v8::False();
    else if (value.isArray())
        return fromJsonArray(value.toArray());
    else if (value.isObject())
        return fromJsonObject(value.toObject());
    else if (value.isNull())
        return v8::Null();
    else
        return v8::Undefined();
}
コード例 #2
0
ファイル: qv4jsonobject.cpp プロジェクト: CodeDJ/qt5-hidpi
ReturnedValue JsonObject::fromJsonValue(ExecutionEngine *engine, const QJsonValue &value)
{
    if (value.isString())
        return engine->currentContext()->engine->newString(value.toString())->asReturnedValue();
    else if (value.isDouble())
        return Encode(value.toDouble());
    else if (value.isBool())
        return Encode(value.toBool());
    else if (value.isArray())
        return fromJsonArray(engine, value.toArray());
    else if (value.isObject())
        return fromJsonObject(engine, value.toObject());
    else if (value.isNull())
        return Encode::null();
    else
        return Encode::undefined();
}
コード例 #3
0
ファイル: protoobject.cpp プロジェクト: jcapoduri/ndlite
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());
    };
}
コード例 #4
0
    void PresetKeywordsModelConfig::parsePresetArray(const QJsonArray &array) {
        const int size = array.size();

        for (int i = 0; i < size; ++i) {
            QJsonValue item = array.at(i);

            if (!item.isObject()) { continue; }

            QJsonObject presetKeywordsItem = item.toObject();

            // legacy format
            if (presetKeywordsItem.size() == 1) {
                QString presetName = presetKeywordsItem.keys()[0];
                QJsonValue presetKeywordsValue = presetKeywordsItem.value(presetName);
                QStringList keywords;

                if (tryParsePresetKeywords(presetKeywordsValue, keywords)) {
                    m_PresetData.push_back({keywords, presetName, DEFAULT_GROUP_ID});
                }
            } else {
                QString presetName;
                QJsonValue presetNameValue = presetKeywordsItem.value(PRESET_NAME_KEY);
                if (presetNameValue.isString()) {
                    presetName = presetNameValue.toString().trimmed();
                } else {
                    continue;
                }

                if (presetName.isEmpty()) { continue; }

                QJsonValue keywordsValue = presetKeywordsItem.value(PRESET_KEYWORDS_KEY);
                QStringList keywords;
                if (!tryParsePresetKeywords(keywordsValue, keywords)) { continue; }

                QJsonValue groupIdValue = presetKeywordsItem.value(PRESET_GROUP_ID_KEY);
                int groupID = DEFAULT_GROUP_ID;
                if (groupIdValue.isDouble()) {
                    groupID = groupIdValue.toInt(DEFAULT_GROUP_ID);
                }

                m_PresetData.push_back({keywords, presetName, groupID});
            }
        }
    }
コード例 #5
0
ファイル: shadow.cpp プロジェクト: garfeng/shadow
QString Shadow::GetJsonVal(QString key,QJsonObject jsonObj)
{
    if(jsonObj.contains(key))
    {
        QJsonValue value = jsonObj.take(key);
        if(value.isDouble())
        {
            int valueInt = (int)(value.toDouble());
            QString str = QString::number(valueInt);
            return str;
        } else if(value.isString()){
            QString valueString = value.toString();
            return valueString;
        } else {
            return "";
        }
    }
    return "";
}
コード例 #6
0
ファイル: Filter.cpp プロジェクト: AlphaStaxLLC/hifi
bool Filter::parseSingleFloatParameter(const QJsonValue& parameters, const QString& name, float& output) {
    if (parameters.isDouble()) {
        output = parameters.toDouble();
        return true;
    } else if (parameters.isArray()) {
        auto arrayParameters = parameters.toArray();
        if (arrayParameters.size() > 1) {
            output = arrayParameters[0].toDouble();
            return true;
        }
    } else if (parameters.isObject()) {
        static const QString JSON_MIN = QStringLiteral("interval");
        auto objectParameters = parameters.toObject();
        if (objectParameters.contains(name)) {
            output = objectParameters[name].toDouble();
            return true;
        }
    } 
    return false;
}
コード例 #7
0
QVariant JsonTablemodel::data(const QModelIndex &index, int role) const
{
	if (index.row() >= mData.count() || index.column() >= mMapping.count())
	{
		return QVariant();
	}

	if (role == Qt::DisplayRole || role == Qt::EditRole)
	{
		QJsonObject object = mData.at(index.row());
		QString name = mMapping.at(index.column());
        QJsonValue value = object[name];
        if (value.isDouble())
        {
            return QString("$") + QString::number(value.toDouble());
        }
        return value.toVariant();
	}
	return QVariant();
}
コード例 #8
0
    void PresetKeywordsModelConfig::parsePresetGroups(const QJsonArray &array) {
        const int size = array.size();

        for (int i = 0; i < size; ++i) {
            QJsonValue item = array.at(i);

            if (!item.isObject()) { continue; }

            QJsonObject groupItem = item.toObject();

            QJsonValue groupNameValue = groupItem.value(GROUP_NAME_KEY);
            if (!groupNameValue.isString()) { continue; }
            QString groupName = groupNameValue.toString().trimmed();
            if (groupName.isEmpty()) { continue; }

            QJsonValue groupIdValue = groupItem.value(GROUP_ID_KEY);
            if (!groupIdValue.isDouble()) { continue; }
            int groupId = groupIdValue.toInt(DEFAULT_GROUP_ID);

            m_PresetGroupsData.push_back({groupName, groupId});
        }
    }
コード例 #9
0
ファイル: JSONHelpers.cpp プロジェクト: disigma/hifi
vec3 vec3FromJsonValue(const QJsonValue& v) {
    if (v.isDouble()) {
        return vec3((float)v.toDouble());
    }
    return glmFromJson<vec3>(v);
}
コード例 #10
0
BlockOptionType BlockOptionType_fromJson(QJsonValue node, bool *ok) {
    *ok = node.isDouble() && (node.toDouble() == node.toInt());
    return (BlockOptionType)(node.toInt());
}
コード例 #11
0
void BSClient::replySeriesGenresFinished()
{
    qDebug() << "BSClient::replySeriesGenresFinished()";

    QByteArray byteArray = m_reply->readAll();

    if(isCaptcha(byteArray))
    {
        loadSeriesGenres();
        return;
    }

    QJsonDocument document = QJsonDocument::fromJson(byteArray);

    if(!document.isObject())
    {
        Q_EMIT error(tr("JSON-Parse-Fehler: 0x0007"));
        return;
    }

    QHash<QString, QList<QPair<int, QString> > > seriesCategories;

    QJsonObject object = document.object();

    for(QJsonObject::const_iterator iter = object.constBegin();
            iter != object.constEnd();
            iter++)
    {
        if(!iter.value().isObject())
        {
            qDebug() << iter.value();
            Q_EMIT error(tr("JSON-Parse-Fehler: 0x0008"));
            return;
        }

        QJsonObject object_ = iter.value().toObject();

        if(!object_.contains("series"))
        {
            Q_EMIT error(tr("JSON-Parse-Fehler: 0x0009"));
            return;
        }

        QJsonValue value = object_.value("series");

        if(!value.isArray())
        {
            Q_EMIT error(tr("JSON-Parse-Fehler: 0x000A"));
            return;
        }

        QList<QPair<int, QString> > series;

        QJsonArray array = iter.value().toArray();

        Q_FOREACH(const QJsonValue &value_, value.toArray())
        {
             if(!value_.isObject())
             {
                 Q_EMIT error(tr("JSON-Parse-Fehler: 0x000B"));
                 return;
             }

             QJsonObject object__ = value_.toObject();

             if(!object__.contains("name"))
             {
                 Q_EMIT error(tr("JSON-Parse-Fehler: 0x000C"));
                 return;
             }

             QJsonValue idValue = object__.value("id");

             if(!idValue.isDouble())
             {
                 Q_EMIT error(tr("JSON-Parse-Fehler: 0x000D"));
                 return;
             }

             QJsonValue nameValue = object__.value("name");

             if(!nameValue.isString())
             {
                 Q_EMIT error(tr("JSON-Parse-Fehler: 0x000E"));
                 return;
             }

             series << qMakePair(idValue.toInt(), nameValue.toString());
        }

        seriesCategories.insert(iter.key(), series);
    }

    Q_EMIT loadSeriesGenresFinished(seriesCategories);
}
コード例 #12
0
ファイル: httpserver.cpp プロジェクト: supamii/QttpServer
bool HttpServer::initialize()
{
  if(m_IsInitialized)
  {
    LOG_DEBUG("Already initialized");
    return false;
  }

  QProcessEnvironment env = QProcessEnvironment::systemEnvironment();
  if(env.contains(QTTP_HOME_ENV_VAR))
  {
    QDir::setCurrent(env.value(QTTP_HOME_ENV_VAR));
    LOG_DEBUG("Working directory from $" << QTTP_HOME_ENV_VAR << QDir::currentPath());
  }
  else
  {
    // Just a quirk for mac, but I wonder if we can apply to all in general.
    #ifdef Q_OS_MAC
    QDir::setCurrent(qApp->applicationDirPath());
    LOG_DEBUG("Working directory" << QDir::currentPath());
    #else
    LOG_DEBUG("Working directory" << QDir::currentPath());
    #endif
  }

  QCoreApplication* app = QCoreApplication::instance();
  Q_ASSERT(app);

  m_CmdLineParser.addOptions({
    {{"i", "ip"},
     QCoreApplication::translate("main", "ip of the target interface"),
     QCoreApplication::translate("main", "ip")},
    {{"p", "port"},
     QCoreApplication::translate("main", "port to listen on"),
     QCoreApplication::translate("main", "port")},
    {{"m", "meta"},
     QCoreApplication::translate("main", "appends metadata to responses")},
    {{"c", "config"},
     QCoreApplication::translate("main", "absolute path to the global config file (json)"),
     QCoreApplication::translate("main", "config")},
    {{"r", "routes"},
     QCoreApplication::translate("main", "absolute path to the routes config file (json)"),
     QCoreApplication::translate("main", "routes")},
    {{"d", "dir"},
     QCoreApplication::translate("main", "absolute path to the config directory, don't combine with -c or -r args"),
     QCoreApplication::translate("main", "dir")},
    {{"w", "www"},
     QCoreApplication::translate("main", "absolute path to the www folder to serve http files"),
     QCoreApplication::translate("main", "www")},
    {{"s", "swagger"},
     QCoreApplication::translate("main", "exposes swagger-api json responses for the path /swagger/")},
  });

  m_CmdLineParser.addHelpOption();
  m_CmdLineParser.process(*app);

  if(env.contains(CONFIG_DIRECTORY_ENV_VAR))
  {
    QString var = env.value(CONFIG_DIRECTORY_ENV_VAR);
    if(!var.isNull() && !var.trimmed().isEmpty())
    {
      LOG_INFO("Processing ENVIRONMENT VARIABLE [" << var << "]");
      initConfigDirectory(var);
    }
    else
    {
      LOG_WARN("Invalid ENVIRONMENT VARIABLE [" << CONFIG_DIRECTORY_ENV_VAR << "]");
    }
  }

  QJsonValue d = m_CmdLineParser.value("d");
  if(d.isString() && !d.isNull() && !d.toString().trimmed().isEmpty())
  {
    initConfigDirectory(d.toString());
  }
  else
  {
    QJsonValue c = m_CmdLineParser.value("c");
    if(c.isString() && !c.isNull() && !c.toString().trimmed().isEmpty())
    {
      initGlobal(c.toString());
    }
    else
    {
      initGlobal(GLOBAL_CONFIG_FILE_PATH);
    }

    QJsonValue r = m_CmdLineParser.value("r");
    if(r.isString() && !r.isNull() && !r.toString().trimmed().isEmpty())
    {
      initRoutes(r.toString());
    }
    else
    {
      initRoutes(ROUTES_CONFIG_FILE_PATH);
    }
  }

  if(!m_SendRequestMetadata)
  {
    m_SendRequestMetadata = m_CmdLineParser.isSet("m");
    LOG_DEBUG("CmdLine meta-data" << m_SendRequestMetadata);
  }

  if(!m_IsSwaggerEnabled)
  {
    initSwagger(m_CmdLineParser.isSet("s"));
    LOG_DEBUG("CmdLine swagger" << m_IsSwaggerEnabled);
  }

  QJsonValue i = m_CmdLineParser.value("i");
  if((i.isString() || i.isDouble()) && !i.toString().trimmed().isEmpty())
  {
    QString ip = i.toString();
    m_GlobalConfig["bindIp"] = ip;
    LOG_DEBUG("CmdLine ip" << ip);
  }

  QJsonValue p = m_CmdLineParser.value("p");
  if((p.isString() || p.isDouble()) && !p.toString().trimmed().isEmpty())
  {
    qint32 port = p.toInt();
    m_GlobalConfig["bindPort"] = port;
    LOG_DEBUG("CmdLine port" << port);
  }

  QJsonValue w = m_CmdLineParser.value("w");
  if(w.isString() && !w.isNull() && !w.toString().trimmed().isEmpty())
  {
    initHttpDirectory(w.toString());
    LOG_DEBUG("CmdLine www/web/http-files" << w);
  }

  m_IsInitialized = true;

  return true;
}