From 7a92d17721f7329f9aa23a9fad2a73c9f6be5f92 Mon Sep 17 00:00:00 2001 From: David Sanner Date: Thu, 16 May 2024 15:04:03 -0700 Subject: [PATCH] Add track start date column to Route Manager dialog --- gui/include/gui/routemanagerdialog.h | 2 +- gui/src/routemanagerdialog.cpp | 25 ++++++++++++++++++++++++- model/include/model/track.h | 13 +++++++++++++ 3 files changed, 38 insertions(+), 2 deletions(-) diff --git a/gui/include/gui/routemanagerdialog.h b/gui/include/gui/routemanagerdialog.h index 86c79b0784..07d6a4b4f9 100644 --- a/gui/include/gui/routemanagerdialog.h +++ b/gui/include/gui/routemanagerdialog.h @@ -36,7 +36,7 @@ #define NAME_COLUMN 2 #define DISTANCE_COLUMN 3 -enum { SORT_ON_DISTANCE = 1, SORT_ON_NAME }; +enum { SORT_ON_DISTANCE = 1, SORT_ON_NAME, SORT_ON_DATE }; enum TrackContextMenu { TRACK_MERGE = 1, TRACK_COPY_TEXT, TRACK_CLEAN }; diff --git a/gui/src/routemanagerdialog.cpp b/gui/src/routemanagerdialog.cpp index 51891a35d6..8a89025226 100644 --- a/gui/src/routemanagerdialog.cpp +++ b/gui/src/routemanagerdialog.cpp @@ -74,7 +74,7 @@ #define DIALOG_MARGIN 10 enum { rmVISIBLE = 0, rmROUTENAME, rmROUTEDESC }; // RMColumns; -enum { colTRKVISIBLE = 0, colTRKNAME, colTRKLENGTH }; +enum { colTRKVISIBLE = 0, colTRKNAME, colTRKLENGTH, colTRKDATE }; enum { colLAYVISIBLE = 0, colLAYNAME, colLAYITEMS, colLAYPERSIST }; enum { colWPTICON = 0, colWPTSCALE, colWPTNAME, colWPTDIST }; @@ -175,6 +175,19 @@ int wxCALLBACK SortTracksOnDistance(long item1, long item2, long list) ((Track *)item2)->Length()); } +// sort callback. Sort by track start date. +static int sort_track_date_dir; +#if wxCHECK_VERSION(2, 9, 0) +static int wxCALLBACK SortTracksOnDate(wxIntPtr item1, wxIntPtr item2, + wxIntPtr list) +#else +int wxCALLBACK SortTracksOnDate(long item1, long item2, long list) +#endif +{ + return SortRouteTrack(sort_track_date_dir, ((Track *)item1)->GetDate(), + ((Track *)item2)->GetDate()); +} + static int sort_wp_key; static int sort_track_key; @@ -599,6 +612,8 @@ void RouteManagerDialog::Create() { 4 * char_width); m_pTrkListCtrl->InsertColumn(colTRKNAME, _("Track Name"), wxLIST_FORMAT_LEFT, 20 * char_width); + m_pTrkListCtrl->InsertColumn(colTRKDATE, _("Start Date"), wxLIST_FORMAT_LEFT, + 20 * char_width); m_pTrkListCtrl->InsertColumn(colTRKLENGTH, _("Length"), wxLIST_FORMAT_LEFT, 5 * char_width); @@ -2080,6 +2095,7 @@ void RouteManagerDialog::UpdateTrkListCtrl() { long idx = m_pTrkListCtrl->InsertItem(li); m_pTrkListCtrl->SetItem(idx, colTRKNAME, trk->GetName(true)); + m_pTrkListCtrl->SetItem(idx, colTRKDATE, trk->GetDate(true)); wxString len; len.Printf(wxT("%5.2f"), trk->Length()); @@ -2102,6 +2118,9 @@ void RouteManagerDialog::UpdateTrkListCtrl() { case SORT_ON_DISTANCE: m_pTrkListCtrl->SortItems(SortTracksOnDistance, (wxIntPtr)NULL); break; + case SORT_ON_DATE: + m_pTrkListCtrl->SortItems(SortTracksOnDate, (wxIntPtr)NULL); + break; case SORT_ON_NAME: default: m_pTrkListCtrl->SortItems(SortTracksOnName, (wxIntPtr)NULL); @@ -2140,6 +2159,10 @@ void RouteManagerDialog::OnTrkColumnClicked(wxListEvent &event) { sort_track_key = SORT_ON_DISTANCE; sort_track_len_dir++; m_pTrkListCtrl->SortItems(SortTracksOnDistance, (wxIntPtr)NULL); + } else if (event.m_col == 3) { + sort_track_key = SORT_ON_DATE; + sort_track_date_dir++; + m_pTrkListCtrl->SortItems(SortTracksOnDate, (wxIntPtr)NULL); } } diff --git a/model/include/model/track.h b/model/include/model/track.h index cc6ce15985..caa9d08eb4 100644 --- a/model/include/model/track.h +++ b/model/include/model/track.h @@ -124,6 +124,19 @@ friend class TrackGui; } void SetName(const wxString name) { m_TrackNameString = name; } + wxString GetDate(bool auto_if_empty = false) const { + wxString name; + TrackPoint *rp = NULL; + if ((int)TrackPoints.size() > 0) rp = TrackPoints[0]; + if (rp && rp->GetCreateTime().IsValid()) + name = rp->GetCreateTime().FormatISODate() + _T(" ") + + rp->GetCreateTime() + .FormatISOTime(); // name = rp->m_CreateTime.Format(); + else + name = _("(Unknown Date)"); + return name; + } + wxString m_GUID; bool m_bIsInLayer; int m_LayerID;