QGIS API Documentation  2.5.0-Master
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
qgscomposermapgrid.h
Go to the documentation of this file.
1 /***************************************************************************
2  qgscomposermapgrid.h
3  --------------------
4  begin : December 2013
5  copyright : (C) 2013 by Marco Hugentobler
6  email : marco dot hugentobler at sourcepole dot ch
7  ***************************************************************************/
8 
9 /***************************************************************************
10  * *
11  * This program is free software; you can redistribute it and/or modify *
12  * it under the terms of the GNU General Public License as published by *
13  * the Free Software Foundation; either version 2 of the License, or *
14  * (at your option) any later version. *
15  * *
16  ***************************************************************************/
17 
18 #ifndef QGSCOMPOSERMAPGRID_H
19 #define QGSCOMPOSERMAPGRID_H
20 
22 #include "qgscomposermap.h"
23 #include <QString>
24 
26 class QgsLineSymbolV2;
27 class QgsMarkerSymbolV2;
28 class QDomDocument;
29 class QDomElement;
30 class QPainter;
31 
32 class CORE_EXPORT QgsComposerMapGrid
33 {
34  public:
35 
36  enum GridUnit
37  {
39  MM,
40  CM
41  };
42 
43  QgsComposerMapGrid( const QString& name, QgsComposerMap* map );
45 
47  void drawGrid( QPainter* painter ) const;
48 
53  bool writeXML( QDomElement& elem, QDomDocument & doc ) const;
54 
59  bool readXML( const QDomElement& itemElem, const QDomDocument& doc );
60 
61  //setters and getters
62  void setComposerMap( QgsComposerMap* map );
63  const QgsComposerMap* composerMap() const { return mComposerMap; }
64 
65  void setName( const QString& name ) { mName = name; }
66  QString name() const { return mName; }
67 
68  QString id() const { return mUuid; }
69 
72  void setGridEnabled( bool enabled ) {mGridEnabled = enabled;}
73  bool gridEnabled() const { return mGridEnabled; }
74 
77  void setGridStyle( QgsComposerMap::GridStyle style ) {mGridStyle = style;}
78  QgsComposerMap::GridStyle gridStyle() const { return mGridStyle; }
79 
82  void setGridIntervalX( double interval ) { mGridIntervalX = interval;}
83  double gridIntervalX() const { return mGridIntervalX; }
84 
87  void setGridIntervalY( double interval ) { mGridIntervalY = interval;}
88  double gridIntervalY() const { return mGridIntervalY; }
89 
92  void setGridOffsetX( double offset ) { mGridOffsetX = offset; }
93  double gridOffsetX() const { return mGridOffsetX; }
94 
97  void setGridOffsetY( double offset ) { mGridOffsetY = offset; }
98  double gridOffsetY() const { return mGridOffsetY; }
99 
102  void setGridPen( const QPen& p );
103  QPen gridPen() const;
104 
107  void setGridPenWidth( double w );
108 
111  void setGridPenColor( const QColor& c );
112 
115  void setGridAnnotationFont( const QFont& f ) { mGridAnnotationFont = f; }
116  QFont gridAnnotationFont() const { return mGridAnnotationFont; }
117 
118  void setGridAnnotationFontColor( const QColor& c ) { mGridAnnotationFontColor = c; }
119  QColor gridAnnotationFontColor() const { return mGridAnnotationFontColor; }
120 
123  void setGridAnnotationPrecision( int p ) {mGridAnnotationPrecision = p;}
124  int gridAnnotationPrecision() const {return mGridAnnotationPrecision;}
125 
128  void setShowGridAnnotation( bool show ) {mShowGridAnnotation = show;}
129  bool showGridAnnotation() const {return mShowGridAnnotation;}
130 
131  void setGridAnnotationPosition( QgsComposerMap::GridAnnotationPosition p, QgsComposerMap::Border border );
132  QgsComposerMap::GridAnnotationPosition gridAnnotationPosition( QgsComposerMap::Border border ) const;
133 
136  void setAnnotationFrameDistance( double d ) {mAnnotationFrameDistance = d;}
137  double annotationFrameDistance() const {return mAnnotationFrameDistance;}
138 
139  void setGridAnnotationDirection( QgsComposerMap::GridAnnotationDirection d, QgsComposerMap::Border border );
140  QgsComposerMap::GridAnnotationDirection gridAnnotationDirection( QgsComposerMap::Border border ) const;
141 
144  void setGridAnnotationDirection( QgsComposerMap::GridAnnotationDirection d );
145  QgsComposerMap::GridAnnotationDirection gridAnnotationDirection() const;
146 
147  void setGridAnnotationFormat( QgsComposerMap::GridAnnotationFormat f ) { mGridAnnotationFormat = f; }
148  QgsComposerMap::GridAnnotationFormat gridAnnotationFormat() const { return mGridAnnotationFormat; }
149 
152  void setGridFrameStyle( QgsComposerMap::GridFrameStyle style ) { mGridFrameStyle = style; }
153  QgsComposerMap::GridFrameStyle gridFrameStyle() const { return mGridFrameStyle; }
154 
157  void setGridFrameWidth( double w ) { mGridFrameWidth = w; }
158  double gridFrameWidth() const { return mGridFrameWidth; }
159 
162  void setGridFramePenSize( double w ) { mGridFramePenThickness = w; }
163  double gridFramePenSize() const { return mGridFramePenThickness; }
164 
167  void setGridFramePenColor( const QColor& c ) { mGridFramePenColor = c;}
170  QColor gridFramePenColor() const {return mGridFramePenColor;}
171 
174  void setGridFrameFillColor1( const QColor& c ) { mGridFrameFillColor1 = c;}
177  QColor gridFrameFillColor1() const {return mGridFrameFillColor1;}
178 
181  void setGridFrameFillColor2( const QColor& c ) { mGridFrameFillColor2 = c;}
184  QColor gridFrameFillColor2() const {return mGridFrameFillColor2;}
185 
188  void setCrossLength( double l ) {mCrossLength = l;}
189  double crossLength() const {return mCrossLength;}
190 
191  void setGridLineSymbol( QgsLineSymbolV2* symbol );
192  const QgsLineSymbolV2* gridLineSymbol() const { return mGridLineSymbol; }
193  QgsLineSymbolV2* gridLineSymbol() { return mGridLineSymbol; }
194 
195  void setGridMarkerSymbol( QgsMarkerSymbolV2* symbol );
196  const QgsMarkerSymbolV2* gridMarkerSymbol() const { return mGridMarkerSymbol; }
197  QgsMarkerSymbolV2* gridMarkerSymbol() { return mGridMarkerSymbol; }
198 
199  void setCrs( const QgsCoordinateReferenceSystem& crs ) { mCRS = crs; }
200  QgsCoordinateReferenceSystem crs() const { return mCRS; }
201 
202  void setGridUnit( GridUnit u ) { mGridUnit = u; }
203  GridUnit gridUnit() const { return mGridUnit; }
204 
205  void setBlendMode( QPainter::CompositionMode mode ) { mBlendMode = mode; }
206  QPainter::CompositionMode blendMode() const { return mBlendMode; }
207 
208  double maxExtension() const;
209 
210  private:
211  QgsComposerMapGrid(); //forbidden
212 
214  QString mName;
215  QString mUuid;
216 
226  double mGridOffsetX;
228  double mGridOffsetY;
237 
246 
249 
265  double mCrossLength;
266 
269 
271 
273 
274  QPainter::CompositionMode mBlendMode;
275 
277  void drawGridFrame( QPainter* p, const QList< QPair< double, QLineF > >& hLines, const QList< QPair< double, QLineF > >& vLines ) const;
282  void drawCoordinateAnnotations( QPainter* p, const QList< QPair< double, QLineF > >& hLines, const QList< QPair< double, QLineF > >& vLines ) const;
283  void drawCoordinateAnnotation( QPainter* p, const QPointF& pos, QString annotationString ) const;
289  void drawAnnotation( QPainter* p, const QPointF& pos, int rotation, const QString& annotationText ) const;
290  QString gridAnnotationString( double value, QgsComposerMap::AnnotationCoordinate coord ) const;
293  int xGridLines( QList< QPair< double, QLineF > >& lines ) const;
296  int yGridLines( QList< QPair< double, QLineF > >& lines ) const;
297  int xGridLinesCRSTransform( const QgsRectangle& bbox, const QgsCoordinateTransform& t, QList< QPair< double, QPolygonF > >& lines ) const;
298  int yGridLinesCRSTransform( const QgsRectangle& bbox, const QgsCoordinateTransform& t, QList< QPair< double, QPolygonF > >& lines ) const;
299  void drawGridLine( const QLineF& line, QgsRenderContext &context ) const;
300  void drawGridLine( const QPolygonF& line, QgsRenderContext &context ) const;
301  void sortGridLinesOnBorders( const QList< QPair< double, QLineF > >& hLines, const QList< QPair< double, QLineF > >& vLines, QMap< double, double >& leftFrameEntries,
302  QMap< double, double >& rightFrameEntries, QMap< double, double >& topFrameEntries, QMap< double, double >& bottomFrameEntries ) const;
303  void drawGridFrameBorder( QPainter* p, const QMap< double, double >& borderPos, QgsComposerMap::Border border ) const;
305  QgsComposerMap::Border borderForLineCoord( const QPointF& p ) const;
307  int crsGridParams( QgsRectangle& crsRect, QgsCoordinateTransform& inverseTransform ) const;
308  static QPolygonF trimLineToMap( const QPolygonF& line, const QgsRectangle& rect );
309  QPolygonF scalePolygon( const QPolygonF &polygon, const double scale ) const;
310 
312  void drawGridCRSTransform( QgsRenderContext &context , double dotsPerMM, QList< QPair< double, QLineF > > &horizontalLines,
313  QList< QPair< double, QLineF > > &verticalLines ) const;
314 
315  void drawGridNoTransform( QgsRenderContext &context, double dotsPerMM, QList<QPair<double, QLineF> > &horizontalLines, QList<QPair<double, QLineF> > &verticalLines ) const;
316  void createDefaultGridLineSymbol();
317  void createDefaultGridMarkerSymbol();
318  void drawGridMarker( const QPointF &point, QgsRenderContext &context ) const;
319 };
320 
321 #endif // QGSCOMPOSERMAPGRID_H
QColor gridFrameFillColor2() const
Get second fill color for grid zebra frame.
double gridFrameWidth() const
A rectangle specified with double values.
Definition: qgsrectangle.h:35
void setGridFramePenColor(const QColor &c)
Sets pen color for grid frame.
QColor gridFrameFillColor1() const
Get first fill color for grid zebra frame.
double gridIntervalX() const
double mGridOffsetX
Grid line offset in x-direction.
QgsComposerMap::GridAnnotationPosition mLeftGridAnnotationPosition
Annotation position for left map side (inside / outside / not shown)
QgsComposerMap::GridFrameStyle gridFrameStyle() const
void setGridAnnotationFormat(QgsComposerMap::GridAnnotationFormat f)
void setName(const QString &name)
Border
Enum for different frame borders.
double annotationFrameDistance() const
void setGridIntervalX(double interval)
Sets coordinate interval in x-direction for composergrid.
double mGridIntervalY
Grid line interval in y-direction (map units)
QgsLineSymbolV2 * mGridLineSymbol
void setGridFrameFillColor1(const QColor &c)
Sets first fill color for grid zebra frame.
void setCrossLength(double l)
Sets length of the cros segments (if grid style is cross)
bool mShowGridAnnotation
True if coordinate values should be drawn.
QgsLineSymbolV2 * gridLineSymbol()
const QgsComposerMap * composerMap() const
QgsComposerMap * mComposerMap
QgsComposerMap::GridAnnotationDirection mBottomGridAnnotationDirection
Annotation direction on bottom side ( horizontal or vertical )
QPainter::CompositionMode mBlendMode
void setGridStyle(QgsComposerMap::GridStyle style)
Sets coordinate grid style to solid or cross.
void setGridAnnotationFontColor(const QColor &c)
QgsComposerMap::GridStyle mGridStyle
Solid or crosses.
QgsComposerMap::GridAnnotationDirection mRightGridAnnotationDirection
Annotation direction on right side ( horizontal or vertical )
void setGridAnnotationPrecision(int p)
Sets coordinate precision for grid annotations.
QgsComposerMap::GridStyle gridStyle() const
QColor mGridAnnotationFontColor
Font color for grid coordinates.
QColor gridFramePenColor() const
Get pen color for grid frame.
QgsComposerMap::GridAnnotationPosition mRightGridAnnotationPosition
Annotation position for right map side (inside / outside / not shown)
double gridIntervalY() const
QgsComposerMap::GridAnnotationPosition mTopGridAnnotationPosition
Annotation position for top map side (inside / outside / not shown)
void setAnnotationFrameDistance(double d)
Sets distance between map frame and annotations.
void setGridOffsetX(double offset)
Sets x-coordinate offset for composer grid.
QgsComposerMap::GridFrameStyle mGridFrameStyle
int gridAnnotationPrecision() const
GridUnit gridUnit() const
void setCrs(const QgsCoordinateReferenceSystem &crs)
bool gridEnabled() const
QFont gridAnnotationFont() const
void setGridFrameWidth(double w)
Set grid frame width.
Object representing map window.
QgsComposerMap::GridAnnotationDirection mTopGridAnnotationDirection
Annotation direction on top side ( horizontal or vertical )
const QgsLineSymbolV2 * gridLineSymbol() const
bool showGridAnnotation() const
QString name() const
const QgsMarkerSymbolV2 * gridMarkerSymbol() const
QgsComposerMap::GridAnnotationPosition mBottomGridAnnotationPosition
Annotation position for bottom map side (inside / outside / not shown)
QPainter::CompositionMode blendMode() const
double mGridIntervalX
Grid line interval in x-direction (map units)
QgsComposerMap::GridAnnotationDirection mLeftGridAnnotationDirection
Annotation direction on left side ( horizontal or vertical )
bool mGridEnabled
True if coordinate grid has to be displayed.
Contains information about the context of a rendering operation.
void setGridOffsetY(double offset)
Sets y-coordinate offset for composer grid.
void setGridAnnotationFont(const QFont &f)
Sets font for grid annotations.
QColor gridAnnotationFontColor() const
void setGridEnabled(bool enabled)
Enables a coordinate grid that is shown on top of this composermap.
double gridFramePenSize() const
int mGridAnnotationPrecision
Digits after the dot.
void setGridFramePenSize(double w)
Set grid frame pen thickness.
QString id() const
QgsComposerMap::GridAnnotationFormat mGridAnnotationFormat
void setGridUnit(GridUnit u)
Class for storing a coordinate reference system (CRS)
void setGridFrameStyle(QgsComposerMap::GridFrameStyle style)
Set grid frame style (NoGridFrame or Zebra)
double gridOffsetX() const
Class for doing transforms between two map coordinate systems.
double mGridOffsetY
Grid line offset in y-direction.
double crossLength() const
QgsMarkerSymbolV2 * gridMarkerSymbol()
QgsMarkerSymbolV2 * mGridMarkerSymbol
void setBlendMode(QPainter::CompositionMode mode)
QgsCoordinateReferenceSystem crs() const
QFont mGridAnnotationFont
Font for grid line annotation.
double gridOffsetY() const
void setGridIntervalY(double interval)
Sets coordinate interval in y-direction for composergrid.
void setShowGridAnnotation(bool show)
Sets flag if grid annotation should be shown.
QgsCoordinateReferenceSystem mCRS
double mAnnotationFrameDistance
Distance between map frame and annotation.
QgsComposerMap::GridAnnotationFormat gridAnnotationFormat() const
void setGridFrameFillColor2(const QColor &c)
Sets second fill color for grid zebra frame.