|
Quantum GIS API Documentation
master-693a1fe
|
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 #include <QPainter> 00024 00025 #include "qgis.h" 00026 #include "qgsrectangle.h" 00027 #include "qgsrendercontext.h" 00028 #include "qgsfeature.h" 00029 00030 class QDomDocument; 00031 class QDomNode; 00032 class QPainter; 00033 00034 class QgsMapToPixel; 00035 class QgsMapLayer; 00036 class QgsMapRenderer; 00037 class QgsScaleCalculator; 00038 class QgsCoordinateReferenceSystem; 00039 class QgsDistanceArea; 00040 class QgsOverlayObjectPositionManager; 00041 class QgsVectorLayer; 00042 00043 class QgsPalLayerSettings; 00044 class QgsDiagramLayerSettings; 00045 00046 class CORE_EXPORT QgsLabelPosition 00047 { 00048 public: 00049 QgsLabelPosition( int id, double r, const QVector< QgsPoint >& corners, const QgsRectangle& rect, double w, double h, const QString& layer, const QString& labeltext, bool upside_down, bool diagram = false, bool pinned = false ): 00050 featureId( id ), rotation( r ), cornerPoints( corners ), labelRect( rect ), width( w ), height( h ), layerID( layer ), labelText( labeltext ), upsideDown( upside_down ), isDiagram( diagram ), isPinned( pinned ) {} 00051 QgsLabelPosition(): featureId( -1 ), rotation( 0 ), labelRect( QgsRectangle() ), width( 0 ), height( 0 ), layerID( "" ), labelText( "" ), upsideDown( false ), isDiagram( false ), isPinned( false ) {} 00052 int featureId; 00053 double rotation; 00054 QVector< QgsPoint > cornerPoints; 00055 QgsRectangle labelRect; 00056 double width; 00057 double height; 00058 QString layerID; 00059 QString labelText; 00060 bool upsideDown; 00061 bool isDiagram; 00062 bool isPinned; 00063 }; 00064 00068 class CORE_EXPORT QgsLabelingEngineInterface 00069 { 00070 public: 00071 00072 virtual ~QgsLabelingEngineInterface() {} 00073 00075 virtual void init( QgsMapRenderer* mp ) = 0; 00077 virtual bool willUseLayer( QgsVectorLayer* layer ) = 0; 00080 virtual int prepareLayer( QgsVectorLayer* layer, QSet<int>& attrIndices, QgsRenderContext& ctx ) = 0; 00083 virtual QgsPalLayerSettings& layer( const QString& layerName ) = 0; 00085 virtual int addDiagramLayer( QgsVectorLayer* layer, QgsDiagramLayerSettings* s ) 00086 { Q_UNUSED( layer ); Q_UNUSED( s ); return 0; } 00088 virtual void registerFeature( QgsVectorLayer* layer, QgsFeature& feat, const QgsRenderContext& context = QgsRenderContext() ) = 0; 00090 virtual void registerDiagramFeature( QgsVectorLayer* layer, QgsFeature& feat, const QgsRenderContext& context = QgsRenderContext() ) 00091 { Q_UNUSED( layer ); Q_UNUSED( feat ); Q_UNUSED( context ); } 00093 virtual void drawLabeling( QgsRenderContext& context ) = 0; 00095 virtual void exit() = 0; 00098 virtual QList<QgsLabelPosition> labelsAtPosition( const QgsPoint& p ) = 0; 00101 virtual QList<QgsLabelPosition> labelsWithinRect( const QgsRectangle& r ) = 0; 00102 00104 virtual QgsLabelingEngineInterface* clone() = 0; 00105 }; 00106 00107 00108 00113 class CORE_EXPORT QgsMapRenderer : public QObject 00114 { 00115 Q_OBJECT 00116 00117 public: 00118 00120 enum OutputUnits 00121 { 00122 Millimeters, 00123 Pixels 00124 //MAP_UNITS probably supported in future versions 00125 }; 00126 00130 enum BlendMode 00131 { 00132 BlendNormal, 00133 BlendLighten, 00134 BlendScreen, 00135 BlendDodge, 00136 BlendAddition, 00137 BlendDarken, 00138 BlendMultiply, 00139 BlendBurn, 00140 BlendOverlay, 00141 BlendSoftLight, 00142 BlendHardLight, 00143 BlendDifference, 00144 BlendSubtract 00145 }; 00146 00148 QgsMapRenderer(); 00149 00151 ~QgsMapRenderer(); 00152 00155 void render( QPainter* painter, double* forceWidthScale = 0 ); 00156 00158 bool setExtent( const QgsRectangle& extent ); 00159 00161 QgsRectangle extent() const; 00162 00163 const QgsMapToPixel* coordinateTransform() { return &( mRenderContext.mapToPixel() ); } 00164 00166 double scale() const { return mScale; } 00169 void setScale( double scale ) {mScale = scale;} 00170 double mapUnitsPerPixel() const { return mMapUnitsPerPixel; } 00171 00172 int width() const { return mSize.width(); }; 00173 int height() const { return mSize.height(); }; 00174 00176 void updateScale(); 00177 00178 QGis::UnitType mapUnits() const; 00179 void setMapUnits( QGis::UnitType u ); 00180 00182 void enableOverviewMode( bool isOverview = true ) { mOverview = isOverview; } 00183 00184 void setOutputSize( QSize size, int dpi ); 00185 void setOutputSize( QSizeF size, double dpi ); 00186 00188 double outputDpi(); 00190 QSize outputSize(); 00191 QSizeF outputSizeF(); 00192 00198 QgsRectangle layerExtentToOutputExtent( QgsMapLayer* theLayer, QgsRectangle extent ); 00199 00205 QgsRectangle outputExtentToLayerExtent( QgsMapLayer* theLayer, QgsRectangle extent ); 00206 00211 QgsPoint layerToMapCoordinates( QgsMapLayer* theLayer, QgsPoint point ); 00212 00218 QgsRectangle layerToMapCoordinates( QgsMapLayer* theLayer, QgsRectangle rect ); 00219 00224 QgsPoint mapToLayerCoordinates( QgsMapLayer* theLayer, QgsPoint point ); 00225 00231 QgsRectangle mapToLayerCoordinates( QgsMapLayer* theLayer, QgsRectangle rect ); 00232 00234 void setProjectionsEnabled( bool enabled ); 00235 00237 bool hasCrsTransformEnabled() const; 00238 00240 void setDestinationCrs( const QgsCoordinateReferenceSystem& crs ); 00241 00243 const QgsCoordinateReferenceSystem& destinationCrs() const; 00244 00245 void setOutputUnits( OutputUnits u ) {mOutputUnits = u;} 00246 00247 OutputUnits outputUnits() const {return mOutputUnits;} 00248 00250 QgsRectangle fullExtent(); 00251 00253 QStringList& layerSet(); 00254 00256 void setLayerSet( const QStringList& layers ); 00257 00259 void updateFullExtent(); 00260 00262 bool readXML( QDomNode & theNode ); 00263 00265 bool writeXML( QDomNode & theNode, QDomDocument & theDoc ); 00266 00268 QgsRenderContext* rendererContext() {return &mRenderContext;} 00269 00272 QgsLabelingEngineInterface* labelingEngine() { return mLabelingEngine; } 00273 00277 void setLabelingEngine( QgsLabelingEngineInterface* iface ); 00278 00281 static QPainter::CompositionMode getCompositionMode( const QgsMapRenderer::BlendMode blendMode ); 00284 static QgsMapRenderer::BlendMode getBlendModeEnum( const QPainter::CompositionMode blendMode ); 00285 00286 signals: 00287 00288 void drawingProgress( int current, int total ); 00289 00290 void hasCrsTransformEnabled( bool flag ); 00291 00292 void destinationSrsChanged(); 00293 00294 void updateMap(); 00295 00296 void mapUnitsChanged(); 00297 00299 void drawError( QgsMapLayer* ); 00300 00301 public slots: 00302 00304 void onDrawingProgress( int current, int total ); 00305 00306 protected: 00307 00309 void adjustExtentToSize(); 00310 00317 bool splitLayersExtent( QgsMapLayer* layer, QgsRectangle& extent, QgsRectangle& r2 ); 00318 00321 QgsOverlayObjectPositionManager* overlayManagerFromSettings(); 00322 00324 static bool mDrawing; 00325 00327 double mMapUnitsPerPixel; 00328 00330 double mScale; 00331 00333 QgsScaleCalculator * mScaleCalculator; 00334 00336 QgsRectangle mExtent; 00337 // 00343 QgsRectangle mLastExtent; 00344 00346 bool mOverview; 00347 00348 QSizeF mSize; 00349 00351 bool mProjectionsEnabled; 00352 00354 QgsCoordinateReferenceSystem* mDestCRS; 00355 00357 QStringList mLayerSet; 00358 00360 QgsRectangle mFullExtent; 00361 00363 QgsDistanceArea* mDistArea; 00364 00366 QgsRenderContext mRenderContext; 00367 00369 OutputUnits mOutputUnits; 00370 00372 QgsLabelingEngineInterface* mLabelingEngine; 00373 00375 QMutex mRenderMutex; 00376 00377 private: 00378 const QgsCoordinateTransform* tr( QgsMapLayer *layer ); 00379 }; 00380 00381 #endif 00382