@@ -42,7 +42,7 @@ QgsComposerMap::QgsComposerMap( QgsComposition *composition, int x, int y, int w
42
42
mGridIntervalX( 0.0 ), mGridIntervalY( 0.0 ), mGridOffsetX( 0.0 ), mGridOffsetY( 0.0 ), mGridAnnotationPrecision( 3 ), mShowGridAnnotation( false ),
43
43
mLeftGridAnnotationPosition( OutsideMapFrame ), mRightGridAnnotationPosition( OutsideMapFrame ), mTopGridAnnotationPosition( OutsideMapFrame ),
44
44
mBottomGridAnnotationPosition( OutsideMapFrame ), mAnnotationFrameDistance( 1.0 ), mLeftGridAnnotationDirection( Horizontal ), mRightGridAnnotationDirection( Horizontal ),
45
- mTopGridAnnotationDirection( Horizontal ), mBottomGridAnnotationDirection( Horizontal ),
45
+ mTopGridAnnotationDirection( Horizontal ), mBottomGridAnnotationDirection( Horizontal ), mGridFrameStyle( NoGridFrame ), mGridFrameWidth( 2.0 ),
46
46
mCrossLength( 3 ), mMapCanvas( 0 ), mDrawCanvasItems( true )
47
47
{
48
48
mComposition = composition;
@@ -89,7 +89,7 @@ QgsComposerMap::QgsComposerMap( QgsComposition *composition )
89
89
mGridIntervalX( 0.0 ), mGridIntervalY( 0.0 ), mGridOffsetX( 0.0 ), mGridOffsetY( 0.0 ), mGridAnnotationPrecision( 3 ), mShowGridAnnotation( false ),
90
90
mLeftGridAnnotationPosition( OutsideMapFrame ), mRightGridAnnotationPosition( OutsideMapFrame ), mTopGridAnnotationPosition( OutsideMapFrame ),
91
91
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 ),
93
93
mMapCanvas( 0 ), mDrawCanvasItems( true )
94
94
{
95
95
// Offset
@@ -960,12 +960,79 @@ void QgsComposerMap::drawGrid( QPainter* p )
960
960
961
961
p->setClipRect ( thisPaintRect , Qt::NoClip );
962
962
963
+ if ( mGridFrameStyle != QgsComposerMap::NoGridFrame )
964
+ {
965
+ drawGridFrame ( p, horizontalLines, verticalLines );
966
+ }
967
+
963
968
if ( mShowGridAnnotation )
964
969
{
965
970
drawCoordinateAnnotations ( p, horizontalLines, verticalLines );
966
971
}
967
972
}
968
973
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
+
969
1036
void QgsComposerMap::drawCoordinateAnnotations ( QPainter* p, const QList< QPair< double , QLineF > >& hLines, const QList< QPair< double , QLineF > >& vLines )
970
1037
{
971
1038
if ( !p )
@@ -1002,6 +1069,8 @@ void QgsComposerMap::drawCoordinateAnnotation( QPainter* p, const QPointF& pos,
1002
1069
double ypos = pos.y ();
1003
1070
int rotation = 0 ;
1004
1071
1072
+ double gridFrameDistance = ( mGridFrameStyle == NoGridFrame ) ? 0 : mGridFrameWidth ;
1073
+
1005
1074
if ( frameBorder == Left )
1006
1075
{
1007
1076
@@ -1023,13 +1092,13 @@ void QgsComposerMap::drawCoordinateAnnotation( QPainter* p, const QPointF& pos,
1023
1092
{
1024
1093
if ( mLeftGridAnnotationDirection == Vertical || mLeftGridAnnotationDirection == BoundaryDirection )
1025
1094
{
1026
- xpos -= mAnnotationFrameDistance ;
1095
+ xpos -= ( mAnnotationFrameDistance + gridFrameDistance ) ;
1027
1096
ypos += textWidth / 2.0 ;
1028
1097
rotation = 270 ;
1029
1098
}
1030
1099
else
1031
1100
{
1032
- xpos -= textWidth + mAnnotationFrameDistance ;
1101
+ xpos -= ( textWidth + mAnnotationFrameDistance + gridFrameDistance ) ;
1033
1102
ypos += textHeight / 2.0 ;
1034
1103
}
1035
1104
}
@@ -1059,13 +1128,13 @@ void QgsComposerMap::drawCoordinateAnnotation( QPainter* p, const QPointF& pos,
1059
1128
{
1060
1129
if ( mRightGridAnnotationDirection == Vertical || mRightGridAnnotationDirection == BoundaryDirection )
1061
1130
{
1062
- xpos += textHeight + mAnnotationFrameDistance ;
1131
+ xpos += ( textHeight + mAnnotationFrameDistance + gridFrameDistance ) ;
1063
1132
ypos += textWidth / 2.0 ;
1064
1133
rotation = 270 ;
1065
1134
}
1066
1135
else // Horizontal
1067
1136
{
1068
- xpos += mAnnotationFrameDistance ;
1137
+ xpos += ( mAnnotationFrameDistance + gridFrameDistance ) ;
1069
1138
ypos += textHeight / 2.0 ;
1070
1139
}
1071
1140
}
@@ -1094,13 +1163,13 @@ void QgsComposerMap::drawCoordinateAnnotation( QPainter* p, const QPointF& pos,
1094
1163
{
1095
1164
if ( mBottomGridAnnotationDirection == Horizontal || mBottomGridAnnotationDirection == BoundaryDirection )
1096
1165
{
1097
- ypos += mAnnotationFrameDistance + textHeight;
1166
+ ypos += ( mAnnotationFrameDistance + textHeight + gridFrameDistance ) ;
1098
1167
xpos -= textWidth / 2.0 ;
1099
1168
}
1100
1169
else // Vertical
1101
1170
{
1102
1171
xpos += textHeight / 2.0 ;
1103
- ypos += textWidth + mAnnotationFrameDistance ;
1172
+ ypos += ( textWidth + mAnnotationFrameDistance + gridFrameDistance ) ;
1104
1173
rotation = 270 ;
1105
1174
}
1106
1175
}
@@ -1130,12 +1199,12 @@ void QgsComposerMap::drawCoordinateAnnotation( QPainter* p, const QPointF& pos,
1130
1199
if ( mTopGridAnnotationDirection == Horizontal || mTopGridAnnotationDirection == BoundaryDirection )
1131
1200
{
1132
1201
xpos -= textWidth / 2.0 ;
1133
- ypos -= mAnnotationFrameDistance ;
1202
+ ypos -= ( mAnnotationFrameDistance + gridFrameDistance ) ;
1134
1203
}
1135
1204
else // Vertical
1136
1205
{
1137
1206
xpos += textHeight / 2.0 ;
1138
- ypos -= mAnnotationFrameDistance ;
1207
+ ypos -= ( mAnnotationFrameDistance + gridFrameDistance ) ;
1139
1208
rotation = 270 ;
1140
1209
}
1141
1210
}
@@ -1389,7 +1458,9 @@ double QgsComposerMap::maxExtension() const
1389
1458
maxExtension = qMax ( maxExtension, currentExtension );
1390
1459
}
1391
1460
1392
- return maxExtension + mAnnotationFrameDistance ;
1461
+ // grid frame
1462
+ double gridFrameDist = ( mGridFrameStyle == NoGridFrame ) ? 0 : mGridFrameWidth ;
1463
+ return maxExtension + mAnnotationFrameDistance + gridFrameDist;
1393
1464
}
1394
1465
1395
1466
void QgsComposerMap::mapPolygon ( QPolygonF& poly ) const
@@ -1729,3 +1800,45 @@ QgsComposerMap::GridAnnotationDirection QgsComposerMap::gridAnnotationDirection(
1729
1800
break ;
1730
1801
}
1731
1802
}
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