@@ -1747,6 +1747,8 @@ QgsProcessingParameterDefinition *QgsProcessingParameters::parameterFromVariantM
1747
1747
def.reset ( new QgsProcessingParameterLayoutItem ( name ) );
1748
1748
else if ( type == QgsProcessingParameterColor::typeName () )
1749
1749
def.reset ( new QgsProcessingParameterColor ( name ) );
1750
+ else if ( type == QgsProcessingParameterCoordinateOperation::typeName () )
1751
+ def.reset ( new QgsProcessingParameterCoordinateOperation ( name ) );
1750
1752
else
1751
1753
{
1752
1754
QgsProcessingParameterType *paramType = QgsApplication::instance ()->processingRegistry ()->parameterType ( type );
@@ -1841,6 +1843,8 @@ QgsProcessingParameterDefinition *QgsProcessingParameters::parameterFromScriptCo
1841
1843
return QgsProcessingParameterLayoutItem::fromScriptCode ( name, description, isOptional, definition );
1842
1844
else if ( type == QStringLiteral ( " color" ) )
1843
1845
return QgsProcessingParameterColor::fromScriptCode ( name, description, isOptional, definition );
1846
+ else if ( type == QStringLiteral ( " coordinateoperation" ) )
1847
+ return QgsProcessingParameterCoordinateOperation::fromScriptCode ( name, description, isOptional, definition );
1844
1848
1845
1849
return nullptr ;
1846
1850
}
@@ -5923,3 +5927,121 @@ QgsProcessingParameterColor *QgsProcessingParameterColor::fromScriptCode( const
5923
5927
5924
5928
return new QgsProcessingParameterColor ( name, description, defaultValue, allowOpacity, isOptional );
5925
5929
}
5930
+
5931
+ //
5932
+ // QgsProcessingParameterCoordinateOperation
5933
+ //
5934
+ QgsProcessingParameterCoordinateOperation::QgsProcessingParameterCoordinateOperation ( const QString &name, const QString &description, const QVariant &defaultValue, const QString &sourceCrsParameterName, const QString &destinationCrsParameterName, const QVariant &staticSourceCrs, const QVariant &staticDestinationCrs, bool optional )
5935
+ : QgsProcessingParameterDefinition( name, description, defaultValue, optional )
5936
+ , mSourceParameterName( sourceCrsParameterName )
5937
+ , mDestParameterName( destinationCrsParameterName )
5938
+ , mSourceCrs( staticSourceCrs )
5939
+ , mDestCrs( staticDestinationCrs )
5940
+ {
5941
+
5942
+ }
5943
+
5944
+ QgsProcessingParameterDefinition *QgsProcessingParameterCoordinateOperation::clone () const
5945
+ {
5946
+ return new QgsProcessingParameterCoordinateOperation ( * this );
5947
+ }
5948
+
5949
+ QString QgsProcessingParameterCoordinateOperation::valueAsPythonString ( const QVariant &value, QgsProcessingContext &context ) const
5950
+ {
5951
+ if ( !value.isValid () || value.isNull () )
5952
+ return QStringLiteral ( " None" );
5953
+
5954
+ if ( value.canConvert <QgsCoordinateReferenceSystem>() )
5955
+ {
5956
+ if ( !value.value < QgsCoordinateReferenceSystem >().isValid () )
5957
+ return QStringLiteral ( " QgsCoordinateReferenceSystem()" );
5958
+ else
5959
+ return QStringLiteral ( " QgsCoordinateReferenceSystem('%1')" ).arg ( value.value < QgsCoordinateReferenceSystem >().authid () );
5960
+ }
5961
+
5962
+ if ( value.canConvert <QgsProperty>() )
5963
+ return QStringLiteral ( " QgsProperty.fromExpression('%1')" ).arg ( value.value < QgsProperty >().asExpression () );
5964
+
5965
+ QVariantMap p;
5966
+ p.insert ( name (), value );
5967
+ QgsMapLayer *layer = QgsProcessingParameters::parameterAsLayer ( this , p, context );
5968
+ if ( layer )
5969
+ return QgsProcessingUtils::stringToPythonLiteral ( QgsProcessingUtils::normalizeLayerSource ( layer->source () ) );
5970
+
5971
+ QString s = value.toString ();
5972
+ return QgsProcessingUtils::stringToPythonLiteral ( s );
5973
+ }
5974
+
5975
+ QString QgsProcessingParameterCoordinateOperation::asScriptCode () const
5976
+ {
5977
+ QString code = QStringLiteral ( " ##%1=" ).arg ( mName );
5978
+ if ( mFlags & FlagOptional )
5979
+ code += QStringLiteral ( " optional " );
5980
+ code += QStringLiteral ( " coordinateoperation " );
5981
+
5982
+ code += mDefault .toString ();
5983
+ return code.trimmed ();
5984
+ }
5985
+
5986
+ QString QgsProcessingParameterCoordinateOperation::asPythonString ( QgsProcessing::PythonOutputType outputType ) const
5987
+ {
5988
+ switch ( outputType )
5989
+ {
5990
+ case QgsProcessing::PythonQgsProcessingAlgorithmSubclass:
5991
+ {
5992
+ QgsProcessingContext c;
5993
+ QString code = QStringLiteral ( " QgsProcessingParameterCoordinateOperation('%1', '%2'" ).arg ( name (), description () );
5994
+ if ( mFlags & FlagOptional )
5995
+ code += QStringLiteral ( " , optional=True" );
5996
+ if ( !mSourceParameterName .isEmpty () )
5997
+ code += QStringLiteral ( " , sourceCrsParameterName=%1" ).arg ( valueAsPythonString ( mSourceParameterName , c ) );
5998
+ if ( !mDestParameterName .isEmpty () )
5999
+ code += QStringLiteral ( " , destinationCrsParameterName=%1" ).arg ( valueAsPythonString ( mDestParameterName , c ) );
6000
+
6001
+ if ( mSourceCrs .isValid () )
6002
+ code += QStringLiteral ( " , staticSourceCrs=%1" ).arg ( valueAsPythonString ( mSourceCrs , c ) );
6003
+ if ( mDestCrs .isValid () )
6004
+ code += QStringLiteral ( " , staticDestinationCrs=%1" ).arg ( valueAsPythonString ( mDestCrs , c ) );
6005
+
6006
+ code += QStringLiteral ( " , defaultValue=%1)" ).arg ( valueAsPythonString ( mDefault , c ) );
6007
+ return code;
6008
+ }
6009
+ }
6010
+ return QString ();
6011
+ }
6012
+
6013
+ QVariantMap QgsProcessingParameterCoordinateOperation::toVariantMap () const
6014
+ {
6015
+ QVariantMap map = QgsProcessingParameterDefinition::toVariantMap ();
6016
+ map.insert ( QStringLiteral ( " source_crs_parameter_name" ), mSourceParameterName );
6017
+ map.insert ( QStringLiteral ( " dest_crs_parameter_name" ), mDestParameterName );
6018
+ map.insert ( QStringLiteral ( " static_source_crs" ), mSourceCrs );
6019
+ map.insert ( QStringLiteral ( " static_dest_crs" ), mDestCrs );
6020
+ return map;
6021
+ }
6022
+
6023
+ bool QgsProcessingParameterCoordinateOperation::fromVariantMap ( const QVariantMap &map )
6024
+ {
6025
+ QgsProcessingParameterDefinition::fromVariantMap ( map );
6026
+ mSourceParameterName = map.value ( QStringLiteral ( " source_crs_parameter_name" ) ).toString ();
6027
+ mDestParameterName = map.value ( QStringLiteral ( " dest_crs_parameter_name" ) ).toString ();
6028
+ mSourceCrs = map.value ( QStringLiteral ( " static_source_crs" ) );
6029
+ mDestCrs = map.value ( QStringLiteral ( " static_dest_crs" ) );
6030
+ return true ;
6031
+ }
6032
+
6033
+ QgsProcessingParameterCoordinateOperation *QgsProcessingParameterCoordinateOperation::fromScriptCode ( const QString &name, const QString &description, bool isOptional, const QString &definition )
6034
+ {
6035
+ QString def = definition;
6036
+
6037
+ if ( def.startsWith ( ' "' ) || def.startsWith ( ' \' ' ) )
6038
+ def = def.mid ( 1 );
6039
+ if ( def.endsWith ( ' "' ) || def.endsWith ( ' \' ' ) )
6040
+ def.chop ( 1 );
6041
+
6042
+ QVariant defaultValue = def;
6043
+ if ( def == QStringLiteral ( " None" ) )
6044
+ defaultValue = QVariant ();
6045
+
6046
+ return new QgsProcessingParameterCoordinateOperation ( name, description, defaultValue, QString (), QString (), QVariant (), QVariant (), isOptional );
6047
+ }
0 commit comments