Skip to content

Commit 0bda18b

Browse files
committed
Fix merge attributes tool sets skipped attributes to null (fix #13231)
1 parent 46f0730 commit 0bda18b

File tree

3 files changed

+32
-3
lines changed

3 files changed

+32
-3
lines changed

src/app/qgisapp.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6150,11 +6150,15 @@ void QgisApp::mergeAttributesOfSelectedFeatures()
61506150
vl->beginEditCommand( tr( "Merged feature attributes" ) );
61516151

61526152
QgsAttributes merged = d.mergedAttributes();
6153+
QSet<int> toSkip = d.skippedAttributeIndexes();
61536154

61546155
Q_FOREACH ( QgsFeatureId fid, vl->selectedFeaturesIds() )
61556156
{
61566157
for ( int i = 0; i < merged.count(); ++i )
61576158
{
6159+
if ( toSkip.contains( i ) )
6160+
continue;
6161+
61586162
vl->changeAttributeValue( fid, i, merged.at( i ) );
61596163
}
61606164
}

src/app/qgsmergeattributesdialog.cpp

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -586,8 +586,6 @@ QgsAttributes QgsMergeAttributesDialog::mergedAttributes() const
586586
return QgsAttributes();
587587
}
588588

589-
QgsFields fields = mVectorLayer->fields();
590-
591589
QgsAttributes results( mTableWidget->columnCount() );
592590
for ( int i = 0; i < mTableWidget->columnCount(); i++ )
593591
{
@@ -604,7 +602,7 @@ QgsAttributes QgsMergeAttributesDialog::mergedAttributes() const
604602
if ( idx >= results.count() )
605603
results.resize( idx + 1 ); // make sure the results vector is long enough (maybe not necessary)
606604

607-
if ( comboBox->itemData( comboBox->currentIndex() ) != "skip" )
605+
if ( comboBox->itemData( comboBox->currentIndex() ).toString() != "skip" )
608606
{
609607
results[idx] = currentItem->data( Qt::DisplayRole );
610608
}
@@ -616,3 +614,25 @@ QgsAttributes QgsMergeAttributesDialog::mergedAttributes() const
616614

617615
return results;
618616
}
617+
618+
QSet<int> QgsMergeAttributesDialog::skippedAttributeIndexes() const
619+
{
620+
QSet<int> skipped;
621+
for ( int i = 0; i < mTableWidget->columnCount(); ++i )
622+
{
623+
QComboBox *comboBox = qobject_cast<QComboBox *>( mTableWidget->cellWidget( 0, i ) );
624+
if ( !comboBox )
625+
{
626+
//something went wrong, better skip this attribute
627+
skipped << i;
628+
continue;
629+
}
630+
631+
if ( comboBox->itemData( comboBox->currentIndex() ).toString() == "skip" )
632+
{
633+
skipped << i;
634+
}
635+
}
636+
637+
return skipped;
638+
}

src/app/qgsmergeattributesdialog.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,11 @@ class APP_EXPORT QgsMergeAttributesDialog: public QDialog, private Ui::QgsMergeA
3737
~QgsMergeAttributesDialog();
3838
QgsAttributes mergedAttributes() const;
3939

40+
/** Returns a list of attribute indexes which should be skipped when merging (eg, attributes
41+
* which have been set to "skip"
42+
*/
43+
QSet<int> skippedAttributeIndexes() const;
44+
4045
private slots:
4146
void comboValueChanged( const QString & text );
4247
void selectedRowChanged();

0 commit comments

Comments
 (0)