QGroundControl
Ground Control Station for MAVLink Drones
Loading...
Searching...
No Matches
MapPositionTracker.h
Go to the documentation of this file.
1/****************************************************************************
2 *
3 * (c) 2009-2024 QGROUNDCONTROL PROJECT <http://www.qgroundcontrol.org>
4 *
5 * QGroundControl is licensed according to the terms in the file
6 * COPYING.md in the root of the source code directory.
7 *
8 ****************************************************************************/
9
10#pragma once
11
12#include <QtCore/QLoggingCategory>
13#include <QtCore/QObject>
14#include <QtCore/QPointF>
15#include <QtCore/QRectF>
16#include <QtCore/QTimer>
17#include <QtCore/QVariantList>
18#include <QtPositioning/QGeoCoordinate>
19#include <QtQmlIntegration/QtQmlIntegration>
20
21Q_DECLARE_LOGGING_CATEGORY(MapPositionTrackerLog)
22
23
32class MapPositionTracker : public QObject
33{
34 Q_OBJECT
35 QML_ELEMENT
36 Q_PROPERTY(bool active READ active WRITE setActive NOTIFY activeChanged)
37 Q_PROPERTY(QGeoCoordinate gcsPosition READ gcsPosition WRITE setGcsPosition NOTIFY gcsPositionChanged)
38 Q_PROPERTY(QGeoCoordinate vehicleCoordinate READ vehicleCoordinate WRITE setVehicleCoordinate NOTIFY
46 Q_PROPERTY(bool keepVehicleCentered READ keepVehicleCentered WRITE setKeepVehicleCentered NOTIFY
49 Q_PROPERTY(bool animating READ animating WRITE setAnimating NOTIFY animatingChanged)
52
53public:
54 explicit MapPositionTracker(QObject* parent = nullptr);
55
57 static constexpr int kResumeDelayMs = 10000;
58
59 bool active() const { return _active; }
60
61 void setActive(bool active);
62
63 QGeoCoordinate gcsPosition() const { return _gcsPosition; }
64
65 void setGcsPosition(const QGeoCoordinate& position);
66
67 QGeoCoordinate vehicleCoordinate() const { return _vehicleCoordinate; }
68
69 void setVehicleCoordinate(const QGeoCoordinate& coordinate);
70
71 bool allowGCSLocationCenter() const { return _allowGCSLocationCenter; }
72
73 void setAllowGCSLocationCenter(bool allow);
74
75 bool allowVehicleLocationCenter() const { return _allowVehicleLocationCenter; }
76
77 void setAllowVehicleLocationCenter(bool allow);
78
82 bool centerGCSWhenVehicleValid() const { return _centerGCSWhenVehicleValid; }
83
84 void setCenterGCSWhenVehicleValid(bool center);
85
86 bool keepVehicleCentered() const { return _keepVehicleCentered; }
87
88 void setKeepVehicleCentered(bool keep);
89
90 bool userInteracting() const { return _userInteracting; }
91
92 void setUserInteracting(bool interacting);
93
95 bool animating() const { return _animating; }
96
97 void setAnimating(bool animating);
98
101 bool firstVehiclePositionReceived() const { return _firstVehiclePositionReceived; }
102
103 void setFirstVehiclePositionReceived(bool received);
104
110 Q_INVOKABLE void evaluateOccluderFollow(const QPointF& vehicleScreenPoint, const QRectF& viewportRect,
111 const QVariantList& occluderRects);
112
113#ifdef QGC_UNITTEST_BUILD
114 void setResumeDelayMsForTest(int ms) { _resumeTimer.setInterval(ms); }
115#endif
116
117signals:
120 void centerMap(const QGeoCoordinate& coordinate, bool firstPosition);
122 void recenterVehicleTo(const QPointF& screenPoint);
123
134
135private:
136 bool _paused() const { return _userInteracting || _resumeTimer.isActive(); }
137
139 bool _evaluateVehicleOneShot();
140 void _evaluateGCSOneShot();
141 void _resumeFollowing();
142
143 bool _active = true;
144 QGeoCoordinate _gcsPosition;
145 QGeoCoordinate _vehicleCoordinate;
146 bool _allowGCSLocationCenter = false;
147 bool _allowVehicleLocationCenter = false;
148 bool _centerGCSWhenVehicleValid = false;
149 bool _keepVehicleCentered = false;
150 bool _userInteracting = false;
151 bool _animating = false;
152 bool _firstVehiclePositionReceived = false;
153 bool _firstGCSPositionReceived = false;
154 QTimer _resumeTimer;
155};
bool firstVehiclePositionReceived() const
void setFirstVehiclePositionReceived(bool received)
void setAllowVehicleLocationCenter(bool allow)
bool centerGCSWhenVehicleValid() const
static constexpr int kResumeDelayMs
Following resumes this long after the user stops interacting.
QGeoCoordinate vehicleCoordinate() const
bool animating() const
Consumer's recenter animation is running: occluder evaluation is skipped.
void setVehicleCoordinate(const QGeoCoordinate &coordinate)
void setActive(bool active)
void setUserInteracting(bool interacting)
void keepVehicleCenteredChanged()
bool keepVehicleCentered() const
MapPositionTracker(QObject *parent=nullptr)
QGeoCoordinate gcsPosition() const
void userInteractingChanged()
void setCenterGCSWhenVehicleValid(bool center)
void setAllowGCSLocationCenter(bool allow)
void recenterVehicleTo(const QPointF &screenPoint)
Consumer moves the map (animated) so the vehicle lands at screenPoint.
void setGcsPosition(const QGeoCoordinate &position)
bool userInteracting() const
void firstVehiclePositionReceivedChanged()
void allowVehicleLocationCenterChanged()
void setKeepVehicleCentered(bool keep)
void setAnimating(bool animating)
bool allowGCSLocationCenter() const
bool allowVehicleLocationCenter() const
void vehicleCoordinateChanged()
void centerMap(const QGeoCoordinate &coordinate, bool firstPosition)
void centerGCSWhenVehicleValidChanged()
void allowGCSLocationCenterChanged()