Quantum GIS API Documentation
1.8
|
00001 /*************************************************************************** 00002 qgscomposermap.h 00003 ------------------- 00004 begin : January 2005 00005 copyright : (C) 2005 by Radim Blazek 00006 email : [email protected] 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 <QGraphicsRectItem> 00024 00025 class QgsComposition; 00026 class QgsMapRenderer; 00027 class QgsMapToPixel; 00028 class QDomNode; 00029 class QDomDocument; 00030 class QGraphicsView; 00031 class QPainter; 00032 00037 // NOTE: QgsComposerMapBase must be first, otherwise does not compile 00038 class CORE_EXPORT QgsComposerMap : public QgsComposerItem 00039 { 00040 Q_OBJECT 00041 00042 public: 00044 QgsComposerMap( QgsComposition *composition, int x, int y, int width, int height ); 00046 QgsComposerMap( QgsComposition *composition ); 00047 ~QgsComposerMap(); 00048 00050 virtual int type() const { return ComposerMap; } 00051 00053 enum PreviewMode 00054 { 00055 Cache = 0, // Use raster cache 00056 Render, // Render the map 00057 Rectangle // Display only rectangle 00058 }; 00059 00060 enum GridStyle 00061 { 00062 Solid = 0, //solid lines 00063 Cross //only draw line crossings 00064 }; 00065 00066 enum GridAnnotationPosition 00067 { 00068 InsideMapFrame = 0, 00069 OutsideMapFrame 00070 }; 00071 00072 enum GridAnnotationDirection 00073 { 00074 Horizontal = 0, 00075 Vertical, 00076 HorizontalAndVertical, 00077 BoundaryDirection 00078 }; 00079 00081 void draw( QPainter *painter, const QgsRectangle& extent, const QSize& size, int dpi ); 00082 00090 void draw( QPainter *painter, const QgsRectangle& extent, const QSizeF& size, double dpi, double* forceWidthScale = 0 ); 00091 00093 void paint( QPainter* painter, const QStyleOptionGraphicsItem* itemStyle, QWidget* pWidget ); 00094 00096 void cache( void ); 00097 00099 int id() const {return mId;} 00100 00102 bool isDrawing() const {return mDrawing;} 00103 00105 void resize( double dx, double dy ); 00106 00110 void moveContent( double dx, double dy ); 00111 00116 void zoomContent( int delta, double x, double y ); 00117 00119 void setSceneRect( const QRectF& rectangle ); 00120 00122 double scale( void ) const; 00123 00125 void setNewScale( double scaleDenominator ); 00126 00128 void setNewExtent( const QgsRectangle& extent ); 00129 00130 PreviewMode previewMode() const {return mPreviewMode;} 00131 void setPreviewMode( PreviewMode m ); 00132 00135 bool keepLayerSet() const {return mKeepLayerSet;} 00138 void setKeepLayerSet( bool enabled ) {mKeepLayerSet = enabled;} 00139 00142 QStringList layerSet() const {return mLayerSet;} 00145 void setLayerSet( const QStringList& layerSet ) {mLayerSet = layerSet;} 00147 void storeCurrentLayerSet(); 00148 00149 // Set cache outdated 00150 void setCacheUpdated( bool u = false ); 00151 00152 QgsRectangle extent() const {return mExtent;} 00153 00154 const QgsMapRenderer* mapRenderer() const {return mMapRenderer;} 00155 00157 void setOffset( double xOffset, double yOffset ); 00158 00160 bool containsWMSLayer() const; 00161 00166 bool writeXML( QDomElement& elem, QDomDocument & doc ) const; 00167 00172 bool readXML( const QDomElement& itemElem, const QDomDocument& doc ); 00173 00176 void setGridEnabled( bool enabled ) {mGridEnabled = enabled;} 00177 bool gridEnabled() const { return mGridEnabled; } 00178 00181 void setGridStyle( GridStyle style ) {mGridStyle = style;} 00182 GridStyle gridStyle() const { return mGridStyle; } 00183 00186 void setGridIntervalX( double interval ) { mGridIntervalX = interval;} 00187 double gridIntervalX() const { return mGridIntervalX; } 00188 00191 void setGridIntervalY( double interval ) { mGridIntervalY = interval;} 00192 double gridIntervalY() const { return mGridIntervalY; } 00193 00196 void setGridOffsetX( double offset ) { mGridOffsetX = offset; } 00197 double gridOffsetX() const { return mGridOffsetX; } 00198 00201 void setGridOffsetY( double offset ) { mGridOffsetY = offset; } 00202 double gridOffsetY() const { return mGridOffsetY; } 00203 00206 void setGridPen( const QPen& p ) { mGridPen = p; } 00207 QPen gridPen() const { return mGridPen; } 00210 void setGridPenWidth( double w ); 00213 void setGridPenColor( const QColor& c ); 00214 00217 void setGridAnnotationFont( const QFont& f ) { mGridAnnotationFont = f; } 00218 QFont gridAnnotationFont() const { return mGridAnnotationFont; } 00219 00222 void setGridAnnotationPrecision( int p ) {mGridAnnotationPrecision = p;} 00223 int gridAnnotationPrecision() const {return mGridAnnotationPrecision;} 00224 00227 void setShowGridAnnotation( bool show ) {mShowGridAnnotation = show;} 00228 bool showGridAnnotation() const {return mShowGridAnnotation;} 00229 00232 void setGridAnnotationPosition( GridAnnotationPosition p ) {mGridAnnotationPosition = p;} 00233 GridAnnotationPosition gridAnnotationPosition() const {return mGridAnnotationPosition;} 00234 00237 void setAnnotationFrameDistance( double d ) {mAnnotationFrameDistance = d;} 00238 double annotationFrameDistance() const {return mAnnotationFrameDistance;} 00239 00242 void setGridAnnotationDirection( GridAnnotationDirection d ) {mGridAnnotationDirection = d;} 00243 GridAnnotationDirection gridAnnotationDirection() const {return mGridAnnotationDirection;} 00244 00247 QRectF boundingRect() const; 00250 void updateBoundingRect(); 00251 00254 void setCrossLength( double l ) {mCrossLength = l;} 00255 double crossLength() {return mCrossLength;} 00256 00257 void setMapRotation( double r ); 00258 00259 void updateItem(); 00260 00262 void setMapCanvas( QGraphicsView* canvas ) { mMapCanvas = canvas; } 00263 00264 void setDrawCanvasItems( bool b ) { mDrawCanvasItems = b; } 00265 bool drawCanvasItems() const { return mDrawCanvasItems; } 00266 00268 double mapUnitsToMM() const; 00269 00270 signals: 00271 void extentChanged(); 00272 00273 public slots: 00274 00276 void updateCachedImage( ); 00278 void renderModeUpdateCachedImage(); 00279 00280 private: 00281 00283 enum Border 00284 { 00285 Left, 00286 Right, 00287 Bottom, 00288 Top 00289 }; 00290 00291 // Pointer to map renderer of the QGIS main map. Note that QgsComposerMap uses a different map renderer, 00292 //it just copies some properties from the main map renderer. 00293 QgsMapRenderer *mMapRenderer; 00294 00296 int mId; 00297 00298 // Map region in map units realy used for rendering 00299 // It can be the same as mUserExtent, but it can be bigger in on dimension if mCalculate==Scale, 00300 // so that full rectangle in paper is used. 00301 QgsRectangle mExtent; 00302 00303 // Cache used in composer preview 00304 QImage mCacheImage; 00305 00306 // Is cache up to date 00307 bool mCacheUpdated; 00308 00310 PreviewMode mPreviewMode; 00311 00313 int mNumCachedLayers; 00314 00316 bool mDrawing; 00317 00319 double mXOffset; 00321 double mYOffset; 00322 00324 bool mKeepLayerSet; 00325 00327 QStringList mLayerSet; 00328 00330 void connectUpdateSlot(); 00331 00333 void syncLayerSet(); 00334 00336 bool mGridEnabled; 00338 GridStyle mGridStyle; 00340 double mGridIntervalX; 00342 double mGridIntervalY; 00344 double mGridOffsetX; 00346 double mGridOffsetY; 00348 QPen mGridPen; 00350 QFont mGridAnnotationFont; 00352 int mGridAnnotationPrecision; 00354 bool mShowGridAnnotation; 00356 GridAnnotationPosition mGridAnnotationPosition; 00358 double mAnnotationFrameDistance; 00360 GridAnnotationDirection mGridAnnotationDirection; 00362 QRectF mCurrentRectangle; 00364 double mCrossLength; 00365 QGraphicsView* mMapCanvas; 00367 bool mDrawCanvasItems; 00368 00370 void drawGrid( QPainter* p ); 00375 void drawCoordinateAnnotations( QPainter* p, const QList< QPair< double, QLineF > >& hLines, const QList< QPair< double, QLineF > >& vLines ); 00376 void drawCoordinateAnnotation( QPainter* p, const QPointF& pos, QString annotationString ); 00382 void drawAnnotation( QPainter* p, const QPointF& pos, int rotation, const QString& annotationText ); 00385 int xGridLines( QList< QPair< double, QLineF > >& lines ) const; 00388 int yGridLines( QList< QPair< double, QLineF > >& lines ) const; 00390 QgsRectangle transformedExtent() const; 00392 QPolygonF transformedMapPolygon() const; 00393 double maxExtension() const; 00397 void mapPolygon( QPolygonF& poly ) const; 00399 void requestedExtent( QgsRectangle& extent ) const; 00403 void transformShift( double& xShift, double& yShift ) const; 00405 QPointF mapToItemCoords( const QPointF& mapCoords ) const; 00407 Border borderForLineCoord( const QPointF& p ) const; 00408 00409 void drawCanvasItems( QPainter* painter, const QStyleOptionGraphicsItem* itemStyle ); 00410 void drawCanvasItem( QGraphicsItem* item, QPainter* painter, const QStyleOptionGraphicsItem* itemStyle ); 00411 QPointF composerMapPosForItem( const QGraphicsItem* item ) const; 00412 }; 00413 00414 #endif