Skip to content
Permalink
Browse files

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

  • Loading branch information
nyalldawson committed Oct 19, 2015
1 parent 46f0730 commit 0bda18b6e04105d52cfe6f54792de2f2e2b4a925
Showing with 32 additions and 3 deletions.
  1. +4 −0 src/app/qgisapp.cpp
  2. +23 −3 src/app/qgsmergeattributesdialog.cpp
  3. +5 −0 src/app/qgsmergeattributesdialog.h
@@ -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();

0 comments on commit 0bda18b

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