@@ -5235,10 +5235,12 @@ void QgisApp::fileOpen()
5235
5235
// Retrieve last used project dir from persistent settings
5236
5236
QgsSettings settings;
5237
5237
QString lastUsedDir = settings.value ( QStringLiteral ( " UI/lastProjectDir" ), QDir::homePath () ).toString ();
5238
+ const QString qgs_ext = tr ( " QGIS files" ) + " (*.qgs *.QGS)" ;
5239
+ const QString zip_ext = tr ( " QGZ files" ) + " (*.qgz)" ;
5238
5240
QString fullPath = QFileDialog::getOpenFileName ( this ,
5239
5241
tr ( " Choose a QGIS project file to open" ),
5240
5242
lastUsedDir,
5241
- tr ( " QGIS files " ) + " (*.qgs *.QGS) " );
5243
+ qgs_ext + " ;; " + zip_ext );
5242
5244
if ( fullPath.isNull () )
5243
5245
{
5244
5246
return ;
@@ -5271,6 +5273,8 @@ void QgisApp::enableProjectMacros()
5271
5273
*/
5272
5274
bool QgisApp::addProject ( const QString &projectFile )
5273
5275
{
5276
+ bool zip = ( QFileInfo ( projectFile ).suffix () == " qgz" ) ? true : false ;
5277
+
5274
5278
// close the previous opened project if any
5275
5279
closeProject ();
5276
5280
@@ -5283,7 +5287,17 @@ bool QgisApp::addProject( const QString &projectFile )
5283
5287
bool autoSetupOnFirstLayer = mLayerTreeCanvasBridge ->autoSetupOnFirstLayer ();
5284
5288
mLayerTreeCanvasBridge ->setAutoSetupOnFirstLayer ( false );
5285
5289
5286
- if ( !QgsProject::instance ()->read ( projectFile ) )
5290
+ bool readOk = false ;
5291
+ if ( zip )
5292
+ {
5293
+ readOk = QgsProject::instance ()->unzip ( projectFile );
5294
+ }
5295
+ else
5296
+ {
5297
+ readOk = QgsProject::instance ()->read ( projectFile );
5298
+ }
5299
+
5300
+ if ( !readOk && !zip )
5287
5301
{
5288
5302
QString backupFile = projectFile + " ~" ;
5289
5303
QString loadBackupPrompt;
@@ -5417,34 +5431,47 @@ bool QgisApp::fileSave()
5417
5431
// that the project file name is reset to null in fileNew()
5418
5432
QFileInfo fullPath;
5419
5433
5420
- if ( QgsProject::instance ()->fileName ().isNull () )
5434
+ if ( QgsProject::instance ()->fileName ().isNull () && QgsProject::instance ()-> zipFileName (). isNull () )
5421
5435
{
5422
5436
// Retrieve last used project dir from persistent settings
5423
5437
QgsSettings settings;
5424
5438
QString lastUsedDir = settings.value ( QStringLiteral ( " UI/lastProjectDir" ), QDir::homePath () ).toString ();
5425
5439
5440
+ const QString qgs_ext = tr ( " QGIS files" ) + " (*.qgs)" ;
5441
+ const QString zip_ext = tr ( " QGZ files" ) + " (*.qgz)" ;
5442
+ QString filter;
5426
5443
QString path = QFileDialog::getSaveFileName (
5427
5444
this ,
5428
5445
tr ( " Choose a QGIS project file" ),
5429
5446
lastUsedDir + ' /' + QgsProject::instance ()->title (),
5430
- tr ( " QGIS files " ) + " (*.qgs *.QGS) " );
5447
+ qgs_ext + " ;; " + zip_ext, &filter );
5431
5448
if ( path.isEmpty () )
5432
5449
return false ;
5433
5450
5434
5451
fullPath.setFile ( path );
5435
5452
5436
5453
// make sure we have the .qgs extension in the file name
5437
- if ( " qgs " != fullPath. suffix (). toLower () )
5454
+ if ( filter == zip_ext )
5438
5455
{
5439
- fullPath. setFile ( fullPath.filePath () + " .qgs " );
5440
- }
5456
+ if ( " qgz " != fullPath.suffix (). toLower () )
5457
+ fullPath. setFile ( fullPath. filePath () + " .qgz " );
5441
5458
5459
+ QgsProject::instance ()->setZipFileName ( fullPath.filePath () );
5460
+ }
5461
+ else
5462
+ {
5463
+ if ( " qgs" != fullPath.suffix ().toLower () )
5464
+ fullPath.setFile ( fullPath.filePath () + " .qgs" );
5442
5465
5443
- QgsProject::instance ()->setFileName ( fullPath.filePath () );
5466
+ QgsProject::instance ()->setFileName ( fullPath.filePath () );
5467
+ }
5444
5468
}
5445
5469
else
5446
5470
{
5447
5471
QFileInfo fi ( QgsProject::instance ()->fileName () );
5472
+ if ( QgsProject::instance ()->unzipped () )
5473
+ fi.setFile ( QgsProject::instance ()->zipFileName () );
5474
+
5448
5475
fullPath = fi.absoluteFilePath ();
5449
5476
if ( fi.exists () && !mProjectLastModified .isNull () && mProjectLastModified != fi.lastModified () )
5450
5477
{
@@ -5468,20 +5495,34 @@ bool QgisApp::fileSave()
5468
5495
}
5469
5496
}
5470
5497
5471
- if ( QgsProject::instance ()->write () )
5498
+ bool writeOk = false ;
5499
+ QString writtenFileName;
5500
+
5501
+ if ( QgsProject::instance ()->unzipped () )
5502
+ {
5503
+ writeOk = QgsProject::instance ()->zip ();
5504
+ writtenFileName = QgsProject::instance ()->zipFileName ();
5505
+ }
5506
+ else
5507
+ {
5508
+ writeOk = QgsProject::instance ()->write ();
5509
+ writtenFileName = QgsProject::instance ()->fileName ();
5510
+ }
5511
+
5512
+ if ( writeOk )
5472
5513
{
5473
5514
setTitleBarText_ ( *this ); // update title bar
5474
- mStatusBar ->showMessage ( tr ( " Saved project to: %1" ).arg ( QDir::toNativeSeparators ( QgsProject::instance ()-> fileName () ) ), 5000 );
5515
+ mStatusBar ->showMessage ( tr ( " Saved project to: %1" ).arg ( QDir::toNativeSeparators ( writtenFileName ) ), 5000 );
5475
5516
5476
5517
saveRecentProjectPath ( fullPath.filePath () );
5477
5518
5478
- QFileInfo fi ( QgsProject::instance ()-> fileName () );
5519
+ QFileInfo fi ( writtenFileName );
5479
5520
mProjectLastModified = fi.lastModified ();
5480
5521
}
5481
5522
else
5482
5523
{
5483
5524
QMessageBox::critical ( this ,
5484
- tr ( " Unable to save project %1" ).arg ( QDir::toNativeSeparators ( QgsProject::instance ()-> fileName () ) ),
5525
+ tr ( " Unable to save project %1" ).arg ( QDir::toNativeSeparators ( writtenFileName ) ),
5485
5526
QgsProject::instance ()->error () );
5486
5527
return false ;
5487
5528
}
@@ -5501,29 +5542,41 @@ void QgisApp::fileSaveAs()
5501
5542
QgsSettings settings;
5502
5543
QString lastUsedDir = settings.value ( QStringLiteral ( " UI/lastProjectDir" ), QDir::homePath () ).toString ();
5503
5544
5545
+ const QString qgs_ext = tr ( " QGIS files" ) + " (*.qgs *.QGS)" ;
5546
+ const QString zip_ext = tr ( " QGZ files" ) + " (*.qgz)" ;
5547
+ QString filter;
5504
5548
QString path = QFileDialog::getSaveFileName ( this ,
5505
5549
tr ( " Choose a file name to save the QGIS project file as" ),
5506
5550
lastUsedDir + ' /' + QgsProject::instance ()->title (),
5507
- tr ( " QGIS files " ) + " (*.qgs *.QGS) " );
5551
+ qgs_ext + " ;; " + zip_ext, &filter );
5508
5552
if ( path.isEmpty () )
5509
5553
return ;
5510
5554
5511
5555
QFileInfo fullPath ( path );
5512
5556
5513
5557
settings.setValue ( QStringLiteral ( " UI/lastProjectDir" ), fullPath.path () );
5514
5558
5515
- // make sure the .qgs extension is included in the path name. if not, add it...
5516
- if ( " qgs " != fullPath. suffix (). toLower () )
5559
+ bool writeOk = false ;
5560
+ if ( filter == zip_ext )
5517
5561
{
5518
- fullPath.setFile ( fullPath.filePath () + " .qgs" );
5562
+ if ( " qgz" != fullPath.suffix ().toLower () )
5563
+ fullPath.setFile ( fullPath.filePath () + " .qgz" );
5564
+
5565
+ writeOk = QgsProject::instance ()->zip ( fullPath.filePath () );
5519
5566
}
5567
+ else // .qgs
5568
+ {
5569
+ if ( " qgs" != fullPath.suffix ().toLower () )
5570
+ fullPath.setFile ( fullPath.filePath () + " .qgs" );
5520
5571
5521
- QgsProject::instance ()->setFileName ( fullPath.filePath () );
5572
+ QgsProject::instance ()->setFileName ( fullPath.filePath () );
5573
+ writeOk = QgsProject::instance ()->write ();
5574
+ }
5522
5575
5523
- if ( QgsProject::instance ()-> write () )
5576
+ if ( writeOk )
5524
5577
{
5525
5578
setTitleBarText_ ( *this ); // update title bar
5526
- mStatusBar ->showMessage ( tr ( " Saved project to: %1" ).arg ( QDir::toNativeSeparators ( QgsProject::instance ()-> fileName () ) ), 5000 );
5579
+ mStatusBar ->showMessage ( tr ( " Saved project to: %1" ).arg ( QDir::toNativeSeparators ( fullPath. filePath () ) ), 5000 );
5527
5580
// add this to the list of recently used project files
5528
5581
saveRecentProjectPath ( fullPath.filePath () );
5529
5582
mProjectLastModified = fullPath.lastModified ();
0 commit comments