mirror of
https://github.com/qgis/QGIS.git
synced 2025-03-01 00:46:20 -05:00
Fix merge attributes tool sets skipped attributes to null (fix #13231)
This commit is contained in:
parent
46f073086f
commit
0bda18b6e0
@ -6150,11 +6150,15 @@ void QgisApp::mergeAttributesOfSelectedFeatures()
|
||||
vl->beginEditCommand( tr( "Merged feature attributes" ) );
|
||||
|
||||
QgsAttributes merged = d.mergedAttributes();
|
||||
QSet<int> toSkip = d.skippedAttributeIndexes();
|
||||
|
||||
Q_FOREACH ( QgsFeatureId fid, vl->selectedFeaturesIds() )
|
||||
{
|
||||
for ( int i = 0; i < merged.count(); ++i )
|
||||
{
|
||||
if ( toSkip.contains( i ) )
|
||||
continue;
|
||||
|
||||
vl->changeAttributeValue( fid, i, merged.at( i ) );
|
||||
}
|
||||
}
|
||||
|
@ -586,8 +586,6 @@ QgsAttributes QgsMergeAttributesDialog::mergedAttributes() const
|
||||
return QgsAttributes();
|
||||
}
|
||||
|
||||
QgsFields fields = mVectorLayer->fields();
|
||||
|
||||
QgsAttributes results( mTableWidget->columnCount() );
|
||||
for ( int i = 0; i < mTableWidget->columnCount(); i++ )
|
||||
{
|
||||
@ -604,7 +602,7 @@ QgsAttributes QgsMergeAttributesDialog::mergedAttributes() const
|
||||
if ( idx >= results.count() )
|
||||
results.resize( idx + 1 ); // make sure the results vector is long enough (maybe not necessary)
|
||||
|
||||
if ( comboBox->itemData( comboBox->currentIndex() ) != "skip" )
|
||||
if ( comboBox->itemData( comboBox->currentIndex() ).toString() != "skip" )
|
||||
{
|
||||
results[idx] = currentItem->data( Qt::DisplayRole );
|
||||
}
|
||||
@ -616,3 +614,25 @@ QgsAttributes QgsMergeAttributesDialog::mergedAttributes() const
|
||||
|
||||
return results;
|
||||
}
|
||||
|
||||
QSet<int> QgsMergeAttributesDialog::skippedAttributeIndexes() const
|
||||
{
|
||||
QSet<int> skipped;
|
||||
for ( int i = 0; i < mTableWidget->columnCount(); ++i )
|
||||
{
|
||||
QComboBox *comboBox = qobject_cast<QComboBox *>( mTableWidget->cellWidget( 0, i ) );
|
||||
if ( !comboBox )
|
||||
{
|
||||
//something went wrong, better skip this attribute
|
||||
skipped << i;
|
||||
continue;
|
||||
}
|
||||
|
||||
if ( comboBox->itemData( comboBox->currentIndex() ).toString() == "skip" )
|
||||
{
|
||||
skipped << i;
|
||||
}
|
||||
}
|
||||
|
||||
return skipped;
|
||||
}
|
||||
|
@ -37,6 +37,11 @@ class APP_EXPORT QgsMergeAttributesDialog: public QDialog, private Ui::QgsMergeA
|
||||
~QgsMergeAttributesDialog();
|
||||
QgsAttributes mergedAttributes() const;
|
||||
|
||||
/** Returns a list of attribute indexes which should be skipped when merging (eg, attributes
|
||||
* which have been set to "skip"
|
||||
*/
|
||||
QSet<int> skippedAttributeIndexes() const;
|
||||
|
||||
private slots:
|
||||
void comboValueChanged( const QString & text );
|
||||
void selectedRowChanged();
|
||||
|
Loading…
x
Reference in New Issue
Block a user