Fix merge attributes tool sets skipped attributes to null (fix #13231)

This commit is contained in:
Nyall Dawson 2015-10-19 17:36:24 +11:00
parent 46f073086f
commit 0bda18b6e0
3 changed files with 32 additions and 3 deletions

View File

@ -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 ) );
}
}

View File

@ -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;
}

View File

@ -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();