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

svn_qgis at osgeo.org svn_qgis at osgeo.org
Thu Oct 15 11:02:02 EDT 2009


Author: mhugent
Date: 2009-10-15 11:02:01 -0400 (Thu, 15 Oct 2009)
New Revision: 11811

Modified:
   trunk/qgis/src/app/composer/qgscomposermapwidget.cpp
   trunk/qgis/src/app/composer/qgscomposermapwidget.h
   trunk/qgis/src/core/composer/qgscomposermap.cpp
   trunk/qgis/src/core/composer/qgscomposermap.h
   trunk/qgis/src/ui/qgscomposermapwidgetbase.ui
Log:
Grid annotation can be with coordinates or 1A, 1B, ...

Modified: trunk/qgis/src/app/composer/qgscomposermapwidget.cpp
===================================================================
--- trunk/qgis/src/app/composer/qgscomposermapwidget.cpp	2009-10-15 13:22:08 UTC (rev 11810)
+++ trunk/qgis/src/app/composer/qgscomposermapwidget.cpp	2009-10-15 15:02:01 UTC (rev 11811)
@@ -54,6 +54,9 @@
   mAnnotationDirectionComboBox->insertItem( 0, tr( "Horizontal" ) );
   mAnnotationDirectionComboBox->insertItem( 1, tr( "Vertical" ) );
   mAnnotationDirectionComboBox->insertItem( 2, tr( "Horizontal and Vertical" ) );
+
+  mAnnotationTypeComboBox->insertItem( 0, tr( "Coordinate" ) );
+  mAnnotationTypeComboBox->insertItem( 1, tr( "Sector" ) );
   blockAllSignals( false );
 
   if ( composerMap )
@@ -340,7 +343,17 @@
       mAnnotationDirectionComboBox->setCurrentIndex( mAnnotationDirectionComboBox->findText( tr( "Horizontal and Vertical" ) ) );
     }
 
+    QgsComposerMap::GridAnnotationType type = mComposerMap->gridAnnotationType();
+    if ( type == QgsComposerMap::Sector )
+    {
+      mAnnotationTypeComboBox->setCurrentIndex( mAnnotationTypeComboBox->findText( tr( "Sector" ) ) );
+    }
+    else
+    {
+      mAnnotationTypeComboBox->setCurrentIndex( mAnnotationTypeComboBox->findText( tr( "Coordinate" ) ) );
+    }
 
+
     QPen gridPen = mComposerMap->gridPen();
     mLineWidthSpinBox->setValue( gridPen.widthF() );
     mLineColorButton->setColor( gridPen.color() );
@@ -397,6 +410,7 @@
   mAnnotationPositionComboBox->blockSignals( b );
   mDistanceToMapFrameSpinBox->blockSignals( b );
   mAnnotationDirectionComboBox->blockSignals( b );
+  mAnnotationTypeComboBox->blockSignals( b );
 }
 
 void QgsComposerMapWidget::on_mUpdatePreviewButton_clicked()
@@ -639,3 +653,21 @@
   mComposerMap->updateBoundingRect();
   mComposerMap->update();
 }
+
+void QgsComposerMapWidget::on_mAnnotationTypeComboBox_currentIndexChanged( const QString& text )
+{
+  if ( !mComposerMap )
+  {
+    return;
+  }
+
+  if ( text == tr( "Sector" ) )
+  {
+    mComposerMap->setGridAnnotationType( QgsComposerMap::Sector );
+  }
+  else
+  {
+    mComposerMap->setGridAnnotationType( QgsComposerMap::Coordinate );
+  }
+  mComposerMap->update();
+}

Modified: trunk/qgis/src/app/composer/qgscomposermapwidget.h
===================================================================
--- trunk/qgis/src/app/composer/qgscomposermapwidget.h	2009-10-15 13:22:08 UTC (rev 11810)
+++ trunk/qgis/src/app/composer/qgscomposermapwidget.h	2009-10-15 15:02:01 UTC (rev 11811)
@@ -61,6 +61,7 @@
     void on_mAnnotationPositionComboBox_currentIndexChanged( const QString& text );
     void on_mDrawAnnotationCheckBox_stateChanged( int state );
     void on_mAnnotationDirectionComboBox_currentIndexChanged( const QString& text );
+    void on_mAnnotationTypeComboBox_currentIndexChanged( const QString& text );
 
     /**Updates width and height without notify the composer map (to avoid infinite recursion)*/
     void updateSettingsNoSignals();

