QGIS API Documentation  2.5.0-Master
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules 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 
16 #ifndef QGSMAPRENDER_H
17 #define QGSMAPRENDER_H
18 
19 #include <QMutex>
20 #include <QSize>
21 #include <QStringList>
22 #include <QVector>
23 #include <QPainter>
24 
25 #include "qgis.h"
26 #include "qgsrectangle.h"
27 #include "qgsrendercontext.h"
28 #include "qgsfeature.h"
29 #include "qgsmapsettings.h"
30 
31 class QDomDocument;
32 class QDomNode;
33 class QPainter;
34 
35 class QgsMapToPixel;
36 class QgsMapLayer;
37 class QgsMapRenderer;
38 class QgsScaleCalculator;
40 class QgsDistanceArea;
41 class QgsVectorLayer;
42 
45 
46 class CORE_EXPORT QgsLabelPosition
47 {
48  public:
49  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 ):
50  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 ) {}
51  QgsLabelPosition(): featureId( -1 ), rotation( 0 ), labelRect( QgsRectangle() ), width( 0 ), height( 0 ), layerID( "" ), labelText( "" ), labelFont( QFont() ), upsideDown( false ), isDiagram( false ), isPinned( false ) {}
52  int featureId;
53  double rotation;
54  QVector< QgsPoint > cornerPoints;
56  double width;
57  double height;
58  QString layerID;
59  QString labelText;
60  QFont labelFont;
61  bool upsideDown;
62  bool isDiagram;
63  bool isPinned;
64 };
65 
69 class CORE_EXPORT QgsLabelingEngineInterface
70 {
71  public:
72 
74 
77  Q_DECL_DEPRECATED virtual void init( QgsMapRenderer* mp ) = 0;
79  virtual void init( const QgsMapSettings& mapSettings ) = 0;
81  virtual bool willUseLayer( QgsVectorLayer* layer ) = 0;
84  virtual void clearActiveLayers() = 0;
87  virtual void clearActiveLayer( const QString& layerID ) = 0;
90  virtual int prepareLayer( QgsVectorLayer* layer, QStringList& attrNames, QgsRenderContext& ctx ) = 0;
93  virtual QgsPalLayerSettings& layer( const QString& layerName ) = 0;
95  virtual int addDiagramLayer( QgsVectorLayer* layer, const QgsDiagramLayerSettings* s )
96  { Q_UNUSED( layer ); Q_UNUSED( s ); return 0; }
98  virtual void registerFeature( const QString& layerID, QgsFeature& feat, const QgsRenderContext& context = QgsRenderContext(), QString dxfLayer = QString::null ) = 0;
100  virtual void registerDiagramFeature( const QString& layerID, QgsFeature& feat, const QgsRenderContext& context = QgsRenderContext() )
101  { Q_UNUSED( layerID ); Q_UNUSED( feat ); Q_UNUSED( context ); }
103  virtual void drawLabeling( QgsRenderContext& context ) = 0;
105  virtual void exit() = 0;
109  Q_DECL_DEPRECATED virtual QList<QgsLabelPosition> labelsAtPosition( const QgsPoint& p ) = 0;
113  Q_DECL_DEPRECATED virtual QList<QgsLabelPosition> labelsWithinRect( const QgsRectangle& r ) = 0;
114 
116  virtual QgsLabelingEngineInterface* clone() = 0;
117 };
118 
119 struct CORE_EXPORT QgsLayerCoordinateTransform
120 {
121  QString srcAuthId;
122  QString destAuthId;
123  int srcDatumTransform; //-1 if unknown or not specified
125 };
126 
127 // ### QGIS 3: remove QgsMapRenderer in favor of QgsMapRendererJob
128 
133 class CORE_EXPORT QgsMapRenderer : public QObject
134 {
135  Q_OBJECT
136 
137  public:
138 
141  {
143  Pixels
144  //MAP_UNITS probably supported in future versions
145  };
146 
151  {
176  };
177 
179  QgsMapRenderer();
180 
182  ~QgsMapRenderer();
183 
187  void render( QPainter* painter, double* forceWidthScale = 0 );
188 
190  bool setExtent( const QgsRectangle& extent );
191 
193  QgsRectangle extent() const;
194 
195  const QgsMapToPixel* coordinateTransform() { return &( mRenderContext.mapToPixel() ); }
196 
198  double scale() const { return mScale; }
201  void setScale( double scale ) {mScale = scale;}
202  double mapUnitsPerPixel() const { return mMapUnitsPerPixel; }
203 
204  int width() const { return ( int ) mSize.width(); }
205  int height() const { return ( int ) mSize.height(); }
206 
208  void updateScale();
209 
210  QGis::UnitType mapUnits() const;
211  void setMapUnits( QGis::UnitType u );
212 
214  void enableOverviewMode( bool isOverview = true ) { mOverview = isOverview; }
215 
216  void setOutputSize( QSize size, int dpi );
217  void setOutputSize( QSizeF size, double dpi );
218 
220  double outputDpi();
222  QSize outputSize();
223  QSizeF outputSizeF();
224 
230  QgsRectangle layerExtentToOutputExtent( QgsMapLayer* theLayer, QgsRectangle extent );
231 
237  QgsRectangle outputExtentToLayerExtent( QgsMapLayer* theLayer, QgsRectangle extent );
238 
243  QgsPoint layerToMapCoordinates( QgsMapLayer* theLayer, QgsPoint point );
244 
250  QgsRectangle layerToMapCoordinates( QgsMapLayer* theLayer, QgsRectangle rect );
251 
256  QgsPoint mapToLayerCoordinates( QgsMapLayer* theLayer, QgsPoint point );
257 
263  QgsRectangle mapToLayerCoordinates( QgsMapLayer* theLayer, QgsRectangle rect );
264 
266  void setProjectionsEnabled( bool enabled );
267 
269  bool hasCrsTransformEnabled() const;
270 
272  void setDestinationCrs( const QgsCoordinateReferenceSystem& crs, bool refreshCoordinateTransformInfo = true, bool transformExtent = true );
273 
275  const QgsCoordinateReferenceSystem& destinationCrs() const;
276 
277  void setOutputUnits( OutputUnits u ) {mOutputUnits = u;}
278 
279  OutputUnits outputUnits() const {return mOutputUnits;}
280 
282  QgsRectangle fullExtent();
283 
285  QStringList& layerSet();
286 
288  void setLayerSet( const QStringList& layers );
289 
291  void updateFullExtent();
292 
294  bool readXML( QDomNode & theNode );
295 
297  bool writeXML( QDomNode & theNode, QDomDocument & theDoc );
298 
300  QgsRenderContext* rendererContext() {return &mRenderContext;}
301 
304  QgsLabelingEngineInterface* labelingEngine() { return mLabelingEngine; }
305 
309  void setLabelingEngine( QgsLabelingEngineInterface* iface );
310 
313  static QPainter::CompositionMode getCompositionMode( const QgsMapRenderer::BlendMode &blendMode );
316  static QgsMapRenderer::BlendMode getBlendModeEnum( const QPainter::CompositionMode &blendMode );
317 
318  void addLayerCoordinateTransform( const QString& layerId, const QString& srcAuthId, const QString& destAuthId, int srcDatumTransform = -1, int destDatumTransform = -1 );
319  void clearLayerCoordinateTransforms();
320 
321  const QgsCoordinateTransform* transformation( const QgsMapLayer *layer ) const;
322 
325  const QgsMapSettings& mapSettings();
326 
333  bool splitLayersExtent( QgsMapLayer* layer, QgsRectangle& extent, QgsRectangle& r2 );
334 
335  signals:
336 
338  void drawingProgress( int current, int total );
339 
344 #ifndef Q_MOC_RUN
345  Q_DECL_DEPRECATED
346 #endif
347  void hasCrsTransformEnabled( bool flag );
348 
352  void hasCrsTransformEnabledChanged( bool flag );
353 
354  void destinationSrsChanged();
355 
357  void updateMap();
358 
359  void mapUnitsChanged();
360 
362  void drawError( QgsMapLayer* );
363 
366  void extentsChanged();
367 
369  void datumTransformInfoRequested( const QgsMapLayer* ml, const QString& srcAuthId, const QString& destAuthId ) const;
370 
371 
372  public slots:
373 
375  Q_DECL_DEPRECATED void onDrawingProgress( int current, int total );
376 
377  protected:
378 
380  void adjustExtentToSize();
381 
383  static bool mDrawing;
384 
387 
389  double mScale;
390 
393 
396  //
403 
405  bool mOverview;
406 
407  QSizeF mSize;
408 
411 
414 
416  QStringList mLayerSet;
417 
420 
423 
426 
429 
432 
434  QMutex mRenderMutex;
435 
438 
439  QHash< QString, QgsLayerCoordinateTransform > mLayerCoordinateTransformInfo;
440 };
441 
442 #endif
443 
Definition: qgsmaprenderer.h:175
QgsRectangle labelRect
Definition: qgsmaprenderer.h:55
const QgsMapToPixel * coordinateTransform()
Definition: qgsmaprenderer.h:195
virtual ~QgsLabelingEngineInterface()
Definition: qgsmaprenderer.h:73
QString labelText
Definition: qgsmaprenderer.h:59
A rectangle specified with double values.
Definition: qgsrectangle.h:35
Base class for all map layer types.
Definition: qgsmaplayer.h:48
QgsRenderContext * rendererContext()
Accessor for render context.
Definition: qgsmaprenderer.h:300
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)
Definition: qgsmaprenderer.h:49
bool isDiagram
Definition: qgsmaprenderer.h:62
QString srcAuthId
Definition: qgsmaprenderer.h:121
Definition: qgsmaprenderer.h:153
Definition: qgsmaprenderer.h:162
OutputUnits outputUnits() const
Definition: qgsmaprenderer.h:279
OutputUnits mOutputUnits
Output units.
Definition: qgsmaprenderer.h:428
int featureId
Definition: qgsmaprenderer.h:52
UnitType
Map units that qgis supports.
Definition: qgis.h:229
bool mProjectionsEnabled
detemines whether on the fly projection support is enabled
Definition: qgsmaprenderer.h:410
QgsRectangle mLastExtent
Last extent to we drew so we know if we can used layer render caching or not.
Definition: qgsmaprenderer.h:402
QgsScaleCalculator * mScaleCalculator
scale calculator
Definition: qgsmaprenderer.h:392
QString layerID
Definition: qgsmaprenderer.h:58
Definition: qgspallabeling.h:64
void setScale(double scale)
Sets scale for scale based visibility.
Definition: qgsmaprenderer.h:201
double height
Definition: qgsmaprenderer.h:57
static bool mDrawing
indicates drawing in progress
Definition: qgsmaprenderer.h:383
Definition: qgsmaprenderer.h:173
Definition: qgsmaprenderer.h:165
void enableOverviewMode(bool isOverview=true)
sets whether map image will be for overview
Definition: qgsmaprenderer.h:214
Definition: qgsmaprenderer.h:172
virtual int addDiagramLayer(QgsVectorLayer *layer, const QgsDiagramLayerSettings *s)
adds a diagram layer to the labeling engine
Definition: qgsmaprenderer.h:95
The feature class encapsulates a single feature including its id, geometry and a list of field/values...
Definition: qgsfeature.h:113
A non GUI class for rendering a map layer set onto a QPainter.
Definition: qgsmaprenderer.h:133
QVector< QgsPoint > cornerPoints
Definition: qgsmaprenderer.h:54
Definition: qgsmaprenderer.h:164
bool upsideDown
Definition: qgsmaprenderer.h:61
Definition: qgsmaprenderer.h:170
QgsRectangle mExtent
current extent to be drawn
Definition: qgsmaprenderer.h:395
Definition: qgsmaprenderer.h:155
int width() const
Definition: qgsmaprenderer.h:204
Definition: qgsmaprenderer.h:163
Definition: qgsmaprenderer.h:158
The QgsMapSettings class contains configuration for rendering of the map.
Definition: qgsmapsettings.h:52
QMutex mRenderMutex
Locks rendering loop for concurrent draws.
Definition: qgsmaprenderer.h:434
Perform transforms between map coordinates and device coordinates.
Definition: qgsmaptopixel.h:33
double width
Definition: qgsmaprenderer.h:56
int destDatumTransform
Definition: qgsmaprenderer.h:124
QgsCoordinateReferenceSystem * mDestCRS
destination spatial reference system of the projection
Definition: qgsmaprenderer.h:413
Definition: qgsmaprenderer.h:159
QgsDistanceArea * mDistArea
tool for measuring
Definition: qgsmaprenderer.h:422
double mapUnitsPerPixel() const
Definition: qgsmaprenderer.h:202
double scale() const
Scale denominator.
Definition: qgsmaprenderer.h:198
bool mOverview
indicates whether it's map image for overview
Definition: qgsmaprenderer.h:405
Definition: qgsmaprenderer.h:168
Definition: qgsmaprenderer.h:152
Definition: qgsmaprenderer.h:157
A class to represent a point geometry.
Definition: qgspoint.h:63
BlendMode
Blending modes enum defining the available composition modes that can be used when rendering a layer...
Definition: qgsmaprenderer.h:150
QSizeF mSize
Definition: qgsmaprenderer.h:407
Definition: qgsmaprenderer.h:161
bool isPinned
Definition: qgsmaprenderer.h:63
QgsLabelPosition()
Definition: qgsmaprenderer.h:51
Calculates scale for a given combination of canvas size, map extent, and monitor dpi.
Definition: qgsscalecalculator.h:31
double rotation
Definition: qgsmaprenderer.h:53
Definition: qgsdiagramrendererv2.h:39
General purpose distance and area calculator.
Definition: qgsdistancearea.h:34
Definition: qgsmaprenderer.h:171
int srcDatumTransform
Definition: qgsmaprenderer.h:123
Definition: qgsmaprenderer.h:142
Contains information about the context of a rendering operation.
Definition: qgsrendercontext.h:39
Definition: qgsmaprenderer.h:156
int height() const
Definition: qgsmaprenderer.h:205
QgsMapSettings mMapSettings
map settings - used only for export in mapSettings() for use in classes that deal with QgsMapSettings...
Definition: qgsmaprenderer.h:437
OutputUnits
Output units for pen width and point marker width/height.
Definition: qgsmaprenderer.h:140
QgsLabelingEngineInterface * labelingEngine()
Labeling engine (NULL if there's no custom engine)
Definition: qgsmaprenderer.h:304
Definition: qgsmaprenderer.h:169
Definition: qgsmaprenderer.h:46
double mScale
Map scale denominator at its current zoom level.
Definition: qgsmaprenderer.h:389
QHash< QString, QgsLayerCoordinateTransform > mLayerCoordinateTransformInfo
Definition: qgsmaprenderer.h:439
Class for storing a coordinate reference system (CRS)
Definition: qgscoordinatereferencesystem.h:50
QFont labelFont
Definition: qgsmaprenderer.h:60
Definition: qgsmaprenderer.h:166
Class for doing transforms between two map coordinate systems.
Definition: qgscoordinatetransform.h:52
Definition: qgsmaprenderer.h:167
Definition: qgsmaprenderer.h:119
QStringList mLayerSet
stores array of layers to be rendered (identified by string)
Definition: qgsmaprenderer.h:416
double mMapUnitsPerPixel
map units per pixel
Definition: qgsmaprenderer.h:386
Labeling engine interface.
Definition: qgsmaprenderer.h:69
QgsRenderContext mRenderContext
Encapsulates context of rendering.
Definition: qgsmaprenderer.h:425
Definition: qgsmaprenderer.h:160
QString destAuthId
Definition: qgsmaprenderer.h:122
virtual void registerDiagramFeature(const QString &layerID, QgsFeature &feat, const QgsRenderContext &context=QgsRenderContext())
called for every diagram feature
Definition: qgsmaprenderer.h:100
Represents a vector layer which manages a vector based data sets.
Definition: qgsvectorlayer.h:470
QgsLabelingEngineInterface * mLabelingEngine
Labeling engine (NULL by default)
Definition: qgsmaprenderer.h:431
double size
Definition: qgssvgcache.cpp:77
void setOutputUnits(OutputUnits u)
Definition: qgsmaprenderer.h:277
QgsRectangle mFullExtent
full extent of the layer set
Definition: qgsmaprenderer.h:419
Definition: qgsmaprenderer.h:174
Definition: qgsmaprenderer.h:154