QGIS API Documentation  2.3.0-Master
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties 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 
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() ) = 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  {
164  BlendSubtract
165  };
166 
168  QgsMapRenderer();
169 
171  ~QgsMapRenderer();
172 
175  void render( QPainter* painter, double* forceWidthScale = 0 );
176 
178  bool setExtent( const QgsRectangle& extent );
179 
181  QgsRectangle extent() const;
182 
183  const QgsMapToPixel* coordinateTransform() { return &( mRenderContext.mapToPixel() ); }
184 
186  double scale() const { return mScale; }
189  void setScale( double scale ) {mScale = scale;}
190  double mapUnitsPerPixel() const { return mMapUnitsPerPixel; }
191 
192  int width() const { return mSize.width(); }
193  int height() const { return mSize.height(); }
194 
196  void updateScale();
197 
198  QGis::UnitType mapUnits() const;
199  void setMapUnits( QGis::UnitType u );
200 
202  void enableOverviewMode( bool isOverview = true ) { mOverview = isOverview; }
203 
204  void setOutputSize( QSize size, int dpi );
205  void setOutputSize( QSizeF size, double dpi );
206 
208  double outputDpi();
210  QSize outputSize();
211  QSizeF outputSizeF();
212 
218  QgsRectangle layerExtentToOutputExtent( QgsMapLayer* theLayer, QgsRectangle extent );
219 
225  QgsRectangle outputExtentToLayerExtent( QgsMapLayer* theLayer, QgsRectangle extent );
226 
231  QgsPoint layerToMapCoordinates( QgsMapLayer* theLayer, QgsPoint point );
232 
238  QgsRectangle layerToMapCoordinates( QgsMapLayer* theLayer, QgsRectangle rect );
239 
244  QgsPoint mapToLayerCoordinates( QgsMapLayer* theLayer, QgsPoint point );
245 
251  QgsRectangle mapToLayerCoordinates( QgsMapLayer* theLayer, QgsRectangle rect );
252 
254  void setProjectionsEnabled( bool enabled );
255 
257  bool hasCrsTransformEnabled() const;
258 
260  void setDestinationCrs( const QgsCoordinateReferenceSystem& crs, bool refreshCoordinateTransformInfo = true );
261 
263  const QgsCoordinateReferenceSystem& destinationCrs() const;
264 
265  void setOutputUnits( OutputUnits u ) {mOutputUnits = u;}
266 
267  OutputUnits outputUnits() const {return mOutputUnits;}
268 
270  QgsRectangle fullExtent();
271 
273  QStringList& layerSet();
274 
276  void setLayerSet( const QStringList& layers );
277 
279  void updateFullExtent();
280 
282  bool readXML( QDomNode & theNode );
283 
285  bool writeXML( QDomNode & theNode, QDomDocument & theDoc );
286 
288  QgsRenderContext* rendererContext() {return &mRenderContext;}
289 
292  QgsLabelingEngineInterface* labelingEngine() { return mLabelingEngine; }
293 
297  void setLabelingEngine( QgsLabelingEngineInterface* iface );
298 
301  static QPainter::CompositionMode getCompositionMode( const QgsMapRenderer::BlendMode &blendMode );
304  static QgsMapRenderer::BlendMode getBlendModeEnum( const QPainter::CompositionMode &blendMode );
305 
306  void addLayerCoordinateTransform( const QString& layerId, const QString& srcAuthId, const QString& destAuthId, int srcDatumTransform = -1, int destDatumTransform = -1 );
307  void clearLayerCoordinateTransforms();
308 
309  const QgsCoordinateTransform* transformation( const QgsMapLayer *layer ) const;
310 
313  const QgsMapSettings& mapSettings();
314 
315  signals:
316 
318  void drawingProgress( int current, int total );
319 
324 #ifndef Q_MOC_RUN
325  Q_DECL_DEPRECATED
326 #endif
327  void hasCrsTransformEnabled( bool flag );
328 
332  void hasCrsTransformEnabledChanged( bool flag );
333 
334  void destinationSrsChanged();
335 
337  void updateMap();
338 
339  void mapUnitsChanged();
340 
342  void drawError( QgsMapLayer* );
343 
346  void extentsChanged();
347 
349  void datumTransformInfoRequested( const QgsMapLayer* ml, const QString& srcAuthId, const QString& destAuthId ) const;
350 
351 
352  public slots:
353 
355  Q_DECL_DEPRECATED void onDrawingProgress( int current, int total );
356 
357  protected:
358 
360  void adjustExtentToSize();
361 
368  bool splitLayersExtent( QgsMapLayer* layer, QgsRectangle& extent, QgsRectangle& r2 );
369 
371  static bool mDrawing;
372 
375 
377  double mScale;
378 
381 
384  //
391 
393  bool mOverview;
394 
395  QSizeF mSize;
396 
399 
402 
404  QStringList mLayerSet;
405 
408 
411 
414 
417 
420 
422  QMutex mRenderMutex;
423 
426 
427  QHash< QString, QgsLayerCoordinateTransform > mLayerCoordinateTransformInfo;
428 
429 };
430 
431 #endif
432 
QgsRectangle labelRect
const QgsMapToPixel * coordinateTransform()
A rectangle specified with double values.
Definition: qgsrectangle.h:35
Base class for all map layer types.
Definition: qgsmaplayer.h:47
QgsRenderContext * rendererContext()
Accessor for render context.
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)
OutputUnits outputUnits() const
OutputUnits mOutputUnits
Output units.
bool mProjectionsEnabled
detemines whether on the fly projection support is enabled
QgsRectangle mLastExtent
Last extent to we drew so we know if we can used layer render caching or not.
QgsScaleCalculator * mScaleCalculator
scale calculator
void setScale(double scale)
Sets scale for scale based visibility.
static bool mDrawing
indicates drawing in progress
void enableOverviewMode(bool isOverview=true)
sets whether map image will be for overview
virtual int addDiagramLayer(QgsVectorLayer *layer, const QgsDiagramLayerSettings *s)
adds a diagram layer to the labeling engine
The feature class encapsulates a single feature including its id, geometry and a list of field/values...
Definition: qgsfeature.h:114
A non GUI class for rendering a map layer set onto a QPainter.
QVector< QgsPoint > cornerPoints
BlendMode
Blending modes enum defining the available composition modes that can be used when rendering a layer...
QgsRectangle mExtent
current extent to be drawn
int width() const
QMutex mRenderMutex
Locks rendering loop for concurrent draws.
Perform transforms between map coordinates and device coordinates.
Definition: qgsmaptopixel.h:33
QgsCoordinateReferenceSystem * mDestCRS
destination spatial reference system of the projection
QgsDistanceArea * mDistArea
tool for measuring
double mapUnitsPerPixel() const
double scale() const
Scale denominator.
bool mOverview
indicates whether it's map image for overview
A class to represent a point geometry.
Definition: qgspoint.h:63
OutputUnits
Output units for pen width and point marker width/height.
Calculates scale for a given combination of canvas size, map extent, and monitor dpi.
General purpose distance and area calculator.
Contains information about the context of a rendering operation.
int height() const
QgsMapSettings mMapSettings
map settings - used only for export in mapSettings() for use in classes that deal with QgsMapSettings...
QgsLabelingEngineInterface * labelingEngine()
Labeling engine (NULL if there's no custom engine)
double mScale
Map scale denominator at its current zoom level.
QHash< QString, QgsLayerCoordinateTransform > mLayerCoordinateTransformInfo
Class for storing a coordinate reference system (CRS)
Class for doing transforms between two map coordinate systems.
UnitType
Map units that qgis supports.
Definition: qgis.h:229
QStringList mLayerSet
stores array of layers to be rendered (identified by string)
double mMapUnitsPerPixel
map units per pixel
Labeling engine interface.
QgsRenderContext mRenderContext
Encapsulates context of rendering.
virtual void registerDiagramFeature(const QString &layerID, QgsFeature &feat, const QgsRenderContext &context=QgsRenderContext())
called for every diagram feature
Represents a vector layer which manages a vector based data sets.
QgsLabelingEngineInterface * mLabelingEngine
Labeling engine (NULL by default)
double size
Definition: qgssvgcache.cpp:77
void setOutputUnits(OutputUnits u)
QgsRectangle mFullExtent
full extent of the layer set