Merge pull request #462 from Scrumplex/fix-world-size-sort

fix: use size in bytes to sort by world size
This commit is contained in:
Ezekiel Smith 2022-04-20 08:32:38 +10:00 committed by GitHub
commit 405c44c9e1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 14 additions and 1 deletions

View File

@ -17,6 +17,7 @@
#include "Application.h"
#include <FileSystem.h>
#include <Qt>
#include <QMimeData>
#include <QUrl>
#include <QUuid>
@ -190,6 +191,16 @@ QVariant WorldList::data(const QModelIndex &index, int role) const
return QVariant();
}
case Qt::UserRole:
switch (column)
{
case SizeColumn:
return qVariantFromValue<qlonglong>(world.bytes());
default:
return data(index, Qt::DisplayRole);
}
case Qt::ToolTipRole:
{
return world.folderName();
@ -216,7 +227,7 @@ QVariant WorldList::data(const QModelIndex &index, int role) const
}
case SizeRole:
{
return locale.formattedDataSize(world.bytes());
return qVariantFromValue<qlonglong>(world.bytes());
}
case IconFileRole:
{

View File

@ -45,6 +45,7 @@
#include <QTreeView>
#include <QInputDialog>
#include <QProcess>
#include <Qt>
#include "tools/MCEditTool.h"
#include "FileSystem.h"
@ -92,6 +93,7 @@ WorldListPage::WorldListPage(BaseInstance *inst, std::shared_ptr<WorldList> worl
WorldListProxyModel * proxy = new WorldListProxyModel(this);
proxy->setSortCaseSensitivity(Qt::CaseInsensitive);
proxy->setSourceModel(m_worlds.get());
proxy->setSortRole(Qt::UserRole);
ui->worldTreeView->setSortingEnabled(true);
ui->worldTreeView->setModel(proxy);
ui->worldTreeView->installEventFilter(this);