summaryrefslogtreecommitdiff
path: root/src/filetreemodel.cpp
diff options
context:
space:
mode:
authorisanae <14251494+isanae@users.noreply.github.com>2020-01-22 03:58:22 -0500
committerisanae <14251494+isanae@users.noreply.github.com>2020-02-04 03:33:22 -0500
commita55a69e6ac56dfb6851b5538e4252e9d8dab402b (patch)
tree2c0a9556869d2f263641c4866741a2ee71c80ae2 /src/filetreemodel.cpp
parent412165fcfbbd27d679a7400ebdef75ff3a9d6aa7 (diff)
file size column
Diffstat (limited to 'src/filetreemodel.cpp')
-rw-r--r--src/filetreemodel.cpp41
1 files changed, 32 insertions, 9 deletions
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<QString, ColumnCount> 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<int>(names.size())) {
+ return names[static_cast<std::size_t>(i)];
}
}