Modified: trunk/qgis/src/core/composer/qgscomposermap.cpp
===================================================================
--- trunk/qgis/src/core/composer/qgscomposermap.cpp	2009-10-15 13:22:08 UTC (rev 11810)
+++ trunk/qgis/src/core/composer/qgscomposermap.cpp	2009-10-15 15:02:01 UTC (rev 11811)
@@ -44,7 +44,7 @@
 QgsComposerMap::QgsComposerMap( QgsComposition *composition, int x, int y, int width, int height )
     : QgsComposerItem( x, y, width, height, composition ), mKeepLayerSet( false ), mGridEnabled( false ), mGridStyle( Solid ), \
     mGridIntervalX( 0.0 ), mGridIntervalY( 0.0 ), mGridOffsetX( 0.0 ), mGridOffsetY( 0.0 ), mShowGridAnnotation( false ), \
-    mGridAnnotationPosition( OutsideMapFrame ), mAnnotationFrameDistance( 1.0 ), mGridAnnotationDirection( Horizontal )
+    mGridAnnotationPosition( OutsideMapFrame ), mAnnotationFrameDistance( 1.0 ), mGridAnnotationDirection( Horizontal ), mGridAnnotationType( Coordinate )
 {
   mComposition = composition;
   mMapRenderer = mComposition->mapRenderer();
@@ -74,7 +74,7 @@
 QgsComposerMap::QgsComposerMap( QgsComposition *composition )
     : QgsComposerItem( 0, 0, 10, 10, composition ), mKeepLayerSet( false ), mGridEnabled( false ), mGridStyle( Solid ), \
     mGridIntervalX( 0.0 ), mGridIntervalY( 0.0 ), mGridOffsetX( 0.0 ), mGridOffsetY( 0.0 ), mShowGridAnnotation( false ), \
-    mGridAnnotationPosition( OutsideMapFrame ), mAnnotationFrameDistance( 1.0 ), mGridAnnotationDirection( Horizontal )
+    mGridAnnotationPosition( OutsideMapFrame ), mAnnotationFrameDistance( 1.0 ), mGridAnnotationDirection( Horizontal ), mGridAnnotationType( Coordinate )
 {
   //Offset
   mXOffset = 0.0;
@@ -568,6 +568,7 @@
   annotationElem.setAttribute( "frameDistance", mAnnotationFrameDistance );
   annotationElem.setAttribute( "direction", mGridAnnotationDirection );
   annotationElem.setAttribute( "font", mGridAnnotationFont.toString() );
+  annotationElem.setAttribute( "type", mGridAnnotationType);
 
   gridElem.appendChild( annotationElem );
   composerMapElem.appendChild( gridElem );
@@ -668,6 +669,7 @@
       mAnnotationFrameDistance = annotationElem.attribute( "frameDistance", "0" ).toDouble();
       mGridAnnotationDirection = QgsComposerMap::GridAnnotationDirection( annotationElem.attribute( "direction", "0" ).toInt() );
       mGridAnnotationFont.fromString( annotationElem.attribute( "font", "" ) );
+      mGridAnnotationType = QgsComposerMap::GridAnnotationType( annotationElem.attribute( "type", "0" ).toInt() );
     }
   }
 
@@ -785,45 +787,81 @@
   double currentFontHeight = fontAscentMillimeters( mGridAnnotationFont );
   QPointF currentAnnotationPos1, currentAnnotationPos2;
   double rotation = 0;
+  double xpos1, xpos2, ypos1, ypos2;
 
   //first draw annotations for vertical grid lines
   if ( mGridAnnotationDirection != Horizontal )
   {
     rotation = 270;
   }
+
+
   QList< QPair< double, QLineF > >::const_iterator vIt = vLines.constBegin();
