Skip to content
Permalink
Browse files

File encoding selector made consistent and persistent between differe…

…nt dialogs.

git-svn-id: http://svn.osgeo.org/qgis/trunk/qgis@11182 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
homann
homann committed Jul 27, 2009
1 parent c04aef6 commit ea9b4fabbedfa205ab55b2a4db70c52273e70c70
@@ -247,7 +247,7 @@ void QgsLegendLayerFile::saveAsShapefileGeneral( bool saveOnlySelection )
tr( "Save layer as..." ),
dirName,
filter,
QString( "UTF-8" ) );
QString( "" ) );
openFileDialog->setAcceptMode( QFileDialog::AcceptSave );

// allow for selection of more than one file
@@ -40,7 +40,19 @@ QgsOpenVectorLayerDialog::QgsOpenVectorLayerDialog( QWidget* parent, Qt::WFlags
radioSrcFile->setChecked( true );
mDataSourceType = "file";
//set encoding
cmbEncodings->setItemText( cmbEncodings->currentIndex(), QString( QTextCodec::codecForLocale()->name() ) );
// cmbEncodings->setItemText( cmbEncodings->currentIndex(), QString( QTextCodec::codecForLocale()->name() ) );
QSettings settings;
QString enc = settings.value( "/UI/encoding", QString("System") ).toString();

// The specified decoding is added if not existing alread, 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 );

//add database drivers
mVectorFileFilter = QgsProviderRegistry::instance()->fileVectorFilters();
@@ -379,11 +391,11 @@ void QgsOpenVectorLayerDialog::openFilesRememberingFilter( QString const &filter
//********************auto connected slots *****************/
void QgsOpenVectorLayerDialog::on_buttonBox_accepted()
{
QSettings settings;
QgsDebugMsg( "dialog button accepted" );
if ( radioSrcDatabase->isChecked() )
{
mDataSources.clear();
QSettings settings;
QString baseKey = "/" + cmbDatabaseTypes->currentText() + "/connections/";
baseKey += cmbConnections->currentText();
QString host = settings.value( baseKey + "/host" ).toString();
@@ -414,6 +426,9 @@ void QgsOpenVectorLayerDialog::on_buttonBox_accepted()
protocolURI->text()
) );
}
// Save the used encoding
settings.setValue( "/UI/encoding", encoding() );

accept();
}

@@ -2300,12 +2300,10 @@ static void openFilesRememberingFilter_( QString const &filterName,

QString lastUsedDir = settings.value( "/UI/" + filterName + "Dir", "." ).toString();

QString lastUsedEncoding = settings.value( "/UI/encoding" ).toString();

QgsDebugMsg( "Opening file dialog with filters: " + filters );

QgsEncodingFileDialog* openFileDialog = new QgsEncodingFileDialog( 0,
title, lastUsedDir, filters, lastUsedEncoding );
title, lastUsedDir, filters, QString ("" ) );

// allow for selection of more than one file
openFileDialog->setFileMode( QFileDialog::ExistingFiles );
@@ -2330,7 +2328,6 @@ static void openFilesRememberingFilter_( QString const &filterName,

settings.setValue( "/UI/" + filterName, openFileDialog->selectedFilter() );
settings.setValue( "/UI/" + filterName + "Dir", myPath );
settings.setValue( "/UI/encoding", openFileDialog->encoding() );
}

delete openFileDialog;
@@ -3153,12 +3150,10 @@ void QgisApp::newVectorLayer()
QString lastUsedDir = settings.value( "/UI/lastVectorFileFilterDir",
"." ).toString();

QString lastUsedEncoding = settings.value( "/UI/encoding" ).toString();

QgsDebugMsg( "Saving vector file dialog without filters: " );

QgsEncodingFileDialog* openFileDialog = new QgsEncodingFileDialog( this,
tr( "Save As" ), lastUsedDir, "", lastUsedEncoding );
tr( "Save As" ), lastUsedDir, "", QString( "" ) );

// allow for selection of more than one file
openFileDialog->setFileMode( QFileDialog::AnyFile );
@@ -3188,7 +3183,6 @@ void QgisApp::newVectorLayer()
settings.setValue( "/UI/lastVectorFileFilter", openFileDialog->selectedFilter() );

