Skip to content

Commit

Permalink
Merge pull request OpenCPN#3911 from davidsanner/track-date-column
Browse files Browse the repository at this point in the history
Add track start date column to Route Manager dialog track display tab
  • Loading branch information
bdbcat authored Jun 4, 2024
2 parents 0f81b3d + 792897b commit 6125e8d
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 2 deletions.
2 changes: 1 addition & 1 deletion gui/include/gui/routemanagerdialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 };

Expand Down
25 changes: 24 additions & 1 deletion gui/src/routemanagerdialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 };

Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -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());
Expand All @@ -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);
Expand Down Expand Up @@ -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);
}
}

Expand Down
13 changes: 13 additions & 0 deletions model/include/model/track.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 6125e8d

Please sign in to comment.