Skip to content
Permalink
Browse files

[processing] Move responsiblity for creation of file filter strings f…

…rom python to c++
  • Loading branch information
nyalldawson committed Mar 15, 2020
1 parent 51f40f7 commit edd0635fe3a7a517482dce0a75d853d43d91ac5d
@@ -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,14 +2414,16 @@ 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
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.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 @@ def setupSpinboxes(self, index):

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 processing.gui.MultipleInputDialog import MultipleInputDialog

from processing.gui.ParameterGuiUtils import getFileFilter
from processing.tools import dataobjects


@@ -174,7 +173,7 @@ def showFileDialog(self, seldir):

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.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 @@ def showSelectionDialog(self):
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.core import (QgsProcessing,
QgsDataSourceUri,
QgsCredentials,
QgsExpression,
QgsSettings,
QgsProcessingParameterFeatureSink,
QgsProcessingParameterRasterDestination,
@@ -43,9 +42,7 @@
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 @@ def saveToGeopackage(self):
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'

This file was deleted.

@@ -122,7 +122,6 @@
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 @@ def getFileName(self, initial_value=''):

# 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)))

0 comments on commit edd0635

Please sign in to comment.
You can’t perform that action at this time.