summaryrefslogtreecommitdiffstats
path: root/src/widgets/dialogs/qfilesystemmodel.cpp
diff options
context:
space:
mode:
authorMarc Mutz <marc.mutz@kdab.com>2015-01-29 12:13:47 +0100
committerMarc Mutz <marc.mutz@kdab.com>2015-07-18 13:32:31 +0000
commit648a496e5e64ccdefe5383238fc7c4b84d0159a8 (patch)
treebc539f2305d5b5d461e6db26d67da5ac8b8d782b /src/widgets/dialogs/qfilesystemmodel.cpp
parentce7fb157f0b8f74025e6927e7b61b1d79de0581c (diff)
QFileSystemModel: avoid sibling() calls
...by allowing to pass the column to the Private::index() overloads. Because Private::index() always returns an index in column 0, callers that needed a different column used QModelIndex::sibling() to adjust the column of the returned index. But that calls QAIM::sibling(), which calls both QFSM::index() and ::parent(). Simply allowing to pass the column number instead of hard-coding 0 avoids that heavy detour. Change-Id: I8895b3d102d576ba291333cf61075b7263f96b9d Reviewed-by: Friedemann Kleint <Friedemann.Kleint@theqtcompany.com> Reviewed-by: David Faure <david.faure@kdab.com>
Diffstat (limited to 'src/widgets/dialogs/qfilesystemmodel.cpp')
-rw-r--r--src/widgets/dialogs/qfilesystemmodel.cpp13
1 files changed, 4 insertions, 9 deletions
diff --git a/src/widgets/dialogs/qfilesystemmodel.cpp b/src/widgets/dialogs/qfilesystemmodel.cpp
index 05bacdbd63..c4d2db95f3 100644
--- a/src/widgets/dialogs/qfilesystemmodel.cpp
+++ b/src/widgets/dialogs/qfilesystemmodel.cpp
@@ -259,10 +259,7 @@ QModelIndex QFileSystemModel::index(const QString &path, int column) const
{
Q_D(const QFileSystemModel);
QFileSystemModelPrivate::QFileSystemNode *node = d->node(path, false);
- QModelIndex idx = d->index(node);
- if (idx.column() != column)
- idx = idx.sibling(idx.row(), column);
- return idx;
+ return d->index(node, column);
}
/*!
@@ -562,7 +559,7 @@ QModelIndex QFileSystemModel::parent(const QModelIndex &index) const
return the index for node
*/
-QModelIndex QFileSystemModelPrivate::index(const QFileSystemModelPrivate::QFileSystemNode *node) const
+QModelIndex QFileSystemModelPrivate::index(const QFileSystemModelPrivate::QFileSystemNode *node, int column) const
{
Q_Q(const QFileSystemModel);
QFileSystemModelPrivate::QFileSystemNode *parentNode = (node ? node->parent : 0);
@@ -575,7 +572,7 @@ QModelIndex QFileSystemModelPrivate::index(const QFileSystemModelPrivate::QFileS
return QModelIndex();
int visualRow = translateVisibleLocation(parentNode, parentNode->visibleLocation(node->fileName));
- return q->createIndex(visualRow, 0, const_cast<QFileSystemNode*>(node));
+ return q->createIndex(visualRow, column, const_cast<QFileSystemNode*>(node));
}
/*!
@@ -1202,9 +1199,7 @@ void QFileSystemModel::sort(int column, Qt::SortOrder order)
QModelIndexList newList;
for (int i = 0; i < nodeCount; ++i) {
const QPair<QFileSystemModelPrivate::QFileSystemNode*, int> &oldNode = oldNodes.at(i);
- QModelIndex idx = d->index(oldNode.first);
- idx = idx.sibling(idx.row(), oldNode.second);
- newList.append(idx);
+ newList.append(d->index(oldNode.first, oldNode.second));
}
changePersistentIndexList(oldList, newList);
emit layoutChanged();