QFileSystemModel: improve readability of the renaming code
Instead of calling QHash::value(), inserting the return value into the hash with a different name and only many lines later removing the old node, do the extraction into a QScopedPointer, and the insertion into the hash from the QScopedPoiner, keeping the node update in between the two. Avoids the double-lookup of 'oldName', makes it clearer what's going on, and limits the potential for some return between the insertion under the new name and the removal under the old one sneaking in, which would cause a double-delete later in the dtor. Change-Id: Ia2d1cca77c04708421ccb5e594729ec83de85345 Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
This commit is contained in:
parent
4039568837
commit
56734cdf33
@ -904,16 +904,14 @@ bool QFileSystemModel::setData(const QModelIndex &idx, const QVariant &value, in
|
||||
int visibleLocation = parentNode->visibleLocation(parentNode->children.value(indexNode->fileName)->fileName);
|
||||
|
||||
parentNode->visibleChildren.removeAt(visibleLocation);
|
||||
QFileSystemModelPrivate::QFileSystemNode * oldValue = parentNode->children.value(oldName);
|
||||
parentNode->children[newName] = oldValue;
|
||||
oldValue->fileName = newName;
|
||||
oldValue->parent = parentNode;
|
||||
QScopedPointer<QFileSystemModelPrivate::QFileSystemNode> nodeToRename(parentNode->children.take(oldName));
|
||||
nodeToRename->fileName = newName;
|
||||
nodeToRename->parent = parentNode;
|
||||
#ifndef QT_NO_FILESYSTEMWATCHER
|
||||
oldValue->populate(d->fileInfoGatherer.getInfo(QFileInfo(parentPath, newName)));
|
||||
nodeToRename->populate(d->fileInfoGatherer.getInfo(QFileInfo(parentPath, newName)));
|
||||
#endif
|
||||
oldValue->isVisible = true;
|
||||
|
||||
parentNode->children.remove(oldName);
|
||||
nodeToRename->isVisible = true;
|
||||
parentNode->children[newName] = nodeToRename.take();
|
||||
parentNode->visibleChildren.insert(visibleLocation, newName);
|
||||
|
||||
d->delayedSort();
|
||||
|
Loading…
x
Reference in New Issue
Block a user