Fixed 'Select All' and 'Invert Selection' for the column view (only the items of the currently active column will be selected, not the whole tree). The current implementation is quite slow, but this will be fixed later.

svn path=/trunk/KDE/kdebase/apps/; revision=696893
This commit is contained in:
Peter Penz 2007-08-06 06:56:36 +00:00
parent 1fbb2359d3
commit 0111d9b0a0
4 changed files with 62 additions and 22 deletions

View 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"

View 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;

View 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) {

View 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.