┌   ┐
54
└   ┘

summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorFrank Reininghaus <[email protected]>2013-02-10 18:06:07 +0100
committerFrank Reininghaus <[email protected]>2013-02-10 18:06:07 +0100
commit4f5a2eb943792af51fa2125725c356ca1090113e (patch)
tree60cbc2f2c2fc99744b5d2304d80a76a506331740 /src
parentac6d3d8250fdceeccdc692af96d74581512f23b2 (diff)
Include parent-child relationships in KFileItemModel's consistency check
Diffstat (limited to 'src')
-rw-r--r--src/kitemviews/kfileitemmodel.cpp19
-rw-r--r--src/tests/kfileitemmodeltest.cpp3
2 files changed, 21 insertions, 1 deletions
diff --git a/src/kitemviews/kfileitemmodel.cpp b/src/kitemviews/kfileitemmodel.cpp
index a763b3fff..d0fd3d77c 100644
--- a/src/kitemviews/kfileitemmodel.cpp
+++ b/src/kitemviews/kfileitemmodel.cpp
@@ -2018,12 +2018,12 @@ void KFileItemModel::determineMimeTypes(const KFileItemList& items, int timeout)
bool KFileItemModel::isConsistent() const
{
- // Check that m_items and m_itemData are consistent, and that the items are sorted.
if (m_items.count() != m_itemData.count()) {
return false;
}
for (int i = 0; i < count(); ++i) {
+ // Check if m_items and m_itemData are consistent.
const KFileItem item = fileItem(i);
if (item.isNull()) {
qWarning() << "Item" << i << "is null";
@@ -2036,11 +2036,28 @@ bool KFileItemModel::isConsistent() const
return false;
}
+ // Check if the items are sorted correctly.
if (i > 0 && !lessThan(m_itemData.at(i - 1), m_itemData.at(i))) {
qWarning() << "The order of items" << i - 1 << "and" << i << "is wrong:"
<< fileItem(i - 1) << fileItem(i);
return false;
}
+
+ // Check if all parent-child relationships are consistent.
+ const ItemData* data = m_itemData.at(i);
+ const ItemData* parent = data->parent;
+ if (parent) {
+ if (data->values.value("expandedParentsCount").toInt() != parent->values.value("expandedParentsCount").toInt() + 1) {
+ qWarning() << "expandedParentsCount is inconsistent for parent" << parent->item << "and child" << data->item;
+ return false;
+ }
+
+ const int parentIndex = index(parent->item);
+ if (parentIndex >= i) {
+ qWarning() << "Index" << parentIndex << "of parent" << parent->item << "is not smaller than index" << i << "of child" << data->item;
+ return false;
+ }
+ }
}
return true;
diff --git a/src/tests/kfileitemmodeltest.cpp b/src/tests/kfileitemmodeltest.cpp
index 2ad18428a..85a46488f 100644
--- a/src/tests/kfileitemmodeltest.cpp
+++ b/src/tests/kfileitemmodeltest.cpp
@@ -486,6 +486,7 @@ void KFileItemModelTest::testExpandItems()
QCOMPARE(spyRemoved.count(), 1);
itemRangeList = spyRemoved.takeFirst().at(0).value<KItemRangeList>();
QCOMPARE(itemRangeList, KItemRangeList() << KItemRange(1, 4)); // 4 items removed
+ QVERIFY(m_model->isConsistent());
// Clear the model, reload the folder and try to restore the expanded folders.
m_model->clear();
@@ -502,6 +503,7 @@ void KFileItemModelTest::testExpandItems()
QVERIFY(m_model->isExpanded(3));
QVERIFY(!m_model->isExpanded(4));
QCOMPARE(m_model->expandedDirectories(), allFolders);
+ QVERIFY(m_model->isConsistent());
// Move to a sub folder, then call restoreExpandedFolders() *before* going back.
// This is how DolphinView restores the expanded folders when navigating in history.
@@ -564,6 +566,7 @@ void KFileItemModelTest::testExpandParentItems()
QVERIFY(m_model->isExpanded(2));
QVERIFY(m_model->isExpanded(3));
QVERIFY(!m_model->isExpanded(4));
+ QVERIFY(m_model->isConsistent());
}
void KFileItemModelTest::testSorting()