]> cloud.milkyroute.net Git - dolphin.git/commitdiff
KFileItemModel: Remove minimum-update timer
authorPeter Penz <peter.penz19@gmail.com>
Tue, 20 Mar 2012 16:19:12 +0000 (17:19 +0100)
committerPeter Penz <peter.penz19@gmail.com>
Tue, 20 Mar 2012 16:23:28 +0000 (17:23 +0100)
The timer became unnecessary after introducing the behavior to
collect all new items until KDirLister emits a completed()-signal.

src/kitemviews/kfileitemmodel.cpp
src/kitemviews/kfileitemmodel.h
src/tests/kfileitemmodeltest.cpp
src/views/dolphinview.cpp

index 0fef47787763ff746157884977beb93a4e62bb24..4b9f2f00ed111e20858a8175eeee6bab305b0892 100644 (file)
@@ -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)
index d48f600dfcf2a0a92a732b72ba6138af1269a06d..0b1885a8cb9d8b93b6b9217bba789827199b5c5e 100644 (file)
@@ -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<QPair<int, QVariant> > m_groups;
index 04be625d870b161d491abd6c7e2e246b44c6f14c..3931925822da078fb02664c740ca68d38d580688 100644 (file)
@@ -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));
index 75561a9c69c02a657a03a3d8167656f9bad3439a..f3d386b3b7f24f3602dd29bb15f969200234e925 100644 (file)
@@ -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());