Skip to content

Commit

Permalink
Keep width and height of the composer map fixed if user sets the comp…
Browse files Browse the repository at this point in the history
…oser map extent to the map canvas extent

git-svn-id: http://svn.osgeo.org/qgis/trunk@10777 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
mhugent committed May 13, 2009
1 parent 524023d commit ece7a72
Showing 1 changed file with 25 additions and 6 deletions.
31 changes: 25 additions & 6 deletions src/app/composer/qgscomposermapwidget.cpp
Expand Up @@ -148,15 +148,34 @@ void QgsComposerMapWidget::on_mSetToMapCanvasExtentButton_clicked()
const QgsMapRenderer* renderer = mComposerMap->mapRenderer();
if ( renderer )
{
QgsRectangle canvasExtent = renderer->extent();
QgsRectangle newExtent = renderer->extent();

//Make sure the width/height ratio is the same as in current composer map extent.
//This is to keep the map item frame and the page layout fixed
QgsRectangle currentMapExtent = mComposerMap->extent();
double currentWidthHeightRatio = currentMapExtent.width() / currentMapExtent.height();
double newWidthHeightRatio = newExtent.width() / newExtent.height();

if(currentWidthHeightRatio < newWidthHeightRatio)
{
//enlarge height of new extent
double newHeight = newExtent.width() / currentWidthHeightRatio;
newExtent.setYMinimum(newExtent.yMaximum() - newHeight);
}
else if(currentWidthHeightRatio > newWidthHeightRatio)
{
//enlarge width of new extent
double newWidth = currentWidthHeightRatio * newExtent.height();
newExtent.setXMaximum(newExtent.xMinimum() + newWidth);
}

//fill text into line edits
mXMinLineEdit->setText( QString::number( canvasExtent.xMinimum() ) );
mXMaxLineEdit->setText( QString::number( canvasExtent.xMaximum() ) );
mYMinLineEdit->setText( QString::number( canvasExtent.yMinimum() ) );
mYMaxLineEdit->setText( QString::number( canvasExtent.yMaximum() ) );
mXMinLineEdit->setText( QString::number( newExtent.xMinimum() ) );
mXMaxLineEdit->setText( QString::number( newExtent.xMaximum() ) );
mYMinLineEdit->setText( QString::number( newExtent.yMinimum() ) );
mYMaxLineEdit->setText( QString::number( newExtent.yMaximum() ) );

mComposerMap->setNewExtent( canvasExtent );
mComposerMap->setNewExtent( newExtent );
}
}
}
Expand Down

0 comments on commit ece7a72

Please sign in to comment.