From a55a69e6ac56dfb6851b5538e4252e9d8dab402b Mon Sep 17 00:00:00 2001 From: isanae <14251494+isanae@users.noreply.github.com> Date: Wed, 22 Jan 2020 03:58:22 -0500 Subject: file size column --- src/filetreemodel.cpp | 41 ++++++++++++++++++++++++++++++++--------- 1 file changed, 32 insertions(+), 9 deletions(-) (limited to 'src/filetreemodel.cpp') diff --git a/src/filetreemodel.cpp b/src/filetreemodel.cpp index 5b513ce2..351e0d2f 100644 --- a/src/filetreemodel.cpp +++ b/src/filetreemodel.cpp @@ -196,7 +196,7 @@ int FileTreeModel::rowCount(const QModelIndex& parent) const int FileTreeModel::columnCount(const QModelIndex&) const { - return 2; + return ColumnCount; } bool FileTreeModel::hasChildren(const QModelIndex& parent) const @@ -246,10 +246,31 @@ QVariant FileTreeModel::data(const QModelIndex& index, int role) const case Qt::DisplayRole: { if (auto* item=itemFromIndex(index)) { - if (index.column() == 0) { - return item->filename(); - } else if (index.column() == 1) { - return item->mod(); + switch (index.column()) + { + case Filename: + { + return item->filename(); + } + + case ModName: + { + return item->mod(); + } + + case FileSize: + { + if (item->isDirectory()) { + return {}; + } else { + return localizedByteSize(item->meta().size); + } + } + + default: + { + break; + } } } @@ -304,11 +325,13 @@ QVariant FileTreeModel::data(const QModelIndex& index, int role) const QVariant FileTreeModel::headerData(int i, Qt::Orientation ori, int role) const { + static const std::array names = { + tr("File"), tr("Mod"), tr("Size") + }; + if (role == Qt::DisplayRole) { - if (i == 0) { - return tr("File"); - } else if (i == 1) { - return tr("Mod"); + if (i > 0 && i < static_cast(names.size())) { + return names[static_cast(i)]; } } -- cgit v1.3.1