[QGIS Commit] r8621 - in trunk/qgis: python/core src/core

svn_qgis at osgeo.org svn_qgis at osgeo.org
Sat Jun 7 20:55:29 EDT 2008


Author: wonder
Date: 2008-06-07 20:55:29 -0400 (Sat, 07 Jun 2008)
New Revision: 8621

Modified:
   trunk/qgis/python/core/qgsvectorfilewriter.sip
   trunk/qgis/src/core/qgsvectorfilewriter.cpp
Log:
QgsVectorFileWriter:
- added missing deleteShapeFile() PyQGIS wrapper
- added some error handling when adding features
- improved deleteShapeFile method


Modified: trunk/qgis/python/core/qgsvectorfilewriter.sip
===================================================================
--- trunk/qgis/python/core/qgsvectorfilewriter.sip	2008-06-08 00:43:41 UTC (rev 8620)
+++ trunk/qgis/python/core/qgsvectorfilewriter.sip	2008-06-08 00:55:29 UTC (rev 8621)
@@ -47,5 +47,10 @@
     /** close opened shapefile for writing */
     ~QgsVectorFileWriter();
     
+    /** Delete a shapefile (and its accompanying shx / dbf / prf)
+     * @param QString theFileName - /path/to/file.shp
+     * @return bool true if the file was deleted successfully
+     */ 
+    static bool deleteShapeFile(QString theFileName);
 };
 

Modified: trunk/qgis/src/core/qgsvectorfilewriter.cpp
===================================================================
--- trunk/qgis/src/core/qgsvectorfilewriter.cpp	2008-06-08 00:43:41 UTC (rev 8620)
+++ trunk/qgis/src/core/qgsvectorfilewriter.cpp	2008-06-08 00:55:29 UTC (rev 8621)
@@ -200,7 +200,7 @@
         OGR_F_SetFieldString(poFeature, ogrField, mCodec->fromUnicode(attrValue.toString()).data());
         break;
       default:
-        //assert(0 && "invalid variant type");
+        QgsDebugMsg("Invalid variant type for field "+QString::number(ogrField)+": "+QString::number(attrValue.type()));
         return false;
     }
   }
@@ -321,43 +321,25 @@
 {
   //
   // Remove old copies that may be lying around
+  // TODO: should be case-insensitive
   //
-  QFileInfo myInfo(theFileName);
   QString myFileBase = theFileName.replace(".shp","");
-  if (myInfo.exists())
+  bool ok = TRUE;
+
+  const char* suffixes[] = { ".shp", ".shx", ".dbf", ".prj", ".qix" };
+  for (int i = 0; i < sizeof(suffixes) / sizeof(char*); i++)
   {
-    if(!QFile::remove(myFileBase + ".shp"))
+    QString file = myFileBase + suffixes[i];
+    QFileInfo myInfo(file);
+    if (myInfo.exists())
     {
-      qDebug("Removing file failed : " + myFileBase.toLocal8Bit() + ".shp");
-      return false;
+      if(!QFile::remove(file))
+      {
+        QgsDebugMsg("Removing file failed : " + file);
+        ok = FALSE;
+      }
     }
   }
-  myInfo.setFile(myFileBase + ".shx");
-  if (myInfo.exists())
-  {
-    if(!QFile::remove(myFileBase + ".shx"))
-    {
-      qDebug("Removing file failed : " + myFileBase.toLocal8Bit() + ".shx");
-      return false;
-    }
-  }
-  myInfo.setFile(myFileBase + ".dbf");
-  if (myInfo.exists())
-  {
-    if(!QFile::remove(myFileBase + ".dbf"))
-    {
-      qDebug("Removing file failed : " + myFileBase.toLocal8Bit() + ".dbf");
-      return false;
-    }
-  }
-  myInfo.setFile(myFileBase + ".prj");
-  if (myInfo.exists())
-  {
-    if(!QFile::remove(myFileBase + ".prj"))
-    {
-      qDebug("Removing file failed : " + myFileBase.toLocal8Bit() + ".prj");
-      return false;
-    }
-  }
-  return true;
+  
+  return ok;
 }



More information about the QGIS-commit mailing list