mirror of
https://github.com/qgis/QGIS.git
synced 2025-02-27 00:33:48 -05:00
This reverts commits f8890d8f047cd2bb934eaad83e1057814927adb5, f085f5527658c0a81b9a065a6fcee4d654d16bb6 and 5844a0fc906c744327139e137642f0ec97ae240a
88 lines
3.8 KiB
Python
88 lines
3.8 KiB
Python
# -*- coding: utf-8 -*-
|
|
|
|
"""
|
|
***************************************************************************
|
|
ParameterGuiUtils.py
|
|
---------------------
|
|
Date : June 2017
|
|
Copyright : (C) 2017 by Nyall Dawson
|
|
Email : nyall dot dawson at gmail dot com
|
|
***************************************************************************
|
|
* *
|
|
* This program is free software; you can redistribute it and/or modify *
|
|
* it under the terms of the GNU General Public License as published by *
|
|
* the Free Software Foundation; either version 2 of the License, or *
|
|
* (at your option) any later version. *
|
|
* *
|
|
***************************************************************************
|
|
"""
|
|
|
|
|
|
__author__ = 'Nyall Dawson'
|
|
__date__ = 'June 2017'
|
|
__copyright__ = '(C) 2017, Nyall Dawson'
|
|
|
|
from qgis.core import (QgsProcessing,
|
|
QgsProviderRegistry,
|
|
QgsProcessingFeatureSourceDefinition,
|
|
QgsVectorFileWriter,
|
|
QgsRasterFileWriter)
|
|
from qgis.PyQt.QtCore import QCoreApplication
|
|
from processing.tools import dataobjects
|
|
|
|
|
|
def tr(string, context=''):
|
|
if context == '':
|
|
context = 'Processing'
|
|
return QCoreApplication.translate(context, string)
|
|
|
|
|
|
def getFileFilter(param):
|
|
"""
|
|
Returns a suitable file filter pattern for the specified parameter definition
|
|
:param param:
|
|
:return:
|
|
"""
|
|
if param.type() == 'layer':
|
|
vectors = QgsProviderRegistry.instance().fileVectorFilters().split(';;')
|
|
vectors.pop(0)
|
|
rasters = QgsProviderRegistry.instance().fileRasterFilters().split(';;')
|
|
rasters.pop(0)
|
|
filters = set(vectors + rasters)
|
|
filters = sorted(filters)
|
|
return tr('All files (*.*)') + ';;' + ";;".join(filters)
|
|
elif param.type() == 'multilayer':
|
|
if param.layerType() == QgsProcessing.TypeRaster:
|
|
exts = QgsRasterFileWriter.supportedFormatExtensions()
|
|
elif param.layerType() == QgsProcessing.TypeFile:
|
|
return tr('All files (*.*)', 'QgsProcessingParameterMultipleLayers')
|
|
else:
|
|
exts = QgsVectorFileWriter.supportedFormatExtensions()
|
|
for i in range(len(exts)):
|
|
exts[i] = tr('{0} files (*.{1})', 'QgsProcessingParameterMultipleLayers').format(exts[i].upper(), exts[i].lower())
|
|
return tr('All files (*.*)') + ';;' + ';;'.join(exts)
|
|
elif param.type() == 'raster':
|
|
return QgsProviderRegistry.instance().fileRasterFilters()
|
|
elif param.type() == 'rasterDestination':
|
|
exts = param.supportedOutputRasterLayerExtensions()
|
|
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'):
|
|
exts = param.supportedOutputVectorLayerExtensions()
|
|
for i in range(len(exts)):
|
|
exts[i] = tr('{0} files (*.{1})', 'ParameterVector').format(exts[i].upper(), exts[i].lower())
|
|
return ';;'.join(exts) + ';;' + tr('All files (*.*)')
|
|
elif param.type() == 'source':
|
|
return QgsProviderRegistry.instance().fileVectorFilters()
|
|
elif param.type() == 'vector':
|
|
return QgsProviderRegistry.instance().fileVectorFilters()
|
|
elif param.type() == 'fileDestination':
|
|
return param.fileFilter() + ';;' + tr('All files (*.*)')
|
|
elif param.type() == 'mesh':
|
|
return tr('All files (*.*)')
|
|
if param.defaultFileExtension():
|
|
return tr('Default extension') + ' (*.' + param.defaultFileExtension() + ')'
|
|
else:
|
|
return ''
|