diff options
Diffstat (limited to 'src/imports/folderlistmodel')
-rw-r--r-- | src/imports/folderlistmodel/qquickfolderlistmodel.cpp | 41 |
1 files changed, 17 insertions, 24 deletions
diff --git a/src/imports/folderlistmodel/qquickfolderlistmodel.cpp b/src/imports/folderlistmodel/qquickfolderlistmodel.cpp index f8d43f0594..1f28d8009e 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(); } } |