Quantum GIS API Documentation
1.7.4
|
00001 /*************************************************************************** 00002 qgsmaprender.h - class for rendering map layer set 00003 ---------------------- 00004 begin : January 2006 00005 copyright : (C) 2006 by Martin Dobias 00006 email : wonder.sk at gmail dot com 00007 *************************************************************************** 00008 * * 00009 * This program is free software; you can redistribute it and/or modify * 00010 * it under the terms of the GNU General Public License as published by * 00011 * the Free Software Foundation; either version 2 of the License, or * 00012 * (at your option) any later version. * 00013 * * 00014 ***************************************************************************/ 00015 /* $Id$ */ 00016 00017 #ifndef QGSMAPRENDER_H 00018 #define QGSMAPRENDER_H 00019 00020 #include <QSize> 00021 #include <QStringList> 00022 #include <QVector> 00023 00024 #include "qgis.h" 00025 #include "qgsrectangle.h" 00026 #include "qgsrendercontext.h" 00027 00028 class QDomDocument; 00029 class QDomNode; 00030 class QPainter; 00031 00032 class QgsMapToPixel; 00033 class QgsMapLayer; 00034 class QgsMapRenderer; 00035 class QgsScaleCalculator; 00036 class QgsCoordinateReferenceSystem; 00037 class QgsDistanceArea; 00038 class QgsOverlayObjectPositionManager; 00039 class QgsVectorLayer; 00040 class QgsFeature; 00041 00042 struct QgsDiagramLayerSettings; 00043 00044 struct CORE_EXPORT QgsLabelPosition 00045 { 00046 QgsLabelPosition( int id, double r, const QVector< QgsPoint >& corners, const QgsRectangle& rect, double w, double h, const QString& layer, bool upside_down, bool diagram = false ): 00047 featureId( id ), rotation( r ), cornerPoints( corners ), labelRect( rect ), width( w ), height( h ), layerID( layer ), upsideDown( upside_down ), isDiagram( diagram ) {} 00048 QgsLabelPosition(): featureId( -1 ), rotation( 0 ), labelRect( QgsRectangle() ), width( 0 ), height( 0 ), layerID( "" ), upsideDown( false ), isDiagram( false ) {} 00049 int featureId; 00050 double rotation; 00051 QVector< QgsPoint > cornerPoints; 00052 QgsRectangle labelRect; 00053 double width; 00054 double height; 00055 QString layerID; 00056 bool upsideDown; 00057 bool isDiagram; 00058 }; 00059 00063 class QgsLabelingEngineInterface 00064 { 00065 public: 00066 00067 virtual ~QgsLabelingEngineInterface() {} 00068 00070 virtual void init( QgsMapRenderer* mp ) = 0; 00072 virtual bool willUseLayer( QgsVectorLayer* layer ) = 0; 00075 virtual int prepareLayer( QgsVectorLayer* layer, QSet<int>& attrIndices, QgsRenderContext& ctx ) = 0; 00077 virtual int addDiagramLayer( QgsVectorLayer* layer, QgsDiagramLayerSettings* s ) { return 0; } 00079 virtual void registerFeature( QgsVectorLayer* layer, QgsFeature& feat, const QgsRenderContext& context = QgsRenderContext() ) = 0; 00081 virtual void registerDiagramFeature( QgsVectorLayer* layer, QgsFeature& feat, const QgsRenderContext& context = QgsRenderContext() ) {}; 00083 virtual void drawLabeling( QgsRenderContext& context ) = 0; 00085 virtual void exit() = 0; 00088 virtual QList<QgsLabelPosition> labelsAtPosition( const QgsPoint& p ) = 0; 00089 00091 virtual QgsLabelingEngineInterface* clone() = 0; 00092 }; 00093 00094 00095 00100 class CORE_EXPORT QgsMapRenderer : public QObject 00101 { 00102 Q_OBJECT 00103 00104 public: 00105 00107 enum OutputUnits 00108 { 00109 Millimeters, 00110 Pixels 00111 //MAP_UNITS probably supported in future versions 00112 }; 00113 00115 QgsMapRenderer(); 00116 00118 ~QgsMapRenderer(); 00119 00121 void render( QPainter* painter ); 00122 00124 bool setExtent( const QgsRectangle& extent ); 00125 00127 QgsRectangle extent() const; 00128 00129 const QgsMapToPixel* coordinateTransform() { return &( mRenderContext.mapToPixel() ); } 00130 00131 double scale() const { return mScale; } 00134 void setScale( double scale ) {mScale = scale;} 00135 double mapUnitsPerPixel() const { return mMapUnitsPerPixel; } 00136 00137 int width() const { return mSize.width(); }; 00138 int height() const { return mSize.height(); }; 00139 00141 void updateScale(); 00142 00145 Q_DECL_DEPRECATED QgsDistanceArea *distanceArea() { return mDistArea; } 00146 QGis::UnitType mapUnits() const; 00147 void setMapUnits( QGis::UnitType u ); 00148 00150 void enableOverviewMode( bool isOverview = true ) { mOverview = isOverview; } 00151 00152 void setOutputSize( QSize size, int dpi ); 00153 void setOutputSize( QSizeF size, double dpi ); 00154 00156 double outputDpi(); 00158 QSize outputSize(); 00159 QSizeF outputSizeF(); 00160 00162 QgsRectangle layerExtentToOutputExtent( QgsMapLayer* theLayer, QgsRectangle extent ); 00163 00165 QgsPoint layerToMapCoordinates( QgsMapLayer* theLayer, QgsPoint point ); 00166 00168 QgsPoint mapToLayerCoordinates( QgsMapLayer* theLayer, QgsPoint point ); 00169 00171 QgsRectangle mapToLayerCoordinates( QgsMapLayer* theLayer, QgsRectangle rect ); 00172 00174 void setProjectionsEnabled( bool enabled ); 00175 00177 bool hasCrsTransformEnabled(); 00178 00183 Q_DECL_DEPRECATED void setDestinationSrs( const QgsCoordinateReferenceSystem& srs ) { setDestinationCrs( srs ); }; 00184 00189 Q_DECL_DEPRECATED const QgsCoordinateReferenceSystem& destinationSrs() { return destinationCrs(); }; 00190 00192 void setDestinationCrs( const QgsCoordinateReferenceSystem& crs ); 00193 00195 const QgsCoordinateReferenceSystem& destinationCrs(); 00196 00197 void setOutputUnits( OutputUnits u ) {mOutputUnits = u;} 00198 00199 OutputUnits outputUnits() const {return mOutputUnits;} 00200 00202 QgsRectangle fullExtent(); 00203 00205 QStringList& layerSet(); 00206 00208 void setLayerSet( const QStringList& layers ); 00209 00211 void updateFullExtent(); 00212 00214 bool readXML( QDomNode & theNode ); 00215 00217 bool writeXML( QDomNode & theNode, QDomDocument & theDoc ); 00218 00220 QgsRenderContext* rendererContext() {return &mRenderContext;} 00221 00224 QgsLabelingEngineInterface* labelingEngine() { return mLabelingEngine; } 00225 00229 void setLabelingEngine( QgsLabelingEngineInterface* iface ); 00230 00231 signals: 00232 00233 void drawingProgress( int current, int total ); 00234 00235 void hasCrsTransformEnabled( bool flag ); 00236 00237 void destinationSrsChanged(); 00238 00239 void updateMap(); 00240 00241 void mapUnitsChanged(); 00242 00244 void drawError( QgsMapLayer* ); 00245 00246 public slots: 00247 00249 void onDrawingProgress( int current, int total ); 00250 00251 protected: 00252 00254 void adjustExtentToSize(); 00255 00262 bool splitLayersExtent( QgsMapLayer* layer, QgsRectangle& extent, QgsRectangle& r2 ); 00263 00266 QgsOverlayObjectPositionManager* overlayManagerFromSettings(); 00267 00268 protected: 00269 00271 static bool mDrawing; 00272 00274 double mMapUnitsPerPixel; 00275 00277 double mScale; 00278 00280 QgsScaleCalculator * mScaleCalculator; 00281 00283 QgsRectangle mExtent; 00284 // 00290 QgsRectangle mLastExtent; 00291 00293 bool mOverview; 00294 00295 QSizeF mSize; 00296 00298 bool mProjectionsEnabled; 00299 00301 QgsCoordinateReferenceSystem* mDestCRS; 00302 00304 QStringList mLayerSet; 00305 00307 QgsRectangle mFullExtent; 00308 00310 QgsDistanceArea* mDistArea; 00311 00313 QgsRenderContext mRenderContext; 00314 00316 OutputUnits mOutputUnits; 00317 00319 QgsLabelingEngineInterface* mLabelingEngine; 00320 }; 00321 00322 #endif 00323