Skip to content

Commit 7672d42

Browse files
author
mhugent
committed
Possibility to choose the precision of composer grid annotations
git-svn-id: http://svn.osgeo.org/qgis/trunk/qgis@11849 c8812cc2-4d05-0410-92ff-de0c093fc19c
1 parent 8c6cf59 commit 7672d42

File tree

6 files changed

+116
-9
lines changed

6 files changed

+116
-9
lines changed

python/core/qgscomposermap.sip

Lines changed: 43 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -131,52 +131,93 @@ class QgsComposerMap : QObject, QgsComposerItem
131131
*/
132132
bool readXML( const QDomElement& itemElem, const QDomDocument& doc );
133133

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

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

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

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

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

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

164+
/**Sets the pen to draw composer grid
165+
@note this function was added in version 1.4*/
152166
void setGridPen( const QPen& p );
153167
QPen gridPen() const;
168+
169+
/**Sets with of grid pen
170+
@note this function was added in version 1.4*/
154171
void setGridPenWidth( double w );
172+
173+
/**Sets the color of the grid pen
174+
@note this function was added in version 1.4*/
155175
void setGridPenColor( const QColor& c );
156176

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

182+
/**Sets coordinate precision for grid annotations
183+
@note this function was added in version 1.4*/
184+
void setGridAnnotationPrecision( int p );
185+
int gridAnnotationPrecision() const;
186+
187+
/**Sets flag if grid annotation should be shown
188+
@note this function was added in version 1.4*/
160189
void setShowGridAnnotation( bool show );
161190
bool showGridAnnotation() const;
162191

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

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

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

172-
/**In case of annotations, the bounding rectangle can be larger than the map item rectangle*/
207+
/**In case of annotations, the bounding rectangle can be larger than the map item rectangle
208+
@note this function was added in version 1.4*/
173209
QRectF boundingRect() const;
174-
/**Updates the bounding rect of this item. Call this function before doing any changes related to annotation out of the map rectangle*/
210+
/**Updates the bounding rect of this item. Call this function before doing any changes related to annotation out of the map rectangle
211+
@note this function was added in version 1.4*/
175212
void updateBoundingRect();
176213

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

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

src/app/composer/qgscomposermapwidget.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -365,6 +365,7 @@ void QgsComposerMapWidget::updateGuiElements()
365365
mAnnotationDirectionComboBox->setCurrentIndex( mAnnotationDirectionComboBox->findText( tr( "Boundary direction" ) ) );
366366
}
367367

368+
mCoordinatePrecisionSpinBox->setValue( mComposerMap->gridAnnotationPrecision() );
368369

369370
QPen gridPen = mComposerMap->gridPen();
370371
mLineWidthSpinBox->setValue( gridPen.widthF() );
@@ -423,6 +424,7 @@ void QgsComposerMapWidget::blockAllSignals( bool b )
423424
mAnnotationPositionComboBox->blockSignals( b );
424425
mDistanceToMapFrameSpinBox->blockSignals( b );
425426
mAnnotationDirectionComboBox->blockSignals( b );
427+
mCoordinatePrecisionSpinBox->blockSignals( b );
426428
}
427429

428430
void QgsComposerMapWidget::on_mUpdatePreviewButton_clicked()
@@ -692,3 +694,13 @@ void QgsComposerMapWidget::on_mShowGridDialogCheckBox_stateChanged( int state )
692694
mGridWidget->setVisible( false );
693695
}
694696
}
697+
698+
void QgsComposerMapWidget::on_mCoordinatePrecisionSpinBox_valueChanged( int value )
699+
{
700+
if ( !mComposerMap )
701+
{
702+
return;
703+
}
704+
mComposerMap->setGridAnnotationPrecision( value );
705+
mComposerMap->update();
706+
}

src/app/composer/qgscomposermapwidget.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ class QgsComposerMapWidget: public QWidget, private Ui::QgsComposerMapWidgetBase
6464
void on_mDrawAnnotationCheckBox_stateChanged( int state );
6565
void on_mAnnotationDirectionComboBox_currentIndexChanged( const QString& text );
6666
void on_mShowGridDialogCheckBox_stateChanged( int state );
67+
void on_mCoordinatePrecisionSpinBox_valueChanged( int value );
6768

