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


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

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


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

示例1: updateElement

void ExposedModel::updateElement(const QString &key, QScriptValue value)
{
    tinia::model::StateSchemaElement schemaElement = m_model->getStateSchemaElement(key.toStdString());
    std::string type = schemaElement.getXSDType();

    if(type.find("xsd:") != std::string::npos) {
        type = type.substr(4);
    }


    if (type == std::string("double")) {
        m_model->updateElement(key.toStdString(), double(value.toNumber()));
    }
    else if(type==std::string("integer"))  {
        m_model->updateElement(key.toStdString(), int(value.toNumber()));
    }
    else if(type==std::string("bool")) {
        m_model->updateElement(key.toStdString(), value.toBool());
    }
    else if(type==std::string("string")) {
        m_model->updateElement(key.toStdString(), value.toString().toStdString());
    }
    else if(type==std::string("complexType")) {
        m_model->updateElement(key.toStdString(), static_cast<Viewer*>(value.toQObject())->viewer());
    }

}
开发者ID:KjeFre,项目名称:tinia,代码行数:27,代码来源:ExposedModel.cpp

示例2: add

	QScriptValue SegmentCollectionPrototype::add(QScriptValue startTime, QScriptValue duration, QScriptValue videoIndex)
	{
		if (!this->_editor->getVideoCount())
        {
            return this->throwError(QString(QT_TR_NOOP("A video must be open to perform this operation.")));
        }

        QScriptValue result;

        while (true)
        {
            result = this->validateNumber("videoIndex", videoIndex, 0, this->_editor->getVideoCount());

            if (!result.isUndefined())
            {
                break;
            }

            this->_editor->addSegment(videoIndex.toNumber(), startTime.toNumber(), duration.toNumber());

            result = this->_editor->getNbSegment() - 1;

            break;
        }

        return result;
	}
开发者ID:AlexanderStohr,项目名称:avidemux2,代码行数:27,代码来源:SegmentCollectionPrototype.cpp

示例3: animVariantMapFromScriptValue

void AnimVariantMap::animVariantMapFromScriptValue(const QScriptValue& source) {
    if (QThread::currentThread() != source.engine()->thread()) {
        qCWarning(animation) << "Cannot examine Javacript object from non-script thread" << QThread::currentThread();
        Q_ASSERT(false);
        return;
    }
    // POTENTIAL OPTIMIZATION: cache the types we've seen. I.e, keep a dictionary mapping property names to an enumeration of types.
    // Whenever we identify a new outbound type in animVariantMapToScriptValue above, or a new inbound type in the code that follows here,
    // we would enter it into the dictionary. Then switch on that type here, with the code that follow being executed only if
    // the type is not known. One problem with that is that there is no checking that two different script use the same name differently.
    QScriptValueIterator property(source);
    // Note: QScriptValueIterator iterates only over source's own properties. It does not follow the prototype chain.
    while (property.hasNext()) {
        property.next();
        QScriptValue value = property.value();
        if (value.isBool()) {
            set(property.name(), value.toBool());
        } else if (value.isString()) {
            set(property.name(), value.toString());
        } else if (value.isNumber()) {
            int asInteger = value.toInt32();
            float asFloat = value.toNumber();
            if (asInteger == asFloat) {
                set(property.name(), asInteger);
            } else {
                set(property.name(), asFloat);
            }
        } else { // Try to get x,y,z and possibly w
            if (value.isObject()) {
                QScriptValue x = value.property("x");
                if (x.isNumber()) {
                    QScriptValue y = value.property("y");
                    if (y.isNumber()) {
                        QScriptValue z = value.property("z");
                        if (z.isNumber()) {
                            QScriptValue w = value.property("w");
                            if (w.isNumber()) {
                                set(property.name(), glm::quat(w.toNumber(), x.toNumber(), y.toNumber(), z.toNumber()));
                            } else {
                                set(property.name(), glm::vec3(x.toNumber(), y.toNumber(), z.toNumber()));
                            }
                            continue; // we got either a vector or quaternion object, so don't fall through to warning
                        }
                    }
                }
            }
            qCWarning(animation) << "Ignoring unrecognized data" << value.toString() << "for animation property" << property.name();
            Q_ASSERT(false);
        }
    }
}
开发者ID:AndrewMeadows,项目名称:hifi,代码行数:51,代码来源:AnimVariant.cpp

示例4: pos

