Skip to content

MapWidget

class nmeasim::app::map::MapWidget · Applications

A slippy map: raster tiles from a TileCache, the vessel with its heading and a vector of its course and speed, the track it has sailed, and mouse, touchpad and keyboard navigation.

Inherits QWidget

Declared in src/app/map/map_widget.hpp (line 94)

Overlays show the zoom level and view state with a north arrow, zoom buttons and a follow button, a scale bar, the position under the pointer and the attribution of the tile server (see attribution). The chart is always north up. Longitudes are wrapped into [-180, 180), so the world repeats east and west and the view can pan across the antimeridian. The zoom level is fractional in [kMinZoom, kMaxZoom], so the wheel, the touchpad and pinch gestures zoom smoothly: tiles come from the nearest whole level and are scaled by the remaining factor. The keyboard and the buttons step to whole levels. In follow mode the centre tracks the vessel; dragging the map switches follow mode off.

The sailed track is a list of segments, at most 5000 points in all, the oldest dropped first. Moving the vessel by hand or seeking in a track or log starts a new segment (break_track), so that no line joins the old and the new position.

The widget does not move the vessel or set the destination itself: it reports the operator's choices through position_picked, destination_picked and destination_cleared, and the owner feeds the resulting state back with set_vessel and set_destination.

Nested types

Type Description
MapWidget::Vessel The vessel as last placed with set_vessel.

Summary

Public member functions

Name Description
MapWidget() Creates the map centred on central Athens (37.9838 N, 23.7275 E, the default vessel position of a profile) at zoom 12, in follow mode and without a vessel.
cache() Returns the tile cache the map paints from.
center() Returns the position at the centre of the widget.
set_center() Moves the centre of the view to a position without changing the zoom.
zoom() Returns the zoom level rounded to the nearest whole level.
zoom_level() Returns the fractional zoom level.
set_zoom() Sets a whole zoom level, keeping the centre.
zoom_by() Zooms by whole levels from the nearest whole level, keeping the position under an anchor fixed.
zoom_to() Zooms to a fractional level, keeping the position under an anchor fixed.
follows_vessel() Returns whether the map follows the vessel.
set_follow_vessel() Switches follow mode on or off.
set_vessel() Places the vessel and extends the sailed track.
vessel_position() Returns where the vessel was last placed.
clear_track() Removes every track segment and repaints; the vessel stays.
break_track() Ends the current track segment; the next vessel position starts a new one.
track_length() Returns the number of points in all track segments.
track_segment_count() Returns the number of track segments.
set_route() Sets the track or route loaded from a file, drawn in green under the sailed track.
clear_route() Removes the loaded route and repaints.
route_length() Returns the number of points of the loaded route.
set_destination() Sets the destination waypoint and the origin of its leg.
destination() Returns the destination waypoint drawn on the map.
point_of() Returns the widget pixel of a position at the current view.
position_at() Returns the position under a widget pixel at the current view, the inverse of point_of.
attribution() Returns the attribution drawn in the bottom-right corner.
set_attribution() Sets the attribution drawn in the bottom-right corner and repaints.
scale_m_per_px() Returns the ground distance one pixel covers at the centre latitude.
course_vector_length_px() Returns the length of the course vector drawn ahead of the vessel.
pointer_position() Returns the position under the pointer, as the bottom-right readout shows it.
zoom_in_button() Returns the on-map + button, which zooms in one level around the centre; for tests.
zoom_out_button() Returns the on-map − button, which zooms out one level around the centre; for tests.
follow_button() Returns the on-map Follow the vessel button, checked while following; for tests.

Signals

Name Description
position_picked() Emitted when the operator asks to move the vessel to a point of the map.
destination_picked() Emitted when the operator asks to steer for a point of the map.
destination_cleared() Emitted when the operator chooses Clear destination in the context menu, which is enabled only while a destination is set.
view_changed() Emitted when the centre or the zoom level changes through the view functions or a drag.
follow_changed() Emitted when follow mode is switched on or off, and only then.

Protected member functions

