Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Automatically enable OTF projection if layers have different CRS
  • Loading branch information
blazek committed Jul 19, 2012
1 parent 3af7ef3 commit 5b4a7ae
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 31 deletions.
26 changes: 24 additions & 2 deletions src/app/legend/qgslegend.cpp
Expand Up @@ -884,10 +884,16 @@ void QgsLegend::addLayers( QList<QgsMapLayer *> theLayerList )
//Note if the canvas was previously blank so we can
//zoom to all layers at the end if neeeded
bool myFirstLayerFlag = false;
QgsCoordinateReferenceSystem myPreviousCrs;
if ( layers().count() < 1 )
{
myFirstLayerFlag = true;
}
else
{
// remember CRS of present layer
myPreviousCrs = layers().first()->crs();
}

//iteratively add the layers to the canvas
for ( int i = 0; i < theLayerList.size(); ++i )
Expand Down Expand Up @@ -956,10 +962,26 @@ void QgsLegend::addLayers( QList<QgsMapLayer *> theLayerList )
mMapCanvas->zoomToFullExtent();
mMapCanvas->clearExtentHistory();
}
else
{
if ( settings.value( "/Projections/otfTransformAutoEnable", true ).toBool() &&
!mMapCanvas->mapRenderer()->hasCrsTransformEnabled() )
{
// Verify if all layers have the same CRS
foreach( QgsMapLayer *l, layers() )
{
if ( myPreviousCrs != l->crs() )
{
// Set to the previous de facto used so that extent does not change
mMapCanvas->mapRenderer()->setDestinationCrs( myPreviousCrs );
mMapCanvas->mapRenderer()->setProjectionsEnabled( true );
break;
}
}
}
}
//make the QTreeWidget item up-to-date
doItemsLayout();


}

//deprecated since 1.8 - delegates to addLayers
Expand Down
2 changes: 2 additions & 0 deletions src/app/qgsoptions.cpp
Expand Up @@ -245,6 +245,7 @@ QgsOptions::QgsOptions( QWidget *parent, Qt::WFlags fl ) :
leLayerGlobalCrs->setText( mLayerDefaultCrs.authid() + " - " + mLayerDefaultCrs.description() );

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

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

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

Expand Down
70 changes: 41 additions & 29 deletions src/ui/qgsoptionsbase.ui
Expand Up @@ -66,8 +66,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>760</width>
<height>887</height>
<width>766</width>
<height>938</height>
</rect>
</property>
<layout class="QGridLayout" name="gridLayout">
Expand Down Expand Up @@ -890,8 +890,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>630</width>
<height>625</height>
<width>766</width>
<height>592</height>
</rect>
</property>
<layout class="QGridLayout" name="gridLayout_8">
Expand Down Expand Up @@ -1136,9 +1136,9 @@
<property name="geometry">
<rect>
<x>0</x>
<y>-313</y>
<width>762</width>
<height>750</height>
<y>0</y>
<width>766</width>
<height>718</height>
</rect>
</property>
<layout class="QGridLayout" name="gridLayout_4">
Expand Down Expand Up @@ -1507,8 +1507,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>270</width>
<height>93</height>
<width>784</width>
<height>452</height>
</rect>
</property>
<layout class="QGridLayout" name="gridLayout_10">
Expand Down Expand Up @@ -1588,8 +1588,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>571</width>
<height>627</height>
<width>766</width>
<height>572</height>
</rect>
</property>
<layout class="QGridLayout" name="gridLayout_13">
Expand Down Expand Up @@ -1964,8 +1964,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>425</width>
<height>417</height>
<width>784</width>
<height>452</height>
</rect>
</property>
<layout class="QGridLayout" name="gridLayout_15">
Expand All @@ -1984,28 +1984,21 @@
<bool>false</bool>
</property>
<layout class="QGridLayout" name="gridLayout_22">
<item row="1" column="0">
<item row="3" column="0">
<widget class="QLineEdit" name="leProjectGlobalCrs">
<property name="readOnly">
<bool>true</bool>
</property>
</widget>
</item>
<item row="3" column="0">
<widget class="QCheckBox" name="chkOtfTransform">
<property name="text">
<string>Enable 'on the &amp;fly' reprojection by default</string>
</property>
</widget>
</item>
<item row="1" column="1">
<item row="3" column="1">
<widget class="QPushButton" name="pbnSelectOtfProjection">
<property name="text">
<string>Select...</string>
</property>
</widget>
</item>
<item row="4" column="0" colspan="2">
<item row="6" column="0" colspan="2">
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
Expand All @@ -2018,7 +2011,7 @@
</property>
</spacer>
</item>
<item row="0" column="0">
<item row="2" column="0">
<widget class="QLabel" name="label_16">
<property name="text">
<string>Always start new projects with this CRS</string>
Expand All @@ -2028,6 +2021,26 @@
</property>
</widget>
</item>
<item row="0" column="0">
<widget class="QCheckBox" name="chkOtfAuto">
<property name="toolTip">
<string/>
</property>
<property name="whatsThis">
<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>
</property>
<property name="text">
<string>Automatically enable 'on the fly' reprojection if layers have different CRS</string>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QCheckBox" name="chkOtfTransform">
<property name="text">
<string>Enable 'on the &amp;fly' reprojection by default</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>
Expand Down Expand Up @@ -2138,8 +2151,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>519</width>
<height>584</height>
<width>766</width>
<height>536</height>
</rect>
</property>
<layout class="QGridLayout" name="gridLayout_17">
Expand Down Expand Up @@ -2235,8 +2248,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>355</width>
<height>554</height>
<width>766</width>
<height>491</height>
</rect>
</property>
<layout class="QGridLayout" name="gridLayout_20">
Expand Down Expand Up @@ -2528,7 +2541,6 @@
<tabstop>scrollArea_6</tabstop>
<tabstop>pbnSelectOtfProjection</tabstop>
<tabstop>leProjectGlobalCrs</tabstop>
<tabstop>chkOtfTransform</tabstop>
<tabstop>radPromptForProjection</tabstop>
<tabstop>radUseProjectProjection</tabstop>
<tabstop>radUseGlobalProjection</tabstop>
Expand Down

0 comments on commit 5b4a7ae

Please sign in to comment.