@@ -44,7 +44,7 @@ int QgsComposerMap::mCurrentComposerId = 0;
4444QgsComposerMap::QgsComposerMap ( QgsComposition *composition, int x, int y, int width, int height )
4545 : QgsComposerItem( x, y, width, height, composition ), mKeepLayerSet( false ), mGridEnabled( false ), mGridStyle( Solid ), \
4646 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 )
4848{
4949 mComposition = composition;
5050 mMapRenderer = mComposition ->mapRenderer ();
@@ -74,7 +74,7 @@ QgsComposerMap::QgsComposerMap( QgsComposition *composition, int x, int y, int w
7474QgsComposerMap::QgsComposerMap ( QgsComposition *composition )
7575 : QgsComposerItem( 0 , 0 , 10 , 10 , composition ), mKeepLayerSet( false ), mGridEnabled( false ), mGridStyle( Solid ), \
7676 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 )
7878{
7979 // Offset
8080 mXOffset = 0.0 ;
@@ -568,6 +568,7 @@ bool QgsComposerMap::writeXML( QDomElement& elem, QDomDocument & doc ) const
568568 annotationElem.setAttribute ( " frameDistance" , mAnnotationFrameDistance );
569569 annotationElem.setAttribute ( " direction" , mGridAnnotationDirection );
570570 annotationElem.setAttribute ( " font" , mGridAnnotationFont .toString () );
571+ annotationElem.setAttribute ( " type" , mGridAnnotationType );
571572
572573 gridElem.appendChild ( annotationElem );
573574 composerMapElem.appendChild ( gridElem );
@@ -668,6 +669,7 @@ bool QgsComposerMap::readXML( const QDomElement& itemElem, const QDomDocument& d
668669 mAnnotationFrameDistance = annotationElem.attribute ( " frameDistance" , " 0" ).toDouble ();
669670 mGridAnnotationDirection = QgsComposerMap::GridAnnotationDirection ( annotationElem.attribute ( " direction" , " 0" ).toInt () );
670671 mGridAnnotationFont .fromString ( annotationElem.attribute ( " font" , " " ) );
672+ mGridAnnotationType = QgsComposerMap::GridAnnotationType ( annotationElem.attribute ( " type" , " 0" ).toInt () );
671673 }
672674 }
673675
@@ -785,45 +787,81 @@ void QgsComposerMap::drawGridAnnotations( QPainter* p, const QList< QPair< doubl
785787 double currentFontHeight = fontAscentMillimeters ( mGridAnnotationFont );
786788 QPointF currentAnnotationPos1, currentAnnotationPos2;
787789 double rotation = 0 ;
790+ double xpos1, xpos2, ypos1, ypos2;
788791
789792 // first draw annotations for vertical grid lines
790793 if ( mGridAnnotationDirection != Horizontal )
791794 {
792795 rotation = 270 ;
793796 }
797+
798+
794799 QList< QPair< double , QLineF > >::const_iterator vIt = vLines.constBegin ();
800+ int loopCounter = 0 ;
795801 for ( ; vIt != vLines.constEnd (); ++vIt )
796802 {
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+
798813 currentFontWidth = textWidthMillimeters ( mGridAnnotationFont , currentAnnotationString );
799814 if ( mGridAnnotationDirection == Horizontal )
800815 {
816+ xpos1 = vIt->second .x1 () - currentFontWidth / 2.0 ;
817+ xpos2 = vIt->second .x2 () - currentFontWidth / 2.0 ;
801818 if ( mGridAnnotationPosition == OutsideMapFrame )
802819 {
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;
805822 }
806823 else
807824 {
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 ;
810827 }
811828 }
812829 else // vertical annotation
813830 {
831+ xpos1 = vIt->second .x1 () + currentFontHeight / 2.0 ;
832+ xpos2 = vIt->second .x2 () + currentFontHeight / 2.0 ;
814833 if ( mGridAnnotationPosition == OutsideMapFrame )
815834 {
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;
818837 }
819838 else
820839 {
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 ;
823842 }
824843 }
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;
827865 }
828866
829867 // then annotations for horizontal grid lines
@@ -835,40 +873,72 @@ void QgsComposerMap::drawGridAnnotations( QPainter* p, const QList< QPair< doubl
835873 {
836874 rotation = 270 ;
837875 }
876+
877+ loopCounter = 0 ;
838878 QList< QPair< double , QLineF > >::const_iterator hIt = hLines.constBegin ();
839879 for ( ; hIt != hLines.constEnd (); ++hIt )
840880 {
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+
842890 currentFontWidth = textWidthMillimeters ( mGridAnnotationFont , currentAnnotationString );
843891 if ( mGridAnnotationDirection == Vertical )
844892 {
893+ ypos1 = hIt->second .y1 () + currentFontWidth / 2.0 ;
894+ ypos2 = hIt->second .y2 () + currentFontWidth / 2.0 ;
845895 if ( mGridAnnotationPosition == OutsideMapFrame )
846896 {
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;
849899 }
850900 else
851901 {
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 ;
854904 }
855905 }
856906 else
857907 {
908+ ypos1 = hIt->second .y1 () + currentFontHeight / 2.0 ;
909+ ypos2 = hIt->second .y2 () + currentFontHeight / 2.0 ;
858910 if ( mGridAnnotationPosition == OutsideMapFrame )
859911 {
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 ;
862914 }
863915 else
864916 {
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 );
867919 }
868920 }
869921
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;
872942 }
873943}
874944
0 commit comments