aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/imports/folderlistmodel/qquickfolderlistmodel.cpp41
-rw-r--r--tests/auto/qml/qquickfolderlistmodel/data/resetfiltering/test1.html1
-rw-r--r--tests/auto/qml/qquickfolderlistmodel/data/resetfiltering/test2.html1
-rw-r--r--tests/auto/qml/qquickfolderlistmodel/tst_qquickfolderlistmodel.cpp47
4 files changed, 55 insertions, 35 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();
}
}
diff --git a/tests/auto/qml/qquickfolderlistmodel/data/resetfiltering/test1.html b/tests/auto/qml/qquickfolderlistmodel/data/resetfiltering/test1.html
new file mode 100644
index 0000000000..4da4639310
--- /dev/null
+++ b/tests/auto/qml/qquickfolderlistmodel/data/resetfiltering/test1.html
@@ -0,0 +1 @@
+<P>This file contains some HTML.</P>
diff --git a/tests/auto/qml/qquickfolderlistmodel/data/resetfiltering/test2.html b/tests/auto/qml/qquickfolderlistmodel/data/resetfiltering/test2.html
new file mode 100644
index 0000000000..4da4639310
--- /dev/null
+++ b/tests/auto/qml/qquickfolderlistmodel/data/resetfiltering/test2.html
@@ -0,0 +1 @@
+<P>This file contains some HTML.</P>
diff --git a/tests/auto/qml/qquickfolderlistmodel/tst_qquickfolderlistmodel.cpp b/tests/auto/qml/qquickfolderlistmodel/tst_qquickfolderlistmodel.cpp
index a6e6345223..4296ae4f09 100644
--- a/tests/auto/qml/qquickfolderlistmodel/tst_qquickfolderlistmodel.cpp
+++ b/tests/auto/qml/qquickfolderlistmodel/tst_qquickfolderlistmodel.cpp
@@ -73,6 +73,7 @@ private slots:
void basicProperties();
void showFiles();
void resetFiltering();
+ void nameFilters();
void refresh();
void cdUp();
#ifdef Q_OS_WIN32
@@ -169,26 +170,50 @@ void tst_qquickfolderlistmodel::resetFiltering()
QAbstractListModel *flm = qobject_cast<QAbstractListModel*>(component.create());
QVERIFY(flm != 0);
+ flm->setProperty("folder", testFileUrl("resetfiltering"));
+ // _q_directoryUpdated may be triggered if model was empty before, but there won't be a rowsRemoved signal
+ QTRY_COMPARE(flm->property("count").toInt(),3); // all files visible
+
+ flm->setProperty("folder", testFileUrl("resetfiltering/innerdir"));
+ // _q_directoryChanged is triggered so it's a total model refresh
+ QTRY_COMPARE(flm->property("count").toInt(),1); // should just be "test2.txt" visible
+
+ flm->setProperty("folder", testFileUrl("resetfiltering"));
+ // _q_directoryChanged is triggered so it's a total model refresh
+ QTRY_COMPARE(flm->property("count").toInt(),3); // all files visible
+}
+
+void tst_qquickfolderlistmodel::nameFilters()
+{
+ // see QTBUG-36576
+ QQmlComponent component(&engine, testFileUrl("resetFiltering.qml"));
+ checkNoErrors(component);
+
+ QAbstractListModel *flm = qobject_cast<QAbstractListModel*>(component.create());
+ QVERIFY(flm != 0);
+
connect(flm, SIGNAL(rowsRemoved(QModelIndex,int,int)),
this, SLOT(removed(QModelIndex,int,int)));
+ QTRY_VERIFY(flm->rowCount() > 0);
flm->setProperty("folder", testFileUrl("resetfiltering"));
- QTRY_COMPARE(flm->property("count").toInt(),1); // should just be "test.txt" visible
+ QTRY_COMPARE(flm->property("count").toInt(),3); // all files visible
+
int count = flm->rowCount();
+ flm->setProperty("nameFilters", QStringList() << "*.txt");
+ // _q_directoryUpdated triggered with range 0:1
+ QTRY_COMPARE(flm->property("count").toInt(),1);
+ QCOMPARE(flm->data(flm->index(0),FileNameRole), QVariant("test.txt"));
QCOMPARE(removeStart, 0);
QCOMPARE(removeEnd, count-1);
- flm->setProperty("folder", testFileUrl("resetfiltering/innerdir"));
- QTRY_COMPARE(flm->property("count").toInt(),1); // should just be "test2.txt" visible
- count = flm->rowCount();
- QCOMPARE(removeStart, 0);
- QCOMPARE(removeEnd, count-1);
+ flm->setProperty("nameFilters", QStringList() << "*.html");
+ QTRY_COMPARE(flm->property("count").toInt(),2);
+ QCOMPARE(flm->data(flm->index(0),FileNameRole), QVariant("test1.html"));
+ QCOMPARE(flm->data(flm->index(1),FileNameRole), QVariant("test2.html"));
- flm->setProperty("folder", testFileUrl("resetfiltering"));
- QTRY_COMPARE(flm->property("count").toInt(),1); // should just be "test.txt" visible
- count = flm->rowCount();
- QCOMPARE(removeStart, 0);
- QCOMPARE(removeEnd, count-1);
+ flm->setProperty("nameFilters", QStringList());
+ QTRY_COMPARE(flm->property("count").toInt(),3); // all files visible
}
void tst_qquickfolderlistmodel::refresh()