QMapControl  0.9.7.4
Public Types | Public Slots | Signals | Public Member Functions | List of all members
MapControl Class Reference

The control element of the widget and also the widget itself. More...

#include <mapcontrol.h>

Inheritance diagram for MapControl:
QWidget

Public Types

enum  MouseMode { Panning, Dragging, None }
 Declares what actions mouse movements have on the map. More...
 

Public Slots

void resize (const QSize newSize)
 Resizes the map to the given size. More...
 
void scroll (const QPoint scroll)
 scrolls the view by the given point
 
void scrollDown (int pixel=10)
 scrolls the view down
 
void scrollLeft (int pixel=10)
 scrolls the view to the left
 
void scrollRight (int pixel=10)
 scrolls the view to the right
 
void scrollUp (int pixel=10)
 scrolls the view up
 
void setZoom (int zoomlevel)
 sets the given zoomlevel More...
 
void updateRequest (QRect rect)
 updates the map for the given rect More...
 
void updateRequestNew ()
 updates the hole map by creating a new offscreen image
 
void zoomIn ()
 zooms in one step
 
void zoomOut ()
 zooms out one step
 

Signals

void boxDragged (const QRectF)
 Emitted, after a Rectangular is dragged. More...
 
void geometryClicked (Geometry *geometry, QPoint coord_px)
 This signal is emitted, when a Geometry is clicked. More...
 
void mouseEventCoordinate (const QMouseEvent *evnt, const QPointF coordinate)
 Emitted AFTER a MouseEvent occured. More...
 
void viewChanged (const QPointF &coordinate, int zoom) const
 This signal is emitted, after the view have changed. More...
 

Public Member Functions

void addLayer (Layer *layer)
 adds a layer More...
 
QPointF currentCoordinate () const
 returns the coordinate of the center of the map More...
 
int currentZoom () const
 returns the current zoom level More...
 
void enableMouseWheelEvents (bool enabled=true)
 enable mouse wheel events More...
 
void enablePersistentCache (int tileExpiry=-1, const QDir &path=QDir::homePath()+"/QMapControl.cache")
 Enable persistent caching of map tiles. More...
 
void followGeometry (const Geometry *geometry) const
 Keeps the center of the map on the Geometry, even when it moves. More...
 
QRectF getBoundingBox ()
 Get current bounding box. More...
 
QRectF getViewport ()
 Get viewport rect. More...
 
bool isBoundingBoxEnabled ()
 Check if bounding box is being used. More...
 
bool isGeometryVisible (Geometry *geometry)
 returns if a geometry is visible on viewport More...
 
Layerlayer (const QString &layername) const
 returns the layer with the given name More...
 
QList< QString > layers () const
 returns the names of all layers More...
 
int loadingQueueSize ()
 returns loading images queue size More...
 
 MapControl (QWidget *parent=0, Qt::WindowFlags windowFlags=0)
 The QWidget constructor of MapControl for use with QtDesigner. More...
 
 MapControl (QSize size, MouseMode mousemode=Panning, bool showScale=false, bool showCrosshairs=true, QWidget *parent=0, Qt::WindowFlags windowFlags=0)
 The constructor of MapControl. More...
 
MapControl::MouseMode mouseMode ()
 returns the current MouseMode More...
 
bool mouseWheelEventsEnabled ()
 returns mouse wheel allowed More...
 
void moveTo (QPointF coordinate)
 Smoothly moves the center of the view to the given Coordinate. More...
 
int numberOfLayers () const
 returns the number of existing layers More...
 
void removeLayer (Layer *layer)
 removes a layer More...
 
void setBoundingBox (QRectF &rect)
 Set constraints for bounding box. More...
 
void setMouseMode (MouseMode mousemode)
 sets the Mouse Mode of the MapControl More...
 
void setProxy (QString host, int port, const QString username=QString(), const QString password=QString())
 Sets the proxy for HTTP connections. More...
 
void setUseBoundingBox (bool usebounds)
 Set whether to enable a view bounding box. More...
 
void setView (const QPointF &coordinate) const
 sets the middle of the map to the given coordinate More...
 
void setView (const QList< QPointF > coordinates) const
 sets the view, so all coordinates are visible More...
 
void setView (const Point *point) const
 sets the view to the given Point More...
 
void setViewAndZoomIn (const QList< QPointF > coordinates) const
 sets the view and zooms in, so all coordinates are visible More...
 
void showScale (bool visible)
 Displays the scale within the widget. More...
 
void stopFollowing (const Geometry *geometry) const
 Stops the following of a Geometry. More...
 
