mirror of
https://github.com/rizinorg/cutter.git
synced 2024-12-18 19:06:10 +00:00
Add more human readable size
This commit is contained in:
parent
3712cf1529
commit
330e230572
@ -3,6 +3,7 @@
|
||||
#include "dialogs/NewFileDialog.h"
|
||||
#include "dialogs/AboutDialog.h"
|
||||
#include "ui_NewfileDialog.h"
|
||||
#include "utils/Helpers.h"
|
||||
|
||||
#include <QFileDialog>
|
||||
#include <QtGui>
|
||||
@ -49,18 +50,6 @@ static QIcon getIconFor(const QString& str, int pos)
|
||||
return QIcon(pixmap);
|
||||
}
|
||||
|
||||
static QString formatBytecount(const long bytecount)
|
||||
{
|
||||
const int exp = log(bytecount) / log(1000);
|
||||
constexpr char suffixes[] = {' ', 'k', 'M', 'G', 'T', 'P', 'E'};
|
||||
|
||||
QString str;
|
||||
QTextStream stream(&str);
|
||||
stream << qSetRealNumberPrecision(3) << bytecount / pow(1000, exp)
|
||||
<< ' ' << suffixes[exp] << 'B';
|
||||
return stream.readAll();
|
||||
}
|
||||
|
||||
NewFileDialog::NewFileDialog(QWidget *parent) :
|
||||
QDialog(parent),
|
||||
ui(new Ui::NewFileDialog)
|
||||
@ -264,7 +253,7 @@ bool NewFileDialog::fillRecentFilesList()
|
||||
{
|
||||
QListWidgetItem *item = new QListWidgetItem(
|
||||
getIconFor(name, i++),
|
||||
file + "\nCreated: " + info.created().toString() + "\nSize: " + formatBytecount(info.size())
|
||||
file + "\nCreated: " + info.created().toString() + "\nSize: " + qhelpers::formatBytecount(info.size())
|
||||
);
|
||||
//":/img/icons/target.svg"), name );
|
||||
item->setData(Qt::UserRole, file);
|
||||
|
@ -1,8 +1,10 @@
|
||||
#include "utils/Helpers.h"
|
||||
|
||||
#include <cmath>
|
||||
#include <QPlainTextEdit>
|
||||
#include <QTextEdit>
|
||||
#include <QFileInfo>
|
||||
#include <QtCore>
|
||||
#include <QCryptographicHash>
|
||||
#include <QTreeWidget>
|
||||
#include <QString>
|
||||
@ -11,6 +13,7 @@
|
||||
#include <QDockWidget>
|
||||
|
||||
|
||||
|
||||
static QAbstractItemView::ScrollMode scrollMode()
|
||||
{
|
||||
const bool use_scrollperpixel = true;
|
||||
@ -20,6 +23,18 @@ static QAbstractItemView::ScrollMode scrollMode()
|
||||
|
||||
namespace qhelpers
|
||||
{
|
||||
|
||||
QString formatBytecount(const long bytecount)
|
||||
{
|
||||
const int exp = log(bytecount) / log(1000);
|
||||
constexpr char suffixes[] = {' ', 'k', 'M', 'G', 'T', 'P', 'E'};
|
||||
|
||||
QString str;
|
||||
QTextStream stream(&str);
|
||||
stream << qSetRealNumberPrecision(3) << bytecount / pow(1000, exp)
|
||||
<< ' ' << suffixes[exp] << 'B';
|
||||
return stream.readAll();
|
||||
}
|
||||
void adjustColumns(QTreeView *tv, int columnCount, int padding)
|
||||
{
|
||||
for (int i = 0; i != columnCount; ++i)
|
||||
|
@ -17,6 +17,7 @@ class QTreeView;
|
||||
|
||||
namespace qhelpers
|
||||
{
|
||||
QString formatBytecount(const long bytecount);
|
||||
void adjustColumns(QTreeView *tv, int columnCount, int padding);
|
||||
void adjustColumns(QTreeWidget *tw, int padding);
|
||||
|
||||
|
@ -1,5 +1,6 @@
|
||||
#include "Dashboard.h"
|
||||
#include "ui_Dashboard.h"
|
||||
#include "utils/Helpers.h"
|
||||
|
||||
#include "MainWindow.h"
|
||||
|
||||
@ -44,7 +45,7 @@ void Dashboard::updateContents()
|
||||
this->ui->formatEdit->setText(item["format"].toString());
|
||||
this->ui->modeEdit->setText(item["mode"].toString());
|
||||
this->ui->typeEdit->setText(item["type"].toString());
|
||||
this->ui->sizeEdit->setText(QString::number(item["size"].toDouble()));
|
||||
this->ui->sizeEdit->setText(qhelpers::formatBytecount(item["size"].toDouble()));
|
||||
this->ui->fdEdit->setText(QString::number(item["fd"].toDouble()));
|
||||
|
||||
this->ui->archEdit->setText(item2["arch"].toString());
|
||||
|
@ -1,3 +1,4 @@
|
||||
#include "utils/Helpers.h"
|
||||
#include "ResourcesWidget.h"
|
||||
#include <QVBoxLayout>
|
||||
|
||||
@ -34,7 +35,7 @@ QVariant ResourcesModel::data(const QModelIndex &index, int role) const
|
||||
case TYPE:
|
||||
return res->type;
|
||||
case SIZE:
|
||||
return res->size;
|
||||
return qhelpers::formatBytecount(res->size);
|
||||
case LANG:
|
||||
return res->lang;
|
||||
default:
|
||||
|
Loading…
Reference in New Issue
Block a user