Qt: Improve size column display

This commit is contained in:
Vicki Pfau 2017-01-27 16:56:13 -08:00
parent 46782f16a0
commit 849f80e7a1
2 changed files with 18 additions and 3 deletions

View File

@ -40,16 +40,17 @@ LibraryModel::LibraryModel(const QString& path, QObject* parent)
[](const mLibraryEntry& e) -> QString {
double size = e.filesize;
QString unit = "B";
if (size > 1024.0) {
if (size >= 1024.0) {
size /= 1024.0;
unit = "kiB";
}
if (size > 1024.0) {
if (size >= 1024.0) {
size /= 1024.0;
unit = "MiB";
}
return QString("%0 %1").arg(size, 0, 'f', 1).arg(unit);
}
},
Qt::AlignRight
};
s_columns["platform"] = {
tr("Platform"),
@ -174,6 +175,8 @@ QVariant LibraryModel::data(const QModelIndex& index, int role) const {
QFontMetrics fm((QFont()));
return fm.size(Qt::TextSingleLine, m_columns[index.column()].value(entry));
}
case Qt::TextAlignmentRole:
return m_columns[index.column()].alignment;
default:
return QVariant();
}
@ -250,6 +253,15 @@ void LibraryModel::directoryLoaded(const QString& path) {
}
}
LibraryModel::LibraryColumn::LibraryColumn() {
}
LibraryModel::LibraryColumn::LibraryColumn(const QString& name, std::function<QString(const mLibraryEntry&)> value, int alignment)
: name(name)
, value(value)
, alignment(alignment)
{
}
LibraryModel::LibraryHandle::LibraryHandle(mLibrary* lib, const QString& p)
: library(lib)

View File

@ -58,8 +58,11 @@ private slots:
private:
struct LibraryColumn {
LibraryColumn();
LibraryColumn(const QString&, std::function<QString(const mLibraryEntry&)>, int = Qt::AlignLeft);
QString name;
std::function<QString(const mLibraryEntry&)> value;
int alignment;
};
class LibraryHandle {