本文整理汇总了C++中QDirModel::remove方法的典型用法代码示例。如果您正苦于以下问题:C++ QDirModel::remove方法的具体用法?C++ QDirModel::remove怎么用?C++ QDirModel::remove使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QDirModel
的用法示例。
在下文中一共展示了QDirModel::remove方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: QVERIFY
void tst_QDirModel::task244669_remove()
{
QFile f1(SRCDIR "dirtest/f1.txt");
QVERIFY(f1.open(QIODevice::WriteOnly));
f1.close();
QFile f2(SRCDIR "dirtest/f2.txt");
QVERIFY(f2.open(QIODevice::WriteOnly));
f2.close();
QDirModel model;
model.setReadOnly(false);
QPersistentModelIndex parent = model.index(SRCDIR "dirtest");
QPersistentModelIndex index2 = model.index(SRCDIR "dirtest/f2.txt");
QPersistentModelIndex index1 = model.index(SRCDIR "dirtest/f1.txt");
QVERIFY(parent.isValid());
QVERIFY(index1.isValid());
QVERIFY(index2.isValid());
QCOMPARE(parent.data() , model.index(SRCDIR "dirtest").data());
QCOMPARE(index1.data() , model.index(SRCDIR "dirtest/f1.txt").data());
QCOMPARE(index2.data() , model.index(SRCDIR "dirtest/f2.txt").data());
QVERIFY(model.remove(index1));
QVERIFY(parent.isValid());
QVERIFY(!index1.isValid());
QVERIFY(index2.isValid());
QCOMPARE(parent.data() , model.index(SRCDIR "dirtest").data());
QCOMPARE(index2.data() , model.index(SRCDIR "dirtest/f2.txt").data());
QVERIFY(model.remove(index2));
QVERIFY(parent.isValid());
QVERIFY(!index2.isValid());
QVERIFY(!index1.isValid());
QCOMPARE(parent.data() , model.index(SRCDIR "dirtest").data());
}
示例2: rowsAboutToBeRemoved
void tst_QDirModel::rowsAboutToBeRemoved()
{
QFETCH(QString, test_path);
QFETCH(QStringList, initial_files);
QFETCH(int, remove_row);
QFETCH(QStringList, remove_files);
QFETCH(QStringList, expected_files);
rowsAboutToBeRemoved_cleanup(test_path); // clean up first
QVERIFY(rowsAboutToBeRemoved_init(test_path, initial_files));
QDirModel model;
model.setReadOnly(false);
qRegisterMetaType<QModelIndex>("QModelIndex");
// NOTE: QDirModel will call refresh() when a file is removed. refresh() will reread the entire directory,
// and emit layoutAboutToBeChanged and layoutChange. So, instead of checking for
// rowsAboutToBeRemoved/rowsRemoved we check for layoutAboutToBeChanged/layoutChanged
QSignalSpy spy(&model, SIGNAL(layoutAboutToBeChanged()));
QModelIndex parent = model.index(test_path);
QVERIFY(parent.isValid());
// remove the file
{
QModelIndex index = model.index(remove_row, 0, parent);
QVERIFY(index.isValid());
QVERIFY(model.remove(index));
}
QCOMPARE(spy.count(), 1);
// Compare the result
for (int row = 0; row < expected_files.count(); ++row) {
QModelIndex index = model.index(row, 0, parent);
QString str = index.data().toString();
QCOMPARE(str, expected_files.at(row));
}
QVERIFY(rowsAboutToBeRemoved_cleanup(test_path));
}