]> cloud.milkyroute.net Git - dolphin.git/commitdiff
Replace setExpanded(const QSet<KUrl>&) by expandParentItems(const KUrl&)
authorFrank Reininghaus <frank78ac@googlemail.com>
Fri, 3 Feb 2012 18:09:42 +0000 (19:09 +0100)
committerFrank Reininghaus <frank78ac@googlemail.com>
Sun, 5 Feb 2012 14:59:59 +0000 (15:59 +0100)
The use case of this function (Folders Panel) requires the expansion of
the parent items of a single URL, so it's not needed to handle a full
set of URLs in this function. Moreover, the issue that not only the
parents, but also the URLs themselves were expanded is fixed by this
commit.
(cherry picked from commit 89082ca391807abdc26d8985efe6b4c27183a9b1)

src/kitemviews/kfileitemmodel.cpp
src/kitemviews/kfileitemmodel.h
src/panels/folders/folderspanel.cpp
src/tests/kfileitemmodeltest.cpp

index db9b71189beaf648c7be093c43413c2294be0f0d..6cb7577f27d404352aa70f7ba2df53d85c1ea4b5 100644 (file)
@@ -478,7 +478,7 @@ void KFileItemModel::restoreExpandedUrls(const QSet<KUrl>& urls)
     m_urlsToExpand = urls;
 }
 
     m_urlsToExpand = urls;
 }
 
-void KFileItemModel::setExpanded(const QSet<KUrl>& urls)
+void KFileItemModel::expandParentItems(const KUrl& url)
 {
     const KDirLister* dirLister = m_dirLister.data();
     if (!dirLister) {
 {
     const KDirLister* dirLister = m_dirLister.data();
     if (!dirLister) {
@@ -487,20 +487,15 @@ void KFileItemModel::setExpanded(const QSet<KUrl>& urls)
 
     const int pos = dirLister->url().path().length();
 
 
     const int pos = dirLister->url().path().length();
 
-    // Assure that each sub-path of the URLs that should be
-    // expanded is added to m_urlsToExpand too. KDirLister
+    // Assure that each sub-path of the URL that should be
+    // expanded is added to m_urlsToExpand. KDirLister
     // does not care whether the parent-URL has already been
     // expanded.
     // does not care whether the parent-URL has already been
     // expanded.
-    QSetIterator<KUrl> it1(urls);
-    while (it1.hasNext()) {
-        const KUrl& url = it1.next();
-
-        KUrl urlToExpand = dirLister->url();
-        const QStringList subDirs = url.path().mid(pos).split(QDir::separator());
-        for (int i = 0; i < subDirs.count(); ++i) {
-            urlToExpand.addPath(subDirs.at(i));
-            m_urlsToExpand.insert(urlToExpand);
-        }
+    KUrl urlToExpand = dirLister->url();
+    const QStringList subDirs = url.path().mid(pos).split(QDir::separator());
+    for (int i = 0; i < subDirs.count() - 1; ++i) {
+        urlToExpand.addPath(subDirs.at(i));
+        m_urlsToExpand.insert(urlToExpand);
     }
 
     // KDirLister::open() must called at least once to trigger an initial
     }
 
     // KDirLister::open() must called at least once to trigger an initial
index ff816c85ca0e5ce5835b427df9424cc8d6a4fc6b..a792b089f19ae373791104f57811a00e34dafdc4 100644 (file)
@@ -150,9 +150,9 @@ public:
     void restoreExpandedUrls(const QSet<KUrl>& urls);
 
     /**
     void restoreExpandedUrls(const QSet<KUrl>& urls);
 
     /**
-     * Expands all parent-items of each URL given by \a urls.
+     * Expands all parent-items of \a url.
      */
      */
-    void setExpanded(const QSet<KUrl>& urls);
+    void expandParentItems(const KUrl& url);
 
     void setNameFilter(const QString& nameFilter);
     QString nameFilter() const;
 
     void setNameFilter(const QString& nameFilter);
     QString nameFilter() const;
index 2511d7e4b4d88ff9000d601ede0e292713e5deeb..3b24f5868b180004c6830509ed325028de9d3fb5 100644 (file)
@@ -330,7 +330,7 @@ void FoldersPanel::loadTree(const KUrl& url)
         updateCurrentItem(index);
     } else {
         m_updateCurrentItem = true;
         updateCurrentItem(index);
     } else {
         m_updateCurrentItem = true;
-        model->setExpanded(QSet<KUrl>() << url);
+        model->expandParentItems(url);
         // slotLoadingCompleted() will be invoked after the model has
         // expanded the url
     }
         // slotLoadingCompleted() will be invoked after the model has
         // expanded the url
     }
index c3611ef7346fbb79e3ddb0b45e91e1fd29aef8fc..d0accd68aa5176aede54a5fb7ff44d9b085197f9 100644 (file)
@@ -68,6 +68,7 @@ private slots:
     void testModelConsistencyWhenInsertingItems();
     void testItemRangeConsistencyWhenInsertingItems();
     void testExpandItems();
     void testModelConsistencyWhenInsertingItems();
     void testItemRangeConsistencyWhenInsertingItems();
     void testExpandItems();
+    void testExpandParentItems();
     void testSorting();
 
     void testExpansionLevelsCompare_data();
     void testSorting();
 
     void testExpansionLevelsCompare_data();
@@ -478,6 +479,57 @@ void KFileItemModelTest::testExpandItems()
     QCOMPARE(m_model->expandedUrls(), allFolders);
 }
 
     QCOMPARE(m_model->expandedUrls(), allFolders);
 }
 
