Skip to content
Permalink
Browse files

Default to "Automatic" encoding option when adding OGR vector files

through the Data Source Manager

This allows the embedded (LDID/CPG based) Shapefile encoding to
be used by default, but still offers users a way to override this.
  • Loading branch information
nyalldawson committed Feb 10, 2020
1 parent a74b259 commit 301d2baeffdc043293c320e391e01feb4d7ccc30
Showing with 3 additions and 16 deletions.
  1. +3 −16 src/gui/providers/ogr/qgsogrsourceselect.cpp
@@ -67,18 +67,8 @@ QgsOgrSourceSelect::QgsOgrSourceSelect( QWidget *parent, Qt::WindowFlags fl, Qgs
//set encoding
cmbEncodings->addItems( QgsVectorDataProvider::availableEncodings() );

QgsSettings settings;
QString enc = settings.value( QStringLiteral( "UI/encoding" ), "System" ).toString();

// The specified decoding is added if not existing already, and then set current.
// This should select it.
int encindex = cmbEncodings->findText( enc );
if ( encindex < 0 )
{
cmbEncodings->insertItem( 0, enc );
encindex = 0;
}
cmbEncodings->setCurrentIndex( encindex );
cmbEncodings->insertItem( 0, tr( "Automatic" ), QString() );
cmbEncodings->setCurrentIndex( 0 );

//add database drivers
mVectorFileFilter = QgsProviderRegistry::instance()->fileVectorFilters();
@@ -155,7 +145,7 @@ QStringList QgsOgrSourceSelect::dataSources()

QString QgsOgrSourceSelect::encoding()
{
return cmbEncodings->currentText();
return cmbEncodings->currentData().isValid() ? cmbEncodings->currentData().toString() : cmbEncodings->currentText();
}

QString QgsOgrSourceSelect::dataSourceType()
@@ -435,9 +425,6 @@ void QgsOgrSourceSelect::addButtonClicked()
mDataSources << mVectorPath;
}

// Save the used encoding
settings.setValue( QStringLiteral( "UI/encoding" ), encoding() );

if ( ! mDataSources.isEmpty() )
{
emit addVectorLayers( mDataSources, encoding(), dataSourceType() );

0 comments on commit 301d2ba

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