void updateView () const
 update screen
 

Detailed Description

The control element of the widget and also the widget itself.

This is the main widget. To this control layers can be added. A MapControl has to be instantiated with a QSize which sets the size the widget takes in a layout. The given size is also the size which is assured to be filled with map images.

Author
Kai Winter kaiwi.nosp@m.nter.nosp@m.@gmx..nosp@m.de

Member Enumeration Documentation

enum MouseMode

Declares what actions mouse movements have on the map.

Enumerator
Panning 

The map is moved

Dragging 

A rectangular can be drawn

None 

Mouse move events have no efect to the map

Constructor & Destructor Documentation

MapControl ( QWidget parent = 0,
Qt::WindowFlags  windowFlags = 0 
)

The QWidget constructor of MapControl for use with QtDesigner.

Parameters
qParentQWidget parent
windowFlagsQWidget Window flags

References MapControl::Panning.

MapControl ( QSize  size,
MouseMode  mousemode = Panning,
bool  showScale = false,
bool  showCrosshairs = true,
QWidget parent = 0,
Qt::WindowFlags  windowFlags = 0 
)

The constructor of MapControl.

The MapControl is the widget which displays the maps. The size describes the area which gets filled with map data When you give no MouseMode, the mouse moves the map. You can change the MouseMode at runtime, e.g. to Dragging, which lets the user drag a rectangular box. After the dragging a signal with the size of the box is emitted. The MouseMode ´None´ can be used, to completely define the control of the map yourself.

Parameters
sizethe size which the widget should fill with map data
mousemodethe way mouse events are handled
showScaletrue if the scale should be displayed
showCrossHairstrue if crosshairs should be shown at the centre of the map
parentQWidget parent
windowFlagsQWidget Window flags

References MapControl::updateRequestNew().

Member Function Documentation

void addLayer ( Layer layer)

adds a layer

If multiple layers are added, they are painted in the added order.

Parameters
layerthe layer which should be added
void boxDragged ( const QRectF  )
signal

Emitted, after a Rectangular is dragged.

It is possible to select a rectangular area in the map, if the MouseMode is set to Dragging. The coordinates are in world coordinates

Parameters
QRectFthe dragged Rect
QPointF currentCoordinate ( ) const

returns the coordinate of the center of the map

Returns
returns the coordinate of the middle of the screen

Referenced by MapControl::resize(), MapControl::setView(), MapControl::setViewAndZoomIn(), MapControl::setZoom(), MapControl::updateView(), MapControl::zoomIn(), and MapControl::zoomOut().

int currentZoom ( ) const
void enableMouseWheelEvents ( bool  enabled = true)

enable mouse wheel events

enable mouse event

void enablePersistentCache ( int  tileExpiry = -1,
const QDir &  path = QDir::homePath() + "/QMapControl.cache" 
)

Enable persistent caching of map tiles.

Call this method to allow the QMapControl widget to save map tiles persistent (also over application restarts). Tiles are stored in the subdirectory "QMapControl.cache" within the user's home directory. This can be changed by giving a path.

Parameters
tileExpiryhow long to keep in cache before requesting a new image. 0 or -1 to disable and keep forever
paththe path to the cache directory
void followGeometry ( const Geometry geometry) const

Keeps the center of the map on the Geometry, even when it moves.

To stop the following the method stopFollowing() have to be called

Parameters
geometrythe Geometry which should stay centered.

References MapControl::stopFollowing().

void geometryClicked ( Geometry geometry,
QPoint  coord_px 
)
signal

This signal is emitted, when a Geometry is clicked.

Parameters
geometryThe clicked Geometry object
coord_pxThe coordinate in pixel coordinates
QRectF getBoundingBox ( )

Get current bounding box.

Returns
bounding box
QRectF getViewport ( )

Get viewport rect.

Returns
view port rect

Referenced by MapControl::isGeometryVisible().

bool isBoundingBoxEnabled ( )

Check if bounding box is being used.

Returns
if bounding box is being used
bool isGeometryVisible ( Geometry geometry)

returns if a geometry is visible on viewport

Parameters
geometrythe Geometry object to check
Returns
true if geometry is visible

References Geometry::boundingBox(), and MapControl::getViewport().

Layer * layer ( const QString &  layername) const

returns the layer with the given name

Parameters
layernamename of the wanted layer
Returns
the layer with the given name
QList< QString > layers ( ) const

returns the names of all layers

Returns
returns a QList with the names of all layers
int loadingQueueSize ( )

returns loading images queue size

