diff --git a/src/app/qgisapp.cpp b/src/app/qgisapp.cpp index 47891bbe770..e4e1f5e6ccc 100644 --- a/src/app/qgisapp.cpp +++ b/src/app/qgisapp.cpp @@ -1740,27 +1740,6 @@ void QgisApp::applyDefaultSettingsToCanvas( QgsMapCanvas *canvas ) canvas->setSegmentationToleranceType( QgsAbstractGeometry::SegmentationToleranceType( settings.value( QStringLiteral( "qgis/segmentationToleranceType" ), "0" ).toInt() ) ); } -QgsCoordinateReferenceSystem QgisApp::defaultCrsForNewLayers() const -{ - QgsSettings settings; - QgsCoordinateReferenceSystem defaultCrs; - if ( settings.value( QStringLiteral( "/Projections/defaultBehavior" ), QStringLiteral( "prompt" ) ).toString() == QStringLiteral( "useProject" ) - || settings.value( QStringLiteral( "/Projections/defaultBehavior" ), QStringLiteral( "prompt" ) ).toString() == QStringLiteral( "prompt" ) ) - { - // for new layers if the new layer crs method is set to either prompt or use project, then we use the project crs - // (since "prompt" has no meaning here - the prompt will always be shown, it's just deciding on the default choice in the prompt!) - defaultCrs = QgsProject::instance()->crs(); - } - else - { - // global crs - QString layerDefaultCrs = settings.value( QStringLiteral( "/Projections/layerDefaultCrs" ), GEO_EPSG_CRS_AUTHID ).toString(); - defaultCrs = QgsCoordinateReferenceSystem::fromOgcWmsCrs( layerDefaultCrs ); - } - - return defaultCrs; -} - int QgisApp::chooseReasonableDefaultIconSize() const { QScreen *screen = QApplication::screens().at( 0 ); @@ -5099,7 +5078,7 @@ void QgisApp::fileNewFromTemplateAction( QAction *qAction ) void QgisApp::newVectorLayer() { QString enc; - QString fileName = QgsNewVectorLayerDialog::runAndCreateLayer( this, &enc, defaultCrsForNewLayers() ); + QString fileName = QgsNewVectorLayerDialog::runAndCreateLayer( this, &enc, QgsProject::instance()->defaultCrsForNewLayers() ); if ( !fileName.isEmpty() ) { @@ -5121,7 +5100,7 @@ void QgisApp::newVectorLayer() void QgisApp::newMemoryLayer() { - QgsVectorLayer *newLayer = QgsNewMemoryLayerDialog::runAndCreateLayer( this, defaultCrsForNewLayers() ); + QgsVectorLayer *newLayer = QgsNewMemoryLayerDialog::runAndCreateLayer( this, QgsProject::instance()->defaultCrsForNewLayers() ); if ( newLayer ) { @@ -5136,14 +5115,14 @@ void QgisApp::newMemoryLayer() void QgisApp::newSpatialiteLayer() { - QgsNewSpatialiteLayerDialog spatialiteDialog( this, QgsGuiUtils::ModalDialogFlags, defaultCrsForNewLayers() ); + QgsNewSpatialiteLayerDialog spatialiteDialog( this, QgsGuiUtils::ModalDialogFlags, QgsProject::instance()->defaultCrsForNewLayers() ); spatialiteDialog.exec(); } void QgisApp::newGeoPackageLayer() { QgsNewGeoPackageLayerDialog dialog( this ); - dialog.setCrs( defaultCrsForNewLayers() ); + dialog.setCrs( QgsProject::instance()->defaultCrsForNewLayers() ); dialog.exec(); } diff --git a/src/core/qgsproject.cpp b/src/core/qgsproject.cpp index 0354057dc25..0e69b4ac3ec 100644 --- a/src/core/qgsproject.cpp +++ b/src/core/qgsproject.cpp @@ -2241,3 +2241,23 @@ QMap QgsProject::mapLayers() const } +QgsCoordinateReferenceSystem QgsProject::defaultCrsForNewLayers() const +{ + QgsSettings settings; + QgsCoordinateReferenceSystem defaultCrs; + if ( settings.value( QStringLiteral( "/Projections/defaultBehavior" ), QStringLiteral( "prompt" ) ).toString() == QStringLiteral( "useProject" ) + || settings.value( QStringLiteral( "/Projections/defaultBehavior" ), QStringLiteral( "prompt" ) ).toString() == QStringLiteral( "prompt" ) ) + { + // for new layers if the new layer crs method is set to either prompt or use project, then we use the project crs + // (since "prompt" has no meaning here - the prompt will always be shown, it's just deciding on the default choice in the prompt!) + defaultCrs = crs(); + } + else + { + // global crs + QString layerDefaultCrs = settings.value( QStringLiteral( "/Projections/layerDefaultCrs" ), GEO_EPSG_CRS_AUTHID ).toString(); + defaultCrs = QgsCoordinateReferenceSystem::fromOgcWmsCrs( layerDefaultCrs ); + } + + return defaultCrs; +} diff --git a/src/core/qgsproject.h b/src/core/qgsproject.h index 0a70c88af7b..4cee7a691a1 100644 --- a/src/core/qgsproject.h +++ b/src/core/qgsproject.h @@ -750,6 +750,12 @@ class CORE_EXPORT QgsProject : public QObject, public QgsExpressionContextGenera */ void reloadAllLayers(); + /** Returns the default CRS for new layers based on the settings and + * the current project CRS + */ + QgsCoordinateReferenceSystem defaultCrsForNewLayers() const; + + signals: //! emitted when project is being read void readProject( const QDomDocument & ); @@ -967,6 +973,8 @@ class CORE_EXPORT QgsProject : public QObject, public QgsExpressionContextGenera */ void legendLayersAdded( const QList &layers ); + + public slots: /**