Skip to content

Commit

Permalink
bugfixes
Browse files Browse the repository at this point in the history
  • Loading branch information
t-weber committed Jan 4, 2025
1 parent 0c1b533 commit cb6fb3e
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 8 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ Fully local calculation and visualisation of running 🏃 tracks.
- No remote collection or transmission of data.
- No AI!

Version 0.1.
Version 0.2.
12 changes: 7 additions & 5 deletions src/gui/docks/track_browser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -182,17 +182,16 @@ t_size TrackBrowser::GetCurrentTrackIndex() const

t_size TrackBrowser::GetTrackIndex(int row) const
{
const t_size invalid = std::numeric_limits<t_size>::max();
if(!m_list || row < 0)
return invalid;
return m_invalid_idx;

QListWidgetItem *item = m_list->item(row);
if(!item)
return invalid;
return m_invalid_idx;

QVariant val = item->data(TRACK_IDX);
if(!val.isValid())
return invalid;
return m_invalid_idx;

return val.value<t_size>();
}
Expand Down Expand Up @@ -262,7 +261,7 @@ void TrackBrowser::DeleteSelectedTracks()
for(int row = start_row; row < m_list->count(); ++row)
{
t_size idx = GetTrackIndex(row);
if(idx <= deleted_idx)
if(idx <= deleted_idx || idx == m_invalid_idx)
continue;
SetTrackIndex(row, idx - 1);
}
Expand All @@ -275,6 +274,9 @@ void TrackBrowser::DeleteSelectedTracks()

int row = m_list->row(item);
t_size idx = GetTrackIndex(row);
if(idx == m_invalid_idx)
continue;

decrease_indices(row, idx);

emit TrackDeleted(idx);
Expand Down
3 changes: 3 additions & 0 deletions src/gui/docks/track_browser.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@ class TrackBrowser : public QWidget
private:
std::shared_ptr<QListWidget> m_list{};

// an index considered invalid
static constexpr t_size m_invalid_idx = std::numeric_limits<t_size>::max();


signals:
void NewTrackSelected(t_size idx);
Expand Down
23 changes: 21 additions & 2 deletions src/gui/docks/track_infos.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ TrackInfos::TrackInfos(QWidget* parent) : QWidget{parent}
m_map_context->addAction(actionSaveSvg);

m_mapfile = std::make_shared<QLineEdit>(map_panel);
m_mapfile->setPlaceholderText("Directory with Map Files (.osm or .osm.pbf)");
m_mapfile->setPlaceholderText("Directory with Map Files (.osm.pbf)");
m_mapfile->setToolTip("Directory containing map files.");

QPushButton *btn_browse_map = new QPushButton(map_panel);
Expand Down Expand Up @@ -611,7 +611,10 @@ void TrackInfos::PlotMap(bool load_cached)
m_map->load(m_map_image);

if(m_mapfile->text() == "")
{
emit StatusMessageChanged("No source maps available. Please specify a map directory with .osm.pbf files.");
return;
}

t_real lon_range = m_max_long_plot - m_min_long_plot;
t_real lat_range = m_max_lat_plot - m_min_lat_plot;
Expand Down Expand Up @@ -685,11 +688,19 @@ void TrackInfos::PlotMap(bool load_cached)
static_cast<t_real_map>(m_max_lat_plot + lat_range*g_map_overdraw),
&progress);

if(cached_map_name)
if(map_loaded && cached_map_name)
{
// cache generated map
map.Save(*cached_map_name);
}

if(!map_loaded)
{
progress_dlg.cancel();
QMessageBox::critical(this, "Error",
"No suitable source maps could be found. "
"Please provide .osm.pbf files.");
}
}

if(map_loaded)
Expand All @@ -707,6 +718,14 @@ void TrackInfos::PlotMap(bool load_cached)
m_map->load(m_map_image);
}

if(map_loaded)
emit StatusMessageChanged("Map successfully loaded.");
else if(!load_cached)
emit StatusMessageChanged("Error: No map could be generated.");
else
emit StatusMessageChanged("No map available for this track.");


/*MapPlotter map;
if(map.Import(m_mapfile->text().toStdString(),
m_min_long_plot, m_max_long_plot,
Expand Down

0 comments on commit cb6fb3e

Please sign in to comment.