Skip to content

Commit

Permalink
Applied patch for #363 from Alex Bruy to enable on the fly projection…
Browse files Browse the repository at this point in the history
… by default.

git-svn-id: http://svn.osgeo.org/qgis/trunk@15344 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
timlinux committed Mar 5, 2011
1 parent 0bb234d commit 79eb19e
Show file tree
Hide file tree
Showing 4 changed files with 119 additions and 33 deletions.
48 changes: 46 additions & 2 deletions src/app/qgisapp.cpp
Expand Up @@ -3256,7 +3256,28 @@ void QgisApp::fileNew( bool thePromptToSaveFlag )
mMapCanvas->refresh();
mMapCanvas->clearExtentHistory();

mMapCanvas->mapRenderer()->setProjectionsEnabled( false );
// 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 );
}

// set the initial map tool
mMapCanvas->setMapTool( mMapTools.mPan );
Expand Down Expand Up @@ -5506,7 +5527,30 @@ void QgisApp::options()
int action = mySettings.value( "/qgis/wheel_action", 0 ).toInt();
double zoomFactor = mySettings.value( "/qgis/zoom_factor", 2 ).toDouble();
mMapCanvas->setWheelAction(( QgsMapCanvas::WheelAction ) action, zoomFactor );
}

//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();
}

delete optionsDialog;
}
Expand Down
32 changes: 32 additions & 0 deletions src/app/qgsoptions.cpp
Expand Up @@ -191,6 +191,10 @@ QgsOptions::QgsOptions( QWidget *parent, Qt::WFlags fl ) :

txtGlobalWkt->setText( settings.value( "/Projections/defaultProjectionString", GEOPROJ4 ).toString() );

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

// populate combo box with ellipsoids
getEllipsoidList();
QString myEllipsoidId = settings.value( "/qgis/measure/ellipsoid", "WGS84" ).toString();
Expand Down Expand Up @@ -631,6 +635,10 @@ void QgsOptions::saveOptions()

settings.setValue( "/Projections/defaultProjectionString", txtGlobalWkt->toPlainText() );

// save 'on the fly' CRS transformation settings
settings.setValue( "/Projections/otfTransformEnabled", grpOtfTransform->isChecked() );
settings.setValue( "/Projections/defaultOTFProjectionString", leGlobalOtfProjString->text() );

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

if ( radFeet->isChecked() )
Expand Down Expand Up @@ -760,6 +768,30 @@ void QgsOptions::on_pbnSelectProjection_clicked()

}

void QgsOptions::on_pbnSelectOtfProjection_clicked()
{
QSettings settings;
QgsGenericProjectionSelector * mySelector = new QgsGenericProjectionSelector( this );

//find out srs id of current proj4 string
QgsCoordinateReferenceSystem refSys;
if ( refSys.createFromProj4( leGlobalOtfProjString->text() ) )
{
mySelector->setSelectedCrsId( refSys.srsid() );
}

if ( mySelector->exec() )
{
leGlobalOtfProjString->setText( mySelector->selectedProj4String() );
QgsDebugMsg( QString( "------ Global OTF Projection Selection set to ----------\n%1" ).arg( leGlobalOtfProjString->text() ) );
}
else
{
QgsDebugMsg( "------ Global OTF Projection Selection change cancelled ----------" );
QApplication::restoreOverrideCursor();
}
}

// Return state of the visibility flag for newly added layers. If

bool QgsOptions::newVisible()
Expand Down
7 changes: 2 additions & 5 deletions src/app/qgsoptions.h
Expand Up @@ -50,6 +50,8 @@ class QgsOptions : public QDialog, private Ui::QgsOptionsBase
public slots:
//! Slot called when user chooses to change the project wide projection.
void on_pbnSelectProjection_clicked();
//! Slot called when user chooses to change the default 'on the fly' projection.
void on_pbnSelectOtfProjection_clicked();
void saveOptions();
//! Slot to change the theme this is handled when the user
// activates or highlights a theme name in the drop-down list
Expand Down Expand Up @@ -125,12 +127,7 @@ class QgsOptions : public QDialog, private Ui::QgsOptionsBase
QString getEllipsoidName( QString theEllipsoidAcronym );

private:
//
QStringList i18nList();

//!Default proj4 string used for new layers added that have no projection
QString mGlobalProj4String;

};

#endif // #ifndef QGSOPTIONS_H
65 changes: 39 additions & 26 deletions src/ui/qgsoptionsbase.ui
Expand Up @@ -60,8 +60,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>744</width>
<height>817</height>
<width>746</width>
<height>862</height>
</rect>
</property>
<layout class="QGridLayout" name="gridLayout_12">
Expand Down Expand Up @@ -499,8 +499,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>666</width>
<height>466</height>
<width>746</width>
<height>481</height>
</rect>
</property>
<layout class="QGridLayout" name="gridLayout_8">
Expand Down Expand Up @@ -670,8 +670,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>612</width>
<height>469</height>
<width>746</width>
<height>500</height>
</rect>
</property>
<layout class="QGridLayout" name="gridLayout_4">
Expand Down Expand Up @@ -950,8 +950,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>310</width>
<height>86</height>
<width>762</width>
<height>457</height>
</rect>
</property>
<layout class="QGridLayout" name="gridLayout_10">
Expand Down Expand Up @@ -1025,8 +1025,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>838</width>
<height>432</height>
<width>837</width>
<height>454</height>
</rect>
</property>
<layout class="QGridLayout" name="gridLayout_13">
Expand Down Expand Up @@ -1354,9 +1354,9 @@
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>416</width>
<height>568</height>
<y>-59</y>
<width>746</width>
<height>516</height>
</rect>
</property>
<layout class="QGridLayout" name="gridLayout_15">
Expand Down Expand Up @@ -1414,17 +1414,30 @@
</widget>
</item>
<item row="3" column="0">
<spacer>
<property name="orientation">
<enum>Qt::Vertical</enum>
<widget class="QGroupBox" name="grpOtfTransform">
<property name="title">
<string>Always use 'on the fly' CRS transformation for new projects</string>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>51</width>
<height>135</height>
</size>
<property name="checkable">
<bool>true</bool>
</property>
</spacer>
<layout class="QVBoxLayout" name="verticalLayout_3">
<item>
<widget class="QLineEdit" name="leGlobalOtfProjString">
<property name="readOnly">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="pbnSelectOtfProjection">
<property name="text">
<string>Select CRS for 'on the fly' transformation ...</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>
</layout>
</widget>
Expand All @@ -1451,8 +1464,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>519</width>
<height>567</height>
<width>746</width>
<height>551</height>
</rect>
</property>
<layout class="QGridLayout" name="gridLayout_17">
Expand Down Expand Up @@ -1542,8 +1555,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>407</width>
<height>508</height>
<width>746</width>
<height>548</height>
</rect>
</property>
<layout class="QGridLayout" name="gridLayout_20">
Expand Down

0 comments on commit 79eb19e

Please sign in to comment.