00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017 #ifndef QGSMAPRENDER_H
00018 #define QGSMAPRENDER_H
00019
00020 #include <QSize>
00021 #include <QStringList>
00022
00023 #include "qgis.h"
00024 #include "qgsrectangle.h"
00025 #include "qgsrendercontext.h"
00026
00027 class QDomDocument;
00028 class QDomNode;
00029 class QPainter;
00030
00031 class QgsMapToPixel;
00032 class QgsMapLayer;
00033 class QgsMapRenderer;
00034 class QgsScaleCalculator;
00035 class QgsCoordinateReferenceSystem;
00036 class QgsDistanceArea;
00037 class QgsOverlayObjectPositionManager;
00038 class QgsVectorLayer;
00039 class QgsFeature;
00040
00044 class QgsLabelingEngineInterface
00045 {
00046 public:
00047 virtual ~QgsLabelingEngineInterface() {}
00048
00050 virtual void init( QgsMapRenderer* mp ) = 0;
00052 virtual bool willUseLayer( QgsVectorLayer* layer ) = 0;
00055 virtual int prepareLayer( QgsVectorLayer* layer, QSet<int>& attrIndices, QgsRenderContext& ctx ) = 0;
00057 virtual void registerFeature( QgsVectorLayer* layer, QgsFeature& feat, const QgsRenderContext& context = QgsRenderContext() ) = 0;
00059 virtual void drawLabeling( QgsRenderContext& context ) = 0;
00061 virtual void exit() = 0;
00062
00064 virtual QgsLabelingEngineInterface* clone() = 0;
00065 };
00066
00067
00068
00073 class CORE_EXPORT QgsMapRenderer : public QObject
00074 {
00075 Q_OBJECT
00076
00077 public:
00078
00080 enum OutputUnits
00081 {
00082 Millimeters,
00083 Pixels
00084
00085 };
00086
00088 QgsMapRenderer();
00089
00091 ~QgsMapRenderer();
00092
00094 void render( QPainter* painter );
00095
00097 bool setExtent( const QgsRectangle& extent );
00098
00100 QgsRectangle extent() const;
00101
00102 const QgsMapToPixel* coordinateTransform() { return &( mRenderContext.mapToPixel() ); }
00103
00104 double scale() const { return mScale; }
00107 void setScale( double scale ) {mScale = scale;}
00108 double mapUnitsPerPixel() const { return mMapUnitsPerPixel; }
00109
00110 int width() const { return mSize.width(); };
00111 int height() const { return mSize.height(); };
00112
00114 void updateScale();
00115
00117 QgsDistanceArea* distanceArea() { return mDistArea; }
00118 QGis::UnitType mapUnits() const;
00119 void setMapUnits( QGis::UnitType u );
00120
00122 void enableOverviewMode( bool isOverview = true ) { mOverview = isOverview; }
00123
00124 void setOutputSize( QSize size, int dpi );
00125 void setOutputSize( QSizeF size, double dpi );
00126
00128 double outputDpi();
00130 QSize outputSize();
00131 QSizeF outputSizeF();
00132
00134 QgsRectangle layerExtentToOutputExtent( QgsMapLayer* theLayer, QgsRectangle extent );
00135
00137 QgsPoint layerToMapCoordinates( QgsMapLayer* theLayer, QgsPoint point );
00138
00140 QgsPoint mapToLayerCoordinates( QgsMapLayer* theLayer, QgsPoint point );
00141
00143 QgsRectangle mapToLayerCoordinates( QgsMapLayer* theLayer, QgsRectangle rect );
00144
00146 void setProjectionsEnabled( bool enabled );
00147
00149 bool hasCrsTransformEnabled();
00150
00152 void setDestinationSrs( const QgsCoordinateReferenceSystem& srs );
00153
00155 const QgsCoordinateReferenceSystem& destinationSrs();
00156
00157 void setOutputUnits( OutputUnits u ) {mOutputUnits = u;}
00158
00159 OutputUnits outputUnits() const {return mOutputUnits;}
00160
00162 QgsRectangle fullExtent();
00163
00165 QStringList& layerSet();
00166
00168 void setLayerSet( const QStringList& layers );
00169
00171 void updateFullExtent();
00172
00174 bool readXML( QDomNode & theNode );
00175
00177 bool writeXML( QDomNode & theNode, QDomDocument & theDoc );
00178
00180 QgsRenderContext* rendererContext() {return &mRenderContext;}
00181
00184 QgsLabelingEngineInterface* labelingEngine() { return mLabelingEngine; }
00185
00189 void setLabelingEngine( QgsLabelingEngineInterface* iface );
00190
00191 signals:
00192
00193 void drawingProgress( int current, int total );
00194
00195 void hasCrsTransformEnabled( bool flag );
00196
00197 void destinationSrsChanged();
00198
00199 void updateMap();
00200
00201 void mapUnitsChanged();
00202
00204 void drawError( QgsMapLayer* );
00205
00206 public slots:
00207
00209 void onDrawingProgress( int current, int total );
00210
00211 protected:
00212
00214 void adjustExtentToSize();
00215
00222 bool splitLayersExtent( QgsMapLayer* layer, QgsRectangle& extent, QgsRectangle& r2 );
00223
00226 QgsOverlayObjectPositionManager* overlayManagerFromSettings();
00227
00228 protected:
00229
00231 bool mDrawing;
00232
00234 double mMapUnitsPerPixel;
00235
00237 double mScale;
00238
00240 QgsScaleCalculator * mScaleCalculator;
00241
00243 QgsRectangle mExtent;
00244
00250 QgsRectangle mLastExtent;
00251
00253 bool mOverview;
00254
00255 QSizeF mSize;
00256
00258 bool mProjectionsEnabled;
00259
00261 QgsCoordinateReferenceSystem* mDestCRS;
00262
00264 QStringList mLayerSet;
00265
00267 QgsRectangle mFullExtent;
00268
00270 QgsDistanceArea* mDistArea;
00271
00273 QgsRenderContext mRenderContext;
00274
00276 OutputUnits mOutputUnits;
00277
00279 QgsLabelingEngineInterface* mLabelingEngine;
00280 };
00281
00282 #endif
00283