Skip to content
Permalink
Browse files

make QgsVectorLayer::deleteShapefile case-agnostic

git-svn-id: http://svn.osgeo.org/qgis/trunk@12544 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
jef
jef committed Dec 20, 2009
1 parent 0d211e8 commit cace1e2468663f213c5225a78cf9fd4df6f564be
Showing with 16 additions and 22 deletions.
  1. +3 −8 src/app/legend/qgslegendlayer.cpp
  2. +13 −14 src/core/qgsvectorfilewriter.cpp
@@ -533,7 +533,7 @@ void QgsLegendLayer::saveAsShapefileGeneral( bool saveOnlySelection )
return;

// add the extension if not present
if ( shapefileName.indexOf( ".shp" ) == -1 )
if ( !shapefileName.endsWith( ".shp", Qt::CaseInsensitive ) )
{
shapefileName += ".shp";
}
@@ -567,13 +567,8 @@ void QgsLegendLayer::saveAsShapefileGeneral( bool saveOnlySelection )

// 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 );
@@ -29,6 +29,7 @@
#include <QFile>
#include <QSettings>
#include <QFileInfo>
#include <QDir>
#include <QTextCodec>
#include <QTextStream>
#include <QSet>
@@ -439,25 +440,23 @@ QgsVectorFileWriter::writeAsShapefile( QgsVectorLayer* layer,

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;
}
}

0 comments on commit cace1e2

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