QgsVectorFileWriter:

- added missing deleteShapeFile() PyQGIS wrapper
- added some error handling when adding features
- improved deleteShapeFile method


git-svn-id: http://svn.osgeo.org/qgis/trunk@8621 c8812cc2-4d05-0410-92ff-de0c093fc19c
This commit is contained in:
wonder 2008-06-08 00:55:29 +00:00
parent e674fcafb5
commit e32b9bf1e3
2 changed files with 21 additions and 34 deletions

View File

@ -47,5 +47,10 @@ public:
/** 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);
};

View File

@ -200,7 +200,7 @@ bool QgsVectorFileWriter::addFeature(QgsFeature& feature)
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 @@ bool QgsVectorFileWriter::deleteShapeFile(QString theFileName)
{
//
// 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;
}