• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

MerginMaps / input / 3692586550

pending completion
3692586550

push

github

Unknown Committer
Unknown Commit Message

7695 of 12291 relevant lines covered (62.61%)

109.94 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

96.05
/app/position/simulatedpositionprovider.cpp
1
/***************************************************************************
2
 *                                                                         *
3
 *   This program is free software; you can redistribute it and/or modify  *
4
 *   it under the terms of the GNU General Public License as published by  *
5
 *   the Free Software Foundation; either version 2 of the License, or     *
6
 *   (at your option) any later version.                                   *
7
 *                                                                         *
8
 ***************************************************************************/
9

10
#include "simulatedpositionprovider.h"
11
#include "qgspoint.h"
12

13
SimulatedPositionProvider::SimulatedPositionProvider( double longitude, double latitude, double flightRadius, double timerTimeout, QObject *parent )
66✔
14
  : AbstractPositionProvider( QStringLiteral( "simulated" ), QStringLiteral( "internal" ), QStringLiteral( "Simulated provider" ), parent )
22✔
15
  , mTimer( new QTimer() )
22✔
16
  , mLongitude( longitude )
22✔
17
  , mLatitude( latitude )
22✔
18
  , mFlightRadius( flightRadius )
22✔
19
  , mTimerTimeout( timerTimeout )
22✔
20
{
66✔
21
  std::random_device seed;
22✔
22
  mGenerator = std::unique_ptr<std::mt19937>( new std::mt19937( seed() ) );
22✔
23

24
  connect( mTimer.get(), &QTimer::timeout, this, &SimulatedPositionProvider::generateNextPosition );
22✔
25

26
  SimulatedPositionProvider::startUpdates();
22✔
27
}
44✔
28

29
SimulatedPositionProvider::~SimulatedPositionProvider() = default;
66✔
30

31
void SimulatedPositionProvider::startUpdates()
27✔
32
{
33
  mTimer->start( mTimerTimeout );
27✔
34
  generateNextPosition();
27✔
35
}
27✔
36

37
void SimulatedPositionProvider::stopUpdates()
6✔
38
{
39
  mTimer->stop();
6✔
40
}
6✔
41

42
void SimulatedPositionProvider::closeProvider()
4✔
43
{
44
  mTimer->stop();
4✔
45
}
4✔
46

47
void SimulatedPositionProvider::setPosition( QgsPoint position )
5✔
48
{
49
  if ( position.isEmpty() )
5✔
50
    return;
×
51

52
  stopUpdates();
5✔
53
  mLatitude = position.y();
5✔
54
  mLongitude = position.x();
5✔
55
  generateConstantPosition();
5✔
56
}
5✔
57

58
void SimulatedPositionProvider::generateNextPosition()
155✔
59
{
60
  setState( tr( "Connected" ), State::Connected );
177✔
61

62
  if ( mFlightRadius <= 0 )
155✔
63
    generateConstantPosition();
153✔
64
  else
65
    generateRadiusPosition();
2✔
66
}
155✔
67

68
void SimulatedPositionProvider::generateRadiusPosition()
2✔
69
{
70
  double latitude = mLatitude, longitude = mLongitude;
2✔
71
  latitude += sin( mAngle * M_PI / 180 ) * mFlightRadius;
2✔
72
  longitude += cos( mAngle * M_PI / 180 ) * mFlightRadius;
2✔
73
  mAngle += 1;
2✔
74

75
  GeoPosition position;
2✔
76

77
  position.latitude = latitude;
2✔
78
  position.longitude = longitude;
2✔
79

80
  double altitude = ( *mGenerator )() % 40 + 20; // rand altitude <20,55>m and lost (0)
2✔
81
  if ( altitude <= 55 )
2✔
82
  {
83
    position.elevation = altitude;
2✔
84
  }
2✔
85

86
  QDateTime timestamp = QDateTime::currentDateTime();
2✔
87
  position.utcDateTime = timestamp;
2✔
88

89
  position.direction = 360 - int( mAngle ) % 360;
2✔
90

91
  int accuracy = ( *mGenerator )() % 40; // rand accuracy <0,35>m and lost (-1)
2✔
92
  if ( accuracy > 35 )
2✔
93
  {
94
    accuracy = -1;
×
95
  }
×
96
  position.hacc = accuracy;
2✔
97

98
  position.satellitesUsed = ( *mGenerator )() % 30;
2✔
99
  position.satellitesVisible = ( *mGenerator )() % 30;
2✔
100

101
  position.speed = ( *mGenerator )() % 50 - ( ( ( *mGenerator )() % 10 ) / 10. ); // e.g. 45 - 3 / 10 = 44.7 (km/h)
2✔
102

103
  emit positionChanged( position );
2✔
104
}
2✔
105

106
void SimulatedPositionProvider::generateConstantPosition()
158✔
107
{
108
  GeoPosition position;
158✔
109
  position.latitude = mLatitude;
158✔
110
  position.longitude = mLongitude;
158✔
111
  position.elevation = 20;
158✔
112
  position.utcDateTime = QDateTime::currentDateTime();
158✔
113
  position.direction = 360 - int( mAngle ) % 360;
158✔
114
  position.hacc = ( *mGenerator )() % 20;
158✔
115
  position.satellitesUsed = ( *mGenerator )() % 30;
158✔
116
  position.satellitesVisible = ( *mGenerator )() % 30;
158✔
117
  position.speed = ( *mGenerator )() % 50 - ( ( ( *mGenerator )() % 10 ) / 10. );
158✔
118

119
  emit positionChanged( position );
158✔
120
}
158✔
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc