Skip to content
Permalink
Browse files

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

(cherry-picked from 0bda18b)
  • Loading branch information
nyalldawson committed Nov 19, 2015
1 parent ca127f5 commit 45d80f907fd0ef8c095c54ef86387bd8ee3865e3
Showing with 34 additions and 5 deletions.
  1. +6 −2 src/app/qgisapp.cpp
  2. +23 −3 src/app/qgsmergeattributesdialog.cpp
  3. +5 −0 src/app/qgsmergeattributesdialog.h
@@ -5888,12 +5888,16 @@ void QgisApp::mergeAttributesOfSelectedFeatures()

vl->beginEditCommand( tr( "Merged feature attributes" ) );

const QgsAttributes &merged = d.mergedAttributes();
QgsAttributes merged = d.mergedAttributes();
QSet<int> toSkip = d.skippedAttributeIndexes();

foreach ( QgsFeatureId fid, vl->selectedFeaturesIds() )
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 ) );
}
}
@@ -585,8 +585,6 @@ QgsAttributes QgsMergeAttributesDialog::mergedAttributes() const
return QgsAttributes();
}

QgsFields fields = mVectorLayer->pendingFields();

QgsAttributes results( mTableWidget->columnCount() );
for ( int i = 0; i < mTableWidget->columnCount(); i++ )
{
@@ -603,7 +601,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 );
}
@@ -615,3 +613,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();

0 comments on commit 45d80f9

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