Skip to content

Commit

Permalink
the provider should not allocate for the consumer
Browse files Browse the repository at this point in the history
  • Loading branch information
janbar committed Sep 27, 2024
1 parent 4fa1b97 commit 8698e6b
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 10 deletions.
18 changes: 10 additions & 8 deletions src/gpxfilemodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,24 +59,24 @@ QString GPXFile::description() const
return QString::fromUtf8(m_gpx.desc.value_or("").c_str());
}

QList<GPXObject*> GPXFile::tracks() const
QList<GPXObjectTrack> GPXFile::tracks() const
{
int i = 0;
QList<GPXObject*> list;
QList<GPXObjectTrack> list;
for (const osmscout::gpx::Track& track : m_gpx.tracks)
{
list << new GPXObjectTrack(track, ++i);
list << GPXObjectTrack(track, ++i);
}
return list;
}

QList<GPXObject*> GPXFile::waypoints() const
QList<GPXObjectWayPoint> GPXFile::waypoints() const
{
int i = 0;
QList<GPXObject*> list;
QList<GPXObjectWayPoint> list;
for (const osmscout::gpx::Waypoint& waypoint : m_gpx.waypoints)
{
list << new GPXObjectWayPoint(waypoint, ++i);
list << GPXObjectWayPoint(waypoint, ++i);
}
return list;
}
Expand Down Expand Up @@ -259,8 +259,10 @@ bool GPXFileModel::loadData()
if ((ret = (m_file && m_file->isValid())))
{
QList<GPXObject*> data;
data.append(m_file->tracks());
data.append(m_file->waypoints());
for (GPXObjectTrack& t : m_file->tracks())
data.append(new GPXObjectTrack(t));
for (GPXObjectWayPoint& w : m_file->waypoints())
data.append(new GPXObjectWayPoint(w));
beginInsertRows(QModelIndex(), 0, data.count()-1);
for (GPXObject* item : data)
{
Expand Down
6 changes: 4 additions & 2 deletions src/gpxfilemodel.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ class GPXFile

QString name() const;
QString description() const;
QList<GPXObject*> tracks() const;
QList<GPXObject*> waypoints() const;
QList<GPXObjectTrack> tracks() const;
QList<GPXObjectWayPoint> waypoints() const;

private:
bool m_valid;
Expand Down Expand Up @@ -64,6 +64,7 @@ class GPXObjectTrack : public GPXObject
{
public:
GPXObjectTrack(const osmscout::gpx::Track& track, int id) : m_track(track), m_id(id) { }
explicit GPXObjectTrack(const GPXObjectTrack& other) : m_track(other.m_track), m_id(other.m_id) { }
int id() const override { return m_id; }
ObjectType type() const override { return Track; }
QString name() const override { return QString::fromUtf8(m_track.name.value_or(std::to_string(m_id)).c_str()); }
Expand All @@ -81,6 +82,7 @@ class GPXObjectWayPoint : public GPXObject
{
public:
GPXObjectWayPoint(const osmscout::gpx::Waypoint& waipoint, int id) : m_waypoint(waipoint), m_id(id) { }
explicit GPXObjectWayPoint(const GPXObjectWayPoint& other) : m_waypoint(other.m_waypoint), m_id(other.m_id) { }
int id() const override { return m_id; }
ObjectType type() const override { return WayPoint; }
QString name() const override { return QString::fromUtf8(m_waypoint.name.value_or(std::to_string(m_id)).c_str()); }
Expand Down

0 comments on commit 8698e6b

Please sign in to comment.