diff options
author | Arno <am@disconnect.de> | 2010-10-03 14:26:00 +0200 |
---|---|---|
committer | Arno <am@disconnect.de> | 2010-10-03 14:26:00 +0200 |
commit | a30a4c02d1c8a9c8442010b6ae12a2477c936b92 (patch) | |
tree | 37ed67adedcfd72dde7b8f38d9a6a0af1b1de4dd | |
parent | 0861ec020923ff8a1549f6c4a3f5437ce62573b5 (diff) | |
download | SheMov-a30a4c02d1c8a9c8442010b6ae12a2477c936b92.tar.gz SheMov-a30a4c02d1c8a9c8442010b6ae12a2477c936b92.tar.bz2 SheMov-a30a4c02d1c8a9c8442010b6ae12a2477c936b92.zip |
Change display in FSWidget
Display "Date modified" field in FSWidget as dd-mm-yyyy. Also show mime-
I guess I should subclass QFileSystemModel instead of reimplementing
data() in the proxy, because sorting by mimetype doesn't work as
expected. Unfortunately the reason eludes me...
-rw-r--r-- | filesystemfileproxy.cpp | 28 | ||||
-rw-r--r-- | filesystemfileproxy.h | 5 |
2 files changed, 32 insertions, 1 deletions
diff --git a/filesystemfileproxy.cpp b/filesystemfileproxy.cpp index 31059ec..06ad939 100644 --- a/filesystemfileproxy.cpp +++ b/filesystemfileproxy.cpp @@ -9,11 +9,39 @@ #include <QVariant> #include <QFileSystemModel> #include <QFileInfo> +#include <QDateTime> + +#include <QDebug> #include "filesystemfileproxy.h" +#include "helper.h" FilesystemFileProxy::FilesystemFileProxy(QObject *parent) : QSortFilterProxyModel(parent) {} +QVariant FilesystemFileProxy::data(const QModelIndex &index, int role) const{ + if(!index.isValid()){ + return QVariant(); + } + + if(role == Qt::DisplayRole){ + if(index.column() == 2){ + QString filePath = index.data(QFileSystemModel::FilePathRole).toString(); + QString mimeType = Helper::mimeType(filePath); + if(mimeType.contains('/')){ + mimeType = mimeType.split('/').at(1); + mimeType = mimeType.remove(QRegExp("^x-")); + return mimeType; + } + } + if(index.column() == 3){ + QString filePath = index.data(QFileSystemModel::FilePathRole).toString(); + QFileInfo fi(filePath); + return fi.lastModified().toString("MM-dd-yyyy hh:mm"); + } + } + return QSortFilterProxyModel::data(index, role); +} + 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<QFileSystemModel*>(sourceModel()); diff --git a/filesystemfileproxy.h b/filesystemfileproxy.h index 9f9609b..a7b5e18 100644 --- a/filesystemfileproxy.h +++ b/filesystemfileproxy.h @@ -18,7 +18,10 @@ class FilesystemFileProxy : public QSortFilterProxyModel { public: FilesystemFileProxy(QObject *parent = 0); ~FilesystemFileProxy() {}; - bool lessThan(const QModelIndex &left, const QModelIndex &right) const; + virtual QVariant data(const QModelIndex &index, int role) const; + + protected: + virtual bool lessThan(const QModelIndex &left, const QModelIndex &right) const; }; #endif |