mirror of
https://invent.kde.org/system/dolphin
synced 2024-07-04 17:30:55 +00:00
Use QSortFilterProxyModel for sorting KFileItems (thanks to Fredrik for this hint!). TODO: the implementation does not work yet, as QSortFilerProxyModel::lessThan() is not invoked; I'm too tired currently for finding the root of this ;-)
svn path=/trunk/playground/utils/dolphin/; revision=613747
This commit is contained in:
parent
418cfc1d74
commit
1547891be2
|
@ -24,6 +24,7 @@ set(dolphin_SRCS
|
|||
bookmarkselector.cpp
|
||||
urlbutton.cpp
|
||||
dolphincontextmenu.cpp
|
||||
dolphinsortfilterproxymodel.cpp
|
||||
undomanager.cpp
|
||||
progressindicator.cpp
|
||||
iconsviewsettingspage.cpp
|
||||
|
|
72
src/dolphinsortfilterproxymodel.cpp
Normal file
72
src/dolphinsortfilterproxymodel.cpp
Normal file
|
@ -0,0 +1,72 @@
|
|||
/***************************************************************************
|
||||
* Copyright (C) 2006 by Peter Penz <peter.penz@gmx.at> *
|
||||
* Copyright (C) 2006 by Gregor Kališnik <gregor@podnapisi.net> *
|
||||
* *
|
||||
* 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 *
|
||||
* the Free Software Foundation; either version 2 of the License, or *
|
||||
* (at your option) any later version. *
|
||||
* *
|
||||
* This program is distributed in the hope that it will be useful, *
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
||||
* GNU General Public License for more details. *
|
||||
* *
|
||||
* You should have received a copy of the GNU General Public License *
|
||||
* along with this program; if not, write to the *
|
||||
* Free Software Foundation, Inc., *
|
||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA *
|
||||
***************************************************************************/
|
||||
|
||||
#include "dolphinsortfilterproxymodel.h"
|
||||
|
||||
#include <kdirmodel.h>
|
||||
#include <kfileitem.h>
|
||||
|
||||
DolphinSortFilterProxyModel::DolphinSortFilterProxyModel(QObject* parent) :
|
||||
QSortFilterProxyModel(parent),
|
||||
m_sorting(DolphinView::SortByName),
|
||||
m_sortOrder(Qt::Ascending)
|
||||
{
|
||||
}
|
||||
|
||||
DolphinSortFilterProxyModel::~DolphinSortFilterProxyModel()
|
||||
{
|
||||
}
|
||||
|
||||
void DolphinSortFilterProxyModel::setSorting(DolphinView::Sorting sorting)
|
||||
{
|
||||
if (sorting != m_sorting) {
|
||||
m_sorting = sorting;
|
||||
// TODO: how to trigger an update?
|
||||
}
|
||||
}
|
||||
|
||||
void DolphinSortFilterProxyModel::setSortOrder(Qt::SortOrder sortOrder)
|
||||
{
|
||||
if (sortOrder != m_sortOrder) {
|
||||
m_sortOrder = sortOrder;
|
||||
// TODO: how to trigger an update?
|
||||
}
|
||||
}
|
||||
|
||||
bool DolphinSortFilterProxyModel::lessThan(const QModelIndex& left,
|
||||
const QModelIndex& right) const
|
||||
{
|
||||
// TODO: this is just a test implementation
|
||||
KDirModel* model = static_cast<KDirModel*>(sourceModel());
|
||||
|
||||
KFileItem* leftItem = model->itemForIndex(left);
|
||||
if (leftItem == 0) {
|
||||
return true;
|
||||
}
|
||||
|
||||
KFileItem* rightItem = model->itemForIndex(right);
|
||||
if (rightItem == 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return leftItem->name() > rightItem->name();
|
||||
}
|
||||
|
||||
#include "dolphinsortfilterproxymodel.moc"
|
56
src/dolphinsortfilterproxymodel.h
Normal file
56
src/dolphinsortfilterproxymodel.h
Normal file
|
@ -0,0 +1,56 @@
|
|||
/***************************************************************************
|
||||
* Copyright (C) 2006 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 *
|
||||
* the Free Software Foundation; either version 2 of the License, or *
|
||||
* (at your option) any later version. *
|
||||
* *
|
||||
* This program is distributed in the hope that it will be useful, *
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
||||
* GNU General Public License for more details. *
|
||||
* *
|
||||
* You should have received a copy of the GNU General Public License *
|
||||
* along with this program; if not, write to the *
|
||||
* Free Software Foundation, Inc., *
|
||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA *
|
||||
***************************************************************************/
|
||||
|
||||
#ifndef DOLPHINSORTFILTERPROXYMODEL_H
|
||||
#define DOLPHINSORTFILTERPROXYMODEL_H
|
||||
|
||||
#include <QSortFilterProxyModel>
|
||||
#include <dolphinview.h>
|
||||
|
||||
/**
|
||||
* @brief Acts as proxy model for KDirModel to sort and filter
|
||||
* KFileItems.
|
||||
*
|
||||
* TODO: implementation does not work yet (the method lessThan is
|
||||
* not invoked)
|
||||
*/
|
||||
class DolphinSortFilterProxyModel : public QSortFilterProxyModel
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
DolphinSortFilterProxyModel(QObject* parent = 0);
|
||||
virtual ~DolphinSortFilterProxyModel();
|
||||
|
||||
void setSorting(DolphinView::Sorting sorting);
|
||||
DolphinView::Sorting sorting() const { return m_sorting; }
|
||||
|
||||
void setSortOrder(Qt::SortOrder sortOrder);
|
||||
Qt::SortOrder sortOrder() const { return m_sortOrder; }
|
||||
|
||||
protected:
|
||||
virtual bool lessThan(const QModelIndex& left,
|
||||
const QModelIndex& right) const;
|
||||
|
||||
private:
|
||||
DolphinView::Sorting m_sorting;
|
||||
Qt::SortOrder m_sortOrder;
|
||||
};
|
||||
|
||||
#endif
|
|
@ -39,6 +39,7 @@
|
|||
#include "dolphinstatusbar.h"
|
||||
#include "dolphinmainwindow.h"
|
||||
#include "dolphindirlister.h"
|
||||
#include "dolphinsortfilterproxymodel.h"
|
||||
#include "viewproperties.h"
|
||||
#include "dolphindetailsview.h"
|
||||
#include "dolphiniconsview.h"
|
||||
|
@ -57,12 +58,17 @@ DolphinView::DolphinView(DolphinMainWindow *mainWindow,
|
|||
m_refreshing(false),
|
||||
m_showProgress(false),
|
||||
m_mode(mode),
|
||||
m_mainWindow(mainWindow),
|
||||
m_statusBar(0),
|
||||
m_iconSize(0),
|
||||
m_folderCount(0),
|
||||
m_fileCount(0),
|
||||
m_filterBar(0)
|
||||
m_mainWindow(mainWindow),
|
||||
m_topLayout(0),
|
||||
m_urlNavigator(0),
|
||||
m_iconsView(0),
|
||||
m_filterBar(0),
|
||||
m_statusBar(0),
|
||||
m_dirLister(0),
|
||||
m_proxyModel(0)
|
||||
{
|
||||
hide();
|
||||
setFocusPolicy(Qt::StrongFocus);
|
||||
|
@ -98,6 +104,11 @@ DolphinView::DolphinView(DolphinMainWindow *mainWindow,
|
|||
|
||||
KDirModel* model = new KDirModel();
|
||||
model->setDirLister(m_dirLister);
|
||||
|
||||
m_proxyModel = new DolphinSortFilterProxyModel(this);
|
||||
m_proxyModel->setSourceModel(model);
|
||||
m_proxyModel->setDynamicSortFilter(true);
|
||||
|
||||
m_iconsView->setModel(model);
|
||||
|
||||
KFileItemDelegate* delegate = new KFileItemDelegate(this);
|
||||
|
@ -395,8 +406,7 @@ void DolphinView::setSorting(Sorting sorting)
|
|||
ViewProperties props(url());
|
||||
props.setSorting(sorting);
|
||||
|
||||
KDirModel* dirModel = static_cast<KDirModel*>(m_iconsView->model());
|
||||
dirModel->sort(columnIndex(sorting), props.sortOrder());
|
||||
m_proxyModel->setSorting(sorting);
|
||||
|
||||
emit sortingChanged(sorting);
|
||||
}
|
||||
|
@ -404,10 +414,7 @@ void DolphinView::setSorting(Sorting sorting)
|
|||
|
||||
DolphinView::Sorting DolphinView::sorting() const
|
||||
{
|
||||
// TODO: instead of getting the sorting from the properties just fetch
|
||||
// them from KDirModel, if such an interface will be offered (David?)
|
||||
ViewProperties props(url());
|
||||
return props.sorting();
|
||||
return m_proxyModel->sorting();
|
||||
}
|
||||
|
||||
void DolphinView::setSortOrder(Qt::SortOrder order)
|
||||
|
@ -416,8 +423,7 @@ void DolphinView::setSortOrder(Qt::SortOrder order)
|
|||
ViewProperties props(url());
|
||||
props.setSortOrder(order);
|
||||
|
||||
KDirModel* dirModel = static_cast<KDirModel*>(m_iconsView->model());
|
||||
dirModel->sort(columnIndex(props.sorting()), order);
|
||||
m_proxyModel->setSortOrder(order);
|
||||
|
||||
emit sortOrderChanged(order);
|
||||
}
|
||||
|
@ -425,10 +431,7 @@ void DolphinView::setSortOrder(Qt::SortOrder order)
|
|||
|
||||
Qt::SortOrder DolphinView::sortOrder() const
|
||||
{
|
||||
// TODO: instead of getting the order from the properties just fetch
|
||||
// them from KDirModel, if such an interface will be offered (David?)
|
||||
ViewProperties props(url());
|
||||
return props.sortOrder();
|
||||
return m_proxyModel->sortOrder();
|
||||
}
|
||||
|
||||
void DolphinView::goBack()
|
||||
|
|
|
@ -50,6 +50,7 @@ class DolphinDirLister;
|
|||
class DolphinStatusBar;
|
||||
class DolphinIconsView;
|
||||
class DolphinDetailsView;
|
||||
class DolphinSortFilterProxyModel;
|
||||
class ViewProperties;
|
||||
class KProgress;
|
||||
class FilterBar;
|
||||
|
@ -452,19 +453,20 @@ private:
|
|||
bool m_showProgress;
|
||||
Mode m_mode;
|
||||
|
||||
DolphinMainWindow* m_mainWindow;
|
||||
QVBoxLayout* m_topLayout;
|
||||
UrlNavigator* m_urlNavigator;
|
||||
DolphinIconsView* m_iconsView;
|
||||
DolphinStatusBar* m_statusBar;
|
||||
|
||||
int m_iconSize;
|
||||
int m_folderCount;
|
||||
int m_fileCount;
|
||||
|
||||
DolphinDirLister* m_dirLister;
|
||||
|
||||
DolphinMainWindow* m_mainWindow;
|
||||
QVBoxLayout* m_topLayout;
|
||||
UrlNavigator* m_urlNavigator;
|
||||
DolphinIconsView* m_iconsView;
|
||||
FilterBar *m_filterBar;
|
||||
DolphinStatusBar* m_statusBar;
|
||||
|
||||
DolphinDirLister* m_dirLister;
|
||||
DolphinSortFilterProxyModel* m_proxyModel;
|
||||
|
||||
};
|
||||
|
||||
#endif // _DOLPHINVIEW_H_
|
||||
|
|
Loading…
Reference in New Issue
Block a user