Skip to content
Permalink
Browse files
followup r13591: force KML encoding to utf-8 in save as dialog and mo…
…ve filename/encoding validation to vector file write

git-svn-id: http://svn.osgeo.org/qgis/trunk@13592 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
jef committed May 29, 2010
1 parent 4e207a1 commit 24ce8da4b2438870acae17d9c686baec0f8c86bb
Showing with 35 additions and 67 deletions.
  1. +10 −0 src/app/ogr/qgsvectorlayersaveasdialog.cpp
  2. +1 −61 src/app/qgisapp.cpp
  3. +1 −5 src/app/qgisapp.h
  4. +23 −1 src/core/qgsvectorfilewriter.cpp
@@ -74,6 +74,16 @@ void QgsVectorLayerSaveAsDialog::on_mFormatComboBox_currentIndexChanged( int idx
{
browseFilename->setEnabled( true );
leFilename->setEnabled( true );

if( format() == "KML" )
{
mEncodingComboBox->setCurrentIndex( mEncodingComboBox->findText( "UTF-8" ) );
mEncodingComboBox->setDisabled( true );
}
else
{
mEncodingComboBox->setEnabled( true );
}
}

void QgsVectorLayerSaveAsDialog::on_browseFilename_clicked()
@@ -2700,19 +2700,6 @@ void QgisApp::loadOGRSublayers( QString layertype, QString uri, QStringList list
}
}

/** This helper checks to see whether the file name appears to be a valid vector file name */
bool QgisApp::isValidShapeFileName( QString theFileNameQString )
{
return theFileNameQString.endsWith( ".shp", Qt::CaseInsensitive );
}

/** Overloaded of the above function provided for convenience that takes a qstring pointer */
bool QgisApp::isValidShapeFileName( QString * theFileNameQString )
{
//dereference and delegate
return isValidShapeFileName( *theFileNameQString );
}

#ifndef HAVE_POSTGRESQL
void QgisApp::addDatabaseLayer() {}
#else
@@ -3030,31 +3017,7 @@ void QgisApp::newVectorLayer()
openFileDialog->selectFilter( lastUsedFilter );
}

int res;
while (( res = openFileDialog->exec() ) == QDialog::Accepted )
{
fileName = openFileDialog->selectedFiles().first();

if ( fileformat == "ESRI Shapefile" )
{
if ( !isValidShapeFileName( fileName ) )
{
fileName += ".shp";
}

if ( !isValidShapeFileName( fileName ) )
{
QMessageBox::information( this,
tr( "New Shapefile" ),
tr( "Shapefiles must end on .shp" ) );
continue;
}
}

break;
}

if ( res == QDialog::Rejected )
if( openFileDialog->exec() == QDialog::Rejected )
{
delete openFileDialog;
return;
@@ -3864,29 +3827,6 @@ void QgisApp::saveAsVectorFileGeneral( bool saveOnlySelection )
destCRS = QgsCoordinateReferenceSystem( dialog->crs(), QgsCoordinateReferenceSystem::InternalCrsId );
}

// overwrite the file - user will already have been prompted
// to verify they want to overwrite by the file dialog above
// might not even exists in the given case.
// add the extension if not present
if ( format == "ESRI Shapefile" )
{
if ( !vectorFilename.endsWith( ".shp", Qt::CaseInsensitive ) )
{
vectorFilename += ".shp";
}
QgsVectorFileWriter::deleteShapeFile( vectorFilename );
}

//GE does not open files without extensions. Therefore we append it automatically for kml files
if ( format == "KML" )
{
if ( !vectorFilename.endsWith( ".kml", Qt::CaseInsensitive ) )
{
vectorFilename += ".kml";
}
encoding = "UTF-8";
}

// ok if the file existed it should be deleted now so we can continue...
QApplication::setOverrideCursor( Qt::WaitCursor );

@@ -742,11 +742,7 @@ class QgisApp : public QMainWindow
* It won't force a refresh.
*/
bool addRasterLayer( QgsRasterLayer * theRasterLayer );
//@todo We should move these next two into vector layer class
/** This helper checks to see whether the file name appears to be a valid shape file name */
bool isValidShapeFileName( QString theFileNameQString );
/** Overloaded version of the above function provided for convenience that takes a qstring pointer */
bool isValidShapeFileName( QString * theFileNameQString );

/** add this file to the recently opened/saved projects list
* pass settings by reference since creating more than one
* instance simultaneously results in data loss.
@@ -43,7 +43,7 @@

QgsVectorFileWriter::QgsVectorFileWriter(
const QString &theVectorFileName,
const QString& fileEncoding,
const QString &theFileEncoding,
const QgsFieldMap& fields,
QGis::WkbType geometryType,
const QgsCoordinateReferenceSystem* srs,
@@ -54,6 +54,7 @@ QgsVectorFileWriter::QgsVectorFileWriter(
, mError( NoError )
{
QString vectorFileName = theVectorFileName;
QString fileEncoding = theFileEncoding;

// find driver in OGR
OGRSFDriverH poDriver;
@@ -91,6 +92,27 @@ QgsVectorFileWriter::QgsVectorFileWriter(
}
fieldNames << name;
}

deleteShapeFile( vectorFileName );
}
else if( driverName == "KML" )
{
if( !vectorFileName.endsWith( ".kml", Qt::CaseInsensitive ) )
{
vectorFileName += ".kml";
}

if( fileEncoding.compare( "UTF-8", Qt::CaseInsensitive )!=0 )
{
QgsDebugMsg( "forced UTF-8 encoding for KML" );
fileEncoding = "UTF-8";
}

QFile::remove( vectorFileName );
}
else
{
QFile::remove( vectorFileName );
}

// create the data source

0 comments on commit 24ce8da

Please sign in to comment.