Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Merge pull request #52771 from domi4484/fixmergeid
  • Loading branch information
m-kuhn committed Apr 21, 2023
2 parents d9d41ad + 0ce567b commit 9423166
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 7 deletions.
4 changes: 1 addition & 3 deletions src/app/qgsmergeattributesdialog.cpp
Expand Up @@ -105,9 +105,6 @@ QgsMergeAttributesDialog::QgsMergeAttributesDialog( const QgsFeatureList &featur
break;
}

if ( ! mFeatureList.isEmpty() )
mTargetFeatureId = mFeatureList.first().id();

connect( mSkipAllButton, &QAbstractButton::clicked, this, &QgsMergeAttributesDialog::setAllToSkip );
connect( mTableWidget, &QTableWidget::cellChanged, this, &QgsMergeAttributesDialog::tableWidgetCellChanged );

Expand Down Expand Up @@ -233,6 +230,7 @@ void QgsMergeAttributesDialog::createTableWidgetContents()
{
int idx = mTableWidget->horizontalHeaderItem( j )->data( FieldIndex ).toInt();
bool setToManual = false;

if ( !mVectorLayer->dataProvider()->defaultValueClause( idx ).isEmpty() )
{
mTableWidget->item( mTableWidget->rowCount() - 1, j )->setData( Qt::DisplayRole, mVectorLayer->dataProvider()->defaultValueClause( idx ) );
Expand Down
14 changes: 11 additions & 3 deletions src/core/vector/qgsvectorlayereditutils.cpp
Expand Up @@ -910,10 +910,18 @@ bool QgsVectorLayerEditUtils::mergeFeatures( const QgsFeatureId &targetFeatureId
mLayer->deleteFeature( *feature_it );
}

// Modify merge feature
// Modify target feature or create a new one if invalid
QgsGeometry mergeGeometry = unionGeometry;
mLayer->changeGeometry( targetFeatureId, mergeGeometry );
mLayer->changeAttributeValues( targetFeatureId, newAttributes );
if ( targetFeatureId == FID_NULL )
{
QgsFeature mergeFeature = QgsVectorLayerUtils::createFeature( mLayer, mergeGeometry, newAttributes );
mLayer->addFeature( mergeFeature );
}
else
{
mLayer->changeGeometry( targetFeatureId, mergeGeometry );
mLayer->changeAttributeValues( targetFeatureId, newAttributes );
}

mLayer->endEditCommand();

Expand Down
4 changes: 3 additions & 1 deletion tests/src/app/testqgsmergeattributesdialog.cpp
Expand Up @@ -85,11 +85,13 @@ class TestQgsMergeattributesDialog : public QObject
QgsMergeAttributesDialog dialog( QgsFeatureList() << f1 << f2, &layer, mQgisApp->mapCanvas() );

// At beginnning the first feature of the list is the target
QCOMPARE( dialog.targetFeatureId(), f1.id() );
QCOMPARE( dialog.targetFeatureId(), FID_NULL );
QCOMPARE( dialog.mergedAttributes().first(), "Autogenerate" );

// Check after taking feature with largest geometry
QVERIFY( QMetaObject::invokeMethod( &dialog, "mFromLargestPushButton_clicked" ) );
QCOMPARE( dialog.targetFeatureId(), f2.id() );
QCOMPARE( dialog.mergedAttributes().first(), f2.id() );
}
};

Expand Down

0 comments on commit 9423166

Please sign in to comment.