@@ -783,44 +783,104 @@ void QgsComposerMap::drawGridAnnotations( QPainter* p, const QList< QPair< doubl
783
783
QString currentAnnotationString;
784
784
double currentFontWidth = 0 ;
785
785
double currentFontHeight = fontAscentMillimeters ( mGridAnnotationFont );
786
+ QPointF currentAnnotationPos1, currentAnnotationPos2;
787
+ double rotation = 0 ;
786
788
789
+ // first draw annotations for vertical grid lines
790
+ if ( mGridAnnotationDirection != Horizontal )
791
+ {
792
+ rotation = 270 ;
793
+ }
787
794
QList< QPair< double , QLineF > >::const_iterator vIt = vLines.constBegin ();
788
795
for ( ; vIt != vLines.constEnd (); ++vIt )
789
796
{
790
797
currentAnnotationString = QString::number ( vIt->first );
791
798
currentFontWidth = textWidthMillimeters ( mGridAnnotationFont , currentAnnotationString );
792
-
793
- if ( mGridAnnotationPosition == OutsideMapFrame )
799
+ if ( mGridAnnotationDirection == Horizontal )
794
800
{
795
- drawText ( p, vIt->second .x1 () - currentFontWidth / 2.0 , vIt->second .y1 () - mAnnotationFrameDistance , currentAnnotationString, mGridAnnotationFont );
796
- drawText ( p, vIt->second .x2 () - currentFontWidth / 2.0 , vIt->second .y2 () + mAnnotationFrameDistance + currentFontHeight, currentAnnotationString, mGridAnnotationFont );
801
+ if ( mGridAnnotationPosition == OutsideMapFrame )
802
+ {
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 );
805
+ }
806
+ else
807
+ {
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 );
810
+ }
797
811
}
798
- else
812
+ else // vertical annotation
799
813
{
800
- drawText ( p, vIt->second .x1 () - currentFontWidth / 2.0 , vIt->second .y1 () + mAnnotationFrameDistance + currentFontHeight, currentAnnotationString, mGridAnnotationFont );
801
- drawText ( p, vIt->second .x2 () - currentFontWidth / 2.0 , vIt->second .y2 () - mAnnotationFrameDistance , currentAnnotationString, mGridAnnotationFont );
814
+ if ( mGridAnnotationPosition == OutsideMapFrame )
815
+ {
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 );
818
+ }
819
+ else
820
+ {
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 );
823
+ }
802
824
}
825
+ drawAnnotation ( p, currentAnnotationPos1, rotation, currentAnnotationString );
826
+ drawAnnotation ( p, currentAnnotationPos2, rotation, currentAnnotationString );
803
827
}
804
828
829
+ // then annotations for horizontal grid lines
830
+ if ( mGridAnnotationDirection != Vertical )
831
+ {
832
+ rotation = 0 ;
833
+ }
834
+ else
835
+ {
836
+ rotation = 270 ;
837
+ }
805
838
QList< QPair< double , QLineF > >::const_iterator hIt = hLines.constBegin ();
806
839
for ( ; hIt != hLines.constEnd (); ++hIt )
807
840
{
808
841
currentAnnotationString = QString::number ( hIt->first );
809
842
currentFontWidth = textWidthMillimeters ( mGridAnnotationFont , currentAnnotationString );
810
-
811
- if ( mGridAnnotationPosition == OutsideMapFrame )
843
+ if ( mGridAnnotationDirection == Vertical )
812
844
{
813
- drawText ( p, hIt->second .x1 () - ( mAnnotationFrameDistance + currentFontWidth ), hIt->second .y1 () + currentFontHeight / 2.0 , currentAnnotationString, mGridAnnotationFont );
814
- drawText ( p, hIt->second .x2 () + mAnnotationFrameDistance , hIt->second .y2 () + currentFontHeight / 2.0 , currentAnnotationString, mGridAnnotationFont );
845
+ if ( mGridAnnotationPosition == OutsideMapFrame )
846
+ {
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 );
849
+ }
850
+ else
851
+ {
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 );
854
+ }
815
855
}
816
856
else
817
857
{
818
- drawText ( p, hIt->second .x1 () + mAnnotationFrameDistance , hIt->second .y1 () + currentFontHeight / 2.0 , currentAnnotationString, mGridAnnotationFont );
819
- drawText ( p, hIt->second .x2 () - ( mAnnotationFrameDistance + currentFontWidth ), hIt->second .y2 () + currentFontHeight / 2.0 , currentAnnotationString, mGridAnnotationFont );
858
+ if ( mGridAnnotationPosition == OutsideMapFrame )
859
+ {
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 );
862
+ }
863
+ else
864
+ {
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 );
867
+ }
820
868
}
869
+
870
+ drawAnnotation ( p, currentAnnotationPos1, rotation, currentAnnotationString );
871
+ drawAnnotation ( p, currentAnnotationPos2, rotation, currentAnnotationString );
821
872
}
822
873
}
823
874
875
+ void QgsComposerMap::drawAnnotation ( QPainter* p, const QPointF& pos, int rotation, const QString& annotationText )
876
+ {
877
+ p->save ();
878
+ p->translate ( pos );
879
+ p->rotate ( rotation );
880
+ drawText ( p, 0 , 0 , annotationText, mGridAnnotationFont );
881
+ p->restore ();
882
+ }
883
+
824
884
int QgsComposerMap::verticalGridLines ( QList< QPair< double , QLineF > >& lines ) const
825
885
{
826
886
lines.clear ();
0 commit comments