change type

This commit is contained in:
vcoppe
2026-10-03 11:49:10 +02:00
parent dbe894b3a3
commit 87d6d5f30e
2 changed files with 42 additions and 50 deletions
+20 -13
View File
@@ -43,28 +43,32 @@ impl StatisticsCache {
if let Some(state) = state {
match selection {
Selection::Empty => (),
Selection::File(s) => {
for id in s.files.iter() {
Selection::File { file_ids } => {
for id in file_ids.iter() {
if let Some(file) = state.get(id) {
self.add_file_stats(file, &mut stats);
}
}
}
Selection::Track(s) => {
if let Some(file) = state.get(&s.file) {
Selection::Track { file_id, trk_ids } => {
if let Some(file) = state.get(file_id) {
for trk in file.trk.iter() {
if s.trk.contains(&trk.id) {
if trk_ids.contains(&trk.id) {
self.add_track_stats(trk, &mut stats);
}
}
}
}
Selection::TrackSegment(s) => {
if let Some(file) = state.get(&s.file) {
Selection::TrackSegment {
file_id,
trk_id,
trkseg_ids,
} => {
if let Some(file) = state.get(file_id) {
for trk in file.trk.iter() {
if s.trk == trk.id {
if *trk_id == trk.id {
for trkseg in trk.trkseg.iter() {
if s.trkseg.contains(&trkseg.id) {
if trkseg_ids.contains(&trkseg.id) {
self.add_segment_stats(trkseg, &mut stats);
}
}
@@ -73,13 +77,16 @@ impl StatisticsCache {
}
}
}
Selection::Waypoints(s) => {
if let Some(file) = state.get(&s.file) {
Selection::Waypoints { file_id } => {
if let Some(file) = state.get(file_id) {
self.add_file_stats(file, &mut stats);
}
}
Selection::Waypoint(s) => {
if let Some(file) = state.get(&s.file) {
Selection::Waypoint {
file_id,
wpt_ids: _,
} => {
if let Some(file) = state.get(file_id) {
self.add_file_stats(file, &mut stats);
}
}
+22 -37
View File
@@ -2,50 +2,35 @@ use std::collections::HashSet;
use crate::{FileId, TrackId, TrackSegmentId, WaypointId};
#[derive(Debug)]
pub struct FileSelection {
pub files: HashSet<FileId>,
}
#[derive(Debug)]
pub struct TrackSelection {
pub file: FileId,
pub trk: HashSet<TrackId>,
}
#[derive(Debug)]
pub struct TrackSegmentSelection {
pub file: FileId,
pub trk: TrackId,
pub trkseg: HashSet<TrackSegmentId>,
}
#[derive(Debug)]
pub struct WaypointsSelection {
pub file: FileId,
}
#[derive(Debug)]
pub struct WaypointSelection {
pub file: FileId,
pub wpt: HashSet<WaypointId>,
}
#[derive(Debug, Default)]
pub enum Selection {
#[default]
Empty,
File(FileSelection),
Track(TrackSelection),
TrackSegment(TrackSegmentSelection),
Waypoints(WaypointsSelection),
Waypoint(WaypointSelection),
File {
file_ids: HashSet<FileId>,
},
Track {
file_id: FileId,
trk_ids: HashSet<TrackId>,
},
TrackSegment {
file_id: FileId,
trk_id: TrackId,
trkseg_ids: HashSet<TrackSegmentId>,
},
Waypoints {
file_id: FileId,
},
Waypoint {
file_id: FileId,
wpt_ids: HashSet<WaypointId>,
},
}
impl Selection {
pub fn select(&mut self, id: FileId) {
let mut files = HashSet::default();
files.insert(id);
*self = Selection::File(FileSelection { files });
let mut file_ids = HashSet::default();
file_ids.insert(id);
*self = Selection::File { file_ids };
}
}