本文整理汇总了C++中NodePtr::dynamicProperty方法的典型用法代码示例。如果您正苦于以下问题:C++ NodePtr::dynamicProperty方法的具体用法?C++ NodePtr::dynamicProperty怎么用?C++ NodePtr::dynamicProperty使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类NodePtr
的用法示例。
在下文中一共展示了NodePtr::dynamicProperty方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: nodeDynamicProperties
void TestKernel::nodeDynamicProperties()
{
GraphDocumentPtr document = GraphDocument::create();
NodeTypePtr type = document->nodeTypes().first();
NodePtr node = Node::create(document);
type->addDynamicProperty("propertyA");
type->addDynamicProperty("propertyB");
type->addDynamicProperty("propertyC");
// test nodes
Kernel kernel;
QString script;
QScriptValue result;
// property read-access from script
node->setDynamicProperty("propertyA", "1");
script = "Document.nodes()[0].propertyA;";
result = kernel.execute(document, script);
QCOMPARE(result.toString().toInt(), 1);
// property local write/read-access in script
script = "Document.nodes()[0].propertyB = 2; Document.nodes()[0].propertyB";
kernel.execute(document, script);
QCOMPARE(node->dynamicProperty("propertyB").toInt(), 2);
// property write-access from script
script = "Document.nodes()[0].propertyC = 3";
kernel.execute(document, script);
QCOMPARE(node->dynamicProperty("propertyC").toInt(), 3);
// cleanup
document->destroy();
}
示例2: automaticScriptObjectPropertyGeneration
void TestKernel::automaticScriptObjectPropertyGeneration()
{
GraphDocumentPtr document = GraphDocument::create();
NodePtr nodeA = Node::create(document);
NodePtr nodeB = Node::create(document);
EdgePtr edge = Edge::create(nodeA, nodeB);
Kernel kernel;
QString script;
QScriptValue result;
// For edges/nodes we can assign arbitrary dynamic properties during
// script execution. However, they exist only during execution and are removed
// at the end of the execution.
script = "Document.nodes()[0].nonRegProp=1; Document.nodes()[0].nonRegProp;";
result = kernel.execute(document, script);
QCOMPARE(result.toString().toInt(), 1);
QCOMPARE(nodeA->dynamicProperty("nonRegProp").toInt(), 0);
script = "Document.edges()[0].nonRegProp=1; Document.edges()[0].nonRegProp;";
result = kernel.execute(document, script);
QCOMPARE(result.toString().toInt(), 1);
QCOMPARE(edge->dynamicProperty("nonRegProp").toInt(), 0);
// cleanup
document->destroy();
}
示例3: foreach
foreach(const NodePtr &node, nodes) {
QString name = node->dynamicProperty("name").toString();
int index = nodeNames.indexOf(name);
if (index == -1) {
qCDebug(GRAPHTHEORY_FILEFORMAT) << "Node "<< name << " was created unnecessarily.";
}
QVERIFY(index != -1);
nodeNames.removeAt(index);
}