mirror of
https://github.com/qgis/QGIS.git
synced 2025-02-28 00:17:30 -05:00
Register meta type for geometry processing parameter
Fix QgsProcessingParameterGeometry argument list
This commit is contained in:
parent
aa0a8ab628
commit
6262965df9
@ -1574,7 +1574,7 @@ A geometry parameter for processing algorithms.
|
||||
%End
|
||||
public:
|
||||
|
||||
QgsProcessingParameterGeometry( const QString &name, const QString &description = QString(), const QVariant &defaultValue = QVariant(), bool optional = false, const QList<QgsWkbTypes::GeometryType> &geometryTypes = QList<QgsWkbTypes::GeometryType>() );
|
||||
QgsProcessingParameterGeometry( const QString &name, const QString &description = QString(), const QVariant &defaultValue = QVariant(), bool optional = false, const QList< int > &geometryTypes = QList< int >() );
|
||||
%Docstring
|
||||
Constructor for QgsProcessingParameterGeometry.
|
||||
|
||||
@ -1602,14 +1602,14 @@ Returns the type name for the parameter class.
|
||||
virtual bool fromVariantMap( const QVariantMap &map );
|
||||
|
||||
|
||||
QList<QgsWkbTypes::GeometryType> geometryTypes() const;
|
||||
QList<int> geometryTypes() const;
|
||||
%Docstring
|
||||
Returns the parameter allowed geometries.
|
||||
|
||||
.. seealso:: :py:func:`setGeometryTypes`
|
||||
%End
|
||||
|
||||
void setGeometryTypes( QList<QgsWkbTypes::GeometryType> geometryTypes );
|
||||
void setGeometryTypes( const QList<int> &geometryTypes );
|
||||
%Docstring
|
||||
Sets the allowed ``geometryTypes``.
|
||||
|
||||
|
@ -2951,7 +2951,7 @@ QgsProcessingParameterPoint *QgsProcessingParameterPoint::fromScriptCode( const
|
||||
}
|
||||
|
||||
QgsProcessingParameterGeometry::QgsProcessingParameterGeometry( const QString &name, const QString &description,
|
||||
const QVariant &defaultValue, bool optional, const QList<QgsWkbTypes::GeometryType> &geometryTypes )
|
||||
const QVariant &defaultValue, bool optional, const QList<int> &geometryTypes )
|
||||
: QgsProcessingParameterDefinition( name, description, defaultValue, optional ),
|
||||
mGeomTypes( geometryTypes )
|
||||
{
|
||||
@ -3099,9 +3099,9 @@ QString QgsProcessingParameterGeometry::asScriptCode() const
|
||||
code += QStringLiteral( "optional " );
|
||||
code += type() + ' ';
|
||||
|
||||
for ( QgsWkbTypes::GeometryType type : mGeomTypes )
|
||||
for ( int type : mGeomTypes )
|
||||
{
|
||||
switch ( type )
|
||||
switch ( static_cast<QgsWkbTypes::GeometryType>( type ) )
|
||||
{
|
||||
case QgsWkbTypes::PointGeometry:
|
||||
code += QStringLiteral( "point " );
|
||||
@ -3165,9 +3165,9 @@ QString QgsProcessingParameterGeometry::asPythonString( const QgsProcessing::Pyt
|
||||
|
||||
QStringList options;
|
||||
options.reserve( mGeomTypes.size() );
|
||||
for ( QgsWkbTypes::GeometryType type : mGeomTypes )
|
||||
for ( int type : mGeomTypes )
|
||||
{
|
||||
options << QStringLiteral( " QgsWkbTypes.%1" ).arg( geomTypeToString( type ) );
|
||||
options << QStringLiteral( " QgsWkbTypes.%1" ).arg( geomTypeToString( static_cast<QgsWkbTypes::GeometryType>( type ) ) );
|
||||
}
|
||||
code += QStringLiteral( ", geometryTypes=[%1 ]" ).arg( options.join( ',' ) );
|
||||
}
|
||||
@ -3184,7 +3184,7 @@ QVariantMap QgsProcessingParameterGeometry::toVariantMap() const
|
||||
{
|
||||
QVariantMap map = QgsProcessingParameterDefinition::toVariantMap();
|
||||
QVariantList types;
|
||||
for ( QgsWkbTypes::GeometryType type : mGeomTypes )
|
||||
for ( int type : mGeomTypes )
|
||||
{
|
||||
types << type;
|
||||
}
|
||||
@ -3199,7 +3199,7 @@ bool QgsProcessingParameterGeometry::fromVariantMap( const QVariantMap &map )
|
||||
const QVariantList values = map.value( QStringLiteral( "geometrytypes" ) ).toList();
|
||||
for ( const QVariant &val : values )
|
||||
{
|
||||
mGeomTypes << static_cast<QgsWkbTypes::GeometryType>( val.toInt() );
|
||||
mGeomTypes << val.toInt();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
@ -1616,7 +1616,7 @@ class CORE_EXPORT QgsProcessingParameterGeometry : public QgsProcessingParameter
|
||||
* The \a geometryTypes argument allows for specifying a list of geometry types acceptable for this
|
||||
* parameter. Passing a empty list will allow for any type of geometry.
|
||||
*/
|
||||
QgsProcessingParameterGeometry( const QString &name, const QString &description = QString(), const QVariant &defaultValue = QVariant(), bool optional = false, const QList<QgsWkbTypes::GeometryType> &geometryTypes = QList<QgsWkbTypes::GeometryType>() );
|
||||
QgsProcessingParameterGeometry( const QString &name, const QString &description = QString(), const QVariant &defaultValue = QVariant(), bool optional = false, const QList< int > &geometryTypes = QList< int >() );
|
||||
|
||||
/**
|
||||
* Returns the type name for the parameter class.
|
||||
@ -1635,13 +1635,13 @@ class CORE_EXPORT QgsProcessingParameterGeometry : public QgsProcessingParameter
|
||||
* Returns the parameter allowed geometries.
|
||||
* \see setGeometryTypes()
|
||||
*/
|
||||
QList<QgsWkbTypes::GeometryType> geometryTypes() const { return mGeomTypes; }
|
||||
QList<int> geometryTypes() const { return mGeomTypes; }
|
||||
|
||||
/**
|
||||
* Sets the allowed \a geometryTypes.
|
||||
* \see geometryTypes()
|
||||
*/
|
||||
void setGeometryTypes( QList<QgsWkbTypes::GeometryType> geometryTypes ) { mGeomTypes = geometryTypes; }
|
||||
void setGeometryTypes( const QList<int> &geometryTypes ) { mGeomTypes = geometryTypes; }
|
||||
|
||||
/**
|
||||
* Creates a new parameter using the definition from a script code.
|
||||
@ -1650,7 +1650,7 @@ class CORE_EXPORT QgsProcessingParameterGeometry : public QgsProcessingParameter
|
||||
|
||||
private:
|
||||
|
||||
QList<QgsWkbTypes::GeometryType> mGeomTypes;
|
||||
QList<int> mGeomTypes;
|
||||
|
||||
};
|
||||
|
||||
|
@ -224,6 +224,7 @@ void QgsApplication::init( QString profileFolder )
|
||||
qRegisterMetaType<Qgis::MessageLevel>( "Qgis::MessageLevel" );
|
||||
qRegisterMetaType<QgsReferencedRectangle>( "QgsReferencedRectangle" );
|
||||
qRegisterMetaType<QgsReferencedPointXY>( "QgsReferencedPointXY" );
|
||||
qRegisterMetaType<QgsReferencedGeometry>( "QgsReferencedGeometry" );
|
||||
qRegisterMetaType<QgsLayoutRenderContext::Flags>( "QgsLayoutRenderContext::Flags" );
|
||||
qRegisterMetaType<QgsStyle::StyleEntity>( "QgsStyle::StyleEntity" );
|
||||
qRegisterMetaType<QgsCoordinateReferenceSystem>( "QgsCoordinateReferenceSystem" );
|
||||
|
@ -207,6 +207,7 @@ ADD_PYTHON_TEST(PyQgsProcessingRecentAlgorithmLog test_qgsprocessingrecentalgori
|
||||
ADD_PYTHON_TEST(PyQgsProcessingInPlace test_qgsprocessinginplace.py)
|
||||
ADD_PYTHON_TEST(PyQgsProcessingAlgRunner test_qgsprocessingalgrunner.py)
|
||||
ADD_PYTHON_TEST(PyQgsProcessingAlgDecorator test_processing_alg_decorator.py)
|
||||
ADD_PYTHON_TEST(PyQgsProcessingParameters test_qgsprocessingparameters.py)
|
||||
ADD_PYTHON_TEST(PyQgsImportIntoPostGIS test_processing_importintopostgis.py)
|
||||
ADD_PYTHON_TEST(PyQgsProjectionSelectionWidgets test_qgsprojectionselectionwidgets.py)
|
||||
ADD_PYTHON_TEST(PyQgsProjectMetadata test_qgsprojectmetadata.py)
|
||||
|
63
tests/src/python/test_qgsprocessingparameters.py
Normal file
63
tests/src/python/test_qgsprocessingparameters.py
Normal file
@ -0,0 +1,63 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
"""QGIS Unit tests for Processing algorithm runner(s).
|
||||
|
||||
.. note:: 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__ = 'David Marteau'
|
||||
__date__ = '2020-09'
|
||||
__copyright__ = 'Copyright 2020, The QGIS Project'
|
||||
|
||||
import re
|
||||
from qgis.PyQt.QtCore import QCoreApplication
|
||||
from qgis.testing import start_app, unittest
|
||||
from qgis.core import QgsProcessingAlgRunnerTask
|
||||
|
||||
from processing.core.Processing import Processing
|
||||
from processing.core.ProcessingConfig import ProcessingConfig
|
||||
from qgis.testing import start_app, unittest
|
||||
from qgis.core import (
|
||||
QgsApplication,
|
||||
QgsSettings,
|
||||
QgsProcessingContext,
|
||||
QgsProcessingAlgRunnerTask,
|
||||
QgsProcessingAlgorithm,
|
||||
QgsProject,
|
||||
QgsProcessingFeedback,
|
||||
QgsProcessingParameterGeometry,
|
||||
QgsWkbTypes,
|
||||
)
|
||||
|
||||
start_app()
|
||||
|
||||
|
||||
|
||||
class TestQgsProcessingParameters(unittest.TestCase):
|
||||
|
||||
@classmethod
|
||||
def setUpClass(cls):
|
||||
"""Run before all tests"""
|
||||
QCoreApplication.setOrganizationName("QGIS_Test")
|
||||
QCoreApplication.setOrganizationDomain(
|
||||
"QGIS_TestPyQgsProcessingParameters.com")
|
||||
QCoreApplication.setApplicationName("QGIS_TestPyQgsProcessingParameters")
|
||||
QgsSettings().clear()
|
||||
Processing.initialize()
|
||||
cls.registry = QgsApplication.instance().processingRegistry()
|
||||
|
||||
def test_qgsprocessinggometry(self): # spellok
|
||||
""" Test QgsProcessingParameterGeometry initialisation
|
||||
"""
|
||||
geomtypes = [QgsWkbTypes.PointGeometry, QgsWkbTypes.PolygonGeometry]
|
||||
param = QgsProcessingParameterGeometry( name='test', geometryTypes=geomtypes)
|
||||
|
||||
types = param.geometryTypes()
|
||||
|
||||
self.assertEqual( param.geometryTypes(), geomtypes)
|
||||
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
Loading…
x
Reference in New Issue
Block a user