Skip to content

Commit

Permalink
Possibility to choose the precision of composer grid annotations
Browse files Browse the repository at this point in the history
git-svn-id: http://svn.osgeo.org/qgis/trunk@11849 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
mhugent committed Oct 26, 2009
1 parent 80bd5f0 commit ee19d5f
Show file tree
Hide file tree
Showing 6 changed files with 116 additions and 9 deletions.
45 changes: 43 additions & 2 deletions python/core/qgscomposermap.sip
Expand Up @@ -131,52 +131,93 @@ class QgsComposerMap : QObject, QgsComposerItem
*/
bool readXML( const QDomElement& itemElem, const QDomDocument& doc );

/**Enables a coordinate grid that is shown on top of this composermap.
@note this function was added in version 1.4*/
void setGridEnabled( bool enabled );
bool gridEnabled() const;

/**Sets coordinate grid style to solid or cross
@note this function was added in version 1.4*/
void setGridStyle( GridStyle style );
GridStyle gridStyle() const;

/**Sets coordinate interval in x-direction for composergrid.
@note this function was added in version 1.4*/
void setGridIntervalX( double interval );
double gridIntervalX() const;

/**Sets coordinate interval in y-direction for composergrid.
@note this function was added in version 1.4*/
void setGridIntervalY( double interval );
double gridIntervalY() const;

/**Sets x-coordinate offset for composer grid
@note this function was added in version 1.4*/
void setGridOffsetX( double offset );
double gridOffsetX() const;

/**Sets y-coordinate offset for composer grid
@note this function was added in version 1.4*/
void setGridOffsetY( double offset );
double gridOffsetY() const;

/**Sets the pen to draw composer grid
@note this function was added in version 1.4*/
void setGridPen( const QPen& p );
QPen gridPen() const;

/**Sets with of grid pen
@note this function was added in version 1.4*/
void setGridPenWidth( double w );

/**Sets the color of the grid pen
@note this function was added in version 1.4*/
void setGridPenColor( const QColor& c );

/**Sets font for grid annotations
@note this function was added in version 1.4*/
void setGridAnnotationFont( const QFont& f );
QFont gridAnnotationFont() const;

/**Sets coordinate precision for grid annotations
@note this function was added in version 1.4*/
void setGridAnnotationPrecision( int p );
int gridAnnotationPrecision() const;

/**Sets flag if grid annotation should be shown
@note this function was added in version 1.4*/
void setShowGridAnnotation( bool show );
bool showGridAnnotation() const;

/**Sets position of grid annotations. Possibilities are inside or outside of the map frame
@note this function was added in version 1.4*/
void setGridAnnotationPosition( GridAnnotationPosition p );
GridAnnotationPosition gridAnnotationPosition() const;

/**Sets distance between map frame and annotations
@note this function was added in version 1.4*/
void setAnnotationFrameDistance( double d ) {mAnnotationFrameDistance = d;}
double annotationFrameDistance() const {return mAnnotationFrameDistance;}

/**Sets grid annotation direction. Can be horizontal, vertical, direction of axis and horizontal and vertical
@note this function was added in version 1.4*/
void setGridAnnotationDirection( GridAnnotationDirection d );
GridAnnotationDirection gridAnnotationDirection() const;

/**In case of annotations, the bounding rectangle can be larger than the map item rectangle*/
/**In case of annotations, the bounding rectangle can be larger than the map item rectangle
@note this function was added in version 1.4*/
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*/
/**Updates the bounding rect of this item. Call this function before doing any changes related to annotation out of the map rectangle
@note this function was added in version 1.4*/
void updateBoundingRect();

/**Sets the rotation of the map content
@note this function was added in version 1.4*/
void setRotation(double r);
double rotation() const;

/**Sets length of the cros segments (if grid style is cross)
@note this function was added in version 1.4*/
void setCrossLength(double l);
double crossLength();

Expand Down
12 changes: 12 additions & 0 deletions src/app/composer/qgscomposermapwidget.cpp
Expand Up @@ -365,6 +365,7 @@ void QgsComposerMapWidget::updateGuiElements()
mAnnotationDirectionComboBox->setCurrentIndex( mAnnotationDirectionComboBox->findText( tr( "Boundary direction" ) ) );
}

mCoordinatePrecisionSpinBox->setValue( mComposerMap->gridAnnotationPrecision() );

QPen gridPen = mComposerMap->gridPen();
mLineWidthSpinBox->setValue( gridPen.widthF() );
Expand Down Expand Up @@ -423,6 +424,7 @@ void QgsComposerMapWidget::blockAllSignals( bool b )
mAnnotationPositionComboBox->blockSignals( b );
mDistanceToMapFrameSpinBox->blockSignals( b );
mAnnotationDirectionComboBox->blockSignals( b );
mCoordinatePrecisionSpinBox->blockSignals( b );
}

void QgsComposerMapWidget::on_mUpdatePreviewButton_clicked()
Expand Down Expand Up @@ -692,3 +694,13 @@ void QgsComposerMapWidget::on_mShowGridDialogCheckBox_stateChanged( int state )
mGridWidget->setVisible( false );
}
}

