]> cloud.milkyroute.net Git - dolphin.git/commitdiff
Treeview fixes:
authorPeter Penz <peter.penz19@gmail.com>
Thu, 17 Jan 2008 18:05:11 +0000 (18:05 +0000)
committerPeter Penz <peter.penz19@gmail.com>
Thu, 17 Jan 2008 18:05:11 +0000 (18:05 +0000)
* don't jump to the selected folder when expanding a sub tree within the treeview widget
* don't reset the root of non-local URLs when there is no Places-URL available

BUG: 155996
BUG: 156008

svn path=/trunk/KDE/kdebase/apps/; revision=762704

src/treeviewsidebarpage.cpp
src/treeviewsidebarpage.h

index 82e2a0507f43f882561ee9d61749628e32c896eb..3196fe7bd77395e8ee03d8405db8103aecbce3c4 100644 (file)
@@ -37,6 +37,7 @@
 
 TreeViewSidebarPage::TreeViewSidebarPage(QWidget* parent) :
     SidebarPage(parent),
+    m_setLeafVisible(false),
     m_dirLister(0),
     m_dolphinModel(0),
     m_proxyModel(0),
@@ -67,6 +68,7 @@ void TreeViewSidebarPage::setUrl(const KUrl& url)
 
     SidebarPage::setUrl(url);
     if (m_dirLister != 0) {
+        m_setLeafVisible = true;
         loadTree(url);
     }
 }
@@ -184,21 +186,13 @@ void TreeViewSidebarPage::expandToLeafDir()
     QModelIndex dirIndex = m_dolphinModel->indexForUrl(parentUrl);
     QModelIndex proxyIndex = m_proxyModel->mapFromSource(dirIndex);
     m_treeView->setExpanded(proxyIndex, true);
-
-    // assure that m_leafDir gets selected
-    dirIndex = m_dolphinModel->indexForUrl(m_leafDir);
-    proxyIndex = m_proxyModel->mapFromSource(dirIndex);
-    m_treeView->scrollTo(proxyIndex);
-
-    QItemSelectionModel* selModel = m_treeView->selectionModel();
-    selModel->setCurrentIndex(proxyIndex, QItemSelectionModel::Select);
+    selectLeafDirectory();
 }
 
 
 void TreeViewSidebarPage::loadSubTree()
 {
-    QItemSelectionModel* selModel = m_treeView->selectionModel();
-    selModel->clearSelection();
+    m_treeView->selectionModel()->clearSelection();
 
     if (m_leafDir.isParentOf(m_dirLister->url())) {
         // The leaf directory is not a child of the base URL, hence
@@ -208,10 +202,7 @@ void TreeViewSidebarPage::loadSubTree()
 
     const QModelIndex index = m_dolphinModel->indexForUrl(m_leafDir);
     if (index.isValid()) {
-        // the item with the given URL is already part of the model
-        const QModelIndex proxyIndex = m_proxyModel->mapFromSource(index);
-        m_treeView->scrollTo(proxyIndex);
-        selModel->setCurrentIndex(proxyIndex, QItemSelectionModel::Select);
+        selectLeafDirectory();
     } else {
         // Load all sub directories that need to get expanded for making
         // the leaf directory visible. The slot triggerExpanding() will
@@ -231,7 +222,14 @@ void TreeViewSidebarPage::loadTree(const KUrl& url)
     if (!baseUrl.isValid()) {
         // it's possible that no closest item is available and hence an
         // empty URL is returned
-        baseUrl = url;
+        if (url.isLocalFile()) {
+            // use the root directory as base for local URLs
+            baseUrl = KUrl("file:///");
+        } else {
+            // clear the path for non-local URLs and use it as base
+            baseUrl = url;
+            baseUrl.setPath(QString());
+        }
     }
 
     if (m_dirLister->url() != baseUrl) {
@@ -242,4 +240,18 @@ void TreeViewSidebarPage::loadTree(const KUrl& url)
     }
 }
 
+void TreeViewSidebarPage::selectLeafDirectory()
+{
+    const QModelIndex dirIndex = m_dolphinModel->indexForUrl(m_leafDir);
+    const QModelIndex proxyIndex = m_proxyModel->mapFromSource(dirIndex);
+
+    if (m_setLeafVisible) {
+        m_treeView->scrollTo(proxyIndex);
+        m_setLeafVisible = false;
+    }
+
+    QItemSelectionModel* selModel = m_treeView->selectionModel();
+    selModel->setCurrentIndex(proxyIndex, QItemSelectionModel::Select);
+}
+
 #include "treeviewsidebarpage.moc"
index 978323f409ea4db16fac76bd5cee5eb33e9a29d6..d0c3850e925ee639414a68bd70efc2159fa04a3e 100644 (file)
@@ -107,7 +107,15 @@ private:
      */
     void loadTree(const KUrl& url);
 
+    /**
+     * Selects the current leaf directory m_leafDir and assures
+     * that the directory is visible if the leaf has been set by
+     * TreeViewSidebarPage::setUrl().
+     */
+    void selectLeafDirectory();
+
 private:
+    bool m_setLeafVisible;
     bool m_dirListerCompleted;
     KDirLister* m_dirLister;
     DolphinModel* m_dolphinModel;