18 _resumeTimer.setSingleShot(
true);
19 _resumeTimer.setInterval(kResumeDelayMs);
20 connect(&_resumeTimer, &QTimer::timeout,
this, &MapPositionTracker::_resumeFollowing);
32 if (!_evaluateVehicleOneShot()) {
33 _evaluateGCSOneShot();
40 if (_gcsPosition == position) {
43 _gcsPosition = position;
45 _evaluateGCSOneShot();
50 if (_vehicleCoordinate == coordinate) {
53 _vehicleCoordinate = coordinate;
55 if (_evaluateVehicleOneShot()) {
59 if (_active && _keepVehicleCentered && _vehicleCoordinate.isValid() && !_paused()) {
60 emit
centerMap(_vehicleCoordinate,
false);
66 if (_allowGCSLocationCenter == allow) {
69 _allowGCSLocationCenter = allow;
73 _evaluateGCSOneShot();
79 if (_allowVehicleLocationCenter == allow) {
82 _allowVehicleLocationCenter = allow;
86 _evaluateVehicleOneShot();
92 if (_centerGCSWhenVehicleValid == center) {
95 _centerGCSWhenVehicleValid = center;
101 if (_keepVehicleCentered == keep) {
104 _keepVehicleCentered = keep;
110 if (_userInteracting == interacting) {
113 _userInteracting = interacting;
115 if (_userInteracting) {
117 qCDebug(MapPositionTrackerLog) <<
"user interaction started, following paused";
119 _resumeTimer.start();
134 if (_firstVehiclePositionReceived == received) {
137 _firstVehiclePositionReceived = received;
141bool MapPositionTracker::_evaluateVehicleOneShot()
143 if (!_active || _firstVehiclePositionReceived || !_allowVehicleLocationCenter || !_vehicleCoordinate.isValid()) {
147 qCDebug(MapPositionTrackerLog) <<
"centering on first vehicle position";
148 emit
centerMap(_vehicleCoordinate,
true);
152void MapPositionTracker::_evaluateGCSOneShot()
154 if (!_active || _firstGCSPositionReceived || _firstVehiclePositionReceived || !_allowGCSLocationCenter ||
155 !_gcsPosition.isValid()) {
160 _firstGCSPositionReceived =
true;
163 if (_keepVehicleCentered || _centerGCSWhenVehicleValid || !_vehicleCoordinate.isValid()) {
164 qCDebug(MapPositionTrackerLog) <<
"centering on first GCS position";
169void MapPositionTracker::_resumeFollowing()
171 qCDebug(MapPositionTrackerLog) <<
"following resumed after user interaction";
172 if (_active && _keepVehicleCentered && _vehicleCoordinate.isValid()) {
173 emit
centerMap(_vehicleCoordinate,
false);
179 const QVariantList& cornerRects)
181 if (!_active || _keepVehicleCentered || !_firstVehiclePositionReceived || !_vehicleCoordinate.isValid() ||
182 _paused() || _animating) {
185 bool recenterNeeded = !centerRect.contains(vehicleScreenPoint);
186 if (!recenterNeeded) {
188 for (
const QVariant& rect : cornerRects) {
189 if (rect.toRectF().contains(vehicleScreenPoint)) {
190 recenterNeeded =
true;
195 if (recenterNeeded) {
#define QGC_LOGGING_CATEGORY(name, categoryStr)
void setFirstVehiclePositionReceived(bool received)
void setAllowVehicleLocationCenter(bool allow)
bool animating() const
Consumer's recenter animation is running: inset evaluation is skipped.
void setVehicleCoordinate(const QGeoCoordinate &coordinate)
void setActive(bool active)
void gcsPositionChanged()
void setUserInteracting(bool interacting)
Q_INVOKABLE void evaluateInsetFollow(const QPointF &vehicleScreenPoint, const QRectF ¢erRect, const QVariantList &cornerRects)
void keepVehicleCenteredChanged()
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)
void firstVehiclePositionReceivedChanged()
void allowVehicleLocationCenterChanged()
void setKeepVehicleCentered(bool keep)
void setAnimating(bool animating)
void vehicleCoordinateChanged()
void centerMap(const QGeoCoordinate &coordinate, bool firstPosition)
void centerGCSWhenVehicleValidChanged()
void allowGCSLocationCenterChanged()