QScriptValue PHIBaseItem::pos( const QScriptValue &x, const QScriptValue &y )
{
    if ( !x.isValid() ) {
        QPointF p=adjustedPos();
        QScriptValue v=scriptEngine()->newObject();
        v.setProperty( L1( "left" ), qRound( realX()+p.x() ) );
        v.setProperty( L1( "top" ), qRound( realY()+p.y() ) );
        v.setProperty( L1( "x" ), qRound( realX() ) );
        v.setProperty( L1( "y" ), qRound( realY() ) );
        return v;
    }
    setPos( x.toNumber(), y.toNumber() );
    return self();
}
开发者ID:Phisketeer,项目名称:phisketeer,代码行数:14,代码来源:phiitemhandler.cpp

示例5: add

QScriptValue UniversalInputDialogScript::add(const QScriptValue& def, const QScriptValue& description, const QScriptValue& id){
	QWidget* w = 0;
	if (def.isArray()) {
		QStringList options;
		QScriptValueIterator it(def);
		while (it.hasNext()) {
			it.next();
			if (it.flags() & QScriptValue::SkipInEnumeration)
				continue;
			if (it.value().isString() || it.value().isNumber()) options << it.value().toString();
			else engine->currentContext()->throwError("Invalid default value in array (must be string or number): "+it.value().toString());
		}
		w = addComboBox(ManagedProperty::fromValue(options), description.toString());
	} else if (def.isBool()) {
		w = addCheckBox(ManagedProperty::fromValue(def.toBool()), description.toString());
	} else if (def.isNumber()) {
		w = addDoubleSpinBox(ManagedProperty::fromValue(def.toNumber()), description.toString());
	} else if (def.isString()) {
		w = addLineEdit(ManagedProperty::fromValue(def.toString()), description.toString());
	} else {	
		
		engine->currentContext()->throwError(tr("Invalid default value: %1").arg(def.toString()));
		return QScriptValue();
	}
	if (id.isValid()) properties.last().name = id.toString();
	return engine->newQObject(w);
}
开发者ID:svn2github,项目名称:texstudio-trunk,代码行数:27,代码来源:scriptengine.cpp

示例6: TextImportDialog_script_changeFontSize

QScriptValue TextImportDialog_script_changeFontSize(QScriptContext *context, QScriptEngine */*engine*/)
{
	QObject *obj = context->argument(0).toQObject();
	if(!obj)
	{
		qDebug() << "TextImportDialog_script_changeFontSize(textbox,fontSize): Must give Slide (QObject) as first argument"; 
		return QScriptValue(QScriptValue::NullValue);
	}
	TextBoxItem *text = dynamic_cast<TextBoxItem*>(obj);
	if(!text)
	{
		qDebug() << "TextImportDialog_script_changeFontSize(textbox,fontSize): First argument is not a Slide"; 
		return QScriptValue(QScriptValue::NullValue);
	}
	
	
	QScriptValue fontSizeVal = context->argument(1);
	if(!fontSizeVal.isNumber())
	{
		qDebug() << "TextImportDialog_script_changeFontSize(textbox,fontSize): Second argument is not a number"; 
		return QScriptValue(QScriptValue::NullValue);
	}
	double size = (double)fontSizeVal.toNumber();
	text->changeFontSize(size);
	return QScriptValue(text->findFontSize());
}
开发者ID:dtbinh,项目名称:dviz,代码行数:26,代码来源:TextImportDialog.cpp

示例7: thisObject

void tst_QScriptContext::thisObject()
{
    QScriptEngine eng;

    QScriptValue fun = eng.newFunction(get_thisObject);
    eng.globalObject().setProperty("get_thisObject", fun);

    {
        QScriptValue result = eng.evaluate("get_thisObject()");
        QCOMPARE(result.isObject(), true);
        QCOMPARE(result.toString(), QString("[object global]"));
    }

    {
        QScriptValue result = eng.evaluate("get_thisObject.apply(new Number(123))");
        QCOMPARE(result.isObject(), true);
        QCOMPARE(result.toNumber(), 123.0);
    }

    {
        QScriptValue obj = eng.newObject();
        eng.currentContext()->setThisObject(obj);
        QVERIFY(eng.currentContext()->thisObject().equals(obj));
        eng.currentContext()->setThisObject(QScriptValue());
        QVERIFY(eng.currentContext()->thisObject().equals(obj));

        QScriptEngine eng2;
        QScriptValue obj2 = eng2.newObject();
        QTest::ignoreMessage(QtWarningMsg, "QScriptContext::setThisObject() failed: cannot set an object created in a different engine");
        eng.currentContext()->setThisObject(obj2);
    }
}
开发者ID:kuailexs,项目名称:symbiandump-mw3,代码行数:32,代码来源:tst_qscriptcontext.cpp

