Skip to content

Commit

Permalink
Make entering manual values in merge attributes dialog more user
Browse files Browse the repository at this point in the history
friendly (fix #14146)

Previously, if a value was manually entered it would be ignored if
the user forgot to change the combo box from the "skip" value
to some other value (even though that value would not be used).

Now, there's a new "manual" value in the combo box, and manually
entering a value will switch the combo automatically to the
"manual" option.
  • Loading branch information
nyalldawson committed Jan 21, 2016
1 parent a212fac commit 3f94adc
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
27 changes: 27 additions & 0 deletions src/app/qgsmergeattributesdialog.cpp
Expand Up @@ -73,6 +73,7 @@ QgsMergeAttributesDialog::QgsMergeAttributesDialog( const QgsFeatureList &featur
restoreGeometry( settings.value( "/Windows/MergeAttributes/geometry" ).toByteArray() );

connect( mSkipAllButton, SIGNAL( clicked() ), this, SLOT( setAllToSkip() ) );
connect( mTableWidget, SIGNAL( cellChanged( int, int ) ), this, SLOT( tableWidgetCellChanged( int, int ) ) );
}

QgsMergeAttributesDialog::QgsMergeAttributesDialog()
Expand Down Expand Up @@ -186,6 +187,7 @@ QComboBox *QgsMergeAttributesDialog::createMergeComboBox( QVariant::Type columnT
}

newComboBox->addItem( tr( "Skip attribute" ), "skip" );
newComboBox->addItem( tr( "Manual value" ), "manual" );

QObject::connect( newComboBox, SIGNAL( currentIndexChanged( const QString& ) ),
this, SLOT( comboValueChanged( const QString& ) ) );
Expand Down Expand Up @@ -275,6 +277,10 @@ void QgsMergeAttributesDialog::refreshMergedValue( int col )
{
mergeResult = tr( "Skipped" );
}
else if ( mergeBehaviourString == "manual" )
{
return; //nothing to do
}
else if ( mergeBehaviourString.startsWith( 'f' ) )
{
//an existing feature value
Expand All @@ -292,7 +298,11 @@ void QgsMergeAttributesDialog::refreshMergedValue( int col )
QTableWidgetItem* newTotalItem = new QTableWidgetItem();
newTotalItem->setData( Qt::DisplayRole, mergeResult );
newTotalItem->setFlags( Qt::ItemIsEnabled | Qt::ItemIsSelectable | Qt::ItemIsEditable );

//block signals to prevent table widget switching combo box to "manual" entry
mTableWidget->blockSignals( true );
mTableWidget->setItem( mTableWidget->rowCount() - 1, col, newTotalItem );
mTableWidget->blockSignals( false );
}

QVariant QgsMergeAttributesDialog::featureAttribute( QgsFeatureId featureId, int col )
Expand Down Expand Up @@ -463,6 +473,23 @@ void QgsMergeAttributesDialog::on_mRemoveFeatureFromSelectionButton_clicked()
}
}

void QgsMergeAttributesDialog::tableWidgetCellChanged( int row, int column )
{
if ( row < mTableWidget->rowCount() - 1 )
{
//only looking for edits in the final row
return;
}

QComboBox* currentComboBox = qobject_cast<QComboBox *>( mTableWidget->cellWidget( 0, column ) );
if ( currentComboBox )
{
currentComboBox->blockSignals( true );
currentComboBox->setCurrentIndex( currentComboBox->findData( "manual" ) );
currentComboBox->blockSignals( false );
}
}

void QgsMergeAttributesDialog::createRubberBandForFeature( QgsFeatureId featureId )
{
//create rubber band to highlight the feature
Expand Down
1 change: 1 addition & 0 deletions src/app/qgsmergeattributesdialog.h
Expand Up @@ -55,6 +55,7 @@ class APP_EXPORT QgsMergeAttributesDialog: public QDialog, private Ui::QgsMergeA
void selectedRowChanged();
void on_mFromSelectedPushButton_clicked();
void on_mRemoveFeatureFromSelectionButton_clicked();
void tableWidgetCellChanged( int row, int column );

private:
QgsMergeAttributesDialog(); //default constructor forbidden
Expand Down

0 comments on commit 3f94adc

Please sign in to comment.