Skip to content

Commit

Permalink
[processing] use core methods for raster and vector extensions handling
Browse files Browse the repository at this point in the history
  • Loading branch information
alexbruy committed Dec 11, 2017
1 parent 48661ad commit 79d83f2
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 36 deletions.
5 changes: 3 additions & 2 deletions python/plugins/processing/core/ProcessingConfig.py
Expand Up @@ -31,7 +31,8 @@
from qgis.core import (NULL,
QgsApplication,
QgsSettings,
QgsVectorFileWriter)
QgsVectorFileWriter,
QgsRasterFileWriter)
from processing.tools.system import defaultOutputFolder
import processing.tools.dataobjects

Expand Down Expand Up @@ -170,7 +171,7 @@ def initialize():
valuetype=Setting.SELECTION,
options=extensions))

extensions = processing.tools.dataobjects.getSupportedOutputRasterLayerExtensions()
extensions = QgsRasterFileWriter.supportedFormatExtensions()
ProcessingConfig.addSetting(Setting(
ProcessingConfig.tr('General'),
ProcessingConfig.DEFAULT_OUTPUT_RASTER_LAYER_EXT,
Expand Down
12 changes: 9 additions & 3 deletions python/plugins/processing/gui/ParameterGuiUtils.py
Expand Up @@ -29,7 +29,8 @@
from qgis.core import (QgsProcessing,
QgsProviderRegistry,
QgsProcessingFeatureSourceDefinition,
QgsVectorFileWriter)
QgsVectorFileWriter,
QgsRasterFileWriter)
from qgis.PyQt.QtCore import QCoreApplication
from processing.tools import dataobjects

Expand All @@ -48,7 +49,7 @@ def getFileFilter(param):
"""
if param.type() == 'multilayer':
if param.layerType() == QgsProcessing.TypeRaster:
exts = dataobjects.getSupportedOutputRasterLayerExtensions()
exts = QgsRasterFileWriter.supportedFormatExtensions()
elif param.layerType() == QgsProcessing.TypeFile:
return tr('All files (*.*)', 'QgsProcessingParameterMultipleLayers')
else:
Expand All @@ -59,7 +60,12 @@ def getFileFilter(param):
elif param.type() == 'raster':
return QgsProviderRegistry.instance().fileRasterFilters()
elif param.type() == 'rasterDestination':
exts = dataobjects.getSupportedOutputRasterFilters()
if param.provider() is not None:
exts = param.provider().supportedOutputRasterLayerExtensions()
else:
exts = QgsRasterFileWriter.supportedFormatExtensions()
for i in range(len(exts)):
exts[i] = tr('{0} files (*.{1})', 'ParameterRaster').format(exts[i].upper(), exts[i].lower())
return ';;'.join(exts) + ';;' + tr('All files (*.*)')
elif param.type() in ('sink', 'vectorDestination'):
if param.provider() is not None:
Expand Down
29 changes: 0 additions & 29 deletions python/plugins/processing/tools/dataobjects.py
Expand Up @@ -105,35 +105,6 @@ def createExpressionContext():
return context


def getSupportedOutputRasterLayerExtensions():
allexts = []
for exts in list(GdalUtils.getSupportedRasters().values()):
for ext in exts:
if ext != 'tif' and ext not in allexts:
allexts.append(ext)
allexts.sort()
allexts.insert(0, 'tif') # tif is the default, should be the first
return allexts


def getSupportedOutputRasterFilters():
"""
Return a list of file filters for supported raster formats.
Supported formats come from Gdal.
:return: a list of strings for Qt file filters.
"""
allFilters = []
supported = GdalUtils.getSupportedOutputRasters()
formatList = sorted(supported.keys())
# Place GTiff as the first format
if 'GTiff' in formatList:
formatList.pop(formatList.index('GTiff'))
formatList.insert(0, 'GTiff')
for f in formatList:
allFilters.append('{0} files (*.{1})'.format(f, ' *.'.join(supported[f])))
return allFilters


def load(fileName, name=None, crs=None, style=None, isRaster=False):
"""Loads a layer/table into the current project, given its file.
"""
Expand Down
4 changes: 2 additions & 2 deletions src/core/processing/qgsprocessingprovider.cpp
Expand Up @@ -18,6 +18,7 @@
#include "qgsprocessingprovider.h"
#include "qgsapplication.h"
#include "qgsvectorfilewriter.h"
#include "qgsrasterfilewriter.h"
#include "qgssettings.h"

QgsProcessingProvider::QgsProcessingProvider( QObject *parent SIP_TRANSFERTHIS )
Expand Down Expand Up @@ -47,7 +48,7 @@ QString QgsProcessingProvider::longName() const

QStringList QgsProcessingProvider::supportedOutputRasterLayerExtensions() const
{
return QStringList() << QStringLiteral( "tif" );
return QgsRasterFileWriter::supportedFormatExtensions();
}

void QgsProcessingProvider::refreshAlgorithms()
Expand Down Expand Up @@ -136,4 +137,3 @@ QString QgsProcessingProvider::defaultRasterFileExtension() const
return defaultExtension;
}
}

0 comments on commit 79d83f2

Please sign in to comment.