Marble::GeoPainter

Search for usage in LXR

Marble::GeoPainter Class Reference

#include <GeoPainter.h>

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 ()
 
QList< QPolygonF * > createFillPolygons (const QList< QPolygonF * > &outerPolygons, const QList< 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 drawEllipse (const QPoint &center, int rx, int ry)
 
void drawEllipse (const QPointF &center, qreal rx, qreal ry)
 
void drawEllipse (const QRect &rectangle)
 
void drawEllipse (const QRectF &rectangle)
 
void drawEllipse (int x, int y, int width, int height)
 
void drawImage (const GeoDataCoordinates &centerPosition, const QImage &image)
 
void drawImage (const QPoint &point, const QImage &image)
 
void drawImage (const QPoint &point, const QImage &image, const QRect &source, Qt::ImageConversionFlags flags)
 
void drawImage (const QPointF &point, const QImage &image)
 
void drawImage (const QPointF &point, const QImage &image, const QRectF &source, Qt::ImageConversionFlags flags)
 
void drawImage (const QRect &rectangle, const QImage &image)
 
void drawImage (const QRect &target, const QImage &image, const QRect &source, Qt::ImageConversionFlags flags)
 
void drawImage (const QRectF &rectangle, const QImage &image)
 
void drawImage (const QRectF &target, const QImage &image, const QRectF &source, Qt::ImageConversionFlags flags)
 
void drawImage (int x, int y, const QImage &image, int sx, int sy, int sw, int sh, Qt::ImageConversionFlags flags)
 
void drawLabelsForPolygons (const QList< QPolygonF * > &polygons, const QString &labelText, LabelPositionFlags labelPositionFlags, const QColor &labelColor)
 
void drawPixmap (const GeoDataCoordinates &centerPosition, const QPixmap &pixmap)
 
void drawPixmap (const QPoint &point, const QPixmap &pixmap)
 
void drawPixmap (const QPoint &point, const QPixmap &pixmap, const QRect &source)
 
void drawPixmap (const QPointF &point, const QPixmap &pixmap)
 
void drawPixmap (const QPointF &point, const QPixmap &pixmap, const QRectF &source)
 
void drawPixmap (const QRect &rectangle, const QPixmap &pixmap)
 
void drawPixmap (const QRect &target, const QPixmap &pixmap, const QRect &source)
 
void drawPixmap (const QRectF &target, const QPixmap &pixmap, const QRectF &source)
 
void drawPixmap (int x, int y, const QPixmap &pixmap)
 
void drawPixmap (int x, int y, const QPixmap &pixmap, int sx, int sy, int sw, int sh)
 
void drawPixmap (int x, int y, int w, int h, const QPixmap &pixmap, int sx, int sy, int sw, int sh)
 
void drawPixmap (int x, int y, int width, int height, const QPixmap &pixmap)
 
void drawPoint (const GeoDataCoordinates &position)
 
void drawPoint (const GeoDataPoint &point)
 
void drawPoint (const QPoint &position)
 
void drawPoint (const QPointF &position)
 
void drawPoint (int x, int y)
 
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)
 
void drawPolyline (const GeoDataLineString &lineString, const QString &labelText, LabelPositionFlags labelPositionFlags=LineCenter, const QColor &labelcolor=Qt::black)
 
void drawRect (const GeoDataCoordinates &centerPosition, qreal width, qreal height, bool isGeoProjected=false)
 
void drawRect (const QRect &rectangle)
 
void drawRect (const QRectF &rectangle)
 
void drawRect (int x, int y, int width, int height)
 
void drawRoundedRect (const GeoDataCoordinates &centerPosition, qreal width, qreal height, qreal xRnd=25.0, qreal yRnd=25.0)
 
void drawRoundedRect (const QRect &rect, qreal xRadius, qreal yRadius, Qt::SizeMode mode)
 
void drawRoundedRect (const QRectF &rect, qreal xRadius, qreal yRadius, Qt::SizeMode mode)
 
