Skip to content
Permalink
Browse files

Fix pasting features - only a single insert operation, no unnecessary…

… updates
  • Loading branch information
suricactus committed Jul 15, 2020
1 parent 66b9f03 commit 0772c7851258bbdb130a4789d764291b38adddc6
Showing with 22 additions and 3 deletions.
  1. +1 −1 src/app/qgsfixattributedialog.cpp
  2. +1 −0 src/gui/qgsattributeeditorcontext.h
  3. +20 −2 src/gui/qgsattributeform.cpp
@@ -52,7 +52,7 @@ void QgsFixAttributeDialog::init( QgsVectorLayer *layer, const QgsAttributeEdito
infoLayout->addWidget( mProgressBar );
QgsFeature feature;
mAttributeForm = new QgsAttributeForm( layer, *mCurrentFeature, context, this );
mAttributeForm->setMode( QgsAttributeEditorContext::SingleEditMode );
mAttributeForm->setMode( QgsAttributeEditorContext::FixAttributeMode );
mAttributeForm->disconnectButtonBox();
layout()->addWidget( mAttributeForm );

@@ -49,6 +49,7 @@ class GUI_EXPORT QgsAttributeEditorContext
SingleEditMode, //!< Single edit mode, for editing a single feature
AddFeatureMode, /*!< Add feature mode, for setting attributes for a new feature. In this mode the dialog will be editable even with an invalid feature and
will add a new feature when the form is accepted. */
FixAttributeMode, //!< Fix feature mode, for modifying the feature attributes without saving. The updated feature is available via `feature()` after `save()`
MultiEditMode, //!< Multi edit mode, for editing fields of multiple features at once
SearchMode, //!< Form values are used for searching/filtering the layer
AggregateSearchMode, //!< Form is in aggregate search mode, show each widget in this mode \since QGIS 3.0
@@ -173,6 +173,10 @@ void QgsAttributeForm::setMode( QgsAttributeEditorContext::Mode mode )
w->setMode( QgsAttributeFormWidget::DefaultMode );
break;

case QgsAttributeEditorContext::FixAttributeMode:
w->setMode( QgsAttributeFormWidget::DefaultMode );
break;

case QgsAttributeEditorContext::MultiEditMode:
w->setMode( QgsAttributeFormWidget::MultiEditMode );
break;
@@ -216,6 +220,11 @@ void QgsAttributeForm::setMode( QgsAttributeEditorContext::Mode mode )
mSearchButtonBox->setVisible( false );
break;

case QgsAttributeEditorContext::FixAttributeMode:
synchronizeEnabledState();
mSearchButtonBox->setVisible( false );
break;

case QgsAttributeEditorContext::MultiEditMode:
resetMultiEdit( false );
synchronizeEnabledState();
@@ -278,6 +287,7 @@ void QgsAttributeForm::setFeature( const QgsFeature &feature )
case QgsAttributeEditorContext::SingleEditMode:
case QgsAttributeEditorContext::IdentifyMode:
case QgsAttributeEditorContext::AddFeatureMode:
case QgsAttributeEditorContext::FixAttributeMode:
{
resetValues();

@@ -320,7 +330,7 @@ bool QgsAttributeForm::saveEdits()

// An add dialog should perform an action by default
// and not only if attributes have "changed"
if ( mMode == QgsAttributeEditorContext::AddFeatureMode )
if ( mMode == QgsAttributeEditorContext::AddFeatureMode || mMode == QgsAttributeEditorContext::FixAttributeMode )
doUpdate = true;

QgsAttributes src = mFeature.attributes();
@@ -379,7 +389,11 @@ bool QgsAttributeForm::saveEdits()

if ( doUpdate )
{
if ( mMode == QgsAttributeEditorContext::AddFeatureMode )
if ( mMode == QgsAttributeEditorContext::FixAttributeMode )
{
mFeature = updatedFeature;
}
else if ( mMode == QgsAttributeEditorContext::AddFeatureMode )
{
mFeature.setValid( true );
mLayer->beginEditCommand( mEditCommandMessage );
@@ -735,6 +749,7 @@ bool QgsAttributeForm::save()
{
case QgsAttributeEditorContext::SingleEditMode:
case QgsAttributeEditorContext::IdentifyMode:
case QgsAttributeEditorContext::FixAttributeMode:
case QgsAttributeEditorContext::MultiEditMode:
if ( !mDirty )
return true;
@@ -761,6 +776,7 @@ bool QgsAttributeForm::save()
case QgsAttributeEditorContext::SingleEditMode:
case QgsAttributeEditorContext::IdentifyMode:
case QgsAttributeEditorContext::AddFeatureMode:
case QgsAttributeEditorContext::FixAttributeMode:
case QgsAttributeEditorContext::SearchMode:
case QgsAttributeEditorContext::AggregateSearchMode:
success = saveEdits();
@@ -848,6 +864,7 @@ void QgsAttributeForm::onAttributeChanged( const QVariant &value, const QVariant
case QgsAttributeEditorContext::SingleEditMode:
case QgsAttributeEditorContext::IdentifyMode:
case QgsAttributeEditorContext::AddFeatureMode:
case QgsAttributeEditorContext::FixAttributeMode:
{
Q_NOWARN_DEPRECATED_PUSH
emit attributeChanged( eww->field().name(), value );
@@ -2264,6 +2281,7 @@ void QgsAttributeForm::layerSelectionChanged()
case QgsAttributeEditorContext::SingleEditMode:
case QgsAttributeEditorContext::IdentifyMode:
case QgsAttributeEditorContext::AddFeatureMode:
case QgsAttributeEditorContext::FixAttributeMode:
case QgsAttributeEditorContext::SearchMode:
case QgsAttributeEditorContext::AggregateSearchMode:
break;

0 comments on commit 0772c78

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