I have updated filterAcceptsRow for FileListViewModelProxy, and now when it hits a directory, it recursively dives in, and matches on filterText_, however, the display results are not what is expected.
bool FileListViewModelProxy::filterAcceptsRow(int sourceRow, const QModelIndex& sourceParent) const {
QFileSystemModel* fileSystemModel = qobject_cast<QFileSystemModel*>(sourceModel());
if (sourceParent == fileSystemModel->index(fileSystemModel->rootPath())) {
}
QModelIndex index
= sourceModel
()->index
(sourceRow,
0, sourceParent
);
QFileInfo fileInfo
= fileSystemModel
->fileInfo
(index
);
QString fileName
= fileInfo.
fileName();
if (fileName.startsWith(filterText_))
return true;
if (fileInfo.isDir())
return searchDirectory(fileInfo);
}
bool FileListViewModelProxy::filterAcceptsRow(int sourceRow, const QModelIndex& sourceParent) const {
QFileSystemModel* fileSystemModel = qobject_cast<QFileSystemModel*>(sourceModel());
if (sourceParent == fileSystemModel->index(fileSystemModel->rootPath())) {
return QSortFilterProxyModel::filterAcceptsRow(sourceRow, sourceParent);
}
QModelIndex index = sourceModel()->index(sourceRow, 0, sourceParent);
QFileInfo fileInfo = fileSystemModel->fileInfo(index);
QString fileName = fileInfo.fileName();
if (fileName.startsWith(filterText_))
return true;
if (fileInfo.isDir())
return searchDirectory(fileInfo);
return QSortFilterProxyModel::filterAcceptsRow(sourceRow, sourceParent);
}
To copy to clipboard, switch view to plain text mode
bool FileListViewModelProxy
::searchDirectory(QFileInfo fileInfo
) const { QString filePath
= fileInfo.
filePath();
QDir dir
(fileInfo.
filePath());
QString dirName
= fileInfo.
fileName();
QFileInfoList fileList
= dir.
entryInfoList(QDir::Files |
QDir::Dirs |
QDir::NoDotAndDotDot);
for (int i = 0; i < fileList.size(); i++) {
QString fileName
= fileInfo.
fileName();
if (fileName.startsWith(filterText_))
return true;
if (fileInfo.isDir()) {
return searchDirectory(fileInfo);
}
}
return false;
}
bool FileListViewModelProxy::searchDirectory(QFileInfo fileInfo) const {
QString filePath = fileInfo.filePath();
QDir dir(fileInfo.filePath());
QString dirName = fileInfo.fileName();
QFileInfoList fileList = dir.entryInfoList(QDir::Files | QDir::Dirs | QDir::NoDotAndDotDot);
for (int i = 0; i < fileList.size(); i++) {
QFileInfo fileInfo = fileList[i];
QString fileName = fileInfo.fileName();
if (fileName.startsWith(filterText_))
return true;
if (fileInfo.isDir()) {
return searchDirectory(fileInfo);
}
}
return false;
}
To copy to clipboard, switch view to plain text mode
Bookmarks