Skip to content

Commit 368fa90

Browse files
committed
[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 (cherry-picked from 615cb6c)
1 parent 2fd51c0 commit 368fa90

File tree

1 file changed

+39
-0
lines changed

1 file changed

+39
-0
lines changed

src/app/qgsmergeattributesdialog.cpp

+39
Original file line numberDiff line numberDiff line change
@@ -167,11 +167,50 @@ void QgsMergeAttributesDialog::createTableWidgetContents()
167167
verticalHeaderLabels << tr( "Merge" );
168168
mTableWidget->setVerticalHeaderLabels( verticalHeaderLabels );
169169

170+
for ( int j = 0; j < mTableWidget->columnCount(); j++ )
171+
{
172+
QTableWidgetItem *mergedItem = new QTableWidgetItem();
173+
mergedItem->setFlags( Qt::ItemIsEnabled | Qt::ItemIsSelectable | Qt::ItemIsEditable );
174+
mTableWidget->setItem( mTableWidget->rowCount() - 1, j, mergedItem );
175+
}
176+
170177
//insert currently merged values
171178
for ( int i = 0; i < mTableWidget->columnCount(); ++i )
172179
{
173180
refreshMergedValue( i );
174181
}
182+
183+
//initially set any fields with default values/default value clauses to that value
184+
for ( int j = 0; j < mTableWidget->columnCount(); j++ )
185+
{
186+
int idx = mTableWidget->horizontalHeaderItem( j )->data( FieldIndex ).toInt();
187+
bool setToManual = false;
188+
if ( !mVectorLayer->dataProvider()->defaultValueClause( idx ).isEmpty() )
189+
{
190+
mTableWidget->item( mTableWidget->rowCount() - 1, j )->setData( Qt::DisplayRole, mVectorLayer->dataProvider()->defaultValueClause( idx ) );
191+
setToManual = true;
192+
}
193+
else
194+
{
195+
QVariant v = mVectorLayer->dataProvider()->defaultValue( idx );
196+
if ( v.isValid() )
197+
{
198+
mTableWidget->item( mTableWidget->rowCount() - 1, j )->setData( Qt::DisplayRole, v );
199+
setToManual = true;
200+
}
201+
}
202+
if ( setToManual )
203+
{
204+
QComboBox *currentComboBox = qobject_cast<QComboBox *>( mTableWidget->cellWidget( 0, j ) );
205+
if ( currentComboBox )
206+
{
207+
currentComboBox->blockSignals( true );
208+
currentComboBox->setCurrentIndex( currentComboBox->findData( "manual" ) );
209+
currentComboBox->blockSignals( false );
210+
}
211+
}
212+
}
213+
175214
}
176215

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

0 commit comments

Comments
 (0)