Skip to content

Commit 24ce8da

Browse files
author
jef
committedMay 29, 2010
followup r13591: force KML encoding to utf-8 in save as dialog and move filename/encoding validation to vector file write
git-svn-id: http://svn.osgeo.org/qgis/trunk@13592 c8812cc2-4d05-0410-92ff-de0c093fc19c
1 parent 4e207a1 commit 24ce8da

File tree

4 files changed

+35
-67
lines changed

4 files changed

+35
-67
lines changed
 

‎src/app/ogr/qgsvectorlayersaveasdialog.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,16 @@ void QgsVectorLayerSaveAsDialog::on_mFormatComboBox_currentIndexChanged( int idx
7474
{
7575
browseFilename->setEnabled( true );
7676
leFilename->setEnabled( true );
77+
78+
if( format() == "KML" )
79+
{
80+
mEncodingComboBox->setCurrentIndex( mEncodingComboBox->findText( "UTF-8" ) );
81+
mEncodingComboBox->setDisabled( true );
82+
}
83+
else
84+
{
85+
mEncodingComboBox->setEnabled( true );
86+
}
7787
}
7888

7989
void QgsVectorLayerSaveAsDialog::on_browseFilename_clicked()

‎src/app/qgisapp.cpp

Lines changed: 1 addition & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -2700,19 +2700,6 @@ void QgisApp::loadOGRSublayers( QString layertype, QString uri, QStringList list
27002700
}
27012701
}
27022702

2703-
/** This helper checks to see whether the file name appears to be a valid vector file name */
2704-
bool QgisApp::isValidShapeFileName( QString theFileNameQString )
2705-
{
2706-
return theFileNameQString.endsWith( ".shp", Qt::CaseInsensitive );
2707-
}
2708-
2709-
/** Overloaded of the above function provided for convenience that takes a qstring pointer */
2710-
bool QgisApp::isValidShapeFileName( QString * theFileNameQString )
2711-
{
2712-
//dereference and delegate
2713-
return isValidShapeFileName( *theFileNameQString );
2714-
}
2715-
27162703
#ifndef HAVE_POSTGRESQL
27172704
void QgisApp::addDatabaseLayer() {}
27182705
#else
@@ -3030,31 +3017,7 @@ void QgisApp::newVectorLayer()
30303017
openFileDialog->selectFilter( lastUsedFilter );
30313018
}
30323019

3033-
int res;
3034-
while (( res = openFileDialog->exec() ) == QDialog::Accepted )
3035-
{
3036-
fileName = openFileDialog->selectedFiles().first();
3037-
3038-
if ( fileformat == "ESRI Shapefile" )
3039-
{
3040-
if ( !isValidShapeFileName( fileName ) )
3041-
{
3042-
fileName += ".shp";
3043-
}
3044-
3045-
if ( !isValidShapeFileName( fileName ) )
3046-
{
3047-
QMessageBox::information( this,
3048-
tr( "New Shapefile" ),
3049-
tr( "Shapefiles must end on .shp" ) );
3050-
continue;
3051-
}
3052-
}
3053-
3054-
break;
3055-
}
3056-
3057-
if ( res == QDialog::Rejected )
3020+
if( openFileDialog->exec() == QDialog::Rejected )
30583021
{
30593022
delete openFileDialog;
30603023
return;
@@ -3864,29 +3827,6 @@ void QgisApp::saveAsVectorFileGeneral( bool saveOnlySelection )
38643827
destCRS = QgsCoordinateReferenceSystem( dialog->crs(), QgsCoordinateReferenceSystem::InternalCrsId );
38653828
}
38663829

3867-
// overwrite the file - user will already have been prompted
3868-
// to verify they want to overwrite by the file dialog above
3869-
// might not even exists in the given case.
3870-
// add the extension if not present
3871-
if ( format == "ESRI Shapefile" )
3872-
{
3873-
if ( !vectorFilename.endsWith( ".shp", Qt::CaseInsensitive ) )
3874-
{
3875-
vectorFilename += ".shp";
3876-
}
3877-
QgsVectorFileWriter::deleteShapeFile( vectorFilename );
3878-
}
3879-
3880-
//GE does not open files without extensions. Therefore we append it automatically for kml files
3881-
if ( format == "KML" )
3882-
{
3883-
if ( !vectorFilename.endsWith( ".kml", Qt::CaseInsensitive ) )
3884-
{
3885-
vectorFilename += ".kml";
3886-
}
3887-
encoding = "UTF-8";
3888-
}
3889-
38903830
// ok if the file existed it should be deleted now so we can continue...
38913831
QApplication::setOverrideCursor( Qt::WaitCursor );
38923832

‎src/app/qgisapp.h

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -742,11 +742,7 @@ class QgisApp : public QMainWindow
742742
* It won't force a refresh.
743743
*/
744744
bool addRasterLayer( QgsRasterLayer * theRasterLayer );
745-
//@todo We should move these next two into vector layer class
746-
/** This helper checks to see whether the file name appears to be a valid shape file name */
747-
bool isValidShapeFileName( QString theFileNameQString );
748-
/** Overloaded version of the above function provided for convenience that takes a qstring pointer */
749-
bool isValidShapeFileName( QString * theFileNameQString );
745+
750746
/** add this file to the recently opened/saved projects list
751747
* pass settings by reference since creating more than one
752748
* instance simultaneously results in data loss.

‎src/core/qgsvectorfilewriter.cpp

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@
4343

4444
QgsVectorFileWriter::QgsVectorFileWriter(
4545
const QString &theVectorFileName,
46-
const QString& fileEncoding,
46+
const QString &theFileEncoding,
4747
const QgsFieldMap& fields,
4848
QGis::WkbType geometryType,
4949
const QgsCoordinateReferenceSystem* srs,
@@ -54,6 +54,7 @@ QgsVectorFileWriter::QgsVectorFileWriter(
5454
, mError( NoError )
5555
{
5656
QString vectorFileName = theVectorFileName;
57+
QString fileEncoding = theFileEncoding;
5758

5859
// find driver in OGR
5960
OGRSFDriverH poDriver;
@@ -91,6 +92,27 @@ QgsVectorFileWriter::QgsVectorFileWriter(
9192
}
9293
fieldNames << name;
9394
}
95+
96+
deleteShapeFile( vectorFileName );
97+
}
98+
else if( driverName == "KML" )
99+
{
100+
if( !vectorFileName.endsWith( ".kml", Qt::CaseInsensitive ) )
101+
{
102+
vectorFileName += ".kml";
103+
}
104+
105+
if( fileEncoding.compare( "UTF-8", Qt::CaseInsensitive )!=0 )
106+
{
107+
QgsDebugMsg( "forced UTF-8 encoding for KML" );
108+
fileEncoding = "UTF-8";
109+
}
110+
111+
QFile::remove( vectorFileName );
112+
}
113+
else
114+
{
115+
QFile::remove( vectorFileName );
94116
}
95117

96118
// create the data source

0 commit comments

Comments
 (0)