22 QgsQuickSimulatedPositionSource::QgsQuickSimulatedPositionSource( QObject *parent,
double longitude,
double latitude,
double flightRadius )
23 : QGeoPositionInfoSource( parent )
24 , mTimer( qgis::make_unique< QTimer >() )
25 , mFlightRadius( flightRadius )
26 , mLongitude( longitude )
27 , mLatitude( latitude )
29 connect( mTimer.get(), &QTimer::timeout,
this, &QgsQuickSimulatedPositionSource::readNextPosition );
32 void QgsQuickSimulatedPositionSource::startUpdates()
34 int interval = updateInterval();
35 if ( interval < minimumUpdateInterval() )
36 interval = minimumUpdateInterval();
38 mTimer->start( interval );
42 void QgsQuickSimulatedPositionSource::stopUpdates()
47 void QgsQuickSimulatedPositionSource::requestUpdate(
int )
54 void QgsQuickSimulatedPositionSource::readNextPosition()
56 if ( mFlightRadius <= 0 )
57 readConstantPosition();
62 void QgsQuickSimulatedPositionSource::readRandomPosition()
64 double latitude = mLatitude, longitude = mLongitude;
65 latitude += sin( mAngle * M_PI / 180 ) * mFlightRadius;
66 longitude += cos( mAngle * M_PI / 180 ) * mFlightRadius;
69 QGeoCoordinate coordinate( latitude, longitude );
70 double altitude = std::rand() % 40 + 20;
73 coordinate.setAltitude( altitude );
76 QDateTime timestamp = QDateTime::currentDateTime();
78 QGeoPositionInfo info( coordinate, timestamp );
82 info.setAttribute( QGeoPositionInfo::Direction, 360 -
int( mAngle ) % 360 );
83 int accuracy = std::rand() % 40 + 20;
88 info.setAttribute( QGeoPositionInfo::HorizontalAccuracy, accuracy );
89 emit positionUpdated( info );
93 void QgsQuickSimulatedPositionSource::readConstantPosition()
95 QGeoCoordinate coordinate( mLatitude, mLongitude );
96 coordinate.setAltitude( 20 );
97 QDateTime timestamp = QDateTime::currentDateTime();
98 QGeoPositionInfo info( coordinate, timestamp );
99 info.setAttribute( QGeoPositionInfo::Direction, 0 );
100 info.setAttribute( QGeoPositionInfo::HorizontalAccuracy, 20 );
101 emit positionUpdated( info );