41#include <QRegularExpression>
49 map.insert( QStringLiteral(
"feature_limit" ),
featureLimit );
50 map.insert( QStringLiteral(
"flags" ),
static_cast< int >(
flags ) );
51 map.insert( QStringLiteral(
"geometry_check" ),
static_cast< int >(
geometryCheck ) );
59 featureLimit = map.value( QStringLiteral(
"feature_limit" ), -1 ).toLongLong();
60 flags =
static_cast< Flags
>( map.value( QStringLiteral(
"flags" ), 0 ).toInt() );
73 mRemappingDefinition = definition;
80 map.insert( QStringLiteral(
"create_options" ),
createOptions );
82 map.insert( QStringLiteral(
"remapping" ), QVariant::fromValue( mRemappingDefinition ) );
89 createOptions = map.value( QStringLiteral(
"create_options" ) ).toMap();
90 if ( map.contains( QStringLiteral(
"remapping" ) ) )
97 mUseRemapping =
false;
105 && mUseRemapping == other.mUseRemapping && mRemappingDefinition == other.mRemappingDefinition;
110 return !( *
this == other );
115 const QVariant val = parameters.value( name );
116 if ( val.userType() == QMetaType::type(
"QgsProperty" ) )
135 QVariant val = value;
136 if ( val.userType() == QMetaType::type(
"QgsProperty" ) )
139 if ( !val.isValid() )
148 return destParam->generateTemporaryDestination();
151 return val.toString();
167 const QVariant val = value;
168 if ( val.userType() == QMetaType::type(
"QgsProperty" ) )
171 if ( val.isValid() && !val.toString().isEmpty() )
175 return val.toString();
195 QVariant val = value;
196 if ( val.userType() == QMetaType::type(
"QgsProperty" ) )
200 const double res = val.toDouble( &ok );
206 return val.toDouble();
222 QVariant val = value;
223 if ( val.userType() == QMetaType::type(
"QgsProperty" ) )
227 double dbl = val.toDouble( &ok );
232 dbl = val.toDouble( &ok );
239 const double round = std::round( dbl );
240 if ( round > std::numeric_limits<int>::max() || round < -std::numeric_limits<int>::max() )
245 return static_cast< int >( std::round( dbl ) );
254 return QList< int >();
262 return QList< int >();
264 QList< int > resultList;
265 const QVariant val = value;
268 if ( val.userType() == QMetaType::type(
"QgsProperty" ) )
270 else if ( val.type() == QVariant::List )
272 const QVariantList list = val.toList();
273 for (
auto it = list.constBegin(); it != list.constEnd(); ++it )
274 resultList << it->toInt();
278 const QStringList parts = val.toString().split(
';' );
279 for (
auto it = parts.constBegin(); it != parts.constEnd(); ++it )
280 resultList << it->toInt();
284 if ( resultList.isEmpty() )
289 if ( definition->
defaultValue().type() == QVariant::List )
291 const QVariantList list = definition->
defaultValue().toList();
292 for (
auto it = list.constBegin(); it != list.constEnd(); ++it )
293 resultList << it->toInt();
297 const QStringList parts = definition->
defaultValue().toString().split(
';' );
298 for (
auto it = parts.constBegin(); it != parts.constEnd(); ++it )
299 resultList << it->toInt();
320 QVariant val = value;
321 if ( val.userType() == QMetaType::type(
"QgsProperty" ) )
324 QDateTime d = val.toDateTime();
325 if ( !d.isValid() && val.type() == QVariant::String )
327 d = QDateTime::fromString( val.toString() );
334 d = val.toDateTime();
336 if ( !d.isValid() && val.type() == QVariant::String )
338 d = QDateTime::fromString( val.toString() );
357 QVariant val = value;
358 if ( val.userType() == QMetaType::type(
"QgsProperty" ) )
361 QDate d = val.toDate();
362 if ( !d.isValid() && val.type() == QVariant::String )
364 d = QDate::fromString( val.toString() );
373 if ( !d.isValid() && val.type() == QVariant::String )
375 d = QDate::fromString( val.toString() );
394 QVariant val = value;
395 if ( val.userType() == QMetaType::type(
"QgsProperty" ) )
400 if ( val.type() == QVariant::DateTime )
401 d = val.toDateTime().time();
405 if ( !d.isValid() && val.type() == QVariant::String )
407 d = QTime::fromString( val.toString() );
416 if ( !d.isValid() && val.type() == QVariant::String )
418 d = QTime::fromString( val.toString() );
439 if ( enumDef && val >= enumDef->
options().size() )
459 QVariantList resultList;
460 const QVariant val = value;
461 if ( val.userType() == QMetaType::type(
"QgsProperty" ) )
463 else if ( val.type() == QVariant::List )
465 const auto constToList = val.toList();
466 for (
const QVariant &var : constToList )
469 else if ( val.type() == QVariant::String )
471 const auto constSplit = val.toString().split(
',' );
472 for (
const QString &var : constSplit )
478 if ( resultList.isEmpty() )
479 return QList< int >();
481 if ( ( !val.isValid() || !resultList.at( 0 ).isValid() ) && definition )
485 if ( definition->
defaultValue().type() == QVariant::List )
487 const auto constToList = definition->
defaultValue().toList();
488 for (
const QVariant &var : constToList )
491 else if ( definition->
defaultValue().type() == QVariant::String )
493 const auto constSplit = definition->
defaultValue().toString().split(
',' );
494 for (
const QString &var : constSplit )
503 const auto constResultList = resultList;
504 for (
const QVariant &var : constResultList )
506 const int resInt = var.toInt();
507 if ( !enumDef || resInt < enumDef->options().size() )
530 if ( enumText.isEmpty() || !enumDef->
options().contains( enumText ) )
539 return QStringList();
547 return QStringList();
549 const QVariant val = value;
551 QStringList enumValues;
553 std::function< void(
const QVariant &var ) > processVariant;
554 processVariant = [ &enumValues, &context, &definition, &processVariant ](
const QVariant & var )
556 if ( var.type() == QVariant::List )
558 const auto constToList = var.toList();
559 for (
const QVariant &listVar : constToList )
561 processVariant( listVar );
564 else if ( var.type() == QVariant::StringList )
566 const auto constToStringList = var.toStringList();
567 for (
const QString &s : constToStringList )
572 else if ( var.userType() == QMetaType::type(
"QgsProperty" ) )
576 const QStringList parts = var.toString().split(
',' );
577 for (
const QString &s : parts )
584 processVariant( val );
590 const QStringList options = enumDef->
options();
591 const QSet<QString> subtraction = QSet<QString>( enumValues.begin(), enumValues.end() ).subtract( QSet<QString>( options.begin(), options.end() ) );
593 if ( enumValues.isEmpty() || !subtraction.isEmpty() )
625 const QVariant val = value;
626 if ( val.userType() == QMetaType::type(
"QgsProperty" ) )
628 else if ( val.isValid() )
641 const QVariant val = value;
642 if ( val.userType() == QMetaType::type(
"QgsProperty" ) )
644 else if ( val.isValid() )
652 QgsProcessingContext &context, QString &destinationIdentifier, QgsFeatureSink::SinkFlags sinkFlags,
653 const QVariantMap &createOptions,
const QStringList &datasourceOptions,
const QStringList &layerOptions )
658 val = parameters.value( definition->
name() );
661 return parameterAsSink( definition, val, fields, geometryType,
crs, context, destinationIdentifier, sinkFlags, createOptions, datasourceOptions, layerOptions );
664QgsFeatureSink *
QgsProcessingParameters::parameterAsSink(
const QgsProcessingParameterDefinition *definition,
const QVariant &value,
const QgsFields &fields,
QgsWkbTypes::Type geometryType,
const QgsCoordinateReferenceSystem &
crs,
QgsProcessingContext &context, QString &destinationIdentifier, QgsFeatureSink::SinkFlags sinkFlags,
const QVariantMap &createOptions,
const QStringList &datasourceOptions,
const QStringList &layerOptions )
666 QVariantMap options = createOptions;
667 QVariant val = value;
672 bool useRemapDefinition =
false;
673 if ( val.userType() == QMetaType::type(
"QgsProcessingOutputLayerDefinition" ) )
684 useRemapDefinition =
true;
690 if ( definition && val.userType() == QMetaType::type(
"QgsProperty" ) )
694 else if ( !val.isValid() || val.toString().isEmpty() )
710 dest = val.toString();
715 dest = destParam->generateTemporaryDestination();
718 if ( dest.isEmpty() )
721 std::unique_ptr< QgsFeatureSink > sink(
QgsProcessingUtils::createFeatureSink( dest, context, fields, geometryType,
crs, options, datasourceOptions, layerOptions, sinkFlags, useRemapDefinition ? &remapDefinition :
nullptr ) );
722 destinationIdentifier = dest;
724 if ( destinationProject )
726 if ( destName.isEmpty() && definition )
732 outputName = definition->
name();
736 return sink.release();
760 QVariant val = parameters.value( definition->
name() );
762 bool selectedFeaturesOnly =
false;
763 long long featureLimit = -1;
764 if ( val.userType() == QMetaType::type(
"QgsProcessingFeatureSourceDefinition" ) )
772 else if ( val.userType() == QMetaType::type(
"QgsProcessingOutputLayerDefinition" ) )
779 if ( val.userType() == QMetaType::type(
"QgsProperty" ) )
785 vl = qobject_cast< QgsVectorLayer * >( qvariant_cast<QObject *>( val ) );
790 if ( val.userType() == QMetaType::type(
"QgsProperty" ) )
794 else if ( !val.isValid() || val.toString().isEmpty() )
800 vl = qobject_cast< QgsVectorLayer * >( qvariant_cast<QObject *>( val ) );
806 layerRef = val.toString();
811 if ( layerRef.isEmpty() )
823 compatibleFormats, preferredFormat, context, feedback, *layerName, featureLimit );
826 compatibleFormats, preferredFormat, context, feedback, featureLimit );
836 QString *destLayer = layerName;
851 return parameterAsLayer( definition, parameters.value( definition->
name() ), context, layerHint );
859 QVariant val = value;
860 if ( val.userType() == QMetaType::type(
"QgsProperty" ) )
865 if (
QgsMapLayer *layer = qobject_cast< QgsMapLayer * >( qvariant_cast<QObject *>( val ) ) )
870 if ( val.userType() == QMetaType::type(
"QgsProcessingOutputLayerDefinition" ) )
882 if ( !val.isValid() || val.toString().isEmpty() )
888 if (
QgsMapLayer *layer = qobject_cast< QgsMapLayer * >( qvariant_cast<QObject *>( val ) ) )
893 QString layerRef = val.toString();
894 if ( layerRef.isEmpty() )
897 if ( layerRef.isEmpty() )
928 val = parameters.value( definition->
name() );
935 QVariant val = value;
939 if ( val.userType() == QMetaType::type(
"QgsProcessingOutputLayerDefinition" ) )
949 if ( definition && val.userType() == QMetaType::type(
"QgsProperty" ) )
953 else if ( definition && ( !val.isValid() || val.toString().isEmpty() ) )
960 dest = val.toString();
965 dest = destParam->generateTemporaryDestination();
968 if ( destinationProject )
971 if ( destName.isEmpty() && definition )
976 outputName = definition->
name();
997 val = parameters.value( definition->
name() );
1004 QVariant val = value;
1006 if ( val.userType() == QMetaType::type(
"QgsProcessingOutputLayerDefinition" ) )
1014 if ( definition && val.userType() == QMetaType::type(
"QgsProperty" ) )
1018 else if ( definition && ( !val.isValid() || val.toString().isEmpty() ) )
1025 dest = val.toString();
1030 dest = destParam->generateTemporaryDestination();
1050 return parameterAsCrs( definition, parameters.value( definition->
name() ), context );
1075 QVariant val = value;
1077 if ( val.userType() == QMetaType::type(
"QgsRectangle" ) )
1081 if ( val.userType() == QMetaType::type(
"QgsGeometry" ) )
1087 if ( val.userType() == QMetaType::type(
"QgsReferencedRectangle" ) )
1106 if ( val.userType() == QMetaType::type(
"QgsProcessingFeatureSourceDefinition" ) )
1112 else if ( val.userType() == QMetaType::type(
"QgsProcessingOutputLayerDefinition" ) )
1125 QgsMapLayer *layer = qobject_cast< QgsMapLayer * >( qvariant_cast<QObject *>( val ) );
1128 if ( val.userType() == QMetaType::type(
"QgsProperty" ) )
1131 rectText = val.toString();
1133 if ( rectText.isEmpty() && !layer )
1136 const QRegularExpression rx( QStringLiteral(
"^(.*?)\\s*,\\s*(.*?),\\s*(.*?),\\s*(.*?)\\s*(?:\\[(.*)\\])?\\s*$" ) );
1137 const QRegularExpressionMatch match = rx.match( rectText );
1138 if ( match.hasMatch() )
1140 bool xMinOk =
false;
1141 const double xMin = match.captured( 1 ).toDouble( &xMinOk );
1142 bool xMaxOk =
false;
1143 const double xMax = match.captured( 2 ).toDouble( &xMaxOk );
1144 bool yMinOk =
false;
1145 const double yMin = match.captured( 3 ).toDouble( &yMinOk );
1146 bool yMaxOk =
false;
1147 const double yMax = match.captured( 4 ).toDouble( &yMaxOk );
1148 if ( xMinOk && xMaxOk && yMinOk && yMaxOk )
1199 QVariant val = parameters.value( definition->
name() );
1201 if ( val.userType() == QMetaType::type(
"QgsReferencedRectangle" ) )
1207 g = g.densifyByCount( 20 );
1221 if ( val.userType() == QMetaType::type(
"QgsProcessingFeatureSourceDefinition" ) )
1227 else if ( val.userType() == QMetaType::type(
"QgsProcessingOutputLayerDefinition" ) )
1240 if ( val.userType() == QMetaType::type(
"QgsProperty" ) )
1243 rectText = val.toString();
1245 if ( !rectText.isEmpty() )
1247 const QRegularExpression rx( QStringLiteral(
"^(.*?)\\s*,\\s*(.*?),\\s*(.*?),\\s*(.*?)\\s*(?:\\[(.*)\\])?\\s*$" ) );
1248 const QRegularExpressionMatch match = rx.match( rectText );
1249 if ( match.hasMatch() )
1251 bool xMinOk =
false;
1252 const double xMin = match.captured( 1 ).toDouble( &xMinOk );
1253 bool xMaxOk =
false;
1254 const double xMax = match.captured( 2 ).toDouble( &xMaxOk );
1255 bool yMinOk =
false;
1256 const double yMin = match.captured( 3 ).toDouble( &yMinOk );
1257 bool yMaxOk =
false;
1258 const double yMax = match.captured( 4 ).toDouble( &yMaxOk );
1259 if ( xMinOk && xMaxOk && yMinOk && yMaxOk )
1285 QgsMapLayer *layer = qobject_cast< QgsMapLayer * >( qvariant_cast<QObject *>( val ) );
1314 const QVariant val = parameters.value( definition->
name() );
1320 QVariant val = value;
1321 if ( val.userType() == QMetaType::type(
"QgsReferencedRectangle" ) )
1330 if ( val.userType() == QMetaType::type(
"QgsProcessingFeatureSourceDefinition" ) )
1336 else if ( val.userType() == QMetaType::type(
"QgsProcessingOutputLayerDefinition" ) )
1348 QString valueAsString;
1349 if ( val.userType() == QMetaType::type(
"QgsProperty" ) )
1352 valueAsString = val.toString();
1354 const QRegularExpression rx( QStringLiteral(
"^(.*?)\\s*,\\s*(.*?),\\s*(.*?),\\s*(.*?)\\s*(?:\\[(.*)\\])?\\s*$" ) );
1356 const QRegularExpressionMatch match = rx.match( valueAsString );
1357 if ( match.hasMatch() )
1364 if ( val.userType() == QMetaType::type(
"QgsProcessingFeatureSourceDefinition" ) )
1370 else if ( val.userType() == QMetaType::type(
"QgsProcessingOutputLayerDefinition" ) )
1383 if (
QgsMapLayer *layer = qobject_cast< QgsMapLayer * >( qvariant_cast<QObject *>( val ) ) )
1384 return layer->crs();
1386 return layer->crs();
1388 if (
auto *lProject = context.
project() )
1389 return lProject->crs();
1407 const QVariant val = value;
1408 if ( val.userType() == QMetaType::type(
"QgsPointXY" ) )
1412 if ( val.userType() == QMetaType::type(
"QgsGeometry" ) )
1418 if ( val.userType() == QMetaType::type(
"QgsReferencedPointXY" ) )
1437 if ( pointText.isEmpty() )
1440 if ( pointText.isEmpty() )
1443 const QRegularExpression rx( QStringLiteral(
"^\\s*\\(?\\s*(.*?)\\s*,\\s*(.*?)\\s*(?:\\[(.*)\\])?\\s*\\)?\\s*$" ) );
1446 const QRegularExpressionMatch match = rx.match( valueAsString );
1447 if ( match.hasMatch() )
1450 const double x = match.captured( 1 ).toDouble( &xOk );
1452 const double y = match.captured( 2 ).toDouble( &yOk );
1480 const QVariant val = parameters.value( definition->
name() );
1486 if ( value.userType() == QMetaType::type(
"QgsReferencedPointXY" ) )
1495 const QRegularExpression rx( QStringLiteral(
"^\\s*\\(?\\s*(.*?)\\s*,\\s*(.*?)\\s*(?:\\[(.*)\\])?\\s*\\)?\\s*$" ) );
1498 const QRegularExpressionMatch match = rx.match( valueAsString );
1499 if ( match.hasMatch() )
1506 if (
auto *lProject = context.
project() )
1507 return lProject->crs();
1525 const QVariant val = value;
1526 if ( val.userType() == QMetaType::type(
"QgsGeometry" ) )
1531 if ( val.userType() == QMetaType::type(
"QgsPointXY" ) )
1536 if ( val.userType() == QMetaType::type(
"QgsRectangle" ) )
1541 if ( val.userType() == QMetaType::type(
"QgsReferencedPointXY" ) )
1559 if ( val.userType() == QMetaType::type(
"QgsReferencedRectangle" ) )
1565 g = g.densifyByCount( 20 );
1579 if ( val.userType() == QMetaType::type(
"QgsReferencedGeometry" ) )
1598 if ( valueAsString.isEmpty() )
1601 if ( valueAsString.isEmpty() )
1604 const QRegularExpression rx( QStringLiteral(
"^\\s*(?:CRS=(.*);)?(.*?)$" ) );
1606 const QRegularExpressionMatch match = rx.match( valueAsString );
1607 if ( match.hasMatch() )
1634 const QVariant val = parameters.value( definition->
name() );
1640 if ( value.userType() == QMetaType::type(
"QgsReferencedGeometry" ) )
1649 if ( value.userType() == QMetaType::type(
"QgsReferencedPointXY" ) )
1658 if ( value.userType() == QMetaType::type(
"QgsReferencedRectangle" ) )
1668 const QRegularExpression rx( QStringLiteral(
"^\\s*(?:CRS=(.*);)?(.*?)$" ) );
1671 const QRegularExpressionMatch match = rx.match( valueAsString );
1672 if ( match.hasMatch() )
1679 if (
auto *lProject = context.
project() )
1680 return lProject->crs();
1691 if ( fileText.isEmpty() )
1702 if ( fileText.isEmpty() )
1710 return QVariantList();
1718 return QVariantList();
1720 QString resultString;
1721 const QVariant val = value;
1722 if ( val.userType() == QMetaType::type(
"QgsProperty" ) )
1724 else if ( val.type() == QVariant::List )
1725 return val.toList();
1727 resultString = val.toString();
1729 if ( resultString.isEmpty() )
1732 if ( definition->
defaultValue().type() == QVariant::List )
1738 QVariantList result;
1739 const auto constSplit = resultString.split(
',' );
1742 for (
const QString &s : constSplit )
1744 number = s.toDouble( &ok );
1745 result << ( ok ? QVariant( number ) : s );
1754 return QList<QgsMapLayer *>();
1762 return QList<QgsMapLayer *>();
1764 const QVariant val = value;
1765 if (
QgsMapLayer *layer = qobject_cast< QgsMapLayer * >( qvariant_cast<QObject *>( val ) ) )
1767 return QList<QgsMapLayer *>() << layer;
1770 QList<QgsMapLayer *> layers;
1772 std::function< void(
const QVariant &var ) > processVariant;
1773 processVariant = [ &layers, &context, &definition, &processVariant ](
const QVariant & var )
1775 if ( var.type() == QVariant::List )
1777 const auto constToList = var.toList();
1778 for (
const QVariant &listVar : constToList )
1780 processVariant( listVar );
1783 else if ( var.type() == QVariant::StringList )
1785 const auto constToStringList = var.toStringList();
1786 for (
const QString &s : constToStringList )
1788 processVariant( s );
1791 else if ( var.userType() == QMetaType::type(
"QgsProperty" ) )
1793 else if ( var.userType() == QMetaType::type(
"QgsProcessingOutputLayerDefinition" ) )
1797 const QVariant sink = fromVar.
sink;
1798 if ( sink.userType() == QMetaType::type(
"QgsProperty" ) )
1803 else if (
QgsMapLayer *layer = qobject_cast< QgsMapLayer * >( qvariant_cast<QObject *>( var ) ) )
1815 processVariant( val );
1817 if ( layers.isEmpty() )
1820 if (
QgsMapLayer *layer = qobject_cast< QgsMapLayer * >( qvariant_cast<QObject *>( definition->
defaultValue() ) ) )
1824 else if ( definition->
defaultValue().type() == QVariant::List )
1826 const auto constToList = definition->
defaultValue().toList();
1827 for (
const QVariant &var : constToList )
1829 if (
QgsMapLayer *layer = qobject_cast< QgsMapLayer * >( qvariant_cast<QObject *>( var ) ) )
1835 processVariant( var );
1849 return QStringList();
1851 const QVariant val = value;
1855 std::function< void(
const QVariant &var ) > processVariant;
1856 processVariant = [ &files, &context, &definition, &processVariant ](
const QVariant & var )
1858 if ( var.type() == QVariant::List )
1860 const auto constToList = var.toList();
1861 for (
const QVariant &listVar : constToList )
1863 processVariant( listVar );
1866 else if ( var.type() == QVariant::StringList )
1868 const auto constToStringList = var.toStringList();
1869 for (
const QString &s : constToStringList )
1871 processVariant( s );
1874 else if ( var.userType() == QMetaType::type(
"QgsProperty" ) )
1878 files << var.toString();
1882 processVariant( val );
1884 if ( files.isEmpty() )
1895 return QStringList();
1903 return QList<double>();
1911 return QList<double>();
1913 QStringList resultStringList;
1914 const QVariant val = value;
1916 if ( val.userType() == QMetaType::type(
"QgsProperty" ) )
1918 else if ( val.type() == QVariant::List )
1920 const auto constToList = val.toList();
1921 for (
const QVariant &var : constToList )
1922 resultStringList << var.toString();
1925 resultStringList << val.toString();
1927 if ( ( resultStringList.isEmpty() || ( resultStringList.size() == 1 && resultStringList.at( 0 ).isEmpty() ) ) )
1929 resultStringList.clear();
1931 if ( definition->
defaultValue().type() == QVariant::List )
1933 const auto constToList = definition->
defaultValue().toList();
1934 for (
const QVariant &var : constToList )
1935 resultStringList << var.toString();
1938 resultStringList << definition->
defaultValue().toString();
1941 if ( resultStringList.size() == 1 )
1943 resultStringList = resultStringList.at( 0 ).split(
',' );
1946 if ( resultStringList.size() < 2 )
1947 return QList< double >() << std::numeric_limits<double>::quiet_NaN() << std::numeric_limits<double>::quiet_NaN() ;
1949 QList< double > result;
1951 double n = resultStringList.at( 0 ).toDouble( &ok );
1955 result << std::numeric_limits<double>::quiet_NaN() ;
1957 n = resultStringList.at( 1 ).toDouble( &ok );
1961 result << std::numeric_limits<double>::quiet_NaN() ;
1969 return QStringList();
1977 return QStringList();
1979 QStringList resultStringList;
1980 const QVariant val = value;
1981 if ( val.isValid() )
1983 if ( val.userType() == QMetaType::type(
"QgsProperty" ) )
1985 else if ( val.type() == QVariant::List )
1987 const auto constToList = val.toList();
1988 for (
const QVariant &var : constToList )
1989 resultStringList << var.toString();
1991 else if ( val.type() == QVariant::StringList )
1993 resultStringList = val.toStringList();
1996 resultStringList.append( val.toString().split(
';' ) );
1999 if ( ( resultStringList.isEmpty() || resultStringList.at( 0 ).isEmpty() ) )
2001 resultStringList.clear();
2005 if ( definition->
defaultValue().type() == QVariant::List )
2007 const auto constToList = definition->
defaultValue().toList();
2008 for (
const QVariant &var : constToList )
2009 resultStringList << var.toString();
2011 else if ( definition->
defaultValue().type() == QVariant::StringList )
2013 resultStringList = definition->
defaultValue().toStringList();
2016 resultStringList.append( definition->
defaultValue().toString().split(
';' ) );
2020 return resultStringList;
2034 if ( layoutName.isEmpty() )
2086 QVariant val = value;
2087 if ( val.userType() == QMetaType::type(
"QgsProperty" ) )
2091 if ( val.type() == QVariant::Color )
2093 QColor
c = val.value< QColor >();
2095 if ( !colorParam->opacityEnabled() )
2103 if ( definition->
defaultValue().type() == QVariant::Color )
2109 if ( colorText.isEmpty() )
2112 bool containsAlpha =
false;
2115 if (
c.isValid() && !colorParam->opacityEnabled() )
2187 const QString type = map.value( QStringLiteral(
"parameter_type" ) ).toString();
2188 const QString name = map.value( QStringLiteral(
"name" ) ).toString();
2189 std::unique_ptr< QgsProcessingParameterDefinition > def;
2262 def.reset( paramType->
create( name ) );
2268 def->fromVariantMap( map );
2269 return def.release();
2274 QString desc = name;
2275 desc.replace(
'_',
' ' );
2281 bool isOptional =
false;
2285 if ( !parseScriptCodeParameterOptions( code, isOptional, name, type, definition ) )
2290 if ( type == QLatin1String(
"boolean" ) )
2292 else if ( type == QLatin1String(
"crs" ) )
2294 else if ( type == QLatin1String(
"layer" ) )
2296 else if ( type == QLatin1String(
"extent" ) )
2298 else if ( type == QLatin1String(
"point" ) )
2300 else if ( type == QLatin1String(
"geometry" ) )
2302 else if ( type == QLatin1String(
"file" ) )
2304 else if ( type == QLatin1String(
"folder" ) )
2306 else if ( type == QLatin1String(
"matrix" ) )
2308 else if ( type == QLatin1String(
"multiple" ) )
2310 else if ( type == QLatin1String(
"number" ) )
2312 else if ( type == QLatin1String(
"distance" ) )
2314 else if ( type == QLatin1String(
"duration" ) )
2316 else if ( type == QLatin1String(
"scale" ) )
2318 else if ( type == QLatin1String(
"range" ) )
2320 else if ( type == QLatin1String(
"raster" ) )
2322 else if ( type == QLatin1String(
"enum" ) )
2324 else if ( type == QLatin1String(
"string" ) )
2326 else if ( type == QLatin1String(
"authcfg" ) )
2328 else if ( type == QLatin1String(
"expression" ) )
2330 else if ( type == QLatin1String(
"field" ) )
2332 else if ( type == QLatin1String(
"vector" ) )
2334 else if ( type == QLatin1String(
"source" ) )
2336 else if ( type == QLatin1String(
"sink" ) )
2338 else if ( type == QLatin1String(
"vectordestination" ) )
2340 else if ( type == QLatin1String(
"rasterdestination" ) )
2342 else if ( type == QLatin1String(
"pointclouddestination" ) )
2344 else if ( type == QLatin1String(
"filedestination" ) )
2346 else if ( type == QLatin1String(
"folderdestination" ) )
2348 else if ( type == QLatin1String(
"band" ) )
2350 else if ( type == QLatin1String(
"mesh" ) )
2352 else if ( type == QLatin1String(
"layout" ) )
2354 else if ( type == QLatin1String(
"layoutitem" ) )
2356 else if ( type == QLatin1String(
"color" ) )
2358 else if ( type == QLatin1String(
"coordinateoperation" ) )
2360 else if ( type == QLatin1String(
"maptheme" ) )
2362 else if ( type == QLatin1String(
"datetime" ) )
2364 else if ( type == QLatin1String(
"providerconnection" ) )
2366 else if ( type == QLatin1String(
"databaseschema" ) )
2368 else if ( type == QLatin1String(
"databasetable" ) )
2370 else if ( type == QLatin1String(
"pointcloud" ) )
2372 else if ( type == QLatin1String(
"annotation" ) )
2378bool QgsProcessingParameters::parseScriptCodeParameterOptions(
const QString &code,
bool &isOptional, QString &name, QString &type, QString &definition )
2380 const QRegularExpression re( QStringLiteral(
"(?:#*)(.*?)=\\s*(.*)" ) );
2381 QRegularExpressionMatch m = re.match( code );
2382 if ( !m.hasMatch() )
2385 name = m.captured( 1 );
2386 QString tokens = m.captured( 2 );
2387 if ( tokens.startsWith( QLatin1String(
"optional" ), Qt::CaseInsensitive ) )
2390 tokens.remove( 0, 8 );
2397 tokens = tokens.trimmed();
2399 const QRegularExpression re2( QStringLiteral(
"(.*?)\\s+(.*)" ) );
2400 m = re2.match( tokens );
2401 if ( !m.hasMatch() )
2403 type = tokens.toLower().trimmed();
2408 type = m.captured( 1 ).toLower().trimmed();
2409 definition = m.captured( 2 );
2420 , mDescription( description )
2422 , mDefault( defaultValue )
2423 , mFlags( optional ? FlagOptional : 0 )
2428 if ( !input.isValid() && !
mDefault.isValid() )
2431 if ( ( input.type() == QVariant::String && input.toString().isEmpty() )
2432 || ( !input.isValid() &&
mDefault.type() == QVariant::String &&
mDefault.toString().isEmpty() ) )
2440 if ( !value.isValid() )
2441 return QStringLiteral(
"None" );
2443 if ( value.userType() == QMetaType::type(
"QgsProperty" ) )
2444 return QStringLiteral(
"QgsProperty.fromExpression('%1')" ).arg( value.value<
QgsProperty >().
asExpression() );
2456 if ( !value.isValid() )
2460 if ( value.type() == QVariant::Type::Map )
2462 const QVariantMap sourceMap = value.toMap();
2463 QVariantMap resultMap;
2464 for (
auto it = sourceMap.constBegin(); it != sourceMap.constEnd(); it++ )
2470 else if ( value.type() == QVariant::Type::List || value.type() == QVariant::Type::StringList )
2472 const QVariantList sourceList = value.toList();
2473 QVariantList resultList;
2474 resultList.reserve( sourceList.size() );
2475 for (
const QVariant &v : sourceList )
2483 switch ( value.userType() )
2486 case QMetaType::Bool:
2487 case QMetaType::Char:
2488 case QMetaType::Int:
2489 case QMetaType::Double:
2490 case QMetaType::Float:
2491 case QMetaType::LongLong:
2492 case QMetaType::ULongLong:
2493 case QMetaType::UInt:
2494 case QMetaType::ULong:
2495 case QMetaType::UShort:
2502 if ( value.userType() == QMetaType::type(
"QgsProperty" ) )
2512 return QVariantMap( {{QStringLiteral(
"type" ), QStringLiteral(
"data_defined" )}, {QStringLiteral(
"field" ), prop.
field() }} );
2514 return QVariantMap( {{QStringLiteral(
"type" ), QStringLiteral(
"data_defined" )}, {QStringLiteral(
"expression" ), prop.
expressionString() }} );
2519 if ( value.userType() == QMetaType::type(
"QgsCoordinateReferenceSystem" ) )
2529 else if ( value.userType() == QMetaType::type(
"QgsRectangle" ) )
2537 else if ( value.userType() == QMetaType::type(
"QgsReferencedRectangle" ) )
2546 else if ( value.userType() == QMetaType::type(
"QgsGeometry" ) )
2558 else if ( value.userType() == QMetaType::type(
"QgsReferencedGeometry" ) )
2573 else if ( value.userType() == QMetaType::type(
"QgsPointXY" ) )
2579 else if ( value.userType() == QMetaType::type(
"QgsReferencedPointXY" ) )
2586 else if ( value.userType() == QMetaType::type(
"QgsProcessingFeatureSourceDefinition" ) )
2593 else if ( value.userType() == QMetaType::type(
"QgsProcessingOutputLayerDefinition" ) )
2598 else if ( value.userType() == QMetaType::type(
"QColor" ) )
2600 const QColor fromVar = value.value< QColor >();
2601 if ( !fromVar.isValid() )
2604 return QStringLiteral(
"rgba( %1, %2, %3, %4 )" ).arg( fromVar.red() ).arg( fromVar.green() ).arg( fromVar.blue() ).arg( QString::number( fromVar.alphaF(),
'f', 2 ) );
2606 else if ( value.userType() == QMetaType::type(
"QDateTime" ) )
2608 const QDateTime fromVar = value.toDateTime();
2609 if ( !fromVar.isValid() )
2612 return fromVar.toString( Qt::ISODate );
2614 else if ( value.userType() == QMetaType::type(
"QDate" ) )
2616 const QDate fromVar = value.toDate();
2617 if ( !fromVar.isValid() )
2620 return fromVar.toString( Qt::ISODate );
2622 else if ( value.userType() == QMetaType::type(
"QTime" ) )
2624 const QTime fromVar = value.toTime();
2625 if ( !fromVar.isValid() )
2628 return fromVar.toString( Qt::ISODate );
2635 p.insert(
name(), value );
2639 if ( !source.isEmpty() )
2646 if ( value.userType() == QMetaType::QString )
2651 Q_ASSERT_X(
false,
"QgsProcessingParameterDefinition::valueAsJsonObject", QStringLiteral(
"unsupported variant type %1" ).arg(
QMetaType::typeName( value.userType() ) ).toLocal8Bit() );
2664 if ( !value.isValid() )
2667 switch ( value.userType() )
2670 case QMetaType::Bool:
2671 case QMetaType::Char:
2672 case QMetaType::Int:
2673 case QMetaType::Double:
2674 case QMetaType::Float:
2675 case QMetaType::LongLong:
2676 case QMetaType::ULongLong:
2677 case QMetaType::UInt:
2678 case QMetaType::ULong:
2679 case QMetaType::UShort:
2680 return value.toString();
2686 if ( value.userType() == QMetaType::type(
"QgsProperty" ) )
2696 return QStringLiteral(
"field:%1" ).arg( prop.
field() );
2703 if ( value.userType() == QMetaType::type(
"QgsCoordinateReferenceSystem" ) )
2713 else if ( value.userType() == QMetaType::type(
"QgsRectangle" ) )
2721 else if ( value.userType() == QMetaType::type(
"QgsReferencedRectangle" ) )
2729 else if ( value.userType() == QMetaType::type(
"QgsGeometry" ) )
2741 else if ( value.userType() == QMetaType::type(
"QgsReferencedGeometry" ) )
2756 else if ( value.userType() == QMetaType::type(
"QgsPointXY" ) )
2762 else if ( value.userType() == QMetaType::type(
"QgsReferencedPointXY" ) )
2769 else if ( value.userType() == QMetaType::type(
"QgsProcessingFeatureSourceDefinition" ) )
2774 else if ( value.userType() == QMetaType::type(
"QgsProcessingOutputLayerDefinition" ) )
2779 else if ( value.userType() == QMetaType::type(
"QColor" ) )
2781 const QColor fromVar = value.value< QColor >();
2782 if ( !fromVar.isValid() )
2785 return QStringLiteral(
"rgba( %1, %2, %3, %4 )" ).arg( fromVar.red() ).arg( fromVar.green() ).arg( fromVar.blue() ).arg( QString::number( fromVar.alphaF(),
'f', 2 ) );
2787 else if ( value.userType() == QMetaType::type(
"QDateTime" ) )
2789 const QDateTime fromVar = value.toDateTime();
2790 if ( !fromVar.isValid() )
2793 return fromVar.toString( Qt::ISODate );
2795 else if ( value.userType() == QMetaType::type(
"QDate" ) )
2797 const QDate fromVar = value.toDate();
2798 if ( !fromVar.isValid() )
2801 return fromVar.toString( Qt::ISODate );
2803 else if ( value.userType() == QMetaType::type(
"QTime" ) )
2805 const QTime fromVar = value.toTime();
2806 if ( !fromVar.isValid() )
2809 return fromVar.toString( Qt::ISODate );
2816 p.insert(
name(), value );
2820 if ( !source.isEmpty() )
2827 if ( value.userType() == QMetaType::QString )
2828 return value.toString();
2833 return value.toString();
2839 if ( !value.isValid( ) )
2840 return QStringList();
2842 if ( value.type() == QVariant::Type::List || value.type() == QVariant::Type::StringList )
2844 const QVariantList sourceList = value.toList();
2845 QStringList resultList;
2846 resultList.reserve( sourceList.size() );
2847 for (
const QVariant &v : sourceList )
2856 return QStringList();
2868 QString code = QStringLiteral(
"##%1=" ).arg(
mName );
2870 code += QLatin1String(
"optional " );
2871 code +=
type() +
' ';
2873 return code.trimmed();
2881 switch ( outputType )
2885 QString code = t->className() + QStringLiteral(
"('%1', %2" )
2888 code += QLatin1String(
", optional=True" );
2904 map.insert( QStringLiteral(
"parameter_type" ),
type() );
2905 map.insert( QStringLiteral(
"name" ),
mName );
2906 map.insert( QStringLiteral(
"description" ),
mDescription );
2907 map.insert( QStringLiteral(
"help" ),
mHelp );
2908 map.insert( QStringLiteral(
"default" ),
mDefault );
2909 map.insert( QStringLiteral(
"defaultGui" ),
mGuiDefault );
2910 map.insert( QStringLiteral(
"flags" ),
static_cast< int >(
mFlags ) );
2911 map.insert( QStringLiteral(
"metadata" ),
mMetadata );
2917 mName = map.value( QStringLiteral(
"name" ) ).toString();
2918 mDescription = map.value( QStringLiteral(
"description" ) ).toString();
2919 mHelp = map.value( QStringLiteral(
"help" ) ).toString();
2920 mDefault = map.value( QStringLiteral(
"default" ) );
2921 mGuiDefault = map.value( QStringLiteral(
"defaultGui" ) );
2922 mFlags =
static_cast< Flags
>( map.value( QStringLiteral(
"flags" ) ).toInt() );
2923 mMetadata = map.value( QStringLiteral(
"metadata" ) ).toMap();
2939 QString text = QStringLiteral(
"<p><b>%1</b></p>" ).arg(
description() );
2940 if ( !
help().isEmpty() )
2942 text += QStringLiteral(
"<p>%1</p>" ).arg(
help() );
2944 text += QStringLiteral(
"<p>%1</p>" ).arg( QObject::tr(
"Python identifier: ‘%1’" ).arg( QStringLiteral(
"<i>%1</i>" ).arg(
name() ) ) );
2959 if ( !val.isValid() )
2960 return QStringLiteral(
"None" );
2962 if ( val.userType() == QMetaType::type(
"QgsProperty" ) )
2964 return val.toBool() ? QStringLiteral(
"True" ) : QStringLiteral(
"False" );
2969 QString code = QStringLiteral(
"##%1=" ).arg(
mName );
2971 code += QLatin1String(
"optional " );
2972 code +=
type() +
' ';
2973 code +=
mDefault.toBool() ? QStringLiteral(
"true" ) : QStringLiteral(
"false" );
2974 return code.trimmed();
2995 if ( !input.isValid() )
2998 if ( input.userType() == QMetaType::type(
"QgsCoordinateReferenceSystem" ) )
3002 else if ( input.userType() == QMetaType::type(
"QgsProcessingFeatureSourceDefinition" ) )
3006 else if ( input.userType() == QMetaType::type(
"QgsProcessingOutputLayerDefinition" ) )
3011 if ( input.userType() == QMetaType::type(
"QgsProperty" ) )
3017 if ( qobject_cast< QgsMapLayer * >( qvariant_cast<QObject *>( input ) ) )
3020 if ( input.type() != QVariant::String || input.toString().isEmpty() )
3028 if ( !value.isValid() )
3029 return QStringLiteral(
"None" );
3031 if ( value.userType() == QMetaType::type(
"QgsCoordinateReferenceSystem" ) )
3034 return QStringLiteral(
"QgsCoordinateReferenceSystem()" );
3039 if ( value.userType() == QMetaType::type(
"QgsProperty" ) )
3040 return QStringLiteral(
"QgsProperty.fromExpression('%1')" ).arg( value.value<
QgsProperty >().
asExpression() );
3043 p.insert(
name(), value );
3080 if ( !input.isValid() )
3083 if ( input.userType() == QMetaType::type(
"QgsProperty" ) )
3088 if ( qobject_cast< QgsMapLayer * >( qvariant_cast<QObject *>( input ) ) )
3093 if ( input.type() != QVariant::String || input.toString().isEmpty() )
3111 if ( !val.isValid() )
3112 return QStringLiteral(
"None" );
3114 if ( val.userType() == QMetaType::type(
"QgsProperty" ) )
3118 p.insert(
name(), val );
3138 for (
const QString &raster : rasters )
3140 if ( !vectors.contains( raster ) )
3144 for (
const QString &mesh : meshFilters )
3146 if ( !vectors.contains( mesh ) )
3150 for (
const QString &pointCloud : pointCloudFilters )
3152 if ( !vectors.contains( pointCloud ) )
3153 vectors << pointCloud;
3155 vectors.removeAll( QObject::tr(
"All files (*.*)" ) );
3156 std::sort( vectors.begin(), vectors.end() );
3158 return QObject::tr(
"All files (*.*)" ) + QStringLiteral(
";;" ) + vectors.join( QLatin1String(
";;" ) );
3168 QString code = QStringLiteral(
"##%1=" ).arg(
mName );
3170 code += QLatin1String(
"optional " );
3171 code += QLatin1String(
"layer " );
3178 code += QLatin1String(
"hasgeometry " );
3182 code += QLatin1String(
"point " );
3186 code += QLatin1String(
"line " );
3190 code += QLatin1String(
"polygon " );
3194 code += QLatin1String(
"raster " );
3198 code += QLatin1String(
"mesh " );
3202 code += QLatin1String(
"plugin " );
3206 code += QLatin1String(
"pointcloud " );
3210 code += QLatin1String(
"annotation " );
3216 return code.trimmed();
3222 QString def = definition;
3225 if ( def.startsWith( QLatin1String(
"hasgeometry" ), Qt::CaseInsensitive ) )
3228 def = def.mid( 12 );
3231 else if ( def.startsWith( QLatin1String(
"point" ), Qt::CaseInsensitive ) )
3237 else if ( def.startsWith( QLatin1String(
"line" ), Qt::CaseInsensitive ) )
3243 else if ( def.startsWith( QLatin1String(
"polygon" ), Qt::CaseInsensitive ) )
3249 else if ( def.startsWith( QLatin1String(
"raster" ), Qt::CaseInsensitive ) )
3255 else if ( def.startsWith( QLatin1String(
"mesh" ), Qt::CaseInsensitive ) )
3261 else if ( def.startsWith( QLatin1String(
"plugin" ), Qt::CaseInsensitive ) )
3267 else if ( def.startsWith( QLatin1String(
"pointcloud" ), Qt::CaseInsensitive ) )
3270 def = def.mid( 11 );
3273 else if ( def.startsWith( QLatin1String(
"annotation" ), Qt::CaseInsensitive ) )
3276 def = def.mid( 11 );
3287 switch ( outputType )
3291 QString code = QStringLiteral(
"QgsProcessingParameterMapLayer('%1', %2" )
3294 code += QLatin1String(
", optional=True" );
3301 QStringList options;
3305 code += QStringLiteral(
", types=[%1])" ).arg( options.join(
',' ) );
3309 code += QLatin1Char(
')' );
3326 map.insert( QStringLiteral(
"data_types" ), types );
3334 const QVariantList values = map.value( QStringLiteral(
"data_types" ) ).toList();
3335 for (
const QVariant &val : values )
3355 if ( !input.isValid() )
3358 if ( input.userType() == QMetaType::type(
"QgsProcessingFeatureSourceDefinition" ) )
3362 else if ( input.userType() == QMetaType::type(
"QgsProcessingOutputLayerDefinition" ) )
3367 if ( input.userType() == QMetaType::type(
"QgsProperty" ) )
3372 if ( input.userType() == QMetaType::type(
"QgsRectangle" ) )
3377 if ( input.userType() == QMetaType::type(
"QgsGeometry" ) )
3381 if ( input.userType() == QMetaType::type(
"QgsReferencedRectangle" ) )
3388 if ( qobject_cast< QgsMapLayer * >( qvariant_cast<QObject *>( input ) ) )
3391 if ( input.type() != QVariant::String || input.toString().isEmpty() )
3400 const QRegularExpression rx( QStringLiteral(
"^(.*?)\\s*,\\s*(.*?)\\s*,\\s*(.*?)\\s*,\\s*(.*?)\\s*(?:\\[(.*)\\])?\\s*$" ) );
3401 const QRegularExpressionMatch match = rx.match( input.toString() );
3402 if ( match.hasMatch() )
3404 bool xMinOk =
false;
3405 ( void )match.captured( 1 ).toDouble( &xMinOk );
3406 bool xMaxOk =
false;
3407 ( void )match.captured( 2 ).toDouble( &xMaxOk );
3408 bool yMinOk =
false;
3409 ( void )match.captured( 3 ).toDouble( &yMinOk );
3410 bool yMaxOk =
false;
3411 ( void )match.captured( 4 ).toDouble( &yMaxOk );
3412 if ( xMinOk && xMaxOk && yMinOk && yMaxOk )
3422 if ( !value.isValid() )
3423 return QStringLiteral(
"None" );
3425 if ( value.userType() == QMetaType::type(
"QgsProperty" ) )
3426 return QStringLiteral(
"QgsProperty.fromExpression('%1')" ).arg( value.value<
QgsProperty >().
asExpression() );
3428 if ( value.userType() == QMetaType::type(
"QgsRectangle" ) )
3436 else if ( value.userType() == QMetaType::type(
"QgsReferencedRectangle" ) )
3444 else if ( value.userType() == QMetaType::type(
"QgsGeometry" ) )
3449 const QString wkt = g.
asWkt();
3450 return QStringLiteral(
"QgsGeometry.fromWkt('%1')" ).arg( wkt );
3455 p.insert(
name(), value );
3491 if ( !input.isValid() )
3494 if ( input.userType() == QMetaType::type(
"QgsProperty" ) )
3499 if ( input.userType() == QMetaType::type(
"QgsPointXY" ) )
3503 if ( input.userType() == QMetaType::type(
"QgsReferencedPointXY" ) )
3507 if ( input.userType() == QMetaType::type(
"QgsGeometry" ) )
3512 if ( input.type() == QVariant::String )
3514 if ( input.toString().isEmpty() )
3518 const QRegularExpression rx( QStringLiteral(
"^\\s*\\(?\\s*(.*?)\\s*,\\s*(.*?)\\s*(?:\\[(.*)\\])?\\s*\\)?\\s*$" ) );
3520 const QRegularExpressionMatch match = rx.match( input.toString() );
3521 if ( match.hasMatch() )
3524 ( void )match.captured( 1 ).toDouble( &xOk );
3526 ( void )match.captured( 2 ).toDouble( &yOk );
3535 if ( !value.isValid() )
3536 return QStringLiteral(
"None" );
3538 if ( value.userType() == QMetaType::type(
"QgsProperty" ) )
3539 return QStringLiteral(
"QgsProperty.fromExpression('%1')" ).arg( value.value<
QgsProperty >().
asExpression() );
3541 if ( value.userType() == QMetaType::type(
"QgsPointXY" ) )
3547 else if ( value.userType() == QMetaType::type(
"QgsReferencedPointXY" ) )
3554 else if ( value.userType() == QMetaType::type(
"QgsGeometry" ) )
3559 const QString wkt = g.
asWkt();
3560 return QStringLiteral(
"QgsGeometry.fromWkt('%1')" ).arg( wkt );
3573 const QVariant &defaultValue,
bool optional,
const QList<int> &geometryTypes,
bool allowMultipart )
3575 mGeomTypes( geometryTypes ),
3576 mAllowMultipart( allowMultipart )
3588 if ( !input.isValid() )
3591 if ( input.userType() == QMetaType::type(
"QgsProperty" ) )
3598 if ( input.userType() == QMetaType::type(
"QgsGeometry" ) )
3600 return ( anyTypeAllowed || mGeomTypes.contains( input.value<
QgsGeometry>().
type() ) ) &&
3601 ( mAllowMultipart || !input.value<
QgsGeometry>().isMultipart() );
3604 if ( input.userType() == QMetaType::type(
"QgsReferencedGeometry" ) )
3610 if ( input.userType() == QMetaType::type(
"QgsPointXY" ) )
3615 if ( input.userType() == QMetaType::type(
"QgsRectangle" ) )
3620 if ( input.userType() == QMetaType::type(
"QgsReferencedPointXY" ) )
3625 if ( input.userType() == QMetaType::type(
"QgsReferencedRectangle" ) )
3630 if ( input.type() == QVariant::String )
3632 if ( input.toString().isEmpty() )
3637 const QRegularExpression rx( QStringLiteral(
"^\\s*(?:CRS=(.*);)?(.*?)$" ) );
3639 const QRegularExpressionMatch match = rx.match( input.toString() );
3640 if ( match.hasMatch() )
3645 return ( anyTypeAllowed || mGeomTypes.contains( g.
type() ) ) && ( mAllowMultipart || !g.
isMultipart() );
3665 if ( !value.isValid() )
3666 return QStringLiteral(
"None" );
3668 if ( value.userType() == QMetaType::type(
"QgsProperty" ) )
3671 if ( value.userType() == QMetaType::type(
"QgsGeometry" ) )
3678 if ( value.userType() == QMetaType::type(
"QgsReferencedGeometry" ) )
3685 if ( value.userType() == QMetaType::type(
"QgsPointXY" ) )
3692 if ( value.userType() == QMetaType::type(
"QgsReferencedPointXY" ) )
3699 if ( value.userType() == QMetaType::type(
"QgsRectangle" ) )
3706 if ( value.userType() == QMetaType::type(
"QgsReferencedRectangle" ) )
3718 QString code = QStringLiteral(
"##%1=" ).arg(
mName );
3720 code += QLatin1String(
"optional " );
3721 code +=
type() +
' ';
3723 for (
const int type : mGeomTypes )
3728 code += QLatin1String(
"point " );
3732 code += QLatin1String(
"line " );
3736 code += QLatin1String(
"polygon " );
3740 code += QLatin1String(
"unknown " );
3746 return code.trimmed();
3751 switch ( outputType )
3755 QString code = QStringLiteral(
"QgsProcessingParameterGeometry('%1', %2" )
3758 code += QLatin1String(
", optional=True" );
3760 if ( !mGeomTypes.empty() )
3767 return QStringLiteral(
"PointGeometry" );
3770 return QStringLiteral(
"LineGeometry" );
3773 return QStringLiteral(
"PolygonGeometry" );
3776 return QStringLiteral(
"UnknownGeometry" );
3779 return QStringLiteral(
"NullGeometry" );
3784 QStringList options;
3785 options.reserve( mGeomTypes.size() );
3786 for (
const int type : mGeomTypes )
3790 code += QStringLiteral(
", geometryTypes=[%1 ]" ).arg( options.join(
',' ) );
3793 if ( ! mAllowMultipart )
3795 code += QLatin1String(
", allowMultipart=False" );
3810 for (
const int type : mGeomTypes )
3814 map.insert( QStringLiteral(
"geometrytypes" ), types );
3815 map.insert( QStringLiteral(
"multipart" ), mAllowMultipart );
3823 const QVariantList values = map.value( QStringLiteral(
"geometrytypes" ) ).toList();
3824 for (
const QVariant &val : values )
3826 mGeomTypes << val.toInt();
3828 mAllowMultipart = map.value( QStringLiteral(
"multipart" ) ).toBool();
3839 , mBehavior( behavior )
3840 , mExtension( fileFilter.isEmpty() ? extension : QString() )
3841 , mFileFilter( fileFilter.isEmpty() && extension.isEmpty() ? QObject::tr(
"All files (*.*)" ) : fileFilter )
3853 if ( !input.isValid() )
3856 if ( input.userType() == QMetaType::type(
"QgsProperty" ) )
3861 const QString
string = input.toString().trimmed();
3863 if ( input.type() != QVariant::String ||
string.isEmpty() )
3866 switch ( mBehavior )
3870 if ( !mExtension.isEmpty() )
3872 return string.endsWith( mExtension, Qt::CaseInsensitive );
3874 else if ( !mFileFilter.isEmpty() )
3892 QString code = QStringLiteral(
"##%1=" ).arg(
mName );
3894 code += QLatin1String(
"optional " );
3895 code += ( mBehavior ==
File ? QStringLiteral(
"file" ) : QStringLiteral(
"folder" ) ) +
' ';
3897 return code.trimmed();
3902 switch ( outputType )
3907 QString code = QStringLiteral(
"QgsProcessingParameterFile('%1', %2" )
3910 code += QLatin1String(
", optional=True" );
3911 code += QStringLiteral(
", behavior=%1" ).arg( mBehavior ==
File ? QStringLiteral(
"QgsProcessingParameterFile.File" ) : QStringLiteral(
"QgsProcessingParameterFile.Folder" ) );
3912 if ( !mExtension.isEmpty() )
3913 code += QStringLiteral(
", extension='%1'" ).arg( mExtension );
3914 if ( !mFileFilter.isEmpty() )
3915 code += QStringLiteral(
", fileFilter='%1'" ).arg( mFileFilter );
3926 switch ( mBehavior )
3930 if ( !mFileFilter.isEmpty() )
3931 return mFileFilter != QObject::tr(
"All files (*.*)" ) ? mFileFilter + QStringLiteral(
";;" ) + QObject::tr(
"All files (*.*)" ) : mFileFilter;
3932 else if ( !mExtension.isEmpty() )
3933 return QObject::tr(
"%1 files" ).arg( mExtension.toUpper() ) + QStringLiteral(
" (*." ) + mExtension.toLower() + QStringLiteral(
");;" ) + QObject::tr(
"All files (*.*)" );
3935 return QObject::tr(
"All files (*.*)" );
3947 mFileFilter.clear();
3957 mFileFilter = filter;
3964 map.insert( QStringLiteral(
"behavior" ), mBehavior );
3965 map.insert( QStringLiteral(
"extension" ), mExtension );
3966 map.insert( QStringLiteral(
"filefilter" ), mFileFilter );
3973 mBehavior =
static_cast< Behavior >( map.value( QStringLiteral(
"behavior" ) ).toInt() );
3974 mExtension = map.value( QStringLiteral(
"extension" ) ).toString();
3975 mFileFilter = map.value( QStringLiteral(
"filefilter" ) ).toString();
3986 , mHeaders( headers )
3987 , mNumberRows( numberRows )
3988 , mFixedNumberRows( fixedNumberRows )
4000 if ( !input.isValid() )
4003 if ( input.type() == QVariant::String )
4005 if ( input.toString().isEmpty() )
4009 else if ( input.type() == QVariant::List )
4011 if ( input.toList().isEmpty() )
4015 else if ( input.type() == QVariant::Double || input.type() == QVariant::Int )
4025 if ( !value.isValid() )
4026 return QStringLiteral(
"None" );
4028 if ( value.userType() == QMetaType::type(
"QgsProperty" ) )
4029 return QStringLiteral(
"QgsProperty.fromExpression('%1')" ).arg( value.value<
QgsProperty >().
asExpression() );
4032 p.insert(
name(), value );
4040 switch ( outputType )
4044 QString code = QStringLiteral(
"QgsProcessingParameterMatrix('%1', %2" )
4047 code += QLatin1String(
", optional=True" );
4048 code += QStringLiteral(
", numberRows=%1" ).arg( mNumberRows );
4049 code += QStringLiteral(
", hasFixedNumberRows=%1" ).arg( mFixedNumberRows ? QStringLiteral(
"True" ) : QStringLiteral(
"False" ) );
4052 headers.reserve( mHeaders.size() );
4053 for (
const QString &h : mHeaders )
4055 code += QStringLiteral(
", headers=[%1]" ).arg(
headers.join(
',' ) );
4087 return mFixedNumberRows;
4092 mFixedNumberRows = fixedNumberRows;
4098 map.insert( QStringLiteral(
"headers" ), mHeaders );
4099 map.insert( QStringLiteral(
"rows" ), mNumberRows );
4100 map.insert( QStringLiteral(
"fixed_number_rows" ), mFixedNumberRows );
4107 mHeaders = map.value( QStringLiteral(
"headers" ) ).toStringList();
4108 mNumberRows = map.value( QStringLiteral(
"rows" ) ).toInt();
4109 mFixedNumberRows = map.value( QStringLiteral(
"fixed_number_rows" ) ).toBool();
4120 , mLayerType( layerType )
4132 if ( !input.isValid() )
4137 if ( qobject_cast< QgsMapLayer * >( qvariant_cast<QObject *>( input ) ) )
4143 if ( input.type() == QVariant::String )
4145 if ( input.toString().isEmpty() )
4148 if ( mMinimumNumberInputs > 1 )
4159 else if ( input.type() == QVariant::List )
4161 if ( input.toList().count() < mMinimumNumberInputs )
4164 if ( mMinimumNumberInputs > input.toList().count() )
4172 const auto constToList = input.toList();
4173 for (
const QVariant &v : constToList )
4175 if ( qobject_cast< QgsMapLayer * >( qvariant_cast<QObject *>( v ) ) )
4184 else if ( input.type() == QVariant::StringList )
4186 if ( input.toStringList().count() < mMinimumNumberInputs )
4189 if ( mMinimumNumberInputs > input.toStringList().count() )
4197 const auto constToStringList = input.toStringList();
4198 for (
const QString &v : constToStringList )
4211 if ( !value.isValid() )
4212 return QStringLiteral(
"None" );
4214 if ( value.userType() == QMetaType::type(
"QgsProperty" ) )
4215 return QStringLiteral(
"QgsProperty.fromExpression('%1')" ).arg( value.value<
QgsProperty >().
asExpression() );
4220 if ( value.type() == QVariant::StringList )
4222 const QStringList list = value.toStringList();
4223 parts.reserve( list.count() );
4224 for (
const QString &v : list )
4227 else if ( value.type() == QVariant::List )
4229 const QVariantList list = value.toList();
4230 parts.reserve( list.count() );
4231 for (
const QVariant &v : list )
4234 if ( !parts.isEmpty() )
4235 return parts.join(
',' ).prepend(
'[' ).append(
']' );
4240 p.insert(
name(), value );
4242 if ( !list.isEmpty() )
4245 parts.reserve( list.count() );
4250 return parts.join(
',' ).prepend(
'[' ).append(
']' );
4269 QString code = QStringLiteral(
"##%1=" ).arg(
mName );
4271 code += QLatin1String(
"optional " );
4272 switch ( mLayerType )
4275 code += QLatin1String(
"multiple raster" );
4279 code += QLatin1String(
"multiple file" );
4283 code += QLatin1String(
"multiple vector" );
4287 if (
mDefault.type() == QVariant::List )
4290 const auto constToList =
mDefault.toList();
4291 for (
const QVariant &var : constToList )
4293 parts << var.toString();
4295 code += parts.join(
',' );
4297 else if (
mDefault.type() == QVariant::StringList )
4299 code +=
mDefault.toStringList().join(
',' );
4305 return code.trimmed();
4310 switch ( outputType )
4314 QString code = QStringLiteral(
"QgsProcessingParameterMultipleLayers('%1', %2" )
4317 code += QLatin1String(
", optional=True" );
4321 code += QStringLiteral(
", layerType=%1" ).arg(
layerType );
4332 switch ( mLayerType )
4335 return QObject::tr(
"All files (*.*)" );
4373 return mMinimumNumberInputs;
4385 map.insert( QStringLiteral(
"layer_type" ), mLayerType );
4386 map.insert( QStringLiteral(
"min_inputs" ), mMinimumNumberInputs );
4394 mMinimumNumberInputs = map.value( QStringLiteral(
"min_inputs" ) ).toInt();
4400 QString
type = definition;
4402 const QRegularExpression re( QStringLiteral(
"(.*?)\\s+(.*)" ) );
4403 const QRegularExpressionMatch m = re.match( definition );
4406 type = m.captured( 1 ).toLower().trimmed();
4407 defaultVal = m.captured( 2 );
4410 if (
type == QLatin1String(
"vector" ) )
4412 else if (
type == QLatin1String(
"raster" ) )
4414 else if (
type == QLatin1String(
"file" ) )
4427 QgsMessageLog::logMessage( QObject::tr(
"Invalid number parameter \"%1\": min value %2 is >= max value %3!" ).arg(
name ).arg( mMin ).arg( mMax ), QObject::tr(
"Processing" ) );
4438 QVariant input = value;
4439 if ( !input.isValid() )
4447 if ( input.userType() == QMetaType::type(
"QgsProperty" ) )
4453 const double res = input.toDouble( &ok );
4457 return !( res < mMin || res > mMax );
4462 if ( !value.isValid() )
4463 return QStringLiteral(
"None" );
4465 if ( value.userType() == QMetaType::type(
"QgsProperty" ) )
4466 return QStringLiteral(
"QgsProperty.fromExpression('%1')" ).arg( value.value<
QgsProperty >().
asExpression() );
4468 return value.toString();
4475 if ( mMin > std::numeric_limits<double>::lowest() + 1 )
4476 parts << QObject::tr(
"Minimum value: %1" ).arg( mMin );
4477 if ( mMax < std::numeric_limits<double>::max() )
4478 parts << QObject::tr(
"Maximum value: %1" ).arg( mMax );
4480 parts << QObject::tr(
"Default value: %1" ).arg( mDataType ==
Integer ?
mDefault.toInt() :
mDefault.toDouble() );
4481 const QString extra = parts.join( QLatin1String(
"<br />" ) );
4482 if ( !extra.isEmpty() )
4483 text += QStringLiteral(
"<p>%1</p>" ).arg( extra );
4489 switch ( outputType )
4493 QString code = QStringLiteral(
"QgsProcessingParameterNumber('%1', %2" )
4496 code += QLatin1String(
", optional=True" );
4498 code += QStringLiteral(
", type=%1" ).arg( mDataType ==
Integer ? QStringLiteral(
"QgsProcessingParameterNumber.Integer" ) : QStringLiteral(
"QgsProcessingParameterNumber.Double" ) );
4500 if ( mMin != std::numeric_limits<double>::lowest() + 1 )
4501 code += QStringLiteral(
", minValue=%1" ).arg( mMin );
4502 if ( mMax != std::numeric_limits<double>::max() )
4503 code += QStringLiteral(
", maxValue=%1" ).arg( mMax );
4545 map.insert( QStringLiteral(
"min" ), mMin );
4546 map.insert( QStringLiteral(
"max" ), mMax );
4547 map.insert( QStringLiteral(
"data_type" ), mDataType );
4554 mMin = map.value( QStringLiteral(
"min" ) ).toDouble();
4555 mMax = map.value( QStringLiteral(
"max" ) ).toDouble();
4556 mDataType =
static_cast< Type >( map.value( QStringLiteral(
"data_type" ) ).toInt() );
4563 : ( definition.toLower().trimmed() == QLatin1String(
"none" ) ? QVariant() : definition ), isOptional );
4580 if ( !input.isValid() )
4583 if ( input.userType() == QMetaType::type(
"QgsProperty" ) )
4588 if ( input.type() == QVariant::String )
4590 const QStringList list = input.toString().split(
',' );
4591 if ( list.count() != 2 )
4594 list.at( 0 ).toDouble( &ok );
4596 list.at( 1 ).toDouble( &ok2 );
4601 else if ( input.type() == QVariant::List )
4603 if ( input.toList().count() != 2 )
4607 input.toList().at( 0 ).toDouble( &ok );
4609 input.toList().at( 1 ).toDouble( &ok2 );
4620 if ( !value.isValid() )
4621 return QStringLiteral(
"None" );
4623 if ( value.userType() == QMetaType::type(
"QgsProperty" ) )
4624 return QStringLiteral(
"QgsProperty.fromExpression('%1')" ).arg( value.value<
QgsProperty >().
asExpression() );
4627 p.insert(
name(), value );
4630 QStringList stringParts;
4631 const auto constParts = parts;
4632 for (
const double v : constParts )
4634 stringParts << QString::number( v );
4636 return stringParts.join(
',' ).prepend(
'[' ).append(
']' );
4641 switch ( outputType )
4645 QString code = QStringLiteral(
"QgsProcessingParameterRange('%1', %2" )
4648 code += QLatin1String(
", optional=True" );
4650 code += QStringLiteral(
", type=%1" ).arg( mDataType ==
QgsProcessingParameterNumber::Integer ? QStringLiteral(
"QgsProcessingParameterNumber.Integer" ) : QStringLiteral(
"QgsProcessingParameterNumber.Double" ) );
4673 map.insert( QStringLiteral(
"data_type" ), mDataType );
4687 : ( definition.toLower().trimmed() == QLatin1String(
"none" ) ? QVariant() : definition ), isOptional );
4703 if ( !input.isValid() )
4706 if ( input.userType() == QMetaType::type(
"QgsProperty" ) )
4711 if ( qobject_cast< QgsRasterLayer * >( qvariant_cast<QObject *>( input ) ) )
4714 if ( input.type() != QVariant::String || input.toString().isEmpty() )
4732 if ( !val.isValid() )
4733 return QStringLiteral(
"None" );
4735 if ( val.userType() == QMetaType::type(
"QgsProperty" ) )
4739 p.insert(
name(), val );
4767 , mOptions( options )
4768 , mAllowMultiple( allowMultiple )
4769 , mUsesStaticStrings( usesStaticStrings )
4781 QVariant input = value;
4782 if ( !input.isValid() )
4790 if ( input.userType() == QMetaType::type(
"QgsProperty" ) )
4795 if ( mUsesStaticStrings )
4797 if ( input.type() == QVariant::List )
4799 if ( !mAllowMultiple )
4802 const QVariantList values = input.toList();
4806 for (
const QVariant &val : values )
4808 if ( !mOptions.contains( val.toString() ) )
4814 else if ( input.type() == QVariant::StringList )
4816 if ( !mAllowMultiple )
4819 const QStringList values = input.toStringList();
4824 if ( values.count() > 1 && !mAllowMultiple )
4827 for (
const QString &val : values )
4829 if ( !mOptions.contains( val ) )
4834 else if ( input.type() == QVariant::String )
4836 const QStringList parts = input.toString().split(
',' );
4837 if ( parts.count() > 1 && !mAllowMultiple )
4840 const auto constParts = parts;
4841 for (
const QString &part : constParts )
4843 if ( !mOptions.contains( part ) )
4851 if ( input.type() == QVariant::List )
4853 if ( !mAllowMultiple )
4856 const QVariantList values = input.toList();
4860 for (
const QVariant &val : values )
4863 const int res = val.toInt( &ok );
4866 else if ( res < 0 || res >= mOptions.count() )
4872 else if ( input.type() == QVariant::String )
4874 const QStringList parts = input.toString().split(
',' );
4875 if ( parts.count() > 1 && !mAllowMultiple )
4878 const auto constParts = parts;
4879 for (
const QString &part : constParts )
4882 const int res = part.toInt( &ok );
4885 else if ( res < 0 || res >= mOptions.count() )
4890 else if ( input.type() == QVariant::Int || input.type() == QVariant::Double )
4893 const int res = input.toInt( &ok );
4896 else if ( res >= 0 && res < mOptions.count() )
4906 if ( !value.isValid() )
4907 return QStringLiteral(
"None" );
4909 if ( value.userType() == QMetaType::type(
"QgsProperty" ) )
4910 return QStringLiteral(
"QgsProperty.fromExpression('%1')" ).arg( value.value<
QgsProperty >().
asExpression() );
4912 if ( mUsesStaticStrings )
4914 if ( value.type() == QVariant::StringList )
4917 const QStringList constList = value.toStringList();
4918 for (
const QString &val : constList )
4922 return parts.join(
',' ).prepend(
'[' ).append(
']' );
4924 else if ( value.type() == QVariant::String )
4927 const QStringList constList = value.toString().split(
',' );
4928 if ( constList.count() > 1 )
4930 for (
const QString &val : constList )
4934 return parts.join(
',' ).prepend(
'[' ).append(
']' );
4942 if ( value.type() == QVariant::List )
4945 const auto constToList = value.toList();
4946 for (
const QVariant &val : constToList )
4948 parts << QString::number( static_cast< int >( val.toDouble() ) );
4950 return parts.join(
',' ).prepend(
'[' ).append(
']' );
4952 else if ( value.type() == QVariant::String )
4954 const QStringList parts = value.toString().split(
',' );
4955 if ( parts.count() > 1 )
4957 return parts.join(
',' ).prepend(
'[' ).append(
']' );
4961 return QString::number(
static_cast< int >( value.toDouble() ) );
4967 if ( !value.isValid() )
4970 if ( value.userType() == QMetaType::type(
"QgsProperty" ) )
4973 if ( mUsesStaticStrings )
4979 if ( value.type() == QVariant::List )
4982 const QVariantList toList = value.toList();
4983 parts.reserve( toList.size() );
4984 for (
const QVariant &val : toList )
4986 parts << mOptions.value(
static_cast< int >( val.toDouble() ) );
4988 return parts.join(
',' );
4990 else if ( value.type() == QVariant::String )
4992 const QStringList parts = value.toString().split(
',' );
4993 QStringList comments;
4994 if ( parts.count() > 1 )
4996 for (
const QString &part : parts )
4999 const int val = part.toInt( &ok );
5001 comments << mOptions.value( val );
5003 return comments.join(
',' );
5007 return mOptions.value(
static_cast< int >( value.toDouble() ) );
5013 QString code = QStringLiteral(
"##%1=" ).arg(
mName );
5015 code += QLatin1String(
"optional " );
5016 code += QLatin1String(
"enum " );
5018 if ( mAllowMultiple )
5019 code += QLatin1String(
"multiple " );
5021 if ( mUsesStaticStrings )
5022 code += QLatin1String(
"static " );
5024 code += mOptions.join(
';' ) +
' ';
5027 return code.trimmed();
5032 switch ( outputType )
5036 QString code = QStringLiteral(
"QgsProcessingParameterEnum('%1', %2" )
5039 code += QLatin1String(
", optional=True" );
5042 options.reserve( mOptions.size() );
5043 for (
const QString &o : mOptions )
5045 code += QStringLiteral(
", options=[%1]" ).arg(
options.join(
',' ) );
5047 code += QStringLiteral(
", allowMultiple=%1" ).arg( mAllowMultiple ? QStringLiteral(
"True" ) : QStringLiteral(
"False" ) );
5049 code += QStringLiteral(
", usesStaticStrings=%1" ).arg( mUsesStaticStrings ? QStringLiteral(
"True" ) : QStringLiteral(
"False" ) );
5072 return mAllowMultiple;
5082 return mUsesStaticStrings;
5093 map.insert( QStringLiteral(
"options" ), mOptions );
5094 map.insert( QStringLiteral(
"allow_multiple" ), mAllowMultiple );
5095 map.insert( QStringLiteral(
"uses_static_strings" ), mUsesStaticStrings );
5102 mOptions = map.value( QStringLiteral(
"options" ) ).toStringList();
5103 mAllowMultiple = map.value( QStringLiteral(
"allow_multiple" ) ).toBool();
5104 mUsesStaticStrings = map.value( QStringLiteral(
"uses_static_strings" ) ).toBool();
5111 QString def = definition;
5113 bool multiple =
false;
5114 if ( def.startsWith( QLatin1String(
"multiple" ), Qt::CaseInsensitive ) )
5120 bool staticStrings =
false;
5121 if ( def.startsWith( QLatin1String(
"static" ), Qt::CaseInsensitive ) )
5123 staticStrings =
true;
5127 const QRegularExpression re( QStringLiteral(
"(.*)\\s+(.*?)$" ) );
5128 const QRegularExpressionMatch m = re.match( def );
5129 QString values = def;
5132 values = m.captured( 1 ).trimmed();
5133 defaultVal = m.captured( 2 );
5141 , mMultiLine( multiLine )
5154 return QStringLiteral(
"None" );
5156 if ( value.userType() == QMetaType::type(
"QgsProperty" ) )
5157 return QStringLiteral(
"QgsProperty.fromExpression('%1')" ).arg( value.value<
QgsProperty >().
asExpression() );
5159 const QString s = value.toString();