]> cloud.milkyroute.net Git - dolphin.git/blobdiff - src/folderexpander.cpp
Fix temporary regression of sorting introduced by SVN commit 1126410
[dolphin.git] / src / folderexpander.cpp
index 777f7ffa34b0a3b9e9f6e61d61642d2f38b0d37a..a2dfb137b29a2bfdc4c4ab45f7c2f5b807408e94 100644 (file)
  ***************************************************************************/
 
 #include "folderexpander.h"
-#include "dolphinview.h"
-
-#include "dolphinsettings.h"
-#include "dolphin_generalsettings.h"
 
 #include <QtCore/QTimer>
 #include <QtGui/QAbstractItemView>
@@ -34,7 +30,6 @@
 #include <QtGui/QSortFilterProxyModel>
 
 #include <kdirmodel.h>
-#include <kdebug.h>
 
 FolderExpander::FolderExpander(QAbstractItemView *view, QSortFilterProxyModel *proxyModel) :
     QObject(view),
@@ -44,26 +39,21 @@ FolderExpander::FolderExpander(QAbstractItemView *view, QSortFilterProxyModel *p
     m_autoExpandTriggerTimer(0),
     m_autoExpandPos()
 {
-    // Validation.  If these fail, the event filter is never
-    // installed on the view and the FolderExpander is inactive.
     if (m_view == 0)  {
-        kWarning() << "Need a view!";
-        return; // Not valid.
+        return;
     }
     if (m_proxyModel == 0)  {
-        kWarning() << "Need a proxyModel!";
-        return; // Not valid.
+        return;
     }
-    KDirModel *m_dirModel = qobject_cast< KDirModel* >( m_proxyModel->sourceModel() );  
+    KDirModel *m_dirModel = qobject_cast<KDirModel*>(m_proxyModel->sourceModel());
     if (m_dirModel == 0) {
-        kWarning() << "Expected m_proxyModel's sourceModel() to be a KDirModel!";
-        return; // Not valid.
+        return;
     }
 
     // Initialise auto-expand timer.
     m_autoExpandTriggerTimer = new QTimer(this);
     m_autoExpandTriggerTimer->setSingleShot(true);
-    connect(m_autoExpandTriggerTimer, SIGNAL(timeout()), 
+    connect(m_autoExpandTriggerTimer, SIGNAL(timeout()),
             this, SLOT(autoExpandTimeout()));
 
     // The view scrolling complicates matters, so we want to
@@ -94,13 +84,6 @@ FolderExpander::~FolderExpander()
 void FolderExpander::viewScrolled()
 {
     if (m_autoExpandTriggerTimer->isActive())  {
-        kDebug() << "Resetting time due to scrolling!"; 
-        // (Re-)set the timer while we're scrolling the view
-        // (or it's being scrolled by some external mechanism).
-        // TODO - experiment with this.  Cancelling the timer,
-        // or adding a "penalty" on top of AUTO_EXPAND_DELAY
-        // might work more nicely when drilling down through the sidebar
-        // tree.
         m_autoExpandTriggerTimer->start(AUTO_EXPAND_DELAY);
     }
 }
@@ -116,24 +99,23 @@ void FolderExpander::autoExpandTimeout()
     // needing to pass in m_proxyModel that has a KDirModel as its sourceModel() ... ?
     QModelIndex proxyIndexToExpand = m_view->indexAt(m_autoExpandPos);
     QModelIndex indexToExpand = m_proxyModel->mapToSource(proxyIndexToExpand);
-    KDirModel* m_dirModel = qobject_cast< KDirModel* >(m_proxyModel->sourceModel()); 
+    KDirModel* m_dirModel = qobject_cast< KDirModel* >(m_proxyModel->sourceModel());
     Q_ASSERT(m_dirModel != 0);
-    KFileItem itemToExpand = m_dirModel->itemForIndex(indexToExpand );
+    KFileItem itemToExpand = m_dirModel->itemForIndex(indexToExpand);
 
-    if (itemToExpand.isNull()) {
+    if (itemToExpand.isNull() || itemToExpand == m_dirModel->itemForIndex(QModelIndex())) {
+        // The second clause occurs when we are expanding the folder represented
+        // by the view, which is a case we should ignore (#182618).
         return;
     }
-    
-    kDebug() << "Need to expand: " << itemToExpand.targetUrl() << " isDir? = " << itemToExpand.isDir();
 
     if (itemToExpand.isDir()) {
-        QTreeView *viewAsTreeView = qobject_cast<QTreeView*>(m_view);
-        if (viewAsTreeView != 0) {
+        QTreeView* treeView = qobject_cast<QTreeView*>(m_view);
+        if ((treeView != 0) && treeView->itemsExpandable()) {
             // Toggle expanded state of this directory.
-            viewAsTreeView->setExpanded(proxyIndexToExpand, !viewAsTreeView->isExpanded(proxyIndexToExpand));
+            treeView->setExpanded(proxyIndexToExpand, !treeView->isExpanded(proxyIndexToExpand));
         }
         else {
-            // Enter this directory.
             emit enterDir(proxyIndexToExpand);
         }
     }