Name Description
event() Handles pinch gestures on a touchpad and passes every other event to QWidget.
paintEvent() Paints the whole map in one pass.
mousePressEvent() Starts a drag, or picks a position with a modifier.
mouseMoveEvent() Updates the pointer readout and, during a drag, pans the map.
mouseReleaseEvent() Ends a drag when the left button is released and restores the cursor.
mouseDoubleClickEvent() Emits position_picked for a left double-click, to move the vessel there.
leaveEvent() Hides the pointer readout when the pointer leaves the map.
contextMenuEvent() Shows the context menu for the position under the pointer.
wheelEvent() Zooms smoothly around the pointer, or keeping the vessel centred in follow mode.
keyPressEvent() Handles the map keys and passes every other key to QWidget.
resizeEvent() Keeps the buttons in the top-right corner after a resize and repaints.

Private member functions

Name Description
draw_tiles() Paints the tiles covering the widget at the current view.
draw_route() Draws the loaded route as a green line, with a marker on every point when it has 500 points or fewer.
draw_track() Draws the sailed track as a red line per segment; single-point segments draw nothing.
draw_destination() Draws the destination diamond, the dashed bearing line from the vessel and the dotted leg line from the origin; nothing without a destination.
draw_vessel() Draws the vessel: the six-minute course vector, a heading line past the bow and the hull outline rotated to the heading; nothing before the first set_vessel.
draw_overlay() Draws the overlays: the zoom level and view state with the north arrow (top left), the scale bar (bottom left), and the pointer position and the attribution (bottom right); an empty attribution draws no box and the pointer position takes its place.
draw_tile() Draws a tile, falling back to a scaled part of an ancestor when it is not cached.
tile_zoom() Returns the whole zoom level the tiles are taken from.
tile_scale() Returns the factor the tiles of tile_zoom are scaled by to reach the fractional zoom.
world_pixel() Returns the pixel coordinates of a position in the world image at the current fractional zoom.
position_of_world() Returns the position at world pixel coordinates at the current fractional zoom, the inverse of world_pixel.
center_pixel() Returns the world pixel coordinates of the centre at the current fractional zoom.
pan_by() Moves the map content by a distance on screen and emits view_changed.
place_buttons() Stacks the zoom and follow buttons in the top-right corner.

Private data members

Name Description
cache_ Tile source; not owned, outlives the widget.
center_ Position at the centre of the widget; defaults to central Athens, the default vessel position of a profile.
zoom_ Fractional zoom level, in [kMinZoom, kMaxZoom]; the default of 12 matches the default of the saved map/zoom preference.
follow_ Whether the centre tracks the vessel.
vessel_ The vessel, or std::nullopt before the first set_vessel.
track_ Sailed track segments, oldest first, at most 5000 points in all.
track_broken_ Whether the next vessel position starts a new segment, set by break_track.
route_ Track or route loaded from a file; empty when none is loaded.
destination_ Destination waypoint, or std::nullopt when none is set.
leg_origin_ Start of the leg to the destination, or std::nullopt for no leg line; always empty without a destination.
attribution_ Attribution set with set_attribution, or std::nullopt for default_attribution.
pointer_ Position under the pointer, or std::nullopt while the pointer is not over the map.
drag_last_ Pointer position in widget pixels at the last drag step, or std::nullopt when no drag is in progress.
zoom_in_button_ The + button; a child of the widget.
zoom_out_button_ The − button; a child of the widget.
follow_button_ The checkable Follow the vessel button; a child of the widget.

Public member functions

MapWidget()

explicit MapWidget(TileCache* cache, QWidget* parent = nullptr)

Creates the map centred on central Athens (37.9838 N, 23.7275 E, the default vessel position of a profile) at zoom 12, in follow mode and without a vessel.

The widget repaints whenever cache reports a downloaded tile and whenever the theme changes.

Parameters

Name Type Description
cache TileCache* Source of the tiles; not owned, must not be null and must outlive the widget. The widget queues downloads through it while painting.
parent QWidget* Qt parent that owns the widget; null leaves ownership with the caller.

Declared in src/app/map/map_widget.hpp:107 · defined in src/app/map/map_widget.cpp:151

cache()

TileCache* cache() const noexcept

Returns the tile cache the map paints from.

Returns TileCache*: The cache given to the constructor, not owned by the widget.

Declared in src/app/map/map_widget.hpp:112

center()

core::geo::Position center() const noexcept

Returns the position at the centre of the widget.

