summaryrefslogtreecommitdiffstats
path: root/src/widgets/dialogs
diff options
context:
space:
mode:
authorAlexander Volkov <a.volkov@rusbitech.ru>2016-04-14 18:57:14 +0300
committerAlexander Volkov <a.volkov@rusbitech.ru>2016-04-22 09:49:53 +0000
commite27fae353ca9a2d4d5054d32bb3a2622ccf9d889 (patch)
tree58874939b22062d2923b832f144ca6c82e3b412b /src/widgets/dialogs
parentea64dc9a113a850334fbf47ca2cdc3b447945c25 (diff)
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 <Friedemann.Kleint@qt.io> Reviewed-by: Lars Knoll <lars.knoll@theqtcompany.com>
Diffstat (limited to 'src/widgets/dialogs')
-rw-r--r--src/widgets/dialogs/qfilesystemmodel.cpp8
1 files changed, 5 insertions, 3 deletions
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("<b>The name \"%1\" can not be used.</b><p>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;
}