Skip to content

Commit 48661ad

Browse files
committed
add supportedFormatExtensions() method to QgsRasterFileWriter
1 parent 52b5864 commit 48661ad

File tree

3 files changed

+43
-0
lines changed

3 files changed

+43
-0
lines changed

python/core/raster/qgsrasterfilewriter.sip

+12
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,18 @@ Filter string for file picker dialogs
194194
:rtype: list of QgsRasterFileWriter.FilterFormatDetails
195195
%End
196196

197+
static QStringList supportedFormatExtensions( RasterFormatOptions options = SortRecommended );
198+
%Docstring
199+
Returns a list of file extensions for supported formats.
200+
201+
The ``options`` argument can be used to control the sorting and filtering of
202+
returned formats.
203+
204+
.. versionadded:: 3.0
205+
.. seealso:: :py:func:`supportedFiltersAndFormats()`
206+
:rtype: list of str
207+
%End
208+
197209
static QString driverForExtension( const QString &extension );
198210
%Docstring
199211
Returns the GDAL driver name for a specified file ``extension``. E.g. the

src/core/raster/qgsrasterfilewriter.cpp

+20
Original file line numberDiff line numberDiff line change
@@ -1103,3 +1103,23 @@ QList< QgsRasterFileWriter::FilterFormatDetails > QgsRasterFileWriter::supported
11031103

11041104
return results;
11051105
}
1106+
1107+
QStringList QgsRasterFileWriter::supportedFormatExtensions( const RasterFormatOptions options )
1108+
{
1109+
const auto formats = supportedFiltersAndFormats( options );
1110+
QStringList extensions;
1111+
1112+
QRegularExpression rx( QStringLiteral( "\\*\\.([a-zA-Z0-9]*)" ) );
1113+
1114+
for ( const FilterFormatDetails &format : formats )
1115+
{
1116+
QString ext = format.filterString;
1117+
QRegularExpressionMatch match = rx.match( ext );
1118+
if ( !match.hasMatch() )
1119+
continue;
1120+
1121+
QString matched = match.captured( 1 );
1122+
extensions << matched;
1123+
}
1124+
return extensions;
1125+
}

src/core/raster/qgsrasterfilewriter.h

+11
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,17 @@ class CORE_EXPORT QgsRasterFileWriter
171171
*/
172172
static QList< QgsRasterFileWriter::FilterFormatDetails > supportedFiltersAndFormats( RasterFormatOptions options = SortRecommended );
173173

174+
/**
175+
* Returns a list of file extensions for supported formats.
176+
*
177+
* The \a options argument can be used to control the sorting and filtering of
178+
* returned formats.
179+
*
180+
* \since QGIS 3.0
181+
* \see supportedFiltersAndFormats()
182+
*/
183+
static QStringList supportedFormatExtensions( RasterFormatOptions options = SortRecommended );
184+
174185
/**
175186
* Returns the GDAL driver name for a specified file \a extension. E.g. the
176187
* driver name for the ".tif" extension is "GTiff".

0 commit comments

Comments
 (0)