From 918c49d9ddb8025270057d851c4ff0537e972246 Mon Sep 17 00:00:00 2001 From: Mathieu Pellerin Date: Tue, 28 Nov 2023 10:09:08 +0700 Subject: [PATCH 1/3] [ui] Let typed QGIS project file extension dictate the type when saving projects --- src/app/qgisapp.cpp | 115 +++++++++++++++++++++++--------------------- 1 file changed, 59 insertions(+), 56 deletions(-) diff --git a/src/app/qgisapp.cpp b/src/app/qgisapp.cpp index 25a6422cb441..195f8a285bd0 100644 --- a/src/app/qgisapp.cpp +++ b/src/app/qgisapp.cpp @@ -6386,10 +6386,9 @@ void QgisApp::fileOpen() QgsSettings settings; QString lastUsedDir = settings.value( QStringLiteral( "UI/lastProjectDir" ), QDir::homePath() ).toString(); - QStringList fileFilters; QStringList extensions; - fileFilters << tr( "QGIS files" ) + QStringLiteral( " (*.qgs *.qgz *.QGS *.QGZ)" ); + fileFilters << tr( "QGIS Project Formats" ) + QStringLiteral( " (*.qgz *.QGZ *.qgs *.QGS)" ); extensions << QStringLiteral( "qgs" ) << QStringLiteral( "qgz" ); for ( QgsCustomProjectOpenHandler *handler : std::as_const( mCustomProjectOpenHandlers ) ) { @@ -6636,45 +6635,47 @@ bool QgisApp::fileSave() QgsSettings settings; QString lastUsedDir = settings.value( QStringLiteral( "UI/lastProjectDir" ), QDir::homePath() ).toString(); - const QString qgsExt = tr( "QGIS files" ) + " (*.qgs)"; - const QString zipExt = tr( "QGZ files" ) + " (*.qgz)"; - - QString exts; Qgis::ProjectFileFormat defaultProjectFileFormat = settings.enumValue( QStringLiteral( "/qgis/defaultProjectFileFormat" ), Qgis::ProjectFileFormat::Qgz ); - switch ( defaultProjectFileFormat ) - { - case Qgis::ProjectFileFormat::Qgs: - { - exts = qgsExt + QStringLiteral( ";;" ) + zipExt; - break; - } - case Qgis::ProjectFileFormat::Qgz: - { - exts = zipExt + QStringLiteral( ";;" ) + qgsExt; - } - } + const QString qgisProjectExt = tr( "QGIS Project Formats" ) + ( defaultProjectFileFormat == Qgis::ProjectFileFormat::Qgz ? " (*.qgz *.QGZ *.qgs *.QGS)" : " (*.qgs *.QGS *.qgz *.QGZ)" ); + const QString qgzProjectExt = tr( "QGIS Standard Project Format" ) + " (*.qgz *.QGZ)"; + const QString qgsProjectExt = tr( "QGIS Text Project Format" ) + " (*.qgs *.QGS)"; + QString filter; QString path = QFileDialog::getSaveFileName( this, tr( "Choose a QGIS project file" ), lastUsedDir + '/' + QgsProject::instance()->title(), - exts, &filter ); + qgisProjectExt + QStringLiteral( ";;" ) + qgzProjectExt + QStringLiteral( ";;" ) + qgsProjectExt, &filter ); if ( path.isEmpty() ) return false; - QFileInfo fullPath; - fullPath.setFile( path ); + QFileInfo fullPath( path ); + QgsSettings().setValue( QStringLiteral( "UI/lastProjectDir" ), fullPath.path() ); - // make sure we have the .qgs extension in the file name - if ( filter == zipExt ) + const QString ext = fullPath.suffix().toLower(); + if ( filter == qgisProjectExt && ext != QLatin1String( "qgz" ) && ext != QLatin1String( "qgs" ) ) { - if ( fullPath.suffix().compare( QLatin1String( "qgz" ), Qt::CaseInsensitive ) != 0 ) - fullPath.setFile( fullPath.filePath() + ".qgz" ); + switch ( defaultProjectFileFormat ) + { + case Qgis::ProjectFileFormat::Qgs: + { + fullPath.setFile( fullPath.filePath() + ".qgs" ); + break; + } + case Qgis::ProjectFileFormat::Qgz: + { + fullPath.setFile( fullPath.filePath() + ".qgz" ); + break; + } + } } - else + else if ( filter == qgzProjectExt && ext != QLatin1String( "qgz" ) ) { - if ( fullPath.suffix().compare( QLatin1String( "qgs" ), Qt::CaseInsensitive ) != 0 ) - fullPath.setFile( fullPath.filePath() + ".qgs" ); + fullPath.setFile( fullPath.filePath() + ".qgz" ); + } + else if ( filter == qgsProjectExt && ext != QLatin1String( "qgs" ) ) + { + fullPath.setFile( fullPath.filePath() + ".qgs" ); } QgsProject::instance()->setFileName( fullPath.filePath() ); @@ -6750,45 +6751,47 @@ void QgisApp::fileSaveAs() defaultPath += QString( '/' + QgsProject::instance()->title() ); } - const QString qgsExt = tr( "QGIS files" ) + " (*.qgs *.QGS)"; - const QString zipExt = tr( "QGZ files" ) + " (*.qgz)"; - - QString exts; Qgis::ProjectFileFormat defaultProjectFileFormat = settings.enumValue( QStringLiteral( "/qgis/defaultProjectFileFormat" ), Qgis::ProjectFileFormat::Qgz ); - switch ( defaultProjectFileFormat ) - { - case Qgis::ProjectFileFormat::Qgs: - { - exts = qgsExt + QStringLiteral( ";;" ) + zipExt; - break; - } - case Qgis::ProjectFileFormat::Qgz: - { - exts = zipExt + QStringLiteral( ";;" ) + qgsExt; - break; - } - } + const QString qgisProjectExt = tr( "QGIS Project Formats" ) + ( defaultProjectFileFormat == Qgis::ProjectFileFormat::Qgz ? " (*.qgz *.QGZ *.qgs *.QGS)" : " (*.qgs *.QGS *.qgz *.QGZ)" ); + const QString qgzProjectExt = tr( "QGIS Standard Project Format" ) + " (*.qgz *.QGZ)"; + const QString qgsProjectExt = tr( "QGIS Text Project Format" ) + " (*.qgs *.QGS)"; + QString filter; - QString path = QFileDialog::getSaveFileName( this, - tr( "Save Project As" ), - defaultPath, - exts, &filter ); + QString path = QFileDialog::getSaveFileName( + this, + tr( "Save Project As" ), + defaultPath, + qgisProjectExt + QStringLiteral( ";;" ) + qgzProjectExt + QStringLiteral( ";;" ) + qgsProjectExt, &filter ); if ( path.isEmpty() ) return; QFileInfo fullPath( path ); - QgsSettings().setValue( QStringLiteral( "UI/lastProjectDir" ), fullPath.path() ); - if ( filter == zipExt ) + const QString ext = fullPath.suffix().toLower(); + if ( filter == qgisProjectExt && ext != QLatin1String( "qgz" ) && ext != QLatin1String( "qgs" ) ) { - if ( fullPath.suffix().compare( QLatin1String( "qgz" ), Qt::CaseInsensitive ) != 0 ) - fullPath.setFile( fullPath.filePath() + ".qgz" ); + switch ( defaultProjectFileFormat ) + { + case Qgis::ProjectFileFormat::Qgs: + { + fullPath.setFile( fullPath.filePath() + ".qgs" ); + break; + } + case Qgis::ProjectFileFormat::Qgz: + { + fullPath.setFile( fullPath.filePath() + ".qgz" ); + break; + } + } } - else // .qgs + else if ( filter == qgzProjectExt && ext != QLatin1String( "qgz" ) ) { - if ( fullPath.suffix().compare( QLatin1String( "qgs" ), Qt::CaseInsensitive ) != 0 ) - fullPath.setFile( fullPath.filePath() + ".qgs" ); + fullPath.setFile( fullPath.filePath() + ".qgz" ); + } + else if ( filter == qgsProjectExt && ext != QLatin1String( "qgs" ) ) + { + fullPath.setFile( fullPath.filePath() + ".qgs" ); } QgsProject::instance()->setFileName( fullPath.filePath() ); From 43aea69ae2bdc76a25adb74747da444a0e1e8ed7 Mon Sep 17 00:00:00 2001 From: Mathieu Pellerin Date: Thu, 14 Dec 2023 21:00:56 +0700 Subject: [PATCH 2/3] Settle on bundled project format (QGZ) and XML project format (QGS) --- src/app/qgisapp.cpp | 8 ++++---- src/ui/qgsoptionsbase.ui | 4 ++-- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/app/qgisapp.cpp b/src/app/qgisapp.cpp index 195f8a285bd0..4fad248bbcb0 100644 --- a/src/app/qgisapp.cpp +++ b/src/app/qgisapp.cpp @@ -6637,8 +6637,8 @@ bool QgisApp::fileSave() Qgis::ProjectFileFormat defaultProjectFileFormat = settings.enumValue( QStringLiteral( "/qgis/defaultProjectFileFormat" ), Qgis::ProjectFileFormat::Qgz ); const QString qgisProjectExt = tr( "QGIS Project Formats" ) + ( defaultProjectFileFormat == Qgis::ProjectFileFormat::Qgz ? " (*.qgz *.QGZ *.qgs *.QGS)" : " (*.qgs *.QGS *.qgz *.QGZ)" ); - const QString qgzProjectExt = tr( "QGIS Standard Project Format" ) + " (*.qgz *.QGZ)"; - const QString qgsProjectExt = tr( "QGIS Text Project Format" ) + " (*.qgs *.QGS)"; + const QString qgzProjectExt = tr( "QGIS Bundled Project Format" ) + " (*.qgz *.QGZ)"; + const QString qgsProjectExt = tr( "QGIS XML Project Format" ) + " (*.qgs *.QGS)"; QString filter; QString path = QFileDialog::getSaveFileName( @@ -6753,8 +6753,8 @@ void QgisApp::fileSaveAs() Qgis::ProjectFileFormat defaultProjectFileFormat = settings.enumValue( QStringLiteral( "/qgis/defaultProjectFileFormat" ), Qgis::ProjectFileFormat::Qgz ); const QString qgisProjectExt = tr( "QGIS Project Formats" ) + ( defaultProjectFileFormat == Qgis::ProjectFileFormat::Qgz ? " (*.qgz *.QGZ *.qgs *.QGS)" : " (*.qgs *.QGS *.qgz *.QGZ)" ); - const QString qgzProjectExt = tr( "QGIS Standard Project Format" ) + " (*.qgz *.QGZ)"; - const QString qgsProjectExt = tr( "QGIS Text Project Format" ) + " (*.qgs *.QGS)"; + const QString qgzProjectExt = tr( "QGIS Bundled Project Format" ) + " (*.qgz *.QGZ)"; + const QString qgsProjectExt = tr( "QGIS XML Project Format" ) + " (*.qgs *.QGS)"; QString filter; QString path = QFileDialog::getSaveFileName( diff --git a/src/ui/qgsoptionsbase.ui b/src/ui/qgsoptionsbase.ui index 74b2bb1aa72e..92cd31c82663 100644 --- a/src/ui/qgsoptionsbase.ui +++ b/src/ui/qgsoptionsbase.ui @@ -866,7 +866,7 @@ - QGZ Archive file format, embeds auxiliary data + QGZ Bundled project format, compressed into a single file, embeds auxiliary data mDefaultProjectFileFormatButtonGroup @@ -879,7 +879,7 @@ The auxiliary data will be kept in a separate .qgd data file which must be distributed along with the .qgs project file. - QGS Project saved in a clear text, does not embed auxiliary data + QGS XML project format, saved in a clear text, does not embed auxiliary data mDefaultProjectFileFormatButtonGroup From 3a0f6d80c67a93245f6da70e44d7d72c8d1f4895 Mon Sep 17 00:00:00 2001 From: Mathieu Pellerin Date: Thu, 14 Dec 2023 22:33:58 +0700 Subject: [PATCH 3/3] Update src/ui/qgsoptionsbase.ui MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Loïc Bartoletti --- src/ui/qgsoptionsbase.ui | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ui/qgsoptionsbase.ui b/src/ui/qgsoptionsbase.ui index 92cd31c82663..68167d99e805 100644 --- a/src/ui/qgsoptionsbase.ui +++ b/src/ui/qgsoptionsbase.ui @@ -866,7 +866,7 @@ - QGZ Bundled project format, compressed into a single file, embeds auxiliary data + QGZ Bundled project format, compressed into a single zip file, embeds auxiliary data mDefaultProjectFileFormatButtonGroup