From: Peter Penz Date: Tue, 25 Sep 2007 13:53:08 +0000 (+0000) Subject: assure that "Select All" and "Invert Selection" only operate on the active column... X-Git-Url: https://cloud.milkyroute.net/gitweb/dolphin.git/commitdiff_plain/41f8286a568f01bc2723eb74e763556b4c397546 assure that "Select All" and "Invert Selection" only operate on the active column of the column-view instead of selecting the whole hierarchy of the model svn path=/trunk/KDE/kdebase/apps/; revision=716885 --- diff --git a/src/dolphincolumnview.cpp b/src/dolphincolumnview.cpp index 979ff7649..6df71cc1e 100644 --- a/src/dolphincolumnview.cpp +++ b/src/dolphincolumnview.cpp @@ -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); diff --git a/src/dolphincolumnview.h b/src/dolphincolumnview.h index 75d07ce07..639ccec32 100644 --- a/src/dolphincolumnview.h +++ b/src/dolphincolumnview.h @@ -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); diff --git a/src/dolphinview.cpp b/src/dolphinview.cpp index dc8c8dd87..a85e2db9b 100644 --- a/src/dolphinview.cpp +++ b/src/dolphinview.cpp @@ -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