Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[processing] add QgsProcessingParameterMeshLayer parameter
  • Loading branch information
PeterPetrik committed Dec 17, 2018
1 parent c7cb5a8 commit e716602
Show file tree
Hide file tree
Showing 24 changed files with 609 additions and 23 deletions.
3 changes: 1 addition & 2 deletions python/core/auto_generated/processing/qgsprocessing.sip.in
Expand Up @@ -36,10 +36,9 @@ and parameters.
TypeRaster,
TypeFile,
TypeVector,
TypeMesh
};



};

/************************************************************************
Expand Down
Expand Up @@ -670,6 +670,18 @@ sources and stored temporarily in the ``context``. In either case, callers do no
need to handle deletion of the returned layer.
%End

QgsMeshLayer *parameterAsMeshLayer( const QVariantMap &parameters, const QString &name, QgsProcessingContext &context ) const;
%Docstring
Evaluates the parameter with matching ``name`` to a mesh layer.

Layers will either be taken from ``context``'s active project, or loaded from external
sources and stored temporarily in the ``context``. In either case, callers do not
need to handle deletion of the returned layer.

.. versionadded:: 3.6
%End


QString parameterAsOutputLayer( const QVariantMap &parameters, const QString &name, QgsProcessingContext &context ) const;
%Docstring
Evaluates the parameter with matching ``name`` to a output layer destination.
Expand Down
Expand Up @@ -155,6 +155,8 @@ their acceptable ranges, defaults, etc.
sipType = sipType_QgsProcessingParameterRange;
else if ( sipCpp->type() == QgsProcessingParameterRasterLayer::typeName() )
sipType = sipType_QgsProcessingParameterRasterLayer;
else if ( sipCpp->type() == QgsProcessingParameterMeshLayer::typeName() )
sipType = sipType_QgsProcessingParameterMeshLayer;
else if ( sipCpp->type() == QgsProcessingParameterEnum::typeName() )
sipType = sipType_QgsProcessingParameterEnum;
else if ( sipCpp->type() == QgsProcessingParameterString::typeName() )
Expand Down Expand Up @@ -745,6 +747,29 @@ need to handle deletion of the returned layer.
.. versionadded:: 3.4
%End

static QgsMeshLayer *parameterAsMeshLayer( const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, QgsProcessingContext &context );
%Docstring
Evaluates the parameter with matching ``definition`` and ``value`` to a mesh layer.

Layers will either be taken from ``context``'s active project, or loaded from external
sources and stored temporarily in the ``context``. In either case, callers do not
need to handle deletion of the returned layer.

.. versionadded:: 3.6
%End

static QgsMeshLayer *parameterAsMeshLayer( const QgsProcessingParameterDefinition *definition, const QVariant &value, QgsProcessingContext &context );
%Docstring
Evaluates the parameter with matching ``definition`` and ``value`` to a mesh layer.

Layers will either be taken from ``context``'s active project, or loaded from external
sources and stored temporarily in the ``context``. In either case, callers do not
need to handle deletion of the returned layer.

.. versionadded:: 3.6
%End


static QgsCoordinateReferenceSystem parameterAsCrs( const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, QgsProcessingContext &context );
%Docstring
Evaluates the parameter with matching ``definition`` to a coordinate reference system.
Expand Down Expand Up @@ -1955,6 +1980,45 @@ Creates a new parameter using the definition from a script code.

};

class QgsProcessingParameterMeshLayer : QgsProcessingParameterDefinition
{
%Docstring
A mesh layer parameter for processing algorithms.

.. versionadded:: 3.6
%End

%TypeHeaderCode
#include "qgsprocessingparameters.h"
%End
public:

QgsProcessingParameterMeshLayer( const QString &name,
const QString &description = QString(),
const QVariant &defaultValue = QVariant(),
bool optional = false );
%Docstring
Constructor for QgsProcessingParameterMeshLayer.
%End

static QString typeName();
%Docstring
Returns the type name for the parameter class.
%End
virtual QgsProcessingParameterDefinition *clone() const /Factory/;

virtual QString type() const;
virtual bool checkValueIsAcceptable( const QVariant &input, QgsProcessingContext *context = 0 ) const;

virtual QString valueAsPythonString( const QVariant &value, QgsProcessingContext &context ) 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 QgsProcessingParameterField : QgsProcessingParameterDefinition
{
%Docstring
Expand Down
22 changes: 22 additions & 0 deletions python/core/auto_generated/processing/qgsprocessingutils.sip.in
Expand Up @@ -35,6 +35,8 @@ value.

.. seealso:: :py:func:`compatibleVectorLayers`

.. seealso:: :py:func:`compatibleMeshLayers`

.. seealso:: :py:func:`compatibleLayers`
%End

Expand All @@ -55,7 +57,26 @@ value.

.. seealso:: :py:func:`compatibleRasterLayers`

.. seealso:: :py:func:`compatibleMeshLayers`

.. seealso:: :py:func:`compatibleLayers`
%End

static QList<QgsMeshLayer *> compatibleMeshLayers( QgsProject *project, bool sort = true );
%Docstring
Returns a list of mesh layers from a ``project`` which are compatible with the processing
framework.

If the ``sort`` argument is true then the layers will be sorted by their :py:func:`QgsMapLayer.name()`
value.

.. seealso:: :py:func:`compatibleRasterLayers`

.. seealso:: :py:func:`compatibleVectorLayers`

.. seealso:: :py:func:`compatibleLayers`

.. versionadded:: 3.6
%End

static QList< QgsMapLayer * > compatibleLayers( QgsProject *project, bool sort = true );
Expand All @@ -76,6 +97,7 @@ value.
UnknownType,
Vector,
Raster,
Mesh,
};

static QgsMapLayer *mapLayerFromString( const QString &string, QgsProcessingContext &context, bool allowLoadingNewLayers = true, LayerHint typeHint = UnknownType );
Expand Down
1 change: 1 addition & 0 deletions python/core/auto_generated/qgsmaplayerproxymodel.sip.in
Expand Up @@ -33,6 +33,7 @@ The QgsMapLayerProxyModel class provides an easy to use model to display the lis
VectorLayer,
PluginLayer,
WritableLayer,
MeshLayer,
All
};
typedef QFlags<QgsMapLayerProxyModel::Filter> Filters;
Expand Down
3 changes: 2 additions & 1 deletion python/plugins/processing/gui/ParameterGuiUtils.py
Expand Up @@ -83,7 +83,8 @@ def getFileFilter(param):
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:
Expand Down
39 changes: 37 additions & 2 deletions python/plugins/processing/gui/wrappers.py
Expand Up @@ -61,6 +61,7 @@
QgsProcessingParameterString,
QgsProcessingParameterExpression,
QgsProcessingParameterVectorLayer,
QgsProcessingParameterMeshLayer,
QgsProcessingParameterField,
QgsProcessingParameterFeatureSource,
QgsProcessingParameterMapLayer,
Expand Down Expand Up @@ -331,6 +332,7 @@ def createWidget(self):
self.combo.addItem(self.dialog.resolveValueDescription(crs), crs)
layers = self.dialog.getAvailableValuesOfType([QgsProcessingParameterRasterLayer,
QgsProcessingParameterVectorLayer,
QgsProcessingParameterMeshLayer,
QgsProcessingParameterFeatureSource],
[QgsProcessingOutputVectorLayer,
QgsProcessingOutputRasterLayer,
Expand Down Expand Up @@ -402,7 +404,8 @@ def createWidget(self):
widget.addItem(self.USE_MIN_COVERING_EXTENT, None)
layers = self.dialog.getAvailableValuesOfType([QgsProcessingParameterFeatureSource,
QgsProcessingParameterRasterLayer,
QgsProcessingParameterVectorLayer],
QgsProcessingParameterVectorLayer,
QgsProcessingParameterMeshLayer],
[QgsProcessingOutputRasterLayer,
QgsProcessingOutputVectorLayer,
QgsProcessingOutputMapLayer])
Expand Down Expand Up @@ -638,10 +641,15 @@ def _getOptions(self):
[QgsProcessingOutputRasterLayer,
QgsProcessingOutputMapLayer,
QgsProcessingOutputMultipleLayers])
elif self.parameterDefinition().layerType() == QgsProcessing.TypeMesh:
options = self.dialog.getAvailableValuesOfType(
(QgsProcessingParameterMeshLayer, QgsProcessingParameterMultipleLayers),
[])
elif self.parameterDefinition().layerType() == QgsProcessing.TypeMapLayer:
options = self.dialog.getAvailableValuesOfType((QgsProcessingParameterRasterLayer,
QgsProcessingParameterFeatureSource,
QgsProcessingParameterVectorLayer,
QgsProcessingParameterMeshLayer,
QgsProcessingParameterMultipleLayers),
[QgsProcessingOutputRasterLayer,
QgsProcessingOutputVectorLayer,
Expand All @@ -659,11 +667,14 @@ def createWidget(self):
else:
if self.parameterDefinition().layerType() == QgsProcessing.TypeRaster:
options = QgsProcessingUtils.compatibleRasterLayers(QgsProject.instance(), False)
elif self.parameterDefinition().layerType() == QgsProcessing.TypeMesh:
options = QgsProcessingUtils.compatibleMeshLayers(QgsProject.instance(), False)
elif self.parameterDefinition().layerType() in (QgsProcessing.TypeVectorAnyGeometry, QgsProcessing.TypeVector):
options = QgsProcessingUtils.compatibleVectorLayers(QgsProject.instance(), [], False)
elif self.parameterDefinition().layerType() == QgsProcessing.TypeMapLayer:
options = QgsProcessingUtils.compatibleVectorLayers(QgsProject.instance(), [], False)
options.extend(QgsProcessingUtils.compatibleRasterLayers(QgsProject.instance(), False))
options.extend(QgsProcessingUtils.compatibleMeshLayers(QgsProject.instance(), False))
else:
options = QgsProcessingUtils.compatibleVectorLayers(QgsProject.instance(), [self.parameterDefinition().layerType()],
False)
Expand All @@ -681,11 +692,14 @@ def refresh(self):
if self.parameterDefinition().layerType() != QgsProcessing.TypeFile:
if self.parameterDefinition().layerType() == QgsProcessing.TypeRaster:
options = QgsProcessingUtils.compatibleRasterLayers(QgsProject.instance(), False)
elif self.parameterDefinition().layerType() == QgsProcessing.TypeMesh:
options = QgsProcessingUtils.compatibleMeshLayers(QgsProject.instance(), False)
elif self.parameterDefinition().layerType() in (QgsProcessing.TypeVectorAnyGeometry, QgsProcessing.TypeVector):
options = QgsProcessingUtils.compatibleVectorLayers(QgsProject.instance(), [], False)
elif self.parameterDefinition().layerType() == QgsProcessing.TypeMapLayer:
options = QgsProcessingUtils.compatibleVectorLayers(QgsProject.instance(), [], False)
options.extend(QgsProcessingUtils.compatibleRasterLayers(QgsProject.instance(), False))
options.extend(QgsProcessingUtils.compatibleMeshLayers(QgsProject.instance(), False))
else:
options = QgsProcessingUtils.compatibleVectorLayers(QgsProject.instance(), [self.parameterDefinition().layerType()],
False)
Expand Down Expand Up @@ -724,11 +738,14 @@ def value(self):
else:
if self.parameterDefinition().layerType() == QgsProcessing.TypeRaster:
options = QgsProcessingUtils.compatibleRasterLayers(QgsProject.instance(), False)
elif self.parameterDefinition().layerType() == QgsProcessing.TypeMesh:
options = QgsProcessingUtils.compatibleMeshLayers(QgsProject.instance(), False)
elif self.parameterDefinition().layerType() in (QgsProcessing.TypeVectorAnyGeometry, QgsProcessing.TypeVector):
options = QgsProcessingUtils.compatibleVectorLayers(QgsProject.instance(), [], False)
elif self.parameterDefinition().layerType() == QgsProcessing.TypeMapLayer:
options = QgsProcessingUtils.compatibleVectorLayers(QgsProject.instance(), [], False)
options.extend(QgsProcessingUtils.compatibleRasterLayers(QgsProject.instance(), False))
options.extend(QgsProcessingUtils.compatibleMeshLayers(QgsProject.instance(), False))
else:
options = QgsProcessingUtils.compatibleVectorLayers(QgsProject.instance(), [self.parameterDefinition().layerType()],
False)
Expand Down Expand Up @@ -896,7 +913,7 @@ def setComboBoxFilters(self, combo):

def getAvailableLayers(self):
return self.dialog.getAvailableValuesOfType(
[QgsProcessingParameterRasterLayer, QgsProcessingParameterVectorLayer, QgsProcessingParameterMapLayer, QgsProcessingParameterString],
[QgsProcessingParameterRasterLayer, QgsProcessingParameterMeshLayer, QgsProcessingParameterVectorLayer, QgsProcessingParameterMapLayer, QgsProcessingParameterString],
[QgsProcessingOutputRasterLayer, QgsProcessingOutputVectorLayer, QgsProcessingOutputMapLayer, QgsProcessingOutputString, QgsProcessingOutputFile])

def selectFile(self):
Expand Down Expand Up @@ -986,6 +1003,22 @@ def selectFile(self):
self.widgetValueHasChanged.emit(self)


class MeshWidgetWrapper(MapLayerWidgetWrapper):

def getAvailableLayers(self):
return self.dialog.getAvailableValuesOfType((QgsProcessingParameterMeshLayer, QgsProcessingParameterString),
())

def setComboBoxFilters(self, combo):
combo.setFilters(QgsMapLayerProxyModel.MeshLayer)

def selectFile(self):
filename, selected_filter = self.getFileName(self.combo.currentText())
if filename:
self.combo.setEditText(filename)
self.widgetValueHasChanged.emit(self)


class EnumWidgetWrapper(WidgetWrapper):
NOT_SELECTED = '[Not selected]'

Expand Down Expand Up @@ -1856,6 +1889,8 @@ def create_wrapper_from_class(param, dialog, row=0, col=0):
wrapper = RangeWidgetWrapper
elif param.type() == 'matrix':
wrapper = FixedTableWidgetWrapper
elif param.type() == 'mesh':
wrapper = MeshWidgetWrapper
else:
assert False, param.type()
return wrapper(param, dialog, row, col)
3 changes: 3 additions & 0 deletions python/plugins/processing/tests/GuiTest.py
Expand Up @@ -237,6 +237,9 @@ def testRange(self):
def testMapLayer(self):
self.checkConstructWrapper(QgsProcessingParameterMapLayer('test'), MapLayerWidgetWrapper)

def testMeshLayer(self):
self.checkConstructWrapper(QgsProcessingParameterMeshLayer('test'), MeshWidgetWrapper)

def testDistance(self):
self.checkConstructWrapper(QgsProcessingParameterDistance('test'), DistanceWidgetWrapper)

Expand Down
4 changes: 4 additions & 0 deletions python/processing/algfactory.py
Expand Up @@ -54,6 +54,7 @@
QgsProcessingParameterPoint,
QgsProcessingParameterRange,
QgsProcessingParameterVectorLayer,
QgsProcessingParameterMeshLayer,
QgsProcessingOutputString,
QgsProcessingOutputFile,
QgsProcessingOutputFolder,
Expand Down Expand Up @@ -299,6 +300,7 @@ class ProcessingAlgFactory():
MULTILAYER = "MULTILAYER",
RASTER_LAYER = "RASTER_LAYER",
VECTOR_LAYER = "VECTOR_LAYER",
MESH_LAYER = "MESH_LAYER",
FILE_DEST = "FILE_DEST",
FOLDER_DEST = "FOLDER_DEST",
RASTER_LAYER_DEST = "RASTER_LAYER_DEST",
Expand Down Expand Up @@ -439,6 +441,7 @@ def input(self, type, *args, **kwargs):
alg.RANGE: QgsProcessingParameterRange
alg.VECTOR_LAYER: QgsProcessingParameterVectorLayer
alg.AUTH_CFG: QgsProcessingParameterAuthConfig
alg.MESH_LAYER: QgsProcessingParameterMeshLayer
:param type: The type of the input. This should be a type define on `alg` like alg.STRING, alg.DISTANCE
Expand Down Expand Up @@ -485,6 +488,7 @@ def dec(f):
ProcessingAlgFactory.RANGE: QgsProcessingParameterRange,
ProcessingAlgFactory.VECTOR_LAYER: QgsProcessingParameterVectorLayer,
ProcessingAlgFactory.AUTH_CFG: QgsProcessingParameterAuthConfig,
ProcessingAlgFactory.MESH_LAYER: QgsProcessingParameterMeshLayer,
}

output_type_mapping = {
Expand Down
5 changes: 2 additions & 3 deletions src/core/processing/qgsprocessing.h
Expand Up @@ -43,18 +43,17 @@ class CORE_EXPORT QgsProcessing
//! Data source types enum
enum SourceType
{
TypeMapLayer = -2, //!< Any map layer type (raster or vector)
TypeMapLayer = -2, //!< Any map layer type (raster or vector or mesh)
TypeVectorAnyGeometry = -1, //!< Any vector layer with geometry
TypeVectorPoint = 0, //!< Vector point layers
TypeVectorLine = 1, //!< Vector line layers
TypeVectorPolygon = 2, //!< Vector polygon layers
TypeRaster = 3, //!< Raster layers
TypeFile = 4, //!< Files (i.e. non map layer sources, such as text files)
TypeVector = 5, //!< Tables (i.e. vector layers with or without geometry). When used for a sink this indicates the sink has no geometry.
TypeMesh = 6 //!< Mesh layers \since QGIS 3.6
};



};

#endif // QGSPROCESSING_H
6 changes: 6 additions & 0 deletions src/core/processing/qgsprocessingalgorithm.cpp
Expand Up @@ -27,6 +27,7 @@
#include "qgsmessagelog.h"
#include "qgsvectorlayer.h"
#include "qgsprocessingfeedback.h"
#include "qgsmeshlayer.h"

QgsProcessingAlgorithm::~QgsProcessingAlgorithm()
{
Expand Down Expand Up @@ -611,6 +612,11 @@ QgsRasterLayer *QgsProcessingAlgorithm::parameterAsRasterLayer( const QVariantMa
return QgsProcessingParameters::parameterAsRasterLayer( parameterDefinition( name ), parameters, context );
}

QgsMeshLayer *QgsProcessingAlgorithm::parameterAsMeshLayer( const QVariantMap &parameters, const QString &name, QgsProcessingContext &context ) const
{
return QgsProcessingParameters::parameterAsMeshLayer( parameterDefinition( name ), parameters, context );
}

QString QgsProcessingAlgorithm::parameterAsOutputLayer( const QVariantMap &parameters, const QString &name, QgsProcessingContext &context ) const
{
return QgsProcessingParameters::parameterAsOutputLayer( parameterDefinition( name ), parameters, context );
Expand Down

0 comments on commit e716602

Please sign in to comment.