Simplify QFileSystemModel::remove by using QDir::removeRecursively
This also fixes it in case of hidden or system files, which were missing from the filter (found by Denis Kovalskiy). Change-Id: Ic12de12ec51c20de52d040514e90be5e783add43 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>bb10
parent
104debb662
commit
aabbd27dda
|
|
@ -199,32 +199,10 @@ QT_BEGIN_NAMESPACE
|
|||
|
||||
bool QFileSystemModel::remove(const QModelIndex &aindex)
|
||||
{
|
||||
//### TODO optim
|
||||
QString path = filePath(aindex);
|
||||
const QString path = filePath(aindex);
|
||||
QFileSystemModelPrivate * d = const_cast<QFileSystemModelPrivate*>(d_func());
|
||||
d->fileInfoGatherer.removePath(path);
|
||||
QDirIterator it(path,
|
||||
QDir::AllDirs | QDir:: Files | QDir::NoDotAndDotDot,
|
||||
QDirIterator::Subdirectories);
|
||||
QStringList children;
|
||||
while (it.hasNext())
|
||||
children.prepend(it.next());
|
||||
children.append(path);
|
||||
|
||||
bool error = false;
|
||||
for (int i = 0; i < children.count(); ++i) {
|
||||
QFileInfo info(children.at(i));
|
||||
QModelIndex modelIndex = index(children.at(i));
|
||||
if (info.isDir()) {
|
||||
QDir dir;
|
||||
if (children.at(i) != path)
|
||||
error |= remove(modelIndex);
|
||||
error |= rmdir(modelIndex);
|
||||
} else {
|
||||
error |= QFile::remove(filePath(modelIndex));
|
||||
}
|
||||
}
|
||||
return error;
|
||||
return QDir(path).removeRecursively();
|
||||
}
|
||||
|
||||
/*!
|
||||
|
|
|
|||
|
|
@ -921,10 +921,8 @@ void tst_QFileSystemModel::mkdir()
|
|||
int oldRow = idx.row();
|
||||
QTest::qWait(WAITTIME);
|
||||
idx = model->index(newFolderPath);
|
||||
QDir cleanup(tmp);
|
||||
QVERIFY(cleanup.rmdir(QLatin1String("NewFoldermkdirtest3")));
|
||||
QVERIFY(cleanup.rmdir(QLatin1String("NewFoldermkdirtest5")));
|
||||
bestatic.rmdir(newFolderPath);
|
||||
QVERIFY(model->remove(idx));
|
||||
QVERIFY(!bestatic.exists());
|
||||
QVERIFY(0 != idx.row());
|
||||
QCOMPARE(oldRow, idx.row());
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue