Quantum GIS API Documentation
1.8
|
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 00016 #ifndef QGSMAPRENDER_H 00017 #define QGSMAPRENDER_H 00018 00019 #include <QMutex> 00020 #include <QSize> 00021 #include <QStringList> 00022 #include <QVector> 00023 00024 #include "qgis.h" 00025 #include "qgsrectangle.h" 00026 #include "qgsrendercontext.h" 00027 #include "qgsfeature.h" 00028 00029 class QDomDocument; 00030 class QDomNode; 00031 class QPainter; 00032 00033 class QgsMapToPixel; 00034 class QgsMapLayer; 00035 class QgsMapRenderer; 00036 class QgsScaleCalculator; 00037 class QgsCoordinateReferenceSystem; 00038 class QgsDistanceArea; 00039 class QgsOverlayObjectPositionManager; 00040 class QgsVectorLayer; 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 ) 00078 { Q_UNUSED( layer ); Q_UNUSED( s ); return 0; } 00080 virtual void registerFeature( QgsVectorLayer* layer, QgsFeature& feat, const QgsRenderContext& context = QgsRenderContext() ) = 0; 00082 virtual void registerDiagramFeature( QgsVectorLayer* layer, QgsFeature& feat, const QgsRenderContext& context = QgsRenderContext() ) 00083 { Q_UNUSED( layer ); Q_UNUSED( feat ); Q_UNUSED( context ); } 00085 virtual void drawLabeling( QgsRenderContext& context ) = 0; 00087 virtual void exit() = 0; 00090 virtual QList<QgsLabelPosition> labelsAtPosition( const QgsPoint& p ) = 0; 00091 00093 virtual QgsLabelingEngineInterface* clone() = 0; 00094 }; 00095 00096 00097 00102 class CORE_EXPORT QgsMapRenderer : public QObject 00103 { 00104 Q_OBJECT 00105 00106 public: 00107 00109 enum OutputUnits 00110 { 00111 Millimeters, 00112 Pixels 00113 //MAP_UNITS probably supported in future versions 00114 }; 00115 00117 QgsMapRenderer(); 00118 00120 ~QgsMapRenderer(); 00121 00124 void render( QPainter* painter, double* forceWidthScale = 0 ); 00125 00127 bool setExtent( const QgsRectangle& extent ); 00128 00130 QgsRectangle extent() const; 00131 00132 const QgsMapToPixel* coordinateTransform() { return &( mRenderContext.mapToPixel() ); } 00133 00134 double scale() const { return mScale; } 00137 void setScale( double scale ) {mScale = scale;} 00138 double mapUnitsPerPixel() const { return mMapUnitsPerPixel; } 00139 00140 int width() const { return mSize.width(); }; 00141 int height() const { return mSize.height(); }; 00142 00144 void updateScale(); 00145 00148 Q_DECL_DEPRECATED QgsDistanceArea *distanceArea() { return mDistArea; } 00149 QGis::UnitType mapUnits() const; 00150 void setMapUnits( QGis::UnitType u ); 00151 00153 void enableOverviewMode( bool isOverview = true ) { mOverview = isOverview; } 00154 00155 void setOutputSize( QSize size, int dpi ); 00156 void setOutputSize( QSizeF size, double dpi ); 00157 00159 double outputDpi(); 00161 QSize outputSize(); 00162 QSizeF outputSizeF(); 00163 00165 QgsRectangle layerExtentToOutputExtent( QgsMapLayer* theLayer, QgsRectangle extent ); 00166 00168 QgsPoint layerToMapCoordinates( QgsMapLayer* theLayer, QgsPoint point ); 00169 00171 QgsPoint mapToLayerCoordinates( QgsMapLayer* theLayer, QgsPoint point ); 00172 00174 QgsRectangle mapToLayerCoordinates( QgsMapLayer* theLayer, QgsRectangle rect ); 00175 00177 void setProjectionsEnabled( bool enabled ); 00178 00180 bool hasCrsTransformEnabled(); 00181 00186 Q_DECL_DEPRECATED void setDestinationSrs( const QgsCoordinateReferenceSystem& srs ) { setDestinationCrs( srs ); }; 00187 00192 Q_DECL_DEPRECATED const QgsCoordinateReferenceSystem& destinationSrs() { return destinationCrs(); }; 00193 00195 void setDestinationCrs( const QgsCoordinateReferenceSystem& crs ); 00196 00198 const QgsCoordinateReferenceSystem& destinationCrs(); 00199 00200 void setOutputUnits( OutputUnits u ) {mOutputUnits = u;} 00201 00202 OutputUnits outputUnits() const {return mOutputUnits;} 00203 00205 QgsRectangle fullExtent(); 00206 00208 QStringList& layerSet(); 00209 00211 void setLayerSet( const QStringList& layers ); 00212 00214 void updateFullExtent(); 00215 00217 bool readXML( QDomNode & theNode ); 00218 00220 bool writeXML( QDomNode & theNode, QDomDocument & theDoc ); 00221 00223 QgsRenderContext* rendererContext() {return &mRenderContext;} 00224 00227 QgsLabelingEngineInterface* labelingEngine() { return mLabelingEngine; } 00228 00232 void setLabelingEngine( QgsLabelingEngineInterface* iface ); 00233 00234 signals: 00235 00236 void drawingProgress( int current, int total ); 00237 00238 void hasCrsTransformEnabled( bool flag ); 00239 00240 void destinationSrsChanged(); 00241 00242 void updateMap(); 00243 00244 void mapUnitsChanged(); 00245 00247 void drawError( QgsMapLayer* ); 00248 00249 public slots: 00250 00252 void onDrawingProgress( int current, int total ); 00253 00255 void invalidateCachedLayerCrs(); 00256 00258 void cachedLayerDestroyed(); 00259 00260 protected: 00261 00263 void adjustExtentToSize(); 00264 00271 bool splitLayersExtent( QgsMapLayer* layer, QgsRectangle& extent, QgsRectangle& r2 ); 00272 00275 QgsOverlayObjectPositionManager* overlayManagerFromSettings(); 00276 00278 static bool mDrawing; 00279 00281 double mMapUnitsPerPixel; 00282 00284 double mScale; 00285 00287 QgsScaleCalculator * mScaleCalculator; 00288 00290 QgsRectangle mExtent; 00291 // 00297 QgsRectangle mLastExtent; 00298 00300 bool mOverview; 00301 00302 QSizeF mSize; 00303 00305 bool mProjectionsEnabled; 00306 00308 QgsCoordinateReferenceSystem* mDestCRS; 00309 00311 QStringList mLayerSet; 00312 00314 QgsRectangle mFullExtent; 00315 00317 QgsDistanceArea* mDistArea; 00318 00320 QgsRenderContext mRenderContext; 00321 00323 OutputUnits mOutputUnits; 00324 00326 QgsLabelingEngineInterface* mLabelingEngine; 00327 00329 QMutex mRenderMutex; 00330 00331 private: 00332 QgsCoordinateTransform *tr( QgsMapLayer *layer ); 00333 QgsCoordinateTransform *mCachedTr; 00334 QgsMapLayer *mCachedTrForLayer; 00335 }; 00336 00337 #endif 00338