/* 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. */ #include #include #include #include #include "filesystemfileproxy.h" FilesystemFileProxy::FilesystemFileProxy(QObject *parent) : QSortFilterProxyModel(parent) {} bool FilesystemFileProxy::lessThan(const QModelIndex &left, const QModelIndex &right) const { if(left.model()->headerData(left.column(), Qt::Horizontal).toString() == tr("Name")){ QFileSystemModel *source = static_cast(sourceModel()); if(source->isDir(left) && source->isDir(right)){ return left.data().toString().toLower() < right.data().toString().toLower(); } if(source->isDir(left)){ return true; } if(source->isDir(right)){ return false; } return left.data().toString().toLower() < right.data().toString().toLower(); } if(left.model()->headerData(left.column(), Qt::Horizontal).toString() == tr("Size")){ QFileSystemModel *source = static_cast(sourceModel()); QFileInfo lInfo = source->fileInfo(left); QFileInfo rInfo = source->fileInfo(right); if(lInfo.isDir() && rInfo.isDir()){ return lInfo.fileName().toLower() < rInfo.fileName().toLower(); } if(lInfo.isDir() && !rInfo.isDir()){ return true; } return lInfo.size() < rInfo.size(); } return QSortFilterProxyModel::lessThan(left, right); }