[QGIS Commit] r11796 - in trunk/qgis/src: app/composer core/composer

svn_qgis at osgeo.org svn_qgis at osgeo.org
Mon Oct 12 09:16:03 EDT 2009


Author: mhugent
Date: 2009-10-12 09:16:02 -0400 (Mon, 12 Oct 2009)
New Revision: 11796

Modified:
   trunk/qgis/src/app/composer/qgscomposermapwidget.cpp
   trunk/qgis/src/core/composer/qgscomposeritem.cpp
   trunk/qgis/src/core/composer/qgscomposermap.cpp
   trunk/qgis/src/core/composer/qgscomposermap.h
Log:
Possibility to have annotations horizontally or vertically in the composer grid

Modified: trunk/qgis/src/app/composer/qgscomposermapwidget.cpp
===================================================================
--- trunk/qgis/src/app/composer/qgscomposermapwidget.cpp	2009-10-12 08:55:12 UTC (rev 11795)
+++ trunk/qgis/src/app/composer/qgscomposermapwidget.cpp	2009-10-12 13:16:02 UTC (rev 11796)
@@ -25,7 +25,6 @@
 QgsComposerMapWidget::QgsComposerMapWidget( QgsComposerMap* composerMap ): QWidget(), mComposerMap( composerMap )
 {
   setupUi( this );
-  mAnnotationDirectionComboBox->setEnabled( false ); //not yet supported
 
   //add widget for general composer item properties
   QgsComposerItemWidget* itemPropertiesWidget = new QgsComposerItemWidget( this, composerMap );

Modified: trunk/qgis/src/core/composer/qgscomposeritem.cpp
===================================================================
--- trunk/qgis/src/core/composer/qgscomposeritem.cpp	2009-10-12 08:55:12 UTC (rev 11795)
+++ trunk/qgis/src/core/composer/qgscomposeritem.cpp	2009-10-12 13:16:02 UTC (rev 11796)
@@ -717,7 +717,7 @@
 double QgsComposerItem::fontAscentMillimeters( const QFont& font ) const
 {
   QFont metricsFont = scaledFontPixelSize( font );
-  QFontMetrics fontMetrics( metricsFont );
+  QFontMetricsF fontMetrics( metricsFont );
   return ( fontMetrics.ascent() / FONT_WORKAROUND_SCALE );
 }
 

Modified: trunk/qgis/src/core/composer/qgscomposermap.cpp
===================================================================
--- trunk/qgis/src/core/composer/qgscomposermap.cpp	2009-10-12 08:55:12 UTC (rev 11795)
+++ trunk/qgis/src/core/composer/qgscomposermap.cpp	2009-10-12 13:16:02 UTC (rev 11796)
@@ -783,44 +783,104 @@
   QString currentAnnotationString;
   double currentFontWidth = 0;
   double currentFontHeight = fontAscentMillimeters( mGridAnnotationFont );
+  QPointF currentAnnotationPos1, currentAnnotationPos2;
+  double rotation = 0;
 
+  //first draw annotations for vertical grid lines
+  if ( mGridAnnotationDirection != Horizontal )
+  {
+    rotation = 270;
+  }
   QList< QPair< double, QLineF > >::const_iterator vIt = vLines.constBegin();
   for ( ; vIt != vLines.constEnd(); ++vIt )
   {
     currentAnnotationString = QString::number( vIt->first );
     currentFontWidth = textWidthMillimeters( mGridAnnotationFont, currentAnnotationString );
-
-    if ( mGridAnnotationPosition == OutsideMapFrame )
+    if ( mGridAnnotationDirection == Horizontal )
     {
-      drawText( p, vIt->second.x1() - currentFontWidth / 2.0, vIt->second.y1() - mAnnotationFrameDistance, currentAnnotationString, mGridAnnotationFont );
-      drawText( p, vIt->second.x2() - currentFontWidth / 2.0, vIt->second.y2() + mAnnotationFrameDistance + currentFontHeight, currentAnnotationString, mGridAnnotationFont );
+      if ( mGridAnnotationPosition == OutsideMapFrame )
+      {
+        currentAnnotationPos1 = QPointF( vIt->second.x1() - currentFontWidth / 2.0, vIt->second.y1() - mAnnotationFrameDistance );
+        currentAnnotationPos2 = QPointF( vIt->second.x2() - currentFontWidth / 2.0, vIt->second.y2() + mAnnotationFrameDistance + currentFontHeight );
+      }
+      else
+      {
+        currentAnnotationPos1 = QPointF( vIt->second.x1() - currentFontWidth / 2.0, vIt->second.y1() + mAnnotationFrameDistance + currentFontHeight );
+        currentAnnotationPos2 = QPointF( vIt->second.x2() - currentFontWidth / 2.0, vIt->second.y2() - mAnnotationFrameDistance );
+      }
     }
-    else
+    else //vertical annotation
     {
-      drawText( p, vIt->second.x1() - currentFontWidth / 2.0, vIt->second.y1() + mAnnotationFrameDistance + currentFontHeight, currentAnnotationString, mGridAnnotationFont );
-      drawText( p, vIt->second.x2() - currentFontWidth / 2.0, vIt->second.y2() - mAnnotationFrameDistance, currentAnnotationString, mGridAnnotationFont );
+      if ( mGridAnnotationPosition == OutsideMapFrame )
+      {
+        currentAnnotationPos1 = QPointF( vIt->second.x1() + currentFontHeight / 2.0, vIt->second.y1() - mAnnotationFrameDistance );
+        currentAnnotationPos2 = QPointF( vIt->second.x2() + currentFontHeight / 2.0, vIt->second.y2() + mAnnotationFrameDistance + currentFontWidth );
+      }
+      else
+      {
+        currentAnnotationPos1 = QPointF( vIt->second.x1() + currentFontHeight / 2.0, vIt->second.y1() + currentFontWidth + mAnnotationFrameDistance );
+        currentAnnotationPos2 = QPointF( vIt->second.x1() + currentFontHeight / 2.0, vIt->second.y2() - mAnnotationFrameDistance );
+      }
     }
+    drawAnnotation( p, currentAnnotationPos1, rotation, currentAnnotationString );
+    drawAnnotation( p, currentAnnotationPos2, rotation, currentAnnotationString );
   }
 
+  //then annotations for horizontal grid lines
+  if ( mGridAnnotationDirection != Vertical )
+  {
+    rotation = 0;
+  }
+  else
+  {
+    rotation = 270;
+  }
   QList< QPair< double, QLineF > >::const_iterator hIt = hLines.constBegin();
   for ( ; hIt != hLines.constEnd(); ++hIt )
   {
     currentAnnotationString = QString::number( hIt->first );
     currentFontWidth = textWidthMillimeters( mGridAnnotationFont, currentAnnotationString );
-
-    if ( mGridAnnotationPosition == OutsideMapFrame )
+    if ( mGridAnnotationDirection == Vertical )
     {
-      drawText( p, hIt->second.x1() - ( mAnnotationFrameDistance + currentFontWidth ), hIt->second.y1() + currentFontHeight / 2.0, currentAnnotationString, mGridAnnotationFont );
-      drawText( p, hIt->second.x2() + mAnnotationFrameDistance, hIt->second.y2() + currentFontHeight / 2.0, currentAnnotationString, mGridAnnotationFont );
+      if ( mGridAnnotationPosition == OutsideMapFrame )
+      {
+        currentAnnotationPos1 = QPointF( hIt->second.x1() - mAnnotationFrameDistance, hIt->second.y1() + currentFontWidth / 2.0 );
+        currentAnnotationPos2 = QPointF( hIt->second.x2() + mAnnotationFrameDistance + currentFontHeight, hIt->second.y2() + currentFontWidth / 2.0 );
+      }
+      else
+      {
+        currentAnnotationPos1 = QPointF( hIt->second.x1() + mAnnotationFrameDistance + currentFontHeight, hIt->second.y1() + currentFontWidth / 2.0 );
+        currentAnnotationPos2 = QPointF( hIt->second.x2() - mAnnotationFrameDistance, hIt->second.y1() + currentFontWidth / 2.0 );
+      }
     }
     else
     {
-      drawText( p, hIt->second.x1() + mAnnotationFrameDistance, hIt->second.y1() + currentFontHeight / 2.0, currentAnnotationString, mGridAnnotationFont );
-      drawText( p, hIt->second.x2() - ( mAnnotationFrameDistance + currentFontWidth ), hIt->second.y2() + currentFontHeight / 2.0, currentAnnotationString, mGridAnnotationFont );
+      if ( mGridAnnotationPosition == OutsideMapFrame )
+      {
+        currentAnnotationPos1 = QPointF( hIt->second.x1() - ( mAnnotationFrameDistance + currentFontWidth ), hIt->second.y1() + currentFontHeight / 2.0 );
+        currentAnnotationPos2 = QPointF( hIt->second.x2() + mAnnotationFrameDistance, hIt->second.y2() + currentFontHeight / 2.0 );
+      }
+      else
+      {
+        currentAnnotationPos1 = QPointF( hIt->second.x1() + mAnnotationFrameDistance, hIt->second.y1() + currentFontHeight / 2.0 );
+        currentAnnotationPos2 = QPointF( hIt->second.x2() - ( mAnnotationFrameDistance + currentFontWidth ), hIt->second.y2() + currentFontHeight / 2.0 );
+      }
     }
+
+    drawAnnotation( p, currentAnnotationPos1, rotation, currentAnnotationString );
+    drawAnnotation( p, currentAnnotationPos2, rotation, currentAnnotationString );
   }
 }
 