示例8: callee

void tst_QScriptContext::callee()
{
    QScriptEngine eng;

    {
        QScriptValue fun = eng.newFunction(get_callee);
        fun.setProperty("foo", QScriptValue(&eng, "bar"));
        eng.globalObject().setProperty("get_callee", fun);

        QScriptValue result = eng.evaluate("get_callee()");
        QCOMPARE(result.isFunction(), true);
        QCOMPARE(result.property("foo").toString(), QString("bar"));
    }

    // callee when toPrimitive() is called internally
    {
        QScriptValue fun = eng.newFunction(store_callee_and_return_primitive);
        QScriptValue obj = eng.newObject();
        obj.setProperty("toString", fun);
        QVERIFY(!obj.property("callee").isValid());
        (void)obj.toString();
        QVERIFY(obj.property("callee").isFunction());
        QVERIFY(obj.property("callee").strictlyEquals(fun));

        obj.setProperty("callee", QScriptValue());
        QVERIFY(!obj.property("callee").isValid());
        obj.setProperty("valueOf", fun);
        (void)obj.toNumber();
        QVERIFY(obj.property("callee").isFunction());
        QVERIFY(obj.property("callee").strictlyEquals(fun));
    }
}
开发者ID:kuailexs,项目名称:symbiandump-mw3,代码行数:32,代码来源:tst_qscriptcontext.cpp

示例9:

double MainWindow::str2double(QString s){

    QScriptEngine e;
    s.replace(QRegExp("PI"),"Math.PI");
    QScriptValue v = e.evaluate(s);
    return v.toNumber();
}
开发者ID:msis,项目名称:bubbibex,代码行数:7,代码来源:mainwindow.cpp

示例10: fromScriptValue

void PointerEvent::fromScriptValue(const QScriptValue& object, PointerEvent& event) {
    if (object.isObject()) {
        QScriptValue type = object.property("type");
        QString typeStr = type.isString() ? type.toString() : "Move";
        if (typeStr == "Press") {
            event._type = Press;
        } else if (typeStr == "DoublePress") {
            event._type = DoublePress;
        } else if (typeStr == "Release") {
            event._type = Release;
        } else {
            event._type = Move;
        }

        QScriptValue id = object.property("id");
        event._id = id.isNumber() ? (uint32_t)id.toNumber() : 0;

        glm::vec2 pos2D;
        vec2FromScriptValue(object.property("pos2D"), event._pos2D);

        glm::vec3 pos3D;
        vec3FromScriptValue(object.property("pos3D"), event._pos3D);

        glm::vec3 normal;
        vec3FromScriptValue(object.property("normal"), event._normal);

        glm::vec3 direction;
        vec3FromScriptValue(object.property("direction"), event._direction);

        QScriptValue button = object.property("button");
        QString buttonStr = type.isString() ? button.toString() : "NoButtons";

        if (buttonStr == "Primary") {
            event._button = PrimaryButton;
        } else if (buttonStr == "Secondary") {
            event._button = SecondaryButton;
        } else if (buttonStr == "Tertiary") {
            event._button = TertiaryButton;
        } else {
            event._button = NoButtons;
        }

        bool primary = object.property("isPrimaryHeld").toBool();
        bool secondary = object.property("isSecondaryHeld").toBool();
        bool tertiary = object.property("isTertiaryHeld").toBool();
        event._buttons = 0;
        if (primary) {
            event._buttons |= PrimaryButton;
        }
        if (secondary) {
            event._buttons |= SecondaryButton;
        }
        if (tertiary) {
            event._buttons |= TertiaryButton;
        }

        event._keyboardModifiers = (Qt::KeyboardModifiers)(object.property("keyboardModifiers").toUInt32());
    }
}
开发者ID:ZappoMan,项目名称:hifi,代码行数:59,代码来源:PointerEvent.cpp

示例11: evalDouble

double EnvWrap::evalDouble( const QString& nm )
{
	QScriptValue result = evalExp(nm);
	if (result.isNumber())
		return result.toNumber();
	else
		throw ExpressionHasNotThisTypeException("Double",nm);
	return double();
}
开发者ID:Jerdak,项目名称:meshlab,代码行数:9,代码来源:scriptinterface.cpp

示例12: return

