Skip to content

Commit

Permalink
Default to "Automatic" encoding option when adding OGR vector files
Browse files Browse the repository at this point in the history
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 12, 2020
1 parent a74b259 commit 301d2ba
Showing 1 changed file with 3 additions and 16 deletions.
19 changes: 3 additions & 16 deletions src/gui/providers/ogr/qgsogrsourceselect.cpp
Expand Up @@ -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();
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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() );
Expand Down

0 comments on commit 301d2ba

Please sign in to comment.