+void QgsComposerMap::drawAnnotation( QPainter* p, const QPointF& pos, int rotation, const QString& annotationText )
+{
+  p->save();
+  p->translate( pos );
+  p->rotate( rotation );
+  drawText( p, 0, 0, annotationText, mGridAnnotationFont );
+  p->restore();
+}
+
 int QgsComposerMap::verticalGridLines( QList< QPair< double, QLineF > >& lines ) const
 {
   lines.clear();

Modified: trunk/qgis/src/core/composer/qgscomposermap.h
===================================================================
--- trunk/qgis/src/core/composer/qgscomposermap.h	2009-10-12 08:55:12 UTC (rev 11795)
+++ trunk/qgis/src/core/composer/qgscomposermap.h	2009-10-12 13:16:02 UTC (rev 11796)
@@ -294,6 +294,12 @@
     void drawGrid( QPainter* p );
     /**Annotations for composer grid*/
     void drawGridAnnotations( QPainter* p, const QList< QPair< double, QLineF > >& hLines, const QList< QPair< double, QLineF > >& vLines );
+    /**Draws a single annotation
+        @param p drawing painter
+        @param pos item coordinates where to draw
+        @param rotation text rotation
+        @param the text to draw*/
+    void drawAnnotation( QPainter* p, const QPointF& pos, int rotation, const QString& annotationText );
     /**Calculates the horizontal grid lines
         @lines list containing the map coordinates and the lines in item coordinates
         @return 0 in case of success*/



More information about the QGIS-commit mailing list