Returns core::geo::Position: The centre. Its latitude lies within kMaxLatitudeDeg of the equator and its longitude in [-180, 180), also after panning or zooming across the antimeridian.

Declared in src/app/map/map_widget.hpp:118

set_center()

void set_center(core::geo::Position center)

Moves the centre of the view to a position without changing the zoom.

Follow mode is not changed; while it is on, the next set_vessel recentres on the vessel. Emits view_changed, even when the centre did not move.

Parameters

Name Type Description
center core::geo::Position New centre. The latitude is clamped to [-kMaxLatitudeDeg, kMaxLatitudeDeg] and the longitude wrapped into [-180, 180).

Declared in src/app/map/map_widget.hpp:126 · defined in src/app/map/map_widget.cpp:187

zoom()

int zoom() const noexcept

Returns the zoom level rounded to the nearest whole level.

Returns int: The whole zoom level, in [kMinZoom, kMaxZoom].

Declared in src/app/map/map_widget.hpp:130 · defined in src/app/map/map_widget.cpp:194

zoom_level()

double zoom_level() const noexcept

Returns the fractional zoom level.

Returns double: The zoom level, in [kMinZoom, kMaxZoom]; each whole level doubles the scale.

Declared in src/app/map/map_widget.hpp:135

set_zoom()

void set_zoom(int zoom)

Sets a whole zoom level, keeping the centre.

Emits view_changed when the level changes.

Parameters

Name Type Description
zoom int New zoom level; clamped to [kMinZoom, kMaxZoom].

Declared in src/app/map/map_widget.hpp:141 · defined in src/app/map/map_widget.cpp:198

zoom_by()

void zoom_by(int steps, QPoint anchor)

Zooms by whole levels from the nearest whole level, keeping the position under an anchor fixed.

The result is a whole level even when the zoom was fractional. Behaves as zoom_to otherwise, emitting view_changed when the level changes.

Parameters

Name Type Description
steps int Number of levels, positive to zoom in and negative to zoom out; the result is clamped to [kMinZoom, kMaxZoom].
anchor QPoint Widget pixel whose position stays in place; ignored in follow mode.

Declared in src/app/map/map_widget.hpp:151 · defined in src/app/map/map_widget.cpp:209

zoom_to()

void zoom_to(double level, QPointF anchor)

Zooms to a fractional level, keeping the position under an anchor fixed.

In follow mode the centre stays where it is, on the vessel once one is placed, and the anchor is ignored; otherwise the new centre's longitude is wrapped into [-180, 180). A change of less than 1e-9 levels is ignored; otherwise the view repaints and view_changed is emitted.

Parameters

Name Type Description
level double New zoom level; clamped to [kMinZoom, kMaxZoom].
anchor QPointF Widget pixel, from the top-left corner, whose position stays in place.

Declared in src/app/map/map_widget.hpp:161 · defined in src/app/map/map_widget.cpp:213

follows_vessel()

bool follows_vessel() const noexcept

Returns whether the map follows the vessel.

Returns bool: true while the centre tracks the vessel.

Declared in src/app/map/map_widget.hpp:166

set_follow_vessel()

void set_follow_vessel(bool follow)

Switches follow mode on or off.

Switching it on recentres on the vessel, if one has been placed, through set_center, which emits view_changed. The Follow the vessel button is updated to match without re-emitting its own signal. Emits follow_changed when the mode changes and does nothing otherwise. Connected to that button and to the Follow vessel on the map action of the main window.

Parameters

Name Type Description
follow bool true to keep the vessel in the centre, false for a free view.

Declared in src/app/map/map_widget.hpp:176 · defined in src/app/map/map_widget.cpp:231

set_vessel()

void set_vessel(
    core::geo::Position position,
    double heading_true_deg,
    double course_over_ground_deg,
    double speed_over_ground_kn = 0.0)

Places the vessel and extends the sailed track.

The position is appended to the current track segment when it lies at least 2 pixels from the segment's last point at the current zoom, so that a vessel at rest adds nothing; after break_track, or with no track, it starts a new segment. Once the track exceeds 5000 points the oldest are dropped. In follow mode the map recentres on the vessel, its longitude wrapped into [-180, 180), and emits view_changed when the centre moved.

Parameters

