aboutsummaryrefslogtreecommitdiffstats
path: root/src/imports
diff options
context:
space:
mode:
authorShawn Rutledge <shawn.rutledge@digia.com>2014-03-04 16:05:50 +0100
committerThe Qt Project <gerrit-noreply@qt-project.org>2014-03-18 10:18:57 +0100
commita412d0aa7e98d98c6f8ee82050766cc8fd6f7903 (patch)
treec02d48190c8486a2cc5113f4786cf167a830bfda /src/imports
parentc3fbec3ab955eb2b771a6a54d2910d25a1c7277c (diff)
FolderListModel: pessimize change signals when the filter changes
FileInfoThread doesn't have separate signals for insertions, deletions and updates, so QQuickFolderListModel shouldn't make an assumption that if the list got bigger, an insertion was the only thing that happened. Task-number: QTBUG-36576 Change-Id: Ibb02d64e1645dd6df231d28a93e424aaad0effff Reviewed-by: Alan Alpert <aalpert@blackberry.com>
Diffstat (limited to 'src/imports')
-rw-r--r--src/imports/folderlistmodel/qquickfolderlistmodel.cpp41
1 files changed, 17 insertions, 24 deletions
diff --git a/src/imports/folderlistmodel/qquickfolderlistmodel.cpp b/src/imports/folderlistmodel/qquickfolderlistmodel.cpp
index 5ed38db3d7..5dc4332d69 100644
--- a/src/imports/folderlistmodel/qquickfolderlistmodel.cpp
+++ b/src/imports/folderlistmodel/qquickfolderlistmodel.cpp
@@ -158,35 +158,28 @@ void QQuickFolderListModelPrivate::_q_directoryUpdated(const QString &directory,
Q_UNUSED(directory);
QModelIndex parent;
- if (data.size() > list.size()) {
- //File(s) removed. Since I do not know how many
- //or where I need to update the whole list from the first item.
- data = list;
- q->beginRemoveRows(parent, fromIndex, toIndex);
- q->endRemoveRows();
- if (list.size() > 0) {
- q->beginInsertRows(parent, fromIndex, list.size()-1);
- q->endInsertRows();
- }
- emit q->rowCountChanged();
- } else if (data.size() < list.size()) {
- //qDebug() << "File added. FromIndex: " << fromIndex << " toIndex: " << toIndex << " list size: " << list.size();
- //File(s) added. Calculate how many and insert
- //from the first changed one.
- toIndex = fromIndex + (list.size() - data.size()-1);
- q->beginInsertRows(parent, fromIndex, toIndex);
- q->endInsertRows();
- data = list;
- emit q->rowCountChanged();
+ if (data.size() == list.size()) {
QModelIndex modelIndexFrom = q->createIndex(fromIndex, 0);
QModelIndex modelIndexTo = q->createIndex(toIndex, 0);
+ data = list;
emit q->dataChanged(modelIndexFrom, modelIndexTo);
} else {
- //qDebug() << "File has been updated";
- QModelIndex modelIndexFrom = q->createIndex(fromIndex, 0);
- QModelIndex modelIndexTo = q->createIndex(toIndex, 0);
+ // File(s) inserted or removed. Since I do not know how many
+ // or where, I need to update the whole list from the first item.
+ // This is a little pessimistic, but optimizing it would require
+ // more information in the signal from FileInfoThread.
+ if (data.size() > 0) {
+ q->beginRemoveRows(parent, 0, data.size() - 1);
+ q->endRemoveRows();
+ }
data = list;
- emit q->dataChanged(modelIndexFrom, modelIndexTo);
+ if (list.size() > 0) {
+ if (toIndex > list.size() - 1)
+ toIndex = list.size() - 1;
+ q->beginInsertRows(parent, 0, data.size() - 1);
+ q->endInsertRows();
+ }
+ emit q->rowCountChanged();
}
}