Marble::GeoPainter

Search for usage in LXR

Marble::GeoPainter Class Reference

#include <GeoPainter.h>

Inherits Marble::ClipPainter.

Public Types

enum  Frame { NoOptions = 0x0, RoundFrame = 0x1 }
 
typedef QFlags< Frame > Frames
 

Public Member Functions

 GeoPainter (QPaintDevice *paintDevice, const ViewportParams *viewportParams, MapQuality mapQuality=NormalQuality)
 
 ~GeoPainter ()
 
QVector< QPolygonF * > createFillPolygons (const QVector< QPolygonF * > &outerPolygons, const QVector< QPolygonF * > &innerPolygons) const
 
void drawAnnotation (const GeoDataCoordinates &position, const QString &text, QSizeF bubbleSize=QSizeF(130, 100), qreal bubbleOffsetX=-10, qreal bubbleOffsetY=-30, qreal xRnd=5, qreal yRnd=5)
 
void drawEllipse (const GeoDataCoordinates &centerPosition, qreal width, qreal height, bool isGeoProjected=false)
 
void drawImage (const GeoDataCoordinates &centerPosition, const QImage &image)
 
void drawLabelsForPolygons (const QVector< QPolygonF * > &polygons, const QString &labelText, LabelPositionFlags labelPositionFlags, const QColor &labelColor)
 
void drawPixmap (const GeoDataCoordinates &centerPosition, const QPixmap &pixmap)
 
void drawPoint (const GeoDataCoordinates &position)
 
void drawPoint (const GeoDataPoint &point)
 
void drawPolygon (const GeoDataLinearRing &linearRing, Qt::FillRule fillRule=Qt::OddEvenFill)
 
void drawPolygon (const GeoDataPolygon &polygon, Qt::FillRule fillRule=Qt::OddEvenFill)
 
void drawPolyline (const GeoDataLineString &lineString, const QString &labelText, LabelPositionFlags labelPositionFlags=LineCenter, const QColor &labelcolor=Qt::black)
 
void drawPolyline (const GeoDataLineString &lineString)
 
void drawRect (const GeoDataCoordinates &centerPosition, qreal width, qreal height, bool isGeoProjected=false)
 
void drawRoundedRect (const GeoDataCoordinates &centerPosition, qreal width, qreal height, qreal xRnd=25.0, qreal yRnd=25.0)
 
void drawText (const GeoDataCoordinates &position, const QString &text, qreal xOffset=0.0, qreal yOffset=0.0, qreal width=0.0, qreal height=0.0, const QTextOption &option=QTextOption())
 
void drawTextFragment (const QPoint &position, const QString &text, const qreal fontSize, const QColor &color=Qt::black, const Frames &flags=Frames())
 
MapQuality mapQuality () const
 
void polygonsFromLineString (const GeoDataLineString &lineString, QVector< QPolygonF * > &polygons) const
 
QRegion regionFromEllipse (const GeoDataCoordinates &centerPosition, qreal width, qreal height, bool isGeoProjected=false, qreal strokeWidth=3) const
 
QRegion regionFromPixmapRect (const GeoDataCoordinates &centerCoordinates, int width, int height, int margin=0) const
 
QRegion regionFromPoint (const GeoDataCoordinates &position, qreal strokeWidth=3) const
 
QRegion regionFromPoint (const GeoDataPoint &point, qreal strokeWidth=3) const
 
QRegion regionFromPolygon (const GeoDataLinearRing &linearRing, Qt::FillRule fillRule, qreal strokeWidth=3) const
 
QRegion regionFromPolyline (const GeoDataLineString &lineString, qreal strokeWidth=3) const
 
QRegion regionFromRect (const GeoDataCoordinates &centerPosition, qreal width, qreal height, bool isGeoProjected=false, qreal strokeWidth=3) const
 

Detailed Description

A painter that allows to draw geometric primitives on the map.

This class allows application developers to draw simple geometric shapes and objects onto the map.

The API is modeled after the QPainter API.

The GeoPainter provides a wide range of methods that are using geographic ("geodesic") coordinates to position the item. For example a point or the nodes of a polygon can fully be described in geographic coordinates.

In all these cases the position of the object is specified in geographic coordinates.

There are however some cases where there are two viable cases:

  • the shape of the object could still use screen coordinates (like a label or an icon).
  • Alternatively the shape of the object can get projected according to the current projection (e.g. a texture projected onto the spherical surface)

If screen coordinates are used then e.g. width and height are assumed to be expressed in pixels, otherwise degrees are used.

Painter transformations (e.g. translate) always happen in screen coordinates.

Like in QPainter drawing objects onto a widget should always considered to be a volatile operation. This means that e.g. placemarks don't get added to the globe permanently. So the drawing needs to be done on every repaint to prevent that drawings will disappear during the next paint event.

