@@ -55,6 +55,8 @@ QgsComposerMapGrid::QgsComposerMapGrid( const QString& name, QgsComposerMap* map
5555 mBottomGridAnnotationDirection( QgsComposerMap::Horizontal ),
5656 mGridAnnotationFormat( QgsComposerMap::Decimal ),
5757 mGridFrameStyle( QgsComposerMap::NoGridFrame ),
58+ mGridFrameSides( QgsComposerMapGrid::FrameLeft | QgsComposerMapGrid::FrameRight |
59+ QgsComposerMapGrid::FrameTop | QgsComposerMapGrid::FrameBottom ),
5860 mGridFrameWidth( 2.0 ),
5961 mGridFramePenThickness( 0.5 ),
6062 mGridFramePenColor( QColor( 0 , 0 , 0 ) ),
@@ -176,6 +178,7 @@ bool QgsComposerMapGrid::writeXML( QDomElement& elem, QDomDocument& doc ) const
176178 mapGridElem.appendChild ( markerStyleElem );
177179
178180 mapGridElem.setAttribute ( " gridFrameStyle" , mGridFrameStyle );
181+ mapGridElem.setAttribute ( " gridFrameSideFlags" , mGridFrameSides );
179182 mapGridElem.setAttribute ( " gridFrameWidth" , qgsDoubleToString ( mGridFrameWidth ) );
180183 mapGridElem.setAttribute ( " gridFramePenThickness" , qgsDoubleToString ( mGridFramePenThickness ) );
181184 mapGridElem.setAttribute ( " gridFramePenColor" , QgsSymbolLayerV2Utils::encodeColor ( mGridFramePenColor ) );
@@ -227,6 +230,7 @@ bool QgsComposerMapGrid::readXML( const QDomElement& itemElem, const QDomDocumen
227230 mGridOffsetY = itemElem.attribute ( " offsetY" , " 0" ).toDouble ();
228231 mCrossLength = itemElem.attribute ( " crossLength" , " 3" ).toDouble ();
229232 mGridFrameStyle = ( QgsComposerMap::GridFrameStyle )itemElem.attribute ( " gridFrameStyle" , " 0" ).toInt ();
233+ mGridFrameSides = ( QgsComposerMapGrid::GridFrameSideFlags )itemElem.attribute ( " gridFrameSideFlags" , " 15" ).toInt ();
230234 mGridFrameWidth = itemElem.attribute ( " gridFrameWidth" , " 2.0" ).toDouble ();
231235 mGridFramePenThickness = itemElem.attribute ( " gridFramePenThickness" , " 0.5" ).toDouble ();
232236 mGridFramePenColor = QgsSymbolLayerV2Utils::decodeColor ( itemElem.attribute ( " gridFramePenColor" , " 0,0,0" ) );
@@ -531,11 +535,22 @@ void QgsComposerMapGrid::drawGridFrame( QPainter* p, const QList< QPair< double,
531535
532536 sortGridLinesOnBorders ( hLines, vLines, leftGridFrame, rightGridFrame, topGridFrame, bottomGridFrame );
533537
534- drawGridFrameBorder ( p, leftGridFrame, QgsComposerMap::Left );
535- drawGridFrameBorder ( p, rightGridFrame, QgsComposerMap::Right );
536- drawGridFrameBorder ( p, topGridFrame, QgsComposerMap::Top );
537- drawGridFrameBorder ( p, bottomGridFrame, QgsComposerMap::Bottom );
538-
538+ if ( testGridFrameSideFlag ( QgsComposerMapGrid::FrameLeft ) )
539+ {
540+ drawGridFrameBorder ( p, leftGridFrame, QgsComposerMap::Left );
541+ }
542+ if ( testGridFrameSideFlag ( QgsComposerMapGrid::FrameRight ) )
543+ {
544+ drawGridFrameBorder ( p, rightGridFrame, QgsComposerMap::Right );
545+ }
546+ if ( testGridFrameSideFlag ( QgsComposerMapGrid::FrameTop ) )
547+ {
548+ drawGridFrameBorder ( p, topGridFrame, QgsComposerMap::Top );
549+ }
550+ if ( testGridFrameSideFlag ( QgsComposerMapGrid::FrameBottom ) )
551+ {
552+ drawGridFrameBorder ( p, bottomGridFrame, QgsComposerMap::Bottom );
553+ }
539554 p->restore ();
540555}
541556
@@ -577,24 +592,40 @@ void QgsComposerMapGrid::drawGridFrameBorder( QPainter* p, const QMap< double, d
577592 return ;
578593 }
579594
580- double currentCoord = - mGridFrameWidth ;
595+ QMap< double , double > pos = borderPos;
596+
597+ double currentCoord = 0 ;
598+ if (( border == QgsComposerMap::Left || border == QgsComposerMap::Right ) && testGridFrameSideFlag ( QgsComposerMapGrid::FrameTop ) )
599+ {
600+ currentCoord = - mGridFrameWidth ;
601+ pos.insert ( 0 , 0 );
602+ }
603+ else if (( border == QgsComposerMap::Top || border == QgsComposerMap::Bottom ) && testGridFrameSideFlag ( QgsComposerMapGrid::FrameLeft ) )
604+ {
605+ currentCoord = - mGridFrameWidth ;
606+ pos.insert ( 0 , 0 );
607+ }
581608 bool color1 = true ;
582609 double x = 0 ;
583610 double y = 0 ;
584611 double width = 0 ;
585612 double height = 0 ;
586613
587- QMap< double , double > pos = borderPos;
588- pos.insert ( 0 , 0 );
589614 if ( border == QgsComposerMap::Left || border == QgsComposerMap::Right )
590615 {
591616 pos.insert ( mComposerMap ->rect ().height (), mComposerMap ->rect ().height () );
592- pos.insert ( mComposerMap ->rect ().height () + mGridFrameWidth , mComposerMap ->rect ().height () + mGridFrameWidth );
617+ if ( testGridFrameSideFlag ( QgsComposerMapGrid::FrameBottom ) )
618+ {
619+ pos.insert ( mComposerMap ->rect ().height () + mGridFrameWidth , mComposerMap ->rect ().height () + mGridFrameWidth );
620+ }
593621 }
594- else // top or bottom
622+ else if ( border == QgsComposerMap::Top || border == QgsComposerMap::Bottom )
595623 {
596624 pos.insert ( mComposerMap ->rect ().width (), mComposerMap ->rect ().width () );
597- pos.insert ( mComposerMap ->rect ().width () + mGridFrameWidth , mComposerMap ->rect ().width () + mGridFrameWidth );
625+ if ( testGridFrameSideFlag ( QgsComposerMapGrid::FrameRight ) )
626+ {
627+ pos.insert ( mComposerMap ->rect ().width () + mGridFrameWidth , mComposerMap ->rect ().width () + mGridFrameWidth );
628+ }
598629 }
599630
600631 // set pen to current frame pen
@@ -667,10 +698,14 @@ void QgsComposerMapGrid::drawCoordinateAnnotation( QPainter* p, const QPointF& p
667698 double ypos = pos.y ();
668699 int rotation = 0 ;
669700
670- double gridFrameDistance = ( mGridFrameStyle == QgsComposerMap::NoGridFrame ) ? 0 : mGridFrameWidth ;
701+ double gridFrameDistance = ( mGridFrameStyle == QgsComposerMap::NoGridFrame ) ? 0 : mGridFrameWidth + ( mGridFramePenThickness / 2.0 ) ;
671702
672703 if ( frameBorder == QgsComposerMap::Left )
673704 {
705+ if ( !testGridFrameSideFlag ( QgsComposerMapGrid::FrameLeft ) )
706+ {
707+ gridFrameDistance = 0 ;
708+ }
674709
675710 if ( mLeftGridAnnotationPosition == QgsComposerMap::InsideMapFrame )
676711 {
@@ -708,6 +743,11 @@ void QgsComposerMapGrid::drawCoordinateAnnotation( QPainter* p, const QPointF& p
708743 }
709744 else if ( frameBorder == QgsComposerMap::Right )
710745 {
746+ if ( !testGridFrameSideFlag ( QgsComposerMapGrid::FrameRight ) )
747+ {
748+ gridFrameDistance = 0 ;
749+ }
750+
711751 if ( mRightGridAnnotationPosition == QgsComposerMap::InsideMapFrame )
712752 {
713753 if ( mRightGridAnnotationDirection == QgsComposerMap::Vertical || mRightGridAnnotationDirection == QgsComposerMap::BoundaryDirection )
@@ -743,6 +783,11 @@ void QgsComposerMapGrid::drawCoordinateAnnotation( QPainter* p, const QPointF& p
743783 }
744784 else if ( frameBorder == QgsComposerMap::Bottom )
745785 {
786+ if ( !testGridFrameSideFlag ( QgsComposerMapGrid::FrameBottom ) )
787+ {
788+ gridFrameDistance = 0 ;
789+ }
790+
746791 if ( mBottomGridAnnotationPosition == QgsComposerMap::InsideMapFrame )
747792 {
748793 if ( mBottomGridAnnotationDirection == QgsComposerMap::Horizontal || mBottomGridAnnotationDirection == QgsComposerMap::BoundaryDirection )
@@ -778,6 +823,11 @@ void QgsComposerMapGrid::drawCoordinateAnnotation( QPainter* p, const QPointF& p
778823 }
779824 else // Top
780825 {
826+ if ( !testGridFrameSideFlag ( QgsComposerMapGrid::FrameTop ) )
827+ {
828+ gridFrameDistance = 0 ;
829+ }
830+
781831 if ( mTopGridAnnotationPosition == QgsComposerMap::InsideMapFrame )
782832 {
783833 if ( mTopGridAnnotationDirection == QgsComposerMap::Horizontal || mTopGridAnnotationDirection == QgsComposerMap::BoundaryDirection )
@@ -1317,6 +1367,29 @@ QgsComposerMap::GridAnnotationDirection QgsComposerMapGrid::gridAnnotationDirect
13171367 return mLeftGridAnnotationDirection ;
13181368}
13191369
1370+ void QgsComposerMapGrid::setGridFrameSideFlags ( GridFrameSideFlags flags )
1371+ {
1372+ mGridFrameSides = flags;
1373+ }
1374+
1375+ void QgsComposerMapGrid::setGridFrameSideFlag ( QgsComposerMapGrid::GridFrameSideFlag flag, bool on )
1376+ {
1377+ if ( on )
1378+ mGridFrameSides |= flag;
1379+ else
1380+ mGridFrameSides &= ~flag;
1381+ }
1382+
1383+ QgsComposerMapGrid::GridFrameSideFlags QgsComposerMapGrid::gridFrameSideFlags () const
1384+ {
1385+ return mGridFrameSides ;
1386+ }
1387+
1388+ bool QgsComposerMapGrid::testGridFrameSideFlag ( QgsComposerMapGrid::GridFrameSideFlag flag ) const
1389+ {
1390+ return mGridFrameSides .testFlag ( flag );
1391+ }
1392+
13201393void QgsComposerMapGrid::setGridAnnotationDirection ( QgsComposerMap::GridAnnotationDirection d )
13211394{
13221395 mLeftGridAnnotationDirection = d;
0 commit comments