add supportedFormatExtensions() method to QgsRasterFileWriter

This commit is contained in:
Alexander Bruy 2017-12-07 16:20:41 +02:00
parent 52b5864335
commit 48661addc6
3 changed files with 43 additions and 0 deletions

View File

@ -194,6 +194,18 @@ Filter string for file picker dialogs
:rtype: list of QgsRasterFileWriter.FilterFormatDetails
%End
static QStringList supportedFormatExtensions( RasterFormatOptions options = SortRecommended );
%Docstring
Returns a list of file extensions for supported formats.
The ``options`` argument can be used to control the sorting and filtering of
returned formats.
.. versionadded:: 3.0
.. seealso:: :py:func:`supportedFiltersAndFormats()`
:rtype: list of str
%End
static QString driverForExtension( const QString &extension );
%Docstring
Returns the GDAL driver name for a specified file ``extension``. E.g. the

View File

@ -1103,3 +1103,23 @@ QList< QgsRasterFileWriter::FilterFormatDetails > QgsRasterFileWriter::supported
return results;
}
QStringList QgsRasterFileWriter::supportedFormatExtensions( const RasterFormatOptions options )
{
const auto formats = supportedFiltersAndFormats( options );
QStringList extensions;
QRegularExpression rx( QStringLiteral( "\\*\\.([a-zA-Z0-9]*)" ) );
for ( const FilterFormatDetails &format : formats )
{
QString ext = format.filterString;
QRegularExpressionMatch match = rx.match( ext );
if ( !match.hasMatch() )
continue;
QString matched = match.captured( 1 );
extensions << matched;
}
return extensions;
}

View File

@ -171,6 +171,17 @@ class CORE_EXPORT QgsRasterFileWriter
*/
static QList< QgsRasterFileWriter::FilterFormatDetails > supportedFiltersAndFormats( RasterFormatOptions options = SortRecommended );
/**
* Returns a list of file extensions for supported formats.
*
* The \a options argument can be used to control the sorting and filtering of
* returned formats.
*
* \since QGIS 3.0
* \see supportedFiltersAndFormats()
*/
static QStringList supportedFormatExtensions( RasterFormatOptions options = SortRecommended );
/**
* Returns the GDAL driver name for a specified file \a extension. E.g. the
* driver name for the ".tif" extension is "GTiff".