Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[processing] Move responsiblity for creation of file filter strings f…
…rom python to c++
  • Loading branch information
nyalldawson committed Mar 16, 2020
1 parent 51f40f7 commit edd0635
Show file tree
Hide file tree
Showing 10 changed files with 230 additions and 113 deletions.
Expand Up @@ -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.
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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;

Expand All @@ -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.
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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;

Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
Expand Up @@ -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():
Expand Down Expand Up @@ -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'):
Expand Down
3 changes: 1 addition & 2 deletions python/plugins/processing/gui/BatchInputSelectionPanel.py
Expand Up @@ -43,7 +43,6 @@

from processing.gui.MultipleInputDialog import MultipleInputDialog

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


Expand Down Expand Up @@ -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)
Expand Down
3 changes: 1 addition & 2 deletions python/plugins/processing/gui/BatchOutputSelectionPanel.py
Expand Up @@ -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):
Expand Down Expand Up @@ -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'))
Expand Down
5 changes: 1 addition & 4 deletions python/plugins/processing/gui/DestinationSelectionPanel.py
Expand Up @@ -33,7 +33,6 @@
from qgis.core import (QgsProcessing,
QgsDataSourceUri,
QgsCredentials,
QgsExpression,
QgsSettings,
QgsProcessingParameterFeatureSink,
QgsProcessingParameterRasterDestination,
Expand All @@ -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]

Expand Down Expand Up @@ -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'
Expand Down
87 changes: 0 additions & 87 deletions python/plugins/processing/gui/ParameterGuiUtils.py

This file was deleted.

3 changes: 1 addition & 2 deletions python/plugins/processing/gui/wrappers.py
Expand Up @@ -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

Expand Down Expand Up @@ -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)))
Expand Down

0 comments on commit edd0635

Please sign in to comment.