diff --git a/src/app/qgisapp.cpp b/src/app/qgisapp.cpp index cd3ecf559ff..b4120866e9e 100644 --- a/src/app/qgisapp.cpp +++ b/src/app/qgisapp.cpp @@ -14513,55 +14513,60 @@ QgsFeature QgisApp::duplicateFeatureDigitized( QgsMapLayer *mlayer, const QgsFea } -void QgisApp::populateProjectStorageMenu( QMenu *menu, bool saving ) +void QgisApp::populateProjectStorageMenu( QMenu *menu, const bool saving ) { menu->clear(); const QList storages = QgsApplication::projectStorageRegistry()->projectStorages(); - QAction *action = menu->addAction( tr( "Templates" ) + QChar( 0x2026 ) ); // 0x2026 = ellipsis character - connect( action, &QAction::triggered, this, [ this ] + + if ( saving ) { - QgsSettings settings; - QString templateDirName = settings.value( QStringLiteral( "qgis/projectTemplateDir" ), - QgsApplication::qgisSettingsDirPath() + "project_templates" ).toString(); - - const QString originalFilename = QgsProject::instance()->fileName(); - QString templateName = QFileInfo( originalFilename ).baseName(); - - if ( templateName.isEmpty() ) + QAction *action = menu->addAction( tr( "Templates" ) + QChar( 0x2026 ) ); // 0x2026 = ellipsis character + connect( action, &QAction::triggered, this, [ this ] { - bool ok; - templateName = QInputDialog::getText( this, tr( "Template Name" ), - tr( "Name for the template" ), QLineEdit::Normal, - QString(), &ok ); + QgsSettings settings; + QString templateDirName = settings.value( QStringLiteral( "qgis/projectTemplateDir" ), + QgsApplication::qgisSettingsDirPath() + "project_templates" ).toString(); + + const QString originalFilename = QgsProject::instance()->fileName(); + QString templateName = QFileInfo( originalFilename ).baseName(); - if ( !ok ) - return; if ( templateName.isEmpty() ) { - messageBar()->pushInfo( tr( "Template not saved" ), tr( "The template can not have an empty name." ) ); + bool ok; + templateName = QInputDialog::getText( this, tr( "Template Name" ), + tr( "Name for the template" ), QLineEdit::Normal, + QString(), &ok ); + + if ( !ok ) + return; + if ( templateName.isEmpty() ) + { + messageBar()->pushInfo( tr( "Template not saved" ), tr( "The template can not have an empty name." ) ); + } } - } - const QString filePath = templateDirName + QDir::separator() + templateName + QStringLiteral( ".qgz" ); - if ( QFileInfo::exists( filePath ) ) - { - QMessageBox msgBox( this ); - msgBox.setWindowTitle( tr( "Overwrite template" ) ); - msgBox.setText( tr( "The template %1 already exists, do you want to replace it?" ).arg( templateName ) ); - msgBox.addButton( tr( "Overwrite" ), QMessageBox::YesRole ); - auto cancelButton = msgBox.addButton( QMessageBox::Cancel ); - msgBox.setIcon( QMessageBox::Question ); - msgBox.exec(); - if ( msgBox.clickedButton() == cancelButton ) + const QString filePath = templateDirName + QDir::separator() + templateName + QStringLiteral( ".qgz" ); + if ( QFileInfo::exists( filePath ) ) { - return; + QMessageBox msgBox( this ); + msgBox.setWindowTitle( tr( "Overwrite Template" ) ); + msgBox.setText( tr( "The template %1 already exists, do you want to replace it?" ).arg( templateName ) ); + msgBox.addButton( tr( "Overwrite" ), QMessageBox::YesRole ); + auto cancelButton = msgBox.addButton( QMessageBox::Cancel ); + msgBox.setIcon( QMessageBox::Question ); + msgBox.exec(); + if ( msgBox.clickedButton() == cancelButton ) + { + return; + } } - } - QgsProject::instance()->write( filePath ); - QgsProject::instance()->setFileName( originalFilename ); - messageBar()->pushInfo( tr( "Template saved" ), tr( "Template %1 was saved" ).arg( templateName ) ); + QgsProject::instance()->write( filePath ); + QgsProject::instance()->setFileName( originalFilename ); + messageBar()->pushInfo( tr( "Template saved" ), tr( "Template %1 was saved" ).arg( templateName ) ); + + } ); + } - } ); for ( QgsProjectStorage *storage : storages ) { QString name = storage->visibleName();