Skip to content

Commit 5b4a7ae

Browse files
committed
Automatically enable OTF projection if layers have different CRS
1 parent 3af7ef3 commit 5b4a7ae

File tree

3 files changed

+67
-31
lines changed

3 files changed

+67
-31
lines changed

src/app/legend/qgslegend.cpp

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -884,10 +884,16 @@ void QgsLegend::addLayers( QList<QgsMapLayer *> theLayerList )
884884
//Note if the canvas was previously blank so we can
885885
//zoom to all layers at the end if neeeded
886886
bool myFirstLayerFlag = false;
887+
QgsCoordinateReferenceSystem myPreviousCrs;
887888
if ( layers().count() < 1 )
888889
{
889890
myFirstLayerFlag = true;
890891
}
892+
else
893+
{
894+
// remember CRS of present layer
895+
myPreviousCrs = layers().first()->crs();
896+
}
891897

892898
//iteratively add the layers to the canvas
893899
for ( int i = 0; i < theLayerList.size(); ++i )
@@ -956,10 +962,26 @@ void QgsLegend::addLayers( QList<QgsMapLayer *> theLayerList )
956962
mMapCanvas->zoomToFullExtent();
957963
mMapCanvas->clearExtentHistory();
958964
}
965+
else
966+
{
967+
if ( settings.value( "/Projections/otfTransformAutoEnable", true ).toBool() &&
968+
!mMapCanvas->mapRenderer()->hasCrsTransformEnabled() )
969+
{
970+
// Verify if all layers have the same CRS
971+
foreach( QgsMapLayer *l, layers() )
972+
{
973+
if ( myPreviousCrs != l->crs() )
974+
{
975+
// Set to the previous de facto used so that extent does not change
976+
mMapCanvas->mapRenderer()->setDestinationCrs( myPreviousCrs );
977+
mMapCanvas->mapRenderer()->setProjectionsEnabled( true );
978+
break;
979+
}
980+
}
981+
}
982+
}
959983
//make the QTreeWidget item up-to-date
960984
doItemsLayout();
961-
962-
963985
}
964986

965987
//deprecated since 1.8 - delegates to addLayers

src/app/qgsoptions.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,7 @@ QgsOptions::QgsOptions( QWidget *parent, Qt::WFlags fl ) :
245245
leLayerGlobalCrs->setText( mLayerDefaultCrs.authid() + " - " + mLayerDefaultCrs.description() );
246246

247247
//on the fly CRS transformation settings
248+
chkOtfAuto->setChecked( settings.value( "/Projections/otfTransformAutoEnable", true ).toBool() );
248249
chkOtfTransform->setChecked( settings.value( "/Projections/otfTransformEnabled", 0 ).toBool() );
249250

250251
QString myDefaultCrs = settings.value( "/Projections/projectDefaultCrs", GEO_EPSG_CRS_AUTHID ).toString();
@@ -897,6 +898,7 @@ void QgsOptions::saveOptions()
897898
settings.setValue( "/Projections/layerDefaultCrs", mLayerDefaultCrs.authid() );
898899

899900
// save 'on the fly' CRS transformation settings
901+
settings.setValue( "/Projections/otfTransformAutoEnable", chkOtfAuto->isChecked() );
900902
settings.setValue( "/Projections/otfTransformEnabled", chkOtfTransform->isChecked() );
901903
settings.setValue( "/Projections/projectDefaultCrs", mDefaultCrs.authid() );
902904

src/ui/qgsoptionsbase.ui

