map_widget.cpp¶
file src/app/map/map_widget.cpp ยท Applications
Painting, view arithmetic and input handling of MapWidget, and the scale bar choice.
Source src/app/map/map_widget.cpp
Positions are converted to world pixels at the fractional zoom by scaling the pixel coordinates of the nearest whole level, the level the tiles are taken from, so the tiles, the vessel and the overlays always agree.
Namespaces¶
| Namespace | Description |
|---|---|
nmeasim::app::map |
The slippy-map view of the desktop application, part of nmeasim::app. |
Namespace members¶
Declared or defined in this file and documented on the page of their namespace.
| Member | Description |
|---|---|
nmeasim::app::map::default_attribution |
Returns the attribution the map shows for a tile server when none is configured. |
nmeasim::app::map::scale_bar |
Returns the longest round distance whose bar fits in a maximum length. |
Summary¶
File-local functions
| Name | Description |
|---|---|
make_button() |
Creates one of the square on-map buttons. |
overlay_box() |
Returns the rectangle of a box that fits overlay text, placed with one corner on an anchor. |
File-local variables
| Name | Description |
|---|---|
kMaxTrackPoints |
Largest number of points in all track segments together; beyond it the oldest points are dropped, which bounds memory and painting cost. |
kMaxParentLevels |
Number of zoom levels MapWidget::draw_tile looks up for a cached ancestor of a missing tile; four levels up, one ancestor pixel is stretched over 16 by 16 screen pixels. |
kTrackMinPixelDistance |
Smallest distance in pixels, at the zoom of the moment, between a new vessel position and the last point of the track for the position to be added. |
kMaxRouteMarkers |
Routes with more points than this are drawn without point markers. |
kVectorHours |
The course vector ends where the vessel will be after this many hours: six minutes, a tenth of an hour, so that the vector in nautical miles is a tenth of the speed in knots. |
kMaxVectorPx |
Longest course vector in pixels; it caps the vector of a fast vessel at high zoom. |
kButtonSize |
Width and height of the on-map buttons in pixels. |
kButtonMargin |
Distance in pixels of the on-map buttons from the top and right edges. |
kOverlayMargin |
Distance in pixels of the overlay boxes from the edges of the widget. |
File-local functions¶
make_button()¶
QToolButton* make_button(QWidget* parent, const QString& text, const QString& tip)
Creates one of the square on-map buttons.
The button never takes keyboard focus, so that the map keeps it for its keys, and is styled through its object name map_button.
Parameters
| Name | Type | Description |
|---|---|---|
parent |
QWidget* |
Widget that owns the button. |
text |
const QString& |
Caption; empty for a button that shows an icon. |
tip |
const QString& |
Tooltip, which names the keyboard shortcut. |
Returns QToolButton*: The new button, owned by parent.
Declared in src/app/map/map_widget.cpp:72
overlay_box()¶
QRect overlay_box(QPainter& painter, const QString& text, QPoint anchor, Qt::Alignment corner)
Returns the rectangle of a box that fits overlay text, placed with one corner on an anchor.
The box is the text's bounding box with 6 pixels of padding left and right and 3 above and below; the caller fills it translucently behind the text so that the text reads on any chart.
Parameters
| Name | Type | Description |
|---|---|---|
painter |
QPainter& |
Painter whose current font measures the text. |
text |
const QString& |
Text the box must hold. |
anchor |
QPoint |
Widget pixel where the chosen corner of the box goes. |
corner |
Qt::Alignment |
Corner placed on anchor: Qt::AlignRight or left, combined with Qt::AlignBottom or top. |
Returns QRect: The box in widget pixels.
Declared in src/app/map/map_widget.cpp:96
File-local variables¶
kMaxTrackPoints¶
int kMaxTrackPoints{5000}
Largest number of points in all track segments together; beyond it the oldest points are dropped, which bounds memory and painting cost.
Declared in src/app/map/map_widget.cpp:42
kMaxParentLevels¶
int kMaxParentLevels{4}
Number of zoom levels MapWidget::draw_tile looks up for a cached ancestor of a missing tile; four levels up, one ancestor pixel is stretched over 16 by 16 screen pixels.
Declared in src/app/map/map_widget.cpp:45
kTrackMinPixelDistance¶
double kTrackMinPixelDistance{2.0}
Smallest distance in pixels, at the zoom of the moment, between a new vessel position and the last point of the track for the position to be added.
Declared in src/app/map/map_widget.cpp:48
kMaxRouteMarkers¶
qsizetype kMaxRouteMarkers{500}
Routes with more points than this are drawn without point markers.
Declared in src/app/map/map_widget.cpp:50
kVectorHours¶
double kVectorHours{0.1}
The course vector ends where the vessel will be after this many hours: six minutes, a tenth of an hour, so that the vector in nautical miles is a tenth of the speed in knots.
Declared in src/app/map/map_widget.cpp:53
kMaxVectorPx¶
double kMaxVectorPx{400.0}
Longest course vector in pixels; it caps the vector of a fast vessel at high zoom.
Declared in src/app/map/map_widget.cpp:55
kButtonSize¶
int kButtonSize{28}
Width and height of the on-map buttons in pixels.
Declared in src/app/map/map_widget.cpp:57
kButtonMargin¶
int kButtonMargin{8}
Distance in pixels of the on-map buttons from the top and right edges.
Declared in src/app/map/map_widget.cpp:59
kOverlayMargin¶
int kOverlayMargin{6}
Distance in pixels of the overlay boxes from the edges of the widget.
Declared in src/app/map/map_widget.cpp:61