summaryrefslogtreecommitdiffstats
path: root/filesystemfileproxy.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'filesystemfileproxy.cpp')
-rw-r--r--filesystemfileproxy.cpp32
1 files changed, 32 insertions, 0 deletions
diff --git a/filesystemfileproxy.cpp b/filesystemfileproxy.cpp
index 22f8868..2379226 100644
--- a/filesystemfileproxy.cpp
+++ b/filesystemfileproxy.cpp
@@ -7,8 +7,40 @@
#include <QModelIndex>
#include <QVariant>
+#include <QDirModel>
+#include <QDebug>
+#include <QFileInfo>
#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")){
+ QDirModel *source = static_cast<QDirModel*>(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")){
+ QDirModel *source = static_cast<QDirModel*>(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);
+}
+