Mapper  0.9.0
API documentation
Classes | Public Types | Signals | Public Member Functions | Static Public Attributes | Protected Member Functions | List of all members
OpenOrienteering::MapView Class Reference

Stores view position, zoom, rotation and grid / template visibilities to define a view onto a map. More...

#include <map_view.h>

Inheritance diagram for OpenOrienteering::MapView:
Inheritance graph
[legend]
Collaboration diagram for OpenOrienteering::MapView:
Collaboration graph
[legend]

Public Types

enum  ChangeFlag { NoChange = 0, CenterChange = 1, ZoomChange = 2, RotationChange = 4 }
 
enum  VisibilityFeature {
  MultipleFeatures = 0, GridVisible = 1, OverprintingEnabled = 2, AllTemplatesHidden = 4,
  TemplateVisible = 8, MapVisible = 16
}
 

Signals

void viewChanged (OpenOrienteering::MapView::ChangeFlags change)
 Indicates a change of the viewed area of the map. More...
 
void panOffsetChanged (const QPoint &offset)
 Indicates a change of the pan offset. More...
 
void visibilityChanged (OpenOrienteering::MapView::VisibilityFeature feature, bool active, const OpenOrienteering::Template *temp=nullptr)
 Indicates a particular change of visibility. More...
 

Public Member Functions

 MapView (QObject *parent, Map *map)
 Creates a default view looking at the origin. More...
 
 MapView (Map *map)
 Creates a default view looking at the origin. More...
 
 ~MapView () override
 Destroys the map view. More...
 
void save (QXmlStreamWriter &xml, const QLatin1String &element_name, bool template_details=true) const
 Saves the map view state to an XML stream. More...
 
void load (QXmlStreamReader &xml)
 Loads the map view state from the current element of an xml stream. More...
 
void updateAllMapWidgets ()
 Redraws all map widgets completely. More...
 
MapCoord viewToMap (const QPointF &point) const
 Converts the point (with origin at the center of the view) to map coordinates. More...
 
MapCoordF viewToMapF (const QPointF &point) const
 Converts the point (with origin at the center of the view) to map coordinates. More...
 
QPointF mapToView (const MapCoord &coords) const
 Converts map coordinates to view coordinates (with origin at the center of the view) More...
 
QPointF mapToView (const QPointF &coords) const
 Converts map coordinates to view coordinates (with origin at the center of the view) More...
 
qreal lengthToPixel (qreal length) const
 Converts a length from native map coordinates to the current length in view pixels. More...
 
qreal pixelToLength (qreal pixel) const
 Converts a length from current view pixels to native map coordinates. More...
 
QRectF calculateViewedRect (QRectF view_rect) const
 Calculates the bounding box of the map coordinates which can be viewed using the given view coordinates rect. More...
 
QRectF calculateViewBoundingBox (QRectF map_rect) const
 Calculates the bounding box in view coordinates of the given map coordinates rect. More...
 
const QTransformworldTransform () const
 Returns a QTransform suitable for QPainter, so objects defined in map coordinates will be drawn at their view coordinates. More...
 
QPoint panOffset () const
 Returns the current pan offset (when dragging the map). More...
 
void setPanOffset (const QPoint &offset)
 Sets the current pan offset while the map is being dragged. More...
 
void finishPanning (const QPoint &offset)
 Finishes panning the map. More...
 
const MapgetMap () const
 Returns the map this view is defined on. More...
 
MapgetMap ()
 Returns the map this view is defined on. More...
 
void zoomSteps (double num_steps, const QPointF &cursor_pos_view)
 Zooms the maps (in steps), preserving the given cursor position. More...
 
void zoomSteps (double num_steps)
 Zooms the maps (in steps), preserving the center of the view. More...
 
double calculateFinalZoomFactor () const
 Returns the final zoom factor for use in transformations. More...
 
double getZoom () const
 Returns the raw zoom facor, see also calculateFinalZoomFactor(). More...
 
void setZoom (double value, const QPointF &center)
 Sets the zoom factor relative to the given point. More...
 
void setZoom (double value)
 Sets the zoom factor. More...
 
double getRotation () const
 Returns the view rotation (in radians). More...
 
void setRotation (double value)
 Sets the view rotation (in radians). More...
 
MapCoord center () const
 Returns the position of the view center. More...
 
void setCenter (const MapCoord &pos)
 Sets the position of the view center. More...
 
TemplateVisibility effectiveMapVisibility () const
 Returns the effectiv visibility settings of the map drawing. More...
 
TemplateVisibility getMapVisibility () const
 Returns the visibility settings of the map drawing. More...
 
