@@ -42,7 +42,7 @@ QgsComposerMap::QgsComposerMap( QgsComposition *composition, int x, int y, int w
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 ),
45- mTopGridAnnotationDirection( Horizontal ), mBottomGridAnnotationDirection( Horizontal ),
45+ mTopGridAnnotationDirection( Horizontal ), mBottomGridAnnotationDirection( Horizontal ), mGridFrameStyle( NoGridFrame ), mGridFrameWidth( 2.0 ),
4646 mCrossLength( 3 ), mMapCanvas( 0 ), mDrawCanvasItems( true )
4747{
4848 mComposition = composition;
@@ -89,7 +89,7 @@ QgsComposerMap::QgsComposerMap( QgsComposition *composition )
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 ),
92- mTopGridAnnotationDirection( Horizontal ), mBottomGridAnnotationDirection( Horizontal ), mCrossLength( 3 ),
92+ mTopGridAnnotationDirection( Horizontal ), mBottomGridAnnotationDirection( Horizontal ), mGridFrameStyle( NoGridFrame ), mGridFrameWidth( 2.0 ), mCrossLength( 3 ),
9393 mMapCanvas( 0 ), mDrawCanvasItems( true )
9494{
9595 // Offset
@@ -960,12 +960,79 @@ void QgsComposerMap::drawGrid( QPainter* p )
960960
961961 p->setClipRect ( thisPaintRect , Qt::NoClip );
962962
963+ if ( mGridFrameStyle != QgsComposerMap::NoGridFrame )
964+ {
965+ drawGridFrame ( p, horizontalLines, verticalLines );
966+ }
967+
963968 if ( mShowGridAnnotation )
964969 {
965970 drawCoordinateAnnotations ( p, horizontalLines, verticalLines );
966971 }
967972}
968973
974+ void QgsComposerMap::drawGridFrame ( QPainter* p, const QList< QPair< double , QLineF > >& hLines, const QList< QPair< double , QLineF > >& vLines )
975+ {
976+ // Sort the coordinate positions for each side
977+ QMap< double , double > leftGridFrame;
978+ QMap< double , double > rightGridFrame;
979+ QMap< double , double > topGridFrame;
980+ QMap< double , double > bottomGridFrame;
981+
982+ sortGridLinesOnBorders ( hLines, vLines, leftGridFrame, rightGridFrame, topGridFrame, bottomGridFrame );
983+
984+ drawGridFrameBorder ( p, leftGridFrame, QgsComposerMap::Left );
985+ drawGridFrameBorder ( p, rightGridFrame, QgsComposerMap::Right );
986+ drawGridFrameBorder ( p, topGridFrame, QgsComposerMap::Top );
987+ drawGridFrameBorder ( p, bottomGridFrame, QgsComposerMap::Bottom );
988+ }
989+
990+ void QgsComposerMap::drawGridFrameBorder ( QPainter* p, const QMap< double , double >& borderPos, Border border )
991+ {
992+ double currentCoord = - mGridFrameWidth ;
993+ bool white = true ;
994+ double x = 0 ;
995+ double y = 0 ;
996+ double width = 0 ;
997+ double height = 0 ;
998+
999+ QMap< double , double > pos = borderPos;
1000+ pos.insert ( 0 , 0 );
1001+ if ( border == Left || border == Right )
1002+ {
1003+ pos.insert ( rect ().height (), rect ().height () );
1004+ pos.insert ( rect ().height () + mGridFrameWidth , rect ().height () + mGridFrameWidth );
1005+ }
1006+ else // top or bottom
1007+ {
1008+ pos.insert ( rect ().width (), rect ().width () );
1009+ pos.insert ( rect ().width () + mGridFrameWidth , rect ().width () + mGridFrameWidth );
1010+ }
1011+
1012+ QMap< double , double >::const_iterator posIt = pos.constBegin ();
1013+ for ( ; posIt != pos.constEnd (); ++posIt )
1014+ {
1015+ p->setBrush ( QBrush ( white ? Qt::white : Qt::black ) );
1016+ if ( border == Left || border == Right )
1017+ {
1018+ height = posIt.key () - currentCoord;
1019+ width = mGridFrameWidth ;
1020+ x = ( border == Left ) ? -mGridFrameWidth : rect ().width ();
1021+ y = currentCoord;
1022+ }
1023+ else // top or bottom
1024+ {
1025+ height = mGridFrameWidth ;
1026+ width = posIt.key () - currentCoord;
1027+ x = currentCoord;
1028+ y = ( border == Top ) ? -mGridFrameWidth : rect ().height ();
1029+ }
1030+ p->drawRect ( QRectF ( x, y, width, height ) );
1031+ currentCoord = posIt.key ();
1032+ white = !white;
1033+ }
1034+ }
1035+
9691036void QgsComposerMap::drawCoordinateAnnotations ( QPainter* p, const QList< QPair< double , QLineF > >& hLines, const QList< QPair< double , QLineF > >& vLines )
9701037{
9711038 if ( !p )
@@ -1002,6 +1069,8 @@ void QgsComposerMap::drawCoordinateAnnotation( QPainter* p, const QPointF& pos,
10021069 double ypos = pos.y ();
10031070 int rotation = 0 ;
10041071
1072+ double gridFrameDistance = ( mGridFrameStyle == NoGridFrame ) ? 0 : mGridFrameWidth ;
1073+
10051074 if ( frameBorder == Left )
10061075 {
10071076
@@ -1023,13 +1092,13 @@ void QgsComposerMap::drawCoordinateAnnotation( QPainter* p, const QPointF& pos,
10231092 {
10241093 if ( mLeftGridAnnotationDirection == Vertical || mLeftGridAnnotationDirection == BoundaryDirection )
10251094 {
1026- xpos -= mAnnotationFrameDistance ;
1095+ xpos -= ( mAnnotationFrameDistance + gridFrameDistance ) ;
10271096 ypos += textWidth / 2.0 ;
10281097 rotation = 270 ;
10291098 }
10301099 else
10311100 {
1032- xpos -= textWidth + mAnnotationFrameDistance ;
1101+ xpos -= ( textWidth + mAnnotationFrameDistance + gridFrameDistance ) ;
10331102 ypos += textHeight / 2.0 ;
10341103 }
10351104 }
@@ -1059,13 +1128,13 @@ void QgsComposerMap::drawCoordinateAnnotation( QPainter* p, const QPointF& pos,
10591128 {
10601129 if ( mRightGridAnnotationDirection == Vertical || mRightGridAnnotationDirection == BoundaryDirection )
10611130 {
1062- xpos += textHeight + mAnnotationFrameDistance ;
1131+ xpos += ( textHeight + mAnnotationFrameDistance + gridFrameDistance ) ;
10631132 ypos += textWidth / 2.0 ;
10641133 rotation = 270 ;
10651134 }
10661135 else // Horizontal
10671136 {
1068- xpos += mAnnotationFrameDistance ;
1137+ xpos += ( mAnnotationFrameDistance + gridFrameDistance ) ;
10691138 ypos += textHeight / 2.0 ;
10701139 }
10711140 }
@@ -1094,13 +1163,13 @@ void QgsComposerMap::drawCoordinateAnnotation( QPainter* p, const QPointF& pos,
10941163 {
10951164 if ( mBottomGridAnnotationDirection == Horizontal || mBottomGridAnnotationDirection == BoundaryDirection )
10961165 {
1097- ypos += mAnnotationFrameDistance + textHeight;
1166+ ypos += ( mAnnotationFrameDistance + textHeight + gridFrameDistance ) ;
10981167 xpos -= textWidth / 2.0 ;
10991168 }
11001169 else // Vertical
11011170 {
11021171 xpos += textHeight / 2.0 ;
1103- ypos += textWidth + mAnnotationFrameDistance ;
1172+ ypos += ( textWidth + mAnnotationFrameDistance + gridFrameDistance ) ;
11041173 rotation = 270 ;
11051174 }
11061175 }
@@ -1130,12 +1199,12 @@ void QgsComposerMap::drawCoordinateAnnotation( QPainter* p, const QPointF& pos,
11301199 if ( mTopGridAnnotationDirection == Horizontal || mTopGridAnnotationDirection == BoundaryDirection )
11311200 {
11321201 xpos -= textWidth / 2.0 ;
1133- ypos -= mAnnotationFrameDistance ;
1202+ ypos -= ( mAnnotationFrameDistance + gridFrameDistance ) ;
11341203 }
11351204 else // Vertical
11361205 {
11371206 xpos += textHeight / 2.0 ;
1138- ypos -= mAnnotationFrameDistance ;
1207+ ypos -= ( mAnnotationFrameDistance + gridFrameDistance ) ;
11391208 rotation = 270 ;
11401209 }
11411210 }
@@ -1389,7 +1458,9 @@ double QgsComposerMap::maxExtension() const
13891458 maxExtension = qMax ( maxExtension, currentExtension );
13901459 }
13911460
1392- return maxExtension + mAnnotationFrameDistance ;
1461+ // grid frame
1462+ double gridFrameDist = ( mGridFrameStyle == NoGridFrame ) ? 0 : mGridFrameWidth ;
1463+ return maxExtension + mAnnotationFrameDistance + gridFrameDist;
13931464}
13941465
13951466void QgsComposerMap::mapPolygon ( QPolygonF& poly ) const
@@ -1729,3 +1800,45 @@ QgsComposerMap::GridAnnotationDirection QgsComposerMap::gridAnnotationDirection(
17291800 break ;
17301801 }
17311802}
1803+
1804+ void QgsComposerMap::sortGridLinesOnBorders ( const QList< QPair< double , QLineF > >& hLines, const QList< QPair< double , QLineF > >& vLines, QMap< double , double >& leftFrameEntries,
1805+ QMap< double , double >& rightFrameEntries, QMap< double , double >& topFrameEntries, QMap< double , double >& bottomFrameEntries ) const
1806+ {
1807+ QList< QPair< double , QPointF > > borderPositions;
1808+ QList< QPair< double , QLineF > >::const_iterator it = hLines.constBegin ();
1809+ for ( ; it != hLines.constEnd (); ++it )
1810+ {
1811+ borderPositions << qMakePair ( it->first , it->second .p1 () );
1812+ borderPositions << qMakePair ( it->first , it->second .p2 () );
1813+ }
1814+ it = vLines.constBegin ();
1815+ for ( ; it != vLines.constEnd (); ++it )
1816+ {
1817+ borderPositions << qMakePair ( it->first , it->second .p1 () );
1818+ borderPositions << qMakePair ( it->first , it->second .p2 () );
1819+ }
1820+
1821+ QList< QPair< double , QPointF > >::const_iterator bIt = borderPositions.constBegin ();
1822+ for ( ; bIt != borderPositions.constEnd (); ++bIt )
1823+ {
1824+ Border frameBorder = borderForLineCoord ( bIt->second );
1825+ if ( frameBorder == QgsComposerMap::Left )
1826+ {
1827+ leftFrameEntries.insert ( bIt->second .y (), bIt->first );
1828+ }
1829+ else if ( frameBorder == QgsComposerMap::Right )
1830+ {
1831+ rightFrameEntries.insert ( bIt->second .y (), bIt->first );
1832+ }
1833+ else if ( frameBorder == QgsComposerMap::Top )
1834+ {
1835+ topFrameEntries.insert ( bIt->second .x (), bIt->first );
1836+ }
1837+ else // Bottom
1838+ {
1839+ bottomFrameEntries.insert ( bIt->second .x (), bIt->first );
1840+ }
1841+ }
1842+ }
1843+
1844+
0 commit comments