From 7bda040f35c6be15dbf1ba007de28849a0803cae Mon Sep 17 00:00:00 2001 From: Arno Date: Sat, 16 Mar 2013 16:13:05 +0100 Subject: First shot at SmDirModel Gotta take a break here. Hopefully this will end up in a custom QFilesystemModel, but I'm hitting so many bugs on the way. Some things haven't worked for ages, I guess. Anyway, the watcher doesn't do anythying right now, still fixing bugs... --- filesystemfileproxy.cpp | 59 +++++++++++++++++++++++++------------------------ 1 file changed, 30 insertions(+), 29 deletions(-) (limited to 'filesystemfileproxy.cpp') diff --git a/filesystemfileproxy.cpp b/filesystemfileproxy.cpp index ddf5d86..b45b740 100644 --- a/filesystemfileproxy.cpp +++ b/filesystemfileproxy.cpp @@ -10,10 +10,12 @@ #include #include #include +#include #include #include "filesystemfileproxy.h" +#include "smdirmodel.h" #include "helper.h" FilesystemFileProxy::FilesystemFileProxy(QObject *parent) : QSortFilterProxyModel(parent) {} @@ -22,39 +24,38 @@ QVariant FilesystemFileProxy::data(const QModelIndex &index, int role) const{ if(!index.isValid()){ return QVariant(); } - + SmDirModel *source = qobject_cast(sourceModel()); 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"); + QModelIndex real = mapToSource(index); + QLocale l; + if(index.column() == SmDirModel::Created){ + return real.data().toDateTime().toString("MM-dd-yyyy hh:mm"); } + if(index.column() == SmDirModel::Size){ + if(source->isDir(real)){ + return QVariant(); + } + return l.toString(real.data().toLongLong()); + } + if(index.column() == SmDirModel::Type){ + if(source->isDir(real)){ + return QVariant(); + } + } } + if(role == Qt::TextAlignmentRole){ + if(index.column() == SmDirModel::Size || index.column() == SmDirModel::Duration || index.column() == SmDirModel::Bitrate){ + return Qt::AlignRight; + } + } + if(role == Qt::FontRole){ + if(index.column() == SmDirModel::Md5sum || index.column() == SmDirModel::Duration || index.column() == SmDirModel::Bitrate){ + return QFont("courier"); + } + } return QSortFilterProxyModel::data(index, role); } -bool FilesystemFileProxy::filterAcceptsRow(int sourcerow, const QModelIndex &sourceparent) const{ - QFileSystemModel *m = static_cast(sourceModel()); - QModelIndex idx = m->index(sourcerow, 0, sourceparent); - if(!idx.isValid()){ - return false; - } - QString fName = idx.data().toString(); - if(fName == "." ){ - return false; - } - return QSortFilterProxyModel::filterAcceptsRow(sourcerow, sourceparent); -} - bool FilesystemFileProxy::lessThan(const QModelIndex &left, const QModelIndex &right) const { if(left.model()->headerData(left.column(), Qt::Horizontal).toString() == tr("Name")){ if(left.data().toString() == ".."){ @@ -64,7 +65,7 @@ bool FilesystemFileProxy::lessThan(const QModelIndex &left, const QModelIndex &r return false; } } - QFileSystemModel *source = static_cast(sourceModel()); + SmDirModel *source = qobject_cast(sourceModel()); if(source->isDir(left) && source->isDir(right)){ return left.data().toString().toLower() < right.data().toString().toLower(); } @@ -77,7 +78,7 @@ bool FilesystemFileProxy::lessThan(const QModelIndex &left, const QModelIndex &r 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()); + SmDirModel *source = qobject_cast(sourceModel()); QFileInfo lInfo = source->fileInfo(left); QFileInfo rInfo = source->fileInfo(right); if(lInfo.isDir() && rInfo.isDir()){ -- cgit v1.2.3-70-g09d2