From 1bde907a230d11bef023a61cfe9eafd856cf992d Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Fri, 30 Sep 2016 11:57:15 +0200 Subject: QFileSystemNode: simplify three loops over the children hash In the dtor, simply call qDeleteAll(children) instead of looping manually. In updateIcon() and retranslateStrings() replace a manual loop with C++11 ranged for. At least I only saw 'iterator' everywhere (who names an iterator 'iterator' instead of 'it'??). Change-Id: Ib0047dece3c88244bb4364cd4491cd04514a91bb Reviewed-by: Thiago Macieira --- src/widgets/dialogs/qfilesystemmodel_p.h | 24 +++++++++--------------- 1 file changed, 9 insertions(+), 15 deletions(-) (limited to 'src/widgets') diff --git a/src/widgets/dialogs/qfilesystemmodel_p.h b/src/widgets/dialogs/qfilesystemmodel_p.h index 92398d981f..e7149a3097 100644 --- a/src/widgets/dialogs/qfilesystemmodel_p.h +++ b/src/widgets/dialogs/qfilesystemmodel_p.h @@ -85,11 +85,7 @@ public: explicit QFileSystemNode(const QString &filename = QString(), QFileSystemNode *p = 0) : fileName(filename), populatedChildren(false), isVisible(false), dirtyChildrenIndex(-1), parent(p), info(0) {} ~QFileSystemNode() { - QHash::const_iterator i = children.constBegin(); - while (i != children.constEnd()) { - delete i.value(); - ++i; - } + qDeleteAll(children); delete info; info = 0; parent = 0; @@ -164,32 +160,30 @@ public: void updateIcon(QFileIconProvider *iconProvider, const QString &path) { if (info) info->icon = iconProvider->icon(QFileInfo(path)); - QHash::const_iterator iterator; - for(iterator = children.constBegin() ; iterator != children.constEnd() ; ++iterator) { + for (QFileSystemNode *child : qAsConst(children)) { //On windows the root (My computer) has no path so we don't want to add a / for nothing (e.g. /C:/) if (!path.isEmpty()) { if (path.endsWith(QLatin1Char('/'))) - iterator.value()->updateIcon(iconProvider, path + iterator.value()->fileName); + child->updateIcon(iconProvider, path + child->fileName); else - iterator.value()->updateIcon(iconProvider, path + QLatin1Char('/') + iterator.value()->fileName); + child->updateIcon(iconProvider, path + QLatin1Char('/') + child->fileName); } else - iterator.value()->updateIcon(iconProvider, iterator.value()->fileName); + child->updateIcon(iconProvider, child->fileName); } } void retranslateStrings(QFileIconProvider *iconProvider, const QString &path) { if (info) info->displayType = iconProvider->type(QFileInfo(path)); - QHash::const_iterator iterator; - for(iterator = children.constBegin() ; iterator != children.constEnd() ; ++iterator) { + for (QFileSystemNode *child : qAsConst(children)) { //On windows the root (My computer) has no path so we don't want to add a / for nothing (e.g. /C:/) if (!path.isEmpty()) { if (path.endsWith(QLatin1Char('/'))) - iterator.value()->retranslateStrings(iconProvider, path + iterator.value()->fileName); + child->retranslateStrings(iconProvider, path + child->fileName); else - iterator.value()->retranslateStrings(iconProvider, path + QLatin1Char('/') + iterator.value()->fileName); + child->retranslateStrings(iconProvider, path + QLatin1Char('/') + child->fileName); } else - iterator.value()->retranslateStrings(iconProvider, iterator.value()->fileName); + child->retranslateStrings(iconProvider, child->fileName); } } -- cgit v1.2.3