Add support for editing dates (without time) to wxGrid

Add wxGridCellDateRenderer and wxGridCellDateRenderer which can be used
for the grid cells containing only dates, without times.

Also add wxGrid::SetColFormatDate() convenience function.

Refactor wxGridCellDateTimeRenderer slightly to reuse its code.

Closes https://github.com/wxWidgets/wxWidgets/pull/1101
This commit is contained in:
Pavel Kalugin
2018-09-06 05:49:58 +03:00
committed by Vadim Zeitlin
parent ee352d79c8
commit 659ab78c6d
10 changed files with 416 additions and 46 deletions

View File

@@ -142,6 +142,50 @@ public:
wxGridCellBoolRenderer();
};
/**
@class wxGridCellDateRenderer
This class may be used to show a date, without time, in a cell.
See @ref wxGridCellDateTimeRenderer for a date/time version.
wxDateTime::Format() is used internally to render the date
representation. wxDateTime::ParseDate() is used to parse the string
data entered in the cell.
@library{wxcore}
@category{grid}
@see wxGridCellRenderer, wxGridCellAutoWrapStringRenderer,
wxGridCellBoolRenderer, wxGridCellEnumRenderer,
wxGridCellFloatRenderer, wxGridCellNumberRenderer,
wxGridCellStringRenderer, wxGridCellDateTimeRenderer
@since 3.1.3
*/
class wxGridCellDateRenderer : public wxGridCellStringRenderer
{
public:
/**
Date renderer constructor.
@param outformat
strftime()-like format string used to render the output date.
By default (or if provided format string is empty) localized
date representation ("%x") is used.
*/
wxGridCellDateRenderer(const wxString& outformat = wxString());
/**
Sets the strftime()-like format string which will be used to render
the date.
@param params
strftime()-like format string used to render the date.
*/
virtual void SetParameters(const wxString& params);
};
/**
@class wxGridCellDateTimeRenderer
@@ -155,9 +199,9 @@ public:
@see wxGridCellRenderer, wxGridCellAutoWrapStringRenderer,
wxGridCellBoolRenderer, wxGridCellEnumRenderer,
wxGridCellFloatRenderer, wxGridCellNumberRenderer,
wxGridCellStringRenderer
wxGridCellStringRenderer, wxGridCellDateRenderer
*/
class wxGridCellDateTimeRenderer : public wxGridCellStringRenderer
class wxGridCellDateTimeRenderer : public wxGridCellDateRenderer
{
public:
/**
@@ -384,7 +428,7 @@ public:
@see wxGridCellAutoWrapStringEditor, wxGridCellBoolEditor,
wxGridCellChoiceEditor, wxGridCellEnumEditor,
wxGridCellFloatEditor, wxGridCellNumberEditor,
wxGridCellTextEditor
wxGridCellTextEditor, wxGridCellDateEditor
*/
class wxGridCellEditor : public wxClientDataContainer, public wxRefCounter
{
@@ -532,7 +576,8 @@ protected:
@see wxGridCellEditor, wxGridCellBoolEditor, wxGridCellChoiceEditor,
wxGridCellEnumEditor, wxGridCellFloatEditor,
wxGridCellNumberEditor, wxGridCellTextEditor
wxGridCellNumberEditor, wxGridCellTextEditor,
wxGridCellDateEditor
*/
class wxGridCellAutoWrapStringEditor : public wxGridCellTextEditor
{
@@ -551,7 +596,7 @@ public:
@see wxGridCellEditor, wxGridCellAutoWrapStringEditor,
wxGridCellChoiceEditor, wxGridCellEnumEditor,
wxGridCellFloatEditor, wxGridCellNumberEditor,
wxGridCellTextEditor
wxGridCellTextEditor, wxGridCellDateEditor
*/
class wxGridCellBoolEditor : public wxGridCellEditor
{
@@ -590,7 +635,7 @@ public:
@see wxGridCellEditor, wxGridCellAutoWrapStringEditor,
wxGridCellBoolEditor, wxGridCellEnumEditor,
wxGridCellFloatEditor, wxGridCellNumberEditor,
wxGridCellTextEditor
wxGridCellTextEditor, wxGridCellDateEditor
*/
class wxGridCellChoiceEditor : public wxGridCellEditor
{
@@ -641,7 +686,7 @@ public:
@see wxGridCellEditor, wxGridCellAutoWrapStringEditor,
wxGridCellBoolEditor, wxGridCellChoiceEditor,
wxGridCellTextEditor, wxGridCellFloatEditor,
wxGridCellNumberEditor
wxGridCellNumberEditor, wxGridCellDateEditor
*/
class wxGridCellEnumEditor : public wxGridCellChoiceEditor
{
@@ -666,7 +711,7 @@ public:
@see wxGridCellEditor, wxGridCellAutoWrapStringEditor,
wxGridCellBoolEditor, wxGridCellChoiceEditor,
wxGridCellEnumEditor, wxGridCellFloatEditor,
wxGridCellNumberEditor
wxGridCellNumberEditor, wxGridCellDateEditor
*/
class wxGridCellTextEditor : public wxGridCellEditor
{
@@ -705,7 +750,7 @@ public:
@see wxGridCellEditor, wxGridCellAutoWrapStringEditor,
wxGridCellBoolEditor, wxGridCellChoiceEditor,
wxGridCellEnumEditor, wxGridCellNumberEditor,
wxGridCellTextEditor
wxGridCellTextEditor, wxGridCellDateEditor
*/
class wxGridCellFloatEditor : public wxGridCellTextEditor
{
@@ -743,7 +788,7 @@ public:
@see wxGridCellEditor, wxGridCellAutoWrapStringEditor,
wxGridCellBoolEditor, wxGridCellChoiceEditor,
wxGridCellEnumEditor, wxGridCellFloatEditor,
wxGridCellTextEditor
wxGridCellTextEditor, wxGridCellDateEditor
*/
class wxGridCellNumberEditor : public wxGridCellTextEditor
{
@@ -775,6 +820,32 @@ protected:
wxString GetString() const;
};
/**
@class wxGridCellDateEditor
Grid cell editor for dates.
Uses @ref wxDatePickerCtrl as actual edit control.
@library{wxcore}
@category{grid}
@see wxGridCellEditor, wxGridCellAutoWrapStringEditor,
wxGridCellBoolEditor, wxGridCellChoiceEditor,
wxGridCellEnumEditor, wxGridCellFloatEditor,
wxGridCellTextEditor
@since 3.1.3
*/
class wxGridCellDateEditor : public wxGridCellEditor
{
public:
/**
Date editor constructor.
*/
wxGridCellDateEditor();
};
/**
@@ -2080,6 +2151,8 @@ enum wxGridRenderStyle
- wxGridCellFloatRenderer
- wxGridCellNumberRenderer
- wxGridCellStringRenderer
- wxGridCellDateRenderer
- wxGridCellDateTimeRenderer
The look of a cell can be further defined using wxGridCellAttr. An object
of this type may be returned by wxGridTableBase::GetAttr().
@@ -2092,6 +2165,7 @@ enum wxGridRenderStyle
- wxGridCellFloatEditor
- wxGridCellNumberEditor
- wxGridCellTextEditor
- wxGridCellDateEditor
Please see wxGridEvent, wxGridSizeEvent, wxGridRangeSelectEvent, and
wxGridEditorCreatedEvent for the documentation of all event types you can
@@ -2961,9 +3035,10 @@ public:
Name of the new type. May be any string, but if the type name is
the same as the name of an already registered type, including one
of the standard ones (which are @c wxGRID_VALUE_STRING, @c
wxGRID_VALUE_BOOL, @c wxGRID_VALUE_NUMBER, @c wxGRID_VALUE_FLOAT
and @c wxGRID_VALUE_CHOICE), then the new registration information
replaces the previously used renderer and editor.
wxGRID_VALUE_BOOL, @c wxGRID_VALUE_NUMBER, @c wxGRID_VALUE_FLOAT,
@c wxGRID_VALUE_CHOICE and @c wxGRID_VALUE_DATE), then the new
registration information replaces the previously used renderer and
editor.
@param renderer
The renderer to use for the cells of this type. Its ownership is
taken by the grid, i.e. it will call DecRef() on this pointer when
@@ -3090,6 +3165,19 @@ public:
*/
void SetColFormatNumber(int col);
/**
Sets the specified column to display date values.
The @a format argument is used with wxGridCellDateRenderer and allows
to specify the strftime-like format string to use for displaying the
dates in this column.
@see SetColFormatCustom()
@since 3.1.3
*/
void SetColFormatDate(int col, const wxString& format = wxString());
/**
Sets the default editor for grid cells.