Skip to content

Commit

Permalink
add supportedFormatExtensions() method to QgsRasterFileWriter
Browse files Browse the repository at this point in the history
  • Loading branch information
alexbruy committed Dec 11, 2017
1 parent 52b5864 commit 48661ad
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 0 deletions.
12 changes: 12 additions & 0 deletions python/core/raster/qgsrasterfilewriter.sip
Expand Up @@ -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
Expand Down
20 changes: 20 additions & 0 deletions src/core/raster/qgsrasterfilewriter.cpp
Expand Up @@ -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;
}
11 changes: 11 additions & 0 deletions src/core/raster/qgsrasterfilewriter.h
Expand Up @@ -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".
Expand Down

0 comments on commit 48661ad

Please sign in to comment.