const std::string QCATs::sprintf(const CSmallString& fname, QScriptContext* p_context,
                                QScriptEngine* p_engine)
{
    if( p_context->argumentCount() < 1 ) {
        CSmallString error;
        error << fname << "(format[,value1,value2,..]) - illegal number of arguments, at least one is expected";
        p_context->throwError(QString(error));
        return("");
    }

    QString format;
    format = p_context->argument(0).toString();

    // prepare format
    boost::format my_format;
    try {
        my_format.parse(format.toStdString());
    } catch(...) {
        CSmallString error;
        error << fname << "(format[,value1,value2,..]) - unable to parse format";
        p_context->throwError(QString(error));
        return("");
    }

    if( my_format.expected_args() != (p_context->argumentCount() - 1) ){
        CSmallString error;
        error << fname << "(format[,value1,value2,..]) - format requires different number of values (";
        error << my_format.expected_args() << ") than it is provided (" << (p_context->argumentCount() - 1) << ")";
        p_context->throwError(QString(error));
        return("");
    }

    // parse individual arguments
    for(int i=0; i < my_format.expected_args(); i++ ){
        QScriptValue val = p_context->argument(i+1);

        try {
            if( val.isNumber() ){
                double sval = val.toNumber();
                my_format % sval;
            } else {
                QString sval = val.toString();
                my_format % sval.toStdString();
            }
        } catch(...){
            CSmallString error;
            error << fname << "(format[,value1,value2,..]) - unable to process argument (";
            error << i + 1 << ")";
            p_context->throwError(QString(error));
            return("");
        }
    }

    // return string
    return( my_format.str() );
}
开发者ID:kulhanek,项目名称:cats,代码行数:56,代码来源:QCATs.cpp

示例13: throwValue

void tst_QScriptContext::throwValue()
{
    QScriptEngine eng;

    QScriptValue fun = eng.newFunction(throw_value);
    eng.globalObject().setProperty("throw_value", fun);

    {
        QScriptValue result = eng.evaluate("throw_value(123)");
        QCOMPARE(result.isError(), false);
        QCOMPARE(result.toNumber(), 123.0);
        QCOMPARE(eng.hasUncaughtException(), true);
    }
}
开发者ID:kuailexs,项目名称:symbiandump-mw3,代码行数:14,代码来源:tst_qscriptcontext.cpp

示例14: breakpointDataFromScriptValue

static void breakpointDataFromScriptValue(const QScriptValue &in, QScriptBreakpointData &out)
{
    QScriptValue scriptId = in.property(QString::fromLatin1("scriptId"));
    if (scriptId.isValid())
        out.setScriptId((qint64)scriptId.toNumber());
    out.setFileName(in.property(QString::fromLatin1("fileName")).toString());
    out.setLineNumber(in.property(QString::fromLatin1("lineNumber")).toInt32());
    QScriptValue enabled = in.property(QString::fromLatin1("enabled"));
    if (enabled.isValid())
        out.setEnabled(enabled.toBoolean());
    QScriptValue singleShot = in.property(QString::fromLatin1("singleShot"));
    if (singleShot.isValid())
        out.setSingleShot(singleShot.toBoolean());
    out.setIgnoreCount(in.property(QString::fromLatin1("ignoreCount")).toInt32());
    out.setCondition(in.property(QString::fromLatin1("condition")).toString());
}
开发者ID:Drakey83,项目名称:steamlink-sdk,代码行数:16,代码来源:qscriptdebuggerconsole.cpp

示例15: assignAndCopyConstruct_test

void tst_QScriptValueGenerated::assignAndCopyConstruct_test(const char *, const QScriptValue &value)
{
    QScriptValue copy(value);
    QCOMPARE(copy.strictlyEquals(value), !value.isNumber() || !qIsNaN(value.toNumber()));
    QCOMPARE(copy.engine(), value.engine());

    QScriptValue assigned = copy;
    QCOMPARE(assigned.strictlyEquals(value), !copy.isNumber() || !qIsNaN(copy.toNumber()));
    QCOMPARE(assigned.engine(), assigned.engine());

    QScriptValue other(!value.toBool());
    assigned = other;
    QVERIFY(!assigned.strictlyEquals(copy));
    QVERIFY(assigned.strictlyEquals(other));
    QCOMPARE(assigned.engine(), other.engine());
}
开发者ID:venkatarajasekhar,项目名称:Qt,代码行数:16,代码来源:tst_qscriptvalue.cpp


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