void setMapVisibility (TemplateVisibility vis)
 
bool isTemplateVisible (const Template *temp) const
 Checks if the template is visible without creating a template visibility object if none exists. More...
 
TemplateVisibility getTemplateVisibility (const Template *temp) const
 Returns the template visibility. More...
 
void setTemplateVisibility (Template *temp, TemplateVisibility vis)
 Sets the template visibility, and emits a change signal. More...
 
void setAllTemplatesHidden (bool value)
 Enables or disables hiding all templates in this view. More...
 
bool areAllTemplatesHidden () const
 Returns if the "hide all templates" toggle is active. More...
 
bool isGridVisible () const
 Returns if the map grid is visible. More...
 
void setGridVisible (bool visible)
 Sets the map grid visibility. More...
 
bool isOverprintingSimulationEnabled () const
 Returns if overprinting simulation is enabled. More...
 
void setOverprintingSimulationEnabled (bool enabled)
 Enables or disables overprinting simulation. More...
 
bool hasAlpha () const
 Returns true if any of the visible elements is not opaque. More...
 
void setTemplateLoadingBlocked (bool blocked)
 Temporarily blocks automatic template loading on visibility changes. More...
 
bool templateLoadingBlocked () const
 Returns true when template loading on visibility changes is disabled. More...
 
- Public Member Functions inherited from QObject
virtual const QMetaObjectmetaObject () const const
 
 QObject (QObject *parent)
 
virtual ~QObject ()
 
virtual bool event (QEvent *e)
 
virtual bool eventFilter (QObject *watched, QEvent *event)
 
QString objectName () const const
 
void setObjectName (const QString &name)
 
bool isWidgetType () const const
 
bool isWindowType () const const
 
bool signalsBlocked () const const
 
bool blockSignals (bool block)
 
QThreadthread () const const
 
void moveToThread (QThread *targetThread)
 
int startTimer (int interval, Qt::TimerType timerType)
 
int startTimer (std::chrono::milliseconds time, Qt::TimerType timerType)
 
void killTimer (int id)
 
findChild (const QString &name, Qt::FindChildOptions options) const const
 
QList< T > findChildren (const QString &name, Qt::FindChildOptions options) const const
 
QList< T > findChildren (const QRegExp &regExp, Qt::FindChildOptions options) const const
 
QList< T > findChildren (const QRegularExpression &re, Qt::FindChildOptions options) const const
 
const QObjectListchildren () const const
 
void setParent (QObject *parent)
 
void installEventFilter (QObject *filterObj)
 
void removeEventFilter (QObject *obj)
 
QMetaObject::Connection connect (const QObject *sender, const char *signal, const char *method, Qt::ConnectionType type) const const
 
bool disconnect (const char *signal, const QObject *receiver, const char *method) const const
 
bool disconnect (const QObject *receiver, const char *method) const const
 
void dumpObjectTree ()
 
void dumpObjectInfo ()
 
void dumpObjectTree () const const
 
void dumpObjectInfo () const const
 
bool setProperty (const char *name, const QVariant &value)
 
QVariant property (const char *name) const const
 
QList< QByteArraydynamicPropertyNames () const const
 
void destroyed (QObject *obj)
 
void objectNameChanged (const QString &objectName)
 
QObjectparent () const const
 
bool inherits (const char *className) const const
 
void deleteLater ()
 
 Q_DISABLE_COPY (Class)
 
 Q_DISABLE_MOVE (Class)
 
 Q_DISABLE_COPY_MOVE (Class)
 
qobject_cast (QObject *object)
 
qobject_cast (const QObject *object)
 
qFindChild (const QObject *obj, const QString &name)
 
QList< T > qFindChildren (const QObject *obj, const QString &name)
 
QList< T > qFindChildren (const QObject *obj, const QRegExp &regExp)
 
 Q_CLASSINFO (Name, Value)
 
 Q_INTERFACES (...)
 
 Q_PROPERTY (...)
 
 Q_ENUMS (...)
 
 Q_FLAGS (...)
 
 Q_ENUM (...)
 
 Q_FLAG (...)
 
 Q_ENUM_NS (...)
 
 Q_FLAG_NS (...)
 
 Q_OBJECT Q_OBJECT
 
 Q_GADGET Q_GADGET
 
 Q_NAMESPACE Q_NAMESPACE
 
 Q_SIGNALS Q_SIGNALS
 
 Q_SIGNAL Q_SIGNAL
 
 Q_SLOTS Q_SLOTS
 
 Q_SLOT Q_SLOT
 
 Q_EMIT Q_EMIT
 
 Q_INVOKABLE Q_INVOKABLE
 
 Q_REVISION Q_REVISION
 
 Q_SET_OBJECT_NAME (Object)
 
 QT_NO_NARROWING_CONVERSIONS_IN_CONNECT QT_NO_NARROWING_CONVERSIONS_IN_CONNECT
 