Name Type Description
position core::geo::Position Position of the vessel.
heading_true_deg double Heading in degrees true, the direction the hull points.
course_over_ground_deg double Course over ground in degrees true, the direction of the course vector.
speed_over_ground_kn double Speed over ground in knots. The course vector ends where the vessel will be in six minutes at this speed; it is at most 400 pixels long and not drawn below 2 pixels, so the default of 0 draws none.

Declared in src/app/map/map_widget.hpp:194 · defined in src/app/map/map_widget.cpp:247

vessel_position()

std::optional<core::geo::Position> vessel_position() const noexcept

Returns where the vessel was last placed.

Returns std::optional<core::geo::Position>: The vessel position, or std::nullopt before the first set_vessel.

Declared in src/app/map/map_widget.hpp:199 · defined in src/app/map/map_widget.cpp:284

clear_track()

void clear_track()

Removes every track segment and repaints; the vessel stays.

Declared in src/app/map/map_widget.hpp:201 · defined in src/app/map/map_widget.cpp:291

break_track()

void break_track()

Ends the current track segment; the next vessel position starts a new one.

Nothing changes on screen until that position arrives, and track_segment_count counts the new segment only then. Called when the vessel jumps: moved by hand or by a seek in a track or log.

Declared in src/app/map/map_widget.hpp:207 · defined in src/app/map/map_widget.cpp:297

track_length()

int track_length() const noexcept

Returns the number of points in all track segments.

Returns int: The point count, at most 5000.

Declared in src/app/map/map_widget.hpp:211 · defined in src/app/map/map_widget.cpp:301

track_segment_count()

int track_segment_count() const noexcept

Returns the number of track segments.

Returns int: The segment count, including a segment of a single point, which is not drawn.

Declared in src/app/map/map_widget.hpp:215

set_route()

void set_route(const QList<core::geo::Position>& route)

Sets the track or route loaded from a file, drawn in green under the sailed track.

A route of 500 points or fewer also gets a marker on every point.

Parameters

Name Type Description
route const QList<core::geo::Position>& Points in sailing order; empty draws nothing.

Declared in src/app/map/map_widget.hpp:224 · defined in src/app/map/map_widget.cpp:309

clear_route()

void clear_route()

Removes the loaded route and repaints.

Declared in src/app/map/map_widget.hpp:226 · defined in src/app/map/map_widget.cpp:314

route_length()

int route_length() const noexcept

Returns the number of points of the loaded route.

Returns int: The point count; 0 without a route.

Declared in src/app/map/map_widget.hpp:230

set_destination()

void set_destination(
    std::optional<core::geo::Position> destination,
    std::optional<core::geo::Position> origin)

Sets the destination waypoint and the origin of its leg.

The destination is drawn as a magenta diamond with a dashed bearing line from the vessel and a dotted line for the leg from its origin, and the status overlay reads destination set. No signal is emitted.

Parameters

Name Type Description
destination std::optional<core::geo::Position> Waypoint position; std::nullopt removes the destination and the leg.
origin std::optional<core::geo::Position> Start of the leg; std::nullopt draws no leg line. Ignored when destination is empty.

Declared in src/app/map/map_widget.hpp:242 · defined in src/app/map/map_widget.cpp:319

destination()

std::optional<core::geo::Position> destination() const noexcept

Returns the destination waypoint drawn on the map.

Returns std::optional<core::geo::Position>: The destination, or std::nullopt when none is set.

Declared in src/app/map/map_widget.hpp:247

point_of()

QPointF point_of(core::geo::Position position) const

Returns the widget pixel of a position at the current view.

Parameters

Name Type Description
position core::geo::Position Position to locate.

Returns QPointF: Fractional widget coordinates from the top-left corner, x to the right and y downwards; outside the widget when the position is not in view. As the world repeats east and west, the copy of the position within half a world width of the centre is taken, so a position just across the antimeridian lies next to the centre.

Declared in src/app/map/map_widget.hpp:258 · defined in src/app/map/map_widget.cpp:349

position_at()

core::geo::Position position_at(QPointF point) const

Returns the position under a widget pixel at the current view, the inverse of point_of.

Parameters

Name Type Description
point QPointF Widget coordinates from the top-left corner; may lie outside the widget.

Returns core::geo::Position: The position. Its latitude is clamped to [-kMaxLatitudeDeg, kMaxLatitudeDeg] and its longitude wrapped into [-180, 180), also for a point beyond the antimeridian.

