Skip to content
Permalink
Browse files

[needs-docs] In merge features dialog, if a layer has default

values/default value clauses present, then use these as the
initial value for the merged feature

Otherwise the dialog defaulted to skipping these attributes
or taking a value from an existing feature, which meant
that it could violate constraints on the backend.

Users can still easily overwrite these values if desired.

Fixes #18397
  • Loading branch information
nyalldawson committed Apr 3, 2018
1 parent 001796d commit 615cb6ca71e14ea45252951f0ca3fe7e95343eb8
Showing with 39 additions and 0 deletions.
  1. +39 −0 src/app/qgsmergeattributesdialog.cpp
@@ -167,11 +167,50 @@ void QgsMergeAttributesDialog::createTableWidgetContents()
verticalHeaderLabels << tr( "Merge" );
mTableWidget->setVerticalHeaderLabels( verticalHeaderLabels );

for ( int j = 0; j < mTableWidget->columnCount(); j++ )
{
QTableWidgetItem *mergedItem = new QTableWidgetItem();
mergedItem->setFlags( Qt::ItemIsEnabled | Qt::ItemIsSelectable | Qt::ItemIsEditable );
mTableWidget->setItem( mTableWidget->rowCount() - 1, j, mergedItem );
}

//insert currently merged values
for ( int i = 0; i < mTableWidget->columnCount(); ++i )
{
refreshMergedValue( i );
}

//initially set any fields with default values/default value clauses to that value
for ( int j = 0; j < mTableWidget->columnCount(); j++ )
{
int idx = mTableWidget->horizontalHeaderItem( j )->data( FieldIndex ).toInt();
bool setToManual = false;
if ( !mVectorLayer->dataProvider()->defaultValueClause( idx ).isEmpty() )
{
mTableWidget->item( mTableWidget->rowCount() - 1, j )->setData( Qt::DisplayRole, mVectorLayer->dataProvider()->defaultValueClause( idx ) );
setToManual = true;
}
else
{
QVariant v = mVectorLayer->dataProvider()->defaultValue( idx );
if ( v.isValid() )
{
mTableWidget->item( mTableWidget->rowCount() - 1, j )->setData( Qt::DisplayRole, v );
setToManual = true;
}
}
if ( setToManual )
{
QComboBox *currentComboBox = qobject_cast<QComboBox *>( mTableWidget->cellWidget( 0, j ) );
if ( currentComboBox )
{
currentComboBox->blockSignals( true );
currentComboBox->setCurrentIndex( currentComboBox->findData( "manual" ) );
currentComboBox->blockSignals( false );
}
}
}

}

QComboBox *QgsMergeAttributesDialog::createMergeComboBox( QVariant::Type columnType ) const

0 comments on commit 615cb6c

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