Static Public Attributes

static const double zoom_in_limit = 512
 The global zoom in limit for the zoom factor. More...
 
static const double zoom_out_limit = 1 / 16.0
 The global zoom out limit for the zoom factor. More...
 

Protected Member Functions

bool setTemplateVisibilityHelper (const Template *temp, TemplateVisibility vis)
 Sets the template visibility without emitting signals. More...
 
void onTemplateAdded (int pos, Template *temp)
 Creates the visibility data when a template is added to the map. More...
 
void onTemplateDeleted (int pos, const Template *temp)
 Removes the visibility data when a template is deleted. More...
 
- Protected Member Functions inherited from QObject
QObjectsender () const const
 
int senderSignalIndex () const const
 
int receivers (const char *signal) const const
 
bool isSignalConnected (const QMetaMethod &signal) const const
 
virtual void timerEvent (QTimerEvent *event)
 
virtual void childEvent (QChildEvent *event)
 
virtual void customEvent (QEvent *event)
 
virtual void connectNotify (const QMetaMethod &signal)
 
virtual void disconnectNotify (const QMetaMethod &signal)
 

Additional Inherited Members

- Static Public Member Functions inherited from QObject
QString tr (const char *sourceText, const char *disambiguation, int n)
 
QString trUtf8 (const char *sourceText, const char *disambiguation, int n)
 
