|
QGIS API Documentation
master-6164ace
|
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, const QFont& labelfont, 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 ), labelFont( labelfont ), upsideDown( upside_down ), isDiagram( diagram ), isPinned( pinned ) {} 00051 QgsLabelPosition(): featureId( -1 ), rotation( 0 ), labelRect( QgsRectangle() ), width( 0 ), height( 0 ), layerID( "" ), labelText( "" ), labelFont( QFont() ), 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 QFont labelFont; 00061 bool upsideDown; 00062 bool isDiagram; 00063 bool isPinned; 00064 }; 00065 00069 class CORE_EXPORT QgsLabelingEngineInterface 00070 { 00071 public: 00072 00073 virtual ~QgsLabelingEngineInterface() {} 00074 00076 virtual void init( QgsMapRenderer* mp ) = 0; 00078 virtual bool willUseLayer( QgsVectorLayer* layer ) = 0; 00081 virtual void clearActiveLayers() = 0; 00084 virtual void clearActiveLayer( QgsVectorLayer* layer ) = 0; 00087 virtual int prepareLayer( QgsVectorLayer* layer, QSet<int>& attrIndices, QgsRenderContext& ctx ) = 0; 00090 virtual QgsPalLayerSettings& layer( const QString& layerName ) = 0; 00092 virtual int addDiagramLayer( QgsVectorLayer* layer, QgsDiagramLayerSettings* s ) 00093 { Q_UNUSED( layer ); Q_UNUSED( s ); return 0; } 00095 virtual void registerFeature( QgsVectorLayer* layer, QgsFeature& feat, const QgsRenderContext& context = QgsRenderContext() ) = 0; 00097 virtual void registerDiagramFeature( QgsVectorLayer* layer, QgsFeature& feat, const QgsRenderContext& context = QgsRenderContext() ) 00098 { Q_UNUSED( layer ); Q_UNUSED( feat ); Q_UNUSED( context ); } 00100 virtual void drawLabeling( QgsRenderContext& context ) = 0; 00102 virtual void exit() = 0; 00105 virtual QList<QgsLabelPosition> labelsAtPosition( const QgsPoint& p ) = 0; 00108 virtual QList<QgsLabelPosition> labelsWithinRect( const QgsRectangle& r ) = 0; 00109 00111 virtual QgsLabelingEngineInterface* clone() = 0; 00112 }; 00113 00114 00115 00120 class CORE_EXPORT QgsMapRenderer : public QObject 00121 { 00122 Q_OBJECT 00123 00124 public: 00125 00127 enum OutputUnits 00128 { 00129 Millimeters, 00130 Pixels 00131 //MAP_UNITS probably supported in future versions 00132 }; 00133 00137 enum BlendMode 00138 { 00139 BlendNormal, 00140 BlendLighten, 00141 BlendScreen, 00142 BlendDodge, 00143 BlendAddition, 00144 BlendDarken, 00145 BlendMultiply, 00146 BlendBurn, 00147 BlendOverlay, 00148 BlendSoftLight, 00149 BlendHardLight, 00150 BlendDifference, 00151 BlendSubtract 00152 }; 00153 00155 QgsMapRenderer(); 00156 00158 ~QgsMapRenderer(); 00159 00162 void render( QPainter* painter, double* forceWidthScale = 0 ); 00163 00165 bool setExtent( const QgsRectangle& extent ); 00166 00168 QgsRectangle extent() const; 00169 00170 const QgsMapToPixel* coordinateTransform() { return &( mRenderContext.mapToPixel() ); } 00171 00173 double scale() const { return mScale; } 00176 void setScale( double scale ) {mScale = scale;} 00177 double mapUnitsPerPixel() const { return mMapUnitsPerPixel; } 00178 00179 int width() const { return mSize.width(); }; 00180 int height() const { return mSize.height(); }; 00181 00183 void updateScale(); 00184 00185 QGis::UnitType mapUnits() const; 00186 void setMapUnits( QGis::UnitType u ); 00187 00189 void enableOverviewMode( bool isOverview = true ) { mOverview = isOverview; } 00190 00191 void setOutputSize( QSize size, int dpi ); 00192 void setOutputSize( QSizeF size, double dpi ); 00193 00195 double outputDpi(); 00197 QSize outputSize(); 00198 QSizeF outputSizeF(); 00199 00205 QgsRectangle layerExtentToOutputExtent( QgsMapLayer* theLayer, QgsRectangle extent ); 00206 00212 QgsRectangle outputExtentToLayerExtent( QgsMapLayer* theLayer, QgsRectangle extent ); 00213 00218 QgsPoint layerToMapCoordinates( QgsMapLayer* theLayer, QgsPoint point ); 00219 00225 QgsRectangle layerToMapCoordinates( QgsMapLayer* theLayer, QgsRectangle rect ); 00226 00231 QgsPoint mapToLayerCoordinates( QgsMapLayer* theLayer, QgsPoint point ); 00232 00238 QgsRectangle mapToLayerCoordinates( QgsMapLayer* theLayer, QgsRectangle rect ); 00239 00241 void setProjectionsEnabled( bool enabled ); 00242 00244 bool hasCrsTransformEnabled() const; 00245 00247 void setDestinationCrs( const QgsCoordinateReferenceSystem& crs ); 00248 00250 const QgsCoordinateReferenceSystem& destinationCrs() const; 00251 00252 void setOutputUnits( OutputUnits u ) {mOutputUnits = u;} 00253 00254 OutputUnits outputUnits() const {return mOutputUnits;} 00255 00257 QgsRectangle fullExtent(); 00258 00260 QStringList& layerSet(); 00261 00263 void setLayerSet( const QStringList& layers ); 00264 00266 void updateFullExtent(); 00267 00269 bool readXML( QDomNode & theNode ); 00270 00272 bool writeXML( QDomNode & theNode, QDomDocument & theDoc ); 00273 00275 QgsRenderContext* rendererContext() {return &mRenderContext;} 00276 00279 QgsLabelingEngineInterface* labelingEngine() { return mLabelingEngine; } 00280 00284 void setLabelingEngine( QgsLabelingEngineInterface* iface ); 00285 00288 static QPainter::CompositionMode getCompositionMode( const QgsMapRenderer::BlendMode blendMode ); 00291 static QgsMapRenderer::BlendMode getBlendModeEnum( const QPainter::CompositionMode blendMode ); 00292 00293 signals: 00294 00295 void drawingProgress( int current, int total ); 00296 00297 void hasCrsTransformEnabled( bool flag ); 00298 00299 void destinationSrsChanged(); 00300 00301 void updateMap(); 00302 00303 void mapUnitsChanged(); 00304 00306 void drawError( QgsMapLayer* ); 00307 00308 public slots: 00309 00311 void onDrawingProgress( int current, int total ); 00312 00313 protected: 00314 00316 void adjustExtentToSize(); 00317 00324 bool splitLayersExtent( QgsMapLayer* layer, QgsRectangle& extent, QgsRectangle& r2 ); 00325 00328 QgsOverlayObjectPositionManager* overlayManagerFromSettings(); 00329 00331 static bool mDrawing; 00332 00334 double mMapUnitsPerPixel; 00335 00337 double mScale; 00338 00340 QgsScaleCalculator * mScaleCalculator; 00341 00343 QgsRectangle mExtent; 00344 // 00350 QgsRectangle mLastExtent; 00351 00353 bool mOverview; 00354 00355 QSizeF mSize; 00356 00358 bool mProjectionsEnabled; 00359 00361 QgsCoordinateReferenceSystem* mDestCRS; 00362 00364 QStringList mLayerSet; 00365 00367 QgsRectangle mFullExtent; 00368 00370 QgsDistanceArea* mDistArea; 00371 00373 QgsRenderContext mRenderContext; 00374 00376 OutputUnits mOutputUnits; 00377 00379 QgsLabelingEngineInterface* mLabelingEngine; 00380 00382 QMutex mRenderMutex; 00383 00384 private: 00385 const QgsCoordinateTransform* tr( QgsMapLayer *layer ); 00386 }; 00387 00388 #endif 00389