+  int loopCounter = 0;
   for ( ; vIt != vLines.constEnd(); ++vIt )
   {
-    currentAnnotationString = QString::number( vIt->first );
+    if ( mGridAnnotationType == Sector )
+    {
+      int letterNumber = loopCounter % 26 + 66;
+      currentAnnotationString = QString( QChar( letterNumber ) );
+    }
+    else
+    {
+      currentAnnotationString = QString::number( vIt->first );
+    }
+
     currentFontWidth = textWidthMillimeters( mGridAnnotationFont, currentAnnotationString );
     if ( mGridAnnotationDirection == Horizontal )
     {
+      xpos1 = vIt->second.x1() - currentFontWidth / 2.0;
+      xpos2 = vIt->second.x2() - currentFontWidth / 2.0;
       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 );
+        ypos1 = vIt->second.y1() - mAnnotationFrameDistance;
+        ypos2 = 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 );
+        ypos1 = vIt->second.y1() + mAnnotationFrameDistance + currentFontHeight;
+        ypos2 = vIt->second.y2() - mAnnotationFrameDistance;
       }
     }
     else //vertical annotation
     {
+      xpos1 = vIt->second.x1() + currentFontHeight / 2.0;
+      xpos2 = vIt->second.x2() + currentFontHeight / 2.0;
       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 );
+        ypos1 = vIt->second.y1() - mAnnotationFrameDistance;
+        ypos2 = 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 );
+        ypos1 = vIt->second.y1() + currentFontWidth + mAnnotationFrameDistance;
+        ypos2 = vIt->second.y2() - mAnnotationFrameDistance;
       }
     }
-    drawAnnotation( p, currentAnnotationPos1, rotation, currentAnnotationString );
-    drawAnnotation( p, currentAnnotationPos2, rotation, currentAnnotationString );
+
+    //shift positions in case of sector annotation
+    if ( mGridAnnotationType == Sector && loopCounter < ( vLines.size() - 1 ) )
+    {
+      xpos1 += ( vLines.at( loopCounter + 1 ).second.x1() - vLines.at( loopCounter ).second.x1() ) / 2.0;
+      xpos2 += ( vLines.at( loopCounter + 1 ).second.x2() - vLines.at( loopCounter ).second.x2() ) / 2.0;
+    }
+    else if ( mGridAnnotationType == Sector && loopCounter == ( vLines.size() - 1 ) )
+    {
+      xpos1 += ( rect().width() - vLines.at( loopCounter ).second.x1() ) / 2.0;
+      xpos2 += ( rect().width() - vLines.at( loopCounter ).second.x2() ) / 2.0;
+    }
+    drawAnnotation( p, QPointF( xpos1, ypos1 ), rotation, currentAnnotationString );
+    drawAnnotation( p, QPointF( xpos1, ypos2 ), rotation, currentAnnotationString );
+
+    if ( mGridAnnotationType == Sector && loopCounter == 0 )
+    {
+      drawAnnotation( p, QPointF( vLines.at( loopCounter ).second.x1() / 2.0, ypos1 ), rotation, "A" );
+      drawAnnotation( p, QPointF( vLines.at( loopCounter ).second.x2() / 2.0, ypos2 ), rotation, "A" );
+    }
+    ++loopCounter;
   }
 
   //then annotations for horizontal grid lines
@@ -835,40 +873,72 @@
   {
     rotation = 270;
   }
+
+  loopCounter = 0;
   QList< QPair< double, QLineF > >::const_iterator hIt = hLines.constBegin();
   for ( ; hIt != hLines.constEnd(); ++hIt )
   {
-    currentAnnotationString = QString::number( hIt->first );
+    if ( mGridAnnotationType == Sector )
+    {
+      currentAnnotationString = QString::number( hLines.size() - loopCounter - 1 );
+    }
+    else
+    {
+      currentAnnotationString = QString::number( hIt->first );
+    }
+
     currentFontWidth = textWidthMillimeters( mGridAnnotationFont, currentAnnotationString );
     if ( mGridAnnotationDirection == Vertical )
     {
+      ypos1 = hIt->second.y1() + currentFontWidth / 2.0;
+      ypos2 = hIt->second.y2() + currentFontWidth / 2.0;
       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 );
+        xpos1 = hIt->second.x1() - mAnnotationFrameDistance;
+        xpos2 = hIt->second.x2() + mAnnotationFrameDistance + currentFontHeight;
       }
       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 );
+        xpos1 = hIt->second.x1() + mAnnotationFrameDistance + currentFontHeight;
+        xpos2 = hIt->second.x2() - mAnnotationFrameDistance;
       }
     }
     else
     {
+      ypos1 = hIt->second.y1() + currentFontHeight / 2.0;
+      ypos2 = hIt->second.y2() + currentFontHeight / 2.0;
       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 );
+        xpos1 = hIt->second.x1() - ( mAnnotationFrameDistance + currentFontWidth );
+        xpos2 = hIt->second.x2() + mAnnotationFrameDistance;
       }
       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 );
