From 03a65da80aea562ea51bf6db12a30a1acf097368 Mon Sep 17 00:00:00 2001 From: Peter Penz Date: Tue, 20 Mar 2012 17:19:12 +0100 Subject: [PATCH] KFileItemModel: Remove minimum-update timer The timer became unnecessary after introducing the behavior to collect all new items until KDirLister emits a completed()-signal. --- src/kitemviews/kfileitemmodel.cpp | 27 ------------------ src/kitemviews/kfileitemmodel.h | 2 -- src/tests/kfileitemmodeltest.cpp | 47 +++++++++++++++++++++++++++++-- src/views/dolphinview.cpp | 4 +-- 4 files changed, 46 insertions(+), 34 deletions(-) diff --git a/src/kitemviews/kfileitemmodel.cpp b/src/kitemviews/kfileitemmodel.cpp index 0fef47787..4b9f2f00e 100644 --- a/src/kitemviews/kfileitemmodel.cpp +++ b/src/kitemviews/kfileitemmodel.cpp @@ -44,11 +44,9 @@ KFileItemModel::KFileItemModel(KDirLister* dirLister, QObject* parent) : m_filter(), m_filteredItems(), m_requestRole(), - m_minimumUpdateIntervalTimer(0), m_maximumUpdateIntervalTimer(0), m_resortAllItemsTimer(0), m_pendingItemsToInsert(), - m_pendingEmitLoadingCompleted(false), m_groups(), m_expandedParentsCountRoot(UninitializedExpandedParentsCountRoot), m_expandedUrls(), @@ -71,14 +69,6 @@ KFileItemModel::KFileItemModel(KDirLister* dirLister, QObject* parent) : connect(dirLister, SIGNAL(clear()), this, SLOT(slotClear())); connect(dirLister, SIGNAL(clear(KUrl)), this, SLOT(slotClear(KUrl))); - // Although the layout engine of KItemListView is fast it is very inefficient to e.g. - // emit 50 itemsInserted()-signals each 100 ms. m_minimumUpdateIntervalTimer assures that updates - // are done in 1 second intervals for equal operations. - m_minimumUpdateIntervalTimer = new QTimer(this); - m_minimumUpdateIntervalTimer->setInterval(1000); - m_minimumUpdateIntervalTimer->setSingleShot(true); - connect(m_minimumUpdateIntervalTimer, SIGNAL(timeout()), this, SLOT(dispatchPendingItemsToInsert())); - // For slow KIO-slaves like used for searching it makes sense to show results periodically even // before the completed() or canceled() signal has been emitted. m_maximumUpdateIntervalTimer = new QTimer(this); @@ -95,8 +85,6 @@ KFileItemModel::KFileItemModel(KDirLister* dirLister, QObject* parent) : m_resortAllItemsTimer->setSingleShot(true); connect(m_resortAllItemsTimer, SIGNAL(timeout()), this, SLOT(resortAllItems())); - Q_ASSERT(m_minimumUpdateIntervalTimer->interval() <= m_maximumUpdateIntervalTimer->interval()); - connect(KGlobalSettings::self(), SIGNAL(naturalSortingChanged()), this, SLOT(slotNaturalSortingChanged())); } @@ -661,14 +649,6 @@ void KFileItemModel::resortAllItems() void KFileItemModel::slotCompleted() { - if (m_urlsToExpand.isEmpty() && m_minimumUpdateIntervalTimer->isActive()) { - // dispatchPendingItems() will be called when the timer - // has been expired. - m_pendingEmitLoadingCompleted = true; - return; - } - - m_pendingEmitLoadingCompleted = false; dispatchPendingItemsToInsert(); if (!m_urlsToExpand.isEmpty()) { @@ -694,12 +674,10 @@ void KFileItemModel::slotCompleted() } emit loadingCompleted(); - m_minimumUpdateIntervalTimer->start(); } void KFileItemModel::slotCanceled() { - m_minimumUpdateIntervalTimer->stop(); m_maximumUpdateIntervalTimer->stop(); dispatchPendingItemsToInsert(); } @@ -858,7 +836,6 @@ void KFileItemModel::slotClear() m_filteredItems.clear(); m_groups.clear(); - m_minimumUpdateIntervalTimer->stop(); m_maximumUpdateIntervalTimer->stop(); m_resortAllItemsTimer->stop(); m_pendingItemsToInsert.clear(); @@ -893,10 +870,6 @@ void KFileItemModel::dispatchPendingItemsToInsert() insertItems(m_pendingItemsToInsert); m_pendingItemsToInsert.clear(); } - - if (m_pendingEmitLoadingCompleted) { - emit loadingCompleted(); - } } void KFileItemModel::insertItems(const KFileItemList& items) diff --git a/src/kitemviews/kfileitemmodel.h b/src/kitemviews/kfileitemmodel.h index d48f600df..0b1885a8c 100644 --- a/src/kitemviews/kfileitemmodel.h +++ b/src/kitemviews/kfileitemmodel.h @@ -369,11 +369,9 @@ private: bool m_requestRole[RolesCount]; - QTimer* m_minimumUpdateIntervalTimer; QTimer* m_maximumUpdateIntervalTimer; QTimer* m_resortAllItemsTimer; KFileItemList m_pendingItemsToInsert; - bool m_pendingEmitLoadingCompleted; // Cache for KFileItemModel::groups() mutable QList > m_groups; diff --git a/src/tests/kfileitemmodeltest.cpp b/src/tests/kfileitemmodeltest.cpp index 04be625d8..393192582 100644 --- a/src/tests/kfileitemmodeltest.cpp +++ b/src/tests/kfileitemmodeltest.cpp @@ -62,6 +62,7 @@ private slots: void testDefaultGroupedSorting(); void testNewItems(); void testRemoveItems(); + void testLoadingCompleted(); void testSetData(); void testSetDataWithModifiedSortRole_data(); void testSetDataWithModifiedSortRole(); @@ -100,6 +101,7 @@ void KFileItemModelTest::init() m_testDir = new TestDir(); m_dirLister = new KDirLister(); + m_dirLister->setAutoUpdate(false); m_model = new KFileItemModel(m_dirLister); } @@ -176,6 +178,49 @@ void KFileItemModelTest::testRemoveItems() QVERIFY(isModelConsistent()); } +void KFileItemModelTest::testLoadingCompleted() +{ + QSignalSpy loadingCompletedSpy(m_model, SIGNAL(loadingCompleted())); + QSignalSpy itemsInsertedSpy(m_model, SIGNAL(itemsInserted(KItemRangeList))); + QSignalSpy itemsRemovedSpy(m_model, SIGNAL(itemsRemoved(KItemRangeList))); + + m_testDir->createFiles(QStringList() << "a.txt" << "b.txt" << "c.txt"); + + m_dirLister->openUrl(m_testDir->url()); + QVERIFY(QTest::kWaitForSignal(m_model, SIGNAL(loadingCompleted()), DefaultTimeout)); + QCOMPARE(loadingCompletedSpy.count(), 1); + QCOMPARE(itemsInsertedSpy.count(), 1); + QCOMPARE(itemsRemovedSpy.count(), 0); + QCOMPARE(m_model->count(), 3); + + m_testDir->createFiles(QStringList() << "d.txt" << "e.txt"); + m_dirLister->updateDirectory(m_testDir->url()); + QVERIFY(QTest::kWaitForSignal(m_model, SIGNAL(loadingCompleted()), DefaultTimeout)); + QCOMPARE(loadingCompletedSpy.count(), 2); + QCOMPARE(itemsInsertedSpy.count(), 2); + QCOMPARE(itemsRemovedSpy.count(), 0); + QCOMPARE(m_model->count(), 5); + + m_testDir->removeFile("a.txt"); + m_testDir->createFile("f.txt"); + m_dirLister->updateDirectory(m_testDir->url()); + QVERIFY(QTest::kWaitForSignal(m_model, SIGNAL(loadingCompleted()), DefaultTimeout)); + QCOMPARE(loadingCompletedSpy.count(), 3); + QCOMPARE(itemsInsertedSpy.count(), 3); + QCOMPARE(itemsRemovedSpy.count(), 1); + QCOMPARE(m_model->count(), 5); + + m_testDir->removeFile("b.txt"); + m_dirLister->updateDirectory(m_testDir->url()); + QVERIFY(QTest::kWaitForSignal(m_model, SIGNAL(itemsRemoved(KItemRangeList)), DefaultTimeout)); + QCOMPARE(loadingCompletedSpy.count(), 4); + QCOMPARE(itemsInsertedSpy.count(), 3); + QCOMPARE(itemsRemovedSpy.count(), 2); + QCOMPARE(m_model->count(), 4); + + QVERIFY(isModelConsistent()); +} + void KFileItemModelTest::testSetData() { m_testDir->createFile("a.txt"); @@ -288,8 +333,6 @@ void KFileItemModelTest::testModelConsistencyWhenInsertingItems() // one itemsInserted()-signal. However in this test we want to stress // KFileItemModel to do a lot of insert operation and hence decrease // the timeout to 1 millisecond. - m_model->m_minimumUpdateIntervalTimer->setInterval(1); - m_testDir->createFile("1"); m_dirLister->openUrl(m_testDir->url()); QVERIFY(QTest::kWaitForSignal(m_model, SIGNAL(itemsInserted(KItemRangeList)), DefaultTimeout)); diff --git a/src/views/dolphinview.cpp b/src/views/dolphinview.cpp index 75561a9c6..f3d386b3b 100644 --- a/src/views/dolphinview.cpp +++ b/src/views/dolphinview.cpp @@ -1135,9 +1135,7 @@ void DolphinView::slotDirListerStarted(const KUrl& url) void DolphinView::slotLoadingCompleted() { // Update the view-state. This has to be done using a Qt::QueuedConnection - // because the view might not be in its final state yet (the view also - // listens to the completed()-signal from KDirLister and the order of - // of slots is undefined). + // because the view might not be in its final state yet. QTimer::singleShot(0, this, SLOT(updateViewState())); emit finishedPathLoading(url()); -- 2.47.3