|
QGIS API Documentation
master-3f58142
|
00001 /*************************************************************************** 00002 qgscomposermap.h 00003 ------------------- 00004 begin : January 2005 00005 copyright : (C) 2005 by Radim Blazek 00006 email : blazek@itc.it 00007 ***************************************************************************/ 00008 00009 /*************************************************************************** 00010 * * 00011 * This program is free software; you can redistribute it and/or modify * 00012 * it under the terms of the GNU General Public License as published by * 00013 * the Free Software Foundation; either version 2 of the License, or * 00014 * (at your option) any later version. * 00015 * * 00016 ***************************************************************************/ 00017 #ifndef QGSCOMPOSERMAP_H 00018 #define QGSCOMPOSERMAP_H 00019 00020 //#include "ui_qgscomposermapbase.h" 00021 #include "qgscomposeritem.h" 00022 #include "qgsrectangle.h" 00023 #include <QFont> 00024 #include <QGraphicsRectItem> 00025 00026 class QgsComposition; 00027 class QgsMapRenderer; 00028 class QgsMapToPixel; 00029 class QDomNode; 00030 class QDomDocument; 00031 class QGraphicsView; 00032 class QPainter; 00033 class QgsFillSymbolV2; 00034 class QgsLineSymbolV2; 00035 class QgsVectorLayer; 00036 00041 // NOTE: QgsComposerMapBase must be first, otherwise does not compile 00042 class CORE_EXPORT QgsComposerMap : public QgsComposerItem 00043 { 00044 Q_OBJECT 00045 00046 public: 00048 QgsComposerMap( QgsComposition *composition, int x, int y, int width, int height ); 00050 QgsComposerMap( QgsComposition *composition ); 00051 virtual ~QgsComposerMap(); 00052 00054 virtual int type() const { return ComposerMap; } 00055 00057 enum PreviewMode 00058 { 00059 Cache = 0, // Use raster cache 00060 Render, // Render the map 00061 Rectangle // Display only rectangle 00062 }; 00063 00064 enum GridStyle 00065 { 00066 Solid = 0, //solid lines 00067 Cross //only draw line crossings 00068 }; 00069 00070 enum GridAnnotationPosition 00071 { 00072 InsideMapFrame = 0, 00073 OutsideMapFrame, 00074 Disabled 00075 }; 00076 00077 enum GridAnnotationDirection 00078 { 00079 Horizontal = 0, 00080 Vertical, 00081 HorizontalAndVertical, 00082 BoundaryDirection 00083 }; 00084 00085 enum GridAnnotationFormat 00086 { 00087 Decimal = 0, 00088 DegreeMinute, 00089 DegreeMinuteSecond 00090 }; 00091 00092 enum GridFrameStyle 00093 { 00094 NoGridFrame = 0, 00095 Zebra //black / white pattern 00096 }; 00097 00099 enum Border 00100 { 00101 Left, 00102 Right, 00103 Bottom, 00104 Top 00105 }; 00106 00114 void draw( QPainter *painter, const QgsRectangle& extent, const QSizeF& size, double dpi, double* forceWidthScale = 0 ); 00115 00117 void paint( QPainter* painter, const QStyleOptionGraphicsItem* itemStyle, QWidget* pWidget ); 00118 00120 void cache(); 00121 00123 int id() const {return mId;} 00124 00126 bool isDrawing() const {return mDrawing;} 00127 00129 void resize( double dx, double dy ); 00130 00134 void moveContent( double dx, double dy ); 00135 00140 void zoomContent( int delta, double x, double y ); 00141 00143 void setSceneRect( const QRectF& rectangle ); 00144 00146 double scale() const; 00147 00149 void setNewScale( double scaleDenominator ); 00150 00152 void setNewExtent( const QgsRectangle& extent ); 00153 00154 PreviewMode previewMode() const {return mPreviewMode;} 00155 void setPreviewMode( PreviewMode m ); 00156 00159 bool keepLayerSet() const {return mKeepLayerSet;} 00162 void setKeepLayerSet( bool enabled ) {mKeepLayerSet = enabled;} 00163 00166 QStringList layerSet() const {return mLayerSet;} 00169 void setLayerSet( const QStringList& layerSet ) {mLayerSet = layerSet;} 00171 void storeCurrentLayerSet(); 00172 00173 // Set cache outdated 00174 void setCacheUpdated( bool u = false ); 00175 00176 QgsRectangle extent() const {return mExtent;} 00177 00178 const QgsMapRenderer* mapRenderer() const {return mMapRenderer;} 00179 00181 void setOffset( double xOffset, double yOffset ); 00182 00184 bool containsWMSLayer() const; 00185 00187 bool containsAdvancedEffects() const; 00188 00193 bool writeXML( QDomElement& elem, QDomDocument & doc ) const; 00194 00199 bool readXML( const QDomElement& itemElem, const QDomDocument& doc ); 00200 00203 void setGridEnabled( bool enabled ) {mGridEnabled = enabled;} 00204 bool gridEnabled() const { return mGridEnabled; } 00205 00208 void setGridStyle( GridStyle style ) {mGridStyle = style;} 00209 GridStyle gridStyle() const { return mGridStyle; } 00210 00213 void setGridIntervalX( double interval ) { mGridIntervalX = interval;} 00214 double gridIntervalX() const { return mGridIntervalX; } 00215 00218 void setGridIntervalY( double interval ) { mGridIntervalY = interval;} 00219 double gridIntervalY() const { return mGridIntervalY; } 00220 00223 void setGridOffsetX( double offset ) { mGridOffsetX = offset; } 00224 double gridOffsetX() const { return mGridOffsetX; } 00225 00228 void setGridOffsetY( double offset ) { mGridOffsetY = offset; } 00229 double gridOffsetY() const { return mGridOffsetY; } 00230 00233 void setGridPen( const QPen& p ); 00234 QPen gridPen() const; 00235 00238 void setGridPenWidth( double w ); 00239 00242 void setGridPenColor( const QColor& c ); 00243 00246 void setGridAnnotationFont( const QFont& f ) { mGridAnnotationFont = f; } 00247 QFont gridAnnotationFont() const { return mGridAnnotationFont; } 00248 00251 void setAnnotationFontColor( const QColor& c ) {mGridAnnotationFontColor = c;} 00254 QColor annotationFontColor() const {return mGridAnnotationFontColor;} 00255 00258 void setGridAnnotationPrecision( int p ) {mGridAnnotationPrecision = p;} 00259 int gridAnnotationPrecision() const {return mGridAnnotationPrecision;} 00260 00263 void setShowGridAnnotation( bool show ) {mShowGridAnnotation = show;} 00264 bool showGridAnnotation() const {return mShowGridAnnotation;} 00265 00266 void setGridAnnotationPosition( GridAnnotationPosition p, QgsComposerMap::Border border ); 00267 GridAnnotationPosition gridAnnotationPosition( QgsComposerMap::Border border ) const; 00268 00271 void setAnnotationFrameDistance( double d ) {mAnnotationFrameDistance = d;} 00272 double annotationFrameDistance() const {return mAnnotationFrameDistance;} 00273 00274 void setGridAnnotationDirection( GridAnnotationDirection d, QgsComposerMap::Border border ); 00275 GridAnnotationDirection gridAnnotationDirection( QgsComposerMap::Border border ) const; 00276 00277 void setGridAnnotationFormat( GridAnnotationFormat f ) { mGridAnnotationFormat = f; } 00278 GridAnnotationFormat gridAnnotationFormat() const { return mGridAnnotationFormat; } 00279 00282 void setGridFrameStyle( GridFrameStyle style ) { mGridFrameStyle = style; } 00283 GridFrameStyle gridFrameStyle() const { return mGridFrameStyle; } 00284 00287 void setGridFrameWidth( double w ) { mGridFrameWidth = w; } 00288 double gridFrameWidth() const { return mGridFrameWidth; } 00289 00292 QRectF boundingRect() const; 00295 void updateBoundingRect(); 00296 00299 void setCrossLength( double l ) {mCrossLength = l;} 00300 double crossLength() {return mCrossLength;} 00301 00302 void setMapRotation( double r ); 00303 00304 void updateItem(); 00305 00307 void setMapCanvas( QGraphicsView* canvas ) { mMapCanvas = canvas; } 00308 00309 void setDrawCanvasItems( bool b ) { mDrawCanvasItems = b; } 00310 bool drawCanvasItems() const { return mDrawCanvasItems; } 00311 00313 double mapUnitsToMM() const; 00314 00317 void setOverviewFrameMap( int mapId ); 00320 int overviewFrameMapId() const { return mOverviewFrameMapId; } 00321 00322 void setOverviewFrameMapSymbol( QgsFillSymbolV2* symbol ); 00323 QgsFillSymbolV2* overviewFrameMapSymbol() { return mOverviewFrameMapSymbol; } 00324 00326 QPainter::CompositionMode overviewBlendMode() const {return mOverviewBlendMode;} 00328 void setOverviewBlendMode( QPainter::CompositionMode blendMode ); 00329 00331 bool overviewInverted() const {return mOverviewInverted;} 00333 void setOverviewInverted( bool inverted ); 00334 00335 void setGridLineSymbol( QgsLineSymbolV2* symbol ); 00336 QgsLineSymbolV2* gridLineSymbol() { return mGridLineSymbol; } 00337 00339 QPainter::CompositionMode gridBlendMode() const {return mGridBlendMode;} 00341 void setGridBlendMode( QPainter::CompositionMode blendMode ); 00342 00345 void assignFreeId(); 00346 00347 signals: 00348 void extentChanged(); 00349 00350 public slots: 00351 00353 void updateCachedImage( ); 00355 void renderModeUpdateCachedImage(); 00356 00357 private: 00358 00359 enum AnnotationCoordinate 00360 { 00361 Longitude = 0, 00362 Latitude 00363 }; 00364 00365 // Pointer to map renderer of the QGIS main map. Note that QgsComposerMap uses a different map renderer, 00366 //it just copies some properties from the main map renderer. 00367 QgsMapRenderer *mMapRenderer; 00368 00370 int mId; 00371 00372 // Map region in map units realy used for rendering 00373 // It can be the same as mUserExtent, but it can be bigger in on dimension if mCalculate==Scale, 00374 // so that full rectangle in paper is used. 00375 QgsRectangle mExtent; 00376 00377 // Cache used in composer preview 00378 QImage mCacheImage; 00379 00380 // Is cache up to date 00381 bool mCacheUpdated; 00382 00384 PreviewMode mPreviewMode; 00385 00387 int mNumCachedLayers; 00388 00390 bool mDrawing; 00391 00393 double mXOffset; 00395 double mYOffset; 00396 00398 bool mKeepLayerSet; 00399 00401 QStringList mLayerSet; 00402 00404 int mOverviewFrameMapId; 00406 QgsFillSymbolV2* mOverviewFrameMapSymbol; 00407 QgsLineSymbolV2* mGridLineSymbol; 00409 QPainter::CompositionMode mOverviewBlendMode; 00410 bool mOverviewInverted; 00411 00413 void connectUpdateSlot(); 00414 00416 void syncLayerSet(); 00417 00419 bool mGridEnabled; 00421 GridStyle mGridStyle; 00423 double mGridIntervalX; 00425 double mGridIntervalY; 00427 double mGridOffsetX; 00429 double mGridOffsetY; 00431 QFont mGridAnnotationFont; 00433 QColor mGridAnnotationFontColor; 00435 int mGridAnnotationPrecision; 00437 bool mShowGridAnnotation; 00439 QPainter::CompositionMode mGridBlendMode; 00440 00442 GridAnnotationPosition mLeftGridAnnotationPosition; 00444 GridAnnotationPosition mRightGridAnnotationPosition; 00446 GridAnnotationPosition mTopGridAnnotationPosition; 00448 GridAnnotationPosition mBottomGridAnnotationPosition; 00449 00451 double mAnnotationFrameDistance; 00452 00454 GridAnnotationDirection mLeftGridAnnotationDirection; 00456 GridAnnotationDirection mRightGridAnnotationDirection; 00458 GridAnnotationDirection mTopGridAnnotationDirection; 00460 GridAnnotationDirection mBottomGridAnnotationDirection; 00461 00462 GridAnnotationFormat mGridAnnotationFormat; 00463 00464 GridFrameStyle mGridFrameStyle; 00465 double mGridFrameWidth; 00466 00468 QRectF mCurrentRectangle; 00470 double mCrossLength; 00471 QGraphicsView* mMapCanvas; 00473 bool mDrawCanvasItems; 00474 00476 void drawGrid( QPainter* p ); 00477 void drawGridFrame( QPainter* p, const QList< QPair< double, QLineF > >& hLines, const QList< QPair< double, QLineF > >& vLines ); 00482 void drawCoordinateAnnotations( QPainter* p, const QList< QPair< double, QLineF > >& hLines, const QList< QPair< double, QLineF > >& vLines ); 00483 void drawCoordinateAnnotation( QPainter* p, const QPointF& pos, QString annotationString ); 00489 void drawAnnotation( QPainter* p, const QPointF& pos, int rotation, const QString& annotationText ); 00490 QString gridAnnotationString( double value, AnnotationCoordinate coord ) const; 00493 int xGridLines( QList< QPair< double, QLineF > >& lines ) const; 00496 int yGridLines( QList< QPair< double, QLineF > >& lines ) const; 00498 QgsRectangle transformedExtent() const; 00500 QPolygonF transformedMapPolygon() const; 00501 double maxExtension() const; 00505 void mapPolygon( QPolygonF& poly ) const; 00507 void requestedExtent( QgsRectangle& extent ) const; 00511 void transformShift( double& xShift, double& yShift ) const; 00513 QPointF mapToItemCoords( const QPointF& mapCoords ) const; 00515 Border borderForLineCoord( const QPointF& p ) const; 00516 00517 void drawCanvasItems( QPainter* painter, const QStyleOptionGraphicsItem* itemStyle ); 00518 void drawCanvasItem( QGraphicsItem* item, QPainter* painter, const QStyleOptionGraphicsItem* itemStyle ); 00519 QPointF composerMapPosForItem( const QGraphicsItem* item ) const; 00520 void sortGridLinesOnBorders( const QList< QPair< double, QLineF > >& hLines, const QList< QPair< double, QLineF > >& vLines, QMap< double, double >& leftFrameEntries, 00521 QMap< double, double >& rightFrameEntries, QMap< double, double >& topFrameEntries, QMap< double, double >& bottomFrameEntries ) const; 00522 void drawGridFrameBorder( QPainter* p, const QMap< double, double >& borderPos, Border border ); 00523 void drawGridLine( const QLineF& line, QPainter* p ); 00524 void drawOverviewMapExtent( QPainter* p ); 00525 void createDefaultOverviewFrameSymbol(); 00526 void createDefaultGridLineSymbol(); 00527 void initGridAnnotationFormatFromProject(); 00528 }; 00529 00530 #endif