+void KFileItemModelTest::testExpandParentItems()
+{
+    // Create a tree structure of folders:
+    // a 1/
+    // a 1/b1/
+    // a 1/b1/c1/
+    // a2/
+    // a2/b2/
+    // a2/b2/c2/
+    // a2/b2/c2/d2/
+    QSet<QByteArray> modelRoles = m_model->roles();
+    modelRoles << "isExpanded" << "isExpandable" << "expansionLevel";
+    m_model->setRoles(modelRoles);
+
+    QStringList files;
+    files << "a 1/b1/c1/file.txt" << "a2/b2/c2/d2/file.txt"; // missing folders are created automatically
+    m_testDir->createFiles(files);
+
+    m_dirLister->openUrl(m_testDir->url());
+    QVERIFY(QTest::kWaitForSignal(m_model, SIGNAL(itemsInserted(KItemRangeList)), DefaultTimeout));
+
+    // So far, the model contains only "a 1/" and "a2/".
+    QCOMPARE(m_model->count(), 2);
+    QVERIFY(m_model->expandedUrls().empty());
+
+    // Expand the parents of "a2/b2/c2".
+    m_model->expandParentItems(KUrl(m_testDir->name() + "a2/b2/c2"));
+    QVERIFY(QTest::kWaitForSignal(m_model, SIGNAL(loadingCompleted()), DefaultTimeout));
+
+    // The model should now contain "a 1/", "a2/", "a2/b2/", and "a2/b2/c2/".
+    // It's important that only the parents of "a1/b1/c1" are expanded.
+    QCOMPARE(m_model->count(), 4);
+    QVERIFY(!m_model->isExpanded(0));
+    QVERIFY(m_model->isExpanded(1));
+    QVERIFY(m_model->isExpanded(2));
+    QVERIFY(!m_model->isExpanded(3));
+
+    // Expand the parents of "a 1/b1".
+    m_model->expandParentItems(KUrl(m_testDir->name() + "a 1/b1"));
+    QVERIFY(QTest::kWaitForSignal(m_model, SIGNAL(loadingCompleted()), DefaultTimeout));
+
+    // The model should now contain "a 1/", "a 1/b1/", "a2/", "a2/b2", and "a2/b2/c2/".
+    // It's important that only the parents of "a 1/b1/" and "a2/b2/c2/" are expanded.
+    QCOMPARE(m_model->count(), 5);
+    QVERIFY(m_model->isExpanded(0));
+    QVERIFY(!m_model->isExpanded(1));
+    QVERIFY(m_model->isExpanded(2));
+    QVERIFY(m_model->isExpanded(3));
+    QVERIFY(!m_model->isExpanded(4));
+}
+
 void KFileItemModelTest::testSorting()
 {
     // Create some files with different sizes and modification times to check the different sorting options
 void KFileItemModelTest::testSorting()
 {
     // Create some files with different sizes and modification times to check the different sorting options