本文整理汇总了C++中QScriptValue::toInteger方法的典型用法代码示例。如果您正苦于以下问题:C++ QScriptValue::toInteger方法的具体用法?C++ QScriptValue::toInteger怎么用?C++ QScriptValue::toInteger使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QScriptValue
的用法示例。
在下文中一共展示了QScriptValue::toInteger方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: edgeAccessMethodsWithTypes
void TestKernel::edgeAccessMethodsWithTypes()
{
GraphDocumentPtr document = GraphDocument::create();
document->edgeTypes().first()->setDirection(EdgeType::Bidirectional);
NodePtr nodeA = Node::create(document);
NodePtr nodeB = Node::create(document);
NodePtr nodeC = Node::create(document);
EdgePtr edgeAB = Edge::create(nodeA, nodeB);
EdgePtr edgeBC = Edge::create(nodeB, nodeC);
// test edge type
EdgeTypePtr edgeTypeB = EdgeType::create(document);
edgeTypeB->setDirection(EdgeType::Unidirectional);
edgeBC->setType(edgeTypeB);
// test nodes
Kernel kernel;
QString script;
QScriptValue result;
script = QString("Document.nodes()[1].edges(%1).length;").arg(edgeTypeB->id());
result = kernel.execute(document, script);
QCOMPARE(result.toInteger(), qreal(1));
script = QString("Document.nodes()[1].inEdges(%1).length;").arg(edgeTypeB->id());
result = kernel.execute(document, script);
QCOMPARE(result.toInteger(), qreal(0));
script = QString("Document.nodes()[1].outEdges(%1).length;").arg(edgeTypeB->id());
result = kernel.execute(document, script);
QCOMPARE(result.toInteger(), qreal(1));
// cleanup
document->destroy();
}
示例2: distance
void TestKernel::distance()
{
GraphDocumentPtr document = GraphDocument::create();
NodePtr nodeA = Node::create(document);
NodePtr nodeB = Node::create(document);
NodePtr nodeC = Node::create(document);
EdgePtr edgeAB = Edge::create(nodeA, nodeB);
EdgePtr edgeBC = Edge::create(nodeB, nodeC);
document->edgeTypes().first()->addDynamicProperty("dist");
document->edgeTypes().first()->setDirection(EdgeType::Bidirectional);
edgeAB->setDynamicProperty("dist", "1");
edgeBC->setDynamicProperty("dist", "1");
// test nodes
Kernel kernel;
QString script;
QScriptValue result;
script = "Document.nodes()[0].distance(\"dist\", Document.nodes())[2];";
result = kernel.execute(document, script);
QCOMPARE(result.toInteger(), qreal(2));
script = "Document.nodes()[2].distance(\"dist\", Document.nodes())[0];";
result = kernel.execute(document, script);
QCOMPARE(result.toInteger(), qreal(2));
// cleanup
document->destroy();
}
示例3: edgeAccessMethods
void TestKernel::edgeAccessMethods()
{
GraphDocumentPtr document = GraphDocument::create();
document->edgeTypes().first()->setDirection(EdgeType::Unidirectional);
NodePtr nodeA = Node::create(document);
NodePtr nodeB = Node::create(document);
EdgePtr edge = Edge::create(nodeA, nodeB);
// test nodes
Kernel kernel;
QString script;
QScriptValue result;
script = "Document.nodes()[0].edges().length;";
result = kernel.execute(document, script);
QCOMPARE(result.toInteger(), qreal(1));
script = "Document.nodes()[0].inEdges().length;";
result = kernel.execute(document, script);
QCOMPARE(result.toInteger(), qreal(0));
script = "Document.nodes()[0].outEdges().length;";
result = kernel.execute(document, script);
QCOMPARE(result.toInteger(), qreal(1));
// cleanup
document->destroy();
}
示例4: graphObjectAccessWithTypes
void TestKernel::graphObjectAccessWithTypes()
{
GraphDocumentPtr document = GraphDocument::create();
NodeTypePtr nodeTypeB = NodeType::create(document);
EdgeTypePtr edgeTypeB = EdgeType::create(document);
NodePtr nodeA = Node::create(document);
NodePtr nodeB = Node::create(document);
NodePtr nodeC = Node::create(document);
EdgePtr edgeAB = Edge::create(nodeA, nodeB);
EdgePtr edgeBC = Edge::create(nodeB, nodeC);
// setup types
nodeA->setType(nodeTypeB);
edgeAB->setType(edgeTypeB);
// test nodes
Kernel kernel;
QString script;
QScriptValue result;
script = QString("Document.nodes(%1).length;").arg(nodeTypeB->id());
result = kernel.execute(document, script);
QCOMPARE(result.toInteger(), qreal(1));
script = QString("Document.edges(%1).length;").arg(edgeTypeB->id());
result = kernel.execute(document, script);
QCOMPARE(result.toInteger(), qreal(1));
// cleanup
document->destroy();
}
示例5: createMenu
QAction *KWin::AbstractScript::scriptValueToAction(QScriptValue &value, QMenu *parent)
{
QScriptValue titleValue = value.property(QStringLiteral("text"));
QScriptValue checkableValue = value.property(QStringLiteral("checkable"));
QScriptValue checkedValue = value.property(QStringLiteral("checked"));
QScriptValue itemsValue = value.property(QStringLiteral("items"));
QScriptValue triggeredValue = value.property(QStringLiteral("triggered"));
if (!titleValue.isValid()) {
// title not specified - does not make any sense to include
return nullptr;
}
const QString title = titleValue.toString();
const bool checkable = checkableValue.isValid() && checkableValue.toBool();
const bool checked = checkable && checkedValue.isValid() && checkedValue.toBool();
// either a menu or a menu item
if (itemsValue.isValid()) {
if (!itemsValue.isArray()) {
// not an array, so cannot be a menu
return nullptr;
}
QScriptValue lengthValue = itemsValue.property(QStringLiteral("length"));
if (!lengthValue.isValid() || !lengthValue.isNumber() || lengthValue.toInteger() == 0) {
// length property missing
return nullptr;
}
return createMenu(title, itemsValue, parent);
} else if (triggeredValue.isValid()) {
// normal item
return createAction(title, checkable, checked, triggeredValue, parent);
}
return nullptr;
}
示例6: slNewPiece
void PlugScript::slNewPiece(InterfaceTetris tpD)
{
ifTetris=&tpD;
// QByteArray tpCur( tpD.aBoard);
iWaiting=0;
QScriptEngine scrptEngine;
QFile file("d:\\ETK\\Projects\\qt\\tetrisqt\\tetris.js");
if (!file.open(QFile::ReadOnly)) {
QMessageBox::critical(0,
QString("File open error"),
"Can not open the script file:"+file.fileName() ,
QMessageBox::Yes
);
}
QLabel lb;
QScriptValue objTetris=scrptEngine.newQObject(&lb);
scrptEngine.globalObject().setProperty("objTetris", objTetris);
//objTetris.setProperty("mBoard",tpCur);
//scrptEngine.globalObject().setProperty("iTetris",interfaceTetris);
//QScriptValue val=scrptEngine.evaluate("");
QString str=QLatin1String(file.readAll());
scrptEngine.globalObject().setProperty("foo", 123);
QScriptValue result =
scrptEngine.evaluate(str);
// Q_ASSERT(result);
if (result.isError()) {
QMessageBox::critical(0,
"Evaluating error",
result.toString(),
QMessageBox::Yes
);
}
iLines++;
emit sgDbg(result.toInteger());
}
示例7: graphObjectAccess
void TestKernel::graphObjectAccess()
{
GraphDocumentPtr document = GraphDocument::create();
NodePtr nodeA = Node::create(document);
NodePtr nodeB = Node::create(document);
EdgePtr edge = Edge::create(nodeA, nodeB);
// test nodes
Kernel kernel;
QString script;
QScriptValue result;
script = "Document.nodes().length;";
result = kernel.execute(document, script);
QCOMPARE(result.toInteger(), qreal(2));
script = "Document.edges().length;";
result = kernel.execute(document, script);
QCOMPARE(result.toInteger(), qreal(1));
// cleanup
document->destroy();
}
示例8: nodeAccessMethods
void TestKernel::nodeAccessMethods()
{
GraphDocumentPtr document = GraphDocument::create();
NodePtr node = Node::create(document);
node->setId(42);
// test nodes
Kernel kernel;
QString script;
QScriptValue result;
script = "Document.node(42).id;";
result = kernel.execute(document, script);
QCOMPARE(result.toInteger(), qreal(42));
// cleanup
document->destroy();
}
示例9: 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:
//.........这里部分代码省略.........
示例10: callback
void ScriptExtender::callback(QObject* obj, int id , void** args){
//use id to determine the right script and function
SEngine *e = NULL;
int i;
for (i = 0; i < engineList.size(); i++){
if (engineList.at(i)->is(obj, slotlist.at(id).filename)){
e = engineList.at(i);
qDebug() << "engine found";
break;
}
}
if(!e){
//new engine
e = new SEngine(obj, slotlist.at(id).filename);
engineList << e;
}
//qDebug() << e << obj << id << args;
//
QRegExp tx( "(.+)\\((.*)\\)");
tx.indexIn(slotlist.at(id).signature,0);
qDebug() << tx.cap( 1 )<< " arg sig" << tx.cap( 2 );
//ip->newQObject (obj)
QScriptValueList qsarglist = QScriptValueList();// << QScriptValue (e->eng, obj); // first argument always obj)
QStringList al = tx.cap( 2 ).split(",");
for ( int i = 0; i < al.size(); i++){
if(al.at(i) == "int"){
qsarglist << QScriptValue (&e->eng, *reinterpret_cast< int(*)>(args[i+1]));
qDebug() << "add int to args" << *reinterpret_cast< int(*)>(args[i+1]);
}
else if (al.at(i) == "double"){
qsarglist << QScriptValue (&e->eng, *reinterpret_cast< double(*)>(args[i+1]));
}
else if (al.at(i) == "float"){
qsarglist << QScriptValue (&e->eng, *reinterpret_cast< float(*)>(args[i+1]));
}
else if (al.at(i) == "QString"){
qsarglist << QScriptValue (&e->eng,*reinterpret_cast< const QString(*)>(args[i+1]));
}
else if (al.at(i) == "QObject*"){
qsarglist << e->eng.newQObject (*reinterpret_cast< QObject*(*)>(args[i+1])) ;//QScriptValue (&e->eng,*reinterpret_cast< QObject*(*)>(args[i+1]));
}
}
//qDebug() << qsarglist;
QScriptValue f = e->eng.globalObject().property(tx.cap( 1 )).call(e->eng.globalObject(),qsarglist);
if (e->eng.hasUncaughtException()) {
int line = e->eng.uncaughtExceptionLineNumber();
QMessageBox::critical ( 0, QString("Script error"), QString("Error processing Script at Line %1 ").arg(line));
}
if (!args[0])return; //skip return value
if(slotlist.at(id).type == "int"){
*reinterpret_cast< int*>(args[0]) = f.toInteger();
}
else if(slotlist.at(id).type == "float"){
*reinterpret_cast< float*>(args[0]) = f.toNumber();
}
else if(slotlist.at(id).type == "double"){
*reinterpret_cast< double*>(args[0]) = f.toNumber();
}
else if(slotlist.at(id).type == "QString"){
*reinterpret_cast< QString*>(args[0]) = f.toString();
}
else if(slotlist.at(id).type == "QObject*"){
*reinterpret_cast< QObject**>(args[0]) = f.toQObject();
}
}
示例11: neighborshipsWithTypes
void TestKernel::neighborshipsWithTypes()
{
// this test is the same as withouth types but we add an backedge of another type that
// changes the results if types are not respected
GraphDocumentPtr document = GraphDocument::create();
EdgeTypePtr typeA = document->edgeTypes().first();
EdgeTypePtr typeB = EdgeType::create(document);
typeA->setDirection(EdgeType::Unidirectional);
typeA->setId(1);
typeB->setDirection(EdgeType::Unidirectional);
typeB->setId(2);
NodePtr nodeA = Node::create(document);
NodePtr nodeB = Node::create(document);
EdgePtr edgeAB = Edge::create(nodeA, nodeB);
EdgePtr edgeBA = Edge::create(nodeB, nodeA);
edgeBA->setType(typeB);
// test nodes
Kernel kernel;
QString script;
QScriptValue result;
// test with unidirectional edge
script = "Document.nodes()[0].neighbors(1).length;";
result = kernel.execute(document, script);
QCOMPARE(result.toInteger(), qreal(1));
script = "Document.nodes()[1].neighbors(1).length;";
result = kernel.execute(document, script);
QCOMPARE(result.toInteger(), qreal(1));
script = "Document.nodes()[0].successors(1).length;";
result = kernel.execute(document, script);
QCOMPARE(result.toInteger(), qreal(1));
script = "Document.nodes()[1].successors(1).length;";
result = kernel.execute(document, script);
QCOMPARE(result.toInteger(), qreal(0));
script = "Document.nodes()[0].predecessors(1).length;";
result = kernel.execute(document, script);
QCOMPARE(result.toInteger(), qreal(0));
script = "Document.nodes()[1].predecessors(1).length;";
result = kernel.execute(document, script);
QCOMPARE(result.toInteger(), qreal(1));
// test with bidirectional edge
document->edgeTypes().first()->setDirection(EdgeType::Bidirectional);
script = "Document.nodes()[0].neighbors(1).length;";
result = kernel.execute(document, script);
QCOMPARE(result.toInteger(), qreal(1));
script = "Document.nodes()[1].neighbors(1).length;";
result = kernel.execute(document, script);
QCOMPARE(result.toInteger(), qreal(1));
script = "Document.nodes()[0].successors(1).length;";
result = kernel.execute(document, script);
QCOMPARE(result.toInteger(), qreal(1));
script = "Document.nodes()[1].successors(1).length;";
result = kernel.execute(document, script);
QCOMPARE(result.toInteger(), qreal(1));
script = "Document.nodes()[0].predecessors(1).length;";
result = kernel.execute(document, script);
QCOMPARE(result.toInteger(), qreal(1));
script = "Document.nodes()[1].predecessors(1).length;";
result = kernel.execute(document, script);
QCOMPARE(result.toInteger(), qreal(1));
// cleanup
document->destroy();
}
示例12: neighborships
void TestKernel::neighborships()
{
GraphDocumentPtr document = GraphDocument::create();
document->edgeTypes().first()->setDirection(EdgeType::Unidirectional);
NodePtr nodeA = Node::create(document);
NodePtr nodeB = Node::create(document);
EdgePtr edge = Edge::create(nodeA, nodeB);
// test nodes
Kernel kernel;
QString script;
QScriptValue result;
// test with unidirectional edge
script = "Document.nodes()[0].neighbors().length;";
result = kernel.execute(document, script);
QCOMPARE(result.toInteger(), qreal(1));
script = "Document.nodes()[1].neighbors().length;";
result = kernel.execute(document, script);
QCOMPARE(result.toInteger(), qreal(1));
script = "Document.nodes()[0].successors().length;";
result = kernel.execute(document, script);
QCOMPARE(result.toInteger(), qreal(1));
script = "Document.nodes()[1].successors().length;";
result = kernel.execute(document, script);
QCOMPARE(result.toInteger(), qreal(0));
script = "Document.nodes()[0].predecessors().length;";
result = kernel.execute(document, script);
QCOMPARE(result.toInteger(), qreal(0));
script = "Document.nodes()[1].predecessors().length;";
result = kernel.execute(document, script);
QCOMPARE(result.toInteger(), qreal(1));
// test with bidirectional edge
document->edgeTypes().first()->setDirection(EdgeType::Bidirectional);
script = "Document.nodes()[0].neighbors().length;";
result = kernel.execute(document, script);
QCOMPARE(result.toInteger(), qreal(1));
script = "Document.nodes()[1].neighbors().length;";
result = kernel.execute(document, script);
QCOMPARE(result.toInteger(), qreal(1));
script = "Document.nodes()[0].successors().length;";
result = kernel.execute(document, script);
QCOMPARE(result.toInteger(), qreal(1));
script = "Document.nodes()[1].successors().length;";
result = kernel.execute(document, script);
QCOMPARE(result.toInteger(), qreal(1));
script = "Document.nodes()[0].predecessors().length;";
result = kernel.execute(document, script);
QCOMPARE(result.toInteger(), qreal(1));
script = "Document.nodes()[1].predecessors().length;";
result = kernel.execute(document, script);
QCOMPARE(result.toInteger(), qreal(1));
// cleanup
document->destroy();
}