当前位置: 首页>>代码示例>>C++>>正文


C++ QScriptValue::isObject方法代码示例

本文整理汇总了C++中QScriptValue::isObject方法的典型用法代码示例。如果您正苦于以下问题:C++ QScriptValue::isObject方法的具体用法?C++ QScriptValue::isObject怎么用?C++ QScriptValue::isObject使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在QScriptValue的用法示例。


在下文中一共展示了QScriptValue::isObject方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: send

void XMLHttpRequestClass::send(const QScriptValue& data) {
    if (_readyState == OPENED && !_reply) {
        if (!data.isNull()) {
            _sendData = new QBuffer(this);
            if (data.isObject()) {
                QByteArray ba = qscriptvalue_cast<QByteArray>(data);
                _sendData->setData(ba);
            } else {
                _sendData->setData(data.toString().toUtf8());
            }
        }

        doSend();

        if (!_async) {
            QEventLoop loop;
            connect(this, SIGNAL(requestComplete()), &loop, SLOT(quit()));
            loop.exec();
        }
    }
}
开发者ID:imgntn,项目名称:hifi,代码行数:21,代码来源:XMLHttpRequestClass.cpp

示例2: setProperties

void TextOverlay::setProperties(const QScriptValue& properties) {
    Overlay2D::setProperties(properties);
    
    QScriptValue font = properties.property("font");
    if (font.isObject()) {
        if (font.property("size").isValid()) {
            setFontSize(font.property("size").toInt32());
        }
    }

    QScriptValue text = properties.property("text");
    if (text.isValid()) {
        setText(text.toVariant().toString());
    }

    QScriptValue backgroundColor = properties.property("backgroundColor");
    if (backgroundColor.isValid()) {
        QScriptValue red = backgroundColor.property("red");
        QScriptValue green = backgroundColor.property("green");
        QScriptValue blue = backgroundColor.property("blue");
        if (red.isValid() && green.isValid() && blue.isValid()) {
            _backgroundColor.red = red.toVariant().toInt();
            _backgroundColor.green = green.toVariant().toInt();
            _backgroundColor.blue = blue.toVariant().toInt();
        }
    }

    if (properties.property("backgroundAlpha").isValid()) {
        _backgroundAlpha = properties.property("backgroundAlpha").toVariant().toFloat();
    }

    if (properties.property("leftMargin").isValid()) {
        setLeftMargin(properties.property("leftMargin").toVariant().toInt());
    }

    if (properties.property("topMargin").isValid()) {
        setTopMargin(properties.property("topMargin").toVariant().toInt());
    }
}
开发者ID:ey6es,项目名称:hifi,代码行数:39,代码来源:TextOverlay.cpp

示例3: callback

QList< QAction * > KWin::AbstractScript::actionsForUserActionMenu(KWin::AbstractClient *c, QMenu *parent)
{
    QList<QAction*> returnActions;
    for (QList<QScriptValue>::const_iterator it = m_userActionsMenuCallbacks.constBegin(); it != m_userActionsMenuCallbacks.constEnd(); ++it) {
        QScriptValue callback(*it);
        QScriptValueList arguments;
        arguments << callback.engine()->newQObject(c);
        QScriptValue actions = callback.call(QScriptValue(), arguments);
        if (!actions.isValid() || actions.isUndefined() || actions.isNull()) {
            // script does not want to handle this Client
            continue;
        }
        if (actions.isObject()) {
            QAction *a = scriptValueToAction(actions, parent);
            if (a) {
                returnActions << a;
            }
        }
    }

    return returnActions;
}
开发者ID:8l,项目名称:kwin,代码行数:22,代码来源:scripting.cpp

示例4: proxyConstruct

