]> cloud.milkyroute.net Git - dolphin.git/commitdiff
Only group the directories before items if the KDirModel::Name column is sorted....
authorPeter Penz <peter.penz19@gmail.com>
Mon, 5 Feb 2007 23:17:15 +0000 (23:17 +0000)
committerPeter Penz <peter.penz19@gmail.com>
Mon, 5 Feb 2007 23:17:15 +0000 (23:17 +0000)
svn path=/trunk/playground/utils/dolphin/; revision=630674

src/dolphinsortfilterproxymodel.cpp
src/dolphinsortfilterproxymodel.h

index 783a0af42646e6db4d038641a4eec854a04649dc..20b8bf164fcef443497241886a010c92324fadc8 100644 (file)
@@ -39,7 +39,10 @@ static DolphinView::Sorting dirModelColumnToDolphinView[] = {
 
 
 DolphinSortFilterProxyModel::DolphinSortFilterProxyModel(QObject* parent) :
-    QSortFilterProxyModel(parent)
+    QSortFilterProxyModel(parent),
+    m_sortColumn(0),
+    m_sorting(DolphinView::SortByName),
+    m_sortOrder(Qt::Ascending)
 {
     setDynamicSortFilter(true);
 
@@ -70,11 +73,12 @@ void DolphinSortFilterProxyModel::setSortOrder(Qt::SortOrder sortOrder)
 
 void DolphinSortFilterProxyModel::sort(int column, Qt::SortOrder sortOrder)
 {
+    m_sortColumn = column;
     m_sortOrder = sortOrder;
     m_sorting = (column >= 0) && (column <= dolphinMapSize) ?
                 dirModelColumnToDolphinView[column]  :
                 DolphinView::SortByName;
-    QSortFilterProxyModel::sort(column,sortOrder);
+    QSortFilterProxyModel::sort(column, sortOrder);
 }
 
 bool DolphinSortFilterProxyModel::lessThan(const QModelIndex& left,
@@ -86,21 +90,23 @@ bool DolphinSortFilterProxyModel::lessThan(const QModelIndex& left,
     QVariant rightData = dirModel->data(right, sortRole());
 
     if ((leftData.type() == QVariant::String) && (rightData.type() == QVariant::String)) {
-        const QString leftStr  = leftData.toString();
-        const QString rightStr = rightData.toString();
-
-        const bool leftIsDir  = dirModel->itemForIndex(left)->isDir();
-        const bool rightIsDir = dirModel->itemForIndex(right)->isDir();
-
         // assure that directories are always sorted before files
-        if (leftIsDir && !rightIsDir) {
-            return true;
-        }
+        // if the sorting is done by the 'Name' column
+        if (m_sortColumn == KDirModel::Name) {
+            const bool leftIsDir  = dirModel->itemForIndex(left)->isDir();
+            const bool rightIsDir = dirModel->itemForIndex(right)->isDir();
+            if (leftIsDir && !rightIsDir) {
+                return true;
+            }
 
-        if (!leftIsDir && rightIsDir) {
-            return false;
+            if (!leftIsDir && rightIsDir) {
+                return false;
+            }
         }
 
+        const QString leftStr  = leftData.toString();
+        const QString rightStr = rightData.toString();
+
         return sortCaseSensitivity() ? (naturalCompare(leftStr, rightStr) < 0) :
                                        (naturalCompare(leftStr.toLower(), rightStr.toLower()) < 0);
     }
index c8de791c6adbb61c1b97982979472db38d128d06..d73f4579bba7cb622ed9af1bfc22d44b62479e4e 100644 (file)
@@ -69,6 +69,7 @@ private:
     static int naturalCompare(const QString& a, const QString& b);
 
 private:
+    int m_sortColumn;
     DolphinView::Sorting m_sorting;
     Qt::SortOrder m_sortOrder;
 };