@@ -2304,8 +2304,6 @@ static bool openFilesRememberingFilter_( QString const &filterName,
2304
2304
bool cancelAll = false )
2305
2305
{
2306
2306
2307
- bool retVal = false ;
2308
-
2309
2307
bool haveLastUsedFilter = false ; // by default, there is no last
2310
2308
// used filter
2311
2309
@@ -2319,28 +2317,9 @@ static bool openFilesRememberingFilter_( QString const &filterName,
2319
2317
QString lastUsedDir = settings.value ( " /UI/" + filterName + " Dir" , " ." ).toString ();
2320
2318
2321
2319
QgsDebugMsg ( " Opening file dialog with filters: " + filters );
2322
-
2323
- QgsEncodingFileDialog* openFileDialog = new QgsEncodingFileDialog ( 0 ,
2324
- title, lastUsedDir, filters, QString ( " " ) );
2325
-
2326
- // allow for selection of more than one file
2327
- openFileDialog->setFileMode ( QFileDialog::ExistingFiles );
2328
-
2329
- if ( haveLastUsedFilter ) // set the filter to the last one used
2330
- {
2331
- openFileDialog->selectFilter ( lastUsedFilter );
2332
- }
2333
-
2334
- // Check if we should add a cancel all button
2335
- if ( cancelAll )
2336
- {
2337
- openFileDialog->addCancelAll ();
2338
- }
2339
-
2340
- if ( openFileDialog->exec () == QDialog::Accepted )
2320
+ selectedFiles = QFileDialog::getOpenFileNames ( 0 , title, lastUsedDir, filters, &lastUsedFilter );
2321
+ if ( !selectedFiles.isEmpty () )
2341
2322
{
2342
- selectedFiles = openFileDialog->selectedFiles ();
2343
- enc = openFileDialog->encoding ();
2344
2323
// Fix by Tim - getting the dirPath from the dialog
2345
2324
// directly truncates the last node in the dir path.
2346
2325
// This is a workaround for that
@@ -2350,17 +2329,11 @@ static bool openFilesRememberingFilter_( QString const &filterName,
2350
2329
2351
2330
QgsDebugMsg ( " Writing last used dir: " + myPath );
2352
2331
2353
- settings.setValue ( " /UI/" + filterName, openFileDialog-> selectedFilter () );
2332
+ settings.setValue ( " /UI/" + filterName, lastUsedFilter );
2354
2333
settings.setValue ( " /UI/" + filterName + " Dir" , myPath );
2334
+ return true ;
2355
2335
}
2356
- else
2357
- {
2358
- // Cancel or cancel all
2359
- retVal = openFileDialog->cancelAll ();
2360
- }
2361
-
2362
- delete openFileDialog;
2363
- return retVal;
2336
+ return false ;
2364
2337
} // openFilesRememberingFilter_
2365
2338
2366
2339
@@ -3281,33 +3254,19 @@ void QgisApp::fileOpen()
3281
3254
// Retrieve last used project dir from persistent settings
3282
3255
QSettings settings;
3283
3256
QString lastUsedDir = settings.value ( " /UI/lastProjectDir" , " ." ).toString ();
3284
-
3285
- QFileDialog * openFileDialog = new QFileDialog ( this ,
3286
- tr ( " Choose a QGIS project file to open" ),
3287
- lastUsedDir, tr ( " QGis files (*.qgs)" ) );
3288
- openFileDialog->setFileMode ( QFileDialog::ExistingFile );
3289
-
3290
-
3291
- QString fullPath;
3292
- if ( openFileDialog->exec () == QDialog::Accepted )
3293
- {
3294
- // Fix by Tim - getting the dirPath from the dialog
3295
- // directly truncates the last node in the dir path.
3296
- // This is a workaround for that
3297
- fullPath = openFileDialog->selectedFiles ().first ();
3298
- QFileInfo myFI ( fullPath );
3299
- QString myPath = myFI.path ();
3300
- // Persist last used project dir
3301
- settings.setValue ( " /UI/lastProjectDir" , myPath );
3302
- }
3303
- else
3257
+ QString fullPath = QFileDialog::getOpenFileName ( this , tr ( " Choose a QGIS project file to open" ), lastUsedDir, tr ( " QGis files (*.qgs)" ) );
3258
+ if ( fullPath.isNull () )
3304
3259
{
3305
- // if they didn't select anything, just return
3306
- delete openFileDialog;
3307
3260
return ;
3308
3261
}
3309
3262
3310
- delete openFileDialog;
3263
+ // Fix by Tim - getting the dirPath from the dialog
3264
+ // directly truncates the last node in the dir path.
3265
+ // This is a workaround for that
3266
+ QFileInfo myFI ( fullPath );
3267
+ QString myPath = myFI.path ();
3268
+ // Persist last used project dir
3269
+ settings.setValue ( " /UI/lastProjectDir" , myPath );
3311
3270
3312
3271
delete mComposer ;
3313
3272
mComposer = new QgsComposer ( this );
@@ -3563,55 +3522,31 @@ void QgisApp::fileSaveAs()
3563
3522
// Retrieve last used project dir from persistent settings
3564
3523
QSettings settings;
3565
3524
QString lastUsedDir = settings.value ( " /UI/lastProjectDir" , " ." ).toString ();
3566
-
3567
- std::auto_ptr<QFileDialog> saveFileDialog ( new QFileDialog ( this ,
3568
- tr ( " Choose a file name to save the QGIS project file as" ),
3569
- lastUsedDir, tr ( " QGis files (*.qgs)" ) ) );
3570
-
3571
- saveFileDialog->setFileMode ( QFileDialog::AnyFile );
3572
-
3573
- saveFileDialog->setAcceptMode ( QFileDialog::AcceptSave );
3574
-
3575
- saveFileDialog->setConfirmOverwrite ( true );
3576
-
3577
- // if we don't have a file name, then obviously we need to get one; note
3578
- // that the project file name is reset to null in fileNew()
3579
- QFileInfo fullPath;
3580
-
3581
- if ( saveFileDialog->exec () == QDialog::Accepted )
3525
+ QString saveFilePath = QFileDialog::getSaveFileName ( this , tr ( " Choose a file name to save the QGIS project file as" ), lastUsedDir, tr ( " QGis files (*.qgs)" ) );
3526
+ if ( saveFilePath.isNull () ) // canceled
3582
3527
{
3583
- // Fix by Tim - getting the dirPath from the dialog
3584
- // directly truncates the last node in the dir path.
3585
- // This is a workaround for that
3586
- fullPath.setFile ( saveFileDialog->selectedFiles ().first () );
3587
- QString myPath = fullPath.path ();
3588
- // Persist last used project dir
3589
- settings.setValue ( " /UI/lastProjectDir" , myPath );
3590
- }
3591
- else
3592
- {
3593
- // if they didn't select anything, just return
3594
- // delete saveFileDialog; auto_ptr auto deletes
3595
3528
return ;
3596
3529
}
3530
+ QFileInfo myFI ( saveFilePath );
3531
+ QString myPath = myFI.path ();
3532
+ settings.setValue ( " /UI/lastProjectDir" , myPath );
3597
3533
3598
3534
// make sure the .qgs extension is included in the path name. if not, add it...
3599
- if ( " qgs" != fullPath .suffix () )
3535
+ if ( " qgs" != myFI .suffix () )
3600
3536
{
3601
- QString newFilePath = fullPath.filePath () + " .qgs" ;
3602
- fullPath.setFile ( newFilePath );
3537
+ saveFilePath = myFI.filePath () + " .qgs" ;
3603
3538
}
3604
3539
3605
3540
try
3606
3541
{
3607
- QgsProject::instance ()->setFileName ( fullPath. filePath () );
3542
+ QgsProject::instance ()->setFileName ( saveFilePath );
3608
3543
3609
3544
if ( QgsProject::instance ()->write () )
3610
3545
{
3611
3546
setTitleBarText_ ( *this ); // update title bar
3612
3547
statusBar ()->showMessage ( tr ( " Saved project to: %1" ).arg ( QgsProject::instance ()->fileName () ) );
3613
3548
// add this to the list of recently used project files
3614
- saveRecentProjectPath ( fullPath. filePath () , settings );
3549
+ saveRecentProjectPath ( saveFilePath , settings );
3615
3550
}
3616
3551
else
3617
3552
{
0 commit comments