JSC::JSObject* FunctionWrapper::proxyConstruct(JSC::ExecState *exec, JSC::JSObject *callee,
                                               const JSC::ArgList &args)
{
    FunctionWrapper *self = static_cast<FunctionWrapper*>(callee);
    QScriptEnginePrivate *eng_p = QScript::scriptEngineFromExec(exec);

    JSC::ExecState *oldFrame = eng_p->currentFrame;
    eng_p->pushContext(exec, JSC::JSValue(), args, callee, true);
    QScriptContext *ctx = eng_p->contextForFrame(eng_p->currentFrame);

    QScriptValue result = self->data->function(ctx, QScriptEnginePrivate::get(eng_p));

    if (JSC::Debugger* debugger = eng_p->originalGlobalObject()->debugger())
        debugger->functionExit(QScriptValuePrivate::get(result)->jscValue, -1);

    if (!result.isObject())
        result = ctx->thisObject();

    eng_p->popContext();
    eng_p->currentFrame = oldFrame;

    return JSC::asObject(eng_p->scriptValueToJSCValue(result));
}
开发者ID:kileven,项目名称:qt5,代码行数:23,代码来源:qscriptfunction.cpp

示例5: loadSearchProvider

void SearchEngine::loadSearchProvider(const QString path)
{
	if (QDir(path).exists())
	{
		QString configPath = StaticHelpers::CombinePathes(path, "search.ini");
		QSettings searchSettings(configPath, QSettings::IniFormat);
		SearchInfo info;
		searchSettings.beginGroup("SearchEngine");
		info.GlobalName = searchSettings.value("GlobalName").toString();
		info.IconName = searchSettings.value("Icon").toString();
		info.ScriptName = searchSettings.value("ScriptName").toString();
		m_scriptSearchInfos.append(info);
		searchSettings.endGroup();
		QString scriptFileName = StaticHelpers::CombinePathes(path, info.ScriptName);
		QFile scriptFile(scriptFileName);

		if (scriptFile.open(QIODevice::ReadOnly))
		{
			m_scriptEngine->evaluate(scriptFile.readAll(), scriptFileName);
			QScriptValue jsSearchProvider = m_scriptEngine->globalObject().property(info.GlobalName);

			if (jsSearchProvider.isObject() && jsSearchProvider.isValid())
			{
				CustomScriptSearchProvider* provider = qobject_cast<CustomScriptSearchProvider*>(jsSearchProvider.toQObject());

				if (provider != NULL)
				{
					m_pSearchProviders.append(provider);
					provider->setIcon(QIcon(StaticHelpers::CombinePathes(path, info.IconName)));
					connect(provider, SIGNAL(SearchReady(QList<SearchResult*>)), SLOT(OnSearchReady(QList<SearchResult*>)));
				}
			}

			scriptFile.close();
		}
	}
}
开发者ID:solonix,项目名称:CuteTorrent,代码行数:37,代码来源:SearchEngine.cpp

示例6: scriptValueToVariant

QVariant scriptValueToVariant(const QScriptValue &value)
{
	QVariant var;
	if (value.isBool() || value.isNumber()
		|| value.isString() || value.isVariant()
		|| value.isDate() || value.isRegExp()) {
		var = value.toVariant();
	} else if (value.isArray()) {
		QVariantList list;
		int len = value.property(QLatin1String("length")).toInt32();
		for (int i = 0; i < len; i++)
			list << scriptValueToVariant(value.property(i));
		var = list;
	} else if (value.isObject()) {
		QVariantMap map;
		QScriptValueIterator it(value);
		while (it.hasNext()) {
			it.next();
			map.insert(it.name(), scriptValueToVariant(it.value()));
		}
		var = map;
	}
	return var;
}
开发者ID:CyberSys,项目名称:qutim,代码行数:24,代码来源:scriptengine.cpp

示例7: BuildPostData

QString CustomScriptSearchProvider::BuildPostData(QString token, int category, int page)
{
    QScriptValue obj = m_scriptVal;

    if (obj.isObject())
    {
        m_pEngine = obj.engine();
        m_scriptVal = obj;
        QScriptValue buildUrlFunk = obj.property("BuildPostData");

        if (!buildUrlFunk.isFunction())
        {
            m_pEngine->currentContext()->throwError("No implementation for SearchPlugin.BuildPostData provided.");
            return "";
        }

        QScriptValueList args;
        args << QScriptValue(token) << category << page;
        QScriptValue ret = buildUrlFunk.call(obj, args);
        return ret.toString();
    }

    return "";
}
开发者ID:sunpeng196,项目名称:CuteTorrent,代码行数:24,代码来源:CustomScriptSearchProvider.cpp

示例8: set

