diff options
Diffstat (limited to 'src/widgets/dialogs')
-rw-r--r-- | src/widgets/dialogs/qfilesystemmodel.cpp | 53 |
1 files changed, 16 insertions, 37 deletions
diff --git a/src/widgets/dialogs/qfilesystemmodel.cpp b/src/widgets/dialogs/qfilesystemmodel.cpp index 00f466e227..6bbd464398 100644 --- a/src/widgets/dialogs/qfilesystemmodel.cpp +++ b/src/widgets/dialogs/qfilesystemmodel.cpp @@ -243,7 +243,7 @@ QModelIndex QFileSystemModel::index(int row, int column, const QModelIndex &pare Q_ASSERT(parentNode); // now get the internal pointer for the index - QString childName = parentNode->visibleChildren[d->translateVisibleLocation(parentNode, row)]; + const QString &childName = parentNode->visibleChildren.at(d->translateVisibleLocation(parentNode, row)); const QFileSystemModelPrivate::QFileSystemNode *indexNode = parentNode->children.value(childName); Q_ASSERT(indexNode); @@ -811,8 +811,7 @@ QString QFileSystemModelPrivate::name(const QModelIndex &index) const #endif !resolvedSymLinks.isEmpty() && dirNode->isSymLink(/* ignoreNtfsSymLinks = */ true)) { QString fullPath = QDir::fromNativeSeparators(filePath(index)); - if (resolvedSymLinks.contains(fullPath)) - return resolvedSymLinks[fullPath]; + return resolvedSymLinks.value(fullPath, dirNode->fileName); } return dirNode->fileName; } @@ -1127,10 +1126,10 @@ public: return false; } - bool operator()(const QPair<QFileSystemModelPrivate::QFileSystemNode*, int> &l, - const QPair<QFileSystemModelPrivate::QFileSystemNode*, int> &r) const + bool operator()(const QFileSystemModelPrivate::QFileSystemNode *l, + const QFileSystemModelPrivate::QFileSystemNode *r) const { - return compareNodes(l.first, r.first); + return compareNodes(l, r); } @@ -1150,16 +1149,14 @@ void QFileSystemModelPrivate::sortChildren(int column, const QModelIndex &parent if (indexNode->children.count() == 0) return; - QList<QPair<QFileSystemModelPrivate::QFileSystemNode*, int> > values; + QVector<QFileSystemModelPrivate::QFileSystemNode*> values; QHash<QString, QFileSystemNode *>::const_iterator iterator; - int i = 0; for(iterator = indexNode->children.constBegin() ; iterator != indexNode->children.constEnd() ; ++iterator) { if (filtersAcceptsNode(iterator.value())) { - values.append(QPair<QFileSystemModelPrivate::QFileSystemNode*, int>((iterator.value()), i)); + values.append(iterator.value()); } else { iterator.value()->isVisible = false; } - i++; } QFileSystemModelSorter ms(column); std::sort(values.begin(), values.end(), ms); @@ -1167,9 +1164,11 @@ void QFileSystemModelPrivate::sortChildren(int column, const QModelIndex &parent indexNode->visibleChildren.clear(); //No more dirty item we reset our internal dirty index indexNode->dirtyChildrenIndex = -1; - for (int i = 0; i < values.count(); ++i) { - indexNode->visibleChildren.append(values.at(i).first->fileName); - values.at(i).first->isVisible = true; + const int numValues = values.count(); + indexNode->visibleChildren.reserve(numValues); + for (int i = 0; i < numValues; ++i) { + indexNode->visibleChildren.append(values.at(i)->fileName); + values.at(i)->isVisible = true; } if (!disableRecursiveSort) { @@ -1783,26 +1782,6 @@ void QFileSystemModelPrivate::removeNode(QFileSystemModelPrivate::QFileSystemNod q->endRemoveRows(); } -/* - \internal - Helper functor used by addVisibleFiles() -*/ -class QFileSystemModelVisibleFinder -{ -public: - inline QFileSystemModelVisibleFinder(QFileSystemModelPrivate::QFileSystemNode *node, QFileSystemModelSorter *sorter) : parentNode(node), sorter(sorter) {} - - bool operator()(const QString &, QString r) const - { - return sorter->compareNodes(parentNode->children.value(name), parentNode->children.value(r)); - } - - QString name; -private: - QFileSystemModelPrivate::QFileSystemNode *parentNode; - QFileSystemModelSorter *sorter; -}; - /*! \internal @@ -1824,9 +1803,9 @@ void QFileSystemModelPrivate::addVisibleFiles(QFileSystemNode *parentNode, const parentNode->dirtyChildrenIndex = parentNode->visibleChildren.count(); for (int i = 0; i < newFiles.count(); ++i) { - parentNode->visibleChildren.append(newFiles.at(i)); - parentNode->children[newFiles.at(i)]->isVisible = true; - } + parentNode->visibleChildren.append(newFiles.at(i)); + parentNode->children.value(newFiles.at(i))->isVisible = true; + } if (!indexHidden) q->endInsertRows(); } @@ -1848,7 +1827,7 @@ void QFileSystemModelPrivate::removeVisibleFile(QFileSystemNode *parentNode, int if (!indexHidden) q->beginRemoveRows(parent, translateVisibleLocation(parentNode, vLocation), translateVisibleLocation(parentNode, vLocation)); - parentNode->children[parentNode->visibleChildren.at(vLocation)]->isVisible = false; + parentNode->children.value(parentNode->visibleChildren.at(vLocation))->isVisible = false; parentNode->visibleChildren.removeAt(vLocation); if (!indexHidden) q->endRemoveRows(); |