Skip to content

Commit

Permalink
try to keep selected data type when toggling "Create virtual field"
Browse files Browse the repository at this point in the history
checkbox in the field calculator (fix #36679)

Reset to the first item only if compatible data type not found
  • Loading branch information
alexbruy committed Aug 16, 2020
1 parent 1a76a09 commit 97e9754
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions src/gui/vector/qgsfieldcalculator.cpp
Expand Up @@ -349,6 +349,8 @@ void QgsFieldCalculator::populateOutputFieldTypes()
return;
}

int oldDataType = mOutputFieldTypeComboBox->currentData( Qt::UserRole + FTC_TYPE_ROLE_IDX ).toInt();

mOutputFieldTypeComboBox->blockSignals( true );

// Standard subset of fields in case of virtual
Expand Down Expand Up @@ -382,8 +384,18 @@ void QgsFieldCalculator::populateOutputFieldTypes()
mOutputFieldTypeComboBox->setItemData( i, static_cast<int>( typelist[i].mSubType ), Qt::UserRole + FTC_SUBTYPE_IDX );
}
mOutputFieldTypeComboBox->blockSignals( false );
mOutputFieldTypeComboBox->setCurrentIndex( 0 );
mOutputFieldTypeComboBox_activated( 0 );

int idx = mOutputFieldTypeComboBox->findData( oldDataType, Qt::UserRole + FTC_TYPE_ROLE_IDX );
if ( idx != -1 )
{
mOutputFieldTypeComboBox->setCurrentIndex( idx );
mOutputFieldTypeComboBox_activated( idx );
}
else
{
mOutputFieldTypeComboBox->setCurrentIndex( 0 );
mOutputFieldTypeComboBox_activated( 0 );
}
}

void QgsFieldCalculator::mNewFieldGroupBox_toggled( bool on )
Expand Down

0 comments on commit 97e9754

Please sign in to comment.