本文整理汇总了C++中TreeNode::attachSubject方法的典型用法代码示例。如果您正苦于以下问题:C++ TreeNode::attachSubject方法的具体用法?C++ TreeNode::attachSubject怎么用?C++ TreeNode::attachSubject使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类TreeNode
的用法示例。
在下文中一共展示了TreeNode::attachSubject方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: TreeNode
void Qtilities::Testing::TestObserver::testRecursiveAttachmentContained() {
// Example tree using tree node classes to simplify test:
TreeNode* rootNode = new TreeNode("Root");
TreeNode* childNode = rootNode->addNode("Parent Node");
TreeItem* item = childNode->addItem("Child Item");
// Now create and add a contained observer:
TreeNode* containedNode = new TreeNode("Contained Node");
containedNode->setParent(item);
QVERIFY(containedNode->attachSubject(rootNode) == false);
}
示例2: main
int main(int argc, char *argv[])
{
QtilitiesApplication a(argc, argv);
QtilitiesApplication::setOrganizationName("YourOrganization");
QtilitiesApplication::setOrganizationDomain("YourDomain");
QtilitiesApplication::setApplicationName("My Application");
QtilitiesApplication::setApplicationVersion("1.0");
// Set the application export version:
QtilitiesApplication::setApplicationExportVersion(0);
// We need to set a QWidget as the application's main window in order for proxy actions to work:
QWidget* proxy_widget = new QWidget;
QtilitiesApplication::setMainWindow(proxy_widget);
// Register our VersionDetails class in the Qtilities factory:
FactoryItemID version_info_id("Version Details");
OBJECT_MANAGER->registerFactoryInterface(&VersionDetails::factory,version_info_id);
// Next create a TreeNode with a couple of our classes attached to it:
TreeNode* node = new TreeNode("TestNode");
VersionDetails* ver1 = new VersionDetails;
ver1->setDescriptionBrief("Version 1 Brief");
ver1->setDescriptionDetailed("Version 1 Brief");
ver1->setVersionMajor(0);
ver1->setVersionMinor(0);
VersionDetails* ver2 = new VersionDetails;
ver2->setDescriptionBrief("Version 2 Brief");
ver2->setDescriptionDetailed("Version 2 Brief");
ver2->setVersionMajor(1);
ver2->setVersionMinor(2);
node->attachSubject(ver1);
node->attachSubject(ver2);
node->addNode("NewNode");
// Next export the node to a file:
node->saveToFile("Output_Version_0.xml");
node->setApplicationExportVersion(1);
node->saveToFile("Output_Version_1.xml");
ObserverWidget* view = new ObserverWidget(node);
view->show();
return a.exec();
}
示例3: itrA
void Qtilities::Testing::TestSubjectIterator::testIterationComplex() {
TreeNode node;
TreeNode* nodeA = node.addNode("A");
TreeNode* nodeB = node.addNode("B");
nodeA->addItem("1");
TreeItem* shared_item = nodeA->addItem("2");
nodeA->addItem("3");
nodeB->addItem("4");
nodeB->addItem("5");
nodeB->attachSubject(shared_item);
nodeB->addItem("6");
// If we want to iterate through the subjects in nodeA:
SubjectIterator<QObject> itrA(nodeA,SubjectIterator<QObject>::IterateChildren);
QVERIFY(itrA.current() != 0);
// In this case item1 will be skipped:
QStringList testListA;
testListA << itrA.current()->objectName();
while (itrA.hasNext()) {
testListA << itrA.next()->objectName();
}
QCOMPARE(testListA.count(), 3);
QCOMPARE(testListA.at(0), QString("1"));
QCOMPARE(testListA.at(1), QString("2"));
QCOMPARE(testListA.at(2), QString("3"));
// If we want to iterate through the subjects in nodeB:
SubjectIterator<QObject> itrB(nodeB,SubjectIterator<QObject>::IterateChildren);
// In this case item1 will be skipped:
QStringList testListB;
testListB << itrB.current()->objectName();
while (itrB.hasNext()) {
testListB << itrB.next()->objectName();
}
QCOMPARE(testListB.count(), 4);
QCOMPARE(testListB.at(0), QString("4"));
QCOMPARE(testListB.at(1), QString("5"));
QCOMPARE(testListB.at(2), QString("2"));
QCOMPARE(testListB.at(3), QString("6"));
// If we want to iterate through the subjects in nodeB:
SubjectIterator<QObject> itrC(shared_item,nodeB);
// In this case item1 will be skipped:
QStringList testListC;
testListC << itrC.current()->objectName();
while (itrC.hasNext()) {
testListC << itrC.next()->objectName();
}
QCOMPARE(testListC.count(), 2);
QCOMPARE(testListC.at(0), QString("2"));
QCOMPARE(testListC.at(1), QString("6"));
// If we want to iterate through the subjects in nodeB:
SubjectIterator<QObject> itrD(shared_item,nodeA);
// In this case item1 will be skipped:
QStringList testListD;
testListD << itrD.current()->objectName();
while (itrD.hasNext()) {
testListD << itrD.next()->objectName();
}
QCOMPARE(testListD.count(), 2);
QCOMPARE(testListD.at(0), QString("2"));
QCOMPARE(testListD.at(1), QString("3"));
}