Quantum GIS API Documentation  1.7.5-Wroclaw
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
qgsmaprenderer.h
Go to the documentation of this file.
1 /***************************************************************************
2  qgsmaprender.h - class for rendering map layer set
3  ----------------------
4  begin : January 2006
5  copyright : (C) 2006 by Martin Dobias
6  email : wonder.sk at gmail dot com
7  ***************************************************************************
8  * *
9  * This program is free software; you can redistribute it and/or modify *
10  * it under the terms of the GNU General Public License as published by *
11  * the Free Software Foundation; either version 2 of the License, or *
12  * (at your option) any later version. *
13  * *
14  ***************************************************************************/
15 /* $Id$ */
16 
17 #ifndef QGSMAPRENDER_H
18 #define QGSMAPRENDER_H
19 
20 #include <QSize>
21 #include <QStringList>
22 #include <QVector>
23 
24 #include "qgis.h"
25 #include "qgsrectangle.h"
26 #include "qgsrendercontext.h"
27 
28 class QDomDocument;
29 class QDomNode;
30 class QPainter;
31 
32 class QgsMapToPixel;
33 class QgsMapLayer;
34 class QgsMapRenderer;
35 class QgsScaleCalculator;
37 class QgsDistanceArea;
39 class QgsVectorLayer;
40 class QgsFeature;
41 
43 
44 struct CORE_EXPORT QgsLabelPosition
45 {
46  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 ):
47  featureId( id ), rotation( r ), cornerPoints( corners ), labelRect( rect ), width( w ), height( h ), layerID( layer ), upsideDown( upside_down ), isDiagram( diagram ) {}
48  QgsLabelPosition(): featureId( -1 ), rotation( 0 ), labelRect( QgsRectangle() ), width( 0 ), height( 0 ), layerID( "" ), upsideDown( false ), isDiagram( false ) {}
49  int featureId;
50  double rotation;
51  QVector< QgsPoint > cornerPoints;
53  double width;
54  double height;
55  QString layerID;
56  bool upsideDown;
57  bool isDiagram;
58 };
59 
64 {
65  public:
66 
68 
70  virtual void init( QgsMapRenderer* mp ) = 0;
72  virtual bool willUseLayer( QgsVectorLayer* layer ) = 0;
75  virtual int prepareLayer( QgsVectorLayer* layer, QSet<int>& attrIndices, QgsRenderContext& ctx ) = 0;
77  virtual int addDiagramLayer( QgsVectorLayer* layer, QgsDiagramLayerSettings* s ) { return 0; }
79  virtual void registerFeature( QgsVectorLayer* layer, QgsFeature& feat, const QgsRenderContext& context = QgsRenderContext() ) = 0;
81  virtual void registerDiagramFeature( QgsVectorLayer* layer, QgsFeature& feat, const QgsRenderContext& context = QgsRenderContext() ) {};
83  virtual void drawLabeling( QgsRenderContext& context ) = 0;
85  virtual void exit() = 0;
88  virtual QList<QgsLabelPosition> labelsAtPosition( const QgsPoint& p ) = 0;
89 
91  virtual QgsLabelingEngineInterface* clone() = 0;
92 };
93 
94 
95 
100 class CORE_EXPORT QgsMapRenderer : public QObject
101 {
102  Q_OBJECT
103 
104  public:
105 
108  {
110  Pixels
111  //MAP_UNITS probably supported in future versions
112  };
113 
115  QgsMapRenderer();
116 
118  ~QgsMapRenderer();
119 
121  void render( QPainter* painter );
122 
124  bool setExtent( const QgsRectangle& extent );
125 
127  QgsRectangle extent() const;
128 
129  const QgsMapToPixel* coordinateTransform() { return &( mRenderContext.mapToPixel() ); }
130 
131  double scale() const { return mScale; }
134  void setScale( double scale ) {mScale = scale;}
135  double mapUnitsPerPixel() const { return mMapUnitsPerPixel; }
136 
137  int width() const { return mSize.width(); };
138  int height() const { return mSize.height(); };
139 
141  void updateScale();
142 
145  Q_DECL_DEPRECATED QgsDistanceArea *distanceArea() { return mDistArea; }
146  QGis::UnitType mapUnits() const;
147  void setMapUnits( QGis::UnitType u );
148 
150  void enableOverviewMode( bool isOverview = true ) { mOverview = isOverview; }
151 
152  void setOutputSize( QSize size, int dpi );
153  void setOutputSize( QSizeF size, double dpi );
154 
156  double outputDpi();
158  QSize outputSize();
159  QSizeF outputSizeF();
160 
162  QgsRectangle layerExtentToOutputExtent( QgsMapLayer* theLayer, QgsRectangle extent );
163 
165  QgsPoint layerToMapCoordinates( QgsMapLayer* theLayer, QgsPoint point );
166 
168  QgsPoint mapToLayerCoordinates( QgsMapLayer* theLayer, QgsPoint point );
169 
171  QgsRectangle mapToLayerCoordinates( QgsMapLayer* theLayer, QgsRectangle rect );
172 
174  void setProjectionsEnabled( bool enabled );
175 
177  bool hasCrsTransformEnabled();
178 
183  Q_DECL_DEPRECATED void setDestinationSrs( const QgsCoordinateReferenceSystem& srs ) { setDestinationCrs( srs ); };
184 
189  Q_DECL_DEPRECATED const QgsCoordinateReferenceSystem& destinationSrs() { return destinationCrs(); };
190 
192  void setDestinationCrs( const QgsCoordinateReferenceSystem& crs );
193 
195  const QgsCoordinateReferenceSystem& destinationCrs();
196 
197  void setOutputUnits( OutputUnits u ) {mOutputUnits = u;}
198 
199  OutputUnits outputUnits() const {return mOutputUnits;}
200 
202  QgsRectangle fullExtent();
203 
205  QStringList& layerSet();
206 
208  void setLayerSet( const QStringList& layers );
209 
211  void updateFullExtent();
212 
214  bool readXML( QDomNode & theNode );
215 
217  bool writeXML( QDomNode & theNode, QDomDocument & theDoc );
218 
220  QgsRenderContext* rendererContext() {return &mRenderContext;}
221 
224  QgsLabelingEngineInterface* labelingEngine() { return mLabelingEngine; }
225 
229  void setLabelingEngine( QgsLabelingEngineInterface* iface );
230 
231  signals:
232 
233  void drawingProgress( int current, int total );
234 
235  void hasCrsTransformEnabled( bool flag );
236 
237  void destinationSrsChanged();
238 
239  void updateMap();
240 
241  void mapUnitsChanged();
242 
244  void drawError( QgsMapLayer* );
245 
246  public slots:
247 
249  void onDrawingProgress( int current, int total );
250 
251  protected:
252 
254  void adjustExtentToSize();
255 
262  bool splitLayersExtent( QgsMapLayer* layer, QgsRectangle& extent, QgsRectangle& r2 );
263 
266  QgsOverlayObjectPositionManager* overlayManagerFromSettings();
267 
268  protected:
269 
271  static bool mDrawing;
272 
275 
277  double mScale;
278 
281 
284  //
291 
293  bool mOverview;
294 
295  QSizeF mSize;
296 
299 
302 
304  QStringList mLayerSet;
305 
308 
311 
314 
317 
320 };
321 
322 #endif
323