-
Notifications
You must be signed in to change notification settings - Fork 105
/
gps_temporary_markers.cpp
140 lines (111 loc) · 3.48 KB
/
gps_temporary_markers.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
/*
* Copyright 2014 Thomas Schöps
* Copyright 2015 Kai Pastor
*
* This file is part of OpenOrienteering.
*
* OpenOrienteering is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* OpenOrienteering is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with OpenOrienteering. If not, see <http://www.gnu.org/licenses/>.
*/
#include "gps_temporary_markers.h"
#include <Qt>
#include <QtGlobal>
#include <QBrush>
#include <QPainter>
#include <QPen>
#include <QRgb>
#include "core/map_coord.h"
#include "core/map_view.h"
#include "gui/map/map_widget.h"
#include "sensors/gps_display.h"
#include "tools/tool.h"
class QPointF;
namespace OpenOrienteering {
GPSTemporaryMarkers::GPSTemporaryMarkers(MapWidget* widget, GPSDisplay* gps_display): QObject()
{
this->widget = widget;
this->gps_display = gps_display;
recording_path = false;
connect(gps_display, &GPSDisplay::mapPositionUpdated, this, &GPSTemporaryMarkers::newGPSPosition);
widget->setTemporaryMarkerDisplay(this);
}
GPSTemporaryMarkers::~GPSTemporaryMarkers()
{
widget->setTemporaryMarkerDisplay(nullptr);
}
bool GPSTemporaryMarkers::addPoint()
{
if (!gps_display->hasValidPosition())
return false;
points.push_back(gps_display->getLatestGPSCoord());
updateMapWidget();
return true;
}
void GPSTemporaryMarkers::startPath()
{
paths.push_back(std::vector< QPointF >());
recording_path = true;
if (gps_display->hasValidPosition())
newGPSPosition(gps_display->getLatestGPSCoord(), gps_display->getLatestGPSCoordAccuracy());
}
void GPSTemporaryMarkers::stopPath()
{
recording_path = false;
}
void GPSTemporaryMarkers::clear()
{
points.clear();
paths.clear();
updateMapWidget();
}
void GPSTemporaryMarkers::paint(QPainter* painter)
{
painter->save();
widget->applyMapTransform(painter);
float scale_factor = 1.0f / widget->getMapView()->getZoom();
// Draw paths
painter->setBrush(Qt::NoBrush);
painter->setPen(QPen(QBrush(qRgb(255, 255, 255)), scale_factor * 0.3f));
for (const auto& path : paths)
painter->drawPolyline(path.data(), path.size());
painter->setPen(QPen(QBrush(MapEditorTool::active_color), scale_factor * 0.2f));
for (const auto& path : paths)
painter->drawPolyline(path.data(), path.size());
// Draw points
painter->setPen(Qt::NoPen);
painter->setBrush(QBrush(qRgb(255, 255, 255)));
float point_radius = scale_factor * 0.5f;
for (const auto& point : points)
painter->drawEllipse(point, point_radius, point_radius);
painter->setBrush(QBrush(MapEditorTool::inactive_color));
point_radius = scale_factor * 0.4f;
for (const auto& point : points)
painter->drawEllipse(point, point_radius, point_radius);
painter->restore();
}
void GPSTemporaryMarkers::newGPSPosition(const MapCoordF& coord, float accuracy)
{
Q_UNUSED(accuracy);
if (recording_path && ! paths.empty())
{
std::vector< QPointF >& path_coords = paths.back();
path_coords.push_back(coord);
updateMapWidget();
}
}
void GPSTemporaryMarkers::updateMapWidget()
{
// NOTE: could limit the updated area here
widget->update();
}
} // namespace OpenOrienteering