本文整理汇总了C++中TreeModel::rootItem方法的典型用法代码示例。如果您正苦于以下问题:C++ TreeModel::rootItem方法的具体用法?C++ TreeModel::rootItem怎么用?C++ TreeModel::rootItem使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类TreeModel
的用法示例。
在下文中一共展示了TreeModel::rootItem方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: testIteration
void tst_TreeModel::testIteration()
{
TreeModel<> m;
TreeItem *r = m.rootItem();
TreeItem *group0 = createItem("group0");
TreeItem *group1 = createItem("group1");
TreeItem *item10 = createItem("item10");
TreeItem *item11 = createItem("item11");
TreeItem *item12 = createItem("item12");
group1->appendChild(item10);
group1->appendChild(item11);
TreeItem *group2 = createItem("group2");
TreeItem *item20 = createItem("item20");
TreeItem *item21 = createItem("item21");
TreeItem *item22 = createItem("item22");
r->appendChild(group0);
r->appendChild(group1);
r->appendChild(group2);
group1->appendChild(item12);
group2->appendChild(item20);
group2->appendChild(item21);
group2->appendChild(item22);
QCOMPARE(r->childCount(), 3);
QCOMPARE(countLevelItems(r, 1), 3);
QCOMPARE(countLevelItems(r, 2), 6);
QCOMPARE(countLevelItems(r, 3), 0);
QCOMPARE(countLevelItems(group0, 1), 0);
QCOMPARE(countLevelItems(group1, 1), 3);
QCOMPARE(countLevelItems(group1, 2), 0);
QCOMPARE(countLevelItems(group2, 1), 3);
QCOMPARE(countLevelItems(group2, 2), 0);
}
示例2: testMixed
void tst_TreeModel::testMixed()
{
TreeModel<TreeItem, ItemA, ItemB> m;
TreeItem *r = m.rootItem();
TreeItem *ra;
r->appendChild(new ItemA);
r->appendChild(ra = new ItemA);
ra->appendChild(new ItemB);
ra->appendChild(new ItemB);
int n = 0;
m.forItemsAtLevel<1>([&n](ItemA *) { ++n; });
QCOMPARE(n, 2);
n = 0;
m.forItemsAtLevel<2>([&n](ItemB *) { ++n; });
QCOMPARE(n, 2);
}