Skip to content

Commit a8d2b09

Browse files
author
timlinux
committed
Applied patch for #363 from Alex Bruy to enable on the fly projection by default.
git-svn-id: http://svn.osgeo.org/qgis/trunk/qgis@15344 c8812cc2-4d05-0410-92ff-de0c093fc19c
1 parent 56d832b commit a8d2b09

File tree

4 files changed

+119
-33
lines changed

4 files changed

+119
-33
lines changed

src/app/qgisapp.cpp

+46-2
Original file line numberDiff line numberDiff line change
@@ -3256,7 +3256,28 @@ void QgisApp::fileNew( bool thePromptToSaveFlag )
32563256
mMapCanvas->refresh();
32573257
mMapCanvas->clearExtentHistory();
32583258

3259-
mMapCanvas->mapRenderer()->setProjectionsEnabled( false );
3259+
// enable OTF CRS transformation if necessary
3260+
if ( settings.value( "/Projections/otfTransformEnabled", 0 ).toBool() )
3261+
{
3262+
QgsMapRenderer* myRenderer = mMapCanvas->mapRenderer();
3263+
QString projString = settings.value( "/Projections/defaultOTFProjectionString", GEOPROJ4 ).toString();
3264+
QgsCoordinateReferenceSystem srs;
3265+
srs.createFromProj4( projString );
3266+
myRenderer->setProjectionsEnabled( true );
3267+
myRenderer->setDestinationSrs( srs );
3268+
// write the projections _proj string_ to project settings
3269+
prj->writeEntry( "SpatialRefSys", "/ProjectCRSProj4String", projString );
3270+
prj->dirty( false );
3271+
if ( srs.mapUnits() != QGis::UnknownUnit )
3272+
{
3273+
myRenderer->setMapUnits( srs.mapUnits() );
3274+
}
3275+
mOnTheFlyProjectionStatusButton->setIcon( getThemeIcon( "mIconProjectionEnabled.png" ) );
3276+
}
3277+
else
3278+
{
3279+
mMapCanvas->mapRenderer()->setProjectionsEnabled( false );
3280+
}
32603281

32613282
// set the initial map tool
32623283
mMapCanvas->setMapTool( mMapTools.mPan );
@@ -5506,7 +5527,30 @@ void QgisApp::options()
55065527
int action = mySettings.value( "/qgis/wheel_action", 0 ).toInt();
55075528
double zoomFactor = mySettings.value( "/qgis/zoom_factor", 2 ).toDouble();
55085529
mMapCanvas->setWheelAction(( QgsMapCanvas::WheelAction ) action, zoomFactor );
5509-
}
5530+
5531+
//apply OTF CRS transformation if necessary
5532+
if ( mySettings.value( "/Projections/otfTransformEnabled", 0 ).toBool() )
5533+
{
5534+
QgsMapRenderer* myRenderer = mMapCanvas->mapRenderer();
5535+
QString projString = mySettings.value( "/Projections/defaultOTFProjectionString", GEOPROJ4 ).toString();
5536+
QgsCoordinateReferenceSystem srs;
5537+
srs.createFromProj4( projString );
5538+
myRenderer->setProjectionsEnabled( true );
5539+
myRenderer->setDestinationSrs( srs );
5540+
// write the projections _proj string_ to project settings
5541+
QgsProject::instance()->writeEntry( "SpatialRefSys", "/ProjectCRSProj4String", projString );
5542+
if ( srs.mapUnits() != QGis::UnknownUnit )
5543+
{
5544+
myRenderer->setMapUnits( srs.mapUnits() );
5545+
}
5546+
}
5547+
else
5548+
{
5549+
QgsMapRenderer* myRenderer = mMapCanvas->mapRenderer();
5550+
myRenderer->setProjectionsEnabled( false );
5551+
}
5552+
mMapCanvas->refresh();
5553+
}
55105554

55115555
delete optionsDialog;
55125556
}