QMetaObject::Connection connect (const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
 
QMetaObject::Connection connect (const QObject *sender, const QMetaMethod &signal, const QObject *receiver, const QMetaMethod &method, Qt::ConnectionType type)
 
QMetaObject::Connection connect (const QObject *sender, PointerToMemberFunction signal, const QObject *receiver, PointerToMemberFunction method, Qt::ConnectionType type)
 
QMetaObject::Connection connect (const QObject *sender, PointerToMemberFunction signal, Functor functor)
 
QMetaObject::Connection connect (const QObject *sender, PointerToMemberFunction signal, const QObject *context, Functor functor, Qt::ConnectionType type)
 
bool disconnect (const QObject *sender, const char *signal, const QObject *receiver, const char *method)
 
bool disconnect (const QObject *sender, const QMetaMethod &signal, const QObject *receiver, const QMetaMethod &method)
 
bool disconnect (const QMetaObject::Connection &connection)
 
bool disconnect (const QObject *sender, PointerToMemberFunction signal, const QObject *receiver, PointerToMemberFunction method)
 
- Public Attributes inherited from QObject
typedef QObjectList
 
- Properties inherited from QObject
 objectName
 

Detailed Description

Stores view position, zoom, rotation and grid / template visibilities to define a view onto a map.

These parameters define the view coordinates with origin at the view's center, measured in pixels. The class provides methods to convert between view coordinates and map coordinates (defined as millimeter on map paper).

Member Enumeration Documentation

◆ ChangeFlag

Enumerator
NoChange 
CenterChange 
ZoomChange 
RotationChange 

◆ VisibilityFeature

Enumerator
MultipleFeatures 
GridVisible 
OverprintingEnabled 
AllTemplatesHidden 
TemplateVisible 
MapVisible 

Constructor & Destructor Documentation

◆ MapView() [1/2]

OpenOrienteering::MapView::MapView ( QObject parent,
Map map 
)

Creates a default view looking at the origin.

The parameter map must not be null.

◆ MapView() [2/2]

OpenOrienteering::MapView::MapView ( Map map)

Creates a default view looking at the origin.

The map takes ownership of the map view. It must not be null.

◆ ~MapView()

OpenOrienteering::MapView::~MapView ( )
override

Destroys the map view.

Member Function Documentation

◆ areAllTemplatesHidden()

bool OpenOrienteering::MapView::areAllTemplatesHidden ( ) const
inline

Returns if the "hide all templates" toggle is active.

See also setHideAllTemplates().

◆ calculateFinalZoomFactor()

double OpenOrienteering::MapView::calculateFinalZoomFactor ( ) const
inline

Returns the final zoom factor for use in transformations.

Depends on the pixel per millimeter of the display.

◆ calculateViewBoundingBox()

QRectF OpenOrienteering::MapView::calculateViewBoundingBox ( QRectF  map_rect) const

Calculates the bounding box in view coordinates of the given map coordinates rect.

◆ calculateViewedRect()

QRectF OpenOrienteering::MapView::calculateViewedRect ( QRectF  view_rect) const

Calculates the bounding box of the map coordinates which can be viewed using the given view coordinates rect.

◆ center()

MapCoord OpenOrienteering::MapView::center ( ) const
inline

Returns the position of the view center.

◆ effectiveMapVisibility()

TemplateVisibility OpenOrienteering::MapView::effectiveMapVisibility ( ) const

Returns the effectiv visibility settings of the map drawing.

Other than getMapVisibility, this will always return an (100 %) opaque, visible configuration when areAllTemplatesHidden() is true, and it return an invisible configuration when the map's opacity is below 0.005.

◆ finishPanning()

void OpenOrienteering::MapView::finishPanning ( const QPoint offset)

Finishes panning the map.

Parameters
offsetThe final offset, relative to the start of the operation.

◆ getMap() [1/2]

const Map * OpenOrienteering::MapView::getMap ( ) const
inline

Returns the map this view is defined on.

◆ getMap() [2/2]

Map * OpenOrienteering::MapView::getMap ( )
inline

Returns the map this view is defined on.

◆ getMapVisibility()

TemplateVisibility OpenOrienteering::MapView::getMapVisibility ( ) const
inline

Returns the visibility settings of the map drawing.

◆ getRotation()

double OpenOrienteering::MapView::getRotation ( ) const
inline

Returns the view rotation (in radians).

◆ getTemplateVisibility()

TemplateVisibility OpenOrienteering::MapView::getTemplateVisibility ( const Template temp) const

Returns the template visibility.

If the template is unknown, returns default settings.

◆ getZoom()

double OpenOrienteering::MapView::getZoom ( ) const
inline

Returns the raw zoom facor, see also calculateFinalZoomFactor().

◆ hasAlpha()

bool OpenOrienteering::MapView::hasAlpha ( ) const

Returns true if any of the visible elements is not opaque.

◆ isGridVisible()

bool OpenOrienteering::MapView::isGridVisible ( ) const
inline

Returns if the map grid is visible.

◆ isOverprintingSimulationEnabled()

bool OpenOrienteering::MapView::isOverprintingSimulationEnabled ( ) const
inline

Returns if overprinting simulation is enabled.

◆ isTemplateVisible()

bool OpenOrienteering::MapView::isTemplateVisible ( const Template temp) const

Checks if the template is visible without creating a template visibility object if none exists.

◆ lengthToPixel()

qreal OpenOrienteering::MapView::lengthToPixel ( qreal  length) const

Converts a length from native map coordinates to the current length in view pixels.

◆ load()

void OpenOrienteering::MapView::load ( QXmlStreamReader xml)

Loads the map view state from the current element of an xml stream.

◆ mapToView() [1/2]

QPointF OpenOrienteering::MapView::mapToView ( const MapCoord coords) const

Converts map coordinates to view coordinates (with origin at the center of the view)

◆ mapToView() [2/2]

QPointF OpenOrienteering::MapView::mapToView ( const QPointF coords) const

Converts map coordinates to view coordinates (with origin at the center of the view)

◆ onTemplateAdded()

void OpenOrienteering::MapView::onTemplateAdded ( int  pos,
Template temp 
)
protected

Creates the visibility data when a template is added to the map.

◆ onTemplateDeleted()

void OpenOrienteering::MapView::onTemplateDeleted ( int  pos,
const Template temp 
)
protected

Removes the visibility data when a template is deleted.

◆ panOffset()

QPoint OpenOrienteering::MapView::panOffset ( ) const
inline

Returns the current pan offset (when dragging the map).

◆ panOffsetChanged

void OpenOrienteering::MapView::panOffsetChanged ( const QPoint offset)
signal

Indicates a change of the pan offset.

◆ pixelToLength()

qreal OpenOrienteering::MapView::pixelToLength ( qreal  pixel) const

Converts a length from current view pixels to native map coordinates.

◆ save()

void OpenOrienteering::MapView::save ( QXmlStreamWriter xml,
const QLatin1String element_name,
bool  template_details = true 
) const

Saves the map view state to an XML stream.

Parameters
xmlThe XML output stream.
element_nameThe name of the element which will be written.
template_detailsSave template visibilities (default: true)

◆ setAllTemplatesHidden()

void OpenOrienteering::MapView::setAllTemplatesHidden ( bool  value)

Enables or disables hiding all templates in this view.

◆ setCenter()

void OpenOrienteering::MapView::setCenter ( const MapCoord pos)

Sets the position of the view center.

◆ setGridVisible()

void OpenOrienteering::MapView::setGridVisible ( bool  visible)

Sets the map grid visibility.

◆ setMapVisibility()

void OpenOrienteering::MapView::setMapVisibility ( TemplateVisibility  vis)

◆ setOverprintingSimulationEnabled()

void OpenOrienteering::MapView::setOverprintingSimulationEnabled ( bool  enabled)

Enables or disables overprinting simulation.

◆ setPanOffset()

void OpenOrienteering::MapView::setPanOffset ( const QPoint offset)

Sets the current pan offset while the map is being dragged.

◆ setRotation()

void OpenOrienteering::MapView::setRotation ( double  value)

Sets the view rotation (in radians).

◆ setTemplateLoadingBlocked()

void OpenOrienteering::MapView::setTemplateLoadingBlocked ( bool  blocked)

Temporarily blocks automatic template loading on visibility changes.

◆ setTemplateVisibility()

void OpenOrienteering::MapView::setTemplateVisibility ( Template temp,
TemplateVisibility  vis 
)

Sets the template visibility, and emits a change signal.

◆ setTemplateVisibilityHelper()

bool OpenOrienteering::MapView::setTemplateVisibilityHelper ( const Template temp,
TemplateVisibility  vis 
)
protected

Sets the template visibility without emitting signals.

◆ setZoom() [1/2]

void OpenOrienteering::MapView::setZoom ( double  value,
const QPointF center 
)

Sets the zoom factor relative to the given point.

◆ setZoom() [2/2]

void OpenOrienteering::MapView::setZoom ( double  value)

Sets the zoom factor.

◆ templateLoadingBlocked()

bool OpenOrienteering::MapView::templateLoadingBlocked ( ) const
inline

Returns true when template loading on visibility changes is disabled.

◆ updateAllMapWidgets()

void OpenOrienteering::MapView::updateAllMapWidgets ( )

Redraws all map widgets completely.

Note that this calls QWidget::update() which does not cause an immediate repaint; instead it schedules a paint event.

Completely repainting widgets can be slow. Try to do partial updates instead, if possible.

◆ viewChanged

void OpenOrienteering::MapView::viewChanged ( OpenOrienteering::MapView::ChangeFlags  change)
signal

Indicates a change of the viewed area of the map.

Parameters
changeThe aspects that have changed.

◆ viewToMap()

MapCoord OpenOrienteering::MapView::viewToMap ( const QPointF point) const
inline

Converts the point (with origin at the center of the view) to map coordinates.

◆ viewToMapF()

MapCoordF OpenOrienteering::MapView::viewToMapF ( const QPointF point) const
inline

Converts the point (with origin at the center of the view) to map coordinates.

◆ visibilityChanged

void OpenOrienteering::MapView::visibilityChanged ( OpenOrienteering::MapView::VisibilityFeature  feature,
bool  active,
const OpenOrienteering::Template temp = nullptr 
)
signal

Indicates a particular change of visibility.

Parameters
featureThe map view feature that has changed.
activeThe features current state of activation.
tempIf a the feature is a template, a pointer to this template.

◆ worldTransform()

const QTransform & OpenOrienteering::MapView::worldTransform ( ) const
inline

Returns a QTransform suitable for QPainter, so objects defined in map coordinates will be drawn at their view coordinates.

Append a viewport transformation to this to get a complete map-to-viewport transformation which makes the view center appear at the viewport center.

Note: The transform is to be combined with the painter's existing transform.

◆ zoomSteps() [1/2]

void OpenOrienteering::MapView::zoomSteps ( double  num_steps,
const QPointF cursor_pos_view 
)

Zooms the maps (in steps), preserving the given cursor position.

Parameters
num_stepsNumber of zoom steps to zoom in. Negative numbers zoom out.
cursor_pos_viewThe cursor position in view coordinates, must be set if preserve_cursor_pos is used.

◆ zoomSteps() [2/2]

void OpenOrienteering::MapView::zoomSteps ( double  num_steps)

Zooms the maps (in steps), preserving the center of the view.

Parameters
num_stepsNumber of zoom steps to zoom in. Negative numbers zoom out.

Member Data Documentation

◆ zoom_in_limit

const double OpenOrienteering::MapView::zoom_in_limit = 512
static

The global zoom in limit for the zoom factor.

◆ zoom_out_limit

const double OpenOrienteering::MapView::zoom_out_limit = 1 / 16.0
static

The global zoom out limit for the zoom factor.


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