Skip to content
Permalink
Browse files
Improve QgsFileUtils' representFileSize by appending decimal values t…
…o MB and above file sizes
  • Loading branch information
nirvn committed Aug 23, 2021
1 parent 42da0d5 commit b171ba1c12ff847d564995b7ea0e0a2b62c5b293
Showing with 5 additions and 4 deletions.
  1. +5 −4 src/core/qgsfileutils.cpp
@@ -38,14 +38,15 @@ QString QgsFileUtils::representFileSize( qint64 bytes )
list << QObject::tr( "KB" ) << QObject::tr( "MB" ) << QObject::tr( "GB" ) << QObject::tr( "TB" );

QStringListIterator i( list );
QString unit = QObject::tr( "bytes" );
QString unit = QObject::tr( "B" );

while ( bytes >= 1024.0 && i.hasNext() )
double fileSize = bytes;
while ( fileSize >= 1024.0 && i.hasNext() )
{
fileSize /= 1024.0;
unit = i.next();
bytes /= 1024.0;
}
return QStringLiteral( "%1 %2" ).arg( QString::number( bytes ), unit );
return QStringLiteral( "%1 %2" ).arg( QString::number( fileSize, 'f', bytes >= 1048576 ? 2 : 0 ), unit );
}

QStringList QgsFileUtils::extensionsFromFilter( const QString &filter )

0 comments on commit b171ba1

Please sign in to comment.