mirror of
https://github.com/qgis/QGIS.git
synced 2025-10-06 00:07:29 -04:00
[processing] Move responsiblity for creation of file filter strings from python to c++
This commit is contained in:
parent
51f40f7180
commit
edd0635fe3
@ -1629,7 +1629,7 @@ Creates a new parameter using the definition from a script code.
|
||||
|
||||
};
|
||||
|
||||
class QgsProcessingParameterMultipleLayers : QgsProcessingParameterDefinition
|
||||
class QgsProcessingParameterMultipleLayers : QgsProcessingParameterDefinition, QgsFileFilterGenerator
|
||||
{
|
||||
%Docstring
|
||||
A parameter for processing algorithms which accepts multiple map layers.
|
||||
@ -1664,6 +1664,8 @@ Returns the type name for the parameter class.
|
||||
|
||||
virtual QString asPythonString( QgsProcessing::PythonOutputType outputType = QgsProcessing::PythonQgsProcessingAlgorithmSubclass ) const;
|
||||
|
||||
virtual QString createFileFilter() const;
|
||||
|
||||
|
||||
QgsProcessing::SourceType layerType() const;
|
||||
%Docstring
|
||||
@ -2011,7 +2013,7 @@ Creates a new parameter using the definition from a script code.
|
||||
|
||||
};
|
||||
|
||||
class QgsProcessingParameterRasterLayer : QgsProcessingParameterDefinition
|
||||
class QgsProcessingParameterRasterLayer : QgsProcessingParameterDefinition, QgsFileFilterGenerator
|
||||
{
|
||||
%Docstring
|
||||
A raster layer parameter for processing algorithms.
|
||||
@ -2041,6 +2043,8 @@ Returns the type name for the parameter class.
|
||||
|
||||
virtual QString valueAsPythonString( const QVariant &value, QgsProcessingContext &context ) const;
|
||||
|
||||
virtual QString createFileFilter() const;
|
||||
|
||||
|
||||
static QgsProcessingParameterRasterLayer *fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition ) /Factory/;
|
||||
%Docstring
|
||||
@ -2327,7 +2331,7 @@ Sets the geometry ``types`` for sources acceptable by the parameter.
|
||||
|
||||
};
|
||||
|
||||
class QgsProcessingParameterVectorLayer : QgsProcessingParameterDefinition, QgsProcessingParameterLimitedDataTypes
|
||||
class QgsProcessingParameterVectorLayer : QgsProcessingParameterDefinition, QgsProcessingParameterLimitedDataTypes, QgsFileFilterGenerator
|
||||
{
|
||||
%Docstring
|
||||
A vector layer (with or without geometry) parameter for processing algorithms. Consider using
|
||||
@ -2363,6 +2367,8 @@ Returns the type name for the parameter class.
|
||||
|
||||
virtual QString asPythonString( QgsProcessing::PythonOutputType outputType = QgsProcessing::PythonQgsProcessingAlgorithmSubclass ) const;
|
||||
|
||||
virtual QString createFileFilter() const;
|
||||
|
||||
|
||||
virtual QVariantMap toVariantMap() const;
|
||||
|
||||
@ -2376,7 +2382,7 @@ Creates a new parameter using the definition from a script code.
|
||||
|
||||
};
|
||||
|
||||
class QgsProcessingParameterMeshLayer : QgsProcessingParameterDefinition
|
||||
class QgsProcessingParameterMeshLayer : QgsProcessingParameterDefinition, QgsFileFilterGenerator
|
||||
{
|
||||
%Docstring
|
||||
A mesh layer parameter for processing algorithms.
|
||||
@ -2408,6 +2414,8 @@ Returns the type name for the parameter class.
|
||||
|
||||
virtual QString valueAsPythonString( const QVariant &value, QgsProcessingContext &context ) const;
|
||||
|
||||
virtual QString createFileFilter() const;
|
||||
|
||||
|
||||
static QgsProcessingParameterMeshLayer *fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition ) /Factory/;
|
||||
%Docstring
|
||||
@ -2415,7 +2423,7 @@ Creates a new parameter using the definition from a script code.
|
||||
%End
|
||||
};
|
||||
|
||||
class QgsProcessingParameterMapLayer : QgsProcessingParameterDefinition, QgsProcessingParameterLimitedDataTypes
|
||||
class QgsProcessingParameterMapLayer : QgsProcessingParameterDefinition, QgsProcessingParameterLimitedDataTypes, QgsFileFilterGenerator
|
||||
{
|
||||
%Docstring
|
||||
A map layer parameter for processing algorithms.
|
||||
@ -2450,6 +2458,8 @@ Returns the type name for the parameter class.
|
||||
|
||||
virtual QString asPythonString( QgsProcessing::PythonOutputType outputType = QgsProcessing::PythonQgsProcessingAlgorithmSubclass ) const;
|
||||
|
||||
virtual QString createFileFilter() const;
|
||||
|
||||
|
||||
virtual QVariantMap toVariantMap() const;
|
||||
|
||||
@ -2591,7 +2601,7 @@ Creates a new parameter using the definition from a script code.
|
||||
};
|
||||
|
||||
|
||||
class QgsProcessingParameterFeatureSource : QgsProcessingParameterDefinition, QgsProcessingParameterLimitedDataTypes
|
||||
class QgsProcessingParameterFeatureSource : QgsProcessingParameterDefinition, QgsProcessingParameterLimitedDataTypes, QgsFileFilterGenerator
|
||||
{
|
||||
%Docstring
|
||||
An input feature source (such as vector layers) parameter for processing algorithms.
|
||||
@ -2626,6 +2636,8 @@ Returns the type name for the parameter class.
|
||||
|
||||
virtual QString asPythonString( QgsProcessing::PythonOutputType outputType = QgsProcessing::PythonQgsProcessingAlgorithmSubclass ) const;
|
||||
|
||||
virtual QString createFileFilter() const;
|
||||
|
||||
|
||||
virtual QVariantMap toVariantMap() const;
|
||||
|
||||
@ -2639,7 +2651,7 @@ Creates a new parameter using the definition from a script code.
|
||||
|
||||
};
|
||||
|
||||
class QgsProcessingDestinationParameter : QgsProcessingParameterDefinition
|
||||
class QgsProcessingDestinationParameter : QgsProcessingParameterDefinition, QgsFileFilterGenerator
|
||||
{
|
||||
%Docstring
|
||||
Base class for all parameter definitions which represent file or layer destinations, e.g. parameters
|
||||
@ -2669,6 +2681,8 @@ output will not be created by default.
|
||||
|
||||
virtual QString asPythonString( QgsProcessing::PythonOutputType outputType = QgsProcessing::PythonQgsProcessingAlgorithmSubclass ) const;
|
||||
|
||||
virtual QString createFileFilter() const;
|
||||
|
||||
|
||||
virtual QgsProcessingOutputDefinition *toOutputDefinition() const = 0 /Factory/;
|
||||
%Docstring
|
||||
@ -2780,6 +2794,8 @@ Returns the type name for the parameter class.
|
||||
|
||||
virtual QString asPythonString( QgsProcessing::PythonOutputType outputType = QgsProcessing::PythonQgsProcessingAlgorithmSubclass ) const;
|
||||
|
||||
virtual QString createFileFilter() const;
|
||||
|
||||
|
||||
virtual QStringList supportedOutputVectorLayerExtensions() const;
|
||||
%Docstring
|
||||
@ -2872,6 +2888,8 @@ Returns the type name for the parameter class.
|
||||
|
||||
virtual QString asPythonString( QgsProcessing::PythonOutputType outputType = QgsProcessing::PythonQgsProcessingAlgorithmSubclass ) const;
|
||||
|
||||
virtual QString createFileFilter() const;
|
||||
|
||||
|
||||
virtual QStringList supportedOutputVectorLayerExtensions() const;
|
||||
%Docstring
|
||||
@ -2955,6 +2973,8 @@ Returns the type name for the parameter class.
|
||||
|
||||
virtual QString defaultFileExtension() const;
|
||||
|
||||
virtual QString createFileFilter() const;
|
||||
|
||||
|
||||
virtual QStringList supportedOutputRasterLayerExtensions() const;
|
||||
%Docstring
|
||||
@ -3014,6 +3034,8 @@ Returns the type name for the parameter class.
|
||||
|
||||
virtual QString asPythonString( QgsProcessing::PythonOutputType outputType = QgsProcessing::PythonQgsProcessingAlgorithmSubclass ) const;
|
||||
|
||||
virtual QString createFileFilter() const;
|
||||
|
||||
|
||||
QString fileFilter() const;
|
||||
%Docstring
|
||||
|
@ -48,7 +48,6 @@ from processing.gui.AlgorithmExecutor import execute
|
||||
from processing.tools import dataobjects
|
||||
from processing.gui.Postprocessing import handleAlgorithmResults
|
||||
from processing.gui.PostgisTableSelector import PostgisTableSelector
|
||||
from processing.gui.ParameterGuiUtils import getFileFilter
|
||||
|
||||
pluginPath = os.path.dirname(__file__)
|
||||
with warnings.catch_warnings():
|
||||
@ -153,7 +152,7 @@ class FieldsCalculatorDialog(BASE, WIDGET):
|
||||
|
||||
def selectFile(self):
|
||||
output = self.alg.parameterDefinition('OUTPUT')
|
||||
fileFilter = getFileFilter(output)
|
||||
fileFilter = output.createFileFilter()
|
||||
|
||||
settings = QgsSettings()
|
||||
if settings.contains('/Processing/LastOutputPath'):
|
||||
|
@ -43,7 +43,6 @@ from qgis.core import (QgsMapLayer,
|
||||
|
||||
from processing.gui.MultipleInputDialog import MultipleInputDialog
|
||||
|
||||
from processing.gui.ParameterGuiUtils import getFileFilter
|
||||
from processing.tools import dataobjects
|
||||
|
||||
|
||||
@ -174,7 +173,7 @@ class BatchInputSelectionPanel(QWidget):
|
||||
|
||||
if not seldir:
|
||||
ret, selected_filter = QFileDialog.getOpenFileNames(
|
||||
self, self.tr('Select Files'), path, getFileFilter(self.param)
|
||||
self, self.tr('Select Files'), path, self.param.createFileFilter()
|
||||
)
|
||||
else:
|
||||
ret = QFileDialog.getExistingDirectory(self, self.tr('Select Directory'), path)
|
||||
|
@ -37,7 +37,6 @@ from qgis.core import (QgsMapLayer,
|
||||
from qgis.PyQt.QtWidgets import QWidget, QPushButton, QLineEdit, QHBoxLayout, QSizePolicy, QFileDialog
|
||||
|
||||
from processing.gui.AutofillDialog import AutofillDialog
|
||||
from processing.gui.ParameterGuiUtils import getFileFilter
|
||||
|
||||
|
||||
class BatchOutputSelectionPanel(QWidget):
|
||||
@ -70,7 +69,7 @@ class BatchOutputSelectionPanel(QWidget):
|
||||
self.selectDirectory()
|
||||
return
|
||||
|
||||
filefilter = getFileFilter(self.output)
|
||||
filefilter = self.output.createFileFilter()
|
||||
settings = QgsSettings()
|
||||
if settings.contains('/Processing/LastBatchOutputPath'):
|
||||
path = str(settings.value('/Processing/LastBatchOutputPath'))
|
||||
|
@ -33,7 +33,6 @@ from qgis.gui import QgsEncodingSelectionDialog
|
||||
from qgis.core import (QgsProcessing,
|
||||
QgsDataSourceUri,
|
||||
QgsCredentials,
|
||||
QgsExpression,
|
||||
QgsSettings,
|
||||
QgsProcessingParameterFeatureSink,
|
||||
QgsProcessingParameterRasterDestination,
|
||||
@ -43,9 +42,7 @@ from qgis.core import (QgsProcessing,
|
||||
QgsProcessingParameterFolderDestination,
|
||||
QgsProcessingParameterVectorDestination)
|
||||
from processing.core.ProcessingConfig import ProcessingConfig
|
||||
from processing.tools.dataobjects import createContext
|
||||
from processing.gui.PostgisTableSelector import PostgisTableSelector
|
||||
from processing.gui.ParameterGuiUtils import getFileFilter
|
||||
|
||||
pluginPath = os.path.split(os.path.dirname(__file__))[0]
|
||||
|
||||
@ -230,7 +227,7 @@ class DestinationSelectionPanel(BASE, WIDGET):
|
||||
self.destinationChanged.emit()
|
||||
|
||||
def selectFile(self):
|
||||
file_filter = getFileFilter(self.parameter)
|
||||
file_filter = self.parameter.createFileFilter()
|
||||
settings = QgsSettings()
|
||||
if isinstance(self.parameter, (QgsProcessingParameterFeatureSink, QgsProcessingParameterVectorDestination)):
|
||||
last_ext_path = '/Processing/LastVectorOutputExt'
|
||||
|
@ -1,87 +0,0 @@
|
||||
# -*- 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 ''
|
@ -122,7 +122,6 @@ from processing.gui.MultipleInputPanel import MultipleInputPanel
|
||||
from processing.gui.BatchInputSelectionPanel import BatchInputSelectionPanel
|
||||
from processing.gui.FixedTablePanel import FixedTablePanel
|
||||
from processing.gui.ExtentSelectionPanel import ExtentSelectionPanel
|
||||
from processing.gui.ParameterGuiUtils import getFileFilter
|
||||
|
||||
from processing.tools import dataobjects
|
||||
|
||||
@ -249,7 +248,7 @@ class WidgetWrapper(QgsAbstractProcessingParameterWidgetWrapper):
|
||||
|
||||
# TODO: should use selectedFilter argument for default file format
|
||||
filename, selected_filter = QFileDialog.getOpenFileName(self.widget, self.tr('Select File'),
|
||||
path, getFileFilter(self.parameterDefinition()))
|
||||
path, self.parameterDefinition().createFileFilter())
|
||||
if filename:
|
||||
settings.setValue('/Processing/LastInputPath',
|
||||
os.path.dirname(str(filename)))
|
||||
|
@ -35,6 +35,7 @@
|
||||
#include "qgsprintlayout.h"
|
||||
#include "qgssymbollayerutils.h"
|
||||
#include "qgsfileutils.h"
|
||||
#include "qgsproviderregistry.h"
|
||||
#include <functional>
|
||||
|
||||
|
||||
@ -2304,6 +2305,32 @@ QString QgsProcessingParameterMapLayer::valueAsPythonString( const QVariant &val
|
||||
: QgsProcessingUtils::stringToPythonLiteral( val.toString() );
|
||||
}
|
||||
|
||||
QString createAllMapLayerFileFilter()
|
||||
{
|
||||
QStringList vectors = QgsProviderRegistry::instance()->fileVectorFilters().split( QStringLiteral( ";;" ) );
|
||||
QStringList rasters = QgsProviderRegistry::instance()->fileRasterFilters().split( QStringLiteral( ";;" ) );
|
||||
for ( const QString &raster : rasters )
|
||||
{
|
||||
if ( !vectors.contains( raster ) )
|
||||
vectors << raster;
|
||||
}
|
||||
QStringList meshFilters = QgsProviderRegistry::instance()->fileMeshFilters().split( QStringLiteral( ";;" ) );
|
||||
for ( const QString &mesh : meshFilters )
|
||||
{
|
||||
if ( !vectors.contains( mesh ) )
|
||||
vectors << mesh;
|
||||
}
|
||||
vectors.removeAll( QObject::tr( "All files (*.*)" ) );
|
||||
std::sort( vectors.begin(), vectors.end() );
|
||||
|
||||
return QObject::tr( "All files (*.*)" ) + QStringLiteral( ";;" ) + vectors.join( QStringLiteral( ";;" ) );
|
||||
}
|
||||
|
||||
QString QgsProcessingParameterMapLayer::createFileFilter() const
|
||||
{
|
||||
return createAllMapLayerFileFilter();
|
||||
}
|
||||
|
||||
QString QgsProcessingParameterMapLayer::asScriptCode() const
|
||||
{
|
||||
QString code = QStringLiteral( "##%1=" ).arg( mName );
|
||||
@ -3147,6 +3174,33 @@ QString QgsProcessingParameterMultipleLayers::asPythonString( const QgsProcessin
|
||||
return QString();
|
||||
}
|
||||
|
||||
QString QgsProcessingParameterMultipleLayers::createFileFilter() const
|
||||
{
|
||||
QStringList exts;
|
||||
switch ( mLayerType )
|
||||
{
|
||||
case QgsProcessing::TypeFile:
|
||||
return QObject::tr( "All files (*.*)" );
|
||||
|
||||
case QgsProcessing::TypeRaster:
|
||||
return QgsProviderRegistry::instance()->fileRasterFilters() + QStringLiteral( ";;" ) + QObject::tr( "All files (*.*)" );
|
||||
|
||||
case QgsProcessing::TypeVector:
|
||||
case QgsProcessing::TypeVectorAnyGeometry:
|
||||
case QgsProcessing::TypeVectorPoint:
|
||||
case QgsProcessing::TypeVectorLine:
|
||||
case QgsProcessing::TypeVectorPolygon:
|
||||
return QgsProviderRegistry::instance()->fileVectorFilters() + QStringLiteral( ";;" ) + QObject::tr( "All files (*.*)" );
|
||||
|
||||
case QgsProcessing::TypeMesh:
|
||||
return QgsProviderRegistry::instance()->fileMeshFilters() + QStringLiteral( ";;" ) + QObject::tr( "All files (*.*)" );
|
||||
|
||||
case QgsProcessing::TypeMapLayer:
|
||||
return createAllMapLayerFileFilter();
|
||||
}
|
||||
return QString();
|
||||
}
|
||||
|
||||
QgsProcessing::SourceType QgsProcessingParameterMultipleLayers::layerType() const
|
||||
{
|
||||
return mLayerType;
|
||||
@ -3529,6 +3583,11 @@ QString QgsProcessingParameterRasterLayer::valueAsPythonString( const QVariant &
|
||||
: QgsProcessingUtils::stringToPythonLiteral( val.toString() );
|
||||
}
|
||||
|
||||
QString QgsProcessingParameterRasterLayer::createFileFilter() const
|
||||
{
|
||||
return QgsProviderRegistry::instance()->fileRasterFilters() + QStringLiteral( ";;" ) + QObject::tr( "All files (*.*)" );
|
||||
}
|
||||
|
||||
QgsProcessingParameterRasterLayer *QgsProcessingParameterRasterLayer::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
|
||||
{
|
||||
return new QgsProcessingParameterRasterLayer( name, description, definition.isEmpty() ? QVariant() : definition, isOptional );
|
||||
@ -4077,6 +4136,11 @@ QString QgsProcessingParameterVectorLayer::asPythonString( const QgsProcessing::
|
||||
return QString();
|
||||
}
|
||||
|
||||
QString QgsProcessingParameterVectorLayer::createFileFilter() const
|
||||
{
|
||||
return QgsProviderRegistry::instance()->fileVectorFilters() + QStringLiteral( ";;" ) + QObject::tr( "All files (*.*)" );
|
||||
}
|
||||
|
||||
QList<int> QgsProcessingParameterLimitedDataTypes::dataTypes() const
|
||||
{
|
||||
return mDataTypes;
|
||||
@ -4184,6 +4248,11 @@ QString QgsProcessingParameterMeshLayer::valueAsPythonString( const QVariant &va
|
||||
: QgsProcessingUtils::stringToPythonLiteral( val.toString() );
|
||||
}
|
||||
|
||||
QString QgsProcessingParameterMeshLayer::createFileFilter() const
|
||||
{
|
||||
return QgsProviderRegistry::instance()->fileMeshFilters() + QStringLiteral( ";;" ) + QObject::tr( "All files (*.*)" );
|
||||
}
|
||||
|
||||
QgsProcessingParameterMeshLayer *QgsProcessingParameterMeshLayer::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
|
||||
{
|
||||
return new QgsProcessingParameterMeshLayer( name, description, definition.isEmpty() ? QVariant() : definition, isOptional );
|
||||
@ -4648,6 +4717,11 @@ QString QgsProcessingParameterFeatureSource::asPythonString( const QgsProcessing
|
||||
return QString();
|
||||
}
|
||||
|
||||
QString QgsProcessingParameterFeatureSource::createFileFilter() const
|
||||
{
|
||||
return QgsProviderRegistry::instance()->fileVectorFilters() + QStringLiteral( ";;" ) + QObject::tr( "All files (*.*)" );
|
||||
}
|
||||
|
||||
QgsProcessingParameterLimitedDataTypes::QgsProcessingParameterLimitedDataTypes( const QList<int> &types )
|
||||
: mDataTypes( types )
|
||||
{
|
||||
@ -4860,6 +4934,18 @@ QString QgsProcessingParameterFeatureSink::asPythonString( const QgsProcessing::
|
||||
return QString();
|
||||
}
|
||||
|
||||
QString QgsProcessingParameterFeatureSink::createFileFilter() const
|
||||
{
|
||||
const QStringList exts = supportedOutputVectorLayerExtensions();
|
||||
QStringList filters;
|
||||
for ( const QString &ext : exts )
|
||||
{
|
||||
filters << QObject::tr( "%1 files (*.%2)" ).arg( ext.toUpper(), ext.toLower() );
|
||||
}
|
||||
return filters.join( QStringLiteral( ";;" ) ) + QStringLiteral( ";;" ) + QObject::tr( "All files (*.*)" );
|
||||
|
||||
}
|
||||
|
||||
QStringList QgsProcessingParameterFeatureSink::supportedOutputVectorLayerExtensions() const
|
||||
{
|
||||
if ( originalProvider() )
|
||||
@ -5051,6 +5137,17 @@ QString QgsProcessingParameterRasterDestination::defaultFileExtension() const
|
||||
}
|
||||
}
|
||||
|
||||
QString QgsProcessingParameterRasterDestination::createFileFilter() const
|
||||
{
|
||||
const QStringList exts = supportedOutputRasterLayerExtensions();
|
||||
QStringList filters;
|
||||
for ( const QString &ext : exts )
|
||||
{
|
||||
filters << QObject::tr( "%1 files (*.%2)" ).arg( ext.toUpper(), ext.toLower() );
|
||||
}
|
||||
return filters.join( QStringLiteral( ";;" ) ) + QStringLiteral( ";;" ) + QObject::tr( "All files (*.*)" );
|
||||
}
|
||||
|
||||
QStringList QgsProcessingParameterRasterDestination::supportedOutputRasterLayerExtensions() const
|
||||
{
|
||||
if ( originalProvider() )
|
||||
@ -5193,6 +5290,11 @@ QString QgsProcessingParameterFileDestination::asPythonString( const QgsProcessi
|
||||
return QString();
|
||||
}
|
||||
|
||||
QString QgsProcessingParameterFileDestination::createFileFilter() const
|
||||
{
|
||||
return ( fileFilter().isEmpty() ? QString() : fileFilter() + QStringLiteral( ";;" ) ) + QObject::tr( "All files (*.*)" );
|
||||
}
|
||||
|
||||
QString QgsProcessingParameterFileDestination::fileFilter() const
|
||||
{
|
||||
return mFileFilter;
|
||||
@ -5324,6 +5426,11 @@ QString QgsProcessingDestinationParameter::asPythonString( const QgsProcessing::
|
||||
return QString();
|
||||
}
|
||||
|
||||
QString QgsProcessingDestinationParameter::createFileFilter() const
|
||||
{
|
||||
return QObject::tr( "Default extension" ) + QStringLiteral( " (*." ) + defaultFileExtension() + ')';
|
||||
}
|
||||
|
||||
QString QgsProcessingDestinationParameter::generateTemporaryDestination() const
|
||||
{
|
||||
if ( defaultFileExtension().isEmpty() )
|
||||
@ -5495,6 +5602,17 @@ QString QgsProcessingParameterVectorDestination::asPythonString( const QgsProces
|
||||
return QString();
|
||||
}
|
||||
|
||||
QString QgsProcessingParameterVectorDestination::createFileFilter() const
|
||||
{
|
||||
const QStringList exts = supportedOutputVectorLayerExtensions();
|
||||
QStringList filters;
|
||||
for ( const QString &ext : exts )
|
||||
{
|
||||
filters << QObject::tr( "%1 files (*.%2)" ).arg( ext.toUpper(), ext.toLower() );
|
||||
}
|
||||
return filters.join( QStringLiteral( ";;" ) ) + QStringLiteral( ";;" ) + QObject::tr( "All files (*.*)" );
|
||||
}
|
||||
|
||||
QStringList QgsProcessingParameterVectorDestination::supportedOutputVectorLayerExtensions() const
|
||||
{
|
||||
if ( originalProvider() )
|
||||
|
@ -25,6 +25,7 @@
|
||||
#include "qgscoordinatereferencesystem.h"
|
||||
#include "qgsfeaturesource.h"
|
||||
#include "qgsprocessingutils.h"
|
||||
#include "qgsfilefiltergenerator.h"
|
||||
#include <QMap>
|
||||
#include <limits>
|
||||
|
||||
@ -1619,7 +1620,7 @@ class CORE_EXPORT QgsProcessingParameterMatrix : public QgsProcessingParameterDe
|
||||
* A parameter for processing algorithms which accepts multiple map layers.
|
||||
* \since QGIS 3.0
|
||||
*/
|
||||
class CORE_EXPORT QgsProcessingParameterMultipleLayers : public QgsProcessingParameterDefinition
|
||||
class CORE_EXPORT QgsProcessingParameterMultipleLayers : public QgsProcessingParameterDefinition, public QgsFileFilterGenerator
|
||||
{
|
||||
public:
|
||||
|
||||
@ -1640,6 +1641,7 @@ class CORE_EXPORT QgsProcessingParameterMultipleLayers : public QgsProcessingPar
|
||||
QString valueAsPythonString( const QVariant &value, QgsProcessingContext &context ) const override;
|
||||
QString asScriptCode() const override;
|
||||
QString asPythonString( QgsProcessing::PythonOutputType outputType = QgsProcessing::PythonQgsProcessingAlgorithmSubclass ) const override;
|
||||
QString createFileFilter() const override;
|
||||
|
||||
/**
|
||||
* Returns the layer type for layers acceptable by the parameter.
|
||||
@ -1963,7 +1965,7 @@ class CORE_EXPORT QgsProcessingParameterRange : public QgsProcessingParameterDef
|
||||
* A raster layer parameter for processing algorithms.
|
||||
* \since QGIS 3.0
|
||||
*/
|
||||
class CORE_EXPORT QgsProcessingParameterRasterLayer : public QgsProcessingParameterDefinition
|
||||
class CORE_EXPORT QgsProcessingParameterRasterLayer : public QgsProcessingParameterDefinition, public QgsFileFilterGenerator
|
||||
{
|
||||
public:
|
||||
|
||||
@ -1981,6 +1983,7 @@ class CORE_EXPORT QgsProcessingParameterRasterLayer : public QgsProcessingParame
|
||||
QString type() const override { return typeName(); }
|
||||
bool checkValueIsAcceptable( const QVariant &input, QgsProcessingContext *context = nullptr ) const override;
|
||||
QString valueAsPythonString( const QVariant &value, QgsProcessingContext &context ) const override;
|
||||
QString createFileFilter() const override;
|
||||
|
||||
/**
|
||||
* Creates a new parameter using the definition from a script code.
|
||||
@ -2243,7 +2246,7 @@ class CORE_EXPORT QgsProcessingParameterLimitedDataTypes
|
||||
* the more versatile QgsProcessingParameterFeatureSource wherever possible.
|
||||
* \since QGIS 3.0
|
||||
*/
|
||||
class CORE_EXPORT QgsProcessingParameterVectorLayer : public QgsProcessingParameterDefinition, public QgsProcessingParameterLimitedDataTypes
|
||||
class CORE_EXPORT QgsProcessingParameterVectorLayer : public QgsProcessingParameterDefinition, public QgsProcessingParameterLimitedDataTypes, public QgsFileFilterGenerator
|
||||
{
|
||||
public:
|
||||
|
||||
@ -2265,6 +2268,7 @@ class CORE_EXPORT QgsProcessingParameterVectorLayer : public QgsProcessingParame
|
||||
bool checkValueIsAcceptable( const QVariant &input, QgsProcessingContext *context = nullptr ) const override;
|
||||
QString valueAsPythonString( const QVariant &value, QgsProcessingContext &context ) const override;
|
||||
QString asPythonString( QgsProcessing::PythonOutputType outputType = QgsProcessing::PythonQgsProcessingAlgorithmSubclass ) const override;
|
||||
QString createFileFilter() const override;
|
||||
|
||||
QVariantMap toVariantMap() const override;
|
||||
bool fromVariantMap( const QVariantMap &map ) override;
|
||||
@ -2282,7 +2286,7 @@ class CORE_EXPORT QgsProcessingParameterVectorLayer : public QgsProcessingParame
|
||||
* A mesh layer parameter for processing algorithms.
|
||||
* \since QGIS 3.6
|
||||
*/
|
||||
class CORE_EXPORT QgsProcessingParameterMeshLayer : public QgsProcessingParameterDefinition
|
||||
class CORE_EXPORT QgsProcessingParameterMeshLayer : public QgsProcessingParameterDefinition, public QgsFileFilterGenerator
|
||||
{
|
||||
public:
|
||||
|
||||
@ -2302,6 +2306,7 @@ class CORE_EXPORT QgsProcessingParameterMeshLayer : public QgsProcessingParamete
|
||||
QString type() const override { return typeName(); }
|
||||
bool checkValueIsAcceptable( const QVariant &input, QgsProcessingContext *context = nullptr ) const override;
|
||||
QString valueAsPythonString( const QVariant &value, QgsProcessingContext &context ) const override;
|
||||
QString createFileFilter() const override;
|
||||
|
||||
/**
|
||||
* Creates a new parameter using the definition from a script code.
|
||||
@ -2315,7 +2320,7 @@ class CORE_EXPORT QgsProcessingParameterMeshLayer : public QgsProcessingParamete
|
||||
* A map layer parameter for processing algorithms.
|
||||
* \since QGIS 3.0
|
||||
*/
|
||||
class CORE_EXPORT QgsProcessingParameterMapLayer : public QgsProcessingParameterDefinition, public QgsProcessingParameterLimitedDataTypes
|
||||
class CORE_EXPORT QgsProcessingParameterMapLayer : public QgsProcessingParameterDefinition, public QgsProcessingParameterLimitedDataTypes, public QgsFileFilterGenerator
|
||||
{
|
||||
public:
|
||||
|
||||
@ -2336,6 +2341,7 @@ class CORE_EXPORT QgsProcessingParameterMapLayer : public QgsProcessingParameter
|
||||
QString valueAsPythonString( const QVariant &value, QgsProcessingContext &context ) const override;
|
||||
QString asScriptCode() const override;
|
||||
QString asPythonString( QgsProcessing::PythonOutputType outputType = QgsProcessing::PythonQgsProcessingAlgorithmSubclass ) const override;
|
||||
QString createFileFilter() const override;
|
||||
|
||||
QVariantMap toVariantMap() const override;
|
||||
bool fromVariantMap( const QVariantMap &map ) override;
|
||||
@ -2470,7 +2476,7 @@ class CORE_EXPORT QgsProcessingParameterField : public QgsProcessingParameterDef
|
||||
* An input feature source (such as vector layers) parameter for processing algorithms.
|
||||
* \since QGIS 3.0
|
||||
*/
|
||||
class CORE_EXPORT QgsProcessingParameterFeatureSource : public QgsProcessingParameterDefinition, public QgsProcessingParameterLimitedDataTypes
|
||||
class CORE_EXPORT QgsProcessingParameterFeatureSource : public QgsProcessingParameterDefinition, public QgsProcessingParameterLimitedDataTypes, public QgsFileFilterGenerator
|
||||
{
|
||||
public:
|
||||
|
||||
@ -2491,6 +2497,7 @@ class CORE_EXPORT QgsProcessingParameterFeatureSource : public QgsProcessingPara
|
||||
QString valueAsPythonString( const QVariant &value, QgsProcessingContext &context ) const override;
|
||||
QString asScriptCode() const override;
|
||||
QString asPythonString( QgsProcessing::PythonOutputType outputType = QgsProcessing::PythonQgsProcessingAlgorithmSubclass ) const override;
|
||||
QString createFileFilter() const override;
|
||||
|
||||
QVariantMap toVariantMap() const override;
|
||||
bool fromVariantMap( const QVariantMap &map ) override;
|
||||
@ -2509,7 +2516,7 @@ class CORE_EXPORT QgsProcessingParameterFeatureSource : public QgsProcessingPara
|
||||
* which are used for the destination for layers output by an algorithm.
|
||||
* \since QGIS 3.0
|
||||
*/
|
||||
class CORE_EXPORT QgsProcessingDestinationParameter : public QgsProcessingParameterDefinition
|
||||
class CORE_EXPORT QgsProcessingDestinationParameter : public QgsProcessingParameterDefinition, public QgsFileFilterGenerator
|
||||
{
|
||||
public:
|
||||
|
||||
@ -2526,6 +2533,7 @@ class CORE_EXPORT QgsProcessingDestinationParameter : public QgsProcessingParame
|
||||
QVariantMap toVariantMap() const override;
|
||||
bool fromVariantMap( const QVariantMap &map ) override;
|
||||
QString asPythonString( QgsProcessing::PythonOutputType outputType = QgsProcessing::PythonQgsProcessingAlgorithmSubclass ) const override;
|
||||
QString createFileFilter() const override;
|
||||
|
||||
/**
|
||||
* Returns a new QgsProcessingOutputDefinition corresponding to the definition of the destination
|
||||
@ -2638,6 +2646,7 @@ class CORE_EXPORT QgsProcessingParameterFeatureSink : public QgsProcessingDestin
|
||||
QgsProcessingOutputDefinition *toOutputDefinition() const override SIP_FACTORY;
|
||||
QString defaultFileExtension() const override;
|
||||
QString asPythonString( QgsProcessing::PythonOutputType outputType = QgsProcessing::PythonQgsProcessingAlgorithmSubclass ) const override;
|
||||
QString createFileFilter() const override;
|
||||
|
||||
/**
|
||||
* Returns a list of the vector format file extensions supported by this parameter.
|
||||
@ -2714,6 +2723,7 @@ class CORE_EXPORT QgsProcessingParameterVectorDestination : public QgsProcessing
|
||||
QgsProcessingOutputDefinition *toOutputDefinition() const override SIP_FACTORY;
|
||||
QString defaultFileExtension() const override;
|
||||
QString asPythonString( QgsProcessing::PythonOutputType outputType = QgsProcessing::PythonQgsProcessingAlgorithmSubclass ) const override;
|
||||
QString createFileFilter() const override;
|
||||
|
||||
/**
|
||||
* Returns a list of the vector format file extensions supported by this parameter.
|
||||
@ -2786,6 +2796,7 @@ class CORE_EXPORT QgsProcessingParameterRasterDestination : public QgsProcessing
|
||||
QString valueAsPythonString( const QVariant &value, QgsProcessingContext &context ) const override;
|
||||
QgsProcessingOutputDefinition *toOutputDefinition() const override SIP_FACTORY;
|
||||
QString defaultFileExtension() const override;
|
||||
QString createFileFilter() const override;
|
||||
|
||||
/**
|
||||
* Returns a list of the raster format file extensions supported for this parameter.
|
||||
@ -2834,6 +2845,7 @@ class CORE_EXPORT QgsProcessingParameterFileDestination : public QgsProcessingDe
|
||||
QgsProcessingOutputDefinition *toOutputDefinition() const override SIP_FACTORY;
|
||||
QString defaultFileExtension() const override;
|
||||
QString asPythonString( QgsProcessing::PythonOutputType outputType = QgsProcessing::PythonQgsProcessingAlgorithmSubclass ) const override;
|
||||
QString createFileFilter() const override;
|
||||
|
||||
/**
|
||||
* Returns the file filter string for file destinations compatible with this parameter.
|
||||
|
@ -2406,6 +2406,11 @@ void TestQgsProcessing::parameterMapLayer()
|
||||
QVERIFY( !def->checkValueIsAcceptable( "" ) );
|
||||
QVERIFY( !def->checkValueIsAcceptable( QVariant() ) );
|
||||
|
||||
QVERIFY( def->createFileFilter().contains( QStringLiteral( "*.shp" ) ) );
|
||||
QVERIFY( def->createFileFilter().contains( QStringLiteral( "*.tif" ) ) );
|
||||
QVERIFY( def->createFileFilter().contains( QStringLiteral( "*.2dm" ) ) );
|
||||
QVERIFY( def->createFileFilter().contains( QStringLiteral( "*.*" ) ) );
|
||||
|
||||
// should be OK
|
||||
QVERIFY( def->checkValueIsAcceptable( "c:/Users/admin/Desktop/roads_clipped_transformed_v1_reprojected_final_clipped_aAAA.shp" ) );
|
||||
// ... unless we use context, when the check that the layer actually exists is performed
|
||||
@ -3309,6 +3314,10 @@ void TestQgsProcessing::parameterLayerList()
|
||||
QVERIFY( !def->checkValueIsAcceptable( QStringList() << "c:/Users/admin/Desktop/roads_clipped_transformed_v1_reprojected_final_clipped_aAAA.shp", &context ) );
|
||||
QVERIFY( !def->checkValueIsAcceptable( QVariantList() << "c:/Users/admin/Desktop/roads_clipped_transformed_v1_reprojected_final_clipped_aAAA.shp", &context ) );
|
||||
|
||||
QVERIFY( def->createFileFilter().contains( QStringLiteral( "*.shp" ) ) );
|
||||
QVERIFY( def->createFileFilter().contains( QStringLiteral( "*.tif" ) ) );
|
||||
QVERIFY( def->createFileFilter().contains( QStringLiteral( "*.2dm" ) ) );
|
||||
QVERIFY( def->createFileFilter().contains( QStringLiteral( "*.*" ) ) );
|
||||
|
||||
// using existing map layer ID
|
||||
QVariantMap params;
|
||||
@ -3453,6 +3462,10 @@ void TestQgsProcessing::parameterLayerList()
|
||||
def.reset( new QgsProcessingParameterMultipleLayers( "optional", QString(), QgsProcessing::TypeMapLayer, QVariantList() << v1->id() << r1->publicSource(), true ) );
|
||||
params.insert( "optional", QVariant() );
|
||||
QCOMPARE( QgsProcessingParameters::parameterAsLayerList( def.get(), params, context ), QList< QgsMapLayer *>() << v1 << r1 );
|
||||
QVERIFY( def->createFileFilter().contains( QStringLiteral( "*.shp" ) ) );
|
||||
QVERIFY( def->createFileFilter().contains( QStringLiteral( "*.tif" ) ) );
|
||||
QVERIFY( def->createFileFilter().contains( QStringLiteral( "*.2dm" ) ) );
|
||||
QVERIFY( def->createFileFilter().contains( QStringLiteral( "*.*" ) ) );
|
||||
|
||||
pythonCode = def->asPythonString();
|
||||
QCOMPARE( pythonCode, QStringLiteral( "QgsProcessingParameterMultipleLayers('optional', '', optional=True, layerType=QgsProcessing.TypeMapLayer, defaultValue=['" ) + r1->publicSource() + "'])" );
|
||||
@ -3476,6 +3489,11 @@ void TestQgsProcessing::parameterLayerList()
|
||||
QCOMPARE( QgsProcessingParameters::parameterAsLayerList( def.get(), params, context ), QList< QgsMapLayer *>() << v1 << r1 );
|
||||
|
||||
def.reset( new QgsProcessingParameterMultipleLayers( "type", QString(), QgsProcessing::TypeRaster ) );
|
||||
QVERIFY( !def->createFileFilter().contains( QStringLiteral( "*.shp" ) ) );
|
||||
QVERIFY( def->createFileFilter().contains( QStringLiteral( "*.tif" ) ) );
|
||||
QVERIFY( !def->createFileFilter().contains( QStringLiteral( "*.2dm" ) ) );
|
||||
QVERIFY( def->createFileFilter().contains( QStringLiteral( "*.*" ) ) );
|
||||
|
||||
pythonCode = def->asPythonString();
|
||||
QCOMPARE( pythonCode, QStringLiteral( "QgsProcessingParameterMultipleLayers('type', '', layerType=QgsProcessing.TypeRaster, defaultValue=None)" ) );
|
||||
code = def->asScriptCode();
|
||||
@ -3489,6 +3507,8 @@ void TestQgsProcessing::parameterLayerList()
|
||||
QCOMPARE( fromCode->layerType(), QgsProcessing::TypeRaster );
|
||||
|
||||
def.reset( new QgsProcessingParameterMultipleLayers( "type", QString(), QgsProcessing::TypeFile ) );
|
||||
QCOMPARE( def->createFileFilter(), QStringLiteral( "All files (*.*)" ) );
|
||||
|
||||
pythonCode = def->asPythonString();
|
||||
QCOMPARE( pythonCode, QStringLiteral( "QgsProcessingParameterMultipleLayers('type', '', layerType=QgsProcessing.TypeFile, defaultValue=None)" ) );
|
||||
code = def->asScriptCode();
|
||||
@ -4077,6 +4097,11 @@ void TestQgsProcessing::parameterRasterLayer()
|
||||
QVERIFY( def->checkValueIsAcceptable( QVariant::fromValue( r1 ) ) );
|
||||
QVERIFY( !def->checkValueIsAcceptable( QVariant::fromValue( v1 ) ) );
|
||||
|
||||
QVERIFY( !def->createFileFilter().contains( QStringLiteral( "*.shp" ) ) );
|
||||
QVERIFY( def->createFileFilter().contains( QStringLiteral( "*.tif" ) ) );
|
||||
QVERIFY( !def->createFileFilter().contains( QStringLiteral( "*.2dm" ) ) );
|
||||
QVERIFY( def->createFileFilter().contains( QStringLiteral( "*.*" ) ) );
|
||||
|
||||
// should be OK
|
||||
QVERIFY( def->checkValueIsAcceptable( "c:/Users/admin/Desktop/roads_clipped_transformed_v1_reprojected_final_clipped_aAAA.tif" ) );
|
||||
// ... unless we use context, when the check that the layer actually exists is performed
|
||||
@ -5034,6 +5059,11 @@ void TestQgsProcessing::parameterVectorLayer()
|
||||
QVERIFY( def->checkValueIsAcceptable( QgsProperty::fromValue( QStringLiteral( "layer12312312" ) ) ) );
|
||||
QVERIFY( !def->checkValueIsAcceptable( QgsProperty::fromValue( QString() ) ) );
|
||||
|
||||
QVERIFY( def->createFileFilter().contains( QStringLiteral( "*.shp" ) ) );
|
||||
QVERIFY( !def->createFileFilter().contains( QStringLiteral( "*.tif" ) ) );
|
||||
QVERIFY( !def->createFileFilter().contains( QStringLiteral( "*.2dm" ) ) );
|
||||
QVERIFY( def->createFileFilter().contains( QStringLiteral( "*.*" ) ) );
|
||||
|
||||
// should be OK
|
||||
QVERIFY( def->checkValueIsAcceptable( "c:/Users/admin/Desktop/roads_clipped_transformed_v1_reprojected_final_clipped_aAAA.shp" ) );
|
||||
// ... unless we use context, when the check that the layer actually exists is performed
|
||||
@ -5163,6 +5193,11 @@ void TestQgsProcessing::parameterMeshLayer()
|
||||
// ... unless we use context, when the check that the layer actually exists is performed
|
||||
QVERIFY( !def->checkValueIsAcceptable( "c:/Users/admin/Desktop/roads_clipped_transformed_v1_reprojected_final_clipped_aAAA.2dm", &context ) );
|
||||
|
||||
QVERIFY( !def->createFileFilter().contains( QStringLiteral( "*.shp" ) ) );
|
||||
QVERIFY( !def->createFileFilter().contains( QStringLiteral( "*.tif" ) ) );
|
||||
QVERIFY( def->createFileFilter().contains( QStringLiteral( "*.2dm" ) ) );
|
||||
QVERIFY( def->createFileFilter().contains( QStringLiteral( "*.*" ) ) );
|
||||
|
||||
// using existing map layer ID
|
||||
QVariantMap params;
|
||||
params.insert( "non_optional", m1->id() );
|
||||
@ -5284,6 +5319,11 @@ void TestQgsProcessing::parameterFeatureSource()
|
||||
// ... unless we use context, when the check that the layer actually exists is performed
|
||||
QVERIFY( !def->checkValueIsAcceptable( "c:/Users/admin/Desktop/roads_clipped_transformed_v1_reprojected_final_clipped_aAAA.shp", &context ) );
|
||||
|
||||
QVERIFY( def->createFileFilter().contains( QStringLiteral( "*.shp" ) ) );
|
||||
QVERIFY( !def->createFileFilter().contains( QStringLiteral( "*.tif" ) ) );
|
||||
QVERIFY( !def->createFileFilter().contains( QStringLiteral( "*.2dm" ) ) );
|
||||
QVERIFY( def->createFileFilter().contains( QStringLiteral( "*.*" ) ) );
|
||||
|
||||
// using existing map layer ID
|
||||
QVariantMap params;
|
||||
params.insert( "non_optional", v1->id() );
|
||||
@ -5455,6 +5495,11 @@ void TestQgsProcessing::parameterFeatureSink()
|
||||
QVERIFY( def->generateTemporaryDestination().endsWith( QLatin1String( ".gpkg" ) ) );
|
||||
QVERIFY( def->generateTemporaryDestination().startsWith( QgsProcessingUtils::tempFolder() ) );
|
||||
|
||||
QVERIFY( def->createFileFilter().contains( QStringLiteral( "*.shp" ) ) );
|
||||
QVERIFY( !def->createFileFilter().contains( QStringLiteral( "*.tif" ) ) );
|
||||
QVERIFY( !def->createFileFilter().contains( QStringLiteral( "*.2dm" ) ) );
|
||||
QVERIFY( def->createFileFilter().contains( QStringLiteral( "*.*" ) ) );
|
||||
|
||||
QVariantMap map = def->toVariantMap();
|
||||
QgsProcessingParameterFeatureSink fromMap( "x" );
|
||||
QVERIFY( fromMap.fromVariantMap( map ) );
|
||||
@ -5619,6 +5664,11 @@ void TestQgsProcessing::parameterVectorOut()
|
||||
QVERIFY( def->generateTemporaryDestination().endsWith( QLatin1String( ".gpkg" ) ) );
|
||||
QVERIFY( def->generateTemporaryDestination().startsWith( QgsProcessingUtils::tempFolder() ) );
|
||||
|
||||
QVERIFY( def->createFileFilter().contains( QStringLiteral( "*.shp" ) ) );
|
||||
QVERIFY( !def->createFileFilter().contains( QStringLiteral( "*.tif" ) ) );
|
||||
QVERIFY( !def->createFileFilter().contains( QStringLiteral( "*.2dm" ) ) );
|
||||
QVERIFY( def->createFileFilter().contains( QStringLiteral( "*.*" ) ) );
|
||||
|
||||
QVariantMap map = def->toVariantMap();
|
||||
QgsProcessingParameterVectorDestination fromMap( "x" );
|
||||
QVERIFY( fromMap.fromVariantMap( map ) );
|
||||
@ -5802,6 +5852,11 @@ void TestQgsProcessing::parameterRasterOut()
|
||||
QVERIFY( def->generateTemporaryDestination().endsWith( QLatin1String( ".tif" ) ) );
|
||||
QVERIFY( def->generateTemporaryDestination().startsWith( QgsProcessingUtils::tempFolder() ) );
|
||||
|
||||
QVERIFY( !def->createFileFilter().contains( QStringLiteral( "*.shp" ) ) );
|
||||
QVERIFY( def->createFileFilter().contains( QStringLiteral( "*.tif" ) ) );
|
||||
QVERIFY( !def->createFileFilter().contains( QStringLiteral( "*.2dm" ) ) );
|
||||
QVERIFY( def->createFileFilter().contains( QStringLiteral( "*.*" ) ) );
|
||||
|
||||
QVariantMap params;
|
||||
params.insert( "non_optional", "test.tif" );
|
||||
QCOMPARE( QgsProcessingParameters::parameterAsOutputLayer( def.get(), params, context ), QStringLiteral( "test.tif" ) );
|
||||
@ -5922,6 +5977,8 @@ void TestQgsProcessing::parameterFileOut()
|
||||
QCOMPARE( def->defaultFileExtension(), QStringLiteral( "pcx" ) );
|
||||
def->setFileFilter( QStringLiteral( "PCX files (*.pcx *.picx);;BMP files (*.bmp)" ) );
|
||||
QCOMPARE( def->defaultFileExtension(), QStringLiteral( "pcx" ) );
|
||||
QCOMPARE( def->createFileFilter(), QStringLiteral( "PCX files (*.pcx *.picx);;BMP files (*.bmp);;All files (*.*)" ) );
|
||||
|
||||
def->setFileFilter( QString() );
|
||||
QCOMPARE( def->defaultFileExtension(), QStringLiteral( "file" ) );
|
||||
QVERIFY( def->generateTemporaryDestination().endsWith( QLatin1String( ".file" ) ) );
|
||||
@ -5942,6 +5999,8 @@ void TestQgsProcessing::parameterFileOut()
|
||||
QVERIFY( def->checkValueIsAcceptable( "c:/Users/admin/Desktop/roads_clipped_transformed_v1_reprojected_final_clipped_aAAA.txt" ) );
|
||||
QVERIFY( def->checkValueIsAcceptable( "c:/Users/admin/Desktop/roads_clipped_transformed_v1_reprojected_final_clipped_aAAA.txt", &context ) );
|
||||
|
||||
QCOMPARE( def->createFileFilter(), QStringLiteral( "All files (*.*)" ) );
|
||||
|
||||
QVariantMap params;
|
||||
params.insert( "non_optional", "test.txt" );
|
||||
QCOMPARE( QgsProcessingParameters::parameterAsFileOutput( def.get(), params, context ), QStringLiteral( "test.txt" ) );
|
||||
|
Loading…
x
Reference in New Issue
Block a user