Skip to content
Permalink
Browse files

FEATURE: Select default CRS for new projects. Fixes #363

git-svn-id: http://svn.osgeo.org/qgis/trunk@15374 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
borysiasty
borysiasty committed Mar 6, 2011
1 parent 54e4a9f commit 7de1303cb59f6b852e53e05b49e1dfd0d408e208
Showing with 218 additions and 131 deletions.
  1. +28 −25 src/app/qgisapp.cpp
  2. +23 −18 src/app/qgsoptions.cpp
  3. +1 −1 src/app/qgsoptions.h
  4. +166 −87 src/ui/qgsoptionsbase.ui
@@ -3282,27 +3282,29 @@ void QgisApp::fileNew( bool thePromptToSaveFlag )
mMapCanvas->refresh();
mMapCanvas->clearExtentHistory();

// set project CRS
QgsMapRenderer* myRenderer = mMapCanvas->mapRenderer();
QString projString = settings.value( "/Projections/projectDefaultProjectionString", GEOPROJ4 ).toString();
QgsCoordinateReferenceSystem srs;
srs.createFromProj4( projString );
myRenderer->setDestinationSrs( srs );
// write the projections _proj string_ to project settings
prj->writeEntry( "SpatialRefSys", "/ProjectCRSProj4String", projString );
prj->dirty( false );
if ( srs.mapUnits() != QGis::UnknownUnit )
{
myRenderer->setMapUnits( srs.mapUnits() );
}

// enable OTF CRS transformation if necessary
if ( settings.value( "/Projections/otfTransformEnabled", 0 ).toBool() )
{
QgsMapRenderer* myRenderer = mMapCanvas->mapRenderer();
QString projString = settings.value( "/Projections/defaultOTFProjectionString", GEOPROJ4 ).toString();
QgsCoordinateReferenceSystem srs;
srs.createFromProj4( projString );
myRenderer->setProjectionsEnabled( true );
myRenderer->setDestinationSrs( srs );
// write the projections _proj string_ to project settings
prj->writeEntry( "SpatialRefSys", "/ProjectCRSProj4String", projString );
prj->dirty( false );
if ( srs.mapUnits() != QGis::UnknownUnit )
{
myRenderer->setMapUnits( srs.mapUnits() );
}
mOnTheFlyProjectionStatusButton->setIcon( getThemeIcon( "mIconProjectionEnabled.png" ) );
}
else
{
mMapCanvas->mapRenderer()->setProjectionsEnabled( false );
myRenderer->setProjectionsEnabled( false );
}

// set the initial map tool
@@ -5582,25 +5584,26 @@ void QgisApp::options()
double zoomFactor = mySettings.value( "/qgis/zoom_factor", 2 ).toDouble();
mMapCanvas->setWheelAction(( QgsMapCanvas::WheelAction ) action, zoomFactor );

// set project CRS
QgsMapRenderer* myRenderer = mMapCanvas->mapRenderer();
QString projString = mySettings.value( "/Projections/projectDefaultProjectionString", GEOPROJ4 ).toString();
QgsCoordinateReferenceSystem srs;
srs.createFromProj4( projString );
myRenderer->setDestinationSrs( srs );
// write the projections _proj string_ to project settings
QgsProject::instance()->writeEntry( "SpatialRefSys", "/ProjectCRSProj4String", projString );
if ( srs.mapUnits() != QGis::UnknownUnit )
{
myRenderer->setMapUnits( srs.mapUnits() );
}

//apply OTF CRS transformation if necessary
if ( mySettings.value( "/Projections/otfTransformEnabled", 0 ).toBool() )
{
QgsMapRenderer* myRenderer = mMapCanvas->mapRenderer();
QString projString = mySettings.value( "/Projections/defaultOTFProjectionString", GEOPROJ4 ).toString();
QgsCoordinateReferenceSystem srs;
srs.createFromProj4( projString );
myRenderer->setProjectionsEnabled( true );
myRenderer->setDestinationSrs( srs );
// write the projections _proj string_ to project settings
QgsProject::instance()->writeEntry( "SpatialRefSys", "/ProjectCRSProj4String", projString );
if ( srs.mapUnits() != QGis::UnknownUnit )
{
myRenderer->setMapUnits( srs.mapUnits() );
}
}
else
{
QgsMapRenderer* myRenderer = mMapCanvas->mapRenderer();
myRenderer->setProjectionsEnabled( false );
}
mMapCanvas->refresh();
@@ -188,17 +188,18 @@ QgsOptions::QgsOptions( QWidget *parent, Qt::WFlags fl ) :
{
radUseGlobalProjection->setChecked( true );
}
QString myGlobalCrsString = settings.value( "/Projections/defaultProjectionString", GEOPROJ4 ).toString();
mGlobalCrs.createFromProj4( myGlobalCrsString );
QString myLayerDefaultCrsString = settings.value( "/Projections/defaultProjectionString", GEOPROJ4 ).toString();
mLayerDefaultCrs.createFromProj4( myLayerDefaultCrsString );
//display the crs as friendly text rather than in wkt
leGlobalCRS->setText( mGlobalCrs.authid() + " - " + mGlobalCrs.description() );
leLayerGlobalCrs->setText( mLayerDefaultCrs.authid() + " - " + mLayerDefaultCrs.description() );

