@@ -2990,33 +2990,24 @@ void QgisApp::newVectorLayer()
2990
2990
std::list<std::pair<QString, QString> > attributes;
2991
2991
geomDialog.attributes ( attributes );
2992
2992
2993
- bool haveLastUsedFilter = false ; // by default, there is no last
2994
- // used filter
2995
2993
QString enc;
2996
2994
QString fileName;
2997
2995
2998
- QSettings settings; // where we keep last used filter in
2999
- // persistent state
3000
-
3001
- haveLastUsedFilter = settings.contains ( " /UI/lastVectorFileFilter" );
3002
- QString lastUsedFilter = settings.value ( " /UI/lastVectorFileFilter" ,
3003
- QVariant ( QString::null ) ).toString ();
3004
-
3005
- QString lastUsedDir = settings.value ( " /UI/lastVectorFileFilterDir" ,
3006
- " ." ).toString ();
2996
+ QSettings settings;
2997
+ QString lastUsedDir = settings.value ( " /UI/lastVectorFileFilterDir" , " ." ).toString ();
3007
2998
3008
2999
QgsDebugMsg ( " Saving vector file dialog without filters: " );
3009
3000
3010
- QgsEncodingFileDialog* openFileDialog = new QgsEncodingFileDialog ( this ,
3011
- tr ( " Save As" ), lastUsedDir, " " , QString ( " " ) );
3001
+ QgsEncodingFileDialog* openFileDialog =
3002
+ new QgsEncodingFileDialog ( this , tr ( " Save As" ), lastUsedDir, " " , QString ( " " ) );
3012
3003
3013
- // allow for selection of more than one file
3014
3004
openFileDialog->setFileMode ( QFileDialog::AnyFile );
3015
3005
openFileDialog->setAcceptMode ( QFileDialog::AcceptSave );
3016
3006
openFileDialog->setConfirmOverwrite ( true );
3017
3007
3018
- if ( haveLastUsedFilter ) // set the filter to the last one used
3008
+ if ( settings. contains ( " /UI/lastVectorFileFilter " ) )
3019
3009
{
3010
+ QString lastUsedFilter = settings.value ( " /UI/lastVectorFileFilter" , QVariant ( QString::null ) ).toString ();
3020
3011
openFileDialog->selectFilter ( lastUsedFilter );
3021
3012
}
3022
3013
@@ -3026,23 +3017,14 @@ void QgisApp::newVectorLayer()
3026
3017
return ;
3027
3018
}
3028
3019
3029
- enc = openFileDialog->encoding ();
3020
+ fileName = openFileDialog->selectedFiles (). first ();
3030
3021
3031
- // If the file exists, delete it otherwise we'll end up loading that
3032
- // file, which can cause problems (e.g., if the file contains
3033
- // linestrings, but we're wanting to create points, we'll end up
3034
- // with a linestring file).
3035
- if ( fileformat == " ESRI Shapefile" )
3036
- {
3037
- QgsVectorFileWriter::deleteShapeFile ( fileName );
3038
- }
3039
- else
3040
- {
3041
- QFile::remove ( fileName );
3042
- }
3022
+ if ( fileformat == " ESRI Shapefile" && !fileName.endsWith ( " .shp" , Qt::CaseInsensitive ) )
3023
+ fileName += " .shp" ;
3043
3024
3044
- settings. setValue ( " /UI/lastVectorFileFilter " , openFileDialog->selectedFilter () );
3025
+ enc = openFileDialog->encoding ( );
3045
3026
3027
+ settings.setValue ( " /UI/lastVectorFileFilter" , openFileDialog->selectedFilter () );
3046
3028
settings.setValue ( " /UI/lastVectorFileFilterDir" , openFileDialog->directory ().absolutePath () );
3047
3029
3048
3030
delete openFileDialog;
0 commit comments