8#include "AutoNavigation.h"
10#include "MarbleQuickItem.h"
11#include "PositionTracking.h"
12#include "RenderPlugin.h"
18Tracking::Tracking(
QObject *parent)
21 , m_hasLastKnownPosition(false)
22 , m_positionMarkerType(
None)
24 connect(&m_lastKnownPosition, &Coordinate::longitudeChanged,
this, &Tracking::setHasLastKnownPosition);
25 connect(&m_lastKnownPosition, &Coordinate::latitudeChanged,
this, &Tracking::setHasLastKnownPosition);
28bool Tracking::showTrack()
const
33void Tracking::setShowTrack(
bool show)
35 if (show != m_showTrack) {
36 if (m_marbleQuickItem) {
37 m_marbleQuickItem->model()->positionTracking()->setTrackVisible(show);
38 m_marbleQuickItem->update();
42 Q_EMIT showTrackChanged();
46PositionSource *Tracking::positionSource()
48 return m_positionSource;
51void Tracking::setPositionSource(PositionSource *source)
53 if (source != m_positionSource) {
54 m_positionSource = source;
56 connect(source, SIGNAL(positionChanged()),
this, SLOT(updatePositionMarker()));
57 connect(source, SIGNAL(positionChanged()),
this, SLOT(updateLastKnownPosition()));
58 connect(source, SIGNAL(hasPositionChanged()),
this, SLOT(updatePositionMarker()));
59 connect(source, SIGNAL(positionChanged()),
this, SIGNAL(distanceChanged()));
61 Q_EMIT positionSourceChanged();
65MarbleQuickItem *Tracking::map()
67 return m_marbleQuickItem;
70void Tracking::setMap(MarbleQuickItem *item)
72 if (item != m_marbleQuickItem) {
73 m_marbleQuickItem = item;
75 if (m_marbleQuickItem) {
76 m_marbleQuickItem->model()->positionTracking()->setTrackVisible(showTrack());
77 setShowPositionMarkerPlugin(m_positionMarkerType == Arrow);
79 connect(m_marbleQuickItem, SIGNAL(visibleLatLonAltBoxChanged()),
this, SLOT(updatePositionMarker()));
80 connect(m_marbleQuickItem, SIGNAL(mapThemeChanged()),
this, SLOT(updatePositionMarker()));
87void Tracking::setPositionMarker(
QObject *marker)
89 if (marker != m_positionMarker) {
90 m_positionMarker = marker;
91 Q_EMIT positionMarkerChanged();
95QObject *Tracking::positionMarker()
97 return m_positionMarker;
100void Tracking::updatePositionMarker()
102 if (m_marbleQuickItem && m_positionMarker && m_positionMarkerType == Circle) {
104 bool visible = (m_marbleQuickItem->model()->planetId() ==
QLatin1StringView(
"earth"));
105 if (m_positionSource && m_positionSource->hasPosition()) {
106 position = m_positionSource->position();
107 }
else if (hasLastKnownPosition()) {
108 position = lastKnownPosition();
116 visible = visible && m_marbleQuickItem->map()->viewport()->screenCoordinates(pos.longitude(), pos.latitude(), x, y);
117 QQuickItem *item = qobject_cast<QQuickItem *>(m_positionMarker);
126 }
else if (m_positionMarkerType != Circle) {
127 QQuickItem *item = qobject_cast<QQuickItem *>(m_positionMarker);
134void Tracking::updateLastKnownPosition()
136 if (m_positionSource && m_positionSource->hasPosition()) {
137 setLastKnownPosition(m_positionSource->position());
141void Tracking::setHasLastKnownPosition()
143 if (!m_hasLastKnownPosition) {
144 m_hasLastKnownPosition =
true;
145 Q_EMIT hasLastKnownPositionChanged();
149void Tracking::setShowPositionMarkerPlugin(
bool visible)
151 if (m_marbleQuickItem) {
153 for (RenderPlugin *renderPlugin : renderPlugins) {
154 Q_ASSERT(renderPlugin);
156 renderPlugin->setEnabled(
true);
157 renderPlugin->setVisible(visible);
163bool Tracking::hasLastKnownPosition()
const
165 return m_hasLastKnownPosition;
170 return &m_lastKnownPosition;
173void Tracking::setLastKnownPosition(
Coordinate *lastKnownPosition)
175 if (lastKnownPosition && *lastKnownPosition != m_lastKnownPosition) {
176 m_lastKnownPosition.setCoordinates(lastKnownPosition->
coordinates());
177 Q_EMIT lastKnownPositionChanged();
181bool Tracking::autoCenter()
const
183 if (m_autoNavigation) {
184 return m_autoNavigation->recenterMode() != Marble::AutoNavigation::DontRecenter;
190void Tracking::setAutoCenter(
bool enabled)
192 if (autoCenter() != enabled) {
193 if (enabled && !m_autoNavigation && m_marbleQuickItem) {
194 m_autoNavigation =
new Marble::AutoNavigation(m_marbleQuickItem->model(), m_marbleQuickItem->map()->viewport(),
this);
197 connect(m_autoNavigation, SIGNAL(centerOn(GeoDataCoordinates,
bool)), m_marbleQuickItem, SLOT(centerOn(GeoDataCoordinates)));
199 connect(m_marbleQuickItem, SIGNAL(visibleLatLonAltBoxChanged()), m_autoNavigation, SLOT(inhibitAutoAdjustments()));
202 if (m_autoNavigation) {
203 m_autoNavigation->setRecenter(Marble::AutoNavigation::RecenterOnBorder);
206 Q_EMIT autoCenterChanged();
210bool Tracking::autoZoom()
const
212 if (m_autoNavigation) {
213 return m_autoNavigation->autoZoom();
219void Tracking::setAutoZoom(
bool enabled)
221 if (autoZoom() != enabled) {
222 if (enabled && !m_autoNavigation && m_marbleQuickItem) {
223 m_autoNavigation =
new Marble::AutoNavigation(m_marbleQuickItem->model(), m_marbleQuickItem->map()->viewport(),
this);
226 connect(m_autoNavigation, SIGNAL(centerOn(GeoDataCoordinates,
bool)), m_marbleQuickItem, SLOT(centerOn(GeoDataCoordinates)));
228 connect(m_marbleQuickItem, SIGNAL(visibleLatLonAltBoxChanged()), m_autoNavigation, SLOT(inhibitAutoAdjustments()));
231 if (m_autoNavigation) {
232 m_autoNavigation->setAutoZoom(enabled);
235 Q_EMIT autoZoomChanged();
239Tracking::PositionMarkerType Tracking::positionMarkerType()
const
241 return m_positionMarkerType;
244void Tracking::setPositionMarkerType(Tracking::PositionMarkerType type)
246 setShowPositionMarkerPlugin(type == Arrow);
247 if (type != m_positionMarkerType) {
248 m_positionMarkerType =
type;
249 Q_EMIT positionMarkerTypeChanged();
253double Tracking::distance()
const
255 return m_marbleQuickItem ? m_marbleQuickItem->model()->positionTracking()->length(m_marbleQuickItem->model()->planetRadius()) : 0.0;
258void Tracking::saveTrack(
const QString &fileName)
260 if (m_marbleQuickItem) {
263 m_marbleQuickItem->model()->positionTracking()->saveTrack(target);
267void Tracking::openTrack(
const QString &fileName)
269 if (m_marbleQuickItem) {
272 m_marbleQuickItem->model()->addGeoDataFile(target);
276void Tracking::clearTrack()
278 if (m_marbleQuickItem) {
279 m_marbleQuickItem->model()->positionTracking()->clearTrack();
285#include "moc_Tracking.cpp"
This file contains the headers for MarbleModel.
This file contains the headers for ViewportParams.
Represents a coordinate with the properties of a name and coordinates.
Marble::GeoDataCoordinates coordinates() const
Change the altitude of the coordinate.
A 3d point representation.
VehicleSection::Type type(QStringView coachNumber, QStringView coachClassification)
QAction * zoomIn(const QObject *recvr, const char *slot, QObject *parent)
QAction * zoomOut(const QObject *recvr, const char *slot, QObject *parent)
Binds a QML item to a specific geodetic location in screen coordinates.
QString mid(qsizetype position, qsizetype n) const const
bool startsWith(QChar c, Qt::CaseSensitivity cs) const const
QFuture< ArgsType< Signal > > connect(Sender *sender, Signal signal)