Get dates directly from table in wxGridCellDateEditor if possible

Unlike wxGridCellDateRenderer, which already did it, the editor class
always got the cell value from the table as a string, even if the table
supported returning the dates directly.

Fix this by using the same code in the editor as in the renderer, which
required a further refactoring in order to make it reusable: the helper
TryParseDate() was replaced with TryGetValueAsDate() and DateParseParams
was added to allow overriding the arguments passed to it in the
overridden wxGridCellDateTimeRenderer::GetDateParseParams().
This commit is contained in:
Vadim Zeitlin
2020-11-03 17:30:54 +01:00
parent 9311dc8ffb
commit ce0f10c377
4 changed files with 100 additions and 44 deletions

View File

@@ -171,6 +171,8 @@ public:
#include "wx/datetime.h"
namespace wxGridPrivate { class DateParseParams; }
// renderer for the cells containing dates only, without time component
class WXDLLIMPEXP_ADV wxGridCellDateRenderer : public wxGridCellStringRenderer
{
@@ -207,7 +209,11 @@ public:
protected:
wxString GetString(const wxGrid& grid, int row, int col);
virtual bool Parse(const wxString& text, wxDateTime& result);
// This is overridden in wxGridCellDateTimeRenderer which uses a separate
// input format and forbids fallback to ParseDate().
virtual void
GetDateParseParams(wxGridPrivate::DateParseParams& params) const;
wxString m_oformat;
wxDateTime::TimeZone m_tz;
@@ -229,7 +235,8 @@ public:
virtual wxGridCellRenderer *Clone() const wxOVERRIDE;
protected:
virtual bool Parse(const wxString& text, wxDateTime& result) wxOVERRIDE;
virtual void
GetDateParseParams(wxGridPrivate::DateParseParams& params) const wxOVERRIDE;
wxString m_iformat;
};