6869
/**Updates width and height without notify the composer map (to avoid infinite recursion)*/
6970
void updateSettingsNoSignals();

src/core/composer/qgscomposermap.cpp

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ int QgsComposerMap::mCurrentComposerId = 0;
4343

4444
QgsComposerMap::QgsComposerMap( QgsComposition *composition, int x, int y, int width, int height )
4545
: QgsComposerItem( x, y, width, height, composition ), mKeepLayerSet( false ), mGridEnabled( false ), mGridStyle( Solid ), \
46-
mGridIntervalX( 0.0 ), mGridIntervalY( 0.0 ), mGridOffsetX( 0.0 ), mGridOffsetY( 0.0 ), mShowGridAnnotation( false ), \
46+
mGridIntervalX( 0.0 ), mGridIntervalY( 0.0 ), mGridOffsetX( 0.0 ), mGridOffsetY( 0.0 ), mGridAnnotationPrecision( 3 ), mShowGridAnnotation( false ), \
4747
mGridAnnotationPosition( OutsideMapFrame ), mAnnotationFrameDistance( 1.0 ), mGridAnnotationDirection( Horizontal ), \
4848
mRotation( 0 ), mCrossLength( 3 )
4949
{
@@ -75,7 +75,7 @@ QgsComposerMap::QgsComposerMap( QgsComposition *composition, int x, int y, int w
7575

7676
QgsComposerMap::QgsComposerMap( QgsComposition *composition )
7777
: QgsComposerItem( 0, 0, 10, 10, composition ), mKeepLayerSet( false ), mGridEnabled( false ), mGridStyle( Solid ), \
78-
mGridIntervalX( 0.0 ), mGridIntervalY( 0.0 ), mGridOffsetX( 0.0 ), mGridOffsetY( 0.0 ), mShowGridAnnotation( false ), \
78+
mGridIntervalX( 0.0 ), mGridIntervalY( 0.0 ), mGridOffsetX( 0.0 ), mGridOffsetY( 0.0 ), mGridAnnotationPrecision( 3 ), mShowGridAnnotation( false ), \
7979
mGridAnnotationPosition( OutsideMapFrame ), mAnnotationFrameDistance( 1.0 ), mGridAnnotationDirection( Horizontal ), \
8080
mRotation( 0 ), mCrossLength( 3 )
8181
{
@@ -619,6 +619,7 @@ bool QgsComposerMap::writeXML( QDomElement& elem, QDomDocument & doc ) const
619619
annotationElem.setAttribute( "frameDistance", mAnnotationFrameDistance );
620620
annotationElem.setAttribute( "direction", mGridAnnotationDirection );
621621
annotationElem.setAttribute( "font", mGridAnnotationFont.toString() );
622+
annotationElem.setAttribute( "precision", mGridAnnotationPrecision );
622623

623624
gridElem.appendChild( annotationElem );
624625
composerMapElem.appendChild( gridElem );
@@ -723,6 +724,7 @@ bool QgsComposerMap::readXML( const QDomElement& itemElem, const QDomDocument& d
723724
mAnnotationFrameDistance = annotationElem.attribute( "frameDistance", "0" ).toDouble();
724725
mGridAnnotationDirection = QgsComposerMap::GridAnnotationDirection( annotationElem.attribute( "direction", "0" ).toInt() );
725726
mGridAnnotationFont.fromString( annotationElem.attribute( "font", "" ) );
727+
mGridAnnotationPrecision = annotationElem.attribute( "precision", "3" ).toInt();
726728
}
727729
}
728730

@@ -860,15 +862,15 @@ void QgsComposerMap::drawCoordinateAnnotations( QPainter* p, const QList< QPair<
860862
QList< QPair< double, QLineF > >::const_iterator it = hLines.constBegin();
861863
for ( ; it != hLines.constEnd(); ++it )
862864
{
863-
currentAnnotationString = QString::number( it->first );
865+
currentAnnotationString = QString::number( it->first, 'f', mGridAnnotationPrecision );
864866
drawCoordinateAnnotation( p, it->second.p1(), currentAnnotationString );
865867
drawCoordinateAnnotation( p, it->second.p2(), currentAnnotationString );
866868
}
867869

868870
it = vLines.constBegin();
869871
for ( ; it != vLines.constEnd(); ++it )
870872
{
871-
currentAnnotationString = QString::number( it->first );
873+
currentAnnotationString = QString::number( it->first, 'f', mGridAnnotationPrecision );
872874
drawCoordinateAnnotation( p, it->second.p1(), currentAnnotationString );
873875
drawCoordinateAnnotation( p, it->second.p2(), currentAnnotationString );
874876
}

src/core/composer/qgscomposermap.h

Lines changed: 43 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -161,52 +161,91 @@ class CORE_EXPORT QgsComposerMap : /*public QWidget, private Ui::QgsComposerMapB
161161
*/
162162
bool readXML( const QDomElement& itemElem, const QDomDocument& doc );
163163

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

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

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

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

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

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

194+
/**Sets the pen to draw composer grid
195+
@note this function was added in version 1.4*/
182196
void setGridPen( const QPen& p ) { mGridPen = p; }
183197
QPen gridPen() const { return mGridPen; }
198+
/**Sets with of grid pen
199+
@note this function was added in version 1.4*/
184200
void setGridPenWidth( double w );
201+
/**Sets the color of the grid pen
202+
@note this function was added in version 1.4*/
185203
void setGridPenColor( const QColor& c );
186204

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

210+
/**Sets coordinate precision for grid annotations
211+
@note this function was added in version 1.4*/
212+
void setGridAnnotationPrecision( int p ) {mGridAnnotationPrecision = p;}
213+
int gridAnnotationPrecision() const {return mGridAnnotationPrecision;}
214+
215+
/**Sets flag if grid annotation should be shown
216+
@note this function was added in version 1.4*/
190217
void setShowGridAnnotation( bool show ) {mShowGridAnnotation = show;}
191218
bool showGridAnnotation() const {return mShowGridAnnotation;}
192219

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

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

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

202-
/**In case of annotations, the bounding rectangle can be larger than the map item rectangle*/
235+
/**In case of annotations, the bounding rectangle can be larger than the map item rectangle
236+
@note this function was added in version 1.4*/
203237
QRectF boundingRect() const;
204-
/**Updates the bounding rect of this item. Call this function before doing any changes related to annotation out of the map rectangle*/
238+
/**Updates the bounding rect of this item. Call this function before doing any changes related to annotation out of the map rectangle
239+
@note this function was added in version 1.4*/
205240
void updateBoundingRect();
206241

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

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

@@ -295,6 +334,8 @@ class CORE_EXPORT QgsComposerMap : /*public QWidget, private Ui::QgsComposerMapB
295334
QPen mGridPen;
296335
/**Font for grid line annotation*/
297336
QFont mGridAnnotationFont;
337+
/**Digits after the dot*/
338+
int mGridAnnotationPrecision;
298339
/**True if coordinate values should be drawn*/
299340
bool mShowGridAnnotation;
300341
/**Annotation position inside or outside of map frame*/

src/ui/qgscomposermapwidgetbase.ui

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
<x>0</x>
88
<y>0</y>
99
<width>482</width>
10-
<height>641</height>
10+
<height>677</height>
1111
</rect>
1212
</property>
1313
<property name="sizePolicy">
@@ -412,6 +412,16 @@
412412
</property>
413413
</widget>
414414
</item>
415+
<item row="8" column="0" colspan="2">
416+
<widget class="QLabel" name="mCoordinatePrecisionLabel">
417+
<property name="text">
418+
<string>Coordinate precision</string>
419+
</property>
420+
</widget>
421+
</item>
422+
<item row="8" column="2">
423+
<widget class="QSpinBox" name="mCoordinatePrecisionSpinBox"/>
424+
</item>
415425
</layout>
416426
</widget>
417427
</item>

0 commit comments

Comments
 (0)