Skip to content

Commit 851678a

Browse files
committed
Provide visual feedback tracking is replaying position
1 parent 86f8e13 commit 851678a

File tree

6 files changed

+62
-20
lines changed

6 files changed

+62
-20
lines changed

src/core/tracker.cpp

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -350,13 +350,6 @@ void Tracker::replayPositionInformationList( const QList<GnssPositionInformation
350350
{
351351
const qint64 startTime = QDateTime::currentMSecsSinceEpoch();
352352

353-
bool wasActive = false;
354-
if ( mIsActive )
355-
{
356-
wasActive = true;
357-
stop();
358-
}
359-
360353
mIsReplaying = true;
361354
emit isReplayingChanged();
362355

@@ -396,15 +389,27 @@ void Tracker::replayPositionInformationList( const QList<GnssPositionInformation
396389
mIsReplaying = false;
397390
emit isReplayingChanged();
398391

399-
if ( wasActive )
392+
if ( mIsSuspended )
400393
{
394+
mIsSuspended = false;
395+
emit isSuspendedChanged();
401396
start();
402397
}
403398

404399
const qint64 endTime = QDateTime::currentMSecsSinceEpoch();
405400
qInfo() << QStringLiteral( "Tracker position information replay duration: %1ms" ).arg( endTime - startTime );
406401
}
407402

403+
void Tracker::suspendUntilReplay()
404+
{
405+
if ( mIsActive )
406+
{
407+
mIsSuspended = true;
408+
emit isSuspendedChanged();
409+
stop();
410+
}
411+
}
412+
408413
void Tracker::rubberbandModelVertexCountChanged()
409414
{
410415
if ( ( !mIsActive && !mIsReplaying ) || mRubberbandModel->vertexCount() == 0 )

src/core/tracker.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ class Tracker : public QObject
3535
Q_OBJECT
3636

3737
Q_PROPERTY( bool isActive READ isActive NOTIFY isActiveChanged )
38+
Q_PROPERTY( bool isSuspended READ isSuspended NOTIFY isSuspendedChanged )
3839
Q_PROPERTY( bool isReplaying READ isReplaying NOTIFY isReplayingChanged )
3940

4041
Q_PROPERTY( bool visible READ visible WRITE setVisible NOTIFY visibleChanged )
@@ -134,6 +135,9 @@ class Tracker : public QObject
134135
//! Returns whether the tracker has been started
135136
bool isActive() const { return mIsActive; }
136137

138+
//! Returns whether the track has been suspended
139+
bool isSuspended() const { return mIsSuspended; }
140+
137141
//! Returns whether the tracker is replaying positions
138142
bool isReplaying() const { return mIsReplaying; }
139143

@@ -148,8 +152,11 @@ class Tracker : public QObject
148152
//! Replays a list of position information taking into account the tracker settings
149153
void replayPositionInformationList( const QList<GnssPositionInformation> &positionInformationList, QgsQuickCoordinateTransformer *coordinateTransformer = nullptr );
150154

155+
void suspendUntilReplay();
156+
151157
signals:
152158
void isActiveChanged();
159+
void isSuspendedChanged();
153160
void isReplayingChanged();
154161
void visibleChanged();
155162
void vectorLayerChanged();
@@ -177,6 +184,7 @@ class Tracker : public QObject
177184
void trackPosition();
178185

179186
bool mIsActive = false;
187+
bool mIsSuspended = false;
180188
bool mIsReplaying = false;
181189

182190
RubberbandModel *mRubberbandModel = nullptr;

src/core/trackingmodel.cpp

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,13 +169,25 @@ void TrackingModel::replayPositionInformationList( const QList<GnssPositionInfor
169169
for ( int i = 0; i < mTrackers.size(); i++ )
170170
{
171171
Tracker *tracker = mTrackers[i];
172-
if ( tracker->isActive() )
172+
if ( tracker->isSuspended() )
173173
{
174174
tracker->replayPositionInformationList( positionInformationList, coordinateTransformer );
175175
}
176176
}
177177
}
178178

179+
void TrackingModel::suspendUntilReplay()
180+
{
181+
for ( int i = 0; i < mTrackers.size(); i++ )
182+
{
183+
Tracker *tracker = mTrackers[i];
184+
if ( tracker->isActive() )
185+
{
186+
tracker->suspendUntilReplay();
187+
}
188+
}
189+
}
190+
179191
void TrackingModel::setTrackerVisibility( QgsVectorLayer *layer, bool visible )
180192
{
181193
if ( trackerIterator( layer ) != mTrackers.constEnd() )

src/core/trackingmodel.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,8 @@ class TrackingModel : public QAbstractItemModel
7171
//! Replays a list of position information for all active trackers
7272
Q_INVOKABLE void replayPositionInformationList( const QList<GnssPositionInformation> &positionInformationList, QgsQuickCoordinateTransformer *coordinateTransformer = nullptr );
7373

74+
Q_INVOKABLE void suspendUntilReplay();
75+
7476
void reset();
7577

7678
/**

src/qml/TrackingSession.qml

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,8 @@ Item {
2323
enabled: tracker.isActive
2424

2525
function onPositionInformationChanged() {
26-
if (!positionSource.backgroundMode) {
27-
featureModel.positionInformation = positionSource.positionInformation;
28-
tracker.processPositionInformation(positionSource.positionInformation, positionSource.projectedPosition);
29-
}
26+
featureModel.positionInformation = positionSource.positionInformation;
27+
tracker.processPositionInformation(positionSource.positionInformation, positionSource.projectedPosition);
3028
}
3129
}
3230

src/qml/qgismobileapp.qml

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -351,17 +351,34 @@ ApplicationWindow {
351351
}
352352

353353
onBackgroundModeChanged: {
354-
if (!backgroundMode) {
355-
mapCanvasMap.freeze('trackerreplay');
356-
let list = positionSource.getBackgroundPositionInformation();
357-
// Qt bug weirdly returns an empty list on first invokation to source, call twice to insure we've got the actual list
358-
list = positionSource.getBackgroundPositionInformation();
359-
trackingModel.replayPositionInformationList(list, coordinateTransformer);
360-
mapCanvasMap.unfreeze('trackerreplay');
354+
if (trackings.count > 0) {
355+
if (backgroundMode) {
356+
trackingModel.suspendUntilReplay();
357+
} else {
358+
busyOverlay.text = qsTr("Replaying collected positions, hold on");
359+
busyOverlay.state = "visible";
360+
replayTimer.restart();
361+
}
361362
}
362363
}
363364
}
364365

366+
Timer {
367+
id: replayTimer
368+
369+
interval: 250
370+
repeat: false
371+
onTriggered: {
372+
mapCanvasMap.freeze('trackerreplay');
373+
let list = positionSource.getBackgroundPositionInformation();
374+
// Qt bug weirdly returns an empty list on first invokation to source, call twice to insure we've got the actual list
375+
list = positionSource.getBackgroundPositionInformation();
376+
trackingModel.replayPositionInformationList(list, positionSource.coordinateTransformer);
377+
mapCanvasMap.unfreeze('trackerreplay');
378+
busyOverlay.state = "hidden";
379+
}
380+
}
381+
365382
PositioningSettings {
366383
id: positioningSettings
367384
objectName: "positioningSettings"

0 commit comments

Comments
 (0)