Restore filtering of items. The DolphinView just tells the controller about the filter, the views (1:1 iconView + detailView, 1:n columnView) connect to the filter-changed signal and apply it to their proxy model.

svn path=/trunk/KDE/kdebase/apps/; revision=1016782
This commit is contained in:
Peter Penz 2009-08-28 21:53:18 +00:00
parent 8d31eca0e0
commit e1c74b05fd
12 changed files with 64 additions and 50 deletions

View file

@ -172,6 +172,13 @@ DolphinColumnView::DolphinColumnView(QWidget* parent,
connect(controller, SIGNAL(zoomLevelChanged(int)),
this, SLOT(setZoomLevel(int)));
const QString nameFilter = controller->nameFilter();
if (!nameFilter.isEmpty()) {
m_proxyModel->setFilterRegExp(nameFilter);
}
connect(controller, SIGNAL(nameFilterChanged(const QString&)),
this, SLOT(setNameFilter(const QString&)));
updateDecorationSize(dolphinView->showPreview());
}
@ -458,6 +465,10 @@ void DolphinColumnView::currentChanged(const QModelIndex& current, const QModelI
m_autoScroller->handleCurrentIndexChange(current, previous);
}
void DolphinColumnView::setNameFilter(const QString& nameFilter)
{
m_proxyModel->setFilterRegExp(nameFilter);
}
void DolphinColumnView::setZoomLevel(int level)
{

View file

@ -104,6 +104,7 @@ protected:
virtual void currentChanged(const QModelIndex& current, const QModelIndex& previous);
private slots:
void setNameFilter(const QString& nameFilter);
void setZoomLevel(int level);
void slotEntered(const QModelIndex& index);

View file

@ -40,8 +40,7 @@ DolphinColumnViewContainer::DolphinColumnViewContainer(QWidget* parent, DolphinC
m_contentX(0),
m_columns(),
m_emptyViewport(0),
m_animation(0),
m_nameFilter()
m_animation(0)
{
Q_ASSERT(controller != 0);
@ -75,22 +74,6 @@ DolphinColumnViewContainer::~DolphinColumnViewContainer()
{
}
void DolphinColumnViewContainer::setNameFilter(const QString& nameFilter)
{
if (nameFilter != m_nameFilter) {
m_nameFilter = nameFilter;
foreach (DolphinColumnView* column, m_columns) {
DolphinSortFilterProxyModel* proxyModel = static_cast<DolphinSortFilterProxyModel*>(column->model());
proxyModel->setFilterRegExp(nameFilter);
}
}
}
QString DolphinColumnViewContainer::nameFilter() const
{
return m_nameFilter;
}
KUrl DolphinColumnViewContainer::rootUrl() const
{
return m_columns[0]->url();
@ -167,10 +150,6 @@ bool DolphinColumnViewContainer::showColumn(const KUrl& url)
columnIndex++;
DolphinColumnView* column = new DolphinColumnView(viewport(), this, childUrl);
if (!m_nameFilter.isEmpty()) {
DolphinSortFilterProxyModel* proxyModel = static_cast<DolphinSortFilterProxyModel*>(column->model());
proxyModel->setFilterRegExp(m_nameFilter);
}
column->setActive(false);
m_columns.append(column);

View file

@ -47,18 +47,6 @@ public:
explicit DolphinColumnViewContainer(QWidget* parent, DolphinController* controller);
virtual ~DolphinColumnViewContainer();
/**
* Filters the currently shown items by \a nameFilter. All items
* which contain the given filter string will be shown.
*/
void setNameFilter(const QString& nameFilter);
/**
* Returns the currently used name filter. All items
* which contain the name filter will be shown.
*/
QString nameFilter() const;
KUrl rootUrl() const;
QAbstractItemView* activeColumn() const;
@ -142,7 +130,6 @@ private:
QList<DolphinColumnView*> m_columns;
QFrame* m_emptyViewport;
QTimeLine* m_animation;
QString m_nameFilter;
friend class DolphinColumnView;
};

View file

@ -31,6 +31,7 @@ Qt::MouseButtons DolphinController::m_mouseButtons = Qt::NoButton;
DolphinController::DolphinController(DolphinView* dolphinView) :
QObject(dolphinView),
m_zoomLevel(0),
m_nameFilter(),
m_url(),
m_dolphinView(dolphinView),
m_itemView(0)
@ -119,6 +120,19 @@ void DolphinController::indicateActivationChange(bool active)
emit activationChanged(active);
}
void DolphinController::setNameFilter(const QString& nameFilter)
{
if (nameFilter != m_nameFilter) {
m_nameFilter = nameFilter;
emit nameFilterChanged(nameFilter);
}
}
QString DolphinController::nameFilter() const
{
return m_nameFilter;
}
void DolphinController::setZoomLevel(int level)
{
Q_ASSERT(level >= ZoomLevelInfo::minimumLevel());

View file

@ -70,6 +70,7 @@ class QPoint;
* - setShowHiddenFiles()
* - setShowPreview()
* - indicateActivationChange()
* - setNameFilter()
* - setZoomLevel()
*/
class LIBDOLPHINPRIVATE_EXPORT DolphinController : public QObject
@ -196,6 +197,12 @@ public:
void setZoomLevel(int level);
int zoomLevel() const;
/**
* Sets the name filter to \a and emits the signal nameFilterChanged().
*/
void setNameFilter(const QString& nameFilter);
QString nameFilter() const;
/**
* Tells the view implementation to zoom out by emitting the signal zoomOut()
* and is invoked by the abstract Dolphin view.
@ -373,6 +380,12 @@ signals:
*/
void viewportEntered();
/**
* Is emitted if the view should respect the name filter \a nameFilter. The view
* implementation must connect to this signal if it supports name filters.
*/
void nameFilterChanged(const QString& nameFilter);
/**
* Is emitted if the view should change the zoom to \a level. The view implementation
* must connect to this signal if it supports zooming.
@ -389,6 +402,7 @@ private slots:
private:
int m_zoomLevel;
QString m_nameFilter;
static Qt::MouseButtons m_mouseButtons; // TODO: this is a workaround until Qt-issue 176832 has been fixed
KUrl m_url;
DolphinView* m_dolphinView;

View file

@ -38,7 +38,6 @@
#include <klocale.h>
#include <kmenu.h>
#include <QAbstractProxyModel>
#include <QAction>
#include <QApplication>
#include <QHeaderView>
@ -122,6 +121,8 @@ DolphinDetailsView::DolphinDetailsView(QWidget* parent, DolphinController* contr
this, SLOT(slotEntered(const QModelIndex&)));
connect(this, SIGNAL(viewportEntered()),
controller, SLOT(emitViewportEntered()));
connect(controller, SIGNAL(nameFilterChanged(const QString&)),
this, SLOT(setNameFilter(const QString&)));
connect(controller, SIGNAL(zoomLevelChanged(int)),
this, SLOT(setZoomLevel(int)));
connect(controller->dolphinView(), SIGNAL(additionalInfoChanged()),
@ -531,6 +532,12 @@ QRect DolphinDetailsView::elasticBandRect() const
return QRect(topLeft, bottomRight).normalized();
}
void DolphinDetailsView::setNameFilter(const QString& nameFilter)
{
DolphinSortFilterProxyModel* proxyModel = static_cast<DolphinSortFilterProxyModel*>(model());
proxyModel->setFilterRegExp(nameFilter);
}
void DolphinDetailsView::setZoomLevel(int level)
{
const int size = ZoomLevelInfo::iconSizeForZoomLevel(level);

View file

@ -111,6 +111,8 @@ private slots:
*/
QRect elasticBandRect() const;
void setNameFilter(const QString& nameFilter);
void setZoomLevel(int level);
void slotShowPreviewChanged();

View file

@ -1,5 +1,5 @@
/***************************************************************************
* Copyright (C) 2006 by Peter Penz (peter.penz@gmx.at) *
* Copyright (C) 2006-2009 by Peter Penz <peter.penz@gmx.at> *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
@ -22,6 +22,7 @@
#include "dolphincategorydrawer.h"
#include "dolphincontroller.h"
#include "settings/dolphinsettings.h"
#include "dolphinsortfilterproxymodel.h"
#include "dolphinviewautoscroller.h"
#include "dolphin_iconsmodesettings.h"
#include "dolphin_generalsettings.h"
@ -85,6 +86,8 @@ DolphinIconsView::DolphinIconsView(QWidget* parent, DolphinController* controlle
controller, SLOT(emitItemEntered(const QModelIndex&)));
connect(this, SIGNAL(viewportEntered()),
controller, SLOT(emitViewportEntered()));
connect(controller, SIGNAL(nameFilterChanged(const QString&)),
this, SLOT(setNameFilter(const QString&)));
connect(controller, SIGNAL(zoomLevelChanged(int)),
this, SLOT(setZoomLevel(int)));
@ -391,6 +394,12 @@ void DolphinIconsView::slotAdditionalInfoChanged()
updateGridSize(showPreview, view->additionalInfo().count());
}
void DolphinIconsView::setNameFilter(const QString& nameFilter)
{
DolphinSortFilterProxyModel* proxyModel = static_cast<DolphinSortFilterProxyModel*>(model());
proxyModel->setFilterRegExp(nameFilter);
}
void DolphinIconsView::setZoomLevel(int level)
{
IconsModeSettings* settings = DolphinSettings::instance().iconsModeSettings();

View file

@ -1,5 +1,5 @@
/***************************************************************************
* Copyright (C) 2006 by Peter Penz (peter.penz@gmx.at) *
* Copyright (C) 2006-2009 by Peter Penz <peter.penz@gmx.at> *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
@ -73,6 +73,7 @@ protected:
private slots:
void slotShowPreviewChanged();
void slotAdditionalInfoChanged();
void setNameFilter(const QString& nameFilter);
void setZoomLevel(int level);
void requestActivation();
void slotGlobalSettingsChanged(int category);

View file

@ -500,7 +500,7 @@ void DolphinView::updateView(const KUrl& url, const KUrl& rootUrl)
void DolphinView::setNameFilter(const QString& nameFilter)
{
m_viewAccessor.setNameFilter(nameFilter);
m_controller->setNameFilter(nameFilter);
}
void DolphinView::calculateItemCount(int& fileCount,
@ -1555,15 +1555,6 @@ QWidget* DolphinView::ViewAccessor::layoutTarget() const
return itemView();
}
void DolphinView::ViewAccessor::setNameFilter(const QString& nameFilter)
{
if (m_columnsContainer == 0) {
m_columnsContainer->setNameFilter(nameFilter);
} else {
proxyModel()->setFilterRegExp(nameFilter);
}
}
KUrl DolphinView::ViewAccessor::rootUrl() const
{
return (m_columnsContainer != 0) ? m_columnsContainer->rootUrl() : KUrl();

View file

@ -779,8 +779,6 @@ private:
*/
QWidget* layoutTarget() const;
void setNameFilter(const QString& nameFilter);
KUrl rootUrl() const;
bool supportsCategorizedSorting() const;