Declared in src/app/map/map_widget.hpp:266 · defined in src/app/map/map_widget.cpp:359

attribution()

QString attribution() const

Returns the attribution drawn in the bottom-right corner.

Returns QString: The text set with set_attribution; without one, default_attribution of the cache's tile URL template. Empty when nothing is drawn.

Declared in src/app/map/map_widget.hpp:272 · defined in src/app/map/map_widget.cpp:178

set_attribution()

void set_attribution(std::optional<QString> attribution)

Sets the attribution drawn in the bottom-right corner and repaints.

Set from the map/tile_attribution preference by the main window.

Parameters

Name Type Description
attribution std::optional<QString> Text to draw, for example the credit a tile server's terms require; empty draws no attribution. std::nullopt returns to default_attribution of the cache's tile URL template.

Declared in src/app/map/map_widget.hpp:280 · defined in src/app/map/map_widget.cpp:182

scale_m_per_px()

double scale_m_per_px() const

Returns the ground distance one pixel covers at the centre latitude.

Returns double: Metres per pixel at the current fractional zoom.

Declared in src/app/map/map_widget.hpp:285 · defined in src/app/map/map_widget.cpp:364

course_vector_length_px()

double course_vector_length_px() const

Returns the length of the course vector drawn ahead of the vessel.

Returns double: The distance the vessel covers in six minutes at its speed over ground, in pixels at the current view, at most 400; 0 without a vessel.

Declared in src/app/map/map_widget.hpp:290 · defined in src/app/map/map_widget.cpp:368

pointer_position()

std::optional<core::geo::Position> pointer_position() const noexcept

Returns the position under the pointer, as the bottom-right readout shows it.

Returns std::optional<core::geo::Position>: The position, or std::nullopt before the pointer first moves over the map and after it leaves.

Declared in src/app/map/map_widget.hpp:295

zoom_in_button()

QToolButton* zoom_in_button() const noexcept

Returns the on-map + button, which zooms in one level around the centre; for tests.

Returns QToolButton*: The button, a child of and owned by the widget.

Declared in src/app/map/map_widget.hpp:302

zoom_out_button()

QToolButton* zoom_out_button() const noexcept

Returns the on-map − button, which zooms out one level around the centre; for tests.

Returns QToolButton*: The button, a child of and owned by the widget.

Declared in src/app/map/map_widget.hpp:306

follow_button()

QToolButton* follow_button() const noexcept

Returns the on-map Follow the vessel button, checked while following; for tests.

Returns QToolButton*: The button, a child of and owned by the widget.

Declared in src/app/map/map_widget.hpp:310

Signals

position_picked()

void position_picked(nmeasim::core::geo::Position position)

Emitted when the operator asks to move the vessel to a point of the map.

The request comes from a left double-click, a Ctrl+click or Move vessel here in the context menu. The widget itself does not move the vessel; the main window does and calls set_vessel.

Parameters

Name Type Description
position nmeasim::core::geo::Position The position under the pointer, as position_at returns it.

Declared in src/app/map/map_widget.hpp:320

destination_picked()

void destination_picked(nmeasim::core::geo::Position position)

Emitted when the operator asks to steer for a point of the map.

The request comes from a Shift+click or Set destination here in the context menu. The widget itself does not set the destination; see set_destination.

Parameters

Name Type Description
position nmeasim::core::geo::Position The position under the pointer, as position_at returns it.

Declared in src/app/map/map_widget.hpp:327

destination_cleared()

void destination_cleared()

Emitted when the operator chooses Clear destination in the context menu, which is enabled only while a destination is set.

Declared in src/app/map/map_widget.hpp:330

view_changed()

void view_changed()

Emitted when the centre or the zoom level changes through the view functions or a drag.

Emitted by set_center (always), set_zoom, zoom_by and zoom_to (when the level changes), by every step of a drag and by set_vessel when follow mode moves the centre to a new vessel position. The main window saves the zoom level on it.

Declared in src/app/map/map_widget.hpp:337

follow_changed()

void follow_changed(bool follow)

Emitted when follow mode is switched on or off, and only then.

Parameters

Name Type Description
follow bool The new mode, true while the map follows the vessel.

Declared in src/app/map/map_widget.hpp:341

Protected member functions

