diff options
author | Alexis Menard <alexis.menard@nokia.com> | 2009-05-28 12:46:39 (GMT) |
---|---|---|
committer | Alexis Menard <alexis.menard@nokia.com> | 2009-05-28 15:26:48 (GMT) |
commit | 8e4300e2866fd28881853509df6ff054e13f841b (patch) | |
tree | a27cf1b141948e0e34f6b60efdd47063e87265fa /src/gui/dialogs | |
parent | 89029a54cb3adfb54736a6aafaea9ec535407592 (diff) | |
download | Qt-8e4300e2866fd28881853509df6ff054e13f841b.zip Qt-8e4300e2866fd28881853509df6ff054e13f841b.tar.gz Qt-8e4300e2866fd28881853509df6ff054e13f841b.tar.bz2 |
Fix wrong sorting when using the QFileSystemModel with QTreeView
An optimization was made to the sorting of QFileDialog to sort only
the current root (meaning what the user see). This avoided slowness
when the model was big with lots of leafs. The problem here is
for the treeview, the root is always the same, we expands only
nodes. In that case, a recursive sorting is needed to ensure that
all expanded nodes are correctly sorted (and filtered). This will
be slower that's why i use an hidden flag in the d pointer to
deactivate the recursive sort for the QFileDialog.
Task-number:254701
Reviewed-by:olivier
BT:yes
Diffstat (limited to 'src/gui/dialogs')
-rw-r--r-- | src/gui/dialogs/qfiledialog.cpp | 1 | ||||
-rw-r--r-- | src/gui/dialogs/qfilesystemmodel.cpp | 11 | ||||
-rw-r--r-- | src/gui/dialogs/qfilesystemmodel_p.h | 7 |
3 files changed, 18 insertions, 1 deletions
diff --git a/src/gui/dialogs/qfiledialog.cpp b/src/gui/dialogs/qfiledialog.cpp index d42775a..d4d0136 100644 --- a/src/gui/dialogs/qfiledialog.cpp +++ b/src/gui/dialogs/qfiledialog.cpp @@ -2108,6 +2108,7 @@ void QFileDialogPrivate::createWidgets() #else model->setNameFilterDisables(false); #endif + model->d_func()->disableRecursiveSort = true; QFileDialog::connect(model, SIGNAL(fileRenamed(const QString &, const QString &, const QString &)), q, SLOT(_q_fileRenamed(const QString &, const QString &, const QString &))); QFileDialog::connect(model, SIGNAL(rootPathChanged(const QString &)), q, SLOT(_q_pathChanged(const QString &))); diff --git a/src/gui/dialogs/qfilesystemmodel.cpp b/src/gui/dialogs/qfilesystemmodel.cpp index 012d3a1..03017c3 100644 --- a/src/gui/dialogs/qfilesystemmodel.cpp +++ b/src/gui/dialogs/qfilesystemmodel.cpp @@ -1083,6 +1083,7 @@ private: */ void QFileSystemModelPrivate::sortChildren(int column, const QModelIndex &parent) { + Q_Q(QFileSystemModel); QFileSystemModelPrivate::QFileSystemNode *indexNode = node(parent); if (indexNode->children.count() == 0) return; @@ -1106,6 +1107,16 @@ void QFileSystemModelPrivate::sortChildren(int column, const QModelIndex &parent indexNode->visibleChildren.append(values.at(i).first->fileName); values.at(i).first->isVisible = true; } + + if (!disableRecursiveSort) { + for (int i = 0; i < q->rowCount(parent); ++i) { + const QModelIndex childIndex = q->index(i, 0, parent); + QFileSystemModelPrivate::QFileSystemNode *indexNode = node(childIndex); + //Only do a recursive sort on visible nodes + if (indexNode->isVisible) + sortChildren(column, childIndex); + } + } } /*! diff --git a/src/gui/dialogs/qfilesystemmodel_p.h b/src/gui/dialogs/qfilesystemmodel_p.h index 61e8b4c..af4fada 100644 --- a/src/gui/dialogs/qfilesystemmodel_p.h +++ b/src/gui/dialogs/qfilesystemmodel_p.h @@ -208,7 +208,8 @@ public: readOnly(true), setRootPath(false), filters(QDir::AllEntries | QDir::NoDotAndDotDot | QDir::AllDirs), - nameFilterDisables(true) // false on windows, true on mac and unix + nameFilterDisables(true), // false on windows, true on mac and unix + disableRecursiveSort(false) { delayedSortTimer.setSingleShot(true); } @@ -294,6 +295,10 @@ public: QDir::Filters filters; QHash<const QFileSystemNode*, bool> bypassFilters; bool nameFilterDisables; + //This flag is an optimization for the QFileDialog + //It enable a sort which is not recursive, it means + //we sort only what we see. + bool disableRecursiveSort; #ifndef QT_NO_REGEXP QList<QRegExp> nameFilters; #endif |