Details
-
Suggestion
-
Resolution: Out of scope
-
P3: Somewhat important
-
4.4.1
-
None
Description
There's a 'rmdir', 'mkdir' and 'remove' (aka unlink), but no 'touch'. In QFileSystemModel, touch() could be added like this:
QModelIndex QFileSystemModel::touch(const QModelIndex &parent, const QString &name) { Q_D(QFileSystemModel); if (!parent.isValid()) return QModelIndex(); QDir dir(filePath(parent)); if (QFileInfo(dir.filePath(name)).exists()) return index(dir.filePath(name)); QFile file(dir.filePath(name)); if (!file.open(QIODevice::WriteOnly)) return QModelIndex(); file.close(); QFileSystemModelPrivate::QFileSystemNode *parentNode = d->node(parent); d->addNode(parentNode, name); int r = d->findChild(parentNode, QFileSystemModelPrivate::QFileSystemNode(name)); Q_ASSERT(r >= 0); QFileSystemModelPrivate::QFileSystemNode *node = &parentNode->children[r]; node->populate(d->fileInfoGatherer.getInfo(QFileInfo(dir.absolutePath() + QDir::separator() + name))); d->addVisibleFiles(parentNode, QStringList(name)); return d->index(node); }
Possible use case:
void Browser::addButtonClicked() { QModelIndex index = model->touch(parent, newName); treeView->setCurrentIndex(index); treeView->edit(index); }
The user can thereby nicely edit a new file's name directly in the file system view.