40 #include <QRegularExpression>
45 return compatibleMapLayers< QgsRasterLayer >( project, sort );
51 return QList<QgsVectorLayer *>();
53 QList<QgsVectorLayer *> layers;
57 if ( canUseLayer( l, geometryTypes ) )
65 return QString::localeAwareCompare( a->name(), b->name() ) < 0;
73 return compatibleMapLayers< QgsMeshLayer >( project, sort );
78 return compatibleMapLayers< QgsPluginLayer >( project, sort );
83 return compatibleMapLayers< QgsPointCloudLayer >( project, sort );
89 QList<QgsAnnotationLayer *> res = compatibleMapLayers< QgsAnnotationLayer >( project,
false );
97 return QString::localeAwareCompare( a->name(), b->name() ) < 0;
104 template<
typename T> QList<T *> QgsProcessingUtils::compatibleMapLayers(
QgsProject *project,
bool sort )
110 const auto projectLayers = project->
layers<T *>();
111 for ( T *l : projectLayers )
113 if ( canUseLayer( l ) )
119 std::sort( layers.begin(), layers.end(), [](
const T * a,
const T * b ) ->
bool
121 return QString::localeAwareCompare( a->name(), b->name() ) < 0;
130 return QList<QgsMapLayer *>();
132 QList<QgsMapLayer *> layers;
134 const auto rasterLayers = compatibleMapLayers< QgsRasterLayer >( project,
false );
142 const auto meshLayers = compatibleMapLayers< QgsMeshLayer >( project,
false );
146 const auto pointCloudLayers = compatibleMapLayers< QgsPointCloudLayer >( project,
false );
150 const auto annotationLayers = compatibleMapLayers< QgsAnnotationLayer >( project,
false );
155 const auto pluginLayers = compatibleMapLayers< QgsPluginLayer >( project,
false );
163 return QString::localeAwareCompare( a->name(), b->name() ) < 0;
171 return QStringLiteral(
"%1://%2" ).arg( providerKey, uri );
176 QRegularExpression re( QStringLiteral(
"^(\\w+?):\\/\\/(.+)$" ) );
177 const QRegularExpressionMatch match = re.match(
string );
178 if ( !match.hasMatch() )
181 providerKey = match.captured( 1 );
182 uri = match.captured( 2 );
190 if ( !store ||
string.isEmpty() )
193 QList< QgsMapLayer * > layers = store->
mapLayers().values();
195 layers.erase( std::remove_if( layers.begin(), layers.end(), [](
QgsMapLayer * layer )
197 switch ( layer->type() )
199 case QgsMapLayerType::VectorLayer:
200 return !canUseLayer( qobject_cast< QgsVectorLayer * >( layer ) );
201 case QgsMapLayerType::RasterLayer:
202 return !canUseLayer( qobject_cast< QgsRasterLayer * >( layer ) );
203 case QgsMapLayerType::PluginLayer:
204 case QgsMapLayerType::GroupLayer:
206 case QgsMapLayerType::MeshLayer:
207 return !canUseLayer( qobject_cast< QgsMeshLayer * >( layer ) );
208 case QgsMapLayerType::VectorTileLayer:
209 return !canUseLayer( qobject_cast< QgsVectorTileLayer * >( layer ) );
210 case QgsMapLayerType::PointCloudLayer:
211 return !canUseLayer( qobject_cast< QgsPointCloudLayer * >( layer ) );
212 case QgsMapLayerType::AnnotationLayer:
213 return !canUseLayer( qobject_cast< QgsAnnotationLayer * >( layer ) );
218 auto isCompatibleType = [typeHint](
QgsMapLayer * l ) ->
bool
222 case LayerHint::UnknownType:
225 case LayerHint::Vector:
228 case LayerHint::Raster:
231 case LayerHint::Mesh:
234 case LayerHint::PointCloud:
237 case LayerHint::Annotation:
245 if ( isCompatibleType( l ) && l->id() == string )
250 if ( isCompatibleType( l ) && l->name() == string )
255 if ( isCompatibleType( l ) && normalizeLayerSource( l->source() ) == normalizeLayerSource(
string ) )
271 if ( !useProvider || ( provider == QLatin1String(
"ogr" ) || provider == QLatin1String(
"gdal" ) || provider == QLatin1String(
"mdal" ) || provider == QLatin1String(
"pdal" ) || provider == QLatin1String(
"ept" ) ) )
273 QStringList components = uri.split(
'|' );
274 if ( components.isEmpty() )
278 if ( QFileInfo::exists( uri ) )
279 fi = QFileInfo( uri );
280 else if ( QFileInfo::exists( components.at( 0 ) ) )
281 fi = QFileInfo( components.at( 0 ) );
284 name = fi.baseName();
295 options.loadDefaultStyle =
false;
296 options.skipCrsValidation =
true;
298 std::unique_ptr< QgsVectorLayer > layer;
301 layer = std::make_unique<QgsVectorLayer>( uri, name, provider, options );
306 layer = std::make_unique<QgsVectorLayer>( uri, name, QStringLiteral(
"ogr" ), options );
308 if ( layer->isValid() )
310 return layer.release();
319 std::unique_ptr< QgsRasterLayer > rasterLayer;
322 rasterLayer = std::make_unique< QgsRasterLayer >( uri, name, provider, rasterOptions );
327 rasterLayer = std::make_unique< QgsRasterLayer >( uri, name, QStringLiteral(
"gdal" ), rasterOptions );
330 if ( rasterLayer->isValid() )
332 return rasterLayer.release();
340 std::unique_ptr< QgsMeshLayer > meshLayer;
343 meshLayer = std::make_unique< QgsMeshLayer >( uri, name, provider, meshOptions );
347 meshLayer = std::make_unique< QgsMeshLayer >( uri, name, QStringLiteral(
"mdal" ), meshOptions );
349 if ( meshLayer->isValid() )
351 return meshLayer.release();
359 std::unique_ptr< QgsPointCloudLayer > pointCloudLayer;
362 pointCloudLayer = std::make_unique< QgsPointCloudLayer >( uri, name, provider, pointCloudOptions );
366 pointCloudLayer = std::make_unique< QgsPointCloudLayer >( uri, name, QStringLiteral(
"pdal" ), pointCloudOptions );
368 if ( pointCloudLayer->isValid() )
370 return pointCloudLayer.release();
378 if (
string.isEmpty() )
386 if (
auto *lProject = context.
project() )
388 QgsMapLayer *layer = mapLayerFromStore(
string, lProject->layerStore(), typeHint );
397 if ( !allowLoadingNewLayers )
400 layer = loadMapLayerFromString(
string, context.
transformContext(), typeHint );
414 QVariant val = value;
415 bool selectedFeaturesOnly =
false;
416 long long featureLimit = -1;
417 bool overrideGeometryCheck =
false;
426 overrideGeometryCheck = fromVar.
flags & QgsProcessingFeatureSourceDefinition::Flag::FlagOverrideDefaultGeometryCheck;
436 if (
QgsVectorLayer *layer = qobject_cast< QgsVectorLayer * >( qvariant_cast<QObject *>( val ) ) )
438 std::unique_ptr< QgsProcessingFeatureSource> source = std::make_unique< QgsProcessingFeatureSource >( layer, context,
false, featureLimit );
439 if ( overrideGeometryCheck )
440 source->setInvalidGeometryCheck( geometryCheck );
441 return source.release();
449 else if ( !val.isValid() || val.toString().isEmpty() )
452 if (
QgsVectorLayer *layer = qobject_cast< QgsVectorLayer * >( qvariant_cast<QObject *>( fallbackValue ) ) )
454 std::unique_ptr< QgsProcessingFeatureSource> source = std::make_unique< QgsProcessingFeatureSource >( layer, context,
false, featureLimit );
455 if ( overrideGeometryCheck )
456 source->setInvalidGeometryCheck( geometryCheck );
457 return source.release();
460 layerRef = fallbackValue.toString();
464 layerRef = val.toString();
467 if ( layerRef.isEmpty() )
474 std::unique_ptr< QgsProcessingFeatureSource> source;
475 if ( selectedFeaturesOnly )
481 source = std::make_unique< QgsProcessingFeatureSource >( vl, context,
false, featureLimit );
484 if ( overrideGeometryCheck )
485 source->setInvalidGeometryCheck( geometryCheck );
486 return source.release();
491 QVariant val = value;
517 if (
QgsMapLayer *layer = qobject_cast< QgsMapLayer * >( qvariant_cast<QObject *>( val ) ) )
523 if ( !val.isValid() )
529 QString crsText = val.toString();
530 if ( crsText.isEmpty() )
531 crsText = fallbackValue.toString();
533 if ( crsText.isEmpty() )
537 if ( context.
project() && crsText.compare( QLatin1String(
"ProjectCrs" ), Qt::CaseInsensitive ) == 0 )
550 bool QgsProcessingUtils::canUseLayer(
const QgsMeshLayer *layer )
555 bool QgsProcessingUtils::canUseLayer(
const QgsPluginLayer *layer )
557 return layer && layer->
isValid();
562 return layer && layer->
isValid();
565 bool QgsProcessingUtils::canUseLayer(
const QgsRasterLayer *layer )
567 return layer && layer->
isValid();
572 return layer && layer->
isValid();
577 return layer && layer->
isValid();
580 bool QgsProcessingUtils::canUseLayer(
const QgsVectorLayer *layer,
const QList<int> &sourceTypes )
582 return layer && layer->
isValid() &&
583 ( sourceTypes.isEmpty()
594 QString normalized = source;
595 normalized.replace(
'\\',
'/' );
596 return normalized.trimmed();
601 if ( !value.isValid() )
602 return QStringLiteral(
"None" );
605 return QStringLiteral(
"QgsProperty.fromExpression('%1')" ).arg( value.value<
QgsProperty >().
asExpression() );
609 return QStringLiteral(
"QgsCoordinateReferenceSystem()" );
643 switch ( value.type() )
646 return value.toBool() ? QStringLiteral(
"True" ) : QStringLiteral(
"False" );
648 case QVariant::Double:
649 return QString::number( value.toDouble() );
653 return QString::number( value.toInt() );
655 case QVariant::LongLong:
656 case QVariant::ULongLong:
657 return QString::number( value.toLongLong() );
662 const QVariantList vl = value.toList();
663 for (
const QVariant &v : vl )
667 return parts.join(
',' ).prepend(
'[' ).append(
']' );
672 const QVariantMap map = value.toMap();
674 parts.reserve( map.size() );
675 for (
auto it = map.constBegin(); it != map.constEnd(); ++it )
679 return parts.join(
',' ).prepend(
'{' ).append(
'}' );
682 case QVariant::DateTime:
684 const QDateTime dateTime = value.toDateTime();
685 return QStringLiteral(
"QDateTime(QDate(%1, %2, %3), QTime(%4, %5, %6))" )
686 .arg( dateTime.date().year() )
687 .arg( dateTime.date().month() )
688 .arg( dateTime.date().day() )
689 .arg( dateTime.time().hour() )
690 .arg( dateTime.time().minute() )
691 .arg( dateTime.time().second() );
704 s.replace(
'\\', QLatin1String(
"\\\\" ) );
705 s.replace(
'\n', QLatin1String(
"\\n" ) );
706 s.replace(
'\r', QLatin1String(
"\\r" ) );
707 s.replace(
'\t', QLatin1String(
"\\t" ) );
709 if ( s.contains(
'\'' ) && !s.contains(
'\"' ) )
711 s = s.prepend(
'"' ).append(
'"' );
715 s.replace(
'\'', QLatin1String(
"\\\'" ) );
716 s = s.prepend(
'\'' ).append(
'\'' );
721 void QgsProcessingUtils::parseDestinationString( QString &destination, QString &providerKey, QString &uri, QString &layerName, QString &format, QMap<QString, QVariant> &options,
bool &useWriter, QString &extension )
728 QRegularExpression splitRx( QStringLiteral(
"^(.{3,}?):(.*)$" ) );
729 QRegularExpressionMatch match = splitRx.match( destination );
730 if ( match.hasMatch() )
732 providerKey = match.captured( 1 );
733 uri = match.captured( 2 );
740 if ( providerKey == QLatin1String(
"postgis" ) )
742 providerKey = QStringLiteral(
"postgres" );
744 if ( providerKey == QLatin1String(
"ogr" ) )
747 if ( !dsUri.database().isEmpty() )
749 if ( !dsUri.table().isEmpty() )
751 layerName = dsUri.table();
752 options.insert( QStringLiteral(
"layerName" ), layerName );
754 uri = dsUri.database();
755 extension = QFileInfo( uri ).completeSuffix();
757 options.insert( QStringLiteral(
"driverName" ), format );
761 extension = QFileInfo( uri ).completeSuffix();
764 options.insert( QStringLiteral(
"update" ),
true );
771 providerKey = QStringLiteral(
"ogr" );
773 QRegularExpression splitRx( QStringLiteral(
"^(.*)\\.(.*?)$" ) );
774 QRegularExpressionMatch match = splitRx.match( destination );
775 if ( match.hasMatch() )
777 extension = match.captured( 2 );
781 if ( format.isEmpty() )
783 format = QStringLiteral(
"GPKG" );
784 destination = destination + QStringLiteral(
".gpkg" );
787 options.insert( QStringLiteral(
"driverName" ), format );
794 QVariantMap options = createOptions;
795 if ( !options.contains( QStringLiteral(
"fileEncoding" ) ) )
801 if ( destination.isEmpty() || destination.startsWith( QLatin1String(
"memory:" ) ) )
804 if ( destination.startsWith( QLatin1String(
"memory:" ) ) )
805 destination = destination.mid( 7 );
807 if ( destination.isEmpty() )
808 destination = QStringLiteral(
"output" );
812 if ( !layer || !layer->isValid() )
820 destination = layer->id();
823 std::unique_ptr< QgsProcessingFeatureSink > sink(
new QgsProcessingFeatureSink( layer->dataProvider(), destination, context ) );
826 return sink.release();
835 bool useWriter =
false;
836 parseDestinationString( destination, providerKey, uri, layerName, format, options, useWriter, extension );
839 if ( useWriter && providerKey == QLatin1String(
"ogr" ) )
843 QString finalFileName;
844 QString finalLayerName;
846 saveOptions.
fileEncoding = options.value( QStringLiteral(
"fileEncoding" ) ).toString();
847 saveOptions.
layerName = !layerName.isEmpty() ? layerName : options.value( QStringLiteral(
"layerName" ) ).toString();
852 if ( remappingDefinition )
856 std::unique_ptr< QgsVectorLayer > vl = std::make_unique< QgsVectorLayer >( destination );
861 newFields = vl->fields();
871 if ( writer->hasError() )
873 throw QgsProcessingException( QObject::tr(
"Could not create layer %1: %2" ).arg( destination, writer->errorMessage() ) );
875 destination = finalFileName;
876 if ( !saveOptions.
layerName.isEmpty() && !finalLayerName.isEmpty() )
877 destination += QStringLiteral(
"|layername=%1" ).arg( finalLayerName );
879 if ( remappingDefinition )
881 std::unique_ptr< QgsRemappingProxyFeatureSink > remapSink = std::make_unique< QgsRemappingProxyFeatureSink >( *remappingDefinition, writer.release(),
true );
892 if ( remappingDefinition )
897 if ( !layerName.isEmpty() )
900 parts.insert( QStringLiteral(
"layerName" ), layerName );
904 std::unique_ptr< QgsVectorLayer > layer = std::make_unique<QgsVectorLayer>( uri, destination, providerKey, layerOptions );
906 destination = layer->id();
907 if ( layer->isValid() )
914 std::unique_ptr< QgsRemappingProxyFeatureSink > remapSink = std::make_unique< QgsRemappingProxyFeatureSink >( *remappingDefinition, layer->dataProvider(),
false );
924 std::unique_ptr< QgsVectorLayerExporter > exporter = std::make_unique<QgsVectorLayerExporter>( uri, providerKey, newFields, geometryType,
crs,
true, options, sinkFlags );
925 if ( exporter->errorCode() != Qgis::VectorExportResult::Success )
927 throw QgsProcessingException( QObject::tr(
"Could not create layer %1: %2" ).arg( destination, exporter->errorMessage() ) );
931 if ( !layerName.isEmpty() )
933 uri += QStringLiteral(
"|layername=%1" ).arg( layerName );
992 if ( !input.isValid() )
993 return QStringLiteral(
"memory:%1" ).arg(
id.toString() );
1009 QString res = input.toString();
1015 else if ( res.startsWith( QLatin1String(
"memory:" ) ) )
1017 return QString( res +
'_' +
id.toString() );
1023 int lastIndex = res.lastIndexOf(
'.' );
1024 return lastIndex >= 0 ? QString( res.left( lastIndex ) +
'_' +
id.toString() + res.mid( lastIndex ) ) : QString( res +
'_' +
id.toString() );
1035 static std::vector< std::unique_ptr< QTemporaryDir > > sTempFolders;
1036 static QString sFolder;
1037 static QMutex sMutex;
1038 QMutexLocker locker( &sMutex );
1040 if ( basePath.isEmpty() )
1043 if ( sTempFolders.empty() )
1045 const QString templatePath = QStringLiteral(
"%1/processing_XXXXXX" ).arg( QDir::tempPath() );
1046 std::unique_ptr< QTemporaryDir >
tempFolder = std::make_unique< QTemporaryDir >( templatePath );
1048 sTempFolders.emplace_back( std::move(
tempFolder ) );
1051 else if ( sFolder.isEmpty() || !sFolder.startsWith( basePath ) || sTempFolders.empty() )
1053 if ( !QDir().exists( basePath ) )
1054 QDir().mkpath( basePath );
1056 const QString templatePath = QStringLiteral(
"%1/processing_XXXXXX" ).arg( basePath );
1057 std::unique_ptr< QTemporaryDir >
tempFolder = std::make_unique< QTemporaryDir >( templatePath );
1059 sTempFolders.emplace_back( std::move(
tempFolder ) );
1066 QString subPath = QUuid::createUuid().toString().remove(
'-' ).remove(
'{' ).remove(
'}' );
1068 if ( !QDir( path ).exists() )
1071 tmpDir.mkdir( path );
1078 auto getText = [map](
const QString & key )->QString
1080 if ( map.contains( key ) )
1081 return map.value( key ).toString();
1086 s += QStringLiteral(
"<html><body><p>" ) + getText( QStringLiteral(
"ALG_DESC" ) ) + QStringLiteral(
"</p>\n" );
1095 if ( !getText( def->name() ).isEmpty() )
1097 inputs += QStringLiteral(
"<h3>" ) + def->description() + QStringLiteral(
"</h3>\n" );
1098 inputs += QStringLiteral(
"<p>" ) + getText( def->name() ) + QStringLiteral(
"</p>\n" );
1101 if ( !inputs.isEmpty() )
1102 s += QStringLiteral(
"<h2>" ) + QObject::tr(
"Input parameters" ) + QStringLiteral(
"</h2>\n" ) + inputs;
1108 if ( !getText( def->name() ).isEmpty() )
1110 outputs += QStringLiteral(
"<h3>" ) + def->description() + QStringLiteral(
"</h3>\n" );
1111 outputs += QStringLiteral(
"<p>" ) + getText( def->name() ) + QStringLiteral(
"</p>\n" );
1114 if ( !outputs.isEmpty() )
1115 s += QStringLiteral(
"<h2>" ) + QObject::tr(
"Outputs" ) + QStringLiteral(
"</h2>\n" ) + outputs;
1117 if ( !map.value( QStringLiteral(
"EXAMPLES" ) ).toString().isEmpty() )
1118 s += QStringLiteral(
"<h2>%1</h2>\n<p>%2</p>" ).arg( QObject::tr(
"Examples" ), getText( QStringLiteral(
"EXAMPLES" ) ) );
1120 s += QLatin1String(
"<br>" );
1121 if ( !map.value( QStringLiteral(
"ALG_CREATOR" ) ).toString().isEmpty() )
1122 s += QStringLiteral(
"<p align=\"right\">" ) + QObject::tr(
"Algorithm author:" ) + QStringLiteral(
" " ) + getText( QStringLiteral(
"ALG_CREATOR" ) ) + QStringLiteral(
"</p>" );
1123 if ( !map.value( QStringLiteral(
"ALG_HELP_CREATOR" ) ).toString().isEmpty() )
1124 s += QStringLiteral(
"<p align=\"right\">" ) + QObject::tr(
"Help author:" ) + QStringLiteral(
" " ) + getText( QStringLiteral(
"ALG_HELP_CREATOR" ) ) + QStringLiteral(
"</p>" );
1125 if ( !map.value( QStringLiteral(
"ALG_VERSION" ) ).toString().isEmpty() )
1126 s += QStringLiteral(
"<p align=\"right\">" ) + QObject::tr(
"Algorithm version:" ) + QStringLiteral(
" " ) + getText( QStringLiteral(
"ALG_VERSION" ) ) + QStringLiteral(
"</p>" );
1128 s += QLatin1String(
"</body></html>" );
1133 long long featureLimit )
1135 bool requiresTranslation =
false;
1139 requiresTranslation = requiresTranslation || selectedFeaturesOnly;
1142 requiresTranslation = requiresTranslation || featureLimit != -1;
1147 requiresTranslation = requiresTranslation || vl->
providerType() != QLatin1String(
"ogr" );
1151 requiresTranslation = requiresTranslation || !vl->
subsetString().isEmpty();
1155 requiresTranslation = requiresTranslation || vl->
source().startsWith( QLatin1String(
"/vsi" ) );
1159 if ( !requiresTranslation )
1162 if ( parts.contains( QStringLiteral(
"path" ) ) )
1164 diskPath = parts.value( QStringLiteral(
"path" ) ).toString();
1165 QFileInfo fi( diskPath );
1166 requiresTranslation = !compatibleFormats.contains( fi.suffix(), Qt::CaseInsensitive );
1170 const QString srcLayerName = parts.value( QStringLiteral(
"layerName" ) ).toString();
1174 *layerName = srcLayerName;
1179 requiresTranslation = requiresTranslation || ( !srcLayerName.isEmpty() && srcLayerName != fi.baseName() );
1184 requiresTranslation =
true;
1188 if ( requiresTranslation )
1198 if ( featureLimit != -1 )
1200 if ( selectedFeaturesOnly )
1207 if ( selectedFeaturesOnly )
1235 return convertToCompatibleFormatInternal( layer, selectedFeaturesOnly, baseName, compatibleFormats, preferredFormat, context, feedback, &layerName, featureLimit );
1241 QSet< QString > usedNames;
1242 for (
const QgsField &f : fieldsA )
1244 usedNames.insert( f.name().toLower() );
1247 for (
const QgsField &f : fieldsB )
1250 newField.
setName( fieldsBPrefix + f.name() );
1251 if ( usedNames.contains( newField.
name().toLower() ) )
1254 QString newName = newField.
name() +
'_' + QString::number( idx );
1255 while ( usedNames.contains( newName.toLower() ) || fieldsB.indexOf( newName ) != -1 )
1258 newName = newField.
name() +
'_' + QString::number( idx );
1261 outFields.
append( newField );
1265 outFields.
append( newField );
1267 usedNames.insert( newField.
name() );
1277 if ( !fieldNames.isEmpty() )
1279 indices.reserve( fieldNames.count() );
1280 for (
const QString &f : fieldNames )
1284 indices.append( idx );
1289 indices.reserve( fields.
count() );
1290 for (
int i = 0; i < fields.
count(); ++i )
1291 indices.append( i );
1300 for (
int i : indices )
1301 fieldsSubset.
append( fields.
at( i ) );
1302 return fieldsSubset;
1308 if ( setting == -1 )
1309 return QStringLiteral(
"gpkg" );
1316 if ( setting == -1 )
1317 return QStringLiteral(
"tif" );
1323 return QStringLiteral(
"las" );
1328 auto layerPointerToString = [](
QgsMapLayer * layer ) -> QString
1330 if ( layer && layer->
providerType() == QLatin1String(
"memory" ) )
1338 auto cleanPointerValues = [&layerPointerToString](
const QVariant & value ) -> QVariant
1340 if (
QgsMapLayer *layer = qobject_cast< QgsMapLayer * >( value.value< QObject * >() ) )
1343 return layerPointerToString( layer );
1345 else if ( value.userType() == QMetaType::type(
"QPointer< QgsMapLayer >" ) )
1348 return layerPointerToString( value.value< QPointer< QgsMapLayer > >().data() );
1357 for (
auto it = map.constBegin(); it != map.constEnd(); ++it )
1359 if ( it->type() == QVariant::Map )
1363 else if ( it->type() == QVariant::List )
1366 const QVariantList source = it.value().toList();
1367 dest.reserve( source.size() );
1368 for (
const QVariant &v : source )
1370 dest.append( cleanPointerValues( v ) );
1372 res.insert( it.key(), dest );
1376 res.insert( it.key(), cleanPointerValues( it.value() ) );
1387 : mSource( originalSource )
1388 , mOwnsSource( ownsOriginalSource )
1391 : context.invalidGeometryCheck() )
1392 , mInvalidGeometryCallback( context.invalidGeometryCallback( originalSource ) )
1393 , mTransformErrorCallback( context.transformErrorCallback() )
1394 , mInvalidGeometryCallbackSkip( context.defaultInvalidGeometryCallbackForCheck(
QgsFeatureRequest::GeometrySkipInvalid, originalSource ) )
1395 , mInvalidGeometryCallbackAbort( context.defaultInvalidGeometryCallbackForCheck(
QgsFeatureRequest::GeometryAbortOnInvalid, originalSource ) )
1396 , mFeatureLimit( featureLimit )
1418 if ( mFeatureLimit != -1 && req.
limit() != -1 )
1419 req.
setLimit( std::min(
static_cast< long long >( req.
limit() ), mFeatureLimit ) );
1420 else if ( mFeatureLimit != -1 )
1432 return sourceAvailability;
1445 if ( mFeatureLimit != -1 && req.
limit() != -1 )
1446 req.
setLimit( std::min(
static_cast< long long >( req.
limit() ), mFeatureLimit ) );
1447 else if ( mFeatureLimit != -1 )
1460 return mSource->
fields();
1470 if ( mFeatureLimit == -1 )
1473 return std::min( mFeatureLimit, mSource->
featureCount() );
1520 return expressionContextScope;
1525 mInvalidGeometryCheck = method;
1526 switch ( mInvalidGeometryCheck )
1529 mInvalidGeometryCallback =
nullptr;
1533 mInvalidGeometryCallback = mInvalidGeometryCallbackSkip;
1537 mInvalidGeometryCallback = mInvalidGeometryCallbackAbort;
1549 , mContext( context )
1550 , mSinkName( sinkName )
1551 , mOwnsSink( ownsOriginalSink )
1563 if ( !result && mContext.
feedback() )
1566 if ( !error.isEmpty() )
1567 mContext.
feedback()->
reportError( QObject::tr(
"Feature could not be written to %1: %2" ).arg( mSinkName, error ) );
1569 mContext.
feedback()->
reportError( QObject::tr(
"Feature could not be written to %1" ).arg( mSinkName ) );
1577 if ( !result && mContext.
feedback() )
1580 if ( !error.isEmpty() )
1581 mContext.
feedback()->
reportError( QObject::tr(
"%n feature(s) could not be written to %1: %2",
nullptr, features.count() ).arg( mSinkName, error ) );
1583 mContext.
feedback()->
reportError( QObject::tr(
"%n feature(s) could not be written to %1",
nullptr, features.count() ).arg( mSinkName ) );
1591 if ( !result && mContext.
feedback() )
1594 if ( !error.isEmpty() )
1595 mContext.
feedback()->
reportError( QObject::tr(
"Features could not be written to %1: %2" ).arg( mSinkName, error ) );
1597 mContext.
feedback()->
reportError( QObject::tr(
"Features could not be written to %1" ).arg( mSinkName ) );