@@ -783,44 +783,104 @@ void QgsComposerMap::drawGridAnnotations( QPainter* p, const QList< QPair< doubl
783783 QString currentAnnotationString;
784784 double currentFontWidth = 0 ;
785785 double currentFontHeight = fontAscentMillimeters ( mGridAnnotationFont );
786+ QPointF currentAnnotationPos1, currentAnnotationPos2;
787+ double rotation = 0 ;
786788
789+ // first draw annotations for vertical grid lines
790+ if ( mGridAnnotationDirection != Horizontal )
791+ {
792+ rotation = 270 ;
793+ }
787794 QList< QPair< double , QLineF > >::const_iterator vIt = vLines.constBegin ();
788795 for ( ; vIt != vLines.constEnd (); ++vIt )
789796 {
790797 currentAnnotationString = QString::number ( vIt->first );
791798 currentFontWidth = textWidthMillimeters ( mGridAnnotationFont , currentAnnotationString );
792-
793- if ( mGridAnnotationPosition == OutsideMapFrame )
799+ if ( mGridAnnotationDirection == Horizontal )
794800 {
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+ }
797811 }
798- else
812+ else // vertical annotation
799813 {
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+ }
802824 }
825+ drawAnnotation ( p, currentAnnotationPos1, rotation, currentAnnotationString );
826+ drawAnnotation ( p, currentAnnotationPos2, rotation, currentAnnotationString );
803827 }
804828
829+ // then annotations for horizontal grid lines
830+ if ( mGridAnnotationDirection != Vertical )
831+ {
832+ rotation = 0 ;
833+ }
834+ else
835+ {
836+ rotation = 270 ;
837+ }
805838 QList< QPair< double , QLineF > >::const_iterator hIt = hLines.constBegin ();
806839 for ( ; hIt != hLines.constEnd (); ++hIt )
807840 {
808841 currentAnnotationString = QString::number ( hIt->first );
809842 currentFontWidth = textWidthMillimeters ( mGridAnnotationFont , currentAnnotationString );
810-
811- if ( mGridAnnotationPosition == OutsideMapFrame )
843+ if ( mGridAnnotationDirection == Vertical )
812844 {
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+ }
815855 }
816856 else
817857 {
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+ }
820868 }
869+
870+ drawAnnotation ( p, currentAnnotationPos1, rotation, currentAnnotationString );
871+ drawAnnotation ( p, currentAnnotationPos2, rotation, currentAnnotationString );
821872 }
822873}
823874
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+
824884int QgsComposerMap::verticalGridLines ( QList< QPair< double , QLineF > >& lines ) const
825885{
826886 lines.clear ();
0 commit comments