From e27fae353ca9a2d4d5054d32bb3a2622ccf9d889 Mon Sep 17 00:00:00 2001 From: Alexander Volkov Date: Thu, 14 Apr 2016 18:57:14 +0300 Subject: QFileSystemModel: fix updating QFileInfo for a node after a file rename Use the correct parent path for the renamed file when creating QFileInfo. It must be a path to the parent directory, not to the root directory of the model. Modify tst_QFileSystemModel::setData() to test renames in subdirs of the root directory of the model. Change-Id: I69d9e3a937616857a81617791ed118af3f6eea05 Task-number: QTBUG-52561 Reviewed-by: Friedemann Kleint Reviewed-by: Lars Knoll --- src/widgets/dialogs/qfilesystemmodel.cpp | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'src/widgets/dialogs') diff --git a/src/widgets/dialogs/qfilesystemmodel.cpp b/src/widgets/dialogs/qfilesystemmodel.cpp index d23737f130..9bf5a502c3 100644 --- a/src/widgets/dialogs/qfilesystemmodel.cpp +++ b/src/widgets/dialogs/qfilesystemmodel.cpp @@ -849,9 +849,11 @@ bool QFileSystemModel::setData(const QModelIndex &idx, const QVariant &value, in if (newName == idx.data().toString()) return true; + const QString parentPath = filePath(parent(idx)); + if (newName.isEmpty() || QDir::toNativeSeparators(newName).contains(QDir::separator()) - || !QDir(filePath(parent(idx))).rename(oldName, newName)) { + || !QDir(parentPath).rename(oldName, newName)) { #ifndef QT_NO_MESSAGEBOX QMessageBox::information(0, QFileSystemModel::tr("Invalid filename"), QFileSystemModel::tr("The name \"%1\" can not be used.

Try using another name, with fewer characters or no punctuations marks.") @@ -878,7 +880,7 @@ bool QFileSystemModel::setData(const QModelIndex &idx, const QVariant &value, in parentNode->visibleChildren.removeAt(visibleLocation); QFileSystemModelPrivate::QFileSystemNode * oldValue = parentNode->children.value(oldName); parentNode->children[newName] = oldValue; - QFileInfo info(d->rootDir, newName); + QFileInfo info(parentPath, newName); oldValue->fileName = newName; oldValue->parent = parentNode; #ifndef QT_NO_FILESYSTEMWATCHER @@ -890,7 +892,7 @@ bool QFileSystemModel::setData(const QModelIndex &idx, const QVariant &value, in parentNode->visibleChildren.insert(visibleLocation, newName); d->delayedSort(); - emit fileRenamed(filePath(idx.parent()), oldName, newName); + emit fileRenamed(parentPath, oldName, newName); } return true; } -- cgit v1.2.3