]> cloud.milkyroute.net Git - dolphin.git/commitdiff
Send the selectionChanged() signal without delay in case the selection has been chang...
authorPeter Penz <peter.penz19@gmail.com>
Wed, 6 Jan 2010 22:11:28 +0000 (22:11 +0000)
committerPeter Penz <peter.penz19@gmail.com>
Wed, 6 Jan 2010 22:11:28 +0000 (22:11 +0000)
BUG: 210256

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

src/dolphinview.cpp
src/dolphinview.h

index e70cd446b18740366a85e676db217e40a9613af5..1a8435eea1638ae060409c53d1eebc93bc22809b 100644 (file)
@@ -290,7 +290,7 @@ bool DolphinView::supportsCategorizedSorting() const
 bool DolphinView::hasSelection() const
 {
     const QAbstractItemView* view = m_viewAccessor.itemView();
 bool DolphinView::hasSelection() const
 {
     const QAbstractItemView* view = m_viewAccessor.itemView();
-    return view && view->selectionModel()->hasSelection();
+    return (view != 0) && view->selectionModel()->hasSelection();
 }
 
 void DolphinView::markUrlsAsSelected(const QList<KUrl>& urls)
 }
 
 void DolphinView::markUrlsAsSelected(const QList<KUrl>& urls)
@@ -303,14 +303,13 @@ void DolphinView::markUrlsAsSelected(const QList<KUrl>& urls)
 
 KFileItemList DolphinView::selectedItems() const
 {
 
 KFileItemList DolphinView::selectedItems() const
 {
+    KFileItemList itemList;
     const QAbstractItemView* view = m_viewAccessor.itemView();
     const QAbstractItemView* view = m_viewAccessor.itemView();
-
-    // Our view has a selection, we will map them back to the DolphinModel
-    // and then fill the KFileItemList.
-    Q_ASSERT((view != 0) && (view->selectionModel() != 0));
+    if (view == 0) {
+        return itemList;
+    }
 
     const QItemSelection selection = m_viewAccessor.proxyModel()->mapSelectionToSource(view->selectionModel()->selection());
 
     const QItemSelection selection = m_viewAccessor.proxyModel()->mapSelectionToSource(view->selectionModel()->selection());
-    KFileItemList itemList;
 
     const QModelIndexList indexList = selection.indexes();
     foreach (const QModelIndex &index, indexList) {
 
     const QModelIndexList indexList = selection.indexes();
     foreach (const QModelIndex &index, indexList) {
@@ -335,7 +334,12 @@ KUrl::List DolphinView::selectedUrls() const
 
 int DolphinView::selectedItemsCount() const
 {
 
 int DolphinView::selectedItemsCount() const
 {
-    return m_viewAccessor.itemView()->selectionModel()->selectedIndexes().count();
+    const QAbstractItemView* view = m_viewAccessor.itemView();
+    if (view == 0) {
+        return 0;
+    }
+
+    return view->selectionModel()->selectedIndexes().count();
 }
 
 QItemSelectionModel* DolphinView::selectionModel() const
 }
 
 QItemSelectionModel* DolphinView::selectionModel() const
@@ -907,11 +911,17 @@ void DolphinView::triggerItem(const KFileItem& item)
     emit itemTriggered(item); // caught by DolphinViewContainer or DolphinPart
 }
 
     emit itemTriggered(item); // caught by DolphinViewContainer or DolphinPart
 }
 
-void DolphinView::emitDelayedSelectionChangedSignal()
+void DolphinView::slotSelectionChanged(const QItemSelection& selected, const QItemSelection& deselected)
 {
 {
-    // Invoke emitSelectionChangedSignal() with a delay of 300 ms. This assures
-    // that fast selection changes don't result in expensive operations to
-    // collect all file items for the signal (see DolphinView::selectedItems()).
+    const int count = selectedItemsCount();
+    const bool selectionStateChanged = ((count >  0) && (selected.count() == count)) ||
+                                       ((count == 0) && !deselected.isEmpty());
+
+    // If nothing has been selected before and something got selected (or if something
+    // was selected before and now nothing is selected) the selectionChangedSignal must
+    // be emitted asynchronously as fast as possible to update the edit-actions.
+    m_selectionChangedTimer->setInterval(selectionStateChanged ? 0 : 300);
+    const int foo = selectionStateChanged ? 0 : 300;
     m_selectionChangedTimer->start();
 }
 
     m_selectionChangedTimer->start();
 }
 
@@ -1368,7 +1378,7 @@ void DolphinView::createView()
     }
     m_selectionModel->setParent(this);
     connect(view->selectionModel(), SIGNAL(selectionChanged(const QItemSelection&, const QItemSelection&)),
     }
     m_selectionModel->setParent(this);
     connect(view->selectionModel(), SIGNAL(selectionChanged(const QItemSelection&, const QItemSelection&)),
-            this, SLOT(emitDelayedSelectionChangedSignal()));
+            this, SLOT(slotSelectionChanged(const QItemSelection&, const QItemSelection&)));
 
     connect(view->verticalScrollBar(), SIGNAL(valueChanged(int)),
             this, SLOT(emitContentsMoved()));
 
     connect(view->verticalScrollBar(), SIGNAL(valueChanged(int)),
             this, SLOT(emitContentsMoved()));
index 2120e1ee01759df4a9e0cf3961201f5205885949..91a66ddcc1b67d6bcb04db89ee371b791ba5546c 100644 (file)
@@ -600,7 +600,7 @@ private slots:
      * the signal is emitted only after no selection change has been done
      * within a small delay.
      */
      * the signal is emitted only after no selection change has been done
      * within a small delay.
      */
-    void emitDelayedSelectionChangedSignal();
+    void slotSelectionChanged(const QItemSelection& selected, const QItemSelection& deselected);
 
     /**
      * Is called by emitDelayedSelectionChangedSignal() and emits the
 
     /**
      * Is called by emitDelayedSelectionChangedSignal() and emits the