/*!
    \qmlmethod ListModel::set(int index, jsobject dict)

    Changes the item at \a index in the list model with the
    values in \a dict. Properties not appearing in \a dict
    are left unchanged.

    \code
        fruitModel.set(3, {"cost": 5.95, "name":"Pizza"})
    \endcode

    The \a index must be an element in the list.

    \sa append()
*/
void QDeclarativeListModel::set(int index, const QScriptValue& valuemap)
{
    if (!valuemap.isObject() || valuemap.isArray()) {
        qmlInfo(this) << tr("set: value is not an object");
        return;
    }
    if (count() == 0 || index > count() || index < 0) {
        qmlInfo(this) << tr("set: index %1 out of range").arg(index);
        return;
    }

    if (index == count()) {
        append(valuemap);
    } else {
        QList<int> roles;
        if (m_flat)
            m_flat->set(index, valuemap, &roles);
        else
            m_nested->set(index, valuemap, &roles);

        if (!m_isWorkerCopy)
            emit itemsChanged(index, 1, roles);
    }
}
开发者ID:cdaffara,项目名称:symbiandump-mw3,代码行数:39,代码来源:qdeclarativelistmodel.cpp

示例9: createObject

QScriptValue QDeclarativeComponentPrivate::createObject(QObject *publicParent, const QScriptValue valuemap)
{
    Q_Q(QDeclarativeComponent);
    QDeclarativeContext* ctxt = q->creationContext();
    if(!ctxt && engine)
        ctxt = engine->rootContext();
    if (!ctxt)
        return QScriptValue(QScriptValue::NullValue);
    QObject* ret = q->beginCreate(ctxt);
    if (!ret) {
        q->completeCreate();
        return QScriptValue(QScriptValue::NullValue);
    }

    if (publicParent) {
        ret->setParent(publicParent);
        QList<QDeclarativePrivate::AutoParentFunction> functions = QDeclarativeMetaType::parentFunctions();

        bool needParent = false;

        for (int ii = 0; ii < functions.count(); ++ii) {
            QDeclarativePrivate::AutoParentResult res = functions.at(ii)(ret, publicParent);
            if (res == QDeclarativePrivate::Parented) {
                needParent = false;
                break;
            } else if (res == QDeclarativePrivate::IncompatibleParent) {
                needParent = true;
            }
        }

        if (needParent)
            qWarning("QDeclarativeComponent: Created graphical object was not placed in the graphics scene.");
    }

    QDeclarativeEnginePrivate *priv = QDeclarativeEnginePrivate::get(engine);
    QDeclarativeData::get(ret, true)->setImplicitDestructible();
    QScriptValue newObject = priv->objectClass->newQObject(ret, QMetaType::QObjectStar);

    if (valuemap.isObject() && !valuemap.isArray()) {
        //Iterate through and assign properties
        QScriptValueIterator it(valuemap);
        while (it.hasNext()) {
            it.next();
            QScriptValue prop = newObject;
            QString propName = it.name();
            int index = propName.indexOf(QLatin1Char('.'));
            if (index > 0) {
                QString subProp = propName;
                int lastIndex = 0;
                while (index > 0) {
                    subProp = propName.mid(lastIndex, index - lastIndex);
                    prop = prop.property(subProp);
                    lastIndex = index + 1;
                    index = propName.indexOf(QLatin1Char('.'), index + 1);
                }
                prop.setProperty(propName.mid(propName.lastIndexOf(QLatin1Char('.')) + 1), it.value());
            } else {
                newObject.setProperty(propName, it.value());
            }
        }
    }

    q->completeCreate();

    return newObject;
}
开发者ID:RobinWuDev,项目名称:Qt,代码行数:66,代码来源:qdeclarativecomponent.cpp

示例10: execute


