Skip to content
Permalink
Browse files

add supportedFormatExtensions() method to QgsRasterFileWriter

  • Loading branch information
alexbruy committed Dec 7, 2017
1 parent 52b5864 commit 48661addc6a972691ffc5a042049835ea5fac17e
@@ -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
@@ -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;
}
@@ -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".

0 comments on commit 48661ad

Please sign in to comment.
You can’t perform that action at this time.