Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Save vector layer: for CSV/XLS/XLSX/ODS, only use by default displaye…
…d values of a restrict set of widget types
  • Loading branch information
github-actions[bot] authored and nyalldawson committed Mar 29, 2020
1 parent f04aca9 commit be4aca3
Showing 1 changed file with 24 additions and 5 deletions.
29 changes: 24 additions & 5 deletions src/gui/ogr/qgsvectorlayersaveasdialog.cpp
Expand Up @@ -412,7 +412,11 @@ void QgsVectorLayerSaveAsDialog::mFormatComboBox_currentIndexChanged( int idx )
}

bool selectAllFields = true;
bool fieldsAsDisplayedValues = false;

// Is it a format for which fields that have attached widgets of types
// ValueMap, ValueRelation, etc. should be by default exported with their displayed
// values
bool isFormatForFieldsAsDisplayedValues = false;

const QString sFormat( format() );
if ( sFormat == QLatin1String( "DXF" ) || sFormat == QLatin1String( "DGN" ) )
Expand All @@ -423,7 +427,13 @@ void QgsVectorLayerSaveAsDialog::mFormatComboBox_currentIndexChanged( int idx )
else
{
if ( mOptions & Fields )
{
mAttributesSelection->setVisible( true );
isFormatForFieldsAsDisplayedValues = ( sFormat == QLatin1String( "CSV" ) ||
sFormat == QLatin1String( "XLS" ) ||
sFormat == QLatin1String( "XLSX" ) ||
sFormat == QLatin1String( "ODS" ) );
}
}

// Show symbology options only for some formats
Expand Down Expand Up @@ -486,6 +496,7 @@ void QgsVectorLayerSaveAsDialog::mFormatComboBox_currentIndexChanged( int idx )

mAttributeTableItemChangedSlotEnabled = false;

bool checkReplaceRawFieldValues = selectAllFields && isFormatForFieldsAsDisplayedValues;
for ( int i = 0; i < mLayer->fields().size(); ++i )
{
QgsField fld = mLayer->fields().at( i );
Expand All @@ -504,13 +515,21 @@ void QgsVectorLayerSaveAsDialog::mFormatComboBox_currentIndexChanged( int idx )
{
const QgsEditorWidgetSetup setup = QgsGui::editorWidgetRegistry()->findBest( mLayer, mLayer->fields()[i].name() );
QgsEditorWidgetFactory *factory = nullptr;
const QString widgetId( setup.type() );
if ( flags == Qt::ItemIsEnabled &&
setup.type() != QLatin1String( "TextEdit" ) &&
( factory = QgsGui::editorWidgetRegistry()->factory( setup.type() ) ) )
widgetId != QLatin1String( "TextEdit" ) &&
( factory = QgsGui::editorWidgetRegistry()->factory( widgetId ) ) )
{
item = new QTableWidgetItem( tr( "Use %1" ).arg( factory->name() ) );
item->setFlags( ( selectAllFields ) ? ( Qt::ItemIsEnabled | Qt::ItemIsUserCheckable ) : Qt::ItemIsUserCheckable );
item->setCheckState( ( selectAllFields && fieldsAsDisplayedValues ) ? Qt::Checked : Qt::Unchecked );
const bool checkItem = ( selectAllFields && isFormatForFieldsAsDisplayedValues &&
( widgetId == QLatin1String( "ValueMap" ) ||
widgetId == QLatin1String( "ValueRelation" ) ||
widgetId == QLatin1String( "CheckBox" ) ||
widgetId == QLatin1String( "RelationReference" ) ) );
checkReplaceRawFieldValues &= checkItem;
item->setCheckState( checkItem ?
Qt::Checked : Qt::Unchecked );
mAttributeTable->setItem( i, COLUMN_IDX_EXPORT_AS_DISPLAYED_VALUE, item );
}
else
Expand All @@ -525,7 +544,7 @@ void QgsVectorLayerSaveAsDialog::mFormatComboBox_currentIndexChanged( int idx )
mAttributeTableItemChangedSlotEnabled = true;

mReplaceRawFieldValuesStateChangedSlotEnabled = false;
mReplaceRawFieldValues->setChecked( selectAllFields && fieldsAsDisplayedValues );
mReplaceRawFieldValues->setChecked( checkReplaceRawFieldValues );
mReplaceRawFieldValuesStateChangedSlotEnabled = true;
mReplaceRawFieldValues->setEnabled( selectAllFields );
mReplaceRawFieldValues->setVisible( foundFieldThatCanBeExportedAsDisplayedValue );
Expand Down

0 comments on commit be4aca3

Please sign in to comment.