Skip to content
Permalink
Browse files

[composer] Closer cropping to content for map items

Sponsored by NIWA
  • Loading branch information
nyalldawson committed Sep 25, 2015
1 parent dce9da1 commit abf4e121813408a9c4c7104929b5bfd5d2addf12
@@ -100,9 +100,22 @@ class QgsComposerMapGridStack : QgsComposerMapItemStack
/** Calculates the maximum distance grids within the stack extend
* beyond the QgsComposerMap's item rect
* @returns maximum grid extension
* @see calculateMaxGridExtension()
*/
double maxGridExtension() const;

/** Calculates the maximum distance grids within the stack extend beyond the
* QgsComposerMap's item rect. This method calculates the distance for each side of the
* map item seperately
* @param top storage for top extension
* @param right storage for right extension
* @param bottom storage for bottom extension
* @param left storage for left extension
* @note added in QGIS 2.12
* @see maxGridExtension()
*/
void calculateMaxGridExtension( double& top, double& right, double& bottom, double& left ) const;

};

//
@@ -286,7 +299,20 @@ class QgsComposerMapGrid : QgsComposerMapItem
* item rect
* @returns maximum extension in millimetres
*/
double maxExtension() const;
double maxExtension();

/** Calculates the maximum distance the grid extends beyond the
* QgsComposerMap's item rect. This method calculates the distance for each side of the
* map item seperately
* @param top storage for top extension
* @param right storage for right extension
* @param bottom storage for bottom extension
* @param left storage for left extension
* @note added in QGIS 2.12
* @see maxExtension()
*/
void calculateMaxExtension( double& top, double& right, double& bottom, double& left );


//
// GRID UNITS
@@ -807,6 +807,7 @@ void QgsComposerMapWidget::handleChangedFrameDisplay( QgsComposerMapGrid::Border
mComposerMap->beginCommand( tr( "Frame divisions changed" ) );
grid->setFrameDivisions( mode, border );
mComposerMap->endCommand();
mComposerMap->updateBoundingRect();
}

void QgsComposerMapWidget::handleChangedAnnotationDisplay( QgsComposerMapGrid::BorderSide border, const QString &text )
@@ -1677,6 +1678,7 @@ void QgsComposerMapWidget::on_mFrameWidthSpinBox_valueChanged( double val )

mComposerMap->beginCommand( tr( "Frame width changed" ) );
grid->setFrameWidth( val );
mComposerMap->updateBoundingRect();
mComposerMap->update();
mComposerMap->endCommand();
}
@@ -1691,6 +1693,7 @@ void QgsComposerMapWidget::on_mCheckGridLeftSide_toggled( bool checked )

mComposerMap->beginCommand( tr( "Frame left side changed" ) );
grid->setFrameSideFlag( QgsComposerMapGrid::FrameLeft, checked );
mComposerMap->updateBoundingRect();
mComposerMap->update();
mComposerMap->endCommand();
}
@@ -1705,6 +1708,7 @@ void QgsComposerMapWidget::on_mCheckGridRightSide_toggled( bool checked )

mComposerMap->beginCommand( tr( "Frame right side changed" ) );
grid->setFrameSideFlag( QgsComposerMapGrid::FrameRight, checked );
mComposerMap->updateBoundingRect();
mComposerMap->update();
mComposerMap->endCommand();
}
@@ -1719,6 +1723,7 @@ void QgsComposerMapWidget::on_mCheckGridTopSide_toggled( bool checked )

mComposerMap->beginCommand( tr( "Frame top side changed" ) );
grid->setFrameSideFlag( QgsComposerMapGrid::FrameTop, checked );
mComposerMap->updateBoundingRect();
mComposerMap->update();
mComposerMap->endCommand();
}
@@ -1733,6 +1738,7 @@ void QgsComposerMapWidget::on_mCheckGridBottomSide_toggled( bool checked )

mComposerMap->beginCommand( tr( "Frame bottom side changed" ) );
grid->setFrameSideFlag( QgsComposerMapGrid::FrameBottom, checked );
mComposerMap->updateBoundingRect();
mComposerMap->update();
mComposerMap->endCommand();
}
@@ -1956,6 +1962,7 @@ void QgsComposerMapWidget::on_mGridTypeComboBox_currentIndexChanged( const QStri
mGridBlendLabel->setVisible( false );
}

mComposerMap->updateBoundingRect();
mComposerMap->update();
mComposerMap->endCommand();
}
@@ -1978,6 +1985,7 @@ void QgsComposerMapWidget::on_mMapGridCRSButton_clicked()
mComposerMap->beginCommand( tr( "Grid CRS changed" ) );
QString selectedAuthId = crsDialog.selectedAuthId();
grid->setCrs( QgsCoordinateReferenceSystem( selectedAuthId ) );
mComposerMap->updateBoundingRect();
mMapGridCRSButton->setText( selectedAuthId );
mComposerMap->endCommand();
}
@@ -2000,14 +2000,24 @@ void QgsComposerMap::updateBoundingRect()
{
QRectF rectangle = rect();
double frameExtension = mFrame ? pen().widthF() / 2.0 : 0.0;
double maxGridExtension = mGridStack ? mGridStack->maxGridExtension() : 0;

double maxExtension = qMax( frameExtension, maxGridExtension );
double topExtension = 0.0;
double rightExtension = 0.0;
double bottomExtension = 0.0;
double leftExtension = 0.0;

rectangle.setLeft( rectangle.left() - maxExtension );
rectangle.setRight( rectangle.right() + maxExtension );
rectangle.setTop( rectangle.top() - maxExtension );
rectangle.setBottom( rectangle.bottom() + maxExtension );
if ( mGridStack )
mGridStack->calculateMaxGridExtension( topExtension, rightExtension, bottomExtension, leftExtension );

topExtension = qMax( topExtension, frameExtension );
rightExtension = qMax( rightExtension, frameExtension );
bottomExtension = qMax( bottomExtension, frameExtension );
leftExtension = qMax( leftExtension, frameExtension );

rectangle.setLeft( rectangle.left() - leftExtension );
rectangle.setRight( rectangle.right() + rightExtension );
rectangle.setTop( rectangle.top() - topExtension );
rectangle.setBottom( rectangle.bottom() + bottomExtension );
if ( rectangle != mCurrentRectangle )
{
prepareGeometryChange();

0 comments on commit abf4e12

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