Skip to content
Permalink
Browse files

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)
  • Loading branch information
elpaso committed Aug 6, 2017
1 parent 61504e7 commit 64201f1b9bab981f4f017962e799b092c3f7141a
Showing with 32 additions and 25 deletions.
  1. +4 −25 src/app/qgisapp.cpp
  2. +20 −0 src/core/qgsproject.cpp
  3. +8 −0 src/core/qgsproject.h
@@ -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:

/**

0 comments on commit 64201f1

Please sign in to comment.
You can’t perform that action at this time.