// プロパティ取得共通処理 tjs_error TJSInstance::getProp(Isolate *isolate, Local<Object> &obj, const tjs_char *membername, tTJSVariant *result) { if (!membername) { return TJS_E_NOTIMPL; } HandleScope handle_scope(isolate); Context::Scope context_scope(getContext()); TryCatch try_catch; Local<Value> ret = obj->Get(String::NewFromTwoByte(isolate, membername)); if (ret.IsEmpty()) { return TJS_E_MEMBERNOTFOUND; } else { if (result) { if (ret->IsFunction()) { *result = toVariant(isolate, ret->ToObject(), obj); } else { *result = toVariant(isolate, ret); } } } return TJS_S_OK; }
/*! */ QVariant SceneDocument::toVariant(const QJsonValue& value) noexcept { QVariant node; switch (value.type()) { case QJsonValue::Null: { zisc::raiseError("The json value is null."); break; } case QJsonValue::Bool: case QJsonValue::Double: case QJsonValue::String: { node = value.toVariant(); break; } case QJsonValue::Array: { node = toVariant(value.toArray()); break; } case QJsonValue::Object: { node = toVariant(value.toObject()); break; } case QJsonValue::Undefined: { zisc::raiseError("The json value is undefined."); break; } default: { zisc::raiseError("Undefined json value type is specified."); break; } } return node; }
Variant ApiConnector::callGameFunction(int functionId, int nbParameters, Variant parameters[]) { int nbCalls = ceil(nbParameters / 8.); for (int i = 0; i < nbCalls; ++i) { int remainingParameters = nbParameters - i * 8; Variant parameter1 = (remainingParameters > 0) ? parameters[0] : Variant(); Variant parameter2 = (remainingParameters > 1) ? parameters[1] : Variant(); Variant parameter3 = (remainingParameters > 2) ? parameters[2] : Variant(); Variant parameter4 = (remainingParameters > 3) ? parameters[3] : Variant(); Variant parameter5 = (remainingParameters > 4) ? parameters[4] : Variant(); Variant parameter6 = (remainingParameters > 5) ? parameters[5] : Variant(); Variant parameter7 = (remainingParameters > 6) ? parameters[6] : Variant(); Variant parameter8 = (remainingParameters > 7) ? parameters[7] : Variant(); return toVariant(makeCall( functionId, nbParameters, parameter1, parameter2, parameter3, parameter4, parameter5, parameter6, parameter7, parameter8)); } }
/*! \internal */ void QFormBuilder::applyProperties(QObject *o, const QList<DomProperty*> &properties) { typedef QList<DomProperty*> DomPropertyList; if (properties.empty()) return; QFormBuilderExtra *fb = QFormBuilderExtra::instance(this); const QFormBuilderStrings &strings = QFormBuilderStrings::instance(); const DomPropertyList::const_iterator cend = properties.constEnd(); for (DomPropertyList::const_iterator it = properties.constBegin(); it != cend; ++it) { const QVariant v = toVariant(o->metaObject(), *it); if (v.isNull()) continue; const QString attributeName = (*it)->attributeName(); if (o == fb->rootWidget() && attributeName == strings.geometryProperty) { // apply only the size for the rootWidget fb->rootWidget()->resize(qvariant_cast<QRect>(v).size()); } else if (fb->applyPropertyInternally(o, attributeName, v)) { } else if (!qstrcmp("QFrame", o->metaObject()->className ()) && attributeName == strings.orientationProperty) { // ### special-casing for Line (QFrame) -- try to fix me o->setProperty("frameShape", v); // v is of QFrame::Shape enum } else { o->setProperty(attributeName.toUtf8(), v); } } }
/*! * \brief Parse JSON data to QVariant * \param String with JSON data * \return Result of parsing, QVariant::Null if there was an error */ QVariant parse(const QByteArray &data) { QJsonParseError error; auto document = QJsonDocument::fromJson(data, &error); return document.toVariant(); }
/** * TJSオブジェクトのオーバライド処理 * @param args 引数 * @return 結果 */ void TJSInstance::tjsOverride(const FunctionCallbackInfo<Value>& args) { Isolate *isolate = args.GetIsolate(); HandleScope handle_scope(isolate); tTJSVariant instance; if (getVariant(isolate, instance, args.This())) { if (args.Length() > 0) { Local<Value> func = args.Length() > 1 ? args[1] : args.This()->Get(args[0]); if (func->IsFunction()) { tTJSVariant value = toVariant(isolate, func->ToObject(), args.This()); String::Value methodName(args[0]); tjs_error error; if (TJS_FAILED(error = instance.AsObjectClosureNoAddRef().PropSet(TJS_MEMBERENSURE, *methodName, NULL, &value, NULL))) { args.GetReturnValue().Set(ERROR_KRKR(isolate, error)); return; } args.GetReturnValue().Set(Undefined(isolate)); return; } } args.GetReturnValue().Set(isolate->ThrowException(String::NewFromUtf8(isolate, "not function"))); return; } args.GetReturnValue().Set(ERROR_BADINSTANCE(isolate)); }
void QFormBuilder::applyProperties(QObject *o, const QList<DomProperty*> &properties) { typedef QList<DomProperty*> DomPropertyList; if (properties.empty()) return; const QFormBuilderStrings &strings = QFormBuilderStrings::instance(); const DomPropertyList::const_iterator cend = properties.constEnd(); for (DomPropertyList::const_iterator it = properties.constBegin(); it != cend; ++it) { const QVariant v = toVariant(o->metaObject(), *it); if (!v.isValid()) // QTBUG-33130, do not fall for QVariant(QString()).isNull() == true. continue; const QString attributeName = (*it)->attributeName(); const bool isWidget = o->isWidgetType(); if (isWidget && o->parent() == d->parentWidget() && attributeName == strings.geometryProperty) { // apply only the size part of a geometry for the root widget static_cast<QWidget*>(o)->resize(qvariant_cast<QRect>(v).size()); } else if (d->applyPropertyInternally(o, attributeName, v)) { } else if (isWidget && !qstrcmp("QFrame", o->metaObject()->className ()) && attributeName == strings.orientationProperty) { // ### special-casing for Line (QFrame) -- try to fix me o->setProperty("frameShape", v); // v is of QFrame::Shape enum } else { o->setProperty(attributeName.toUtf8(), v); } } }
// コンストラクタ呼び出し共通処理 tjs_error TJSInstance::createMethod(Isolate *isolate, Local<Object> &obj, const tjs_char *membername, iTJSDispatch2 **result, tjs_int numparams, tTJSVariant **param) { if (membername) { return TJS_E_MEMBERNOTFOUND; } HandleScope handle_scope(isolate); Context::Scope context_scope(getContext()); TryCatch try_catch; if (!obj->IsFunction()) { return TJS_E_NOTIMPL; } // 関数抽出 Local<Function> func = Local<Function>::Cast(obj->ToObject()); // 引数 Handle<Value> *argv = new Handle<Value>[numparams]; for (int i=0;i<numparams;i++) { argv[i] = toJSValue(isolate, *param[i]); } Local<Object> ret = func->NewInstance(numparams, argv); delete argv; if (ret.IsEmpty()) { JSEXCEPTION(isolate, &try_catch); } else { if (result) { *result = toVariant(isolate, ret); } } return TJS_S_OK; }
/*! Creates a new private conference and invites additional attendees. The conference will get a random password. JSON Parameters: - participants (Array with fingerprints) */ bool ConferenceModule::Private::processJsonConferenceCreate(TcpSocketHandler &socket, const TcpProtocol::RequestHeader &header, const QVariant &data) { auto json = data.toMap(); auto participants = json.value("participants").toList(); auto server = _pOwner->_serverBase; auto selfInfo = socket.getClientInfo(); // Create invisible channel with random password. auto channel = server->createChannel(); if (!server->joinChannel(selfInfo->id, channel->id)) { QVariantMap m; m["status"] = 500; m["error_message"] = "Can not create channel."; return socket.sendJsonResponse(header, m); } // Invite participants. foreach (auto o, participants) { auto fingerprint = o.toByteArray(); auto sock = server->findSocket(fingerprint); if (sock) { QVariantMap m; m["method"] = "/conference/notify/invite"; m["initiator"] = socket._key.fingerprint(); m["channel"] = channel->toVariant(); sock->sendJsonPackage(m); } }
bool NetworkPackage::unserialize(const QByteArray& a, NetworkPackage* np) { //Json -> QVariant QJsonParseError parseError; auto parser = QJsonDocument::fromJson(a, &parseError); if (parser.isNull()) { qCDebug(KDECONNECT_CORE) << "Unserialization error:" << parseError.errorString(); return false; } auto variant = parser.toVariant().toMap(); qvariant2qobject(variant, np); np->mPayloadSize = variant[QStringLiteral("payloadSize")].toInt(); //Will return 0 if was not present, which is ok if (np->mPayloadSize == -1) { np->mPayloadSize = np->get<int>(QStringLiteral("size"), -1); } np->mPayloadTransferInfo = variant[QStringLiteral("payloadTransferInfo")].toMap(); //Will return an empty qvariantmap if was not present, which is ok //Ids containing characters that are not allowed as dbus paths would make app crash if (np->mBody.contains(QStringLiteral("deviceId"))) { QString deviceId = np->get<QString>(QStringLiteral("deviceId")); DbusHelper::filterNonExportableCharacters(deviceId); np->set(QStringLiteral("deviceId"), deviceId); } return true; }
// メソッド呼び出し共通処理 tjs_error TJSInstance::callMethod(Isolate *isolate, Local<Object> &obj, const tjs_char *membername, tTJSVariant *result, tjs_int numparams, tTJSVariant **param, iTJSDispatch2 *objthis) { HandleScope handle_scope(isolate); Context::Scope context_scope(getContext()); TryCatch try_catch; Local<Object> context = membername ? obj : objthis ? toJSValue(isolate, tTJSVariant(objthis))->ToObject() : getContext()->Global(); Local<Object> method = membername ? obj->Get(String::NewFromTwoByte(isolate, membername))->ToObject() : obj; if (!method->IsFunction()) { return TJS_E_NOTIMPL; } // 関数抽出 Local<Function> func = Local<Function>::Cast(method); // 引数 Handle<Value> *argv = new Handle<Value>[numparams]; for (int i=0;i<numparams;i++) { argv[i] = toJSValue(isolate, *param[i]); } Local<Value> ret = func->Call(context, numparams, argv); delete argv; if (ret.IsEmpty()) { JSEXCEPTION(isolate, &try_catch); } else { if (result) { *result = toVariant(isolate, ret); } } return TJS_S_OK; }
QScriptValue REcmaHelper::listToScriptValue(QScriptEngine* engine, const QList<QSharedPointer<RShape> >& cppValue) { QVariantList vl; for (int i = 0; i < cppValue.size(); ++i) { QVariant v = toVariant(cppValue.at(i)); vl.append(v); } return qScriptValueFromValue(engine, vl); }
//------------------------------------------------------------------------------ variant RobotRpcServer::packPose( CPose2d pose ) { object poseObj; poseObj[ "x" ] = toVariant<double> ( pose.mX ); poseObj[ "y" ] = toVariant<double> ( pose.mY ); poseObj[ "yaw" ] = toVariant<double> ( pose.mYaw ); return toVariant( poseObj ); }
//------------------------------------------------------------------------------ variant RobotRpcServer::packVelocity( CVelocity2d velocity ) { object velocityObj; velocityObj[ "xDot" ] = toVariant<double> ( velocity.mXDot ); velocityObj[ "yDot" ] = toVariant<double> ( velocity.mYDot ); velocityObj[ "yawDot" ] = toVariant<double> ( velocity.mYawDot ); return toVariant( velocityObj ); }
void ChatWindow::processUp(packet &&data) { std::lock_guard<std::mutex> lock_guard(_mutex); queue.append(toVariant(data).toString()); QMetaObject::invokeMethod(this, "read_queue", Qt::QueuedConnection); }
QVariantMap toVariant() const { QVariantMap out; out["name"] = name(); out["value"] = toVariant(Value); out["valueAsString"] = Value["text"]; out["flags"] = 0x00000001; //QScriptValue::ReadOnly; // see "SetScriptValueProperty" comment return out; }
void PythonPaletteManager::storeSettings() { QVariant vLight; QVariant vDark; if (!toVariant(m_SpecsLight, vLight)) { msg("%s: unable to serialize light PythonPalette\n", __FUNCTION__); return; } if (!toVariant(m_SpecsDark, vDark)) { msg("%s: unable to serialize dark PythonPalette\n", __FUNCTION__); return; } GlobalSettingsManger::instance().setValue(GSK_LightPalette, vLight); GlobalSettingsManger::instance().setValue(GSK_DarkPalette, vDark); }
/*! */ QVariant SceneDocument::toVariant(const QJsonObject& object) noexcept { QVariantMap node; const auto keys = object.keys(); for (const auto& key : keys) { const auto value = toVariant(object[key]); node.insert(key, value); } return QVariant::fromValue(node); }
/*! */ QVariant SceneDocument::toVariant(const QJsonArray& array) noexcept { QVariantList node; node.reserve(array.size()); for (const auto& element : array) { const auto value = toVariant(element); node.append(value); } return QVariant::fromValue(node); }
virtual QString toString(MetaSQLInfo * mif, const ParameterList & params, int * nBreaks = 0, bool * isContinue = 0) { //qDebug("MetaSQLFunction::toString()"); QVariant v = toVariant(params, nBreaks, isContinue); if(_noOutput) return QString::null; if(_func==FunctionLiteral) return v.toString(); QString n = QString(":_%1_").arg(++(mif->_paramCount)); mif->_pList.append(n, v); return n + " "; }
QVariant QDBusDemarshaller::toVariantInternal() { switch (q_dbus_message_iter_get_arg_type(&iterator)) { case DBUS_TYPE_BYTE: return qVariantFromValue(toByte()); case DBUS_TYPE_INT16: return qVariantFromValue(toShort()); case DBUS_TYPE_UINT16: return qVariantFromValue(toUShort()); case DBUS_TYPE_INT32: return toInt(); case DBUS_TYPE_UINT32: return toUInt(); case DBUS_TYPE_DOUBLE: return toDouble(); case DBUS_TYPE_BOOLEAN: return toBool(); case DBUS_TYPE_INT64: return toLongLong(); case DBUS_TYPE_UINT64: return toULongLong(); case DBUS_TYPE_STRING: return toString(); case DBUS_TYPE_OBJECT_PATH: return qVariantFromValue(toObjectPath()); case DBUS_TYPE_SIGNATURE: return qVariantFromValue(toSignature()); case DBUS_TYPE_VARIANT: return qVariantFromValue(toVariant()); case DBUS_TYPE_ARRAY: switch (q_dbus_message_iter_get_element_type(&iterator)) { case DBUS_TYPE_BYTE: // QByteArray return toByteArray(); case DBUS_TYPE_STRING: return toStringList(); case DBUS_TYPE_DICT_ENTRY: return qVariantFromValue(duplicate()); default: return qVariantFromValue(duplicate()); } case DBUS_TYPE_STRUCT: return qVariantFromValue(duplicate()); default: qWarning("QDBusDemarshaller: Found unknown D-Bus type %d '%c'", q_dbus_message_iter_get_arg_type(&iterator), q_dbus_message_iter_get_arg_type(&iterator)); return QVariant(); break; }; }
QSettings::SettingsMap jsonDocumentToVariantMap(const QJsonDocument& document) { if (!document.isObject()) { qWarning() << "Settings file does not contain a JSON object"; return QSettings::SettingsMap(); } auto object = document.object(); QSettings::SettingsMap map; for (auto it = object.begin(); it != object.end(); ++it) { QVariant result; if (!it->isString()) { result = it->toVariant(); } else { auto string = it->toString(); if (string.startsWith(QLatin1String("@@"))) { // Standard string starting with '@' result = QVariant(string.mid(1)); } else if (string.startsWith(QLatin1Char('@'))) { // Custom type to string if (string.endsWith(QLatin1Char(')'))) { if (string.startsWith(QLatin1String("@ByteArray("))) { result = QVariant(string.toLatin1().mid(11, string.size() - 12)); } else if (string.startsWith(QLatin1String("@Variant("))) { QByteArray a(string.toLatin1().mid(9)); QDataStream stream(&a, QIODevice::ReadOnly); stream.setVersion(QDataStream::Qt_4_0); stream >> result; } else if (string.startsWith(QLatin1String("@Rect("))) { QStringList args = splitArgs(string, 5); if (args.size() == 4) { result = QRect(args[0].toInt(), args[1].toInt(), args[2].toInt(), args[3].toInt()); } } else if (string.startsWith(QLatin1String("@Size("))) { QStringList args = splitArgs(string, 5); if (args.size() == 2) { result = QSize(args[0].toInt(), args[1].toInt()); } } else if (string.startsWith(QLatin1String("@Point("))) { QStringList args = splitArgs(string, 6); if (args.size() == 2) { result = QPoint(args[0].toInt(), args[1].toInt()); } } } } else { // Standard string
// コンストラクタ FuncInfo(const tTJSVariant &instance, const tTJSVariant &method, const FunctionCallbackInfo<Value>& args) : instance(instance), method(method), args(args), argc(0), argv(NULL) { // 引数生成 argc = args.Length(); if (argc > 0) { argv = new tTJSVariant*[(size_t)argc]; for (tjs_int i=0;i<argc;i++) { argv[i] = new tTJSVariant(); *argv[i] = toVariant(args.GetIsolate(), args[i]); } } }
/*! */ bool SceneDocument::loadDocument(const QUrl& file_url, QVariant& node, QString& error_message) noexcept { QJsonObject object; const auto file_path = toFilePath(file_url); const bool result = loadDocument(file_path, object, error_message); if (result) node = toVariant(object); return result; }
// コンストラクタ CreateInfo(const tTJSVariant &classObj, const FunctionCallbackInfo<Value>& args) : classObj(classObj), args(args), argc(0), argv(NULL) { // 引数生成 argc = args.Length(); if (argc > 0) { argv = new tTJSVariant*[(size_t)argc]; for (tjs_int i=0;i<argc;i++) { argv[i] = new tTJSVariant(); *argv[i] = toVariant(args.GetIsolate(), args[i]); } } }
void QDesignerFormBuilder::applyProperties(QObject *o, const QList<DomProperty*> &properties) { typedef QList<DomProperty*> DomPropertyList; if (properties.empty()) return; const QDesignerPropertySheetExtension *sheet = qt_extension<QDesignerPropertySheetExtension*>(core()->extensionManager(), o); const QDesignerDynamicPropertySheetExtension *dynamicSheet = qt_extension<QDesignerDynamicPropertySheetExtension*>(core()->extensionManager(), o); const bool changingMetaObject = WidgetFactory::classNameOf(core(), o) == QStringLiteral("QAxWidget"); const QDesignerMetaObjectInterface *meta = core()->introspection()->metaObject(o); const bool dynamicPropertiesAllowed = dynamicSheet && dynamicSheet->dynamicPropertiesAllowed(); QDesignerPropertySheet *designerPropertySheet = qobject_cast<QDesignerPropertySheet *>( core()->extensionManager()->extension(o, Q_TYPEID(QDesignerPropertySheetExtension))); if (designerPropertySheet) { if (designerPropertySheet->pixmapCache()) designerPropertySheet->setPixmapCache(m_pixmapCache); if (designerPropertySheet->iconCache()) designerPropertySheet->setIconCache(m_iconCache); } const DomPropertyList::const_iterator cend = properties.constEnd(); for (DomPropertyList::const_iterator it = properties.constBegin(); it != cend; ++it) { DomProperty *p = *it; QVariant v; if (!readDomEnumerationValue(p, sheet, v)) v = toVariant(o->metaObject(), p); if (v.isNull()) continue; const QString attributeName = p->attributeName(); if (d->applyPropertyInternally(o, attributeName, v)) continue; // refuse fake properties like current tab name (weak test) if (!dynamicPropertiesAllowed) { if (changingMetaObject) // Changes after setting control of QAxWidget meta = core()->introspection()->metaObject(o); if (meta->indexOfProperty(attributeName) == -1) continue; } QObject *obj = o; QAbstractScrollArea *scroll = qobject_cast<QAbstractScrollArea *>(o); if (scroll && attributeName == QStringLiteral("cursor") && scroll->viewport()) obj = scroll->viewport(); // a real property obj->setProperty(attributeName.toUtf8(), v); } }
//------------------------------------------------------------------------------ void RobotRpcServer::getCliffs(jsonrpc::variant params, jsonrpc::object& results, const std::string& ip, int port) { lockRpcMutex(); array cliffs; for (unsigned int i = 0; i < mCliff->getNumSamples(); ++i) { cliffs.push_back(toVariant<bool> (mCliff->mBitData[i]) ); } results["cliffs"] = toVariant( cliffs ); unlockRpcMutex(); }
//------------------------------------------------------------------------------ void RobotRpcServer::getBumpers(jsonrpc::variant params, jsonrpc::object& results, const std::string& ip, int port) { lockRpcMutex(); array bumpers; for (unsigned int i = 0; i < mBumper->getNumSamples(); ++i) { bumpers.push_back(toVariant<bool> (mBumper->mBitData[i]) ); } results["bumpers"] = toVariant( bumpers ); unlockRpcMutex(); }
//------------------------------------------------------------------------------ void RobotRpcServer::getWheelDrops(jsonrpc::variant params, jsonrpc::object& results, const std::string& ip, int port) { lockRpcMutex(); array wheeldrops; for (unsigned int i = 0; i < mWheelDrop->getNumSamples(); ++i) { wheeldrops.push_back(toVariant<bool> (mWheelDrop->mBitData[i]) ); } results["wheelDrops"] = toVariant( wheeldrops ); unlockRpcMutex(); }
//------------------------------------------------------------------------------ void RobotRpcServer::getPhotos(jsonrpc::variant params, jsonrpc::object& results, const std::string& ip, int port) { lockRpcMutex(); array photos; for (unsigned int i = 0; i < mPhoto->getNumSamples(); ++i) { photos.push_back(toVariant<double> (mPhoto->mData[i]) ); } results["photos"] = toVariant( photos ); unlockRpcMutex(); }