Qt: Improve size column display
Vicki Pfau vi@endrift.com
Fri, 27 Jan 2017 16:56:13 -0800
2 files changed,
18 insertions(+),
3 deletions(-)
M
src/platform/qt/LibraryModel.cpp
→
src/platform/qt/LibraryModel.cpp
@@ -40,16 +40,17 @@ tr("Size"),
[](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 @@ case Qt::SizeHintRole: {
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 @@ emit doneLoading();
} } +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)
M
src/platform/qt/LibraryModel.h
→
src/platform/qt/LibraryModel.h
@@ -58,8 +58,11 @@ void directoryLoaded(const QString& path);
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 {