Skip to content
Permalink
Browse files

Merge pull request #37570 from signedav/copypaste-references

Fix attributes on copy paste while QGIS stays responsive
  • Loading branch information
signedav committed Jul 6, 2020
2 parents 6597b4a + dc0039a commit 7c89280a82d73b760a20faea86c15e5867ab9256
Showing with 46 additions and 24 deletions.
  1. +33 −16 src/app/qgisapp.cpp
  2. +7 −0 src/app/qgisapp.h
  3. +4 −6 src/app/qgsfixattributedialog.cpp
  4. +2 −2 src/app/qgsfixattributedialog.h
@@ -10221,26 +10221,43 @@ void QgisApp::pasteFromClipboard( QgsMapLayer *destinationLayer )
{
newFeatures.clear();

QgsFixAttributeDialog *dialog = new QgsFixAttributeDialog( pasteVectorLayer, invalidFeatures, this );
int feedback = dialog->exec();
QgsAttributeEditorContext context( createAttributeEditorContext() );
context.setAllowCustomUi( false );
context.setFormMode( QgsAttributeEditorContext::StandaloneDialog );

switch ( feedback )
QgsFixAttributeDialog *dialog = new QgsFixAttributeDialog( pasteVectorLayer, invalidFeatures, this, context );

connect( dialog, &QgsFixAttributeDialog::finished, this, [ = ]( int feedback )
{
case QgsFixAttributeDialog::PasteValid:
//paste valid and fixed, vanish unfixed
newFeatures << validFeatures << dialog->fixedFeatures();
break;
case QgsFixAttributeDialog::PasteAll:
//paste all, even unfixed
newFeatures << validFeatures << dialog->fixedFeatures() << dialog->unfixedFeatures();
break;
}
QgsFeatureList features = newFeatures;
switch ( feedback )
{
case QgsFixAttributeDialog::PasteValid:
//paste valid and fixed, vanish unfixed
features << validFeatures << dialog->fixedFeatures();
break;
case QgsFixAttributeDialog::PasteAll:
//paste all, even unfixed
features << validFeatures << dialog->fixedFeatures() << dialog->unfixedFeatures();
break;
}
pasteFeatures( pasteVectorLayer, invalidGeometriesCount, nTotalFeatures, features );
dialog->deleteLater();
} );
dialog->show();
return;
}
}
pasteVectorLayer->addFeatures( newFeatures );

pasteFeatures( pasteVectorLayer, invalidGeometriesCount, nTotalFeatures, newFeatures );
}

void QgisApp::pasteFeatures( QgsVectorLayer *pasteVectorLayer, int invalidGeometriesCount, int nTotalFeatures, QgsFeatureList &features )
{
pasteVectorLayer->addFeatures( features );
QgsFeatureIds newIds;
newIds.reserve( newFeatures.size() );
for ( const QgsFeature &f : qgis::as_const( newFeatures ) )
newIds.reserve( features.size() );
for ( const QgsFeature &f : qgis::as_const( features ) )
{
newIds << f.id();
}
@@ -10249,7 +10266,7 @@ void QgisApp::pasteFromClipboard( QgsMapLayer *destinationLayer )
pasteVectorLayer->endEditCommand();
pasteVectorLayer->updateExtents();

int nCopiedFeatures = newFeatures.count();
int nCopiedFeatures = features.count();
Qgis::MessageLevel level = ( nCopiedFeatures == 0 || invalidGeometriesCount > 0 ) ? Qgis::Warning : Qgis::Info;
QString message;
if ( nCopiedFeatures == 0 )
@@ -927,6 +927,7 @@ class APP_EXPORT QgisApp : public QMainWindow, private Ui::MainWindow
(defaults to the active layer on the legend)
*/
void pasteFromClipboard( QgsMapLayer *destinationLayer = nullptr );

//! copies features on the clipboard to a new vector layer
void pasteAsNewVector();
//! copies features on the clipboard to a new memory vector layer
@@ -2208,6 +2209,12 @@ class APP_EXPORT QgisApp : public QMainWindow, private Ui::MainWindow
*/
void resolveVectorLayerWeakRelations( QgsVectorLayer *vectorLayer );

/**
* Pastes the \a features to the \a pasteVectorLayer and gives feedback to the user
* according to \a invalidGeometryCount and \a nTotalFeatures
*/
void pasteFeatures( QgsVectorLayer *pasteVectorLayer, int invalidGeometriesCount, int nTotalFeatures, QgsFeatureList &features );


QgisAppStyleSheet *mStyleSheetBuilder = nullptr;

@@ -20,21 +20,19 @@

#include <QtWidgets/QPushButton>

QgsFixAttributeDialog::QgsFixAttributeDialog( QgsVectorLayer *vl, QgsFeatureList &features, QWidget *parent )

QgsFixAttributeDialog::QgsFixAttributeDialog( QgsVectorLayer *vl, QgsFeatureList &features, QWidget *parent, const QgsAttributeEditorContext &context )
: QDialog( parent )
, mFeatures( features )
{
init( vl );
init( vl, context );
}

void QgsFixAttributeDialog::init( QgsVectorLayer *layer )
void QgsFixAttributeDialog::init( QgsVectorLayer *layer, const QgsAttributeEditorContext &context )
{
QgsAttributeEditorContext context;
setWindowTitle( tr( "%1 - Fix Pasted Features" ).arg( layer->name() ) );
setLayout( new QGridLayout() );
layout()->setMargin( 0 );
context.setFormMode( QgsAttributeEditorContext::StandaloneDialog );
context.setVectorLayerTools( QgisApp::instance()->vectorLayerTools() );

mUnfixedFeatures = mFeatures;
mCurrentFeature = mFeatures.begin();
@@ -52,7 +52,7 @@ class APP_EXPORT QgsFixAttributeDialog : public QDialog
/**
* Constructor for QgsFixAttributeDialog
*/
QgsFixAttributeDialog( QgsVectorLayer *vl, QgsFeatureList &features, QWidget *parent SIP_TRANSFERTHIS = nullptr );
QgsFixAttributeDialog( QgsVectorLayer *vl, QgsFeatureList &features, QWidget *parent SIP_TRANSFERTHIS = nullptr, const QgsAttributeEditorContext &context = QgsAttributeEditorContext() );

/**
* Returns fixed features
@@ -69,7 +69,7 @@ class APP_EXPORT QgsFixAttributeDialog : public QDialog
void reject() override;

private:
void init( QgsVectorLayer *layer );
void init( QgsVectorLayer *layer, const QgsAttributeEditorContext &context );
QString descriptionText();

QgsFeatureList mFeatures;

0 comments on commit 7c89280

Please sign in to comment.
You can’t perform that action at this time.