]> cloud.milkyroute.net Git - dolphin.git/commitdiff
DolphinTreeView contains some code to update the selection after a
authorFrank Reininghaus <frank78ac@googlemail.com>
Sun, 16 Jan 2011 18:35:36 +0000 (18:35 +0000)
committerFrank Reininghaus <frank78ac@googlemail.com>
Sun, 16 Jan 2011 18:35:36 +0000 (18:35 +0000)
keyboard search because QTreeView (unlike the other item views) does
not handle this internally.

This commit simplifies that code by performing the selection update in
the method keyboardSearch(). That way, we can get rid of the member
m_updateCurrentIndex and of 3 member functions. The unit tests still
pass, so I'm quite confident that this does not break anything.

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

src/views/dolphintreeview.cpp
src/views/dolphintreeview.h

index 9e7af0dab8c8ae7d2f5237c58c4fe064a4a8bc2f..64b66aa84f90fd43983a35e7f7eb6c7af8d12fee 100644 (file)
@@ -31,7 +31,6 @@
 
 DolphinTreeView::DolphinTreeView(QWidget* parent) :
     QTreeView(parent),
-    m_updateCurrentIndex(false),
     m_expandingTogglePressed(false),
     m_useDefaultIndexAt(true),
     m_ignoreScrollTo(false),
@@ -45,6 +44,17 @@ DolphinTreeView::~DolphinTreeView()
 {
 }
 
+void DolphinTreeView::keyboardSearch(const QString & search)
+{
+    const QModelIndex oldCurrent = currentIndex();
+    QTreeView::keyboardSearch(search);
+    if (currentIndex() != oldCurrent) {
+        // The current index has changed, but it is not selected yet.
+        // To select it, we call setCurrentIndex(...).
+        setCurrentIndex(currentIndex());
+    }
+}
+
 QRegion DolphinTreeView::visualRegionForSelection(const QItemSelection& selection) const
 {
     // We have to make sure that the visualRect of each model index is inside the region.
@@ -72,12 +82,6 @@ bool DolphinTreeView::event(QEvent* event)
     case QEvent::Polish:
         m_useDefaultIndexAt = false;
         break;
-    case QEvent::FocusOut:
-        // If a key-press triggers an action that e. g. opens a dialog, the
-        // widget gets no key-release event. Assure that the pressed state
-        // is reset to prevent accidently setting the current index during a selection.
-        m_updateCurrentIndex = false;
-        break;
     default:
         break;
     }
@@ -238,30 +242,6 @@ void DolphinTreeView::paintEvent(QPaintEvent* event)
     }
 }
 
-void DolphinTreeView::keyPressEvent(QKeyEvent* event)
-{
-    // See DolphinTreeView::currentChanged() for more information about m_updateCurrentIndex
-    m_updateCurrentIndex = (event->modifiers() == Qt::NoModifier);
-    QTreeView::keyPressEvent(event);
-}
-
-void DolphinTreeView::keyReleaseEvent(QKeyEvent* event)
-{
-    QTreeView::keyReleaseEvent(event);
-    m_updateCurrentIndex = false;
-}
-
-void DolphinTreeView::currentChanged(const QModelIndex& current, const QModelIndex& previous)
-{
-    QTreeView::currentChanged(current, previous);
-
-    // Stay consistent with QListView: When changing the current index by key presses
-    // without modifiers, also change the selection.
-    if (m_updateCurrentIndex) {
-        setCurrentIndex(current);
-    }
-}
-
 QModelIndex DolphinTreeView::indexAt(const QPoint& point) const
 {
     // The blank portion of the name column counts as empty space
index dbbc984a6fef076d593977b194e4799c2253d3ba..c037d412a09ff096e43c85ef2962b259ee75b8f6 100644 (file)
@@ -41,6 +41,7 @@ public:
     virtual ~DolphinTreeView();
 
     virtual QModelIndex indexAt (const QPoint& point) const;
+    virtual void keyboardSearch(const QString & search);
     virtual QRegion visualRegionForSelection(const QItemSelection& selection) const;
 
 protected:
@@ -60,9 +61,6 @@ protected:
     virtual void dragMoveEvent(QDragMoveEvent* event);
     virtual void dragLeaveEvent(QDragLeaveEvent* event);
     virtual void paintEvent(QPaintEvent* event);
-    virtual void keyPressEvent(QKeyEvent* event);
-    virtual void keyReleaseEvent(QKeyEvent* event);
-    virtual void currentChanged(const QModelIndex& current, const QModelIndex& previous);
     virtual void setSelection(const QRect& rect, QItemSelectionModel::SelectionFlags command);
     virtual void scrollTo(const QModelIndex& index, ScrollHint hint = EnsureVisible);
 
@@ -95,7 +93,6 @@ private:
     bool isAboveExpandingToggle(const QPoint& pos) const;
 
 private:
-    bool m_updateCurrentIndex;
     bool m_expandingTogglePressed;
     bool m_useDefaultIndexAt; // true, if QTreeView::indexAt() should be used
     bool m_ignoreScrollTo;    // true if calls to scrollTo(...) should do nothing.