Cleanups and simplifications, no change of behavior has been done.

svn path=/trunk/KDE/kdebase/apps/; revision=1126677
This commit is contained in:
Peter Penz 2010-05-14 16:03:22 +00:00
parent 45a74179ae
commit f69f314c50
2 changed files with 13 additions and 94 deletions

View file

@ -1,5 +1,5 @@
/***************************************************************************
* Copyright (C) 2006 by Peter Penz <peter.penz@gmx.at> *
* Copyright (C) 2006-2010 by Peter Penz <peter.penz@gmx.at> *
* Copyright (C) 2006 by Dominic Battre <dominic@battre.de> *
* Copyright (C) 2006 by Martin Pool <mbp@canonical.com> *
* Copyright (C) 2007 by Rafael Fernández López <ereslibre@kde.org> *
@ -22,26 +22,6 @@
#include "dolphinsortfilterproxymodel.h"
#include <config-nepomuk.h>
#include "dolphinmodel.h"
#include <kfileitem.h>
#include <kdatetime.h>
#include <klocale.h>
#include <kstringhandler.h>
static DolphinView::Sorting sortingTypeTable[] =
{
DolphinView::SortByName, // DolphinModel::Name
DolphinView::SortBySize, // DolphinModel::Size
DolphinView::SortByDate, // DolphinModel::ModifiedTime
DolphinView::SortByPermissions, // DolphinModel::Permissions
DolphinView::SortByOwner, // DolphinModel::Owner
DolphinView::SortByGroup, // DolphinModel::Group
DolphinView::SortByType // DolphinModel::Type
};
DolphinSortFilterProxyModel::DolphinSortFilterProxyModel(QObject* parent) :
KDirSortFilterProxyModel(parent),
m_sorting(DolphinView::SortByName),
@ -56,17 +36,13 @@ DolphinSortFilterProxyModel::~DolphinSortFilterProxyModel()
void DolphinSortFilterProxyModel::setSorting(DolphinView::Sorting sorting)
{
m_sorting = sorting;
// change the sorting column by keeping the current sort order
KDirSortFilterProxyModel::sort((int) m_sorting, m_sortOrder);
KDirSortFilterProxyModel::sort(static_cast<int>(m_sorting), m_sortOrder);
}
void DolphinSortFilterProxyModel::setSortOrder(Qt::SortOrder sortOrder)
{
m_sortOrder = sortOrder;
// change the sort order by keeping the current column
KDirSortFilterProxyModel::sort((int) m_sorting, m_sortOrder);
KDirSortFilterProxyModel::sort(static_cast<int>(m_sorting), m_sortOrder);
}
void DolphinSortFilterProxyModel::setSortFoldersFirst(bool foldersFirst)
@ -78,12 +54,12 @@ void DolphinSortFilterProxyModel::setSortFoldersFirst(bool foldersFirst)
// Without the following two lines, QSortFilterProxyModel::sort(int column, Qt::SortOrder order)
// would do nothing because neither the column nor the sort order have changed.
// TODO: remove this hack if we find a better way to force the ProxyModel to re-sort the data.
Qt::SortOrder tmpSortOrder = (m_sortOrder == Qt::AscendingOrder ? Qt::DescendingOrder : Qt::AscendingOrder);
KDirSortFilterProxyModel::sort((int) m_sorting, tmpSortOrder);
const Qt::SortOrder tmpSortOrder = (m_sortOrder == Qt::AscendingOrder ? Qt::DescendingOrder : Qt::AscendingOrder);
KDirSortFilterProxyModel::sort(static_cast<int>(m_sorting), tmpSortOrder);
// Now comes the real sorting with the old column and sort order
KDirSortFilterProxyModel::sort((int) m_sorting, m_sortOrder);
}
KDirSortFilterProxyModel::sort(static_cast<int>(m_sorting), m_sortOrder);
}
}
void DolphinSortFilterProxyModel::sort(int column, Qt::SortOrder sortOrder)
@ -92,46 +68,14 @@ void DolphinSortFilterProxyModel::sort(int column, Qt::SortOrder sortOrder)
m_sortOrder = sortOrder;
emit sortingRoleChanged();
KDirSortFilterProxyModel::sort((int) m_sorting, sortOrder);
KDirSortFilterProxyModel::sort(static_cast<int>(m_sorting), sortOrder);
}
DolphinView::Sorting DolphinSortFilterProxyModel::sortingForColumn(int column)
{
Q_ASSERT(column >= 0);
Q_ASSERT(column < static_cast<int>(sizeof(sortingTypeTable) / sizeof(DolphinView::Sorting)));
return sortingTypeTable[column];
}
bool DolphinSortFilterProxyModel::subSortLessThan(const QModelIndex& left,
const QModelIndex& right) const
{
// switch (left.column()) {
// case DolphinView::Revision:
// return left > right;
// ...
return KDirSortFilterProxyModel::subSortLessThan(left, right);
}
bool DolphinSortFilterProxyModel::isDirectoryOrHidden(const KFileItem& left,
const KFileItem& right,
bool& result) const
{
bool isDirectoryOrHidden = true;
const bool isLessThan = (sortOrder() == Qt::AscendingOrder);
if (left.isDir() && !right.isDir()) {
result = isLessThan;
} else if (!left.isDir() && right.isDir()) {
result = !isLessThan;
} else if (left.isHidden() && !right.isHidden()) {
result = isLessThan;
} else if (!left.isHidden() && right.isHidden()) {
result = !isLessThan;
} else {
isDirectoryOrHidden = false;
}
return isDirectoryOrHidden;
Q_ASSERT(column <= DolphinView::MaxSortingEnum);
return static_cast<DolphinView::Sorting>(column);
}
#include "dolphinsortfilterproxymodel.moc"

View file

@ -1,5 +1,5 @@
/***************************************************************************
* Copyright (C) 2006 by Peter Penz <peter.penz@gmx.at> *
* Copyright (C) 2006-2010 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 *
@ -28,7 +28,7 @@
* @brief Acts as proxy model for DolphinModel to sort and filter
* KFileItems.
*
* A natural sorting is done. This means that items like:
* Per default a natural sorting is done. This means that items like:
* - item_10.png
* - item_1.png
* - item_2.png
@ -36,11 +36,6 @@
* - item_1.png
* - item_2.png
* - item_10.png
*
* @note It is NOT assured that directories are always sorted before files.
* For example, on a Nepomuk based sorting, it is possible to have a file
* rated with 10 stars, and a directory rated with 5 stars. The file will
* be shown before the directory.
*/
class LIBDOLPHINPRIVATE_EXPORT DolphinSortFilterProxyModel : public KDirSortFilterProxyModel
{
@ -58,12 +53,7 @@ public:
void setSortFoldersFirst(bool foldersFirst);
/**
* @reimplemented, @internal
*
* If the view 'forces' sorting order to change we will
* notice now.
*/
/** @reimplemented */
virtual void sort(int column,
Qt::SortOrder order = Qt::AscendingOrder);
@ -77,21 +67,6 @@ public:
signals:
void sortingRoleChanged();
protected:
virtual bool subSortLessThan(const QModelIndex& left,
const QModelIndex& right) const;
private:
/**
* Returns true, if the left or right file item is a directory
* or a hidden file. In this case \a result provides the information
* whether \a left is less than \a right. If false is returned,
* the value of \a result is undefined.
*/
bool isDirectoryOrHidden(const KFileItem& left,
const KFileItem& right,
bool& result) const;
private:
DolphinView::Sorting m_sorting:16;
Qt::SortOrder m_sortOrder:16;