Lines changed: 41 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,8 @@
6666
<rect>
6767
<x>0</x>
6868
<y>0</y>
69-
<width>760</width>
70-
<height>887</height>
69+
<width>766</width>
70+
<height>938</height>
7171
</rect>
7272
</property>
7373
<layout class="QGridLayout" name="gridLayout">
@@ -890,8 +890,8 @@
890890
<rect>
891891
<x>0</x>
892892
<y>0</y>
893-
<width>630</width>
894-
<height>625</height>
893+
<width>766</width>
894+
<height>592</height>
895895
</rect>
896896
</property>
897897
<layout class="QGridLayout" name="gridLayout_8">
@@ -1136,9 +1136,9 @@
11361136
<property name="geometry">
11371137
<rect>
11381138
<x>0</x>
1139-
<y>-313</y>
1140-
<width>762</width>
1141-
<height>750</height>
1139+
<y>0</y>
1140+
<width>766</width>
1141+
<height>718</height>
11421142
</rect>
11431143
</property>
11441144
<layout class="QGridLayout" name="gridLayout_4">
@@ -1507,8 +1507,8 @@
15071507
<rect>
15081508
<x>0</x>
15091509
<y>0</y>
1510-
<width>270</width>
1511-
<height>93</height>
1510+
<width>784</width>
1511+
<height>452</height>
15121512
</rect>
15131513
</property>
15141514
<layout class="QGridLayout" name="gridLayout_10">
@@ -1588,8 +1588,8 @@
15881588
<rect>
15891589
<x>0</x>
15901590
<y>0</y>
1591-
<width>571</width>
1592-
<height>627</height>
1591+
<width>766</width>
1592+
<height>572</height>
15931593
</rect>
15941594
</property>
15951595
<layout class="QGridLayout" name="gridLayout_13">
@@ -1964,8 +1964,8 @@
19641964
<rect>
19651965
<x>0</x>
19661966
<y>0</y>
1967-
<width>425</width>
1968-
<height>417</height>
1967+
<width>784</width>
1968+
<height>452</height>
19691969
</rect>
19701970
</property>
19711971
<layout class="QGridLayout" name="gridLayout_15">
@@ -1984,28 +1984,21 @@
19841984
<bool>false</bool>
19851985
</property>
19861986
<layout class="QGridLayout" name="gridLayout_22">
1987-
<item row="1" column="0">
1987+
<item row="3" column="0">
19881988
<widget class="QLineEdit" name="leProjectGlobalCrs">
19891989
<property name="readOnly">
19901990
<bool>true</bool>
19911991
</property>
19921992
</widget>
19931993
</item>
1994-
<item row="3" column="0">
1995-
<widget class="QCheckBox" name="chkOtfTransform">
1996-
<property name="text">
1997-
<string>Enable 'on the &amp;fly' reprojection by default</string>
1998-
</property>
1999-
</widget>
2000-
</item>
2001-
<item row="1" column="1">
1994+
<item row="3" column="1">
20021995
<widget class="QPushButton" name="pbnSelectOtfProjection">
20031996
<property name="text">
20041997
<string>Select...</string>
20051998
</property>
20061999
</widget>
20072000
</item>
2008-
<item row="4" column="0" colspan="2">
2001+
<item row="6" column="0" colspan="2">
20092002
<spacer name="verticalSpacer">
20102003
<property name="orientation">
20112004
<enum>Qt::Vertical</enum>
@@ -2018,7 +2011,7 @@
20182011
</property>
20192012
</spacer>
20202013
</item>
2021-
<item row="0" column="0">
2014+
<item row="2" column="0">
20222015
<widget class="QLabel" name="label_16">
20232016
<property name="text">
20242017
<string>Always start new projects with this CRS</string>
@@ -2028,6 +2021,26 @@
20282021
</property>
20292022
</widget>
20302023
</item>
2024+
<item row="0" column="0">
2025+
<widget class="QCheckBox" name="chkOtfAuto">
2026+
<property name="toolTip">
2027+
<string/>
2028+
</property>
2029+
<property name="whatsThis">
2030+
<string>Automatically enable 'on the fly' reprojection if CRS of a new added layer differ from CRS of layer(s) already present. CRS of present layer(s) will be used.</string>
2031+
</property>
2032+
<property name="text">
2033+
<string>Automatically enable 'on the fly' reprojection if layers have different CRS</string>
2034+
</property>
2035+
</widget>
2036+
</item>
2037+
<item row="1" column="0">
2038+
<widget class="QCheckBox" name="chkOtfTransform">
2039+
<property name="text">
2040+
<string>Enable 'on the &amp;fly' reprojection by default</string>
2041+
</property>
2042+
</widget>
2043+
</item>
20312044
</layout>
20322045
</widget>
20332046
</item>
@@ -2138,8 +2151,8 @@
21382151
<rect>
21392152
<x>0</x>
21402153
<y>0</y>
2141-
<width>519</width>
2142-
<height>584</height>
2154+
<width>766</width>
2155+
<height>536</height>
21432156
</rect>
21442157
</property>
21452158
<layout class="QGridLayout" name="gridLayout_17">
@@ -2235,8 +2248,8 @@
22352248
<rect>
22362249
<x>0</x>
22372250
<y>0</y>
2238-
<width>355</width>
2239-
<height>554</height>
2251+
<width>766</width>
2252+
<height>491</height>
22402253
</rect>
22412254
</property>
22422255
<layout class="QGridLayout" name="gridLayout_20">
@@ -2528,7 +2541,6 @@
25282541
<tabstop>scrollArea_6</tabstop>
25292542
<tabstop>pbnSelectOtfProjection</tabstop>
25302543
<tabstop>leProjectGlobalCrs</tabstop>
2531-
<tabstop>chkOtfTransform</tabstop>
25322544
<tabstop>radPromptForProjection</tabstop>
25332545
<tabstop>radUseProjectProjection</tabstop>
25342546
<tabstop>radUseGlobalProjection</tabstop>

0 commit comments

Comments
 (0)