//.........这里部分代码省略.........

    case QScriptDebuggerCommand::GetBacktrace:
        response.setResult(backend->backtrace());
        break;

    case QScriptDebuggerCommand::GetContextCount:
        response.setResult(backend->contextCount());
        break;

    case QScriptDebuggerCommand::GetContextState: {
        QScriptContext *ctx = backend->context(command.contextIndex());
        if (ctx)
            response.setResult(static_cast<int>(ctx->state()));
        else
            response.setError(QScriptDebuggerResponse::InvalidContextIndex);
    }   break;

    case QScriptDebuggerCommand::GetContextID: {
        int idx = command.contextIndex();
        if ((idx >= 0) && (idx < backend->contextCount()))
            response.setResult(backend->contextIds()[idx]);
        else
            response.setError(QScriptDebuggerResponse::InvalidContextIndex);
    }   break;

    case QScriptDebuggerCommand::GetContextInfo: {
        QScriptContext *ctx = backend->context(command.contextIndex());
        if (ctx)
            response.setResult(QScriptContextInfo(ctx));
        else
            response.setError(QScriptDebuggerResponse::InvalidContextIndex);
    }   break;

    case QScriptDebuggerCommand::GetThisObject: {
        QScriptContext *ctx = backend->context(command.contextIndex());
        if (ctx)
            response.setResult(ctx->thisObject());
        else
            response.setError(QScriptDebuggerResponse::InvalidContextIndex);
    }   break;

    case QScriptDebuggerCommand::GetActivationObject: {
        QScriptContext *ctx = backend->context(command.contextIndex());
        if (ctx)
            response.setResult(ctx->activationObject());
        else
            response.setError(QScriptDebuggerResponse::InvalidContextIndex);
    }   break;

    case QScriptDebuggerCommand::GetScopeChain: {
        QScriptContext *ctx = backend->context(command.contextIndex());
        if (ctx) {
            QScriptDebuggerValueList dest;
            QScriptValueList src = ctx->scopeChain();
            for (int i = 0; i < src.size(); ++i)
                dest.append(src.at(i));
            response.setResult(dest);
        } else {
            response.setError(QScriptDebuggerResponse::InvalidContextIndex);
        }
    }   break;

    case QScriptDebuggerCommand::ContextsCheckpoint: {
        response.setResult(QVariant::fromValue(backend->contextsCheckpoint()));
    }   break;
开发者ID:Blizzard,项目名称:qt4,代码行数:66,代码来源:qscriptdebuggercommandexecutor.cpp

示例11: addType

