Skip to content

Commit cef1363

Browse files
authored
Merge pull request qgis#55440 from nirvn/qgis_project_save
[ui] Let typed QGIS project file extension dictate the type when saving projects
2 parents b0bb44e + 3a0f6d8 commit cef1363

File tree

2 files changed

+61
-58
lines changed

2 files changed

+61
-58
lines changed

src/app/qgisapp.cpp

Lines changed: 59 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -6386,10 +6386,9 @@ void QgisApp::fileOpen()
63866386
QgsSettings settings;
63876387
QString lastUsedDir = settings.value( QStringLiteral( "UI/lastProjectDir" ), QDir::homePath() ).toString();
63886388

6389-
63906389
QStringList fileFilters;
63916390
QStringList extensions;
6392-
fileFilters << tr( "QGIS files" ) + QStringLiteral( " (*.qgs *.qgz *.QGS *.QGZ)" );
6391+
fileFilters << tr( "QGIS Project Formats" ) + QStringLiteral( " (*.qgz *.QGZ *.qgs *.QGS)" );
63936392
extensions << QStringLiteral( "qgs" ) << QStringLiteral( "qgz" );
63946393
for ( QgsCustomProjectOpenHandler *handler : std::as_const( mCustomProjectOpenHandlers ) )
63956394
{
@@ -6636,45 +6635,47 @@ bool QgisApp::fileSave()
66366635
QgsSettings settings;
66376636
QString lastUsedDir = settings.value( QStringLiteral( "UI/lastProjectDir" ), QDir::homePath() ).toString();
66386637

6639-
const QString qgsExt = tr( "QGIS files" ) + " (*.qgs)";
6640-
const QString zipExt = tr( "QGZ files" ) + " (*.qgz)";
6641-
6642-
QString exts;
66436638
Qgis::ProjectFileFormat defaultProjectFileFormat = settings.enumValue( QStringLiteral( "/qgis/defaultProjectFileFormat" ), Qgis::ProjectFileFormat::Qgz );
6644-
switch ( defaultProjectFileFormat )
6645-
{
6646-
case Qgis::ProjectFileFormat::Qgs:
6647-
{
6648-
exts = qgsExt + QStringLiteral( ";;" ) + zipExt;
6649-
break;
6650-
}
6651-
case Qgis::ProjectFileFormat::Qgz:
6652-
{
6653-
exts = zipExt + QStringLiteral( ";;" ) + qgsExt;
6654-
}
6655-
}
6639+
const QString qgisProjectExt = tr( "QGIS Project Formats" ) + ( defaultProjectFileFormat == Qgis::ProjectFileFormat::Qgz ? " (*.qgz *.QGZ *.qgs *.QGS)" : " (*.qgs *.QGS *.qgz *.QGZ)" );
6640+
const QString qgzProjectExt = tr( "QGIS Bundled Project Format" ) + " (*.qgz *.QGZ)";
6641+
const QString qgsProjectExt = tr( "QGIS XML Project Format" ) + " (*.qgs *.QGS)";
6642+
66566643
QString filter;
66576644
QString path = QFileDialog::getSaveFileName(
66586645
this,
66596646
tr( "Choose a QGIS project file" ),
66606647
lastUsedDir + '/' + QgsProject::instance()->title(),
6661-
exts, &filter );
6648+
qgisProjectExt + QStringLiteral( ";;" ) + qgzProjectExt + QStringLiteral( ";;" ) + qgsProjectExt, &filter );
66626649
if ( path.isEmpty() )
66636650
return false;
66646651

6665-
QFileInfo fullPath;
6666-
fullPath.setFile( path );
6652+
QFileInfo fullPath( path );
6653+
QgsSettings().setValue( QStringLiteral( "UI/lastProjectDir" ), fullPath.path() );
66676654

6668-
// make sure we have the .qgs extension in the file name
6669-
if ( filter == zipExt )
6655+
const QString ext = fullPath.suffix().toLower();
6656+
if ( filter == qgisProjectExt && ext != QLatin1String( "qgz" ) && ext != QLatin1String( "qgs" ) )
66706657
{
6671-
if ( fullPath.suffix().compare( QLatin1String( "qgz" ), Qt::CaseInsensitive ) != 0 )
6672-
fullPath.setFile( fullPath.filePath() + ".qgz" );
6658+
switch ( defaultProjectFileFormat )
6659+
{
6660+
case Qgis::ProjectFileFormat::Qgs:
6661+
{
6662+
fullPath.setFile( fullPath.filePath() + ".qgs" );
6663+
break;
6664+
}
6665+
case Qgis::ProjectFileFormat::Qgz:
6666+
{
6667+
fullPath.setFile( fullPath.filePath() + ".qgz" );
6668+
break;
6669+
}
6670+
}
66736671
}
6674-
else
6672+
else if ( filter == qgzProjectExt && ext != QLatin1String( "qgz" ) )
66756673
{
6676-
if ( fullPath.suffix().compare( QLatin1String( "qgs" ), Qt::CaseInsensitive ) != 0 )
6677-
fullPath.setFile( fullPath.filePath() + ".qgs" );
6674+
fullPath.setFile( fullPath.filePath() + ".qgz" );
6675+
}
6676+
else if ( filter == qgsProjectExt && ext != QLatin1String( "qgs" ) )
6677+
{
6678+
fullPath.setFile( fullPath.filePath() + ".qgs" );
66786679
}
66796680

