@@ -44,7 +44,7 @@ int QgsComposerMap::mCurrentComposerId = 0;
44
44
QgsComposerMap::QgsComposerMap ( QgsComposition *composition, int x, int y, int width, int height )
45
45
: QgsComposerItem( x, y, width, height, composition ), mKeepLayerSet( false ), mGridEnabled( false ), mGridStyle( Solid ), \
46
46
mGridIntervalX( 0.0 ), mGridIntervalY( 0.0 ), mGridOffsetX( 0.0 ), mGridOffsetY( 0.0 ), mShowGridAnnotation( false ), \
47
- mGridAnnotationPosition( OutsideMapFrame ), mAnnotationFrameDistance( 1.0 ), mGridAnnotationDirection( Horizontal )
47
+ mGridAnnotationPosition( OutsideMapFrame ), mAnnotationFrameDistance( 1.0 ), mGridAnnotationDirection( Horizontal ), mGridAnnotationType( Coordinate )
48
48
{
49
49
mComposition = composition;
50
50
mMapRenderer = mComposition ->mapRenderer ();
@@ -74,7 +74,7 @@ QgsComposerMap::QgsComposerMap( QgsComposition *composition, int x, int y, int w
74
74
QgsComposerMap::QgsComposerMap ( QgsComposition *composition )
75
75
: QgsComposerItem( 0 , 0 , 10 , 10 , composition ), mKeepLayerSet( false ), mGridEnabled( false ), mGridStyle( Solid ), \
76
76
mGridIntervalX( 0.0 ), mGridIntervalY( 0.0 ), mGridOffsetX( 0.0 ), mGridOffsetY( 0.0 ), mShowGridAnnotation( false ), \
77
- mGridAnnotationPosition( OutsideMapFrame ), mAnnotationFrameDistance( 1.0 ), mGridAnnotationDirection( Horizontal )
77
+ mGridAnnotationPosition( OutsideMapFrame ), mAnnotationFrameDistance( 1.0 ), mGridAnnotationDirection( Horizontal ), mGridAnnotationType( Coordinate )
78
78
{
79
79
// Offset
80
80
mXOffset = 0.0 ;
@@ -568,6 +568,7 @@ bool QgsComposerMap::writeXML( QDomElement& elem, QDomDocument & doc ) const
568
568
annotationElem.setAttribute ( " frameDistance" , mAnnotationFrameDistance );
569
569
annotationElem.setAttribute ( " direction" , mGridAnnotationDirection );
570
570
annotationElem.setAttribute ( " font" , mGridAnnotationFont .toString () );
571
+ annotationElem.setAttribute ( " type" , mGridAnnotationType );
571
572
572
573
gridElem.appendChild ( annotationElem );
573
574
composerMapElem.appendChild ( gridElem );
@@ -668,6 +669,7 @@ bool QgsComposerMap::readXML( const QDomElement& itemElem, const QDomDocument& d
668
669
mAnnotationFrameDistance = annotationElem.attribute ( " frameDistance" , " 0" ).toDouble ();
669
670
mGridAnnotationDirection = QgsComposerMap::GridAnnotationDirection ( annotationElem.attribute ( " direction" , " 0" ).toInt () );
670
671
mGridAnnotationFont .fromString ( annotationElem.attribute ( " font" , " " ) );
672
+ mGridAnnotationType = QgsComposerMap::GridAnnotationType ( annotationElem.attribute ( " type" , " 0" ).toInt () );
671
673
}
672
674
}
673
675
@@ -785,45 +787,81 @@ void QgsComposerMap::drawGridAnnotations( QPainter* p, const QList< QPair< doubl
785
787
double currentFontHeight = fontAscentMillimeters ( mGridAnnotationFont );
786
788
QPointF currentAnnotationPos1, currentAnnotationPos2;
787
789
double rotation = 0 ;
790
+ double xpos1, xpos2, ypos1, ypos2;
788
791
789
792
// first draw annotations for vertical grid lines
790
793
if ( mGridAnnotationDirection != Horizontal )
791
794
{
792
795
rotation = 270 ;
793
796
}
797
+
798
+
794
799
QList< QPair< double , QLineF > >::const_iterator vIt = vLines.constBegin ();
800
+ int loopCounter = 0 ;
795
801
for ( ; vIt != vLines.constEnd (); ++vIt )
796
802
{
797
- currentAnnotationString = QString::number ( vIt->first );
803
+ if ( mGridAnnotationType == Sector )
804
+ {
805
+ int letterNumber = loopCounter % 26 + 66 ;
806
+ currentAnnotationString = QString ( QChar ( letterNumber ) );
807
+ }
808
+ else
809
+ {
810
+ currentAnnotationString = QString::number ( vIt->first );
811
+ }
812
+
798
813
currentFontWidth = textWidthMillimeters ( mGridAnnotationFont , currentAnnotationString );
799
814
if ( mGridAnnotationDirection == Horizontal )
800
815
{
816
+ xpos1 = vIt->second .x1 () - currentFontWidth / 2.0 ;
817
+ xpos2 = vIt->second .x2 () - currentFontWidth / 2.0 ;
801
818
if ( mGridAnnotationPosition == OutsideMapFrame )
802
819
{
803
- currentAnnotationPos1 = QPointF ( vIt->second .x1 () - currentFontWidth / 2.0 , vIt-> second . y1 () - mAnnotationFrameDistance ) ;
804
- currentAnnotationPos2 = QPointF ( vIt->second .x2 () - currentFontWidth / 2.0 , vIt-> second . y2 () + mAnnotationFrameDistance + currentFontHeight ) ;
820
+ ypos1 = vIt->second .y1 () - mAnnotationFrameDistance ;
821
+ ypos2 = vIt->second .y2 () + mAnnotationFrameDistance + currentFontHeight;
805
822
}
806
823
else
807
824
{
808
- currentAnnotationPos1 = QPointF ( vIt->second .x1 () - currentFontWidth / 2.0 , vIt-> second . y1 () + mAnnotationFrameDistance + currentFontHeight ) ;
809
- currentAnnotationPos2 = QPointF ( vIt->second .x2 () - currentFontWidth / 2.0 , vIt-> second . y2 () - mAnnotationFrameDistance ) ;
825
+ ypos1 = vIt->second .y1 () + mAnnotationFrameDistance + currentFontHeight;
826
+ ypos2 = vIt->second .y2 () - mAnnotationFrameDistance ;
810
827
}
811
828
}
812
829
else // vertical annotation
813
830
{
831
+ xpos1 = vIt->second .x1 () + currentFontHeight / 2.0 ;
832
+ xpos2 = vIt->second .x2 () + currentFontHeight / 2.0 ;
814
833
if ( mGridAnnotationPosition == OutsideMapFrame )
815
834
{
816
- currentAnnotationPos1 = QPointF ( vIt->second .x1 () + currentFontHeight / 2.0 , vIt-> second . y1 () - mAnnotationFrameDistance ) ;
817
- currentAnnotationPos2 = QPointF ( vIt->second .x2 () + currentFontHeight / 2.0 , vIt-> second . y2 () + mAnnotationFrameDistance + currentFontWidth ) ;
835
+ ypos1 = vIt->second .y1 () - mAnnotationFrameDistance ;
836
+ ypos2 = vIt->second .y2 () + mAnnotationFrameDistance + currentFontWidth;
818
837
}
819
838
else
820
839
{
821
- currentAnnotationPos1 = QPointF ( vIt->second .x1 () + currentFontHeight / 2.0 , vIt-> second . y1 () + currentFontWidth + mAnnotationFrameDistance ) ;
822
- currentAnnotationPos2 = QPointF ( vIt->second .x1 () + currentFontHeight / 2.0 , vIt-> second . y2 () - mAnnotationFrameDistance ) ;
840
+ ypos1 = vIt->second .y1 () + currentFontWidth + mAnnotationFrameDistance ;
841
+ ypos2 = vIt->second .y2 () - mAnnotationFrameDistance ;
823
842
}
824
843
}
825
- drawAnnotation ( p, currentAnnotationPos1, rotation, currentAnnotationString );
826
- drawAnnotation ( p, currentAnnotationPos2, rotation, currentAnnotationString );
844
+
845
+ // shift positions in case of sector annotation
846
+ if ( mGridAnnotationType == Sector && loopCounter < ( vLines.size () - 1 ) )
847
+ {
848
+ xpos1 += ( vLines.at ( loopCounter + 1 ).second .x1 () - vLines.at ( loopCounter ).second .x1 () ) / 2.0 ;
849
+ xpos2 += ( vLines.at ( loopCounter + 1 ).second .x2 () - vLines.at ( loopCounter ).second .x2 () ) / 2.0 ;
850
+ }
851
+ else if ( mGridAnnotationType == Sector && loopCounter == ( vLines.size () - 1 ) )
852
+ {
853
+ xpos1 += ( rect ().width () - vLines.at ( loopCounter ).second .x1 () ) / 2.0 ;
854
+ xpos2 += ( rect ().width () - vLines.at ( loopCounter ).second .x2 () ) / 2.0 ;
855
+ }
856
+ drawAnnotation ( p, QPointF ( xpos1, ypos1 ), rotation, currentAnnotationString );
857
+ drawAnnotation ( p, QPointF ( xpos1, ypos2 ), rotation, currentAnnotationString );
858
+
859
+ if ( mGridAnnotationType == Sector && loopCounter == 0 )
860
+ {
861
+ drawAnnotation ( p, QPointF ( vLines.at ( loopCounter ).second .x1 () / 2.0 , ypos1 ), rotation, " A" );
862
+ drawAnnotation ( p, QPointF ( vLines.at ( loopCounter ).second .x2 () / 2.0 , ypos2 ), rotation, " A" );
863
+ }
864
+ ++loopCounter;
827
865
}
828
866
829
867
// then annotations for horizontal grid lines
@@ -835,40 +873,72 @@ void QgsComposerMap::drawGridAnnotations( QPainter* p, const QList< QPair< doubl
835
873
{
836
874
rotation = 270 ;
837
875
}
876
+
877
+ loopCounter = 0 ;
838
878
QList< QPair< double , QLineF > >::const_iterator hIt = hLines.constBegin ();
839
879
for ( ; hIt != hLines.constEnd (); ++hIt )
840
880
{
841
- currentAnnotationString = QString::number ( hIt->first );
881
+ if ( mGridAnnotationType == Sector )
882
+ {
883
+ currentAnnotationString = QString::number ( hLines.size () - loopCounter - 1 );
884
+ }
885
+ else
886
+ {
887
+ currentAnnotationString = QString::number ( hIt->first );
888
+ }
889
+
842
890
currentFontWidth = textWidthMillimeters ( mGridAnnotationFont , currentAnnotationString );
843
891
if ( mGridAnnotationDirection == Vertical )
844
892
{
893
+ ypos1 = hIt->second .y1 () + currentFontWidth / 2.0 ;
894
+ ypos2 = hIt->second .y2 () + currentFontWidth / 2.0 ;
845
895
if ( mGridAnnotationPosition == OutsideMapFrame )
846
896
{
847
- currentAnnotationPos1 = QPointF ( hIt->second .x1 () - mAnnotationFrameDistance , hIt-> second . y1 () + currentFontWidth / 2.0 ) ;
848
- currentAnnotationPos2 = QPointF ( hIt->second .x2 () + mAnnotationFrameDistance + currentFontHeight, hIt-> second . y2 () + currentFontWidth / 2.0 ) ;
897
+ xpos1 = hIt->second .x1 () - mAnnotationFrameDistance ;
898
+ xpos2 = hIt->second .x2 () + mAnnotationFrameDistance + currentFontHeight;
849
899
}
850
900
else
851
901
{
852
- currentAnnotationPos1 = QPointF ( hIt->second .x1 () + mAnnotationFrameDistance + currentFontHeight, hIt-> second . y1 () + currentFontWidth / 2.0 ) ;
853
- currentAnnotationPos2 = QPointF ( hIt->second .x2 () - mAnnotationFrameDistance , hIt-> second . y1 () + currentFontWidth / 2.0 ) ;
902
+ xpos1 = hIt->second .x1 () + mAnnotationFrameDistance + currentFontHeight;
903
+ xpos2 = hIt->second .x2 () - mAnnotationFrameDistance ;
854
904
}
855
905
}
856
906
else
857
907
{
908
+ ypos1 = hIt->second .y1 () + currentFontHeight / 2.0 ;
909
+ ypos2 = hIt->second .y2 () + currentFontHeight / 2.0 ;
858
910
if ( mGridAnnotationPosition == OutsideMapFrame )
859
911
{
860
- currentAnnotationPos1 = QPointF ( hIt->second .x1 () - ( mAnnotationFrameDistance + currentFontWidth ), hIt-> second . y1 () + currentFontHeight / 2.0 );
861
- currentAnnotationPos2 = QPointF ( hIt->second .x2 () + mAnnotationFrameDistance , hIt-> second . y2 () + currentFontHeight / 2.0 ) ;
912
+ xpos1 = hIt->second .x1 () - ( mAnnotationFrameDistance + currentFontWidth );
913
+ xpos2 = hIt->second .x2 () + mAnnotationFrameDistance ;
862
914
}
863
915
else
864
916
{
865
- currentAnnotationPos1 = QPointF ( hIt->second .x1 () + mAnnotationFrameDistance , hIt-> second . y1 () + currentFontHeight / 2.0 ) ;
866
- currentAnnotationPos2 = QPointF ( hIt->second .x2 () - ( mAnnotationFrameDistance + currentFontWidth ), hIt-> second . y2 () + currentFontHeight / 2.0 );
917
+ xpos1 = hIt->second .x1 () + mAnnotationFrameDistance ;
918
+ xpos2 = hIt->second .x2 () - ( mAnnotationFrameDistance + currentFontWidth );
867
919
}
868
920
}
869
921
870
- drawAnnotation ( p, currentAnnotationPos1, rotation, currentAnnotationString );
871
- drawAnnotation ( p, currentAnnotationPos2, rotation, currentAnnotationString );
922
+ // shift y-Positions in case of sectoral annotations
923
+ if ( mGridAnnotationType == Sector && loopCounter < ( hLines.size () - 1 ) )
924
+ {
925
+ ypos1 += ( hLines.at ( loopCounter + 1 ).second .y1 () - hLines.at ( loopCounter ).second .y1 () ) / 2.0 ;
926
+ ypos2 += ( hLines.at ( loopCounter + 1 ).second .y2 () - hLines.at ( loopCounter ).second .y2 () ) / 2.0 ;
927
+ }
928
+ else if ( mGridAnnotationType == Sector && loopCounter == ( hLines.size () - 1 ) )
929
+ {
930
+ ypos1 -= hLines.at ( loopCounter ).second .y1 () / 2.0 ;
931
+ ypos2 -= hLines.at ( loopCounter ).second .y2 () / 2.0 ;
932
+ }
933
+
934
+ drawAnnotation ( p, QPointF ( xpos1, ypos1 ), rotation, currentAnnotationString );
935
+ drawAnnotation ( p, QPointF ( xpos2, ypos2 ), rotation, currentAnnotationString );
936
+ if ( mGridAnnotationType == Sector && loopCounter == 0 )
937
+ {
938
+ drawAnnotation ( p, QPointF ( xpos1, ( rect ().height () + hLines.at ( loopCounter ).second .y1 () ) / 2.0 ), rotation, QString::number ( hLines.size () ) );
939
+ drawAnnotation ( p, QPointF ( xpos2, ( rect ().height () + hLines.at ( loopCounter ).second .y2 () ) / 2.0 ), rotation, QString::number ( hLines.size () ) );
940
+ }
941
+ ++loopCounter;
872
942
}
873
943
}
874
944
0 commit comments