event()

bool event(QEvent* event) override

Handles pinch gestures on a touchpad and passes every other event to QWidget.

A native zoom gesture zooms smoothly by the magnification it reports, around the fingers (or keeping the vessel centred in follow mode), as zoom_to does. Platforms report such gestures on macOS and Wayland.

Parameters

Name Type Description
event QEvent* Event to handle.

Returns bool: true for a zoom gesture, which is consumed; otherwise the result of QWidget::event.

Declared in src/app/map/map_widget.hpp:353 · defined in src/app/map/map_widget.cpp:675

paintEvent()

void paintEvent(QPaintEvent* event) override

Paints the whole map in one pass.

Paints, from bottom to top: the background, the tiles of the visible area (a missing tile replaced by the covering part of a cached ancestor up to four levels up, or a grey square), a translucent shade that dims the chart in the night theme, the loaded route, the sailed track, the destination, the vessel and the overlays. Missing tiles are queued for download when the cache is online, so painting drives downloading.

Parameters

Name Type Description
event QPaintEvent* Paint event; unused, as the whole widget is repainted.

Declared in src/app/map/map_widget.hpp:363 · defined in src/app/map/map_widget.cpp:392

mousePressEvent()

void mousePressEvent(QMouseEvent* event) override

Starts a drag, or picks a position with a modifier.

A left press with Shift emits destination_picked, with Ctrl emits position_picked, and without either starts a drag with a closed-hand cursor. A press that does not pick a position gives the widget keyboard focus.

Parameters

Name Type Description
event QMouseEvent* Press to handle.

Declared in src/app/map/map_widget.hpp:371 · defined in src/app/map/map_widget.cpp:687

mouseMoveEvent()

void mouseMoveEvent(QMouseEvent* event) override

Updates the pointer readout and, during a drag, pans the map.

The first movement of a drag switches follow mode off (emitting follow_changed); every movement pans the map by the pointer's travel and emits view_changed.

Parameters

Name Type Description
event QMouseEvent* Movement to handle.

Declared in src/app/map/map_widget.hpp:378 · defined in src/app/map/map_widget.cpp:703

mouseReleaseEvent()

void mouseReleaseEvent(QMouseEvent* event) override

Ends a drag when the left button is released and restores the cursor.

Parameters

Name Type Description
event QMouseEvent* Release to handle.

Declared in src/app/map/map_widget.hpp:382 · defined in src/app/map/map_widget.cpp:720

mouseDoubleClickEvent()

void mouseDoubleClickEvent(QMouseEvent* event) override

Emits position_picked for a left double-click, to move the vessel there.

Parameters

Name Type Description
event QMouseEvent* Double-click to handle.

Declared in src/app/map/map_widget.hpp:386 · defined in src/app/map/map_widget.cpp:727

leaveEvent()

void leaveEvent(QEvent* event) override

Hides the pointer readout when the pointer leaves the map.

Parameters

Name Type Description
event QEvent* Leave event, passed on to QWidget.

Declared in src/app/map/map_widget.hpp:390 · defined in src/app/map/map_widget.cpp:733

contextMenuEvent()

void contextMenuEvent(QContextMenuEvent* event) override

Shows the context menu for the position under the pointer.

The menu offers Move vessel here (emits position_picked), Set destination here (emits destination_picked) and Clear destination (emits destination_cleared, enabled only while a destination is set). It runs modally and returns once closed.

Parameters

Name Type Description
event QContextMenuEvent* Context menu request, which gives the position.

Declared in src/app/map/map_widget.hpp:398 · defined in src/app/map/map_widget.cpp:739

wheelEvent()

void wheelEvent(QWheelEvent* event) override

Zooms smoothly around the pointer, or keeping the vessel centred in follow mode.

One wheel notch, a vertical angle delta of 120, zooms one level; touchpads and high-resolution wheels send smaller deltas, which zoom by the matching fraction of a level. Horizontal scrolling is ignored. The event is always accepted.

Parameters

Name Type Description
event QWheelEvent* Wheel event to handle.

Declared in src/app/map/map_widget.hpp:406 · defined in src/app/map/map_widget.cpp:752

keyPressEvent()

void keyPressEvent(QKeyEvent* event) override

Handles the map keys and passes every other key to QWidget.

