File indexing completed on 2022-09-27 16:31:48

0001 /*
0002     SPDX-FileCopyrightText: 2009 Dario Andres Rodriguez <andresbajotierra@gmail.com>
0003 
0004     SPDX-License-Identifier: GPL-2.0-or-later
0005 */
0006 
0007 #include "kdfsortproxymodel.h"
0008 
0009 #include "kdfwidget.h"
0010 
0011 bool KDFSortFilterProxyModel::lessThan(const QModelIndex &left, const QModelIndex &right) const
0012 {
0013 
0014     //Properly sort the file sizes using the numeric size instead of the string
0015     // representation (10Mb < 9Gb)
0016     if( left.column() == KDFWidget::SizeCol || left.column() == KDFWidget::FreeCol )
0017     {
0018         qulonglong leftData = sourceModel()->data( left, Qt::UserRole ).toULongLong();
0019         qulonglong rightData = sourceModel()->data( right, Qt::UserRole ).toULongLong();
0020 
0021         return leftData < rightData;
0022     }
0023     // Full percent can be -1 (non mounted disks)
0024     else if ( left.column() == KDFWidget::FullCol || left.column() == KDFWidget::UsageBarCol )
0025     {
0026         int leftData = sourceModel()->data( left, Qt::UserRole ).toInt();
0027         int rightData = sourceModel()->data( right, Qt::UserRole ).toInt();
0028 
0029         return leftData < rightData;
0030 
0031     }
0032     // Default sorting rules for string values
0033     else
0034     {
0035         return QSortFilterProxyModel::lessThan( left, right );
0036     }
0037 
0038 }