[map] return the ElevationInfo for the current track recording

Signed-off-by: Kiryl Kaveryn <kirylkaveryn@gmail.com>
This commit is contained in:
Kiryl Kaveryn 2025-01-09 14:18:22 +04:00 committed by Roman Tsisyk
parent 40e1e63315
commit c96d873fa8
8 changed files with 44 additions and 1 deletions

View file

@ -1739,6 +1739,11 @@ void Framework::SetTrackRecordingUpdateHandler(TrackRecordingUpdateHandler && tr
m_trackRecordingUpdateHandler(GpsTracker::Instance().GetTrackStatistics());
}
const ElevationInfo & Framework::GetTrackRecordingElevationInfo()
{
return GpsTracker::Instance().GetElevationInfo();
}
void Framework::StopTrackRecording()
{
m_connectToGpsTrack = false;

View file

@ -444,6 +444,9 @@ public:
void SaveTrackRecordingWithName(std::string const & name);
bool IsTrackRecordingEmpty() const;
bool IsTrackRecordingEnabled() const;
/// Returns the elevation profile data of the currently recorded track.
/// To get the data on the every track recording state update, this function should be called after receiving the callback from the `SetTrackRecordingUpdateHandler`.
static const ElevationInfo & GetTrackRecordingElevationInfo();
void SetMapStyle(MapStyle mapStyle);
void MarkMapStyle(MapStyle mapStyle);

View file

@ -84,6 +84,11 @@ TrackStatistics GpsTrack::GetTrackStatistics() const
return m_collection ? m_collection->GetTrackStatistics() : TrackStatistics();
}
const ElevationInfo & GpsTrack::GetElevationInfo() const
{
return m_collection->UpdateAndGetElevationInfo();
}
void GpsTrack::Clear()
{
{

View file

@ -32,7 +32,8 @@ public:
/// Returns track statistics
TrackStatistics GetTrackStatistics() const;
const ElevationInfo & GetElevationInfo() const;
/// Clears any previous tracking info
/// @note Callback is called with 'toRemove' points, if some points were removed.
void Clear();

View file

@ -33,6 +33,7 @@ size_t const GpsTrackCollection::kInvalidId = std::numeric_limits<size_t>::max()
GpsTrackCollection::GpsTrackCollection()
: m_lastId(0)
, m_elevationInfoDirty(true)
{}
std::pair<size_t, size_t> GpsTrackCollection::Add(std::vector<TItem> const & items)
@ -54,6 +55,8 @@ std::pair<size_t, size_t> GpsTrackCollection::Add(std::vector<TItem> const & ite
++added;
}
m_elevationInfoDirty = true;
rollbacker.Reset();
if (0 == added)
@ -85,6 +88,7 @@ std::pair<size_t, size_t> GpsTrackCollection::Clear(bool resetIds)
m_items.clear();
m_items.shrink_to_fit();
m_statistics = {};
m_elevationInfo = {};
if (resetIds)
m_lastId = 0;
@ -97,6 +101,21 @@ size_t GpsTrackCollection::GetSize() const
return m_items.size();
}
const ElevationInfo & GpsTrackCollection::UpdateAndGetElevationInfo()
{
if (!m_elevationInfoDirty)
return m_elevationInfo;
auto const elevationInfoSize = m_elevationInfo.GetSize();
if (elevationInfoSize < m_items.size())
{
std::vector<TItem> const missedPoints(m_items.begin() + elevationInfoSize, m_items.end());
m_elevationInfo.AddGpsPoints(missedPoints);
}
m_elevationInfoDirty = false;
return m_elevationInfo;
}
bool GpsTrackCollection::IsEmpty() const
{
return m_items.empty();

View file

@ -41,6 +41,8 @@ public:
/// Returns track statistics.
const TrackStatistics GetTrackStatistics() const { return m_statistics; }
/// Updates the elevation info with the missed points and returns a reference.
const ElevationInfo & UpdateAndGetElevationInfo();
/// Enumerates items in the collection.
/// @param f - callable object, which is called with params - item and item id,
@ -67,4 +69,6 @@ private:
size_t m_lastId;
TrackStatistics m_statistics;
ElevationInfo m_elevationInfo;
bool m_elevationInfoDirty;
};

View file

@ -85,6 +85,11 @@ TrackStatistics GpsTracker::GetTrackStatistics() const
return m_track.GetTrackStatistics();
}
const ElevationInfo & GpsTracker::GetElevationInfo() const
{
return m_track.GetElevationInfo();
}
void GpsTracker::Connect(TGpsTrackDiffCallback const & fn)
{
m_track.SetCallback(fn);

View file

@ -19,6 +19,7 @@ public:
bool IsEmpty() const;
size_t GetTrackSize() const;
TrackStatistics GetTrackStatistics() const;
const ElevationInfo & GetElevationInfo() const;
using TGpsTrackDiffCallback =
std::function<void(std::vector<std::pair<size_t, location::GpsInfo>> && toAdd,