Plus (or equals) and minus zoom one whole level around the centre; Home switches follow mode on and recentres.

Parameters

Name Type Description
event QKeyEvent* Key press to handle.

Declared in src/app/map/map_widget.hpp:413 · defined in src/app/map/map_widget.cpp:762

resizeEvent()

void resizeEvent(QResizeEvent* event) override

Keeps the buttons in the top-right corner after a resize and repaints.

Parameters

Name Type Description
event QResizeEvent* Resize event, passed on to QWidget.

Declared in src/app/map/map_widget.hpp:417 · defined in src/app/map/map_widget.cpp:780

Private member functions

draw_tiles()

void draw_tiles(class QPainter& painter)

Paints the tiles covering the widget at the current view.

Rows are limited to the world; columns wrap around the antimeridian, so the world repeats east and west. Scaled tiles are smoothed.

Parameters

Name Type Description
painter class QPainter& Painter on the widget.

Declared in src/app/map/map_widget.hpp:438 · defined in src/app/map/map_widget.cpp:411

draw_route()

void draw_route(QPainter& painter)

Draws the loaded route as a green line, with a marker on every point when it has 500 points or fewer.

Parameters

Name Type Description
painter QPainter& Painter on the widget.

Declared in src/app/map/map_widget.hpp:443 · defined in src/app/map/map_widget.cpp:465

draw_track()

void draw_track(QPainter& painter)

Draws the sailed track as a red line per segment; single-point segments draw nothing.

Parameters

Name Type Description
painter QPainter& Painter on the widget.

Declared in src/app/map/map_widget.hpp:447 · defined in src/app/map/map_widget.cpp:489

draw_destination()

void draw_destination(QPainter& painter)

Draws the destination diamond, the dashed bearing line from the vessel and the dotted leg line from the origin; nothing without a destination.

Parameters

Name Type Description
painter QPainter& Painter on the widget.

Declared in src/app/map/map_widget.hpp:452 · defined in src/app/map/map_widget.cpp:510

draw_vessel()

void draw_vessel(QPainter& painter)

Draws the vessel: the six-minute course vector, a heading line past the bow and the hull outline rotated to the heading; nothing before the first set_vessel.

Parameters

Name Type Description
painter QPainter& Painter on the widget.

Declared in src/app/map/map_widget.hpp:457 · defined in src/app/map/map_widget.cpp:535

draw_overlay()

void draw_overlay(QPainter& painter)

Draws the overlays: the zoom level and view state with the north arrow (top left), the scale bar (bottom left), and the pointer position and the attribution (bottom right); an empty attribution draws no box and the pointer position takes its place.

Parameters

Name Type Description
painter QPainter& Painter on the widget.

Declared in src/app/map/map_widget.hpp:463 · defined in src/app/map/map_widget.cpp:585

draw_tile()

void draw_tile(QPainter& painter, TileKey key, const QRect& target)

Draws a tile, falling back to a scaled part of an ancestor when it is not cached.

Asking the cache for the tile queues its download when online. The fallback looks up to four levels up and takes only ancestors already cached, so it queues no further downloads; without one the target becomes a grey square with a faint border.

Parameters

Name Type Description
painter QPainter& Painter on the widget.
key TileKey Tile to draw, with x already wrapped into the level.
target const QRect& Widget rectangle the tile fills, in pixels.

Declared in src/app/map/map_widget.hpp:473 · defined in src/app/map/map_widget.cpp:438

tile_zoom()

int tile_zoom() const noexcept

Returns the whole zoom level the tiles are taken from.

Returns int: The fractional zoom rounded to the nearest level, in [kMinZoom, kMaxZoom].

Declared in src/app/map/map_widget.hpp:478 · defined in src/app/map/map_widget.cpp:326

tile_scale()

double tile_scale() const noexcept

Returns the factor the tiles of tile_zoom are scaled by to reach the fractional zoom.

Returns double: 2 to the power of the difference between the fractional and the tile zoom, in about [0.71, 1.41].

Declared in src/app/map/map_widget.hpp:484 · defined in src/app/map/map_widget.cpp:330

world_pixel()

QPointF world_pixel(core::geo::Position position) const

Returns the pixel coordinates of a position in the world image at the current fractional zoom.

Parameters

Name Type Description
position core::geo::Position Position to project, treated as pixel_coordinates treats it.

