So I came up with something like this. I'm not too excited about the code, but I couldn't think of a better way.
// assumes that path and rootPath use the same dir separator and the same letter case
void PopulatePathInModel(const QString& path, const QString& rootPath, QFileSystemModel* model)
{
{
if (!currPath.
isEmpty()) currPath
+= QDir::separator();
currPath += part;
// no need to populate dirs outside of our area of interest
if (!currPath.startsWith(rootPath)) continue;
{
if (idx.isValid())
{
while (model->canFetchMore(idx))
{
model->fetchMore(idx);
}
}
}
}
}
// assumes that path and rootPath use the same dir separator and the same letter case
void PopulatePathInModel(const QString& path, const QString& rootPath, QFileSystemModel* model)
{
QStringList parts = path.split(QDir::separator());
QString currPath;
foreach (QString part, parts)
{
if (!currPath.isEmpty()) currPath += QDir::separator();
currPath += part;
// no need to populate dirs outside of our area of interest
if (!currPath.startsWith(rootPath)) continue;
if (QFileInfo(currPath).isDir())
{
QModelIndex idx = model->index(currPath);
if (idx.isValid())
{
while (model->canFetchMore(idx))
{
model->fetchMore(idx);
}
}
}
}
}
To copy to clipboard, switch view to plain text mode
Bookmarks