Skip to content
Permalink
Browse files

Moving canvas away from QgsMapRenderer, now with OTF projections working

  • Loading branch information
wonder-sk committed Nov 1, 2013
1 parent d9b95bc commit 9fb6a1cae143dd88d59562764360d6dfa41dee67
@@ -679,7 +679,7 @@ void QgsGPSInformationWidget::displayGPSInformation( const QgsGPSInformation& in
// Pan based on user specified behaviour
if ( radRecenterMap->isChecked() || radRecenterWhenNeeded->isChecked() )
{
QgsCoordinateReferenceSystem mypSRS = mpCanvas->mapRenderer()->destinationCrs();
QgsCoordinateReferenceSystem mypSRS = mpCanvas->mapSettings().destinationCrs();
QgsCoordinateTransform myTransform( mWgs84CRS, mypSRS ); // use existing WGS84 CRS

QgsPoint myPoint = myTransform.transform( myNewCenter );
@@ -751,9 +751,9 @@ void QgsGPSInformationWidget::addVertex()
// potential problem with transform errors and wrong coordinates if map CRS is changed after points are stored - SLM
// should catch map CRS change and transform the points
QgsPoint myPoint;
if ( mpCanvas && mpCanvas->mapRenderer() )
if ( mpCanvas )
{
QgsCoordinateTransform t( mWgs84CRS, mpCanvas->mapRenderer()->destinationCrs() );
QgsCoordinateTransform t( mWgs84CRS, mpCanvas->mapSettings().destinationCrs() );
myPoint = t.transform( mLastGpsPosition );
}
else
@@ -41,9 +41,9 @@ void QgsGpsMarker::setSize( int theSize )
void QgsGpsMarker::setCenter( const QgsPoint& point )
{
//transform to map crs
if ( mMapCanvas && mMapCanvas->mapRenderer() )
if ( mMapCanvas )
{
QgsCoordinateTransform t( mWgs84CRS, mMapCanvas->mapRenderer()->destinationCrs() );
QgsCoordinateTransform t( mWgs84CRS, mMapCanvas->mapSettings().destinationCrs() );
try
{
mCenter = t.transform( point );
@@ -1160,27 +1160,27 @@ void QgsLegend::addLayers( QList<QgsMapLayer *> theLayerList )
if ( myFirstLayerFlag )
{
QgsMapLayer * myFirstLayer = theLayerList.at( 0 );
if ( !mMapCanvas->mapRenderer()->hasCrsTransformEnabled() )
if ( !mMapCanvas->mapSettings().hasCrsTransformEnabled() )
{
mMapCanvas->mapRenderer()->setDestinationCrs( myFirstLayer->crs() );
mMapCanvas->mapRenderer()->setMapUnits( myFirstLayer->crs().mapUnits() );
mMapCanvas->setDestinationCrs( myFirstLayer->crs() );
mMapCanvas->setMapUnits( myFirstLayer->crs().mapUnits() );
}
mMapCanvas->zoomToFullExtent();
mMapCanvas->clearExtentHistory();
}
else
{
if ( settings.value( "/Projections/otfTransformAutoEnable", true ).toBool() &&
!mMapCanvas->mapRenderer()->hasCrsTransformEnabled() )
!mMapCanvas->mapSettings().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 );
mMapCanvas->setDestinationCrs( myPreviousCrs );
mMapCanvas->setCrsTransformEnabled( true );
break;
}
}
@@ -2807,10 +2807,10 @@ void QgsLegend::legendLayerZoomNative()
{
// get legth of central canvas pixel width in source raster crs
QgsRectangle e = mMapCanvas->extent();
QgsMapRenderer* r = mMapCanvas->mapRenderer();
QSize s = mMapCanvas->mapSettings().outputSize();
QgsPoint p1( e.center().x(), e.center().y() );
QgsPoint p2( e.center().x() + e.width() / r->width(), e.center().y() + e.height() / r->height() );
QgsCoordinateTransform ct( r->destinationCrs(), layer->crs() );
QgsPoint p2( e.center().x() + e.width() / s.width(), e.center().y() + e.height() / s.height() );
QgsCoordinateTransform ct( mMapCanvas->mapSettings().destinationCrs(), layer->crs() );
p1 = ct.transform( p1 );
p2 = ct.transform( p2 );
double width = sqrt( p1.sqrDist( p2 ) ); // width of reprojected pixel
@@ -386,7 +386,7 @@ void QgisApp::validateSrs( QgsCoordinateReferenceSystem &srs )
QgsGenericProjectionSelector *mySelector = new QgsGenericProjectionSelector();
mySelector->setMessage( srs.validationHint() ); //shows a generic message, if not specified
if ( authid.isNull() )
authid = QgisApp::instance()->mapCanvas()->mapRenderer()->destinationCrs().authid();
authid = QgisApp::instance()->mapCanvas()->mapSettings().destinationCrs().authid();

QgsCoordinateReferenceSystem defaultCrs;
if ( defaultCrs.createFromOgcWmsCrs( authid ) )
@@ -413,7 +413,7 @@ void QgisApp::validateSrs( QgsCoordinateReferenceSystem &srs )
else if ( myDefaultProjectionOption == "useProject" )
{
// XXX TODO: Change project to store selected CS as 'projectCRS' not 'selectedWkt'
authid = QgisApp::instance()->mapCanvas()->mapRenderer()->destinationCrs().authid();
authid = QgisApp::instance()->mapCanvas()->mapSettings().destinationCrs().authid();
QgsDebugMsg( "Layer srs set from project: " + authid );
QgisApp::instance()->statusBar()->showMessage( tr( "CRS undefined - defaulting to project CRS" ) );
srs.createFromOgcWmsCrs( authid );
@@ -1658,7 +1658,6 @@ void QgisApp::createStatusBar()
mOnTheFlyProjectionStatusLabel->setMargin( 3 );
mOnTheFlyProjectionStatusLabel->setAlignment( Qt::AlignCenter );
mOnTheFlyProjectionStatusLabel->setFrameStyle( QFrame::NoFrame );
QString myCrs = mMapCanvas->mapRenderer()->destinationCrs().authid();
statusBar()->addPermanentWidget( mOnTheFlyProjectionStatusLabel, 0 );
// On the fly projection status bar icon
// Changed this to a tool button since a QPushButton is
@@ -1898,9 +1897,9 @@ void QgisApp::setupConnections()
mMapCanvas, SLOT( setRenderFlag( bool ) ) );

// connect renderer
connect( mMapCanvas->mapRenderer(), SIGNAL( hasCrsTransformEnabled( bool ) ),
connect( mMapCanvas, SIGNAL( hasCrsTransformEnabled( bool ) ),
this, SLOT( hasCrsTransformEnabled( bool ) ) );
connect( mMapCanvas->mapRenderer(), SIGNAL( destinationSrsChanged() ),
connect( mMapCanvas, SIGNAL( destinationSrsChanged() ),
this, SLOT( destinationSrsChanged() ) );

// connect legend signals
@@ -3161,9 +3160,9 @@ void QgisApp::addWfsLayer()

//re-enable wfs with extent setting: pass canvas info to source select
wfss->setProperty( "MapExtent", mMapCanvas->extent().toString() );
if ( mMapCanvas->mapRenderer()->hasCrsTransformEnabled() )
if ( mMapCanvas->mapSettings().hasCrsTransformEnabled() )
{ //if "on the fly" reprojection is active, pass canvas CRS
wfss->setProperty( "MapCRS", mMapCanvas->mapRenderer()->destinationCrs().authid() );
wfss->setProperty( "MapCRS", mMapCanvas->mapSettings().destinationCrs().authid() );
}

bool bkRenderFlag = mMapCanvas->renderFlag();
@@ -3271,21 +3270,20 @@ void QgisApp::fileNew( bool thePromptToSaveFlag, bool forceBlank )
mScaleEdit->updateScales();

// set project CRS
QgsMapRenderer* myRenderer = mMapCanvas->mapRenderer();
QString defCrs = settings.value( "/Projections/projectDefaultCrs", GEO_EPSG_CRS_AUTHID ).toString();
QgsCoordinateReferenceSystem srs;
srs.createFromOgcWmsCrs( defCrs );
myRenderer->setDestinationCrs( srs );
mMapCanvas->setDestinationCrs( srs );
// write the projections _proj string_ to project settings
prj->writeEntry( "SpatialRefSys", "/ProjectCrs", defCrs );
prj->dirty( false );
if ( srs.mapUnits() != QGis::UnknownUnit )
{
myRenderer->setMapUnits( srs.mapUnits() );
mMapCanvas->setMapUnits( srs.mapUnits() );
}

// enable OTF CRS transformation if necessary
myRenderer->setProjectionsEnabled( settings.value( "/Projections/otfTransformEnabled", 0 ).toBool() );
mMapCanvas->setCrsTransformEnabled( settings.value( "/Projections/otfTransformEnabled", 0 ).toBool() );

updateCRSStatusBar();

@@ -3826,7 +3824,7 @@ void QgisApp::openProject( QAction *action )
//set the projections enabled icon in the status bar
int myProjectionEnabledFlag =
QgsProject::instance()->readNumEntry( "SpatialRefSys", "/ProjectionsEnabled", 0 );
mMapCanvas->mapRenderer()->setProjectionsEnabled( myProjectionEnabledFlag );
mMapCanvas->setCrsTransformEnabled( myProjectionEnabledFlag );
} // QgisApp::openProject


@@ -4457,7 +4455,7 @@ void QgisApp::saveAsRasterFile()

QgsRasterLayerSaveAsDialog d( rasterLayer, rasterLayer->dataProvider(),
mMapCanvas->extent(), rasterLayer->crs(),
mMapCanvas->mapRenderer()->destinationCrs(),
mMapCanvas->mapSettings().destinationCrs(),
this );
if ( d.exec() == QDialog::Accepted )
{
@@ -4612,7 +4610,7 @@ void QgisApp::saveAsVectorFileGeneral( bool saveOnlySelection, QgsVectorLayer* v
switch ( dialog->crs() )
{
case -2: // Project CRS
destCRS = mMapCanvas->mapRenderer()->destinationCrs();
destCRS = mMapCanvas->mapSettings().destinationCrs();
break;
case -1: // Layer CRS
destCRS = vlayer->crs();
@@ -5547,7 +5545,7 @@ void QgisApp::editPaste( QgsMapLayer *destinationLayer )

pasteVectorLayer->beginEditCommand( tr( "Features pasted" ) );
QgsFeatureList features;
if ( mMapCanvas->mapRenderer()->hasCrsTransformEnabled() )
if ( mMapCanvas->mapSettings().hasCrsTransformEnabled() )
{
features = clipboard()->transformedCopyOf( pasteVectorLayer->crs(), pasteVectorLayer->pendingFields() );
}
@@ -6581,12 +6579,11 @@ void QgisApp::setProjectCRSFromLayer()
}

QgsCoordinateReferenceSystem crs = mMapLegend->currentLayer()->crs();
QgsMapRenderer* myRenderer = mMapCanvas->mapRenderer();
mMapCanvas->freeze();
myRenderer->setDestinationCrs( crs );
mMapCanvas->setDestinationCrs( crs );
if ( crs.mapUnits() != QGis::UnknownUnit )
{
myRenderer->setMapUnits( crs.mapUnits() );
mMapCanvas->setMapUnits( crs.mapUnits() );
}
mMapCanvas->freeze( false );
mMapCanvas->refresh();
@@ -7855,28 +7852,28 @@ void QgisApp::removeWebToolBarIcon( QAction *qAction )

void QgisApp::updateCRSStatusBar()
{
mOnTheFlyProjectionStatusLabel->setText( mMapCanvas->mapRenderer()->destinationCrs().authid() );
mOnTheFlyProjectionStatusLabel->setText( mMapCanvas->mapSettings().destinationCrs().authid() );

if ( mMapCanvas->mapRenderer()->hasCrsTransformEnabled() )
if ( mMapCanvas->mapSettings().hasCrsTransformEnabled() )
{
mOnTheFlyProjectionStatusLabel->setEnabled( true );
mOnTheFlyProjectionStatusLabel->setToolTip(
tr( "Current CRS: %1 (OTFR enabled)" ).arg( mMapCanvas->mapRenderer()->destinationCrs().description() ) );
tr( "Current CRS: %1 (OTFR enabled)" ).arg( mMapCanvas->mapSettings().destinationCrs().description() ) );
mOnTheFlyProjectionStatusButton->setIcon( QgsApplication::getThemeIcon( "mIconProjectionEnabled.png" ) );
}
else
{
mOnTheFlyProjectionStatusLabel->setEnabled( false );
mOnTheFlyProjectionStatusLabel->setToolTip(
tr( "Current CRS: %1 (OTFR disabled)" ).arg( mMapCanvas->mapRenderer()->destinationCrs().description() ) );
tr( "Current CRS: %1 (OTFR disabled)" ).arg( mMapCanvas->mapSettings().destinationCrs().description() ) );
mOnTheFlyProjectionStatusButton->setIcon( QgsApplication::getThemeIcon( "mIconProjectionDisabled.png" ) );
}
}

void QgisApp::destinationSrsChanged()
{
// save this information to project
long srsid = mMapCanvas->mapRenderer()->destinationCrs().srsid();
long srsid = mMapCanvas->mapSettings().destinationCrs().srsid();
QgsProject::instance()->writeEntry( "SpatialRefSys", "/ProjectCRSID", ( int )srsid );
updateCRSStatusBar();
}
@@ -8113,15 +8110,15 @@ void QgisApp::projectProperties()
// It is needed to refresh scale bar after changing display units.
connect( pp, SIGNAL( refresh() ), mMapCanvas, SLOT( refresh() ) );

QgsMapRenderer* myRender = mMapCanvas->mapRenderer();
bool wasProjected = myRender->hasCrsTransformEnabled();
long oldCRSID = myRender->destinationCrs().srsid();
const QgsMapSettings& ms = mMapCanvas->mapSettings();
bool wasProjected = ms.hasCrsTransformEnabled();
long oldCRSID = ms.destinationCrs().srsid();

// Display the modal dialog box.
pp->exec();

long newCRSID = myRender->destinationCrs().srsid();
bool isProjected = myRender->hasCrsTransformEnabled();
long newCRSID = ms.destinationCrs().srsid();
bool isProjected = ms.hasCrsTransformEnabled();

// projections have been turned on/off or dest CRS has changed while projections are on
if ( wasProjected != isProjected || ( isProjected && oldCRSID != newCRSID ) )
@@ -614,7 +614,7 @@ QDialog* QgisAppInterface::getFeatureForm( QgsVectorLayer *l, QgsFeature &featur
QgsDistanceArea myDa;

myDa.setSourceCrs( l->crs().srsid() );
myDa.setEllipsoidalMode( QgisApp::instance()->mapCanvas()->mapRenderer()->hasCrsTransformEnabled() );
myDa.setEllipsoidalMode( QgisApp::instance()->mapCanvas()->mapSettings().hasCrsTransformEnabled() );
myDa.setEllipsoid( QgsProject::instance()->readEntry( "Measure", "/Ellipsoid", GEO_NONE ) );

QgsAttributeDialog *dialog = new QgsAttributeDialog( l, &feature, false, NULL, true );
@@ -179,7 +179,7 @@ void QgsAttributeActionDialog::insertExpression()

QgsDistanceArea myDa;
myDa.setSourceCrs( mActions->layer()->crs().srsid() );
myDa.setEllipsoidalMode( QgisApp::instance()->mapCanvas()->mapRenderer()->hasCrsTransformEnabled() );
myDa.setEllipsoidalMode( QgisApp::instance()->mapCanvas()->mapSettings().hasCrsTransformEnabled() );
myDa.setEllipsoid( QgsProject::instance()->readEntry( "Measure", "/Ellipsoid", GEO_NONE ) );
dlg.setGeomCalculator( myDa );

@@ -76,7 +76,7 @@ QgsAttributeTableDialog::QgsAttributeTableDialog( QgsVectorLayer *theLayer, QWid
QgsDistanceArea myDa;

myDa.setSourceCrs( mLayer->crs() );
myDa.setEllipsoidalMode( QgisApp::instance()->mapCanvas()->mapRenderer()->hasCrsTransformEnabled() );
myDa.setEllipsoidalMode( QgisApp::instance()->mapCanvas()->mapSettings().hasCrsTransformEnabled() );
myDa.setEllipsoid( QgsProject::instance()->readEntry( "Measure", "/Ellipsoid", GEO_NONE ) );

context.setDistanceArea( myDa );
@@ -277,7 +277,7 @@ void QgsAttributeTableDialog::filterExpressionBuilder()

QgsDistanceArea myDa;
myDa.setSourceCrs( mLayer->crs().srsid() );
myDa.setEllipsoidalMode( QgisApp::instance()->mapCanvas()->mapRenderer()->hasCrsTransformEnabled() );
myDa.setEllipsoidalMode( QgisApp::instance()->mapCanvas()->mapSettings().hasCrsTransformEnabled() );
myDa.setEllipsoid( QgsProject::instance()->readEntry( "Measure", "/Ellipsoid", GEO_NONE ) );
dlg.setGeomCalculator( myDa );

@@ -587,7 +587,7 @@ void QgsAttributeTableDialog::setFilterExpression( QString filterString )
QgsDistanceArea myDa;

myDa.setSourceCrs( mLayer->crs().srsid() );
myDa.setEllipsoidalMode( QgisApp::instance()->mapCanvas()->mapRenderer()->hasCrsTransformEnabled() );
myDa.setEllipsoidalMode( QgisApp::instance()->mapCanvas()->mapSettings().hasCrsTransformEnabled() );
myDa.setEllipsoid( QgsProject::instance()->readEntry( "Measure", "/Ellipsoid", GEO_NONE ) );

// parse search string and build parsed tree
@@ -235,7 +235,7 @@ void QgsAttributeTypeDialog::editValueRelationExpression()

QgsDistanceArea myDa;
myDa.setSourceCrs( vl->crs().srsid() );
myDa.setEllipsoidalMode( QgisApp::instance()->mapCanvas()->mapRenderer()->hasCrsTransformEnabled() );
myDa.setEllipsoidalMode( QgisApp::instance()->mapCanvas()->mapSettings().hasCrsTransformEnabled() );
myDa.setEllipsoid( QgsProject::instance()->readEntry( "Measure", "/Ellipsoid", GEO_NONE ) );
dlg.setGeomCalculator( myDa );

@@ -168,7 +168,7 @@ void QgsBookmarks::addClicked()
query.bindValue( ":ymin", canvas->extent().yMinimum() );
query.bindValue( ":xmax", canvas->extent().xMaximum() );
query.bindValue( ":ymax", canvas->extent().yMaximum() );
query.bindValue( ":projection_srid", QVariant::fromValue( canvas->mapRenderer()->destinationCrs().srsid() ) );
query.bindValue( ":projection_srid", QVariant::fromValue( canvas->mapSettings().destinationCrs().srsid() ) );
if ( query.exec() )
{
model->setSort( 0, Qt::AscendingOrder );
@@ -235,10 +235,10 @@ void QgsBookmarks::zoomToBookmark()

// backwards compatibility, older version had -1 in the srid column
if ( srid > 0 &&
srid != QgisApp::instance()->mapCanvas()->mapRenderer()->destinationCrs().srsid() )
srid != QgisApp::instance()->mapCanvas()->mapSettings().destinationCrs().srsid() )
{
QgsCoordinateTransform ct( QgsCoordinateReferenceSystem( srid, QgsCoordinateReferenceSystem::InternalCrsId ),
QgisApp::instance()->mapCanvas()->mapRenderer()->destinationCrs() );
QgisApp::instance()->mapCanvas()->mapSettings().destinationCrs() );
rect = ct.transform( rect );
if ( rect.isEmpty() )
{
@@ -565,7 +565,7 @@ void QgsBrowserDockWidget::showProperties( )
if ( defaultProjectionOption == "prompt" )
{
QgsCoordinateReferenceSystem defaultCrs =
QgisApp::instance()->mapCanvas()->mapRenderer()->destinationCrs();
QgisApp::instance()->mapCanvas()->mapSettings().destinationCrs();
if ( layerCrs == defaultCrs )
ui.lblNotice->setText( "NOTICE: Layer srs set from project (" + defaultCrs.authid() + ")" );
}
@@ -751,7 +751,7 @@ void QgsDecorationGrid::checkMapUnitsChanged()
// this is to avoid problems when CRS changes to/from geographic and projected
// a better solution would be to change the grid interval, but this is a little tricky
// note: we could be less picky (e.g. from degrees to DMS)
QGis::UnitType mapUnits = QgisApp::instance()->mapCanvas()->mapRenderer()->mapUnits();
QGis::UnitType mapUnits = QgisApp::instance()->mapCanvas()->mapSettings().mapUnits();
if ( mEnabled && ( mMapUnits != mapUnits ) )
{
mEnabled = false;
@@ -768,7 +768,7 @@ bool QgsDecorationGrid::isDirty()
// checks if stored map units is undefined or different from canvas map units
// or if interval is 0
if ( mMapUnits == QGis::UnknownUnit ||
mMapUnits != QgisApp::instance()->mapCanvas()->mapRenderer()->mapUnits() ||
mMapUnits != QgisApp::instance()->mapCanvas()->mapSettings().mapUnits() ||
mGridIntervalX == 0 || mGridIntervalY == 0 )
return true;
return false;
@@ -782,7 +782,7 @@ void QgsDecorationGrid::setDirty( bool dirty )
}
else
{
mMapUnits = QgisApp::instance()->mapCanvas()->mapRenderer()->mapUnits();
mMapUnits = QgisApp::instance()->mapCanvas()->mapSettings().mapUnits();
}
}

@@ -837,7 +837,7 @@ bool QgsDecorationGrid::getIntervalFromCurrentLayer( double* values )
}
const QgsCoordinateReferenceSystem& layerCRS = layer->crs();
const QgsCoordinateReferenceSystem& mapCRS =
QgisApp::instance()->mapCanvas()->mapRenderer()->destinationCrs();
QgisApp::instance()->mapCanvas()->mapSettings().destinationCrs();
// is this the best way to compare CRS? should we also make sure map has OTF enabled?
// TODO calculate transformed values if necessary
if ( layerCRS != mapCRS )
@@ -209,7 +209,7 @@ bool QgsDecorationNorthArrow::calculateNorthDirection()
// If no layers are added or shown, we can't get any direction
if ( mapCanvas->layerCount() > 0 && ! extent.isEmpty() )
{
QgsCoordinateReferenceSystem outputCRS = mapCanvas->mapRenderer()->destinationCrs();
QgsCoordinateReferenceSystem outputCRS = mapCanvas->mapSettings().destinationCrs();

if ( outputCRS.isValid() && !outputCRS.geographicFlag() )
{

0 comments on commit 9fb6a1c

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