void drawRoundedRect (int x, int y, int w, int h, qreal xRadius, qreal yRadius, Qt::SizeMode mode)
 
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 drawText (const QPoint &position, const QString &text)
 
void drawText (const QPointF &position, const QString &text)
 
void drawText (const QRect &rectangle, int flags, const QString &text, QRect *boundingRect)
 
void drawText (const QRectF &rectangle, const QString &text, const QTextOption &option)
 
void drawText (const QRectF &rectangle, int flags, const QString &text, QRectF *boundingRect)
 
void drawText (int x, int y, const QString &text)
 
void drawText (int x, int y, int width, int height, int flags, const QString &text, QRect *boundingRect)
 
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, QList< 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 85 of file GeoPainter.h.

Member Typedef Documentation

◆ Frames

Definition at line 93 of file GeoPainter.h.

Member Enumeration Documentation

◆ Frame

enum Marble::GeoPainter::Frame

Definition at line 88 of file GeoPainter.h.

Constructor & Destructor Documentation

◆ GeoPainter()

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 192 of file GeoPainter.cpp.

◆ ~GeoPainter()

GeoPainter::~GeoPainter ( )

Destroys the geo painter.

Definition at line 201 of file GeoPainter.cpp.

Member Function Documentation

◆ createFillPolygons()

QList< QPolygonF * > GeoPainter::createFillPolygons ( const QList< QPolygonF * > & outerPolygons,
const QList< QPolygonF * > & innerPolygons ) const

Definition at line 849 of file GeoPainter.cpp.

◆ drawAnnotation()

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 211 of file GeoPainter.cpp.

◆ drawEllipse()

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 310 of file GeoPainter.cpp.

◆ drawImage()

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 449 of file GeoPainter.cpp.

◆ drawLabelsForPolygons()

void GeoPainter::drawLabelsForPolygons ( const QList< 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 556 of file GeoPainter.cpp.

◆ drawPixmap()

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 473 of file GeoPainter.cpp.

◆ drawPoint() [1/2]

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 243 of file GeoPainter.cpp.

◆ drawPoint() [2/2]

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 264 of file GeoPainter.cpp.

◆ drawPolygon() [1/2]

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 721 of file GeoPainter.cpp.

◆ drawPolygon() [2/2]

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 778 of file GeoPainter.cpp.

◆ drawPolyline() [1/2]

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 679 of file GeoPainter.cpp.

◆ drawPolyline() [2/2]

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 532 of file GeoPainter.cpp.

◆ drawRect()

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 871 of file GeoPainter.cpp.

◆ drawRoundedRect()

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 926 of file GeoPainter.cpp.

◆ drawText()

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 274 of file GeoPainter.cpp.

◆ drawTextFragment()

void GeoPainter::drawTextFragment ( const QPoint & position,
const QString & text,
const qreal fontSize,
const QColor & color = Qt::black,
const Frames & flags = Frames() )

Definition at line 945 of file GeoPainter.cpp.

◆ mapQuality()

MapQuality GeoPainter::mapQuality ( ) const

Returns the map quality.

Returns
The map quality that got assigned to the painter.

Definition at line 206 of file GeoPainter.cpp.

◆ polygonsFromLineString()

void GeoPainter::polygonsFromLineString ( const GeoDataLineString & lineString,
QList< 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 519 of file GeoPainter.cpp.

◆ regionFromEllipse()

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 374 of file GeoPainter.cpp.

◆ regionFromPixmapRect()

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 494 of file GeoPainter.cpp.

◆ regionFromPoint() [1/2]

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 259 of file GeoPainter.cpp.

◆ regionFromPoint() [2/2]

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 269 of file GeoPainter.cpp.

◆ regionFromPolygon()

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 741 of file GeoPainter.cpp.

◆ regionFromPolyline()

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 693 of file GeoPainter.cpp.

◆ regionFromRect()

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 893 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-2024 The KDE developers.
Generated on Mon Nov 4 2024 16:37:04 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.