Returns QPointF: World pixel coordinates, 2 to the power of the zoom times 256 pixels across.

Declared in src/app/map/map_widget.hpp:490 · defined in src/app/map/map_widget.cpp:334

position_of_world()

core::geo::Position position_of_world(QPointF pixel) const

Returns the position at world pixel coordinates at the current fractional zoom, the inverse of world_pixel.

Parameters

Name Type Description
pixel QPointF World pixel coordinates.

Returns core::geo::Position: The position, with the latitude clamped to [-kMaxLatitudeDeg, kMaxLatitudeDeg] and the longitude wrapped into [-180, 180).

Declared in src/app/map/map_widget.hpp:497 · defined in src/app/map/map_widget.cpp:338

center_pixel()

QPointF center_pixel() const

Returns the world pixel coordinates of the centre at the current fractional zoom.

Returns QPointF: world_pixel of the centre.

Declared in src/app/map/map_widget.hpp:501 · defined in src/app/map/map_widget.cpp:345

pan_by()

void pan_by(QPointF delta_px)

Moves the map content by a distance on screen and emits view_changed.

The new centre's longitude is wrapped into [-180, 180).

Parameters

Name Type Description
delta_px QPointF Movement of the content in pixels, x to the right and y downwards; the centre moves the opposite way.

Declared in src/app/map/map_widget.hpp:508 · defined in src/app/map/map_widget.cpp:377

place_buttons()

void place_buttons()

Stacks the zoom and follow buttons in the top-right corner.

Declared in src/app/map/map_widget.hpp:510 · defined in src/app/map/map_widget.cpp:383

Private data members

cache_

TileCache* cache_

Tile source; not owned, outlives the widget.

Declared in src/app/map/map_widget.hpp:513

center_

core::geo::Position center_{37.9838, 23.7275}

Position at the centre of the widget; defaults to central Athens, the default vessel position of a profile.

Declared in src/app/map/map_widget.hpp:516

zoom_

double zoom_{12.0}

Fractional zoom level, in [kMinZoom, kMaxZoom]; the default of 12 matches the default of the saved map/zoom preference.

Declared in src/app/map/map_widget.hpp:519

follow_

bool follow_{true}

Whether the centre tracks the vessel.

Declared in src/app/map/map_widget.hpp:521

vessel_

std::optional<Vessel> vessel_

The vessel, or std::nullopt before the first set_vessel.

Declared in src/app/map/map_widget.hpp:523

track_

QList<QList<core::geo::Position>> track_

Sailed track segments, oldest first, at most 5000 points in all.

Declared in src/app/map/map_widget.hpp:525

track_broken_

bool track_broken_{false}

Whether the next vessel position starts a new segment, set by break_track.

Declared in src/app/map/map_widget.hpp:527

route_

QList<core::geo::Position> route_

Track or route loaded from a file; empty when none is loaded.

Declared in src/app/map/map_widget.hpp:529

destination_

std::optional<core::geo::Position> destination_

Destination waypoint, or std::nullopt when none is set.

Declared in src/app/map/map_widget.hpp:531

leg_origin_

std::optional<core::geo::Position> leg_origin_

Start of the leg to the destination, or std::nullopt for no leg line; always empty without a destination.

Declared in src/app/map/map_widget.hpp:534

attribution_

std::optional<QString> attribution_

Attribution set with set_attribution, or std::nullopt for default_attribution.

Declared in src/app/map/map_widget.hpp:536

pointer_

std::optional<core::geo::Position> pointer_

Position under the pointer, or std::nullopt while the pointer is not over the map.

Declared in src/app/map/map_widget.hpp:538

drag_last_

std::optional<QPoint> drag_last_

Pointer position in widget pixels at the last drag step, or std::nullopt when no drag is in progress.

Declared in src/app/map/map_widget.hpp:541

zoom_in_button_

QToolButton* zoom_in_button_

The + button; a child of the widget.

Declared in src/app/map/map_widget.hpp:543

zoom_out_button_

QToolButton* zoom_out_button_

The − button; a child of the widget.

Declared in src/app/map/map_widget.hpp:545

follow_button_

QToolButton* follow_button_

The checkable Follow the vessel button; a child of the widget.

Declared in src/app/map/map_widget.hpp:547