Expand Up
@@ -86,10 +86,7 @@ QgsComposerMap::QgsComposerMap( QgsComposition *composition, int x, int y, int w
// calculate mExtent based on width/height ratio and map canvas extent
if ( mMapRenderer )
{
QgsRectangle mapExtent = mMapRenderer ->extent ();
// make extent make item shape while keeping centre unchanged
adjustExtentToItemShape ( width, height, mapExtent );
mExtent = mapExtent;
mExtent = mMapRenderer ->extent ();
}
setSceneRect ( QRectF ( x, y, width, height ) );
setToolTip ( tr ( " Map %1" ).arg ( mId ) );
Expand Down
Expand Up
@@ -154,28 +151,6 @@ void QgsComposerMap::adjustExtentToItemShape( double itemWidth, double itemHeigh
}
}
void QgsComposerMap::extentCenteredOnOverview ( QgsRectangle& extent ) const
{
extent = mExtent ;
if ( ! mOverviewCentered )
{
return ;
}
if ( mOverviewFrameMapId != -1 )
{
const QgsComposerMap* overviewFrameMap = mComposition ->getComposerMapById ( mOverviewFrameMapId );
QgsRectangle otherExtent = overviewFrameMap->extent ();
QgsPoint center = otherExtent.center ();
QgsRectangle movedExtent ( center.x () - mExtent .width () / 2 ,
center.y () - mExtent .height () / 2 ,
center.x () - mExtent .width () / 2 + mExtent .width (),
center.y () - mExtent .height () / 2 + mExtent .height () );
extent = movedExtent;
}
}
QgsComposerMap::~QgsComposerMap ()
{
delete mOverviewFrameMapSymbol ;
Expand Down
Expand Up
@@ -312,7 +287,7 @@ void QgsComposerMap::cache( void )
mCacheImage .fill ( QColor ( 255 , 255 , 255 , 0 ).rgba () );
}
double mapUnitsPerPixel = mExtent . width () / w;
double mapUnitsPerPixel = currentMapExtent ()-> width () / w;
// WARNING: ymax in QgsMapToPixel is device height!!!
QgsMapToPixel transform ( mapUnitsPerPixel, h, requestExtent.yMinimum (), requestExtent.xMinimum () );
Expand Down
Expand Up
@@ -360,16 +335,15 @@ void QgsComposerMap::paint( QPainter* painter, const QStyleOptionGraphicsItem* i
QgsRectangle requestRectangle;
requestedExtent ( requestRectangle );
QgsRectangle cExtent;
extentCenteredOnOverview ( cExtent );
QgsRectangle cExtent = *currentMapExtent ();
double horizontalVScaleFactor = horizontalViewScaleFactor ();
if ( horizontalVScaleFactor < 0 )
{
horizontalVScaleFactor = mLastValidViewScaleFactor ;
}
double imagePixelWidth = mExtent .width () / requestRectangle.width () * mCacheImage .width () ; // how many pixels of the image are for the map extent?
double imagePixelWidth = cExtent .width () / requestRectangle.width () * mCacheImage .width () ; // how many pixels of the image are for the map extent?
double scale = rect ().width () / imagePixelWidth;
QgsPoint rotationPoint = QgsPoint (( cExtent.xMaximum () + cExtent.xMinimum () ) / 2.0 , ( cExtent.yMaximum () + cExtent.yMinimum () ) / 2.0 );
Expand Down
Expand Up
@@ -417,8 +391,7 @@ void QgsComposerMap::paint( QPainter* painter, const QStyleOptionGraphicsItem* i
QgsRectangle requestRectangle;
requestedExtent ( requestRectangle );
QgsRectangle cExtent;
extentCenteredOnOverview ( cExtent );
QgsRectangle cExtent = *currentMapExtent ();
QSizeF theSize ( requestRectangle.width () * mapUnitsToMM (), requestRectangle.height () * mapUnitsToMM () );
Expand Down
Expand Up
@@ -492,7 +465,7 @@ double QgsComposerMap::scale() const
QgsScaleCalculator calculator;
calculator.setMapUnits ( mMapRenderer ->mapUnits () );
calculator.setDpi ( 25.4 ); // QGraphicsView units are mm
return calculator.calculate ( mExtent , rect ().width () );
return calculator.calculate ( * currentMapExtent () , rect ().width () );
}
void QgsComposerMap::resize ( double dx, double dy )
Expand All
@@ -509,10 +482,10 @@ void QgsComposerMap::moveContent( double dx, double dy )
if ( !mDrawing )
{
transformShift ( dx, dy );
mExtent . setXMinimum ( mExtent . xMinimum () + dx );
mExtent . setXMaximum ( mExtent . xMaximum () + dx );
mExtent . setYMinimum ( mExtent . yMinimum () + dy );
mExtent . setYMaximum ( mExtent . yMaximum () + dy );
currentMapExtent ()-> setXMinimum ( currentMapExtent ()-> xMinimum () + dx );
currentMapExtent ()-> setXMaximum ( currentMapExtent ()-> xMaximum () + dx );
currentMapExtent ()-> setYMinimum ( currentMapExtent ()-> yMinimum () + dy );
currentMapExtent ()-> setYMaximum ( currentMapExtent ()-> yMaximum () + dy );
cache ();
update ();
emit itemChanged ();
Expand Down
Expand Up
@@ -540,14 +513,14 @@ void QgsComposerMap::zoomContent( int delta, double x, double y )
double zoomFactor = settings.value ( " /qgis/zoom_factor" , 2.0 ).toDouble ();
// find out new center point
double centerX = ( mExtent . xMaximum () + mExtent . xMinimum () ) / 2 ;
double centerY = ( mExtent . yMaximum () + mExtent . yMinimum () ) / 2 ;
double centerX = ( currentMapExtent ()-> xMaximum () + currentMapExtent ()-> xMinimum () ) / 2 ;
double centerY = ( currentMapExtent ()-> yMaximum () + currentMapExtent ()-> yMinimum () ) / 2 ;
if ( zoomMode != 0 )
{
// find out map coordinates of mouse position
double mapMouseX = mExtent . xMinimum () + ( x / rect ().width () ) * ( mExtent . xMaximum () - mExtent . xMinimum () );
double mapMouseY = mExtent . yMinimum () + ( 1 - ( y / rect ().height () ) ) * ( mExtent . yMaximum () - mExtent . yMinimum () );
double mapMouseX = currentMapExtent ()-> xMinimum () + ( x / rect ().width () ) * ( currentMapExtent ()-> xMaximum () - currentMapExtent ()-> xMinimum () );
double mapMouseY = currentMapExtent ()-> yMinimum () + ( 1 - ( y / rect ().height () ) ) * ( currentMapExtent ()-> yMaximum () - currentMapExtent ()-> yMinimum () );
if ( zoomMode == 1 ) // zoom and recenter
{
centerX = mapMouseX;
Expand All
@@ -564,23 +537,23 @@ void QgsComposerMap::zoomContent( int delta, double x, double y )
if ( delta > 0 )
{
newIntervalX = ( mExtent . xMaximum () - mExtent . xMinimum () ) / zoomFactor;
newIntervalY = ( mExtent . yMaximum () - mExtent . yMinimum () ) / zoomFactor;
newIntervalX = ( currentMapExtent ()-> xMaximum () - currentMapExtent ()-> xMinimum () ) / zoomFactor;
newIntervalY = ( currentMapExtent ()-> yMaximum () - currentMapExtent ()-> yMinimum () ) / zoomFactor;
}
else if ( delta < 0 )
{
newIntervalX = ( mExtent . xMaximum () - mExtent . xMinimum () ) * zoomFactor;
newIntervalY = ( mExtent . yMaximum () - mExtent . yMinimum () ) * zoomFactor;
newIntervalX = ( currentMapExtent ()-> xMaximum () - currentMapExtent ()-> xMinimum () ) * zoomFactor;
newIntervalY = ( currentMapExtent ()-> yMaximum () - currentMapExtent ()-> yMinimum () ) * zoomFactor;
}
else // no need to zoom
{
return ;
}
mExtent . setXMaximum ( centerX + newIntervalX / 2 );
mExtent . setXMinimum ( centerX - newIntervalX / 2 );
mExtent . setYMaximum ( centerY + newIntervalY / 2 );
mExtent . setYMinimum ( centerY - newIntervalY / 2 );
currentMapExtent ()-> setXMaximum ( centerX + newIntervalX / 2 );
currentMapExtent ()-> setXMinimum ( centerX - newIntervalX / 2 );
currentMapExtent ()-> setYMaximum ( centerY + newIntervalY / 2 );
currentMapExtent ()-> setYMinimum ( centerY - newIntervalY / 2 );
cache ();
update ();
Expand Down
Expand Up
@@ -624,6 +597,83 @@ void QgsComposerMap::setNewExtent( const QgsRectangle& extent )
updateItem ();
}
void QgsComposerMap::setNewAtlasFeatureExtent ( const QgsRectangle& extent )
{
if ( mAtlasFeatureExtent == extent )
{
return ;
}
// don't adjust size of item, instead adjust size of bounds to fit
QgsRectangle newExtent = extent;
// Make sure the width/height ratio is the same as the map item size
double currentWidthHeightRatio = rect ().width () / rect ().height ();
double newWidthHeightRatio = newExtent.width () / newExtent.height ();
if ( currentWidthHeightRatio < newWidthHeightRatio )
{
// enlarge height of new extent, ensuring the map center stays the same
double newHeight = newExtent.width () / currentWidthHeightRatio;
double deltaHeight = newHeight - newExtent.height ();
newExtent.setYMinimum ( extent.yMinimum () - deltaHeight / 2 );
newExtent.setYMaximum ( extent.yMaximum () + deltaHeight / 2 );
}
else if ( currentWidthHeightRatio >= newWidthHeightRatio )
{
// enlarge width of new extent, ensuring the map center stays the same
double newWidth = currentWidthHeightRatio * newExtent.height ();
double deltaWidth = newWidth - newExtent.width ();
newExtent.setXMinimum ( extent.xMinimum () - deltaWidth / 2 );
newExtent.setXMaximum ( extent.xMaximum () + deltaWidth / 2 );
}
mAtlasFeatureExtent = newExtent;
mCacheUpdated = false ;
updateItem ();
emit itemChanged ();
emit extentChanged ();
}
QgsRectangle* QgsComposerMap::currentMapExtent ()
{
// non-const version
QgsAtlasComposition* atlasMap = &mComposition ->atlasComposition ();
if ( atlasMap->enabled () && atlasMap->composerMap () == this &&
( mComposition ->atlasPreviewEnabled () || mComposition ->plotStyle () != QgsComposition::Preview ) )
{
// if atlas is enabled, and we are either exporting the composition or previewing the atlas, then
// return the current temporary atlas feature extent
return &mAtlasFeatureExtent ;
}
else
{
// otherwise return permenant user set extent
return &mExtent ;
}
}
const QgsRectangle* QgsComposerMap::currentMapExtent () const
{
// const version
QgsAtlasComposition* atlasMap = &mComposition ->atlasComposition ();
if ( atlasMap->enabled () && atlasMap->composerMap () == this &&
( mComposition ->atlasPreviewEnabled () || mComposition ->plotStyle () != QgsComposition::Preview ) )
{
// if atlas is enabled, and we are either exporting the composition or previewing the atlas, then
// return the current temporary atlas feature extent
return &mAtlasFeatureExtent ;
}
else
{
// otherwise return permenant user set extent
return &mExtent ;
}
}
void QgsComposerMap::setNewScale ( double scaleDenominator )
{
double currentScaleDenominator = scale ();
Expand All
@@ -634,7 +684,7 @@ void QgsComposerMap::setNewScale( double scaleDenominator )
}
double scaleRatio = scaleDenominator / currentScaleDenominator;
mExtent . scale ( scaleRatio );
currentMapExtent ()-> scale ( scaleRatio );
mCacheUpdated = false ;
cache ();
update ();
Expand Down
Expand Up
@@ -1844,7 +1894,7 @@ QgsRectangle QgsComposerMap::transformedExtent() const
double dx = mXOffset ;
double dy = mYOffset ;
transformShift ( dx, dy );
return QgsRectangle ( mExtent . xMinimum () - dx, mExtent . yMinimum () - dy, mExtent . xMaximum () - dx, mExtent . yMaximum () - dy );
return QgsRectangle ( currentMapExtent ()-> xMinimum () - dx, currentMapExtent ()-> yMinimum () - dy, currentMapExtent ()-> xMaximum () - dx, currentMapExtent ()-> yMaximum () - dy );
}
QPolygonF QgsComposerMap::transformedMapPolygon () const
Expand Down
Expand Up
@@ -1951,13 +2001,12 @@ void QgsComposerMap::mapPolygon( const QgsRectangle& extent, QPolygonF& poly ) c
void QgsComposerMap::mapPolygon ( QPolygonF& poly ) const
{
return mapPolygon ( mExtent , poly );
return mapPolygon ( * currentMapExtent () , poly );
}
void QgsComposerMap::requestedExtent ( QgsRectangle& extent ) const
{
QgsRectangle newExtent;
extentCenteredOnOverview ( newExtent );
QgsRectangle newExtent = *currentMapExtent ();
if ( mMapRotation == 0 )
{
extent = newExtent;
Expand All
@@ -1976,7 +2025,7 @@ void QgsComposerMap::requestedExtent( QgsRectangle& extent ) const
double QgsComposerMap::mapUnitsToMM () const
{
double extentWidth = mExtent . width ();
double extentWidth = currentMapExtent ()-> width ();
if ( extentWidth <= 0 )
{
return 1 ;
Expand All
@@ -1991,7 +2040,7 @@ void QgsComposerMap::setOverviewFrameMap( int mapId )
const QgsComposerMap* map = mComposition ->getComposerMapById ( mapId );
if ( map )
{
QObject::disconnect ( map, SIGNAL ( extentChanged () ), this , SLOT ( repaint () ) );
QObject::disconnect ( map, SIGNAL ( extentChanged () ), this , SLOT ( overviewExtentChanged () ) );
}
}
mOverviewFrameMapId = mapId;
Expand All
@@ -2000,12 +2049,39 @@ void QgsComposerMap::setOverviewFrameMap( int mapId )
const QgsComposerMap* map = mComposition ->getComposerMapById ( mapId );
if ( map )
{
QObject::connect ( map, SIGNAL ( extentChanged () ), this , SLOT ( repaint () ) );
QObject::connect ( map, SIGNAL ( extentChanged () ), this , SLOT ( overviewExtentChanged () ) );
}
}
update ();
}
void QgsComposerMap::overviewExtentChanged ()
{
// if using overview centering, update the map's extent
if ( mOverviewCentered && mOverviewFrameMapId != -1 )
{
QgsRectangle extent = *currentMapExtent ();
const QgsComposerMap* overviewFrameMap = mComposition ->getComposerMapById ( mOverviewFrameMapId );
QgsRectangle otherExtent = *overviewFrameMap->currentMapExtent ();
QgsPoint center = otherExtent.center ();
QgsRectangle movedExtent ( center.x () - currentMapExtent ()->width () / 2 ,
center.y () - currentMapExtent ()->height () / 2 ,
center.x () - currentMapExtent ()->width () / 2 + currentMapExtent ()->width (),
center.y () - currentMapExtent ()->height () / 2 + currentMapExtent ()->height () );
*currentMapExtent () = movedExtent;
emit itemChanged ();
emit extentChanged ();
}
// redraw so that overview gets updated
cache ();
update ();
}
void QgsComposerMap::setOverviewFrameMapSymbol ( QgsFillSymbolV2* symbol )
{
delete mOverviewFrameMapSymbol ;
Expand All
@@ -2027,7 +2103,7 @@ void QgsComposerMap::setOverviewInverted( bool inverted )
void QgsComposerMap::setOverviewCentered ( bool centered )
{
mOverviewCentered = centered;
update ();
overviewExtentChanged ();
}
void QgsComposerMap::setGridLineSymbol ( QgsLineSymbolV2* symbol )
Expand Down
Expand Up
@@ -2125,7 +2201,7 @@ void QgsComposerMap::drawCanvasItem( QGraphicsItem* item, QPainter* painter, con
painter->save ();
QgsRectangle rendererExtent = mMapRenderer ->extent ();
QgsRectangle composerMapExtent = mExtent ;
QgsRectangle composerMapExtent = * currentMapExtent () ;
// determine scale factor according to graphics view dpi
double scaleFactor = 1.0 / mMapCanvas ->logicalDpiX () * 25.4 ;
Expand Down
Expand Up
@@ -2167,7 +2243,7 @@ QPointF QgsComposerMap::composerMapPosForItem( const QGraphicsItem* item ) const
return QPointF ( 0 , 0 );
}
if ( mExtent . height () <= 0 || mExtent . width () <= 0 || mMapCanvas ->width () <= 0 || mMapCanvas ->height () <= 0 )
if ( currentMapExtent ()-> height () <= 0 || currentMapExtent ()-> width () <= 0 || mMapCanvas ->width () <= 0 || mMapCanvas ->height () <= 0 )
{
return QPointF ( 0 , 0 );
}
Expand Down
Expand Up
@@ -2328,9 +2404,8 @@ void QgsComposerMap::drawOverviewMapExtent( QPainter* p )
return ;
}
QgsRectangle otherExtent = overviewFrameMap->extent ();
QgsRectangle thisExtent;
extentCenteredOnOverview ( thisExtent );
QgsRectangle otherExtent = *overviewFrameMap->currentMapExtent ();
QgsRectangle thisExtent = *currentMapExtent ();
QgsRectangle intersectRect = thisExtent.intersect ( &otherExtent );
QgsRenderContext context;
Expand Down