QScriptValue ScShiftDatabase::addType(QScriptContext *ctx, QScriptEngine *engine)
  {
  ScProfileFunction
  SProperty **propPtr = getThis(ctx);
  SDatabase *db = 0;
  if(propPtr)
    {
    db = (*propPtr)->uncheckedCastTo<SDatabase>();
    }
  if(!db)
    {
    ctx->throwError(QScriptContext::SyntaxError, "Incorrect this argument to SPropertyContainer.size(...);");
    }

  if(ctx->argumentCount() != 1)
    {
    ctx->throwError(QScriptContext::SyntaxError, "Incorrect number of arguments to SDatabase.addType(...);");
    return QScriptValue();
    }

  QScriptValue typeObject = ctx->argument(0);
  if(!typeObject.isObject())
    {
    ctx->throwError(QScriptContext::SyntaxError, "Incorrect argument type to SDatabase.addType(...); expected object");
    return QScriptValue();
    }

  QScriptValue tempObject;

  tempObject = typeObject.property("name");
  QString name = tempObject.toString();
  if(name == "" || STypeRegistry::findType(name) != 0)
    {
    ctx->throwError(QScriptContext::SyntaxError, "Unique, non zero-lengthed string expected as 'name' property");
    return QScriptValue();
    }

  tempObject = typeObject.property("parent");
  const SPropertyInformation *parent = 0;
  if(tempObject.isString())
    {
    parent = STypeRegistry::findType(tempObject.toString());
    }
  if(parent == 0)
    {
    ctx->throwError(QScriptContext::SyntaxError, "Defined property type expected as 'parent' property");
    return QScriptValue();
    }

  tempObject = typeObject.property("version");
  xuint32 version = tempObject.toUInt32();

  xsize endOfUsedMemory = parent->dynamicSize();
  QList<SPropertyInstanceInformation*> properties;

  tempObject = typeObject.property("properties");
  if(tempObject.isArray())
    {
    xuint32 i = 0;
    QScriptValue val = tempObject.property(i);
    QScriptValue tempArrayObject;
    while(val.isObject())
      {
      tempArrayObject = val.property("name");
      if(!tempArrayObject.isString())
        {
        ctx->throwError(QScriptContext::SyntaxError, "String expected as 'properties' array 'name' entry");
        break;
        }
      QString propName = tempArrayObject.toString();

      tempArrayObject = val.property("type");
      const SPropertyInformation *propType = 0;
      if(tempArrayObject.isString())
        {
        propType = STypeRegistry::findType(tempArrayObject.toString());
        }
      if(!propType)
        {
        ctx->throwError(QScriptContext::SyntaxError, "String expected as 'properties' array 'type' entry");
        break;
        }

      SPropertyInstanceInformation::ComputeFunction computeFn = 0;
      tempArrayObject = val.property("compute");
      if(tempArrayObject.isFunction())
        {
        computeFn = computeNode;
        }

      SPropertyInstanceInformation *info = propType->createInstanceInformation()(propType, propName, i, *reinterpret_cast<SProperty SPropertyContainer::**>(&endOfUsedMemory));
      info->setCompute(computeFn);
      info->setExtra(true);

      endOfUsedMemory += propType->size();
      properties << info;

      if(computeFn)
        {
        info->setData(g_computeKey, qVariantFromValue(tempArrayObject));
//.........这里部分代码省略.........
开发者ID:davidmueller13,项目名称:vexx,代码行数:101,代码来源:scshiftdatabase.cpp

示例12: filter

bool EntityEditFilters::filter(glm::vec3& position, EntityItemProperties& propertiesIn, EntityItemProperties& propertiesOut,
        bool& wasChanged, EntityTree::FilterType filterType, EntityItemID& itemID, EntityItemPointer& existingEntity) {
    
    // get the ids of all the zones (plus the global entity edit filter) that the position
    // lies within
    auto zoneIDs = getZonesByPosition(position);
    for (auto id : zoneIDs) {
        if (!itemID.isInvalidID() && id == itemID) {
            continue;
        }
        
        // get the filter pair, etc...  
        _lock.lockForRead();
        FilterData filterData = _filterDataMap.value(id);
        _lock.unlock();
    
        if (filterData.valid()) {
            if (filterData.rejectAll) {
                return false;
            }

            // check to see if this filter wants to filter this message type
            if ((!filterData.wantsToFilterEdit && filterType == EntityTree::FilterType::Edit) ||
                (!filterData.wantsToFilterPhysics && filterType == EntityTree::FilterType::Physics) ||
                (!filterData.wantsToFilterDelete && filterType == EntityTree::FilterType::Delete) ||
                (!filterData.wantsToFilterAdd && filterType == EntityTree::FilterType::Add)) {

                wasChanged = false;
                return true; // accept the message
            }

            auto oldProperties = propertiesIn.getDesiredProperties();
            auto specifiedProperties = propertiesIn.getChangedProperties();
            propertiesIn.setDesiredProperties(specifiedProperties);
            QScriptValue inputValues = propertiesIn.copyToScriptValue(filterData.engine, false, true, true);
            propertiesIn.setDesiredProperties(oldProperties);

            auto in = QJsonValue::fromVariant(inputValues.toVariant()); // grab json copy now, because the inputValues might be side effected by the filter.

            QScriptValueList args;
            args << inputValues;
            args << filterType;

            // get the current properties for then entity and include them for the filter call
            if (existingEntity && filterData.wantsOriginalProperties) {
                auto currentProperties = existingEntity->getProperties(filterData.includedOriginalProperties);
                QScriptValue currentValues = currentProperties.copyToScriptValue(filterData.engine, false, true, true);
                args << currentValues;
            }


            // get the zone properties
            if (filterData.wantsZoneProperties) {
                auto zoneEntity = _tree->findEntityByEntityItemID(id);
                if (zoneEntity) {
                    auto zoneProperties = zoneEntity->getProperties(filterData.includedZoneProperties);
                    QScriptValue zoneValues = zoneProperties.copyToScriptValue(filterData.engine, false, true, true);

                    if (filterData.wantsZoneBoundingBox) {
                        bool success = true;
                        AABox aaBox = zoneEntity->getAABox(success);
                        if (success) {
                            QScriptValue boundingBox = filterData.engine->newObject();
                            QScriptValue bottomRightNear = vec3ToScriptValue(filterData.engine, aaBox.getCorner());
                            QScriptValue topFarLeft = vec3ToScriptValue(filterData.engine, aaBox.calcTopFarLeft());
                            QScriptValue center = vec3ToScriptValue(filterData.engine, aaBox.calcCenter());
                            QScriptValue boundingBoxDimensions = vec3ToScriptValue(filterData.engine, aaBox.getDimensions());
                            boundingBox.setProperty("brn", bottomRightNear);
                            boundingBox.setProperty("tfl", topFarLeft);
                            boundingBox.setProperty("center", center);
                            boundingBox.setProperty("dimensions", boundingBoxDimensions);
                            zoneValues.setProperty("boundingBox", boundingBox);
                        }
                    }

                    // If this is an add or delete, or original properties weren't requested
                    // there won't be original properties in the args, but zone properties need
                    // to be the fourth parameter, so we need to pad the args accordingly
                    int EXPECTED_ARGS = 3;
                    if (args.length() < EXPECTED_ARGS) {
                        args << QScriptValue();
                    }
                    assert(args.length() == EXPECTED_ARGS); // we MUST have 3 args by now!
                    args << zoneValues;
                }
            }

            QScriptValue result = filterData.filterFn.call(_nullObjectForFilter, args);

            if (filterData.uncaughtExceptions()) {
                return false;
            }

            if (result.isObject()) {
                // make propertiesIn reflect the changes, for next filter...
                propertiesIn.copyFromScriptValue(result, false);

                // and update propertiesOut too.  TODO: this could be more efficient...
                propertiesOut.copyFromScriptValue(result, false);
                // Javascript objects are == only if they are the same object. To compare arbitrary values, we need to use JSON.
//.........这里部分代码省略.........
开发者ID:AndrewMeadows,项目名称:hifi,代码行数:101,代码来源:EntityEditFilters.cpp

示例13: arguments

void tst_QScriptContext::arguments()
{
    QScriptEngine eng;

    {
        QScriptValue args = eng.currentContext()->argumentsObject();
        QVERIFY(args.isObject());
        QCOMPARE(args.property("length").toInt32(), 0);
    }
    {
        QScriptValue fun = eng.newFunction(get_arguments);
        eng.globalObject().setProperty("get_arguments", fun);
    }

    for (int x = 0; x < 2; ++x) {
        QString prefix;
        if (x == 0)
            prefix = "";
        else
            prefix = "new ";
        {
            QScriptValue result = eng.evaluate(prefix+"get_arguments()");
            QCOMPARE(result.isArray(), true);
            QCOMPARE(result.property("length").toUInt32(), quint32(0));
        }

        {
            QScriptValue result = eng.evaluate(prefix+"get_arguments(123)");
            QCOMPARE(result.isArray(), true);
            QCOMPARE(result.property("length").toUInt32(), quint32(1));
            QCOMPARE(result.property("0").isNumber(), true);
            QCOMPARE(result.property("0").toNumber(), 123.0);
        }

        {
            QScriptValue result = eng.evaluate(prefix+"get_arguments(\"ciao\", null, true, undefined)");
            QCOMPARE(result.isArray(), true);
            QCOMPARE(result.property("length").toUInt32(), quint32(4));
            QCOMPARE(result.property("0").isString(), true);
            QCOMPARE(result.property("0").toString(), QString("ciao"));
            QCOMPARE(result.property("1").isNull(), true);
            QCOMPARE(result.property("2").isBoolean(), true);
            QCOMPARE(result.property("2").toBoolean(), true);
            QCOMPARE(result.property("3").isUndefined(), true);
        }

        {
            QScriptValue fun = eng.newFunction(get_argumentsObject);
            eng.globalObject().setProperty("get_argumentsObject", fun);
        }

        {
            QScriptValue fun = eng.evaluate("get_argumentsObject");
            QCOMPARE(fun.isFunction(), true);
            QScriptValue result = eng.evaluate(prefix+"get_argumentsObject()");
            QCOMPARE(result.isArray(), false);
            QVERIFY(result.isObject());
            QCOMPARE(result.property("length").toUInt32(), quint32(0));
            QCOMPARE(result.propertyFlags("length"), QScriptValue::SkipInEnumeration);
            QCOMPARE(result.property("callee").strictlyEquals(fun), true);
            QCOMPARE(result.propertyFlags("callee"), QScriptValue::SkipInEnumeration);
            QScriptValue replacedCallee(&eng, 123);
            result.setProperty("callee", replacedCallee);
            QVERIFY(result.property("callee").equals(replacedCallee));
            QScriptValue replacedLength(&eng, 456);
            result.setProperty("length", replacedLength);
            QVERIFY(result.property("length").equals(replacedLength));
            result.setProperty("callee", QScriptValue());
            QVERIFY(!result.property("callee").isValid());
            result.setProperty("length", QScriptValue());
            QVERIFY(!result.property("length").isValid());
        }

        {
            QScriptValue result = eng.evaluate(prefix+"get_argumentsObject(123)");
            eng.evaluate("function nestedArg(x,y,z) { var w = get_argumentsObject('ABC' , x+y+z); return w; }");
            QScriptValue result2 = eng.evaluate("nestedArg(1, 'a', 2)");
            QCOMPARE(result.isArray(), false);
            QVERIFY(result.isObject());
            QCOMPARE(result.property("length").toUInt32(), quint32(1));
            QCOMPARE(result.property("0").isNumber(), true);
            QCOMPARE(result.property("0").toNumber(), 123.0);
            QVERIFY(result2.isObject());
            QCOMPARE(result2.property("length").toUInt32(), quint32(2));
            QCOMPARE(result2.property("0").toString(), QString::fromLatin1("ABC"));
            QCOMPARE(result2.property("1").toString(), QString::fromLatin1("1a2"));
        }

        {
            QScriptValue result = eng.evaluate(prefix+"get_argumentsObject(\"ciao\", null, true, undefined)");
            QCOMPARE(result.isArray(), false);
            QCOMPARE(result.property("length").toUInt32(), quint32(4));
            QCOMPARE(result.property("0").isString(), true);
            QCOMPARE(result.property("0").toString(), QString("ciao"));
            QCOMPARE(result.property("1").isNull(), true);
            QCOMPARE(result.property("2").isBoolean(), true);
            QCOMPARE(result.property("2").toBoolean(), true);
            QCOMPARE(result.property("3").isUndefined(), true);
        }

//.........这里部分代码省略.........
开发者ID:kuailexs,项目名称:symbiandump-mw3,代码行数:101,代码来源:tst_qscriptcontext.cpp

示例14: sendEvent

QScriptValue MainWindow::sendEvent(QScriptContext *context, QScriptEngine *interpreter)
{
    if (context->argumentCount() == 0)
        return QScriptValue::UndefinedValue;

    QScriptValue argPoint = context->argument(0);
    QScriptValue argEvt = context->argument(1);
    QScriptValue argKey = context->argument(2);

    if (!argPoint.isObject())
        return QScriptValue::UndefinedValue;


    // 构造事件触发位置默认值
    int x = 0;
    int y = 0;
    if (argPoint.property("x").isNumber())
        x = argPoint.property("x").toString().toInt();
    if (argPoint.property("y").isNumber())
        y = argPoint.property("y").toString().toInt();

    QPoint targetPoint(x, y);

    // 构造默认值鼠标事件类型默认值
    QMap<QString, QEvent::Type> mouseEventTypeMap;
    mouseEventTypeMap.insert("mousedown", QMouseEvent::MouseButtonPress);
    mouseEventTypeMap.insert("mouseup", QMouseEvent::MouseButtonRelease);
    mouseEventTypeMap.insert("mousemove", QMouseEvent::MouseMove);

    QMouseEvent::Type mouseEvtType = QMouseEvent::MouseButtonRelease;
    QString mouseEvtTypeStr = (!argEvt.isString()) ? "click"
                                                   : argEvt.toString().toLower();
    if (mouseEventTypeMap.contains(mouseEvtTypeStr))
        mouseEvtType = mouseEventTypeMap[mouseEvtTypeStr];

    // 构造辅助按键默认值
    QMap<QString, Qt::KeyboardModifier> keyTypeMap;
    keyTypeMap.insert("shift", Qt::ShiftModifier);
    keyTypeMap.insert("ctrl", Qt::ShiftModifier);
    keyTypeMap.insert("alt", Qt::ShiftModifier);

    Qt::KeyboardModifier keyType = Qt::NoModifier;
    QString keyTypeStr = argKey.toString().toLower();
    if (keyTypeMap.contains(keyTypeStr))
        keyType = keyTypeMap[keyTypeStr];

    // 修复鼠标移动事件的按键值,API原文说明:
    // If the event type is MouseMove,
    // the appropriate button for this event is Qt::NoButton.
    QMouseEvent* event;
    if (mouseEvtType == QMouseEvent::MouseMove) {
        event = new QMouseEvent(mouseEvtType, targetPoint,
                                Qt::NoButton, Qt::NoButton, keyType);
    } else {
        event = new QMouseEvent(mouseEvtType, targetPoint,
                                Qt::LeftButton, Qt::LeftButton, keyType);
    }

    // 对click操作做特殊处理,他是mousdown与mouseup操作的结合体
    if (mouseEvtTypeStr == "click") {
        QMouseEvent* clickEvt1 = new QMouseEvent(QMouseEvent::MouseButtonPress, targetPoint,
                                Qt::LeftButton, Qt::LeftButton, keyType);
        QMouseEvent* clickEvt2 = new QMouseEvent(QMouseEvent::MouseButtonRelease, targetPoint,
                                Qt::LeftButton, Qt::LeftButton, keyType);
        bool b = QApplication::sendEvent(webView, clickEvt1) &&
                 QApplication::sendEvent(webView, clickEvt2);

        delete clickEvt1;
        delete clickEvt2;
        return b;
    }

    bool b = QApplication::sendEvent(webView, event);
    delete event;
    return b;
}
开发者ID:yxq198514,项目名称:berserkJS,代码行数:76,代码来源:mainwindow.cpp

示例15: fromScriptValue

void ReflectiveScriptClass::fromScriptValue(
        const QScriptValue& value, Node_ptr node)
{
    // std::cout << __FUNCTION__ << std::endl;

    using namespace gsim::core;

    const descriptor_type type =
        node->descriptor->get_type();

    node->check_for_initialized();

    holder& hold = node->holder;
    descriptor_base const * descriptor = node->descriptor;

    switch(type)
    {

        case TYPE_STRUCT:
            {
                if (value.isObject())
                {
                    unsigned int count = 
                        node->descriptor->get_children_count();

                    // Search by name
                    for (unsigned int i = 0; i < count; i++) 
                    {
                        const char *childName = descriptor->get_child_name(i);
                        QScriptValue childValue = value.property(childName);

                        if (childValue.isValid())
                            fromScriptValue(childValue, node->children[i]);
                    }
                }
                else
                {
                    std::cerr << "Must be an object!" << std::endl;
                }
            }
            break;

        case TYPE_ARRAY:
            if (descriptor->get_slice()->get_type() == TYPE_CHAR)
            {
                const std::string str(value.toString().toStdString());
                descriptor->from_string(hold, str);
                break;
            }
        case TYPE_SEQUENCE:
            {
                unsigned int length = descriptor->get_length(hold);
                unsigned int newLength = value.property("length").toUInt32();

                if (descriptor->is_variable_length() &&
                        length != newLength)
                {
                    descriptor->set_length(hold, newLength);

                    node->reset();
                    node->check_for_initialized();
                }

                for (unsigned int i = 0; i < newLength && i < length; i++) 
                {
                    fromScriptValue(value.property(i),
                            node->children[i]);
                }
            }
            break;

        case TYPE_BOOL:
            hold.to_value< bool >() = value.toBool();
            break;
        case TYPE_OCTET:
            hold.to_value< unsigned char >() = value.toInteger();
            break;
        case TYPE_CHAR:
            hold.to_value< char >() = value.toInteger();
            break;
        case TYPE_SHORT:
            hold.to_value< short >() = value.toInteger();
            break;
        case TYPE_USHORT:
            hold.to_value< unsigned short >() = value.toUInt16();
            break;
        case TYPE_LONG:
            hold.to_value< int32_t >() = value.toInteger();
            break;
        case TYPE_ULONG:
            hold.to_value< uint32_t >() = value.toUInt32();
            break;
        case TYPE_LONGLONG:
            hold.to_value< int64_t >() = value.toInteger();
            break;
        case TYPE_ULONGLONG:
            hold.to_value< uint64_t >() = value.toInteger();
            break;

        case TYPE_STRING:
//.........这里部分代码省略.........
开发者ID:asenac,项目名称:gsim,代码行数:101,代码来源:ReflectiveScriptClass.cpp


注:本文中的QScriptValue::isObject方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。