3838#include < cmath>
3939
4040QgsComposerMap::QgsComposerMap ( QgsComposition *composition, int x, int y, int width, int height )
41- : QgsComposerItem( x, y, width, height, composition ), mKeepLayerSet( false ), mOverviewFrameMap( 0 ), mGridEnabled( false ), mGridStyle( Solid ),
41+ : QgsComposerItem( x, y, width, height, composition ), mKeepLayerSet( false ), mOverviewFrameMapId( - 1 ), mGridEnabled( false ), mGridStyle( Solid ),
4242 mGridIntervalX( 0.0 ), mGridIntervalY( 0.0 ), mGridOffsetX( 0.0 ), mGridOffsetY( 0.0 ), mGridAnnotationPrecision( 3 ), mShowGridAnnotation( false ),
4343 mLeftGridAnnotationPosition( OutsideMapFrame ), mRightGridAnnotationPosition( OutsideMapFrame ), mTopGridAnnotationPosition( OutsideMapFrame ),
4444 mBottomGridAnnotationPosition( OutsideMapFrame ), mAnnotationFrameDistance( 1.0 ), mLeftGridAnnotationDirection( Horizontal ), mRightGridAnnotationDirection( Horizontal ),
@@ -85,7 +85,7 @@ QgsComposerMap::QgsComposerMap( QgsComposition *composition, int x, int y, int w
8585}
8686
8787QgsComposerMap::QgsComposerMap ( QgsComposition *composition )
88- : QgsComposerItem( 0 , 0 , 10 , 10 , composition ), mKeepLayerSet( false ), mOverviewFrameMap( 0 ), mGridEnabled( false ), mGridStyle( Solid ),
88+ : QgsComposerItem( 0 , 0 , 10 , 10 , composition ), mKeepLayerSet( false ), mOverviewFrameMapId( - 1 ), mGridEnabled( false ), mGridStyle( Solid ),
8989 mGridIntervalX( 0.0 ), mGridIntervalY( 0.0 ), mGridOffsetX( 0.0 ), mGridOffsetY( 0.0 ), mGridAnnotationPrecision( 3 ), mShowGridAnnotation( false ),
9090 mLeftGridAnnotationPosition( OutsideMapFrame ), mRightGridAnnotationPosition( OutsideMapFrame ), mTopGridAnnotationPosition( OutsideMapFrame ),
9191 mBottomGridAnnotationPosition( OutsideMapFrame ), mAnnotationFrameDistance( 1.0 ), mLeftGridAnnotationDirection( Horizontal ), mRightGridAnnotationDirection( Horizontal ),
@@ -364,7 +364,7 @@ void QgsComposerMap::paint( QPainter* painter, const QStyleOptionGraphicsItem* i
364364 drawSelectionBoxes ( painter );
365365 }
366366
367- if ( mOverviewFrameMap )
367+ if ( mOverviewFrameMapId != - 1 )
368368 {
369369 drawOverviewMapExtent ( painter );
370370 }
@@ -663,6 +663,9 @@ bool QgsComposerMap::writeXML( QDomElement& elem, QDomDocument & doc ) const
663663 composerMapElem.setAttribute ( " drawCanvasItems" , " false" );
664664 }
665665
666+ // overview map frame
667+ composerMapElem.setAttribute ( " overviewMapFrame" , mOverviewFrameMapId );
668+
666669 // extent
667670 QDomElement extentElem = doc.createElement ( " Extent" );
668671 extentElem.setAttribute ( " xmin" , QString::number ( mExtent .xMinimum () ) );
@@ -683,12 +686,8 @@ bool QgsComposerMap::writeXML( QDomElement& elem, QDomDocument & doc ) const
683686 }
684687 composerMapElem.appendChild ( layerSetElem );
685688
686- int overviewMapId = -1 ;
687- if ( mOverviewFrameMap )
688- {
689- overviewMapId = mOverviewFrameMap ->id ();
690- }
691- composerMapElem.setAttribute ( " overviewFrameMap" , overviewMapId );
689+ // overview map frame
690+ composerMapElem.setAttribute ( " overviewFrameMap" , mOverviewFrameMapId );
692691
693692 // grid
694693 QDomElement gridElem = doc.createElement ( " Grid" );
@@ -757,6 +756,8 @@ bool QgsComposerMap::readXML( const QDomElement& itemElem, const QDomDocument& d
757756 mPreviewMode = Rectangle;
758757 }
759758
759+ mOverviewFrameMapId = itemElem.attribute ( " overviewFrameMap" , " -1" ).toInt ();
760+
760761 // extent
761762 QDomNodeList extentNodeList = itemElem.elementsByTagName ( " Extent" );
762763 if ( extentNodeList.size () > 0 )
@@ -810,26 +811,6 @@ bool QgsComposerMap::readXML( const QDomElement& itemElem, const QDomDocument& d
810811 mNumCachedLayers = 0 ;
811812 mCacheUpdated = false ;
812813
813- // todo: overview frame map
814- #if 0
815- //rotation map
816- int rotationMapId = itemElem.attribute( "mapId", "-1" ).toInt();
817- if ( rotationMapId == -1 )
818- {
819- mRotationMap = 0;
820- }
821- else if ( mComposition )
822- {
823-
824- if ( mRotationMap )
825- {
826- QObject::disconnect( mRotationMap, SIGNAL( rotationChanged( double ) ), this, SLOT( setRotation( double ) ) );
827- }
828- mRotationMap = mComposition->getComposerMapById( rotationMapId );
829- QObject::connect( mRotationMap, SIGNAL( rotationChanged( double ) ), this, SLOT( setRotation( double ) ) );
830- }
831- #endif // 0
832-
833814 // grid
834815 QDomNodeList gridNodeList = itemElem.elementsByTagName ( " Grid" );
835816 if ( gridNodeList.size () > 0 )
@@ -1569,40 +1550,24 @@ double QgsComposerMap::mapUnitsToMM() const
15691550
15701551void QgsComposerMap::setOverviewFrameMap ( int mapId )
15711552{
1572- if ( !mComposition )
1573- {
1574- return ;
1575- }
1576-
1577- if ( mapId == -1 ) // disable overview map frame
1578- {
1579- QObject::disconnect ( mOverviewFrameMap , SIGNAL ( extentChanged () ), this , SLOT ( repaint () ) );
1580- mOverviewFrameMap = 0 ;
1581- }
1582-
1583- const QgsComposerMap* map = mComposition ->getComposerMapById ( mapId );
1584- if ( !map )
1553+ if ( mOverviewFrameMapId != -1 )
15851554 {
1586- return ;
1587- }
1588- if ( mOverviewFrameMap )
1589- {
1590- QObject::disconnect ( mOverviewFrameMap , SIGNAL ( extentChanged () ), this , SLOT ( repaint () ) );
1591- }
1592- QObject::connect ( mOverviewFrameMap , SIGNAL ( extentChanged () ), this , SLOT ( repaint () ) );
1593- mOverviewFrameMap = map;
1594- }
1595-
1596- int QgsComposerMap::overviewFrameMapId () const
1597- {
1598- if ( !mOverviewFrameMap )
1599- {
1600- return -1 ;
1555+ const QgsComposerMap* map = mComposition ->getComposerMapById ( mapId );
1556+ if ( map )
1557+ {
1558+ QObject::disconnect ( map, SIGNAL ( extentChanged () ), this , SLOT ( repaint () ) );
1559+ }
16011560 }
1602- else
1561+ mOverviewFrameMapId = mapId;
1562+ if ( mOverviewFrameMapId != -1 )
16031563 {
1604- return mOverviewFrameMap ->id ();
1564+ const QgsComposerMap* map = mComposition ->getComposerMapById ( mapId );
1565+ if ( map )
1566+ {
1567+ QObject::connect ( map, SIGNAL ( extentChanged () ), this , SLOT ( repaint () ) );
1568+ }
16051569 }
1570+ update ();
16061571}
16071572
16081573void QgsComposerMap::transformShift ( double & xShift, double & yShift ) const
@@ -1916,12 +1881,18 @@ void QgsComposerMap::sortGridLinesOnBorders( const QList< QPair< double, QLineF
19161881
19171882void QgsComposerMap::drawOverviewMapExtent ( QPainter* p )
19181883{
1919- if ( !mOverviewFrameMap )
1884+ if ( mOverviewFrameMapId == -1 )
1885+ {
1886+ return ;
1887+ }
1888+
1889+ const QgsComposerMap* overviewFrameMap = mComposition ->getComposerMapById ( mOverviewFrameMapId );
1890+ if ( !overviewFrameMap )
19201891 {
19211892 return ;
19221893 }
19231894
1924- QgsRectangle otherExtent = mOverviewFrameMap ->extent ();
1895+ QgsRectangle otherExtent = overviewFrameMap ->extent ();
19251896 QgsRectangle thisExtent = extent ();
19261897 QgsRectangle intersectRect = thisExtent.intersect ( &otherExtent );
19271898
0 commit comments