Exemplo n.º 1
0
void tst_QDirModel::rmdir()
{
    QFETCH(QString, dirName);
    QFETCH(bool, rmdirSuccess);
    QFETCH(int, rowCount);

    QDirModel model;
    model.setReadOnly(false);

    QModelIndex parent = model.index(SRCDIR  "/dirtest");
    QVERIFY(parent.isValid());
    QCOMPARE(model.rowCount(parent), 1); // start out with only 'test1' - in's in the depot

    QModelIndex index;
    if (rmdirSuccess) {
        index = model.mkdir(parent, dirName);
        QVERIFY(index.isValid());
    }

    int rows = model.rowCount(parent);
    bool success = model.rmdir(index);

    if (!success) { // cleanup
        QDir dirtests(SRCDIR  "/dirtests/");
        dirtests.rmdir(dirName);
    }

    QCOMPARE(rows, rowCount);
    QCOMPARE(success, rmdirSuccess);
}
Exemplo n.º 2
0
void tst_QDirModel::filter()
{
    QDirModel model;
    model.setNameFilters(QStringList() << "*.nada");
    QModelIndex index = model.index(SRCDIR "test");
    QCOMPARE(model.rowCount(index), 0);
    QModelIndex index2 = model.index(SRCDIR "test/file01.tst");
    QVERIFY(!index2.isValid());
    QCOMPARE(model.rowCount(index), 0);
}
Exemplo n.º 3
0
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()));
}
Exemplo n.º 4
0
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);
}
Exemplo n.º 5
0
void tst_QColumnView::indexAt()
{
    QColumnView view;
    QCOMPARE(view.indexAt(QPoint(0,0)), QModelIndex());
    QDirModel model;
    view.setModel(&model);

    QModelIndex home = model.index(QDir::homePath());
    QModelIndex homeFile = model.index(0, 0, home);
    if (!homeFile.isValid())
        return;
    view.setRootIndex(home);
    QRect rect = view.visualRect(QModelIndex());
    QVERIFY(!rect.isValid());
    rect = view.visualRect(homeFile);
    QVERIFY(rect.isValid());

    QModelIndex child;
    for (int i = 0; i < model.rowCount(home); ++i) {
        child = model.index(i, 0, home);
        rect = view.visualRect(child);
        QVERIFY(rect.isValid());
        if (i > 0)
            QVERIFY(rect.top() > 0);
        QCOMPARE(view.indexAt(rect.center()), child);

        view.selectionModel()->select(child, QItemSelectionModel::SelectCurrent);
        view.setCurrentIndex(child);
        qApp->processEvents();
        QTest::qWait(200);

        // test that the second row doesn't start at 0
        if (model.rowCount(child) > 0) {
            child = model.index(0, 0, child);
            QVERIFY(child.isValid());
            rect = view.visualRect(child);
            QVERIFY(rect.isValid());
            QVERIFY(rect.left() > 0);
            QCOMPARE(view.indexAt(rect.center()), child);
            break;
        }
    }
}
Exemplo n.º 6
0
void tst_QColumnView::visualRegionForSelection()
{
    ColumnView view;
    QItemSelection emptyItemSelection;
    QCOMPARE(QRegion(), view.visualRegionForSelection(emptyItemSelection));

    // a region that isn't empty
    QDirModel model;
    view.setModel(&model);

    // On Windows CE the home directory might actually be empty.
#ifndef Q_OS_WINCE
    QString location = QDir::homePath();
#else
    QString location = QLatin1String("/Windows");
#endif

    QModelIndex home = model.index(location);
    QVERIFY(model.rowCount(home) > 1);
    QItemSelection itemSelection(model.index(0, 0, home), model.index(model.rowCount(home) - 1, 0, home));
    QVERIFY(QRegion() != view.visualRegionForSelection(itemSelection));
}
Exemplo n.º 7
0
void tst_QDirModel::mkdir()
{
    QFETCH(QString, dirName);
    QFETCH(bool, mkdirSuccess);
    QFETCH(int, rowCount);

    QDirModel model;
    model.setReadOnly(false);

    QModelIndex parent = model.index(SRCDIR "dirtest");
    QVERIFY(parent.isValid());
    QCOMPARE(model.rowCount(parent), 1); // start out with only 'test1' - in's in the depot

    QModelIndex index = model.mkdir(parent, dirName);
    bool success = index.isValid();
    int rows = model.rowCount(parent);

    if (success && !model.rmdir(index))
        QVERIFY(QDir(SRCDIR "dirtests").rmdir(dirName));

    QCOMPARE(rows, rowCount);
    QCOMPARE(success, mkdirSuccess);
}
Exemplo n.º 8
0
int main(int argc, char *argv[])
{
    QApplication app(argc, argv);

    QWidget *window = new QWidget;
    QVBoxLayout *layout = new QVBoxLayout(window);
    QLabel *title = new QLabel("Some items from the directory model", window);
    title->setBackgroundRole(QPalette::Base);
    title->setMargin(8);
    layout->addWidget(title);
    
//! [0]
    QDirModel *model = new QDirModel;
    QModelIndex parentIndex = model->index(QDir::currentPath());
    int numRows = model->rowCount(parentIndex);
//! [0]

//! [1]
    for (int row = 0; row < numRows; ++row) {
        QModelIndex index = model->index(row, 0, parentIndex);
//! [1]

//! [2]
        QString text = model->data(index, Qt::DisplayRole).toString();
        // Display the text in a widget.
//! [2]

        QLabel *label = new QLabel(text, window);
        layout->addWidget(label);
//! [3]
    }
//! [3]

    window->setWindowTitle("A simple model example");
    window->show();
    return app.exec();
}