17 #include <QRegularExpression> 22 list << QObject::tr(
"KB" ) << QObject::tr(
"MB" ) << QObject::tr(
"GB" ) << QObject::tr(
"TB" );
24 QStringListIterator i( list );
25 QString unit = QObject::tr(
"bytes" );
27 while ( bytes >= 1024.0 && i.hasNext() )
32 return QString(
"%1 %2" ).arg( QString::number( bytes ), unit );
37 const QRegularExpression rx( QStringLiteral(
"\\*\\.([a-zA-Z0-9]+)" ) );
38 QStringList extensions;
39 QRegularExpressionMatchIterator matches = rx.globalMatch( filter );
41 while ( matches.hasNext() )
43 const QRegularExpressionMatch match = matches.next();
44 if ( match.hasMatch() )
46 QStringList newExtensions = match.capturedTexts();
47 newExtensions.pop_front();
48 extensions.append( newExtensions );
56 if ( extensions.empty() || f.isEmpty() )
61 for (
const QString &extension : qgis::as_const( extensions ) )
63 const QString extWithDot = extension.startsWith(
'.' ) ? extension :
'.' + extension;
64 if ( fileName.endsWith( extWithDot, Qt::CaseInsensitive ) )
73 const QString extension = extensions.at( 0 );
74 const QString extWithDot = extension.startsWith(
'.' ) ? extension :
'.' + extension;
75 fileName += extWithDot;
89 QRegularExpression rx(
"[/\\\\\\?%\\*\\:\\|\"<>]" );
91 s.replace( rx, QStringLiteral(
"_" ) );
static QString ensureFileNameHasExtension(const QString &fileName, const QStringList &extensions)
Ensures that a fileName ends with an extension from the provided list of extensions.
static QString representFileSize(qint64 bytes)
Return the human size from bytes.
static QString stringToSafeFilename(const QString &string)
Converts a string to a safe filename, replacing characters which are not safe for filenames with an '...
static QStringList extensionsFromFilter(const QString &filter)
Returns a list of the extensions contained within a file filter string.
static QString addExtensionFromFilter(const QString &fileName, const QString &filter)
Ensures that a fileName ends with an extension from the specified filter string.