Quantum GIS API Documentation  1.7.4
src/core/composer/qgscomposermap.h
Go to the documentation of this file.
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 <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 
00088     void draw( QPainter *painter, const QgsRectangle& extent, const QSizeF& size, double dpi );
00089 
00091     void paint( QPainter* painter, const QStyleOptionGraphicsItem* itemStyle, QWidget* pWidget );
00092 
00094     void cache( void );
00095 
00097     int id() const {return mId;}
00098 
00100     bool isDrawing() const {return mDrawing;}
00101 
00103     void resize( double dx, double dy );
00104 
00108     void moveContent( double dx, double dy );
00109 
00114     void zoomContent( int delta, double x, double y );
00115 
00117     void setSceneRect( const QRectF& rectangle );
00118 
00120     double scale( void ) const;
00121 
00123     void setNewScale( double scaleDenominator );
00124 
00126     void setNewExtent( const QgsRectangle& extent );
00127 
00128     PreviewMode previewMode() {return mPreviewMode;}
00129     void setPreviewMode( PreviewMode m ) {mPreviewMode = m;}
00130 
00133     bool keepLayerSet() const {return mKeepLayerSet;}
00136     void setKeepLayerSet( bool enabled ) {mKeepLayerSet = enabled;}
00137 
00140     QStringList layerSet() const {return mLayerSet;}
00143     void setLayerSet( const QStringList& layerSet ) {mLayerSet = layerSet;}
00145     void storeCurrentLayerSet();
00146 
00147     // Set cache outdated
00148     void setCacheUpdated( bool u = false );
00149 
00150     QgsRectangle extent() const {return mExtent;}
00151 
00152     const QgsMapRenderer* mapRenderer() const {return mMapRenderer;}
00153 
00155     void setOffset( double xOffset, double yOffset );
00156 
00158     bool containsWMSLayer() const;
00159 
00164     bool writeXML( QDomElement& elem, QDomDocument & doc ) const;
00165 
00170     bool readXML( const QDomElement& itemElem, const QDomDocument& doc );
00171 
00174     void setGridEnabled( bool enabled ) {mGridEnabled = enabled;}
00175     bool gridEnabled() const { return mGridEnabled; }
00176 
00179     void setGridStyle( GridStyle style ) {mGridStyle = style;}
00180     GridStyle gridStyle() const { return mGridStyle; }
00181 
00184     void setGridIntervalX( double interval ) { mGridIntervalX = interval;}
00185     double gridIntervalX() const { return mGridIntervalX; }
00186 
00189     void setGridIntervalY( double interval ) { mGridIntervalY = interval;}
00190     double gridIntervalY() const { return mGridIntervalY; }
00191 
00194     void setGridOffsetX( double offset ) { mGridOffsetX = offset; }
00195     double gridOffsetX() const { return mGridOffsetX; }
00196 
00199     void setGridOffsetY( double offset ) { mGridOffsetY = offset; }
00200     double gridOffsetY() const { return mGridOffsetY; }
00201 
00204     void setGridPen( const QPen& p ) { mGridPen = p; }
00205     QPen gridPen() const { return mGridPen; }
00208     void setGridPenWidth( double w );
00211     void setGridPenColor( const QColor& c );
00212 
00215     void setGridAnnotationFont( const QFont& f ) { mGridAnnotationFont = f; }
00216     QFont gridAnnotationFont() const { return mGridAnnotationFont; }
00217 
00220     void setGridAnnotationPrecision( int p ) {mGridAnnotationPrecision = p;}
00221     int gridAnnotationPrecision() const {return mGridAnnotationPrecision;}
00222 
00225     void setShowGridAnnotation( bool show ) {mShowGridAnnotation = show;}
00226     bool showGridAnnotation() const {return mShowGridAnnotation;}
00227 
00230     void setGridAnnotationPosition( GridAnnotationPosition p ) {mGridAnnotationPosition = p;}
00231     GridAnnotationPosition gridAnnotationPosition() const {return mGridAnnotationPosition;}
00232 
00235     void setAnnotationFrameDistance( double d ) {mAnnotationFrameDistance = d;}
00236     double annotationFrameDistance() const {return mAnnotationFrameDistance;}
00237 
00240     void setGridAnnotationDirection( GridAnnotationDirection d ) {mGridAnnotationDirection = d;}
00241     GridAnnotationDirection gridAnnotationDirection() const {return mGridAnnotationDirection;}
00242 
00245     QRectF boundingRect() const;
00248     void updateBoundingRect();
00249 
00252     void setCrossLength( double l ) {mCrossLength = l;}
00253     double crossLength() {return mCrossLength;}
00254 
00255     void setMapRotation( double r );
00256 
00258     void setMapCanvas( QGraphicsView* canvas ) { mMapCanvas = canvas; }
00259 
00260     void setDrawCanvasItems( bool b ) { mDrawCanvasItems = b; }
00261     bool drawCanvasItems() const { return mDrawCanvasItems; }
00262 
00264     double mapUnitsToMM() const;
00265 
00266   signals:
00267     void extentChanged();
00268 
00269   public slots:
00270 
00272     void updateCachedImage( );
00274     void renderModeUpdateCachedImage();
00275 
00276   private:
00277 
00279     enum Border
00280     {
00281       Left,
00282       Right,
00283       Bottom,
00284       Top
00285     };
00286 
00287     // Pointer to map renderer of the QGIS main map. Note that QgsComposerMap uses a different map renderer,
00288     //it just copies some properties from the main map renderer.
00289     QgsMapRenderer *mMapRenderer;
00290 
00292     int mId;
00293 
00294     // Map region in map units realy used for rendering
00295     // It can be the same as mUserExtent, but it can be bigger in on dimension if mCalculate==Scale,
00296     // so that full rectangle in paper is used.
00297     QgsRectangle mExtent;
00298 
00299     // Cache used in composer preview
00300     QImage mCacheImage;
00301 
00302     // Is cache up to date
00303     bool mCacheUpdated;
00304 
00306     PreviewMode mPreviewMode;
00307 
00309     int mNumCachedLayers;
00310 
00312     bool mDrawing;
00313 
00315     double mXOffset;
00317     double mYOffset;
00318 
00320     bool mKeepLayerSet;
00321 
00323     QStringList mLayerSet;
00324 
00326     void connectUpdateSlot();
00327 
00329     void syncLayerSet();
00330 
00332     bool mGridEnabled;
00334     GridStyle mGridStyle;
00336     double mGridIntervalX;
00338     double mGridIntervalY;
00340     double mGridOffsetX;
00342     double mGridOffsetY;
00344     QPen mGridPen;
00346     QFont mGridAnnotationFont;
00348     int mGridAnnotationPrecision;
00350     bool mShowGridAnnotation;
00352     GridAnnotationPosition mGridAnnotationPosition;
00354     double mAnnotationFrameDistance;
00356     GridAnnotationDirection mGridAnnotationDirection;
00358     QRectF mCurrentRectangle;
00360     double mCrossLength;
00361     QGraphicsView* mMapCanvas;
00363     bool mDrawCanvasItems;
00364 
00366     void drawGrid( QPainter* p );
00371     void drawCoordinateAnnotations( QPainter* p, const QList< QPair< double, QLineF > >& hLines, const QList< QPair< double, QLineF > >& vLines );
00372     void drawCoordinateAnnotation( QPainter* p, const QPointF& pos, QString annotationString );
00378     void drawAnnotation( QPainter* p, const QPointF& pos, int rotation, const QString& annotationText );
00381     int xGridLines( QList< QPair< double, QLineF > >& lines ) const;
00384     int yGridLines( QList< QPair< double, QLineF > >& lines ) const;
00386     QgsRectangle transformedExtent() const;
00388     QPolygonF transformedMapPolygon() const;
00389     double maxExtension() const;
00393     void mapPolygon( QPolygonF& poly ) const;
00395     void requestedExtent( QgsRectangle& extent ) const;
00399     void transformShift( double& xShift, double& yShift ) const;
00401     QPointF mapToItemCoords( const QPointF& mapCoords ) const;
00403     Border borderForLineCoord( const QPointF& p ) const;
00404 
00405     void drawCanvasItems( QPainter* painter, const QStyleOptionGraphicsItem* itemStyle );
00406     void drawCanvasItem( QGraphicsItem* item, QPainter* painter, const QStyleOptionGraphicsItem* itemStyle );
00407     QPointF composerMapPosForItem( const QGraphicsItem* item ) const;
00408 };
00409 
00410 #endif
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines