2007-01-09 02:39:15 +00:00
|
|
|
|
|
|
|
/**
|
2008-08-05 21:11:58 +00:00
|
|
|
* \class QgsMapRenderer
|
2007-01-09 02:39:15 +00:00
|
|
|
* \brief Class for rendering map layer set
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2008-08-05 21:11:58 +00:00
|
|
|
class QgsMapRenderer : QObject
|
2007-01-09 02:39:15 +00:00
|
|
|
{
|
|
|
|
%TypeHeaderCode
|
2008-08-05 21:11:58 +00:00
|
|
|
#include <qgsmaprenderer.h>
|
2007-01-09 02:39:15 +00:00
|
|
|
%End
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
2009-04-04 22:23:50 +00:00
|
|
|
/**Output units for pen width and point marker width/height*/
|
|
|
|
enum OutputUnits
|
|
|
|
{
|
|
|
|
Millimeters,
|
|
|
|
Pixels
|
|
|
|
//MAP_UNITS probably supported in future versions
|
|
|
|
};
|
|
|
|
|
2007-01-09 02:39:15 +00:00
|
|
|
//! constructor
|
2008-08-05 21:11:58 +00:00
|
|
|
QgsMapRenderer();
|
2007-01-09 02:39:15 +00:00
|
|
|
|
|
|
|
//! destructor
|
2008-08-05 21:11:58 +00:00
|
|
|
~QgsMapRenderer();
|
2007-01-09 02:39:15 +00:00
|
|
|
|
|
|
|
//! starts rendering
|
|
|
|
void render(QPainter* painter);
|
|
|
|
|
|
|
|
//! sets extent and checks whether suitable (returns false if not)
|
2008-11-09 00:14:12 +00:00
|
|
|
bool setExtent(const QgsRectangle& extent);
|
2007-01-09 02:39:15 +00:00
|
|
|
|
|
|
|
//! returns current extent
|
2009-04-04 22:23:50 +00:00
|
|
|
QgsRectangle extent() const;
|
2007-01-09 02:39:15 +00:00
|
|
|
|
2008-08-23 09:19:49 +00:00
|
|
|
const QgsMapToPixel* coordinateTransform();
|
2007-01-09 02:39:15 +00:00
|
|
|
|
|
|
|
double scale() const;
|
2009-04-04 22:23:50 +00:00
|
|
|
/**Sets scale for scale based visibility. Normally, the scale is calculated automatically. This
|
|
|
|
function is only used to force a preview scale (e.g. for print composer)*/
|
|
|
|
void setScale( double scale );
|
2008-08-23 19:15:03 +00:00
|
|
|
double mapUnitsPerPixel() const;
|
2007-01-09 02:39:15 +00:00
|
|
|
|
2008-01-21 13:06:41 +00:00
|
|
|
int width() const;
|
|
|
|
int height() const;
|
|
|
|
|
|
|
|
|
2007-01-09 02:39:15 +00:00
|
|
|
//! Recalculate the map scale
|
|
|
|
void updateScale();
|
|
|
|
|
2009-04-04 22:23:50 +00:00
|
|
|
QgsDistanceArea* distanceArea();
|
2008-10-10 20:02:22 +00:00
|
|
|
QGis::UnitType mapUnits() const;
|
|
|
|
void setMapUnits(QGis::UnitType u);
|
2007-01-09 02:39:15 +00:00
|
|
|
|
|
|
|
//! sets whether map image will be for overview
|
2008-10-24 21:47:48 +00:00
|
|
|
void enableOverviewMode(bool isOverview = true);
|
2007-01-09 02:39:15 +00:00
|
|
|
|
|
|
|
void setOutputSize(QSize size, int dpi);
|
|
|
|
|
2008-02-11 10:39:40 +00:00
|
|
|
//!accessor for output dpi
|
|
|
|
int outputDpi();
|
|
|
|
//!accessor for output size
|
|
|
|
QSize outputSize();
|
|
|
|
|
2008-08-21 21:11:56 +00:00
|
|
|
//! transform extent in layer's CRS to extent in output CRS
|
2008-11-09 00:14:12 +00:00
|
|
|
QgsRectangle layerExtentToOutputExtent(QgsMapLayer* theLayer, QgsRectangle extent);
|
2007-01-09 02:39:15 +00:00
|
|
|
|
2008-08-21 21:11:56 +00:00
|
|
|
//! transform coordinates from layer's CRS to output CRS
|
2008-08-23 09:19:49 +00:00
|
|
|
QgsPoint layerToMapCoordinates(QgsMapLayer* theLayer, QgsPoint point);
|
2007-01-09 02:39:15 +00:00
|
|
|
|
2008-08-21 21:11:56 +00:00
|
|
|
//! transform coordinates from output CRS to layer's CRS
|
2008-08-23 09:19:49 +00:00
|
|
|
QgsPoint mapToLayerCoordinates(QgsMapLayer* theLayer, QgsPoint point);
|
2007-01-09 02:39:15 +00:00
|
|
|
|
2008-08-21 21:11:56 +00:00
|
|
|
//! transform rect's coordinates from output CRS to layer's CRS
|
2008-11-09 00:14:12 +00:00
|
|
|
QgsRectangle mapToLayerCoordinates(QgsMapLayer* theLayer, QgsRectangle rect);
|
2007-01-09 02:39:15 +00:00
|
|
|
|
|
|
|
//! sets whether to use projections for this layer set
|
|
|
|
void setProjectionsEnabled(bool enabled);
|
|
|
|
|
|
|
|
//! returns true if projections are enabled for this layer set
|
2008-10-20 20:41:06 +00:00
|
|
|
bool hasCrsTransformEnabled();
|
2007-01-09 02:39:15 +00:00
|
|
|
|
|
|
|
//! sets destination spatial reference system
|
2008-08-21 21:11:56 +00:00
|
|
|
void setDestinationSrs(const QgsCoordinateReferenceSystem& srs);
|
2007-01-09 02:39:15 +00:00
|
|
|
|
2008-08-21 21:11:56 +00:00
|
|
|
//! returns CRS ID of destination spatial reference system
|
|
|
|
const QgsCoordinateReferenceSystem& destinationSrs();
|
2007-01-09 02:39:15 +00:00
|
|
|
|
2009-04-04 22:23:50 +00:00
|
|
|
void setOutputUnits( OutputUnits u );
|
|
|
|
|
|
|
|
OutputUnits outputUnits() const;
|
|
|
|
|
2007-01-09 02:39:15 +00:00
|
|
|
//! returns current extent of layer set
|
2008-11-09 00:14:12 +00:00
|
|
|
QgsRectangle fullExtent();
|
2007-01-09 02:39:15 +00:00
|
|
|
|
|
|
|
//! returns current layer set
|
2007-03-03 10:53:53 +00:00
|
|
|
QStringList& layerSet();
|
2007-01-09 02:39:15 +00:00
|
|
|
|
|
|
|
//! change current layer set
|
2007-03-03 10:53:53 +00:00
|
|
|
void setLayerSet(const QStringList& layers);
|
2007-01-09 02:39:15 +00:00
|
|
|
|
|
|
|
//! updates extent of the layer set
|
|
|
|
void updateFullExtent();
|
|
|
|
|
|
|
|
//! read settings
|
|
|
|
bool readXML(QDomNode & theNode);
|
|
|
|
|
|
|
|
//! write settings
|
|
|
|
bool writeXML(QDomNode & theNode, QDomDocument & theDoc);
|
|
|
|
|
2009-04-04 22:23:50 +00:00
|
|
|
//! Accessor for render context
|
|
|
|
QgsRenderContext* rendererContext();
|
|
|
|
|
2007-01-09 02:39:15 +00:00
|
|
|
signals:
|
|
|
|
|
2009-04-04 22:23:50 +00:00
|
|
|
void drawingProgress(int current, int total);
|
2007-01-09 02:39:15 +00:00
|
|
|
|
2008-10-20 20:41:06 +00:00
|
|
|
void hasCrsTransformEnabled(bool flag);
|
2007-01-09 02:39:15 +00:00
|
|
|
|
|
|
|
void destinationSrsChanged();
|
|
|
|
|
|
|
|
void updateMap();
|
|
|
|
|
|
|
|
void mapUnitsChanged();
|
|
|
|
|
|
|
|
//! emitted when layer's draw() returned FALSE
|
|
|
|
void drawError(QgsMapLayer*);
|
|
|
|
|
|
|
|
public slots:
|
|
|
|
|
|
|
|
//! called by signal from layer current being drawn
|
|
|
|
void onDrawingProgress(int current, int total);
|
|
|
|
|
|
|
|
protected:
|
|
|
|
|
|
|
|
//! adjust extent to fit the pixmap size
|
|
|
|
void adjustExtentToSize();
|
|
|
|
|
|
|
|
/** Convenience function to project an extent into the layer source
|
2008-08-21 21:11:56 +00:00
|
|
|
* CRS, but also split it into two extents if it crosses
|
2007-01-09 02:39:15 +00:00
|
|
|
* the +/- 180 degree line. Modifies the given extent to be in the
|
2008-08-21 21:11:56 +00:00
|
|
|
* source CRS coordinates, and if it was split, returns true, and
|
2007-01-09 02:39:15 +00:00
|
|
|
* also sets the contents of the r2 parameter
|
|
|
|
*/
|
2008-11-09 00:14:12 +00:00
|
|
|
bool splitLayersExtent(QgsMapLayer* layer, QgsRectangle& extent, QgsRectangle& r2);
|
2007-01-09 02:39:15 +00:00
|
|
|
|
|
|
|
};
|
|
|
|
|