void QgsComposerMapWidget::on_mCoordinatePrecisionSpinBox_valueChanged( int value )
{
if ( !mComposerMap )
{
return;
}
mComposerMap->setGridAnnotationPrecision( value );
mComposerMap->update();
}
1 change: 1 addition & 0 deletions src/app/composer/qgscomposermapwidget.h
Expand Up @@ -64,6 +64,7 @@ class QgsComposerMapWidget: public QWidget, private Ui::QgsComposerMapWidgetBase
void on_mDrawAnnotationCheckBox_stateChanged( int state );
void on_mAnnotationDirectionComboBox_currentIndexChanged( const QString& text );
void on_mShowGridDialogCheckBox_stateChanged( int state );
void on_mCoordinatePrecisionSpinBox_valueChanged( int value );

/**Updates width and height without notify the composer map (to avoid infinite recursion)*/
void updateSettingsNoSignals();
Expand Down
10 changes: 6 additions & 4 deletions src/core/composer/qgscomposermap.cpp
Expand Up @@ -43,7 +43,7 @@ int QgsComposerMap::mCurrentComposerId = 0;

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 ), \
mGridIntervalX( 0.0 ), mGridIntervalY( 0.0 ), mGridOffsetX( 0.0 ), mGridOffsetY( 0.0 ), mGridAnnotationPrecision( 3 ), mShowGridAnnotation( false ), \
mGridAnnotationPosition( OutsideMapFrame ), mAnnotationFrameDistance( 1.0 ), mGridAnnotationDirection( Horizontal ), \
mRotation( 0 ), mCrossLength( 3 )
{
Expand Down Expand Up @@ -75,7 +75,7 @@ QgsComposerMap::QgsComposerMap( QgsComposition *composition, int x, int y, int w

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 ), \
mGridIntervalX( 0.0 ), mGridIntervalY( 0.0 ), mGridOffsetX( 0.0 ), mGridOffsetY( 0.0 ), mGridAnnotationPrecision( 3 ), mShowGridAnnotation( false ), \
mGridAnnotationPosition( OutsideMapFrame ), mAnnotationFrameDistance( 1.0 ), mGridAnnotationDirection( Horizontal ), \
mRotation( 0 ), mCrossLength( 3 )
{
Expand Down Expand Up @@ -619,6 +619,7 @@ bool QgsComposerMap::writeXML( QDomElement& elem, QDomDocument & doc ) const
annotationElem.setAttribute( "frameDistance", mAnnotationFrameDistance );
annotationElem.setAttribute( "direction", mGridAnnotationDirection );
annotationElem.setAttribute( "font", mGridAnnotationFont.toString() );
annotationElem.setAttribute( "precision", mGridAnnotationPrecision );

gridElem.appendChild( annotationElem );
composerMapElem.appendChild( gridElem );
Expand Down Expand Up @@ -723,6 +724,7 @@ bool QgsComposerMap::readXML( const QDomElement& itemElem, const QDomDocument& d
mAnnotationFrameDistance = annotationElem.attribute( "frameDistance", "0" ).toDouble();
mGridAnnotationDirection = QgsComposerMap::GridAnnotationDirection( annotationElem.attribute( "direction", "0" ).toInt() );
mGridAnnotationFont.fromString( annotationElem.attribute( "font", "" ) );
mGridAnnotationPrecision = annotationElem.attribute( "precision", "3" ).toInt();
}
}

Expand Down Expand Up @@ -860,15 +862,15 @@ void QgsComposerMap::drawCoordinateAnnotations( QPainter* p, const QList< QPair<
QList< QPair< double, QLineF > >::const_iterator it = hLines.constBegin();
for ( ; it != hLines.constEnd(); ++it )
{
currentAnnotationString = QString::number( it->first );
currentAnnotationString = QString::number( it->first, 'f', mGridAnnotationPrecision );
drawCoordinateAnnotation( p, it->second.p1(), currentAnnotationString );
drawCoordinateAnnotation( p, it->second.p2(), currentAnnotationString );
}

it = vLines.constBegin();
for ( ; it != vLines.constEnd(); ++it )
{
currentAnnotationString = QString::number( it->first );
currentAnnotationString = QString::number( it->first, 'f', mGridAnnotationPrecision );
drawCoordinateAnnotation( p, it->second.p1(), currentAnnotationString );
drawCoordinateAnnotation( p, it->second.p2(), currentAnnotationString );
}
Expand Down
45 changes: 43 additions & 2 deletions src/core/composer/qgscomposermap.h
Expand Up @@ -161,52 +161,91 @@ class CORE_EXPORT QgsComposerMap : /*public QWidget, private Ui::QgsComposerMapB
*/
bool readXML( const QDomElement& itemElem, const QDomDocument& doc );

/**Enables a coordinate grid that is shown on top of this composermap.
@note this function was added in version 1.4*/
void setGridEnabled( bool enabled ) {mGridEnabled = enabled;}
bool gridEnabled() const { return mGridEnabled; }

/**Sets coordinate grid style to solid or cross
@note this function was added in version 1.4*/
void setGridStyle( GridStyle style ) {mGridStyle = style;}
GridStyle gridStyle() const { return mGridStyle; }

/**Sets coordinate interval in x-direction for composergrid.
@note this function was added in version 1.4*/
void setGridIntervalX( double interval ) { mGridIntervalX = interval;}
double gridIntervalX() const { return mGridIntervalX; }

/**Sets coordinate interval in y-direction for composergrid.
@note this function was added in version 1.4*/
void setGridIntervalY( double interval ) { mGridIntervalY = interval;}
double gridIntervalY() const { return mGridIntervalY; }

/**Sets x-coordinate offset for composer grid
@note this function was added in version 1.4*/
void setGridOffsetX( double offset ) { mGridOffsetX = offset; }
double gridOffsetX() const { return mGridOffsetX; }

/**Sets y-coordinate offset for composer grid
@note this function was added in version 1.4*/
void setGridOffsetY( double offset ) { mGridOffsetY = offset; }
double gridOffsetY() const { return mGridOffsetY; }

/**Sets the pen to draw composer grid
@note this function was added in version 1.4*/
void setGridPen( const QPen& p ) { mGridPen = p; }
QPen gridPen() const { return mGridPen; }
/**Sets with of grid pen
@note this function was added in version 1.4*/
void setGridPenWidth( double w );
/**Sets the color of the grid pen
@note this function was added in version 1.4*/
void setGridPenColor( const QColor& c );

/**Sets font for grid annotations
@note this function was added in version 1.4*/
void setGridAnnotationFont( const QFont& f ) { mGridAnnotationFont = f; }
QFont gridAnnotationFont() const { return mGridAnnotationFont; }

/**Sets coordinate precision for grid annotations
@note this function was added in version 1.4*/
void setGridAnnotationPrecision( int p ) {mGridAnnotationPrecision = p;}
int gridAnnotationPrecision() const {return mGridAnnotationPrecision;}

/**Sets flag if grid annotation should be shown
@note this function was added in version 1.4*/
void setShowGridAnnotation( bool show ) {mShowGridAnnotation = show;}
bool showGridAnnotation() const {return mShowGridAnnotation;}

/**Sets position of grid annotations. Possibilities are inside or outside of the map frame
@note this function was added in version 1.4*/
void setGridAnnotationPosition( GridAnnotationPosition p ) {mGridAnnotationPosition = p;}
GridAnnotationPosition gridAnnotationPosition() const {return mGridAnnotationPosition;}

/**Sets distance between map frame and annotations
@note this function was added in version 1.4*/
void setAnnotationFrameDistance( double d ) {mAnnotationFrameDistance = d;}
double annotationFrameDistance() const {return mAnnotationFrameDistance;}

/**Sets grid annotation direction. Can be horizontal, vertical, direction of axis and horizontal and vertical
@note this function was added in version 1.4*/
void setGridAnnotationDirection( GridAnnotationDirection d ) {mGridAnnotationDirection = d;}
GridAnnotationDirection gridAnnotationDirection() const {return mGridAnnotationDirection;}

/**In case of annotations, the bounding rectangle can be larger than the map item rectangle*/
/**In case of annotations, the bounding rectangle can be larger than the map item rectangle
@note this function was added in version 1.4*/
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*/
/**Updates the bounding rect of this item. Call this function before doing any changes related to annotation out of the map rectangle
@note this function was added in version 1.4*/
void updateBoundingRect();

/**Sets the rotation of the map content
@note this function was added in version 1.4*/
void setRotation( double r ) { mRotation = r; }
double rotation() const { return mRotation; }

/**Sets length of the cros segments (if grid style is cross)
@note this function was added in version 1.4*/
void setCrossLength( double l ) {mCrossLength = l;}
double crossLength() {return mCrossLength;}

Expand Down Expand Up @@ -295,6 +334,8 @@ class CORE_EXPORT QgsComposerMap : /*public QWidget, private Ui::QgsComposerMapB
QPen mGridPen;
/**Font for grid line annotation*/
QFont mGridAnnotationFont;
/**Digits after the dot*/
int mGridAnnotationPrecision;
/**True if coordinate values should be drawn*/
bool mShowGridAnnotation;
/**Annotation position inside or outside of map frame*/
Expand Down
12 changes: 11 additions & 1 deletion src/ui/qgscomposermapwidgetbase.ui
Expand Up @@ -7,7 +7,7 @@
<x>0</x>
<y>0</y>
<width>482</width>
<height>641</height>
<height>677</height>
</rect>
</property>
<property name="sizePolicy">
Expand Down Expand Up @@ -412,6 +412,16 @@
</property>
</widget>
</item>
<item row="8" column="0" colspan="2">
<widget class="QLabel" name="mCoordinatePrecisionLabel">
<property name="text">
<string>Coordinate precision</string>
</property>
</widget>
</item>
<item row="8" column="2">
<widget class="QSpinBox" name="mCoordinatePrecisionSpinBox"/>
</item>
</layout>
</widget>
</item>
Expand Down

0 comments on commit ee19d5f

Please sign in to comment.