Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- QVariant GameListModel::data(
- const QModelIndex& index, int role
- ) const
- {
- // might be cool in the future
- // but for now let's just focus
- // on display role
- if (role != Qt::DisplayRole)
- return QVariant();
- auto file = games.at(index.row());
- QFileInfo file_info(file);
- auto file_size = double(file_info.size());
- switch (index.column())
- {
- case COLUMN_NAME:
- return file_info.fileName();
- case COLUMN_SIZE:
- if (file_size >= 1024*1024*1024) {
- return QString().sprintf("%.1f GiB", file_size / 1024*1024*1024);
- } else if (file_size >= 1024*1024) {
- return QString().sprintf("%.1f MiB", file_size / 1024*1024);
- } else if (file_size >= 1024) {
- return QString().sprintf("%.1f KiB", file_size / 1024);
- }
- return QString().sprintf("%.0lf bytes", file_size);
- }
- return QVariant();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement