コード例 #1
0
ファイル: etheripc.cpp プロジェクト: almindor/etherwall
    void EtherIPC::handleGetSyncing() {
        QJsonValue jv;
        if ( !readReply(jv) ) {
            return bail();
        }

        if ( jv.isNull() || ( jv.isBool() && !jv.toBool(false) ) ) {
            if ( fSyncing ) {
                fSyncing = false;
                if ( fBlockFilterID.isEmpty() ) {
                    newBlockFilter();
                }
                emit syncingChanged(fSyncing);
            }

            return done();
        }

        const QJsonObject syncing = jv.toObject();
        fCurrentBlock = Helpers::toQUInt64(syncing.value("currentBlock"));
        fHighestBlock = Helpers::toQUInt64(syncing.value("highestBlock"));
        fStartingBlock = Helpers::toQUInt64(syncing.value("startingBlock"));
        if ( !fSyncing ) {
            if ( !fBlockFilterID.isEmpty() ) {
                uninstallFilter(fBlockFilterID);
                fBlockFilterID.clear();
            }
            fSyncing = true;
        }

        emit syncingChanged(fSyncing);
        done();
    }
コード例 #2
0
ファイル: jsonobject.cpp プロジェクト: lfritz/qtjsonhelper
bool JsonObject::boolean(const QString& key) const {
    checkContains(key);
    QJsonValue value = o.value(key);
    if ( ! value.isBool())
        wrongType("'true' or 'false'", key);
    return value.toBool();
}
コード例 #3
0
static Nuria::JsonMetaObjectReader::Error parseFieldObject (const QString &name, const QJsonObject &field,
							    Nuria::RuntimeMetaObject *metaObject) {
	using namespace Nuria;
	
	QJsonValue annotationsValue = field.value (QStringLiteral("annotations"));
	QJsonValue readOnlyValue = field.value (QStringLiteral("readOnly"));
	QJsonValue typeValue = field.value (QStringLiteral("type"));
	
	// Type check
	if (!annotationsValue.isArray ()) return JsonMetaObjectReader::AnnotationsIsNotAnArray;
	if (!readOnlyValue.isBool ()) return JsonMetaObjectReader::FieldReadOnlyIsNotABoolean;
	if (!typeValue.isString ()) return JsonMetaObjectReader::FieldTypeIsNotAString;
	
	// Parse annotations
	JsonMetaObjectReader::Error error;
	
	RuntimeMetaObject::AnnotationMap annotations;
	error = parseAnnotationsArray (annotationsValue.toArray (), annotations);
	if (error != JsonMetaObjectReader::NoError) return error;
	
	// Store and done.
	QByteArray typeName = typeValue.toString ().toLatin1 ();
	
	if (readOnlyValue.toBool ()) {
		metaObject->addField (name.toLatin1 (), typeName, annotations, invalidGetter);
	} else {
		metaObject->addField (name.toLatin1 (), typeName, annotations, invalidGetter, invalidSetter);
	}
	
	return JsonMetaObjectReader::NoError;
}
コード例 #4
0
bool QJsonValueProto::isBool() const
{
  QJsonValue *item = qscriptvalue_cast<QJsonValue*>(thisObject());
  if (item)
    return item->isBool();
  return false;
}
コード例 #5
0
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());
                }
            }
        }
    }
}
コード例 #6
0
DocumentFormattingProperty::DocumentFormattingProperty(const QJsonValue &value)
{
    if (value.isBool())
        *this = value.toBool();
    if (value.isDouble())
        *this = value.toDouble();
    if (value.isString())
        *this = value.toString();
}
コード例 #7
0
ファイル: switcherconfig.cpp プロジェクト: Ribtoks/xpiks
    bool tryGetBool(const QJsonObject &object, const QString &key, bool &value) {
        bool hasValue = false;

        if (object.contains(key)) {
            QJsonValue valueObject = object[key];
            if (valueObject.isBool()) {
                value = valueObject.toBool();
                hasValue = true;
            }
        }

        return hasValue;
    }
コード例 #8
0
QHash<QString, DocumentFormattingProperty> FormattingOptions::properties() const
{
    QHash<QString, DocumentFormattingProperty> ret;
    for (const QString &key : keys()) {
        if (key == tabSizeKey || key == insertSpaceKey)
            continue;
        QJsonValue property = value(key);
        if (property.isBool())
            ret[key] = property.toBool();
        if (property.isDouble())
            ret[key] = property.toDouble();
        if (property.isString())
            ret[key] = property.toString();
    }
    return ret;
}
コード例 #9
0
ReturnedValue JsonObject::fromJsonValue(ExecutionEngine *engine, const QJsonValue &value)
{
    if (value.isString())
        return engine->currentContext()->d()->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();
}
コード例 #10
0
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();
}
コード例 #11
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());
    };
}