src/app/qgsoptions.cpp

+32
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,10 @@ QgsOptions::QgsOptions( QWidget *parent, Qt::WFlags fl ) :
191191

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

194+
//on the fly CRS transformation settings
195+
grpOtfTransform->setChecked( settings.value( "/Projections/otfTransformEnabled", 0 ).toBool() );
196+
leGlobalOtfProjString->setText( settings.value( "/Projections/defaultOTFProjectionString", GEOPROJ4 ).toString() );
197+
194198
// populate combo box with ellipsoids
195199
getEllipsoidList();
196200
QString myEllipsoidId = settings.value( "/qgis/measure/ellipsoid", "WGS84" ).toString();
@@ -631,6 +635,10 @@ void QgsOptions::saveOptions()
631635

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

638+
// save 'on the fly' CRS transformation settings
639+
settings.setValue( "/Projections/otfTransformEnabled", grpOtfTransform->isChecked() );
640+
settings.setValue( "/Projections/defaultOTFProjectionString", leGlobalOtfProjString->text() );
641+
634642
settings.setValue( "/qgis/measure/ellipsoid", getEllipsoidAcronym( cmbEllipsoid->currentText() ) );
635643

636644
if ( radFeet->isChecked() )
@@ -760,6 +768,30 @@ void QgsOptions::on_pbnSelectProjection_clicked()
760768

761769
}
762770

771+
void QgsOptions::on_pbnSelectOtfProjection_clicked()
772+
{
773+
QSettings settings;
774+
QgsGenericProjectionSelector * mySelector = new QgsGenericProjectionSelector( this );
775+
776+
//find out srs id of current proj4 string
777+
QgsCoordinateReferenceSystem refSys;
778+
if ( refSys.createFromProj4( leGlobalOtfProjString->text() ) )
779+
{
780+
mySelector->setSelectedCrsId( refSys.srsid() );
781+
}
782+
783+
if ( mySelector->exec() )
784+
{
785+
leGlobalOtfProjString->setText( mySelector->selectedProj4String() );
786+
QgsDebugMsg( QString( "------ Global OTF Projection Selection set to ----------\n%1" ).arg( leGlobalOtfProjString->text() ) );
787+
}
788+
else
789+
{
790+
QgsDebugMsg( "------ Global OTF Projection Selection change cancelled ----------" );
791+
QApplication::restoreOverrideCursor();
792+
}
793+
}
794+
763795
// Return state of the visibility flag for newly added layers. If
764796

765797
bool QgsOptions::newVisible()

src/app/qgsoptions.h

+2-5
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,8 @@ class QgsOptions : public QDialog, private Ui::QgsOptionsBase
5050
public slots:
5151
//! Slot called when user chooses to change the project wide projection.
5252
void on_pbnSelectProjection_clicked();
53+
//! Slot called when user chooses to change the default 'on the fly' projection.
54+
void on_pbnSelectOtfProjection_clicked();
5355
void saveOptions();
5456
//! Slot to change the theme this is handled when the user
5557
// activates or highlights a theme name in the drop-down list
@@ -125,12 +127,7 @@ class QgsOptions : public QDialog, private Ui::QgsOptionsBase
125127
QString getEllipsoidName( QString theEllipsoidAcronym );
126128

127129
private:
128-
//
129130
QStringList i18nList();
130-
131-
//!Default proj4 string used for new layers added that have no projection
132-
QString mGlobalProj4String;
133-
134131
};
135132

136133
#endif // #ifndef QGSOPTIONS_H

src/ui/qgsoptionsbase.ui

