Skip to content
Permalink
Browse files

Bug fox for #809 - file writer does not over write shapefiles.

Files will now be owritten. Unit tests updated too.


git-svn-id: http://svn.osgeo.org/qgis/trunk/qgis@7409 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
timlinux
timlinux committed Nov 15, 2007
1 parent aa213a5 commit 4b1c60ca32f4b6edb4f06ab74bcc504bb4deaeb0
Showing with 62 additions and 0 deletions.
  1. +10 −0 src/app/legend/qgslegendlayerfile.cpp
  2. +47 −0 src/core/qgsvectorfilewriter.cpp
  3. +5 −0 src/core/qgsvectorfilewriter.h
@@ -343,6 +343,16 @@ void QgsLegendLayerFile::saveAsShapefileGeneral(bool saveOnlySelection)
shapefileName += ".shp";
}

// 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;
}
}
// ok if the file existed it should be deleted now so we can continue...
QApplication::setOverrideCursor(Qt::waitCursor);

QgsVectorFileWriter::WriterError error;
@@ -26,6 +26,7 @@
#include "qgsvectordataprovider.h"

#include <QFile>
#include <QFileInfo>
#include <QTextCodec>

#include <cassert>
@@ -329,3 +330,49 @@ QgsVectorFileWriter::WriterError

return NoError;
}


bool QgsVectorFileWriter::deleteShapeFile(QString theFileName)
{
//
// Remove old copies that may be lying around
//
QFileInfo myInfo(theFileName);
QString myFileBase = theFileName.replace(".shp","");
if (myInfo.exists())
{
if(!QFile::remove(myFileBase + ".shp"))
{
qDebug("Removing file failed : " + myFileBase.toLocal8Bit() + ".shp");
return 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;
}
@@ -73,6 +73,11 @@ class CORE_EXPORT QgsVectorFileWriter
/** 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);
protected:

OGRGeometry* createEmptyGeometry(QGis::WKBTYPE wkbType);

0 comments on commit 4b1c60c

Please sign in to comment.
You can’t perform that action at this time.