87
87
#include "qgssourceselectproviderregistry.h"
88
88
#include "qgssourceselectprovider.h"
89
89
#include "qgsprovidermetadata.h"
90
+ #include "qgsattributedialog.h"
90
91
91
92
#include "qgsanalysis.h"
92
93
#include "qgsgeometrycheckregistry.h"
@@ -9588,6 +9589,45 @@ void QgisApp::pasteFromClipboard( QgsMapLayer *destinationLayer )
9588
9589
// now create new feature using pasted feature as a template. This automatically handles default
9589
9590
// values and field constraints
9590
9591
QgsFeatureList newFeatures {QgsVectorLayerUtils::createFeatures( pasteVectorLayer, newFeaturesDataList, &context )};
9592
+
9593
+ // check against hard constraints
9594
+ for ( QgsFeature &f : newFeatures )
9595
+ {
9596
+ bool valid = true;
9597
+ for ( int idx = 0; idx < pasteVectorLayer->fields().count(); ++idx )
9598
+ {
9599
+ QStringList errors;
9600
+ valid = QgsVectorLayerUtils::validateAttribute( pasteVectorLayer, f, idx, errors, QgsFieldConstraints::ConstraintStrengthHard, QgsFieldConstraints::ConstraintOriginNotSet );
9601
+ if ( !valid )
9602
+ {
9603
+ break;
9604
+ }
9605
+ }
9606
+
9607
+ //open attribute form including option "cancel copy all" / "cancel copy of invalid" / "store invalid features"
9608
+ if ( !valid )
9609
+ {
9610
+ //QgsFeatureAction action( tr( "Fix feature" ), f, pasteVectorLayer, QString(), -1, QgisApp::instance() );
9611
+ //action.editFeature( true );
9612
+ QgsAttributeDialog *dialog = new QgsAttributeDialog( pasteVectorLayer, &f, false );
9613
+
9614
+ if ( !f.isValid() )
9615
+ dialog->setMode( QgsAttributeEditorContext::AddFeatureMode );
9616
+
9617
+ int feedback = dialog->exec();
9618
+
9619
+ if ( feedback > 0 )
9620
+ {
9621
+ f.setAttributes( dialog->feature()->attributes() );
9622
+ }
9623
+ else
9624
+ {
9625
+ visibleMessageBar()->pushMessage( tr( "Paste features" ), tr( "Do not copy feature" ), Qgis::Warning, messageTimeout() );
9626
+ newFeatures.removeOne( f );
9627
+ }
9628
+ }
9629
+ }
9630
+
9591
9631
pasteVectorLayer->addFeatures( newFeatures );
9592
9632
QgsFeatureIds newIds;
9593
9633
newIds.reserve( newFeatures.size() );
@@ -9600,7 +9640,7 @@ void QgisApp::pasteFromClipboard( QgsMapLayer *destinationLayer )
9600
9640
pasteVectorLayer->endEditCommand();
9601
9641
pasteVectorLayer->updateExtents();
9602
9642
9603
- int nCopiedFeatures = features .count();
9643
+ int nCopiedFeatures = newFeatures .count();
9604
9644
Qgis::MessageLevel level = ( nCopiedFeatures == 0 || nCopiedFeatures < nTotalFeatures || invalidGeometriesCount > 0 ) ? Qgis::Warning : Qgis::Info;
9605
9645
QString message;
9606
9646
if ( nCopiedFeatures == 0 )
0 commit comments