+39-26
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,8 @@
6060
<rect>
6161
<x>0</x>
6262
<y>0</y>
63-
<width>744</width>
64-
<height>817</height>
63+
<width>746</width>
64+
<height>862</height>
6565
</rect>
6666
</property>
6767
<layout class="QGridLayout" name="gridLayout_12">
@@ -499,8 +499,8 @@
499499
<rect>
500500
<x>0</x>
501501
<y>0</y>
502-
<width>666</width>
503-
<height>466</height>
502+
<width>746</width>
503+
<height>481</height>
504504
</rect>
505505
</property>
506506
<layout class="QGridLayout" name="gridLayout_8">
@@ -670,8 +670,8 @@
670670
<rect>
671671
<x>0</x>
672672
<y>0</y>
673-
<width>612</width>
674-
<height>469</height>
673+
<width>746</width>
674+
<height>500</height>
675675
</rect>
676676
</property>
677677
<layout class="QGridLayout" name="gridLayout_4">
@@ -950,8 +950,8 @@
950950
<rect>
951951
<x>0</x>
952952
<y>0</y>
953-
<width>310</width>
954-
<height>86</height>
953+
<width>762</width>
954+
<height>457</height>
955955
</rect>
956956
</property>
957957
<layout class="QGridLayout" name="gridLayout_10">
@@ -1025,8 +1025,8 @@
10251025
<rect>
10261026
<x>0</x>
10271027
<y>0</y>
1028-
<width>838</width>
1029-
<height>432</height>
1028+
<width>837</width>
1029+
<height>454</height>
10301030
</rect>
10311031
</property>
10321032
<layout class="QGridLayout" name="gridLayout_13">
@@ -1354,9 +1354,9 @@
13541354
<property name="geometry">
13551355
<rect>
13561356
<x>0</x>
1357-
<y>0</y>
1358-
<width>416</width>
1359-
<height>568</height>
1357+
<y>-59</y>
1358+
<width>746</width>
1359+
<height>516</height>
13601360
</rect>
13611361
</property>
13621362
<layout class="QGridLayout" name="gridLayout_15">
@@ -1414,17 +1414,30 @@
14141414
</widget>
14151415
</item>
14161416
<item row="3" column="0">
1417-
<spacer>
1418-
<property name="orientation">
1419-
<enum>Qt::Vertical</enum>
1417+
<widget class="QGroupBox" name="grpOtfTransform">
1418+
<property name="title">
1419+
<string>Always use 'on the fly' CRS transformation for new projects</string>
14201420
</property>
1421-
<property name="sizeHint" stdset="0">
1422-
<size>
1423-
<width>51</width>
1424-
<height>135</height>
1425-
</size>
1421+
<property name="checkable">
1422+
<bool>true</bool>
14261423
</property>
1427-
</spacer>
1424+
<layout class="QVBoxLayout" name="verticalLayout_3">
1425+
<item>
1426+
<widget class="QLineEdit" name="leGlobalOtfProjString">
1427+
<property name="readOnly">
1428+
<bool>true</bool>
1429+
</property>
1430+
</widget>
1431+
</item>
1432+
<item>
1433+
<widget class="QPushButton" name="pbnSelectOtfProjection">
1434+
<property name="text">
1435+
<string>Select CRS for 'on the fly' transformation ...</string>
1436+
</property>
1437+
</widget>
1438+
</item>
1439+
</layout>
1440+
</widget>
14281441
</item>
14291442
</layout>
14301443
</widget>
@@ -1451,8 +1464,8 @@
14511464
<rect>
14521465
<x>0</x>
14531466
<y>0</y>
1454-
<width>519</width>
1455-
<height>567</height>
1467+
<width>746</width>
1468+
<height>551</height>
14561469
</rect>
14571470
</property>
14581471
<layout class="QGridLayout" name="gridLayout_17">
@@ -1542,8 +1555,8 @@
15421555
<rect>
15431556
<x>0</x>
15441557
<y>0</y>
1545-
<width>407</width>
1546-
<height>508</height>
1558+
<width>746</width>
1559+
<height>548</height>
15471560
</rect>
15481561
</property>
15491562
<layout class="QGridLayout" name="gridLayout_20">

0 commit comments

Comments
 (0)