diff options
author | Marc Mutz <[email protected]> | 2016-09-30 11:53:07 +0200 |
---|---|---|
committer | Marc Mutz <[email protected]> | 2016-10-28 18:20:08 +0000 |
commit | 56734cdf3383837f1fd59f2a0e8b0f39fcce71f3 (patch) | |
tree | 34b1d8ea9b57efeb23e1fab7fb435044790fe3b1 /src/widgets/dialogs/qfilesystemmodel.cpp | |
parent | 4039568837919fa3e172a71950b235fcf1ddedc7 (diff) |
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 <[email protected]>
Diffstat (limited to 'src/widgets/dialogs/qfilesystemmodel.cpp')
-rw-r--r-- | src/widgets/dialogs/qfilesystemmodel.cpp | 14 |
1 files changed, 6 insertions, 8 deletions
diff --git a/src/widgets/dialogs/qfilesystemmodel.cpp b/src/widgets/dialogs/qfilesystemmodel.cpp index 6e1bee94c44..db1ce3fe0e0 100644 --- a/src/widgets/dialogs/qfilesystemmodel.cpp +++ b/src/widgets/dialogs/qfilesystemmodel.cpp @@ -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(); |