Returns
int pending loading images (queue size)
void mouseEventCoordinate ( const QMouseEvent *  evnt,
const QPointF  coordinate 
)
signal

Emitted AFTER a MouseEvent occured.

This signals allows to receive click events within the MapWidget together with the world coordinate. It is emitted on MousePressEvents and MouseReleaseEvents. The kind of the event can be obtained by checking the events type.

Parameters
evntthe QMouseEvent that occured
coordinatethe corresponding world coordinate
MapControl::MouseMode mouseMode ( )

returns the current MouseMode

For a explanation for the MouseModes see setMouseMode()

Returns
the current MouseMode
bool mouseWheelEventsEnabled ( )

returns mouse wheel allowed

Returns
mouse wheel events enabled
void moveTo ( QPointF  coordinate)

Smoothly moves the center of the view to the given Coordinate.

Parameters
coordinatethe Coordinate which the center of the view should moved to
int numberOfLayers ( ) const

returns the number of existing layers

Returns
returns the number of existing layers
void removeLayer ( Layer layer)

removes a layer

Removes a layer and redraws existing layers

Parameters
layerthe layer which should be removed
void resize ( const QSize  newSize)
slot

Resizes the map to the given size.

Parameters
newSizeThe new size

References MapControl::currentCoordinate(), MapControl::currentZoom(), and MapControl::viewChanged().

void setBoundingBox ( QRectF &  rect)

Set constraints for bounding box.

Parameters
rectspecified bounds for view to stay within
void setMouseMode ( MouseMode  mousemode)

sets the Mouse Mode of the MapControl

There are three MouseModes declard by an enum. The MouesMode Dragging draws an rectangular in the map while the MouseButton is pressed. When the Button is released a boxDragged() signal is emitted.

The second MouseMode (the default) is Panning, which allows to drag the map around.

Parameters
mousemodethe MouseMode
void setProxy ( QString  host,
int  port,
const QString  username = QString(),
const QString  password = QString() 
)

Sets the proxy for HTTP connections.

This method sets the proxy for HTTP connections. This is not provided by the current Qtopia version!

Parameters
hostthe proxy´s hostname or ip
portthe proxy´s port
usernamethe proxy´s username
passwordthe proxy´s password
void setUseBoundingBox ( bool  usebounds)

Set whether to enable a view bounding box.

Parameters
useboundsenable/disable use of bounding box
void setView ( const QPointF &  coordinate) const

sets the middle of the map to the given coordinate

Parameters
coordinatethe coordinate which the view´s middle should be set to

References MapControl::currentCoordinate(), MapControl::currentZoom(), and MapControl::viewChanged().

void setView ( const QList< QPointF >  coordinates) const

sets the view, so all coordinates are visible

Parameters
coordinatesthe Coorinates which should be visible

References MapControl::currentCoordinate(), MapControl::currentZoom(), and MapControl::viewChanged().

void setView ( const Point point) const

sets the view to the given Point

Parameters
pointthe geometric point the view should be set to

References Point::coordinate().

void setViewAndZoomIn ( const QList< QPointF >  coordinates) const

sets the view and zooms in, so all coordinates are visible

The code of setting the view to multiple coordinates is "brute force" and pretty slow. Have to be reworked.

Parameters
coordinatesthe Coorinates which should be visible

References MapControl::currentCoordinate(), MapControl::currentZoom(), and MapControl::viewChanged().

void setZoom ( int  zoomlevel)
slot

sets the given zoomlevel

Parameters
zoomlevelthe zoomlevel

References MapControl::currentCoordinate(), MapControl::currentZoom(), MapControl::updateView(), and MapControl::viewChanged().

void showScale ( bool  visible)

Displays the scale within the widget.

Parameters
showtrue if the scale should be displayed
void stopFollowing ( const Geometry geometry) const

Stops the following of a Geometry.

if the view is set to follow a Geometry this method stops the trace. See followGeometry().

Parameters
geometrythe Geometry which should not followed anymore

Referenced by MapControl::followGeometry().

void updateRequest ( QRect  rect)
slot

updates the map for the given rect

Parameters
rectthe area which should be repainted
void viewChanged ( const QPointF &  coordinate,
int  zoom 
) const
signal

This signal is emitted, after the view have changed.

Parameters
coordinateThe current coordinate
zoomThe current zoom

Referenced by MapControl::resize(), MapControl::setView(), MapControl::setViewAndZoomIn(), MapControl::setZoom(), MapControl::updateView(), MapControl::zoomIn(), and MapControl::zoomOut().


The documentation for this class was generated from the following files: