mirror of
https://github.com/qgis/QGIS.git
synced 2025-02-28 00:17:30 -05:00
Move the default CRS for new layers function to QgsProject
The reason is that it needs to access to project's crs and it's not only needed by app but also by the providers (will be)
This commit is contained in:
parent
61504e7073
commit
64201f1b9b
@ -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();
|
||||
}
|
||||
|
||||
|
@ -2241,3 +2241,23 @@ QMap<QString, QgsMapLayer *> 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;
|
||||
}
|
||||
|
@ -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<QgsMapLayer *> &layers );
|
||||
|
||||
|
||||
|
||||
public slots:
|
||||
|
||||
/**
|
||||
|
Loading…
x
Reference in New Issue
Block a user