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 <thiago.macieira@intel.com>
This commit is contained in:
parent
8a25006fad
commit
1bde907a23
@ -85,11 +85,7 @@ public:
|
|||||||
explicit QFileSystemNode(const QString &filename = QString(), QFileSystemNode *p = 0)
|
explicit QFileSystemNode(const QString &filename = QString(), QFileSystemNode *p = 0)
|
||||||
: fileName(filename), populatedChildren(false), isVisible(false), dirtyChildrenIndex(-1), parent(p), info(0) {}
|
: fileName(filename), populatedChildren(false), isVisible(false), dirtyChildrenIndex(-1), parent(p), info(0) {}
|
||||||
~QFileSystemNode() {
|
~QFileSystemNode() {
|
||||||
QHash<QString, QFileSystemNode*>::const_iterator i = children.constBegin();
|
qDeleteAll(children);
|
||||||
while (i != children.constEnd()) {
|
|
||||||
delete i.value();
|
|
||||||
++i;
|
|
||||||
}
|
|
||||||
delete info;
|
delete info;
|
||||||
info = 0;
|
info = 0;
|
||||||
parent = 0;
|
parent = 0;
|
||||||
@ -164,32 +160,30 @@ public:
|
|||||||
void updateIcon(QFileIconProvider *iconProvider, const QString &path) {
|
void updateIcon(QFileIconProvider *iconProvider, const QString &path) {
|
||||||
if (info)
|
if (info)
|
||||||
info->icon = iconProvider->icon(QFileInfo(path));
|
info->icon = iconProvider->icon(QFileInfo(path));
|
||||||
QHash<QString, QFileSystemNode *>::const_iterator iterator;
|
for (QFileSystemNode *child : qAsConst(children)) {
|
||||||
for(iterator = children.constBegin() ; iterator != children.constEnd() ; ++iterator) {
|
|
||||||
//On windows the root (My computer) has no path so we don't want to add a / for nothing (e.g. /C:/)
|
//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.isEmpty()) {
|
||||||
if (path.endsWith(QLatin1Char('/')))
|
if (path.endsWith(QLatin1Char('/')))
|
||||||
iterator.value()->updateIcon(iconProvider, path + iterator.value()->fileName);
|
child->updateIcon(iconProvider, path + child->fileName);
|
||||||
else
|
else
|
||||||
iterator.value()->updateIcon(iconProvider, path + QLatin1Char('/') + iterator.value()->fileName);
|
child->updateIcon(iconProvider, path + QLatin1Char('/') + child->fileName);
|
||||||
} else
|
} else
|
||||||
iterator.value()->updateIcon(iconProvider, iterator.value()->fileName);
|
child->updateIcon(iconProvider, child->fileName);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void retranslateStrings(QFileIconProvider *iconProvider, const QString &path) {
|
void retranslateStrings(QFileIconProvider *iconProvider, const QString &path) {
|
||||||
if (info)
|
if (info)
|
||||||
info->displayType = iconProvider->type(QFileInfo(path));
|
info->displayType = iconProvider->type(QFileInfo(path));
|
||||||
QHash<QString, QFileSystemNode *>::const_iterator iterator;
|
for (QFileSystemNode *child : qAsConst(children)) {
|
||||||
for(iterator = children.constBegin() ; iterator != children.constEnd() ; ++iterator) {
|
|
||||||
//On windows the root (My computer) has no path so we don't want to add a / for nothing (e.g. /C:/)
|
//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.isEmpty()) {
|
||||||
if (path.endsWith(QLatin1Char('/')))
|
if (path.endsWith(QLatin1Char('/')))
|
||||||
iterator.value()->retranslateStrings(iconProvider, path + iterator.value()->fileName);
|
child->retranslateStrings(iconProvider, path + child->fileName);
|
||||||
else
|
else
|
||||||
iterator.value()->retranslateStrings(iconProvider, path + QLatin1Char('/') + iterator.value()->fileName);
|
child->retranslateStrings(iconProvider, path + QLatin1Char('/') + child->fileName);
|
||||||
} else
|
} else
|
||||||
iterator.value()->retranslateStrings(iconProvider, iterator.value()->fileName);
|
child->retranslateStrings(iconProvider, child->fileName);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user