//on the fly CRS transformation settings
grpOtfTransform->setChecked( settings.value( "/Projections/otfTransformEnabled", 0 ).toBool() );
QString myDefaultCrsString = settings.value( "/Projections/defaultOTFProjectionString", GEOPROJ4 ).toString();
chkOtfTransform->setChecked( settings.value( "/Projections/otfTransformEnabled", 0 ).toBool() );

QString myDefaultCrsString = settings.value( "/Projections/projectDefaultProjectionString", GEOPROJ4 ).toString();
mDefaultCrs.createFromProj4( myDefaultCrsString );
//display the crs as friendly text rather than in wkt
leGlobalOtfProjString->setText( mDefaultCrs.authid() + " - " + mDefaultCrs.description() );
leProjectGlobalCrs->setText( mDefaultCrs.authid() + " - " + mDefaultCrs.description() );

// populate combo box with ellipsoids
getEllipsoidList();
@@ -638,11 +639,11 @@ void QgsOptions::saveOptions()
settings.setValue( "/Projections/defaultBehaviour", "useGlobal" );
}

settings.setValue( "/Projections/defaultProjectionString", mGlobalCrs.toProj4() );
settings.setValue( "/Projections/defaultProjectionString", mLayerDefaultCrs.toProj4() );

// save 'on the fly' CRS transformation settings
settings.setValue( "/Projections/otfTransformEnabled", grpOtfTransform->isChecked() );
settings.setValue( "/Projections/defaultOTFProjectionString", mDefaultCrs.toProj4() );
settings.setValue( "/Projections/otfTransformEnabled", chkOtfTransform->isChecked() );
settings.setValue( "/Projections/projectDefaultProjectionString", mDefaultCrs.toProj4() );

settings.setValue( "/qgis/measure/ellipsoid", getEllipsoidAcronym( cmbEllipsoid->currentText() ) );

@@ -751,19 +752,21 @@ void QgsOptions::on_pbnSelectProjection_clicked()
{
QSettings settings;
QgsGenericProjectionSelector * mySelector = new QgsGenericProjectionSelector( this );
mySelector->setSelectedCrsId( mGlobalCrs.srsid() );

//find out crs id of current proj4 string
mySelector->setSelectedCrsId( mLayerDefaultCrs.srsid() );

if ( mySelector->exec() )
{
mGlobalCrs.createFromProj4( mySelector->selectedProj4String() );
leGlobalCRS->setText( mySelector->selectedProj4String() );
leGlobalCRS->setText( mGlobalCrs.authid() + " - " +
mGlobalCrs.description() );
QgsDebugMsg( QString( "------ Global Default Projection Selection set to ----------\n%1" ).arg( leGlobalCRS->text() ) );
mLayerDefaultCrs.createFromProj4( mySelector->selectedProj4String() );
QgsDebugMsg( QString( "Setting default project CRS to : %1").arg( mySelector->selectedProj4String() ) );
leLayerGlobalCrs->setText( mLayerDefaultCrs.authid() + " - " +
mLayerDefaultCrs.description() );
QgsDebugMsg( QString( "------ Global Layer Default Projection Selection set to ----------\n%1" ).arg( leLayerGlobalCrs->text() ) );
}
else
{
QgsDebugMsg( "------ Global Default Projection Selection change cancelled ----------" );
QgsDebugMsg( "------ Global Layer Default Projection Selection change cancelled ----------" );
QApplication::restoreOverrideCursor();
}

@@ -773,15 +776,17 @@ void QgsOptions::on_pbnSelectOtfProjection_clicked()
{
QSettings settings;
QgsGenericProjectionSelector * mySelector = new QgsGenericProjectionSelector( this );

//find out crs id of current proj4 string
mySelector->setSelectedCrsId( mDefaultCrs.srsid() );

if ( mySelector->exec() )
{
mDefaultCrs.createFromProj4( mySelector->selectedProj4String() );
QgsDebugMsg( QString( "Setting default project CRS to : %1").arg( mySelector->selectedProj4String() ) );
leGlobalOtfProjString->setText( mDefaultCrs.authid() + " - " +
leProjectGlobalCrs->setText( mDefaultCrs.authid() + " - " +
mDefaultCrs.description() );
QgsDebugMsg( QString( "------ Global OTF Projection Selection set to ----------\n%1" ).arg( leGlobalOtfProjString->text() ) );
QgsDebugMsg( QString( "------ Global OTF Projection Selection set to ----------\n%1" ).arg( leProjectGlobalCrs->text() ) );
}
else
{
@@ -131,7 +131,7 @@ class QgsOptions : public QDialog, private Ui::QgsOptionsBase
private:
QStringList i18nList();
QgsCoordinateReferenceSystem mDefaultCrs;
QgsCoordinateReferenceSystem mGlobalCrs;
QgsCoordinateReferenceSystem mLayerDefaultCrs;
};

#endif // #ifndef QGSOPTIONS_H

0 comments on commit 7de1303

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