settings.setValue( "/UI/lastVectorFileFilterDir", openFileDialog->directory().absolutePath() );
settings.setValue( "/UI/encoding", openFileDialog->encoding() );

delete openFileDialog;

@@ -14,6 +14,7 @@
***************************************************************************/
/* $Id$ */

#include <QSettings>
#include <QTextCodec>

#include <cfloat> // for DBL_MAX
@@ -27,9 +28,10 @@
QgsVectorDataProvider::QgsVectorDataProvider( QString uri )
: QgsDataProvider( uri ),
mCacheMinMaxDirty( TRUE ),
mEncoding( QTextCodec::codecForLocale() ),
mFetchFeaturesWithoutGeom( FALSE )
{
QSettings settings;
setEncoding( settings.value( "/UI/encoding", QString("System") ).toString() );
}


@@ -27,6 +27,7 @@
#include "qgsvectordataprovider.h"

#include <QFile>
#include <QSettings>
#include <QFileInfo>
#include <QTextCodec>

@@ -72,8 +73,15 @@ QgsVectorFileWriter::QgsVectorFileWriter( const QString& shapefileName,
mCodec = QTextCodec::codecForName( fileEncoding.toLocal8Bit().data() );
if ( !mCodec )
{
QSettings settings;
QString enc = settings.value( "/UI/encoding", QString("System") ).toString();
QgsDebugMsg( "error finding QTextCodec for " + fileEncoding );
mCodec = QTextCodec::codecForLocale();
mCodec = QTextCodec::codecForName( enc.toLocal8Bit().data() );
if ( !mCodec )
{
QgsDebugMsg( "error finding QTextCodec for " + enc );
mCodec = QTextCodec::codecForLocale();
}
}

// consider spatial reference system of the layer
@@ -14,6 +14,9 @@
***************************************************************************/

#include "qgsencodingfiledialog.h"
#include "qgsproject.h"
#include "qgslogger.h"
#include <QSettings>
#include <QComboBox>
#include <QLabel>
#include <QLayout>
@@ -71,21 +74,35 @@ QgsEncodingFileDialog::QgsEncodingFileDialog( QWidget * parent,
mEncodingComboBox->addItem( "CP1258" );
mEncodingComboBox->addItem( "Apple Roman" );
mEncodingComboBox->addItem( "TIS-620" );

// Use default encoding if none supplied
QString enc = encoding;
if ( encoding.isEmpty() )
{
mEncodingComboBox->setItemText( mEncodingComboBox->currentIndex(), QString( QTextCodec::codecForLocale()->name() ) );
QSettings settings;
enc = settings.value( "/UI/encoding", QString("System") ).toString();
}
else

// The specified decoding is added if not existing alread, and then set current.
// This should select it.
int encindex = mEncodingComboBox->findText( enc );
if ( encindex < 0 )
{
mEncodingComboBox->setItemText( mEncodingComboBox->currentIndex(), encoding );
mEncodingComboBox->insertItem( 0, enc );
encindex = 0;
}
mEncodingComboBox->setCurrentIndex( encindex );

// if this dialog is being invoked from QgisApp::findFiles_(), then we
// need to force selection of the first filter since that corresponds to
// the file name we're looking for; even if we're not here from
// findFiles_(), it won't hurt to force selection of the first file filter
selectFilter( filters().at( 0 ) );

// Connect our slot to get a signal when the user is done with the file dialog
connect( this, SIGNAL( accepted() ), this, SLOT( saveUsedEncoding() ) );


}

QgsEncodingFileDialog::~QgsEncodingFileDialog()
@@ -97,3 +114,10 @@ QString QgsEncodingFileDialog::encoding() const
{
return mEncodingComboBox->currentText();
}

void QgsEncodingFileDialog::saveUsedEncoding()
{
QSettings settings;
settings.setValue( "/UI/encoding", encoding() );
QgsDebugMsg(QString( "Set encoding " + encoding() + " as default.") );
}
@@ -32,6 +32,9 @@ class GUI_EXPORT QgsEncodingFileDialog: public QFileDialog
~QgsEncodingFileDialog();
/**Returns a string describing the choosen encoding*/
QString encoding() const;
public slots:
void saveUsedEncoding();

private:
/**Box to choose the encoding type*/
QComboBox* mEncodingComboBox;

0 comments on commit ea9b4fa

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