MCPcopy Create free account
hub / github.com/OpenOrienteering/mapper / enableGPSDisplay

Method enableGPSDisplay

src/gui/map/map_editor.cpp:3537–3622  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

3535
3536
3537void MapEditorController::enableGPSDisplay(bool enable)
3538{
3539 if (enable)
3540 {
3541 gps_display->startUpdates();
3542
3543 // Create gps_track_recorder if we can determine a template track filename
3544 constexpr int gps_track_draw_update_interval = 10 * 1000; // in milliseconds
3545 if (! window->currentPath().isEmpty())
3546 {
3547 // Find or create a template for the track with a specific name
3548 QString gpx_file_path =
3549 QFileInfo(window->currentPath()).absoluteDir().canonicalPath()
3550 + QLatin1Char('/')
3551 + QFileInfo(window->currentPath()).completeBaseName()
3552 + QLatin1String(" - GPS-")
3553 + QDate::currentDate().toString(Qt::ISODate)
3554 + QLatin1String(".gpx");
3555
3556 bool new_template = true; // Indicates that we really add a new template.
3557 TemplateTrack* track = nullptr;
3558 int template_index = 0;
3559 for ( ; template_index < map->getNumTemplates(); ++template_index)
3560 {
3561 auto* temp = map->getTemplate(template_index);
3562 if (temp->getTemplatePath() == gpx_file_path)
3563 {
3564 // There is a template for this track.
3565 new_template = false;
3566 track = qobject_cast<TemplateTrack*>(temp);
3567 break;
3568 }
3569 }
3570
3571 // Derive new visibility from previous/default one.
3572 auto visibility = main_view->getTemplateVisibility(track);
3573 visibility.opacity = std::max(0.5, visibility.opacity);
3574 visibility.visible = true;
3575
3576 if (!track)
3577 {
3578 if (!new_template)
3579 {
3580 // Need to replace the template at template_index
3581 map->deleteTemplate(template_index);
3582 }
3583 track = new TemplateTrack(gpx_file_path, map);
3584 // This will set the state to 'Loaded', so we need to reset it
3585 // to `Unloaded` to allow for loading the file when it becomes
3586 // visible for the first time.
3587 track->configureForGPSTrack();
3588 if (QFileInfo::exists(gpx_file_path))
3589 {
3590 track->unloadTemplateFile();
3591 track->loadTemplateFile();
3592 }
3593 map->addTemplate(template_index, std::unique_ptr<Template>{track});
3594 // When the map is saved, the new track must be saved even if it is empty.

Callers

nothing calls this directly

Calls 15

QLatin1StringClass · 0.85
existsFunction · 0.85
getNumTemplatesMethod · 0.80
getTemplateVisibilityMethod · 0.80
configureForGPSTrackMethod · 0.80
unloadTemplateFileMethod · 0.80
loadTemplateFileMethod · 0.80
addTemplateMethod · 0.80
setTemplateVisibilityMethod · 0.80
stopPathMethod · 0.80
QFileInfoClass · 0.50
startUpdatesMethod · 0.45

Tested by

no test coverage detected