[QGIS Commit] r13592 - in trunk/qgis/src: app app/ogr core

svn_qgis at osgeo.org svn_qgis at osgeo.org
Sat May 29 09:37:51 EDT 2010


Author: jef
Date: 2010-05-29 09:37:51 -0400 (Sat, 29 May 2010)
New Revision: 13592

Modified:
   trunk/qgis/src/app/ogr/qgsvectorlayersaveasdialog.cpp
   trunk/qgis/src/app/qgisapp.cpp
   trunk/qgis/src/app/qgisapp.h
   trunk/qgis/src/core/qgsvectorfilewriter.cpp
Log:
followup r13591: force KML encoding to utf-8 in save as dialog and move filename/encoding validation to vector file write

Modified: trunk/qgis/src/app/ogr/qgsvectorlayersaveasdialog.cpp
===================================================================
--- trunk/qgis/src/app/ogr/qgsvectorlayersaveasdialog.cpp	2010-05-29 12:44:11 UTC (rev 13591)
+++ trunk/qgis/src/app/ogr/qgsvectorlayersaveasdialog.cpp	2010-05-29 13:37:51 UTC (rev 13592)
@@ -74,6 +74,16 @@
 {
   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()

Modified: trunk/qgis/src/app/qgisapp.cpp
===================================================================
--- trunk/qgis/src/app/qgisapp.cpp	2010-05-29 12:44:11 UTC (rev 13591)
+++ trunk/qgis/src/app/qgisapp.cpp	2010-05-29 13:37:51 UTC (rev 13592)
@@ -2700,19 +2700,6 @@
   }
 }
 
-/** 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,32 +3017,8 @@
     openFileDialog->selectFilter( lastUsedFilter );
   }
 
-  int res;
-  while (( res = openFileDialog->exec() ) == QDialog::Accepted )
+  if( openFileDialog->exec() == QDialog::Rejected )
   {
-    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 )
-  {
     delete openFileDialog;
     return;
   }
@@ -3864,29 +3827,6 @@
       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 );
 

Modified: trunk/qgis/src/app/qgisapp.h
===================================================================
--- trunk/qgis/src/app/qgisapp.h	2010-05-29 12:44:11 UTC (rev 13591)
+++ trunk/qgis/src/app/qgisapp.h	2010-05-29 13:37:51 UTC (rev 13592)
@@ -742,11 +742,7 @@
      * 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.

Modified: trunk/qgis/src/core/qgsvectorfilewriter.cpp
===================================================================
--- trunk/qgis/src/core/qgsvectorfilewriter.cpp	2010-05-29 12:44:11 UTC (rev 13591)
+++ trunk/qgis/src/core/qgsvectorfilewriter.cpp	2010-05-29 13:37:51 UTC (rev 13592)
@@ -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 @@
     , mError( NoError )
 {
   QString vectorFileName = theVectorFileName;
+  QString fileEncoding = theFileEncoding;
 
   // find driver in OGR
   OGRSFDriverH poDriver;
@@ -91,8 +92,29 @@
       }
       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
   mDS = OGR_Dr_CreateDataSource( poDriver, vectorFileName.toLocal8Bit().data(), NULL );
   if ( mDS == NULL )



More information about the QGIS-commit mailing list