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


C++ QDirModel::hasChildren方法代码示例

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


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

示例1: moveCursor

void tst_QColumnView::moveCursor()
{
    QFETCH(bool, reverse);
    if (reverse)
        qApp->setLayoutDirection(Qt::RightToLeft);
    ColumnView view;

    // don't crash
    view.MoveCursor(ColumnView::MoveUp, Qt::NoModifier);

    // don't do anything
    QCOMPARE(view.MoveCursor(ColumnView::MoveEnd, Qt::NoModifier), QModelIndex());

    QDirModel model;
    view.setModel(&model);
    QModelIndex home = model.index(QDir::homePath());
    QModelIndex ci = view.currentIndex();
    QCOMPARE(view.MoveCursor(ColumnView::MoveUp, Qt::NoModifier), QModelIndex());
    QCOMPARE(view.MoveCursor(ColumnView::MoveDown, Qt::NoModifier), QModelIndex());

    // left at root
    view.setCurrentIndex(model.index(0,0));
    ColumnView::PublicCursorAction action = reverse ? ColumnView::MoveRight : ColumnView::MoveLeft;
    QCOMPARE(view.MoveCursor(action, Qt::NoModifier), model.index(0,0));

    // left shouldn't move up
    int i = 0;
    ci = model.index(0, 0);
    while (i < model.rowCount() - 1 && !model.hasChildren(ci))
        ci = model.index(++i, 0);
    QVERIFY(model.hasChildren(ci));
    view.setCurrentIndex(ci);
    action = reverse ? ColumnView::MoveRight : ColumnView::MoveLeft;
    QCOMPARE(view.MoveCursor(action, Qt::NoModifier), ci);

    // now move to the left (i.e. move over one column)
    view.setCurrentIndex(home);
    QCOMPARE(view.MoveCursor(action, Qt::NoModifier), home.parent());

    // right
    action = reverse ? ColumnView::MoveLeft : ColumnView::MoveRight;
    view.setCurrentIndex(ci);
    QModelIndex mc = view.MoveCursor(action, Qt::NoModifier);
    QCOMPARE(mc, model.index(0,0, ci));

    // next one should move down
    QModelIndex idx = model.index(0, 0, ci);
    while (model.hasChildren(idx) && model.rowCount(ci) > idx.row() + 1)
        idx = idx.sibling(idx.row() + 1, idx.column());
    view.setCurrentIndex(idx);
    mc = view.MoveCursor(action, Qt::NoModifier);
    QCOMPARE(mc, idx.sibling(idx.row() + 1, idx.column()));
}
开发者ID:Mr-Kumar-Abhishek,项目名称:qt,代码行数:53,代码来源:tst_qcolumnview.cpp

示例2: selectAll

void tst_QColumnView::selectAll()
{
    ColumnView view;
    view.selectAll();

    QDirModel model;
    view.setModel(&model);
    view.selectAll();
    QVERIFY(view.selectionModel()->selectedIndexes().count() >= 0);

    QModelIndex home = model.index(QDir::homePath());
    view.setCurrentIndex(home);
    view.selectAll();
    QVERIFY(view.selectionModel()->selectedIndexes().count() > 0);

    QModelIndex file;
    for (int i = 0; i < model.rowCount(home); ++i)
        if (!model.hasChildren(model.index(i, 0, home))) {
            file = model.index(i, 0, home);
            break;
        }
    view.setCurrentIndex(file);
    view.selectAll();
    QVERIFY(view.selectionModel()->selectedIndexes().count() > 0);

    view.setCurrentIndex(QModelIndex());
    QVERIFY(view.selectionModel()->selectedIndexes().count() == 0);
}
开发者ID:Mr-Kumar-Abhishek,项目名称:qt,代码行数:28,代码来源:tst_qcolumnview.cpp


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