]> cloud.milkyroute.net Git - dolphin.git/commitdiff
Fixed 'Select All' and 'Invert Selection' for the column view (only the items of...
authorPeter Penz <peter.penz19@gmail.com>
Mon, 6 Aug 2007 06:56:36 +0000 (06:56 +0000)
committerPeter Penz <peter.penz19@gmail.com>
Mon, 6 Aug 2007 06:56:36 +0000 (06:56 +0000)
svn path=/trunk/KDE/kdebase/apps/; revision=696893

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

index f4a5ef19a9cb4f7e78449d7bf391f43d304c03bf..ee7fb52aa4c6fea8a30ed0e72bae853a5bd1a8ca 100644 (file)
@@ -173,6 +173,7 @@ void ColumnWidget::obtainSelectionModel()
     if (selectionModel() != m_view->selectionModel()) {
         selectionModel()->deleteLater();
         setSelectionModel(m_view->selectionModel());
+        clearSelection();
     }
 }
 
@@ -428,6 +429,16 @@ DolphinColumnView::~DolphinColumnView()
 {
 }
 
+void DolphinColumnView::invertSelection()
+{
+    selectActiveColumn(QItemSelectionModel::Toggle);
+}
+
+void DolphinColumnView::selectAll()
+{
+    selectActiveColumn(QItemSelectionModel::Select);
+}
+
 QAbstractItemView* DolphinColumnView::createColumn(const QModelIndex& index)
 {
     // let the column widget be aware about its URL...
@@ -598,7 +609,7 @@ void DolphinColumnView::requestActivation(QWidget* column)
             const bool isActive = (widget == column);
             widget->setActive(isActive);
             if (isActive) {
-                m_controller->setUrl(widget->url());
+               m_controller->setUrl(widget->url());
             }
         }
     }
@@ -618,4 +629,23 @@ void DolphinColumnView::requestSelectionModel(QAbstractItemView* view)
     }
 }
 
+void DolphinColumnView::selectActiveColumn(QItemSelectionModel::SelectionFlags flags)
+{
+    // TODO: this approach of selecting the active column is very slow. It should be
+    // possible to speedup the implementation by using QItemSelection, but all adempts
+    // have failed yet...
+
+    QItemSelectionModel* selModel = selectionModel();
+
+    const QAbstractProxyModel* proxyModel = static_cast<const QAbstractProxyModel*>(model());
+    const KDirModel* dirModel = static_cast<const KDirModel*>(proxyModel->sourceModel());
+    KDirLister* dirLister = dirModel->dirLister();
+
+    const KFileItemList list = dirLister->itemsForDir(m_controller->url());
+    foreach (KFileItem* item, list) {
+        const QModelIndex index = dirModel->indexForUrl(item->url());
+        selModel->select(proxyModel->mapFromSource(index), flags);
+    }
+}
+
 #include "dolphincolumnview.moc"
index 03f210229fed4aceaf380841e79c08595bef0beb..b2471fdb76f53e3ec14ba8fd67467674d5e309dc 100644 (file)
@@ -41,6 +41,15 @@ public:
     explicit DolphinColumnView(QWidget* parent, DolphinController* controller);
     virtual ~DolphinColumnView();
 
+    /**
+     * Inverts the selection for the current active column.
+     */
+    void invertSelection();
+
+public slots:
+    /** @see QAbstractItemView::selectAll() */
+    virtual void selectAll();
+
 protected:
     virtual QAbstractItemView* createColumn(const QModelIndex& index);
     virtual void mousePressEvent(QMouseEvent* event);
@@ -86,6 +95,11 @@ private:
      */
     void requestSelectionModel(QAbstractItemView* view);
 
+    /**
+     * Helper method for selecting all items of an active column by \a flags.
+     */
+    void selectActiveColumn(QItemSelectionModel::SelectionFlags flags);
+
 private:
     DolphinController* m_controller;
 
index 7fc727475de6477b8b4d4c224de4b8e6599f2442..a9f160d007035ea00c84f31278793e8151b3aec9 100644 (file)
@@ -269,12 +269,27 @@ bool DolphinView::supportsCategorizedSorting() const
 
 void DolphinView::selectAll()
 {
-    selectAll(QItemSelectionModel::Select);
+    itemView()->selectAll();
 }
 
 void DolphinView::invertSelection()
 {
-    selectAll(QItemSelectionModel::Toggle);
+    if (isColumnViewActive()) {
+        // In opposite to QAbstractItemView::selectAll() there is no virtual method
+        // for adjusting the invertion of a selection. As the generic approach by using
+        // the selection model does not work for the column view, we delegate this task:
+        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);
+
+        QItemSelection selection(topLeft, bottomRight);
+        selectionModel->select(selection, QItemSelectionModel::Toggle);
+    }
 }
 
 bool DolphinView::hasSelection() const
@@ -878,19 +893,6 @@ void DolphinView::createView()
             this, SLOT(emitContentsMoved()));
 }
 
-void DolphinView::selectAll(QItemSelectionModel::SelectionFlags flags)
-{
-    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);
-
-    QItemSelection selection(topLeft, bottomRight);
-    selectionModel->select(selection, flags);
-}
-
 QAbstractItemView* DolphinView::itemView() const
 {
     if (m_detailsView != 0) {
index b26a27069edcd2b796ba500b6a3f468a5d48946d..39e39ef3f2fcff4ce1da0a5d604114c25728c922 100644 (file)
@@ -496,12 +496,6 @@ private:
      */
     void createView();
 
-    /**
-     * Selects all items by using the selection flags \a flags. This is a helper
-     * method for the slots DolphinView::selectAll() and DolphinView::invertSelection().
-     */
-    void selectAll(QItemSelectionModel::SelectionFlags flags);
-
     /**
      * Returns a pointer to the currently used item view, which is either
      * a ListView or a TreeView.