[QGIS Commit] r12544 - in trunk/qgis/src: app/legend core

svn_qgis at osgeo.org svn_qgis at osgeo.org
Sun Dec 20 13:07:28 EST 2009


Author: jef
Date: 2009-12-20 13:07:27 -0500 (Sun, 20 Dec 2009)
New Revision: 12544

Modified:
   trunk/qgis/src/app/legend/qgslegendlayer.cpp
   trunk/qgis/src/core/qgsvectorfilewriter.cpp
Log:
make QgsVectorLayer::deleteShapefile case-agnostic

Modified: trunk/qgis/src/app/legend/qgslegendlayer.cpp
===================================================================
--- trunk/qgis/src/app/legend/qgslegendlayer.cpp	2009-12-20 17:13:44 UTC (rev 12543)
+++ trunk/qgis/src/app/legend/qgslegendlayer.cpp	2009-12-20 18:07:27 UTC (rev 12544)
@@ -533,7 +533,7 @@
     return;
 
   // add the extension if not present
-  if ( shapefileName.indexOf( ".shp" ) == -1 )
+  if ( !shapefileName.endsWith( ".shp", Qt::CaseInsensitive ) )
   {
     shapefileName += ".shp";
   }
@@ -567,13 +567,8 @@
 
   // overwrite the file - user will already have been prompted
   // to verify they want to overwrite by the file dialog above
-  if ( QFile::exists( shapefileName ) )
-  {
-    if ( !QgsVectorFileWriter::deleteShapeFile( shapefileName ) )
-    {
-      return;
-    }
-  }
+  // might not even exists in the given case.
+  QgsVectorFileWriter::deleteShapeFile( shapefileName );
 
   // ok if the file existed it should be deleted now so we can continue...
   QApplication::setOverrideCursor( Qt::WaitCursor );

Modified: trunk/qgis/src/core/qgsvectorfilewriter.cpp
===================================================================
--- trunk/qgis/src/core/qgsvectorfilewriter.cpp	2009-12-20 17:13:44 UTC (rev 12543)
+++ trunk/qgis/src/core/qgsvectorfilewriter.cpp	2009-12-20 18:07:27 UTC (rev 12544)
@@ -29,6 +29,7 @@
 #include <QFile>
 #include <QSettings>
 #include <QFileInfo>
+#include <QDir>
 #include <QTextCodec>
 #include <QTextStream>
 #include <QSet>
@@ -439,25 +440,23 @@
 
 bool QgsVectorFileWriter::deleteShapeFile( QString theFileName )
 {
-  //
-  // Remove old copies that may be lying around
-  // TODO: should be case-insensitive
-  //
-  QString myFileBase = theFileName.replace( ".shp", "" );
-  bool ok = true;
+  QFileInfo fi( theFileName );
+  QDir dir = fi.dir();
 
+  QStringList filter;
   const char *suffixes[] = { ".shp", ".shx", ".dbf", ".prj", ".qix", ".qpj" };
   for ( std::size_t i = 0; i < sizeof( suffixes ) / sizeof( *suffixes ); i++ )
   {
-    QString file = myFileBase + suffixes[i];
-    QFileInfo myInfo( file );
-    if ( myInfo.exists() )
+    filter << fi.completeBaseName() + suffixes[i];
+  }
+
+  bool ok = true;
+  foreach( QString file, dir.entryList( filter ) )
+  {
+    if ( !QFile::remove( dir.canonicalPath() + "/" + file ) )
     {
-      if ( !QFile::remove( file ) )
-      {
-        QgsDebugMsg( "Removing file failed : " + file );
-        ok = false;
-      }
+      QgsDebugMsg( "Removing file failed : " + file );
+      ok = false;
     }
   }
 



More information about the QGIS-commit mailing list