16
16
***************************************************************************/
17
17
18
18
#include " qgscomposermap.h"
19
-
20
19
#include " qgscoordinatetransform.h"
21
20
#include " qgslogger.h"
22
21
#include " qgsmaprenderer.h"
23
- #include " qgsmaplayer.h"
24
22
#include " qgsmaplayerregistry.h"
25
23
#include " qgsmaptopixel.h"
26
24
#include " qgsproject.h"
42
40
QgsComposerMap::QgsComposerMap ( QgsComposition *composition, int x, int y, int width, int height )
43
41
: QgsComposerItem( x, y, width, height, composition ), mKeepLayerSet( false ), mGridEnabled( false ), mGridStyle( Solid ),
44
42
mGridIntervalX( 0.0 ), mGridIntervalY( 0.0 ), mGridOffsetX( 0.0 ), mGridOffsetY( 0.0 ), mGridAnnotationPrecision( 3 ), mShowGridAnnotation( false ),
45
- mGridAnnotationPosition( OutsideMapFrame ), mAnnotationFrameDistance( 1.0 ), mGridAnnotationDirection( Horizontal ),
43
+ mLeftGridAnnotationPosition( OutsideMapFrame ), mRightGridAnnotationPosition( OutsideMapFrame ), mTopGridAnnotationPosition( OutsideMapFrame ),
44
+ mBottomGridAnnotationPosition( OutsideMapFrame ), mAnnotationFrameDistance( 1.0 ), mLeftGridAnnotationDirection( Horizontal ), mRightGridAnnotationDirection( Horizontal ),
45
+ mTopGridAnnotationDirection( Horizontal ), mBottomGridAnnotationDirection( Horizontal ),
46
46
mCrossLength( 3 ), mMapCanvas( 0 ), mDrawCanvasItems( true )
47
47
{
48
48
mComposition = composition;
@@ -87,7 +87,9 @@ QgsComposerMap::QgsComposerMap( QgsComposition *composition, int x, int y, int w
87
87
QgsComposerMap::QgsComposerMap ( QgsComposition *composition )
88
88
: QgsComposerItem( 0 , 0 , 10 , 10 , composition ), mKeepLayerSet( false ), mGridEnabled( false ), mGridStyle( Solid ),
89
89
mGridIntervalX( 0.0 ), mGridIntervalY( 0.0 ), mGridOffsetX( 0.0 ), mGridOffsetY( 0.0 ), mGridAnnotationPrecision( 3 ), mShowGridAnnotation( false ),
90
- mGridAnnotationPosition( OutsideMapFrame ), mAnnotationFrameDistance( 1.0 ), mGridAnnotationDirection( Horizontal ), mCrossLength( 3 ),
90
+ mLeftGridAnnotationPosition( OutsideMapFrame ), mRightGridAnnotationPosition( OutsideMapFrame ), mTopGridAnnotationPosition( OutsideMapFrame ),
91
+ mBottomGridAnnotationPosition( OutsideMapFrame ), mAnnotationFrameDistance( 1.0 ), mLeftGridAnnotationDirection( Horizontal ), mRightGridAnnotationDirection( Horizontal ),
92
+ mTopGridAnnotationDirection( Horizontal ), mBottomGridAnnotationDirection( Horizontal ), mCrossLength( 3 ),
91
93
mMapCanvas( 0 ), mDrawCanvasItems( true )
92
94
{
93
95
// Offset
@@ -694,9 +696,15 @@ bool QgsComposerMap::writeXML( QDomElement& elem, QDomDocument & doc ) const
694
696
// grid annotation
695
697
QDomElement annotationElem = doc.createElement ( " Annotation" );
696
698
annotationElem.setAttribute ( " show" , mShowGridAnnotation );
697
- annotationElem.setAttribute ( " position" , mGridAnnotationPosition );
699
+ annotationElem.setAttribute ( " leftPosition" , mLeftGridAnnotationPosition );
700
+ annotationElem.setAttribute ( " rightPosition" , mRightGridAnnotationPosition );
701
+ annotationElem.setAttribute ( " topPosition" , mTopGridAnnotationPosition );
702
+ annotationElem.setAttribute ( " bottomPosition" , mBottomGridAnnotationPosition );
703
+ annotationElem.setAttribute ( " leftDirection" , mLeftGridAnnotationDirection );
704
+ annotationElem.setAttribute ( " rightDirection" , mRightGridAnnotationDirection );
705
+ annotationElem.setAttribute ( " topDirection" , mTopGridAnnotationDirection );
706
+ annotationElem.setAttribute ( " bottomDirection" , mBottomGridAnnotationDirection );
698
707
annotationElem.setAttribute ( " frameDistance" , QString::number ( mAnnotationFrameDistance ) );
699
- annotationElem.setAttribute ( " direction" , mGridAnnotationDirection );
700
708
annotationElem.setAttribute ( " font" , mGridAnnotationFont .toString () );
701
709
annotationElem.setAttribute ( " precision" , mGridAnnotationPrecision );
702
710
@@ -811,9 +819,15 @@ bool QgsComposerMap::readXML( const QDomElement& itemElem, const QDomDocument& d
811
819
{
812
820
QDomElement annotationElem = annotationNodeList.at ( 0 ).toElement ();
813
821
mShowGridAnnotation = ( annotationElem.attribute ( " show" , " 0" ) != " 0" );
814
- mGridAnnotationPosition = QgsComposerMap::GridAnnotationPosition ( annotationElem.attribute ( " position" , " 0" ).toInt () );
822
+ mLeftGridAnnotationPosition = QgsComposerMap::GridAnnotationPosition ( annotationElem.attribute ( " leftPosition" , " 0" ).toInt () );
823
+ mRightGridAnnotationPosition = QgsComposerMap::GridAnnotationPosition ( annotationElem.attribute ( " rightPosition" , " 0" ).toInt () );
824
+ mTopGridAnnotationPosition = QgsComposerMap::GridAnnotationPosition ( annotationElem.attribute ( " topPosition" , " 0" ).toInt () );
825
+ mBottomGridAnnotationPosition = QgsComposerMap::GridAnnotationPosition ( annotationElem.attribute ( " bottomPosition" , " 0" ).toInt () );
826
+ mLeftGridAnnotationDirection = QgsComposerMap::GridAnnotationDirection ( annotationElem.attribute ( " leftDirection" , " 0" ).toInt () );
827
+ mRightGridAnnotationDirection = QgsComposerMap::GridAnnotationDirection ( annotationElem.attribute ( " rightDirection" , " 0" ).toInt () );
828
+ mTopGridAnnotationDirection = QgsComposerMap::GridAnnotationDirection ( annotationElem.attribute ( " topDirection" , " 0" ).toInt () );
829
+ mBottomGridAnnotationDirection = QgsComposerMap::GridAnnotationDirection ( annotationElem.attribute ( " bottomDirection" , " 0" ).toInt () );
815
830
mAnnotationFrameDistance = annotationElem.attribute ( " frameDistance" , " 0" ).toDouble ();
816
- mGridAnnotationDirection = QgsComposerMap::GridAnnotationDirection ( annotationElem.attribute ( " direction" , " 0" ).toInt () );
817
831
mGridAnnotationFont .fromString ( annotationElem.attribute ( " font" , " " ) );
818
832
mGridAnnotationPrecision = annotationElem.attribute ( " precision" , " 3" ).toInt ();
819
833
}
@@ -991,9 +1005,9 @@ void QgsComposerMap::drawCoordinateAnnotation( QPainter* p, const QPointF& pos,
991
1005
if ( frameBorder == Left )
992
1006
{
993
1007
994
- if ( mGridAnnotationPosition == InsideMapFrame )
1008
+ if ( mLeftGridAnnotationPosition == InsideMapFrame )
995
1009
{
996
- if ( mGridAnnotationDirection == Vertical || mGridAnnotationDirection == BoundaryDirection )
1010
+ if ( mLeftGridAnnotationDirection == Vertical || mLeftGridAnnotationDirection == BoundaryDirection )
997
1011
{
998
1012
xpos += textHeight + mAnnotationFrameDistance ;
999
1013
ypos += textWidth / 2.0 ;
@@ -1005,9 +1019,9 @@ void QgsComposerMap::drawCoordinateAnnotation( QPainter* p, const QPointF& pos,
1005
1019
ypos += textHeight / 2.0 ;
1006
1020
}
1007
1021
}
1008
- else // Outside map frame
1022
+ else if ( mLeftGridAnnotationPosition == OutsideMapFrame ) // Outside map frame
1009
1023
{
1010
- if ( mGridAnnotationDirection == Vertical || mGridAnnotationDirection == BoundaryDirection )
1024
+ if ( mLeftGridAnnotationDirection == Vertical || mLeftGridAnnotationDirection == BoundaryDirection )
1011
1025
{
1012
1026
xpos -= mAnnotationFrameDistance ;
1013
1027
ypos += textWidth / 2.0 ;
@@ -1019,27 +1033,31 @@ void QgsComposerMap::drawCoordinateAnnotation( QPainter* p, const QPointF& pos,
1019
1033
ypos += textHeight / 2.0 ;
1020
1034
}
1021
1035
}
1036
+ else
1037
+ {
1038
+ return ;
1039
+ }
1022
1040
1023
1041
}
1024
1042
else if ( frameBorder == Right )
1025
1043
{
1026
- if ( mGridAnnotationPosition == InsideMapFrame )
1044
+ if ( mRightGridAnnotationPosition == InsideMapFrame )
1027
1045
{
1028
- if ( mGridAnnotationDirection == Vertical || mGridAnnotationDirection == BoundaryDirection )
1046
+ if ( mRightGridAnnotationDirection == Vertical || mRightGridAnnotationDirection == BoundaryDirection )
1029
1047
{
1030
1048
xpos -= mAnnotationFrameDistance ;
1031
1049
ypos += textWidth / 2.0 ;
1032
1050
rotation = 270 ;
1033
1051
}
1034
- else // Horizontal
1052
+ else
1035
1053
{
1036
1054
xpos -= textWidth + mAnnotationFrameDistance ;
1037
1055
ypos += textHeight / 2.0 ;
1038
1056
}
1039
1057
}
1040
- else // OutsideMapFrame
1058
+ else if ( mRightGridAnnotationPosition == OutsideMapFrame ) // OutsideMapFrame
1041
1059
{
1042
- if ( mGridAnnotationDirection == Vertical || mGridAnnotationDirection == BoundaryDirection )
1060
+ if ( mRightGridAnnotationDirection == Vertical || mRightGridAnnotationDirection == BoundaryDirection )
1043
1061
{
1044
1062
xpos += textHeight + mAnnotationFrameDistance ;
1045
1063
ypos += textWidth / 2.0 ;
@@ -1051,12 +1069,16 @@ void QgsComposerMap::drawCoordinateAnnotation( QPainter* p, const QPointF& pos,
1051
1069
ypos += textHeight / 2.0 ;
1052
1070
}
1053
1071
}
1072
+ else
1073
+ {
1074
+ return ;
1075
+ }
1054
1076
}
1055
1077
else if ( frameBorder == Bottom )
1056
1078
{
1057
- if ( mGridAnnotationPosition == InsideMapFrame )
1079
+ if ( mBottomGridAnnotationPosition == InsideMapFrame )
1058
1080
{
1059
- if ( mGridAnnotationDirection == Horizontal || mGridAnnotationDirection == BoundaryDirection )
1081
+ if ( mBottomGridAnnotationDirection == Horizontal || mBottomGridAnnotationDirection == BoundaryDirection )
1060
1082
{
1061
1083
ypos -= mAnnotationFrameDistance ;
1062
1084
xpos -= textWidth / 2.0 ;
@@ -1068,9 +1090,9 @@ void QgsComposerMap::drawCoordinateAnnotation( QPainter* p, const QPointF& pos,
1068
1090
rotation = 270 ;
1069
1091
}
1070
1092
}
1071
- else // OutsideMapFrame
1093
+ else if ( mBottomGridAnnotationPosition == OutsideMapFrame ) // OutsideMapFrame
1072
1094
{
1073
- if ( mGridAnnotationDirection == Horizontal || mGridAnnotationDirection == BoundaryDirection )
1095
+ if ( mBottomGridAnnotationDirection == Horizontal || mBottomGridAnnotationDirection == BoundaryDirection )
1074
1096
{
1075
1097
ypos += mAnnotationFrameDistance + textHeight;
1076
1098
xpos -= textWidth / 2.0 ;
@@ -1082,12 +1104,16 @@ void QgsComposerMap::drawCoordinateAnnotation( QPainter* p, const QPointF& pos,
1082
1104
rotation = 270 ;
1083
1105
}
1084
1106
}
1107
+ else
1108
+ {
1109
+ return ;
1110
+ }
1085
1111
}
1086
1112
else // Top
1087
1113
{
1088
- if ( mGridAnnotationPosition == InsideMapFrame )
1114
+ if ( mTopGridAnnotationPosition == InsideMapFrame )
1089
1115
{
1090
- if ( mGridAnnotationDirection == Horizontal || mGridAnnotationDirection == BoundaryDirection )
1116
+ if ( mTopGridAnnotationDirection == Horizontal || mTopGridAnnotationDirection == BoundaryDirection )
1091
1117
{
1092
1118
xpos -= textWidth / 2.0 ;
1093
1119
ypos += textHeight + mAnnotationFrameDistance ;
@@ -1099,9 +1125,9 @@ void QgsComposerMap::drawCoordinateAnnotation( QPainter* p, const QPointF& pos,
1099
1125
rotation = 270 ;
1100
1126
}
1101
1127
}
1102
- else // OutsideMapFrame
1128
+ else if ( mTopGridAnnotationPosition == OutsideMapFrame ) // OutsideMapFrame
1103
1129
{
1104
- if ( mGridAnnotationDirection == Horizontal || mGridAnnotationDirection == BoundaryDirection )
1130
+ if ( mTopGridAnnotationDirection == Horizontal || mTopGridAnnotationDirection == BoundaryDirection )
1105
1131
{
1106
1132
xpos -= textWidth / 2.0 ;
1107
1133
ypos -= mAnnotationFrameDistance ;
@@ -1113,6 +1139,10 @@ void QgsComposerMap::drawCoordinateAnnotation( QPainter* p, const QPointF& pos,
1113
1139
rotation = 270 ;
1114
1140
}
1115
1141
}
1142
+ else
1143
+ {
1144
+ return ;
1145
+ }
1116
1146
}
1117
1147
1118
1148
drawAnnotation ( p, QPointF ( xpos, ypos ), rotation, annotationString );
@@ -1320,7 +1350,8 @@ QPolygonF QgsComposerMap::transformedMapPolygon() const
1320
1350
1321
1351
double QgsComposerMap::maxExtension () const
1322
1352
{
1323
- if ( !mGridEnabled || !mShowGridAnnotation || mGridAnnotationPosition != OutsideMapFrame )
1353
+ if ( !mGridEnabled || !mShowGridAnnotation || ( mLeftGridAnnotationPosition != OutsideMapFrame && mRightGridAnnotationPosition != OutsideMapFrame
1354
+ && mTopGridAnnotationPosition != OutsideMapFrame && mBottomGridAnnotationPosition != OutsideMapFrame ) )
1324
1355
{
1325
1356
return 0 ;
1326
1357
}
@@ -1611,3 +1642,90 @@ QPointF QgsComposerMap::composerMapPosForItem( const QGraphicsItem* item ) const
1611
1642
double mapY = mapRendererExtent.yMaximum () - itemScenePos.y () / graphicsSceneRect.height () * mapRendererExtent.height ();
1612
1643
return mapToItemCoords ( QPointF ( mapX, mapY ) );
1613
1644
}
1645
+
1646
+ void QgsComposerMap::setGridAnnotationPosition ( GridAnnotationPosition p, QgsComposerMap::Border border )
1647
+ {
1648
+ switch ( border )
1649
+ {
1650
+ case QgsComposerMap::Left:
1651
+ mLeftGridAnnotationPosition = p;
1652
+ break ;
1653
+ case QgsComposerMap::Right:
1654
+ mRightGridAnnotationPosition = p;
1655
+ break ;
1656
+ case QgsComposerMap::Top:
1657
+ mTopGridAnnotationPosition = p;
1658
+ break ;
1659
+ case QgsComposerMap::Bottom:
1660
+ mBottomGridAnnotationPosition = p;
1661
+ break ;
1662
+ default :
1663
+ return ;
1664
+ }
1665
+ updateBoundingRect ();
1666
+ update ();
1667
+ }
1668
+
1669
+ QgsComposerMap::GridAnnotationPosition QgsComposerMap::gridAnnotationPosition ( QgsComposerMap::Border border ) const
1670
+ {
1671
+ switch ( border )
1672
+ {
1673
+ case QgsComposerMap::Left:
1674
+ return mLeftGridAnnotationPosition ;
1675
+ break ;
1676
+ case QgsComposerMap::Right:
1677
+ return mRightGridAnnotationPosition ;
1678
+ break ;
1679
+ case QgsComposerMap::Top:
1680
+ return mTopGridAnnotationPosition ;
1681
+ break ;
1682
+ case QgsComposerMap::Bottom:
1683
+ default :
1684
+ return mBottomGridAnnotationPosition ;
1685
+ break ;
1686
+ }
1687
+ }
1688
+
1689
+ void QgsComposerMap::setGridAnnotationDirection ( GridAnnotationDirection d, QgsComposerMap::Border border )
1690
+ {
1691
+ switch ( border )
1692
+ {
1693
+ case QgsComposerMap::Left:
1694
+ mLeftGridAnnotationDirection = d;
1695
+ break ;
1696
+ case QgsComposerMap::Right:
1697
+ mRightGridAnnotationDirection = d;
1698
+ break ;
1699
+ case QgsComposerMap::Top:
1700
+ mTopGridAnnotationDirection = d;
1701
+ break ;
1702
+ case QgsComposerMap::Bottom:
1703
+ mBottomGridAnnotationDirection = d;
1704
+ break ;
1705
+ default :
1706
+ return ;
1707
+ break ;
1708
+ }
1709
+ updateBoundingRect ();
1710
+ update ();
1711
+ }
1712
+
1713
+ QgsComposerMap::GridAnnotationDirection QgsComposerMap::gridAnnotationDirection ( QgsComposerMap::Border border ) const
1714
+ {
1715
+ switch ( border )
1716
+ {
1717
+ case QgsComposerMap::Left:
1718
+ return mLeftGridAnnotationDirection ;
1719
+ break ;
1720
+ case QgsComposerMap::Right:
1721
+ return mRightGridAnnotationDirection ;
1722
+ break ;
1723
+ case QgsComposerMap::Top:
1724
+ return mTopGridAnnotationDirection ;
1725
+ break ;
1726
+ case QgsComposerMap::Bottom:
1727
+ default :
1728
+ return mBottomGridAnnotationDirection ;
1729
+ break ;
1730
+ }
1731
+ }
0 commit comments