本文整理汇总了C++中QDirModel::rowCount方法的典型用法代码示例。如果您正苦于以下问题:C++ QDirModel::rowCount方法的具体用法?C++ QDirModel::rowCount怎么用?C++ QDirModel::rowCount使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QDirModel
的用法示例。
在下文中一共展示了QDirModel::rowCount方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: rmdir
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);
}
示例2: filter
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);
}
示例3: 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()));
}
示例4: 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);
}
示例5: indexAt
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;
}
}
}
示例6: visualRegionForSelection
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));
}
示例7: mkdir
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);
}
示例8: main
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();
}