66806681
QgsProject::instance()->setFileName( fullPath.filePath() );
@@ -6750,45 +6751,47 @@ void QgisApp::fileSaveAs()
67506751
defaultPath += QString( '/' + QgsProject::instance()->title() );
67516752
}
67526753

6753-
const QString qgsExt = tr( "QGIS files" ) + " (*.qgs *.QGS)";
6754-
const QString zipExt = tr( "QGZ files" ) + " (*.qgz)";
6755-
6756-
QString exts;
67576754
Qgis::ProjectFileFormat defaultProjectFileFormat = settings.enumValue( QStringLiteral( "/qgis/defaultProjectFileFormat" ), Qgis::ProjectFileFormat::Qgz );
6758-
switch ( defaultProjectFileFormat )
6759-
{
6760-
case Qgis::ProjectFileFormat::Qgs:
6761-
{
6762-
exts = qgsExt + QStringLiteral( ";;" ) + zipExt;
6763-
break;
6764-
}
6765-
case Qgis::ProjectFileFormat::Qgz:
6766-
{
6767-
exts = zipExt + QStringLiteral( ";;" ) + qgsExt;
6768-
break;
6769-
}
6770-
}
6755+
const QString qgisProjectExt = tr( "QGIS Project Formats" ) + ( defaultProjectFileFormat == Qgis::ProjectFileFormat::Qgz ? " (*.qgz *.QGZ *.qgs *.QGS)" : " (*.qgs *.QGS *.qgz *.QGZ)" );
6756+
const QString qgzProjectExt = tr( "QGIS Bundled Project Format" ) + " (*.qgz *.QGZ)";
6757+
const QString qgsProjectExt = tr( "QGIS XML Project Format" ) + " (*.qgs *.QGS)";
6758+
67716759
QString filter;
6772-
QString path = QFileDialog::getSaveFileName( this,
6773-
tr( "Save Project As" ),
6774-
defaultPath,
6775-
exts, &filter );
6760+
QString path = QFileDialog::getSaveFileName(
6761+
this,
6762+
tr( "Save Project As" ),
6763+
defaultPath,
6764+
qgisProjectExt + QStringLiteral( ";;" ) + qgzProjectExt + QStringLiteral( ";;" ) + qgsProjectExt, &filter );
67766765
if ( path.isEmpty() )
67776766
return;
67786767

67796768
QFileInfo fullPath( path );
6780-
67816769
QgsSettings().setValue( QStringLiteral( "UI/lastProjectDir" ), fullPath.path() );
67826770

6783-
if ( filter == zipExt )
6771+
const QString ext = fullPath.suffix().toLower();
6772+
if ( filter == qgisProjectExt && ext != QLatin1String( "qgz" ) && ext != QLatin1String( "qgs" ) )
67846773
{
6785-
if ( fullPath.suffix().compare( QLatin1String( "qgz" ), Qt::CaseInsensitive ) != 0 )
6786-
fullPath.setFile( fullPath.filePath() + ".qgz" );
6774+
switch ( defaultProjectFileFormat )
6775+
{
6776+
case Qgis::ProjectFileFormat::Qgs:
6777+
{
6778+
fullPath.setFile( fullPath.filePath() + ".qgs" );
6779+
break;
6780+
}
6781+
case Qgis::ProjectFileFormat::Qgz:
6782+
{
6783+
fullPath.setFile( fullPath.filePath() + ".qgz" );
6784+
break;
6785+
}
6786+
}
67876787
}
6788-
else // .qgs
6788+
else if ( filter == qgzProjectExt && ext != QLatin1String( "qgz" ) )
67896789
{
6790-
if ( fullPath.suffix().compare( QLatin1String( "qgs" ), Qt::CaseInsensitive ) != 0 )
6791-
fullPath.setFile( fullPath.filePath() + ".qgs" );
6790+
fullPath.setFile( fullPath.filePath() + ".qgz" );
6791+
}
6792+
else if ( filter == qgsProjectExt && ext != QLatin1String( "qgs" ) )
6793+
{
6794+
fullPath.setFile( fullPath.filePath() + ".qgs" );
67926795
}
67936796

67946797
QgsProject::instance()->setFileName( fullPath.filePath() );

src/ui/qgsoptionsbase.ui

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -866,7 +866,7 @@
866866
<item row="0" column="1">
867867
<widget class="QRadioButton" name="mFileFormatQgzButton">
868868
<property name="text">
869-
<string>QGZ Archive file format, embeds auxiliary data</string>
869+
<string>QGZ Bundled project format, compressed into a single zip file, embeds auxiliary data</string>
870870
</property>
871871
<attribute name="buttonGroup">
872872
<string notr="true">mDefaultProjectFileFormatButtonGroup</string>
@@ -879,7 +879,7 @@
879879
<string>The auxiliary data will be kept in a separate .qgd data file which must be distributed along with the .qgs project file.</string>
880880
</property>
881881
<property name="text">
882-
<string>QGS Project saved in a clear text, does not embed auxiliary data</string>
882+
<string>QGS XML project format, saved in a clear text, does not embed auxiliary data</string>
883883
</property>
884884
<attribute name="buttonGroup">
885885
<string notr="true">mDefaultProjectFileFormatButtonGroup</string>

0 commit comments

Comments
 (0)