┌   ┐
54
└   ┘

summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/CMakeLists.txt1
-rw-r--r--src/dolphinsortfilterproxymodel.cpp158
-rw-r--r--src/dolphinsortfilterproxymodel.h56
-rw-r--r--src/kcategorizedview.cpp8
-rw-r--r--src/kcategorizedview_p.h4
-rw-r--r--src/ksortfilterproxymodel.cpp52
-rw-r--r--src/ksortfilterproxymodel.h61
7 files changed, 53 insertions, 287 deletions
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index ce741d232..4e27c95cb 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -16,7 +16,6 @@ set(dolphinprivate_LIB_SRCS
dolphincolumnview.cpp
dolphinitemcategorizer.cpp
kcategorizedview.cpp
- ksortfilterproxymodel.cpp
kitemcategorizer.cpp
dolphinsettings.cpp
viewproperties.cpp
diff --git a/src/dolphinsortfilterproxymodel.cpp b/src/dolphinsortfilterproxymodel.cpp
index 255ce982e..b426f0828 100644
--- a/src/dolphinsortfilterproxymodel.cpp
+++ b/src/dolphinsortfilterproxymodel.cpp
@@ -50,16 +50,10 @@ static DolphinView::Sorting sortingTypeTable[] =
};
DolphinSortFilterProxyModel::DolphinSortFilterProxyModel(QObject* parent) :
- KSortFilterProxyModel(parent),
+ KDirSortFilterProxyModel(parent),
m_sorting(DolphinView::SortByName),
m_sortOrder(Qt::AscendingOrder)
{
- setDynamicSortFilter(true);
-
- // sort by the user visible string for now
- setSortRole(DolphinView::SortByName);
- setSortCaseSensitivity(Qt::CaseInsensitive);
- sort(KDirModel::Name, Qt::AscendingOrder);
}
DolphinSortFilterProxyModel::~DolphinSortFilterProxyModel()
@@ -83,19 +77,8 @@ void DolphinSortFilterProxyModel::sort(int column, Qt::SortOrder sortOrder)
m_sorting = sortingForColumn(column);
m_sortOrder = sortOrder;
setSortRole(m_sorting);
- KSortFilterProxyModel::sort(column, sortOrder);
-}
-
-bool DolphinSortFilterProxyModel::hasChildren(const QModelIndex& parent) const
-{
- const QModelIndex sourceParent = mapToSource(parent);
- return sourceModel()->hasChildren(sourceParent);
-}
-
-bool DolphinSortFilterProxyModel::canFetchMore(const QModelIndex& parent) const
-{
- const QModelIndex sourceParent = mapToSource(parent);
- return sourceModel()->canFetchMore(sourceParent);
+ emit sortingRoleChanged();
+ KDirSortFilterProxyModel::sort(column, sortOrder);
}
DolphinView::Sorting DolphinSortFilterProxyModel::sortingForColumn(int column)
@@ -113,6 +96,7 @@ bool DolphinSortFilterProxyModel::lessThanGeneralPurpose(const QModelIndex &left
const KFileItem* leftFileItem = dirModel->itemForIndex(left);
const KFileItem* rightFileItem = dirModel->itemForIndex(right);
+ //FIXME left.column() should be used instead!
switch (sortRole()) {
case DolphinView::SortByName: {
QString leftFileName(leftFileItem->name());
@@ -196,33 +180,12 @@ bool DolphinSortFilterProxyModel::lessThanGeneralPurpose(const QModelIndex &left
bool DolphinSortFilterProxyModel::lessThan(const QModelIndex& left,
const QModelIndex& right) const
{
- // TODO: There is some code duplication of this method inside
- // kdelibs/kfile/kdirsortfilterproxymodel.cpp. Possible solution:
- // - get rid of KSortFilterProxyModel and derive from KDirSortFilterProxyModel
- // - adapt DolphinSortFilterProxyModel::lessThan() to use
- // KSortFilterProxyModel::lessThan() if possible
-
+#ifdef HAVE_NEPOMUK
KDirModel* dirModel = static_cast<KDirModel*>(sourceModel());
const KFileItem* leftFileItem = dirModel->itemForIndex(left);
const KFileItem* rightFileItem = dirModel->itemForIndex(right);
- // If we are sorting by rating, folders and files are citizens of the same
- // class. Same if we are sorting by tags.
-#ifdef HAVE_NEPOMUK
- if ((sortRole() != DolphinView::SortByRating) &&
- (sortRole() != DolphinView::SortByTags))
- {
-#endif
- // On our priority, folders go above regular files.
- if (leftFileItem->isDir() && !rightFileItem->isDir()) {
- return true;
- } else if (!leftFileItem->isDir() && rightFileItem->isDir()) {
- return false;
- }
-#ifdef HAVE_NEPOMUK
- }
-#endif
// Hidden elements go before visible ones, if they both are
// folders or files.
@@ -232,110 +195,8 @@ bool DolphinSortFilterProxyModel::lessThan(const QModelIndex& left,
return false;
}
+ //FIXME left.column() should be used instead!
switch (sortRole()) {
- case DolphinView::SortByName: {
- // So we are in the same priority, what counts now is their names.
- const QVariant leftData = dirModel->data(left, KDirModel::Name);
- const QVariant rightData = dirModel->data(right, KDirModel::Name);
- const QString leftValueString(leftData.toString());
- const QString rightValueString(rightData.toString());
-
- return sortCaseSensitivity() ?
- (naturalCompare(leftValueString, rightValueString) < 0) :
- (naturalCompare(leftValueString.toLower(), rightValueString.toLower()) < 0);
- }
-
- case DolphinView::SortBySize: {
- // If we have two folders, what we have to measure is the number of
- // items that contains each other
- if (leftFileItem->isDir() && rightFileItem->isDir()) {
- QVariant leftValue = dirModel->data(left, KDirModel::ChildCountRole);
- int leftCount = leftValue.type() == QVariant::Int ? leftValue.toInt() : KDirModel::ChildCountUnknown;
-
- QVariant rightValue = dirModel->data(right, KDirModel::ChildCountRole);
- int rightCount = rightValue.type() == QVariant::Int ? rightValue.toInt() : KDirModel::ChildCountUnknown;
-
- // In the case they two have the same child items, we sort them by
- // their names. So we have always everything ordered. We also check
- // if we are taking in count their cases.
- if (leftCount == rightCount) {
- return sortCaseSensitivity() ? (naturalCompare(leftFileItem->name(), rightFileItem->name()) < 0) :
- (naturalCompare(leftFileItem->name().toLower(), rightFileItem->name().toLower()) < 0);
- }
-
- // If they had different number of items, we sort them depending
- // on how many items had each other.
- return leftCount < rightCount;
- }
-
- // If what we are measuring is two files and they have the same size,
- // sort them by their file names.
- if (leftFileItem->size() == rightFileItem->size()) {
- return sortCaseSensitivity() ? (naturalCompare(leftFileItem->name(), rightFileItem->name()) < 0) :
- (naturalCompare(leftFileItem->name().toLower(), rightFileItem->name().toLower()) < 0);
- }
-
- // If their sizes are different, sort them by their sizes, as expected.
- return leftFileItem->size() < rightFileItem->size();
- }
-
- case DolphinView::SortByDate: {
- KDateTime leftTime, rightTime;
- leftTime.setTime_t(leftFileItem->time(KFileItem::ModificationTime));
- rightTime.setTime_t(rightFileItem->time(KFileItem::ModificationTime));
-
- if (leftTime == rightTime) {
- return sortCaseSensitivity() ?
- (naturalCompare(leftFileItem->name(), rightFileItem->name()) < 0) :
- (naturalCompare(leftFileItem->name().toLower(), rightFileItem->name().toLower()) < 0);
- }
-
- return leftTime > rightTime;
- }
-
- case DolphinView::SortByPermissions: {
- if (leftFileItem->permissionsString() == rightFileItem->permissionsString()) {
- return sortCaseSensitivity() ?
- (naturalCompare(leftFileItem->name(), rightFileItem->name()) < 0) :
- (naturalCompare(leftFileItem->name().toLower(), rightFileItem->name().toLower()) < 0);
- }
-
- return naturalCompare(leftFileItem->permissionsString(),
- rightFileItem->permissionsString()) < 0;
- }
-
- case DolphinView::SortByOwner: {
- if (leftFileItem->user() == rightFileItem->user()) {
- return sortCaseSensitivity() ?
- (naturalCompare(leftFileItem->name(), rightFileItem->name()) < 0) :
- (naturalCompare(leftFileItem->name().toLower(), rightFileItem->name().toLower()) < 0);
- }
-
- return naturalCompare(leftFileItem->user(), rightFileItem->user()) < 0;
- }
-
- case DolphinView::SortByGroup: {
- if (leftFileItem->group() == rightFileItem->group()) {
- return sortCaseSensitivity() ? (naturalCompare(leftFileItem->name(), rightFileItem->name()) < 0) :
- (naturalCompare(leftFileItem->name().toLower(), rightFileItem->name().toLower()) < 0);
- }
-
- return naturalCompare(leftFileItem->group(),
- rightFileItem->group()) < 0;
- }
-
- case DolphinView::SortByType: {
- if (leftFileItem->mimetype() == rightFileItem->mimetype()) {
- return sortCaseSensitivity() ?
- (naturalCompare(leftFileItem->name(), rightFileItem->name()) < 0) :
- (naturalCompare(leftFileItem->name().toLower(), rightFileItem->name().toLower()) < 0);
- }
-
- return naturalCompare(leftFileItem->mimeComment(),
- rightFileItem->mimeComment()) < 0;
- }
-
-#ifdef HAVE_NEPOMUK
case DolphinView::SortByRating: {
const quint32 leftRating = ratingForIndex(left);
const quint32 rightRating = ratingForIndex(right);
@@ -385,12 +246,10 @@ bool DolphinSortFilterProxyModel::lessThan(const QModelIndex& left,
return naturalCompare(leftTags, rightTags) < 0;
}
-#endif
}
+#endif
- // We have set a SortRole and trust the ProxyModel to do
- // the right thing for now.
- return QSortFilterProxyModel::lessThan(left, right);
+ return KDirSortFilterProxyModel::lessThan(left, right);
}
quint32 DolphinSortFilterProxyModel::ratingForIndex(const QModelIndex& index)
@@ -439,6 +298,7 @@ QString DolphinSortFilterProxyModel::tagsForIndex(const QModelIndex& index)
return tagsString;
#else
+ Q_UNUSED(index);
return QString();
#endif
}
diff --git a/src/dolphinsortfilterproxymodel.h b/src/dolphinsortfilterproxymodel.h
index 537c6aa1c..146232494 100644
--- a/src/dolphinsortfilterproxymodel.h
+++ b/src/dolphinsortfilterproxymodel.h
@@ -22,7 +22,6 @@
#include <dolphinview.h>
#include <kdirsortfilterproxymodel.h>
-#include <ksortfilterproxymodel.h>
#include <libdolphin_export.h>
/**
@@ -40,7 +39,7 @@
*
* It is assured that directories are always sorted before files.
*/
-class LIBDOLPHINPRIVATE_EXPORT DolphinSortFilterProxyModel : public KSortFilterProxyModel
+class LIBDOLPHINPRIVATE_EXPORT DolphinSortFilterProxyModel : public KDirSortFilterProxyModel
{
Q_OBJECT
@@ -63,12 +62,6 @@ public:
virtual void sort(int column,
Qt::SortOrder order = Qt::AscendingOrder);
- /** Reimplemented from QAbstractItemModel. Returns true for directories. */
- virtual bool hasChildren(const QModelIndex& parent = QModelIndex()) const;
-
- /** Reimplemented from QAbstractItemModel. Returns true for empty directories. */
- virtual bool canFetchMore(const QModelIndex& parent) const;
-
/**
* Helper method to get the DolphinView::Sorting type for a given
* column \a column. If the column is smaller 0 or greater than the
@@ -76,17 +69,47 @@ public:
*/
static DolphinView::Sorting sortingForColumn(int column);
- /** @see KSortFilterProxyModel::lessThanGeneralPurpose() */
+ /**
+ * This method is essential on the categorized view.
+ * It will does a "basic" sorting, just for finding out categories,
+ * and their order. Then over those elements DISORDERED on categories,
+ * the lessThan method will be applied for each category.
+ *
+ * The easy explanation is that not always folders go first. That will depend.
+ * Imagine we sort by Rating. Categories will be created by 10 stars,
+ * 9 stars, 8 stars... but a category with only a file with rating 10
+ * will go before a category with a folder with rating 8.
+ * That's the main reason, and that's lessThanGeneralPurpose() method.
+ * That will go category by category creating sets of elements...
+ */
virtual bool lessThanGeneralPurpose(const QModelIndex &left,
const QModelIndex &right) const;
+ /**
+ * Then for each set of elements lessThanCategoryPurpose() will be applied,
+ * because for each category we wan't first folders and bla bla bla...
+ * That's the main reason of that method existence.
+ *
+ * For that reason, is not that clear that we want ALWAYS folders first.
+ * On each category, yes, that's true. But that's not true always,
+ * as I have pointed out on the example before.
+ */
+ bool lessThanCategoryPurpose(const QModelIndex &left,
+ const QModelIndex &right) const
+ {
+ //when we sort inside 1 category its the usual lessThan()
+ //from KDirSortFilterProxyModel(+nepomuk)
+ return lessThan(left,right);
+ }
+
+signals:
+ void sortingRoleChanged();
+
protected:
virtual bool lessThan(const QModelIndex& left,
const QModelIndex& right) const;
private:
- inline int naturalCompare(const QString& a, const QString& b) const;
-
/**
* Returns the rating for the item with the index \a index. 0 is
* returned if no item could be found.
@@ -100,25 +123,22 @@ private:
static QString tagsForIndex(const QModelIndex& index);
private:
- DolphinView::Sorting m_sorting;
- Qt::SortOrder m_sortOrder;
+ DolphinView::Sorting m_sorting:16;
+ Qt::SortOrder m_sortOrder:16;
friend class DolphinItemCategorizer;
};
+inline
DolphinView::Sorting DolphinSortFilterProxyModel::sorting() const
{
return m_sorting;
}
+inline
Qt::SortOrder DolphinSortFilterProxyModel::sortOrder() const
{
return m_sortOrder;
}
-int DolphinSortFilterProxyModel::naturalCompare(const QString& a, const QString& b) const
-{
- return KDirSortFilterProxyModel::naturalCompare(a, b);
-}
-
#endif
diff --git a/src/kcategorizedview.cpp b/src/kcategorizedview.cpp
index 39d047724..e178760ee 100644
--- a/src/kcategorizedview.cpp
+++ b/src/kcategorizedview.cpp
@@ -33,7 +33,7 @@
#include <kstyle.h>
#include "kitemcategorizer.h"
-#include "ksortfilterproxymodel.h"
+#include "dolphinsortfilterproxymodel.h"
class LessThan
{
@@ -44,7 +44,7 @@ public:
CategoryPurpose
};
- inline LessThan(const KSortFilterProxyModel *proxyModel,
+ inline LessThan(const DolphinSortFilterProxyModel *proxyModel,
Purpose purpose)
: proxyModel(proxyModel)
, purpose(purpose)
@@ -67,7 +67,7 @@ public:
}
private:
- const KSortFilterProxyModel *proxyModel;
+ const DolphinSortFilterProxyModel *proxyModel;
const Purpose purpose;
};
@@ -485,7 +485,7 @@ void KCategorizedView::setModel(QAbstractItemModel *model)
QListView::setModel(model);
- d->proxyModel = dynamic_cast<KSortFilterProxyModel*>(model);
+ d->proxyModel = dynamic_cast<DolphinSortFilterProxyModel*>(model);
if (d->proxyModel)
{
diff --git a/src/kcategorizedview_p.h b/src/kcategorizedview_p.h
index 1a8a7f376..690db5ba9 100644
--- a/src/kcategorizedview_p.h
+++ b/src/kcategorizedview_p.h
@@ -21,7 +21,7 @@
#ifndef KCATEGORIZEDVIEW_P_H
#define KCATEGORIZEDVIEW_P_H
-class KSortFilterProxyModel;
+class DolphinSortFilterProxyModel;
/**
* @internal
@@ -152,7 +152,7 @@ public:
QRect lastSelectionRect;
// Attributes for speed reasons
- KSortFilterProxyModel *proxyModel;
+ DolphinSortFilterProxyModel *proxyModel;
QModelIndexList sourceModelIndexList; // in source model
};
diff --git a/src/ksortfilterproxymodel.cpp b/src/ksortfilterproxymodel.cpp
deleted file mode 100644
index 9b08c420f..000000000
--- a/src/ksortfilterproxymodel.cpp
+++ /dev/null
@@ -1,52 +0,0 @@
-/**
- * This file is part of the KDE project
- * Copyright (C) 2007 Rafael Fernández López <[email protected]>
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Library General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * This library 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
- * Library General Public License for more details.
- *
- * You should have received a copy of the GNU Library General Public License
- * along with this library; see the file COPYING.LIB. If not, write to
- * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
- * Boston, MA 02110-1301, USA.
- */
-
-#include "ksortfilterproxymodel.h"
-
-KSortFilterProxyModel::KSortFilterProxyModel(QObject *parent)
- : QSortFilterProxyModel(parent)
-{
-}
-
-KSortFilterProxyModel::~KSortFilterProxyModel()
-{
-}
-
-void KSortFilterProxyModel::sort(int column, Qt::SortOrder order)
-{
- QSortFilterProxyModel::sort(column, order);
-
- m_sortOrder = order;
-
- emit sortingRoleChanged();
-}
-
-Qt::SortOrder KSortFilterProxyModel::sortOrder() const
-{
- return m_sortOrder;
-}
-
-bool KSortFilterProxyModel::lessThanCategoryPurpose(const QModelIndex &left,
- const QModelIndex &right) const
-{
- return lessThan(left, right);
-}
-
-#include "ksortfilterproxymodel.moc"
diff --git a/src/ksortfilterproxymodel.h b/src/ksortfilterproxymodel.h
deleted file mode 100644
index 1c653f67c..000000000
--- a/src/ksortfilterproxymodel.h
+++ /dev/null
@@ -1,61 +0,0 @@
-/**
- * This file is part of the KDE project
- * Copyright (C) 2007 Rafael Fernández López <[email protected]>
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Library General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * This library 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
- * Library General Public License for more details.
- *
- * You should have received a copy of the GNU Library General Public License
- * along with this library; see the file COPYING.LIB. If not, write to
- * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
- * Boston, MA 02110-1301, USA.
- */
-
-#ifndef KSORTFILTERPROXYMODEL_H
-#define KSORTFILTERPROXYMODEL_H
-
-#include <QtGui/QSortFilterProxyModel>
-
-#include <libdolphin_export.h>
-
-/**
- * @internal
- *
- * This class is meant to be used with KListView class
- *
- * @see KListView
- */
-class LIBDOLPHINPRIVATE_EXPORT KSortFilterProxyModel
- : public QSortFilterProxyModel
-{
- Q_OBJECT
-
-public:
- KSortFilterProxyModel(QObject *parent = 0);
- ~KSortFilterProxyModel();
-
- virtual void sort(int column, Qt::SortOrder order = Qt::AscendingOrder);
-
- Qt::SortOrder sortOrder() const;
-
- virtual bool lessThanGeneralPurpose(const QModelIndex &left,
- const QModelIndex &right) const = 0;
-
- virtual bool lessThanCategoryPurpose(const QModelIndex &left,
- const QModelIndex &right) const;
-
-Q_SIGNALS:
- void sortingRoleChanged();
-
-private:
- Qt::SortOrder m_sortOrder;
-};
-
-#endif // KSORTFILTERPROXYMODEL_H