So if you want to add placemarks to your map widget permanently (i.e. you don't want to take care of repainting) then you need to use other solutions such as the KML import of the Marble framework or Marble's GeoGraphicsItems.

Note
By default the GeoPainter automatically filters geographical content in order to provide fast painting:
  • Geographically positioned objects which are outside the viewport are not drawn at all. Parts of objects which are specified through geographic coordinates (like polygons, ellipses etc.) get cut off if they are not placed within the viewport.
  • Objects which have a shape that is specified through geographic coordinates get filtered according to the viewport resolution: If the object is much smaller than a pixel then it won't get drawn at all.

Definition at line 88 of file GeoPainter.h.

Constructor & Destructor Documentation

GeoPainter::GeoPainter ( QPaintDevice paintDevice,
const ViewportParams viewportParams,
MapQuality  mapQuality = NormalQuality 
)

Creates a new geo painter.

To create a geo painter it's necessary to provide paintDevice as a canvas and the viewportParams to specify the map projection inside the viewport.

Definition at line 195 of file GeoPainter.cpp.

GeoPainter::~GeoPainter ( )

Destroys the geo painter.

Definition at line 205 of file GeoPainter.cpp.

Member Function Documentation

void GeoPainter::drawAnnotation ( const GeoDataCoordinates position,
const QString text,
QSizeF  bubbleSize = QSizeF( 130, 100 ),
qreal  bubbleOffsetX = -10,
qreal  bubbleOffsetY = -30,
qreal  xRnd = 5,
qreal  yRnd = 5 
)

Draws a text annotation that points to a geodesic position.

The annotation consists of a bubble with the specified text inside. By choosing an appropriate pen for the painter it's possible to change the color and line style of the bubble outline and the text. The brush chosen for the painter is used to paint the background of the bubble

The optional parameters which describe the layout of the bubble are similar to those used by QPainter::drawRoundedRect(). Unlike in QPainter the rounded corners are not specified in percentage but in pixels to provide for optimal aesthetics. By choosing a positive or negative bubbleOffset it's possible to place the annotation on top, bottom, left or right of the annotated position.

Parameters
positionThe geodesic position
textThe text contained by the bubble
bubbleSizeThe size of the bubble that holds the annotation text. A height of 0 can be used to have the height calculated automatically to fit the needed text height.
bubbleOffsetXThe x-axis offset between the annotated position and the "root" of the speech bubble's "arrow".
bubbleOffsetYThe y-axis offset between the annotated position and the "root" of the speech bubble's "arrow".
xRndSpecifies the geometry of the rounded corners in pixels along the x-axis.
yRndSpecifies the geometry of the rounded corners in pixels along the y-axis.
See also
GeoDataCoordinates

Definition at line 217 of file GeoPainter.cpp.

void GeoPainter::drawEllipse ( const GeoDataCoordinates centerPosition,
qreal  width,
qreal  height,
bool  isGeoProjected = false 
)

Draws an ellipse at the given position. The ellipse is placed with its center located at the given centerPosition.

For the outline it uses the painter's pen and for the background the painter's brush.

If isGeoProjected is true then the outline of the ellipse is drawn in geographic coordinates. In this case the width and the height are interpreted to be degrees. If isGeoProjected is false then the outline of the ellipse is drawn in screen coordinates. In this case the width and the height are interpreted to be pixels.

See also
GeoDataCoordinates

Definition at line 320 of file GeoPainter.cpp.

void GeoPainter::drawImage ( const GeoDataCoordinates centerPosition,
const QImage image 
)

Draws an image at the given position. The image is placed with its center located at the given centerPosition.

The image rendering is performed in screen coordinates and is not subject to the current projection.

See also
GeoDataCoordinates

Definition at line 466 of file GeoPainter.cpp.

void GeoPainter::drawLabelsForPolygons ( const QVector< QPolygonF * > &  polygons,
const QString labelText,
LabelPositionFlags  labelPositionFlags,
const QColor labelColor 
)

Draws Labels for a given set of screen polygons.

In common cases the drawPolyline overload can be used instead. However in certain more complex cases this particular method might be helpful for further optimization.

Definition at line 592 of file GeoPainter.cpp.

void GeoPainter::drawPixmap ( const GeoDataCoordinates centerPosition,
const QPixmap pixmap 
)

Draws a pixmap at the given position. The pixmap is placed with its center located at the given centerPosition.

The image rendering is performed in screen coordinates and is not subject to the current projection.

See also
GeoDataCoordinates

Definition at line 492 of file GeoPainter.cpp.

void GeoPainter::drawPoint ( const GeoDataCoordinates position)

Draws a single point at a given geographic position. The point is drawn using the painter's pen color.

See also
GeoDataCoordinates

Definition at line 247 of file GeoPainter.cpp.

void GeoPainter::drawPoint ( const GeoDataPoint point)

Draws a single point at a given geographic position. The point is drawn using the painter's pen color.

See also
GeoDataPoint

Definition at line 271 of file GeoPainter.cpp.

void GeoPainter::drawPolygon ( const GeoDataLinearRing linearRing,
Qt::FillRule  fillRule = Qt::OddEvenFill 
)

Draws a given linear ring (a "polygon without holes").

The outline of the linearRing is drawn using the current pen. The background is painted using the current brush of the painter. Like in QPainter::drawPolygon() the fillRule specifies the fill algorithm that is used to fill the polygon.

See also
GeoDataLinearRing

Definition at line 759 of file GeoPainter.cpp.

void GeoPainter::drawPolygon ( const GeoDataPolygon polygon,
Qt::FillRule  fillRule = Qt::OddEvenFill 
)

Draws a given polygon (which may contain holes).

The outline of the polygon is drawn using the current pen. The background is painted using the current brush of the painter. Like in QPainter::drawPolygon() the fillRule specifies the fill algorithm that is used to fill the polygon.

See also
GeoDataPolygon

Definition at line 827 of file GeoPainter.cpp.

void GeoPainter::drawPolyline ( const GeoDataLineString lineString,
const QString labelText,
LabelPositionFlags  labelPositionFlags = LineCenter,
const QColor labelcolor = Qt::black 
)

Draws a given line string (a "polyline") with a label.

The lineString is drawn using the current pen. It's possible to provide a labelText for the lineString. The text is rendered using the painter's font property. The position of the labelText can be specified using the labelPositionFlags.

See also
GeoDataLineString

Definition at line 562 of file GeoPainter.cpp.

void GeoPainter::drawPolyline ( const GeoDataLineString lineString)

Draws a given line string (a "polyline").

The lineString is drawn using the current pen.

See also
GeoDataLineString

Definition at line 712 of file GeoPainter.cpp.

void GeoPainter::drawRect ( const GeoDataCoordinates centerPosition,
qreal  width,
qreal  height,
bool  isGeoProjected = false 
)

Draws a rectangle at the given position. The rectangle is placed with its center located at the given centerPosition.

For the outline it uses the painter's pen and for the background the painter's brush.

If isGeoProjected is true then the outline of the rectangle is drawn in geographic coordinates. In this case the width and the height are interpreted to be degrees. If isGeoProjected is false then the outline of the rectangle is drawn in screen coordinates. In this case the width and the height are interpreted to be pixels.

See also
GeoDataCoordinates

Definition at line 927 of file GeoPainter.cpp.

void GeoPainter::drawRoundedRect ( const GeoDataCoordinates centerPosition,
qreal  width,
qreal  height,
qreal  xRnd = 25.0,
qreal  yRnd = 25.0 
)

Draws a rectangle with rounded corners at the given position. The rectangle is placed with its center located at the given centerPosition.

For the outline it uses the painter's pen and for the background the painter's brush. Unlike in QPainter::drawRoundedRect() the rounded corners are not specified in percentage but in pixels to provide for optimal aesthetics.

Parameters
centerPositionPosition of rectangle center
widthWidth of the rectangle in pixels
heightHeight of the rectangle in pixels
xRndSpecifies the geometry of the rounded corners in pixels along the x-axis.
yRndSpecifies the geometry of the rounded corners in pixels along the y-axis.
See also
GeoDataCoordinates

Definition at line 995 of file GeoPainter.cpp.

void GeoPainter::drawText ( const GeoDataCoordinates position,
const QString text,
qreal  xOffset = 0.0,
qreal  yOffset = 0.0,
qreal  width = 0.0,
qreal  height = 0.0,
const QTextOption option = QTextOption() 
)

Draws the given text at a given geographic position. The text is drawn starting at the given position using the painter's font property. The text rendering is performed in screen coordinates and is not subject to the current projection. An offset given in screenPixels can be provided via xOffset and yOffset in order to tweak the text position. By optionally adding a width, height and text options the text flow can be further influenced.

Definition at line 284 of file GeoPainter.cpp.

MapQuality GeoPainter::mapQuality ( ) const

Returns the map quality.

Returns
The map quality that got assigned to the painter.

Definition at line 211 of file GeoPainter.cpp.

void GeoPainter::polygonsFromLineString ( const GeoDataLineString lineString,
QVector< QPolygonF * > &  polygons 
) const

Helper method for safe and quick linestring conversion.

In general drawPolyline() should be used instead. However in situations where the same linestring is supposed to be drawn multiple times it's a good idea to cache the screen polygons using this method.

See also
GeoDataLineString

Definition at line 544 of file GeoPainter.cpp.

QRegion GeoPainter::regionFromEllipse ( const GeoDataCoordinates centerPosition,
qreal  width,
qreal  height,
bool  isGeoProjected = false,
qreal  strokeWidth = 3 
) const

Creates a region for an ellipse at a given position.

A QRegion object is created that represents the area covered by GeoPainter::drawEllipse(). As such it can be used e.g. for input event handling for objects that have been painted using GeoPainter::drawEllipse().

The strokeWidth allows to extrude the QRegion by half the amount of "stroke width" pixels. For input event handling it's always advisable to use a width that is slightly bigger than the width of the painter's pen.

See also
GeoDataCoordinates

Definition at line 388 of file GeoPainter.cpp.

QRegion GeoPainter::regionFromPixmapRect ( const GeoDataCoordinates centerCoordinates,
int  width,
int  height,
int  margin = 0 
) const

Creates a region for a rectangle for a pixmap at a given position.

A QRegion object is created that represents the area covered by GeoPainter::drawPixmap(). This can be used e.g. for input event handling for objects that have been painted using GeoPainter::drawPixmap().

The margin allows to extrude the QRegion by "margin" pixels on every side.

See also
GeoDataCoordinates

Definition at line 515 of file GeoPainter.cpp.

QRegion GeoPainter::regionFromPoint ( const GeoDataCoordinates position,
qreal  strokeWidth = 3 
) const

Creates a region for a given geographic position.

A QRegion object is created that represents the area covered by GeoPainter::drawPoint( GeoDataCoordinates ). It can be used e.g. for input event handling of objects that have been painted using GeoPainter::drawPoint( GeoDataCoordinates ).

The width allows to set the "stroke width" for the region. For input event handling it's always advisable to use a width that is slightly bigger than the width of the painter's pen.

See also
GeoDataCoordinates

Definition at line 264 of file GeoPainter.cpp.

QRegion GeoPainter::regionFromPoint ( const GeoDataPoint point,
qreal  strokeWidth = 3 
) const

Create a region for a given geographic position.

A QRegion object is created that represents the area covered by GeoPainter::drawPoint( GeoDataPoint ). It can be used e.g. for input event handling of objects that have been painted using GeoPainter::drawPoint( GeoDataPoint ).

The width allows to set the "stroke width" for the region. For input event handling it's always advisable to use a width that is slightly bigger than the width of the painter's pen.

Definition at line 277 of file GeoPainter.cpp.

QRegion GeoPainter::regionFromPolygon ( const GeoDataLinearRing linearRing,
Qt::FillRule  fillRule,
qreal  strokeWidth = 3 
) const

Creates a region for a given linear ring (a "polygon without holes").

A QRegion object is created that represents the area covered by GeoPainter::drawPolygon( GeoDataLinearRing ). As such it can be used e.g. for input event handling for objects that have been painted using GeoPainter::drawPolygon( GeoDataLinearRing ).

Like in drawPolygon() the fillRule specifies the fill algorithm that is used to fill the polygon.

The strokeWidth allows to extrude the QRegion by half the amount of "stroke width" pixels. For input event handling it's always advisable to use a width that is slightly bigger than the width of the painter's pen.

For the polygon case a "cosmetic" strokeWidth of zero should provide the best performance.

See also
GeoDataLinearRing

Definition at line 784 of file GeoPainter.cpp.

QRegion GeoPainter::regionFromPolyline ( const GeoDataLineString lineString,
qreal  strokeWidth = 3 
) const

Creates a region for a given line string (a "polyline").

A QRegion object is created that represents the area covered by GeoPainter::drawPolyline( GeoDataLineString ). As such it can be used e.g. for input event handling for objects that have been painted using GeoPainter::drawPolyline( GeoDataLineString ).

The strokeWidth allows to extrude the QRegion by half the amount of "stroke width" pixels. For input event handling it's always advisable to use a width that is slightly bigger than the width of the painter's pen.

See also
GeoDataLineString

Definition at line 726 of file GeoPainter.cpp.

QRegion GeoPainter::regionFromRect ( const GeoDataCoordinates centerPosition,
qreal  width,
qreal  height,
bool  isGeoProjected = false,
qreal  strokeWidth = 3 
) const

Creates a region for a rectangle at a given position.

A QRegion object is created that represents the area covered by GeoPainter::drawRect(). This can be used e.g. for input event handling for objects that have been painted using GeoPainter::drawRect().

The isGeoProjected parameter is used the same way as for GeoPainter::drawRect().

The strokeWidth allows to extrude the QRegion by half the amount of "stroke width" pixels. For input event handling it's always advisable to use a width that is slightly bigger than the width of the painter's pen. This is especially true for small objects.

See also
GeoDataCoordinates

Definition at line 955 of file GeoPainter.cpp.


The documentation for this class was generated from the following files:
This file is part of the KDE documentation.
Documentation copyright © 1996-2021 The KDE developers.
Generated on Tue Oct 26 2021 23:21:27 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.