diff options
author | Alexis Menard <alexis.menard@nokia.com> | 2009-09-10 09:40:42 (GMT) |
---|---|---|
committer | Alexis Menard <alexis.menard@nokia.com> | 2009-09-10 09:44:42 (GMT) |
commit | 9e8abb63ba4609887d988ee15ba6daee0b01380e (patch) | |
tree | deb02261e3a6eae2869c51019bcd4397372af0b1 /src/gui | |
parent | b300c3022d285deb3b3203aca0746580ba9f3d91 (diff) | |
download | Qt-9e8abb63ba4609887d988ee15ba6daee0b01380e.zip Qt-9e8abb63ba4609887d988ee15ba6daee0b01380e.tar.gz Qt-9e8abb63ba4609887d988ee15ba6daee0b01380e.tar.bz2 |
Fix random selection when the order is descending.
This commit fix the random selection that appear when the sort is not
ascending. The problem is that sometimes the sort is not yet made (timer
is not yet fired) so the visible children list contains both sorted items
and non sorted items (at the end). translateVisibleLocation was buggy
assuming that the list is always sorted. We have now a dirty index that
indicate where the dirty items start. And then when the sort is made
the dirty index is reset. I have added auto-test for that and fix one
that was broken for Mac. The new version of the auto-test showed a crash
because of this broken selection.
Task-number:258751
Reviewed-by:thierry
Diffstat (limited to 'src/gui')
-rw-r--r-- | src/gui/dialogs/qfilesystemmodel.cpp | 6 | ||||
-rw-r--r-- | src/gui/dialogs/qfilesystemmodel_p.h | 13 |
2 files changed, 17 insertions, 2 deletions
diff --git a/src/gui/dialogs/qfilesystemmodel.cpp b/src/gui/dialogs/qfilesystemmodel.cpp index 66d9bb0..b9012c7 100644 --- a/src/gui/dialogs/qfilesystemmodel.cpp +++ b/src/gui/dialogs/qfilesystemmodel.cpp @@ -1104,6 +1104,8 @@ void QFileSystemModelPrivate::sortChildren(int column, const QModelIndex &parent qStableSort(values.begin(), values.end(), ms); // First update the new visible list 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; @@ -1706,6 +1708,10 @@ void QFileSystemModelPrivate::addVisibleFiles(QFileSystemNode *parentNode, const if (!indexHidden) { q->beginInsertRows(parent, parentNode->visibleChildren.count() , parentNode->visibleChildren.count() + newFiles.count() - 1); } + + if (parentNode->dirtyChildrenIndex == -1) + 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; diff --git a/src/gui/dialogs/qfilesystemmodel_p.h b/src/gui/dialogs/qfilesystemmodel_p.h index 9734f1c..175159f 100644 --- a/src/gui/dialogs/qfilesystemmodel_p.h +++ b/src/gui/dialogs/qfilesystemmodel_p.h @@ -84,7 +84,7 @@ public: { public: QFileSystemNode(const QString &filename = QString(), QFileSystemNode *p = 0) - : fileName(filename), populatedChildren(false), isVisible(false), parent(p), info(0) {} + : fileName(filename), populatedChildren(false), isVisible(false), dirtyChildrenIndex(-1), parent(p), info(0) {} ~QFileSystemNode() { QHash<QString, QFileSystemNode*>::const_iterator i = children.constBegin(); while (i != children.constEnd()) { @@ -194,6 +194,7 @@ public: bool isVisible; QHash<QString,QFileSystemNode *> children; QList<QString> visibleChildren; + int dirtyChildrenIndex; QFileSystemNode *parent; @@ -237,7 +238,15 @@ public: void sortChildren(int column, const QModelIndex &parent); inline int translateVisibleLocation(QFileSystemNode *parent, int row) const { - return (sortOrder == Qt::AscendingOrder) ? row : parent->visibleChildren.count() - row - 1; + if (sortOrder == Qt::AscendingOrder) + return row; + if (parent->dirtyChildrenIndex == -1 || row < parent->dirtyChildrenIndex) + if (parent->dirtyChildrenIndex != -1) + return parent->dirtyChildrenIndex - row - 1; + else + return parent->visibleChildren.count() - row - 1; + else + return row; } inline static QString myComputer() { |