]> cloud.milkyroute.net Git - dolphin.git/commitdiff
assure that "Select All" and "Invert Selection" only operate on the active column...
authorPeter Penz <peter.penz19@gmail.com>
Tue, 25 Sep 2007 13:53:08 +0000 (13:53 +0000)
committerPeter Penz <peter.penz19@gmail.com>
Tue, 25 Sep 2007 13:53:08 +0000 (13:53 +0000)
svn path=/trunk/KDE/kdebase/apps/; revision=716885

src/dolphincolumnview.cpp
src/dolphincolumnview.h
src/dolphinview.cpp

index 979ff7649fe746b665387d6cbc53c795350117d0..6df71cc1e81a057801265da5871c23b8a93d3d22 100644 (file)
@@ -503,6 +503,23 @@ void DolphinColumnView::reload()
     dirLister->openUrl(rootUrl, false, true);
 }
 
+void DolphinColumnView::invertSelection()
+{
+    // TODO: this approach of inverting the selection is quite slow. It should
+    // be possible to speedup the implementation by using QItemSelection, but
+    // all adempts have failed yet...
+
+    ColumnWidget* column = activeColumn();
+    QItemSelectionModel* selModel = column->selectionModel();
+
+    KDirLister* dirLister = m_dolphinModel->dirLister();
+    const KFileItemList list = dirLister->itemsForDir(column->url());
+    foreach (KFileItem* item, list) {
+        const QModelIndex index = m_dolphinModel->indexForUrl(item->url());
+        selModel->select(m_proxyModel->mapFromSource(index), QItemSelectionModel::Toggle);
+    }
+}
+
 void DolphinColumnView::showColumn(const KUrl& url)
 {
     const KUrl& rootUrl = m_columns[0]->url();
@@ -621,6 +638,11 @@ void DolphinColumnView::showColumn(const KUrl& url)
     expandToActiveUrl();
 }
 
+void DolphinColumnView::selectAll()
+{
+    activeColumn()->selectAll();
+}
+
 bool DolphinColumnView::isIndexHidden(const QModelIndex& index) const
 {
     Q_UNUSED(index);
index 75d07ce07d1d0b69e616a80ee7ee723892b1b724..639ccec32af0ebd7dd07815de8631d6e21b416de 100644 (file)
@@ -57,6 +57,9 @@ public:
      */
     void reload();
 
+    /** Inverts the selection of the currently active column. */
+    void invertSelection();
+
 public slots:
     /**
      * Shows the column which represents the URL \a url. If the column
@@ -64,6 +67,9 @@ public slots:
      */
     void showColumn(const KUrl& url);
 
+    /** @see QAbstractItemView::selectAll() */
+    virtual void selectAll();
+
 protected:
     virtual bool isIndexHidden(const QModelIndex& index) const;
     virtual QModelIndex moveCursor(CursorAction cursorAction, Qt::KeyboardModifiers modifiers);
index dc8c8dd87bdefab011cd430c8e645886ff3fb32e..a85e2db9ba482c08c420c825421f242ff954eabe 100644 (file)
@@ -252,15 +252,24 @@ void DolphinView::selectAll()
 
 void DolphinView::invertSelection()
 {
-    QItemSelectionModel* selectionModel = itemView()->selectionModel();
-    const QAbstractItemModel* itemModel = selectionModel->model();
+    if (isColumnViewActive()) {
+        // QAbstractItemView does not offer a virtual method invertSelection()
+        // as counterpart to QAbstractItemView::selectAll(). This makes it
+        // necessary to delegate the inverting of the selection to the
+        // column view, as only the selection of the active column should get
+        // inverted.
+        m_columnView->invertSelection();
+    } else {
+        QItemSelectionModel* selectionModel = itemView()->selectionModel();
+        const QAbstractItemModel* itemModel = selectionModel->model();
 
-    const QModelIndex topLeft = itemModel->index(0, 0);
-    const QModelIndex bottomRight = itemModel->index(itemModel->rowCount() - 1,
-                                                     itemModel->columnCount() - 1);
+        const QModelIndex topLeft = itemModel->index(0, 0);
+        const QModelIndex bottomRight = itemModel->index(itemModel->rowCount() - 1,
+                                                         itemModel->columnCount() - 1);
 
-    QItemSelection selection(topLeft, bottomRight);
-    selectionModel->select(selection, QItemSelectionModel::Toggle);
+        const QItemSelection selection(topLeft, bottomRight);
+        selectionModel->select(selection, QItemSelectionModel::Toggle);
+    }
 }
 
 bool DolphinView::hasSelection() const