Skip to content

Commit 3f94adc

Browse files
committedJan 21, 2016
Make entering manual values in merge attributes dialog more user
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.
1 parent a212fac commit 3f94adc

File tree

2 files changed

+28
-0
lines changed

2 files changed

+28
-0
lines changed
 

‎src/app/qgsmergeattributesdialog.cpp

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ QgsMergeAttributesDialog::QgsMergeAttributesDialog( const QgsFeatureList &featur
7373
restoreGeometry( settings.value( "/Windows/MergeAttributes/geometry" ).toByteArray() );
7474

7575
connect( mSkipAllButton, SIGNAL( clicked() ), this, SLOT( setAllToSkip() ) );
76+
connect( mTableWidget, SIGNAL( cellChanged( int, int ) ), this, SLOT( tableWidgetCellChanged( int, int ) ) );
7677
}
7778

7879
QgsMergeAttributesDialog::QgsMergeAttributesDialog()
@@ -186,6 +187,7 @@ QComboBox *QgsMergeAttributesDialog::createMergeComboBox( QVariant::Type columnT
186187
}
187188

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

190192
QObject::connect( newComboBox, SIGNAL( currentIndexChanged( const QString& ) ),
191193
this, SLOT( comboValueChanged( const QString& ) ) );
@@ -275,6 +277,10 @@ void QgsMergeAttributesDialog::refreshMergedValue( int col )
275277
{
276278
mergeResult = tr( "Skipped" );
277279
}
280+
else if ( mergeBehaviourString == "manual" )
281+
{
282+
return; //nothing to do
283+
}
278284
else if ( mergeBehaviourString.startsWith( 'f' ) )
279285
{
280286
//an existing feature value
@@ -292,7 +298,11 @@ void QgsMergeAttributesDialog::refreshMergedValue( int col )
292298
QTableWidgetItem* newTotalItem = new QTableWidgetItem();
293299
newTotalItem->setData( Qt::DisplayRole, mergeResult );
294300
newTotalItem->setFlags( Qt::ItemIsEnabled | Qt::ItemIsSelectable | Qt::ItemIsEditable );
301+
302+
//block signals to prevent table widget switching combo box to "manual" entry
303+
mTableWidget->blockSignals( true );
295304
mTableWidget->setItem( mTableWidget->rowCount() - 1, col, newTotalItem );
305+
mTableWidget->blockSignals( false );
296306
}
297307

298308
QVariant QgsMergeAttributesDialog::featureAttribute( QgsFeatureId featureId, int col )
@@ -463,6 +473,23 @@ void QgsMergeAttributesDialog::on_mRemoveFeatureFromSelectionButton_clicked()
463473
}
464474
}
465475

476+
void QgsMergeAttributesDialog::tableWidgetCellChanged( int row, int column )
477+
{
478+
if ( row < mTableWidget->rowCount() - 1 )
479+
{
480+
//only looking for edits in the final row
481+
return;
482+
}
483+
484+
QComboBox* currentComboBox = qobject_cast<QComboBox *>( mTableWidget->cellWidget( 0, column ) );
485+
if ( currentComboBox )
486+
{
487+
currentComboBox->blockSignals( true );
488+
currentComboBox->setCurrentIndex( currentComboBox->findData( "manual" ) );
489+
currentComboBox->blockSignals( false );
490+
}
491+
}
492+
466493
void QgsMergeAttributesDialog::createRubberBandForFeature( QgsFeatureId featureId )
467494
{
468495
//create rubber band to highlight the feature

‎src/app/qgsmergeattributesdialog.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ class APP_EXPORT QgsMergeAttributesDialog: public QDialog, private Ui::QgsMergeA
5555
void selectedRowChanged();
5656
void on_mFromSelectedPushButton_clicked();
5757
void on_mRemoveFeatureFromSelectionButton_clicked();
58+
void tableWidgetCellChanged( int row, int column );
5859

5960
private:
6061
QgsMergeAttributesDialog(); //default constructor forbidden

0 commit comments

Comments
 (0)