+        xpos1 = hIt->second.x1() + mAnnotationFrameDistance;
+        xpos2 = hIt->second.x2() - ( mAnnotationFrameDistance + currentFontWidth );
       }
     }
 
-    drawAnnotation( p, currentAnnotationPos1, rotation, currentAnnotationString );
-    drawAnnotation( p, currentAnnotationPos2, rotation, currentAnnotationString );
+    //shift y-Positions in case of sectoral annotations
+    if ( mGridAnnotationType == Sector && loopCounter < ( hLines.size() - 1 ) )
+    {
+      ypos1 += ( hLines.at( loopCounter + 1 ).second.y1() - hLines.at( loopCounter ).second.y1() ) / 2.0;
+      ypos2 += ( hLines.at( loopCounter + 1 ).second.y2() - hLines.at( loopCounter ).second.y2() ) / 2.0;
+    }
+    else if ( mGridAnnotationType == Sector && loopCounter == ( hLines.size() - 1 ) )
+    {
+      ypos1 -= hLines.at( loopCounter ).second.y1() / 2.0;
+      ypos2 -= hLines.at( loopCounter ).second.y2() / 2.0;
+    }
+
+    drawAnnotation( p, QPointF( xpos1, ypos1 ), rotation, currentAnnotationString );
+    drawAnnotation( p, QPointF( xpos2, ypos2 ), rotation, currentAnnotationString );
+    if ( mGridAnnotationType == Sector && loopCounter == 0 )
+    {
+      drawAnnotation( p, QPointF( xpos1, ( rect().height() + hLines.at( loopCounter ).second.y1() ) / 2.0 ), rotation, QString::number( hLines.size() ) );
+      drawAnnotation( p, QPointF( xpos2, ( rect().height() + hLines.at( loopCounter ).second.y2() ) / 2.0 ), rotation, QString::number( hLines.size() ) );
+    }
+    ++loopCounter;
   }
 }
 

Modified: trunk/qgis/src/core/composer/qgscomposermap.h
===================================================================
--- trunk/qgis/src/core/composer/qgscomposermap.h	2009-10-15 13:22:08 UTC (rev 11810)
+++ trunk/qgis/src/core/composer/qgscomposermap.h	2009-10-15 15:02:01 UTC (rev 11811)
@@ -73,6 +73,12 @@
       HorizontalAndVertical
     };
 
+    enum GridAnnotationType
+    {
+      Coordinate = 0, //annotation at line, displays coordinates
+      Sector //annotation at sector: 1, 2, 3 for horizontal lines and A, B, C for vertical ones
+    };
+
     /** \brief Draw to paint device
     @param extent map extent
     @param size size in scene coordinates
@@ -198,6 +204,9 @@
     void setGridAnnotationDirection( GridAnnotationDirection d ) {mGridAnnotationDirection = d;}
     GridAnnotationDirection gridAnnotationDirection() const {return mGridAnnotationDirection;}
 
+    void setGridAnnotationType( GridAnnotationType t ) {mGridAnnotationType = t;}
+    GridAnnotationType gridAnnotationType() const {return mGridAnnotationType; }
+
     /**In case of annotations, the bounding rectangle can be larger than the map item rectangle*/
     QRectF boundingRect() const;
     /**Updates the bounding rect of this item. Call this function before doing any changes related to annotation out of the map rectangle*/
@@ -287,6 +296,8 @@
     double mAnnotationFrameDistance;
     /**Annotation can be horizontal / vertical or different for axes*/
     GridAnnotationDirection mGridAnnotationDirection;
+    /**Coordinate values (default) or sector (1A, 1B, ...)*/
+    GridAnnotationType mGridAnnotationType;
     /**Current bounding rectangle. This is used to check if notification to the graphics scene is necessary*/
     QRectF mCurrentRectangle;
 

Modified: trunk/qgis/src/ui/qgscomposermapwidgetbase.ui
===================================================================
--- trunk/qgis/src/ui/qgscomposermapwidgetbase.ui	2009-10-15 13:22:08 UTC (rev 11810)
+++ trunk/qgis/src/ui/qgscomposermapwidgetbase.ui	2009-10-15 15:02:01 UTC (rev 11811)
@@ -7,7 +7,7 @@
     <x>0</x>
     <y>0</y>
     <width>472</width>
-    <height>657</height>
+    <height>675</height>
    </rect>
   </property>
   <property name="sizePolicy">
