19#include "moc_qgsvectorlayertools.cpp"
41 int browsedFeatureCount = 0;
42 int couldNotWriteCount = 0;
43 int noGeometryCount = 0;
47 QMap<QString, int> duplicateFeatureCount;
50 browsedFeatureCount++;
66 QgsDebugError( QStringLiteral(
"Could not add new feature. Original copied feature id: %1" ).arg( f.
id() ) );
70 fidList.insert( newFeature.
id() );
73 const auto duplicateFeatureContextLayers = duplicateFeatureContext.
layers();
76 if ( duplicateFeatureCount.contains( chl->name() ) )
78 duplicateFeatureCount[chl->name()] += duplicateFeatureContext.
duplicatedFeatures( chl ).size();
82 duplicateFeatureCount[chl->name()] = duplicateFeatureContext.
duplicatedFeatures( chl ).size();
92 QgsDebugError( QStringLiteral(
"Could not add new feature. Original copied feature id: %1" ).arg( f.
id() ) );
96 fidList.insert( newFeature.
id() );
104 if ( topologicalEditing )
106 if ( topologicalLayer )
119 QString childrenInfo;
120 for (
auto it = duplicateFeatureCount.constBegin(); it != duplicateFeatureCount.constEnd(); ++it )
122 childrenInfo += ( tr(
"\n%n children on layer %1 duplicated",
nullptr, it.value() ).arg( it.key() ) );
128 if ( childrenInfoMsg && !childrenInfo.isEmpty() )
130 childrenInfoMsg->append( childrenInfo );
133 if ( !couldNotWriteCount && !noGeometryCount )
139 errorMsg =
new QString( tr(
"Only %1 out of %2 features were copied." )
140 .arg( browsedFeatureCount - couldNotWriteCount - noGeometryCount, browsedFeatureCount ) );
141 if ( noGeometryCount )
143 errorMsg->append(
" " );
144 errorMsg->append( tr(
"Some features have no geometry." ) );
146 if ( couldNotWriteCount )
148 errorMsg->append(
" " );
149 errorMsg->append( tr(
"Some could not be created on the layer." ) );
157 return mForceSuppressFormPopup;
CORE_EXPORT QgsAttributeMap toMap() const
Returns a QgsAttributeMap of the attribute values.
Wrapper for iterator of features from vector data provider or vector layer.
bool nextFeature(QgsFeature &f)
Fetch next feature and stores in f, returns true on success.
This class wraps a request for features to a vector layer (or directly its vector data provider).
QgsFeatureRequest & setFilterFids(const QgsFeatureIds &fids)
Sets the feature IDs that should be fetched.
The feature class encapsulates a single feature including its unique ID, geometry and a list of field...
bool hasGeometry() const
Returns true if the feature has an associated geometry.
bool isValid() const
Returns the validity of this feature.
void setGeometry(const QgsGeometry &geometry)
Set the feature's geometry.
A geometry is the spatial representation of a feature.
Qgis::GeometryOperationResult translate(double dx, double dy, double dz=0.0, double dm=0.0)
Translates this geometry by dx, dy, dz and dm.
Contains mainly the QMap with QgsVectorLayer and QgsFeatureIds do list all the duplicated features.
QgsFeatureIds duplicatedFeatures(QgsVectorLayer *layer) const
Returns the duplicated features in the given layer.
QList< QgsVectorLayer * > layers() const
Returns all the layers on which features have been duplicated.
static QgsFeature duplicateFeature(QgsVectorLayer *layer, const QgsFeature &feature, QgsProject *project, QgsDuplicateFeatureContext &duplicateFeatureContext, const int maxDepth=0, int depth=0, QList< QgsVectorLayer * > referencedLayersBranch=QList< QgsVectorLayer * >())
Duplicates a feature and it's children (one level deep).
static QgsFeature createFeature(const QgsVectorLayer *layer, const QgsGeometry &geometry=QgsGeometry(), const QgsAttributeMap &attributes=QgsAttributeMap(), QgsExpressionContext *context=nullptr)
Creates a new feature ready for insertion into a layer.
Represents a vector layer which manages a vector based data sets.
QgsFeatureIterator getFeatures(const QgsFeatureRequest &request=QgsFeatureRequest()) const FINAL
Queries the layer for features specified in request.
bool isEditable() const FINAL
Returns true if the provider is in editing mode.
bool addFeature(QgsFeature &feature, QgsFeatureSink::Flags flags=QgsFeatureSink::Flags()) FINAL
Adds a single feature to the sink.
int addTopologicalPoints(const QgsGeometry &geom)
Adds topological points for every vertex of the geometry.
QSet< QgsFeatureId > QgsFeatureIds
#define QgsDebugError(str)