Skip to content
Permalink
Browse files

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.
  • Loading branch information
nyalldawson committed Jan 21, 2016
1 parent a212fac commit 3f94adc82aebdec553f48ea2fcbd9fb184193722
Showing with 28 additions and 0 deletions.
  1. +27 −0 src/app/qgsmergeattributesdialog.cpp
  2. +1 −0 src/app/qgsmergeattributesdialog.h
@@ -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()
@@ -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& ) ) );
@@ -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
@@ -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 )
@@ -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
@@ -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

0 comments on commit 3f94adc

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