@@ -281,7 +281,7 @@
          </property>
         </widget>
        </item>
-       <item row="1" column="1" colspan="3">
+       <item row="1" column="1" colspan="2">
         <widget class="QComboBox" name="mGridTypeComboBox"/>
        </item>
        <item row="2" column="0">
@@ -291,21 +291,21 @@
          </property>
         </widget>
        </item>
-       <item row="2" column="1" colspan="3">
+       <item row="2" column="1" colspan="2">
         <widget class="QDoubleSpinBox" name="mIntervalXSpinBox">
          <property name="maximum">
           <double>999999.000000000000000</double>
          </property>
         </widget>
        </item>
-       <item row="2" column="5">
+       <item row="2" column="3">
         <widget class="QLabel" name="mIntervalYLabel">
          <property name="text">
           <string>Interval Y:</string>
          </property>
         </widget>
        </item>
-       <item row="2" column="6">
+       <item row="2" column="4">
         <widget class="QDoubleSpinBox" name="mIntervalYSpinBox">
          <property name="maximum">
           <double>9999999.000000000000000</double>
@@ -319,21 +319,21 @@
          </property>
         </widget>
        </item>
-       <item row="3" column="1" colspan="3">
+       <item row="3" column="1" colspan="2">
         <widget class="QDoubleSpinBox" name="mOffsetXSpinBox">
          <property name="maximum">
           <double>9999999.000000000000000</double>
          </property>
         </widget>
        </item>
-       <item row="3" column="5">
+       <item row="3" column="3">
         <widget class="QLabel" name="mOffsetYLabel">
          <property name="text">
           <string>Offset Y:</string>
          </property>
         </widget>
        </item>
-       <item row="3" column="6">
+       <item row="3" column="4">
         <widget class="QDoubleSpinBox" name="mOffsetYSpinBox">
          <property name="maximum">
           <double>9999999.000000000000000</double>
@@ -347,17 +347,17 @@
          </property>
         </widget>
        </item>
-       <item row="4" column="1" colspan="3">
+       <item row="4" column="1" colspan="2">
         <widget class="QDoubleSpinBox" name="mLineWidthSpinBox"/>
        </item>
-       <item row="4" column="4" colspan="2">
+       <item row="4" column="3">
         <widget class="QLabel" name="mLineColorLabel">
          <property name="text">
           <string>Line color:</string>
          </property>
         </widget>
        </item>
-       <item row="4" column="6">
+       <item row="4" column="4">
         <widget class="QgsColorButton" name="mLineColorButton">
          <property name="sizePolicy">
           <sizepolicy hsizetype="Preferred" vsizetype="Preferred">
@@ -384,10 +384,10 @@
          </property>
         </widget>
        </item>
-       <item row="6" column="2" colspan="2">
+       <item row="6" column="2">
         <widget class="QComboBox" name="mAnnotationPositionComboBox"/>
        </item>
-       <item row="6" column="5">
+       <item row="6" column="3">
         <widget class="QLabel" name="mAnnotationDirectionLabel">
          <property name="frameShape">
           <enum>QFrame::NoFrame</enum>
@@ -397,20 +397,30 @@
          </property>
         </widget>
        </item>
-       <item row="6" column="6">
+       <item row="6" column="4">
         <widget class="QComboBox" name="mAnnotationDirectionComboBox"/>
        </item>
-       <item row="7" column="0" colspan="3">
+       <item row="7" column="0" colspan="2">
         <widget class="QLabel" name="mDistanceToFrameLabel">
          <property name="text">
           <string>Distance to map frame:</string>
          </property>
         </widget>
        </item>
-       <item row="7" column="3" colspan="2">
+       <item row="7" column="2">
         <widget class="QDoubleSpinBox" name="mDistanceToMapFrameSpinBox"/>
        </item>
-       <item row="7" column="6">
+       <item row="7" column="3">
+        <widget class="QLabel" name="mAnnotationTypeLabel">
+         <property name="text">
+          <string>Annotation type:</string>
+         </property>
+        </widget>
+       </item>
+       <item row="7" column="4">
+        <widget class="QComboBox" name="mAnnotationTypeComboBox"/>
+       </item>
+       <item row="8" column="0">
         <widget class="QPushButton" name="mAnnotationFontButton">
          <property name="text">
           <string>Font...</string>



More information about the QGIS-commit mailing list