From 615b49692c578db752a871244e836ea6607c4e54 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Sat, 20 Dec 2014 21:51:54 +0000 Subject: [PATCH] Add GetDefaultType() to all standard wxDataViewRenderer-derived classes. This makes it possible to refer to the associated wxVariant types without hard coding the string constants, i.e. instead of writing "string" (error prone as typos are not detected) it is now possible to write wxDataViewTextRenderer:: GetDefaultType(). This will also make it simpler to write generic (in C++ templates sense) code using renderers. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@78288 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- include/wx/generic/dvrenderers.h | 24 +++++++++--- include/wx/gtk/dvrenderers.h | 24 +++++++++--- include/wx/osx/dvrenderers.h | 28 ++++++++++---- include/wx/qt/dvrenderers.h | 28 ++++++++++---- interface/wx/dataview.h | 63 ++++++++++++++++++++++++++++---- 5 files changed, 134 insertions(+), 33 deletions(-) diff --git a/include/wx/generic/dvrenderers.h b/include/wx/generic/dvrenderers.h index 60d431f84e..7a0a9ddf73 100644 --- a/include/wx/generic/dvrenderers.h +++ b/include/wx/generic/dvrenderers.h @@ -18,7 +18,9 @@ class WXDLLIMPEXP_ADV wxDataViewCustomRenderer: public wxDataViewRenderer { public: - wxDataViewCustomRenderer( const wxString &varianttype = wxT("string"), + static wxString GetDefaultType() { return wxS("string"); } + + wxDataViewCustomRenderer( const wxString &varianttype = GetDefaultType(), wxDataViewCellMode mode = wxDATAVIEW_CELL_INERT, int align = wxDVR_DEFAULT_ALIGNMENT ); @@ -46,7 +48,9 @@ private: class WXDLLIMPEXP_ADV wxDataViewTextRenderer: public wxDataViewRenderer { public: - wxDataViewTextRenderer( const wxString &varianttype = wxT("string"), + static wxString GetDefaultType() { return wxS("string"); } + + wxDataViewTextRenderer( const wxString &varianttype = GetDefaultType(), wxDataViewCellMode mode = wxDATAVIEW_CELL_INERT, int align = wxDVR_DEFAULT_ALIGNMENT ); @@ -76,7 +80,9 @@ protected: class WXDLLIMPEXP_ADV wxDataViewBitmapRenderer: public wxDataViewRenderer { public: - wxDataViewBitmapRenderer( const wxString &varianttype = wxT("wxBitmap"), + static wxString GetDefaultType() { return wxS("wxBitmap"); } + + wxDataViewBitmapRenderer( const wxString &varianttype = GetDefaultType(), wxDataViewCellMode mode = wxDATAVIEW_CELL_INERT, int align = wxDVR_DEFAULT_ALIGNMENT ); @@ -101,7 +107,9 @@ protected: class WXDLLIMPEXP_ADV wxDataViewToggleRenderer: public wxDataViewRenderer { public: - wxDataViewToggleRenderer( const wxString &varianttype = wxT("bool"), + static wxString GetDefaultType() { return wxS("bool"); } + + wxDataViewToggleRenderer( const wxString &varianttype = GetDefaultType(), wxDataViewCellMode mode = wxDATAVIEW_CELL_INERT, int align = wxDVR_DEFAULT_ALIGNMENT ); @@ -131,8 +139,10 @@ protected: class WXDLLIMPEXP_ADV wxDataViewProgressRenderer: public wxDataViewRenderer { public: + static wxString GetDefaultType() { return wxS("long"); } + wxDataViewProgressRenderer( const wxString &label = wxEmptyString, - const wxString &varianttype = wxT("long"), + const wxString &varianttype = GetDefaultType(), wxDataViewCellMode mode = wxDATAVIEW_CELL_INERT, int align = wxDVR_DEFAULT_ALIGNMENT ); @@ -157,7 +167,9 @@ protected: class WXDLLIMPEXP_ADV wxDataViewIconTextRenderer: public wxDataViewRenderer { public: - wxDataViewIconTextRenderer( const wxString &varianttype = wxT("wxDataViewIconText"), + static wxString GetDefaultType() { return wxS("wxDataViewIconText"); } + + wxDataViewIconTextRenderer( const wxString &varianttype = GetDefaultType(), wxDataViewCellMode mode = wxDATAVIEW_CELL_INERT, int align = wxDVR_DEFAULT_ALIGNMENT ); diff --git a/include/wx/gtk/dvrenderers.h b/include/wx/gtk/dvrenderers.h index 385fa73a0b..416e0ee98f 100644 --- a/include/wx/gtk/dvrenderers.h +++ b/include/wx/gtk/dvrenderers.h @@ -25,7 +25,9 @@ class WXDLLIMPEXP_ADV wxDataViewTextRenderer: public wxDataViewRenderer { public: - wxDataViewTextRenderer( const wxString &varianttype = "string", + static wxString GetDefaultType() { return wxS("string"); } + + wxDataViewTextRenderer( const wxString &varianttype = GetDefaultType(), wxDataViewCellMode mode = wxDATAVIEW_CELL_INERT, int align = wxDVR_DEFAULT_ALIGNMENT ); @@ -68,7 +70,9 @@ protected: class WXDLLIMPEXP_ADV wxDataViewBitmapRenderer: public wxDataViewRenderer { public: - wxDataViewBitmapRenderer( const wxString &varianttype = "wxBitmap", + static wxString GetDefaultType() { return wxS("wxBitmap"); } + + wxDataViewBitmapRenderer( const wxString &varianttype = GetDefaultType(), wxDataViewCellMode mode = wxDATAVIEW_CELL_INERT, int align = wxDVR_DEFAULT_ALIGNMENT ); @@ -86,7 +90,9 @@ protected: class WXDLLIMPEXP_ADV wxDataViewToggleRenderer: public wxDataViewRenderer { public: - wxDataViewToggleRenderer( const wxString &varianttype = "bool", + static wxString GetDefaultType() { return wxS("bool"); } + + wxDataViewToggleRenderer( const wxString &varianttype = GetDefaultType(), wxDataViewCellMode mode = wxDATAVIEW_CELL_INERT, int align = wxDVR_DEFAULT_ALIGNMENT ); @@ -104,7 +110,9 @@ protected: class WXDLLIMPEXP_ADV wxDataViewCustomRenderer: public wxDataViewCustomRendererBase { public: - wxDataViewCustomRenderer( const wxString &varianttype = "string", + static wxString GetDefaultType() { return wxS("string"); } + + wxDataViewCustomRenderer( const wxString &varianttype = GetDefaultType(), wxDataViewCellMode mode = wxDATAVIEW_CELL_INERT, int align = wxDVR_DEFAULT_ALIGNMENT, bool no_init = false ); @@ -166,8 +174,10 @@ private: class WXDLLIMPEXP_ADV wxDataViewProgressRenderer: public wxDataViewCustomRenderer { public: + static wxString GetDefaultType() { return wxS("long"); } + wxDataViewProgressRenderer( const wxString &label = wxEmptyString, - const wxString &varianttype = "long", + const wxString &varianttype = GetDefaultType(), wxDataViewCellMode mode = wxDATAVIEW_CELL_INERT, int align = wxDVR_DEFAULT_ALIGNMENT ); virtual ~wxDataViewProgressRenderer(); @@ -201,7 +211,9 @@ protected: class WXDLLIMPEXP_ADV wxDataViewIconTextRenderer: public wxDataViewTextRenderer { public: - wxDataViewIconTextRenderer( const wxString &varianttype = "wxDataViewIconText", + static wxString GetDefaultType() { return wxS("wxDataViewIconText"); } + + wxDataViewIconTextRenderer( const wxString &varianttype = GetDefaultType(), wxDataViewCellMode mode = wxDATAVIEW_CELL_INERT, int align = wxDVR_DEFAULT_ALIGNMENT ); virtual ~wxDataViewIconTextRenderer(); diff --git a/include/wx/osx/dvrenderers.h b/include/wx/osx/dvrenderers.h index d046b1a851..8798611ff4 100644 --- a/include/wx/osx/dvrenderers.h +++ b/include/wx/osx/dvrenderers.h @@ -17,7 +17,9 @@ class WXDLLIMPEXP_ADV wxDataViewCustomRenderer : public wxDataViewCustomRendererBase { public: - wxDataViewCustomRenderer(const wxString& varianttype = "string", + static wxString GetDefaultType() { return wxS("string"); } + + wxDataViewCustomRenderer(const wxString& varianttype = GetDefaultType(), wxDataViewCellMode mode = wxDATAVIEW_CELL_INERT, int align = wxDVR_DEFAULT_ALIGNMENT); @@ -51,7 +53,9 @@ private: class WXDLLIMPEXP_ADV wxDataViewTextRenderer: public wxDataViewRenderer { public: - wxDataViewTextRenderer(const wxString& varianttype = "string", + static wxString GetDefaultType() { return wxS("string"); } + + wxDataViewTextRenderer(const wxString& varianttype = GetDefaultType(), wxDataViewCellMode mode = wxDATAVIEW_CELL_INERT, int align = wxDVR_DEFAULT_ALIGNMENT); @@ -74,7 +78,9 @@ private: class WXDLLIMPEXP_ADV wxDataViewBitmapRenderer: public wxDataViewRenderer { public: - wxDataViewBitmapRenderer(const wxString& varianttype = "wxBitmap", + static wxString GetDefaultType() { return wxS("wxBitmap"); } + + wxDataViewBitmapRenderer(const wxString& varianttype = GetDefaultType(), wxDataViewCellMode mode = wxDATAVIEW_CELL_INERT, int align = wxDVR_DEFAULT_ALIGNMENT); @@ -122,7 +128,9 @@ private: class WXDLLIMPEXP_ADV wxDataViewIconTextRenderer: public wxDataViewRenderer { public: - wxDataViewIconTextRenderer(const wxString& varianttype = "wxDataViewIconText", + static wxString GetDefaultType() { return wxS("wxDataViewIconText"); } + + wxDataViewIconTextRenderer(const wxString& varianttype = GetDefaultType(), wxDataViewCellMode mode = wxDATAVIEW_CELL_INERT, int align = wxDVR_DEFAULT_ALIGNMENT); @@ -145,7 +153,9 @@ private: class WXDLLIMPEXP_ADV wxDataViewToggleRenderer: public wxDataViewRenderer { public: - wxDataViewToggleRenderer(const wxString& varianttype = "bool", + static wxString GetDefaultType() { return wxS("bool"); } + + wxDataViewToggleRenderer(const wxString& varianttype = GetDefaultType(), wxDataViewCellMode mode = wxDATAVIEW_CELL_INERT, int align = wxDVR_DEFAULT_ALIGNMENT); @@ -168,8 +178,10 @@ private: class WXDLLIMPEXP_ADV wxDataViewProgressRenderer: public wxDataViewRenderer { public: + static wxString GetDefaultType() { return wxS("long"); } + wxDataViewProgressRenderer(const wxString& label = wxEmptyString, - const wxString& varianttype = "long", + const wxString& varianttype = GetDefaultType(), wxDataViewCellMode mode = wxDATAVIEW_CELL_INERT, int align = wxDVR_DEFAULT_ALIGNMENT); @@ -192,7 +204,9 @@ private: class WXDLLIMPEXP_ADV wxDataViewDateRenderer: public wxDataViewRenderer { public: - wxDataViewDateRenderer(const wxString& varianttype = "datetime", + static wxString GetDefaultType() { return wxS("datetime"); } + + wxDataViewDateRenderer(const wxString& varianttype = GetDefaultType(), wxDataViewCellMode mode = wxDATAVIEW_CELL_ACTIVATABLE, int align = wxDVR_DEFAULT_ALIGNMENT); diff --git a/include/wx/qt/dvrenderers.h b/include/wx/qt/dvrenderers.h index 75a19a87b0..6ae3e527a6 100644 --- a/include/wx/qt/dvrenderers.h +++ b/include/wx/qt/dvrenderers.h @@ -15,7 +15,9 @@ class WXDLLIMPEXP_ADV wxDataViewTextRenderer: public wxDataViewRenderer { public: - wxDataViewTextRenderer( const wxString &varianttype = wxT("string"), + static wxString GetDefaultType() { return wxS("string"); } + + wxDataViewTextRenderer( const wxString &varianttype = GetDefaultType(), wxDataViewCellMode mode = wxDATAVIEW_CELL_INERT, int align = wxDVR_DEFAULT_ALIGNMENT ); @@ -32,7 +34,9 @@ public: class WXDLLIMPEXP_ADV wxDataViewBitmapRenderer: public wxDataViewRenderer { public: - wxDataViewBitmapRenderer( const wxString &varianttype = wxT("wxBitmap"), + static wxString GetDefaultType() { return wxS("wxBitmap"); } + + wxDataViewBitmapRenderer( const wxString &varianttype = GetDefaultType(), wxDataViewCellMode mode = wxDATAVIEW_CELL_INERT, int align = wxDVR_DEFAULT_ALIGNMENT ); @@ -47,7 +51,9 @@ public: class WXDLLIMPEXP_ADV wxDataViewToggleRenderer: public wxDataViewRenderer { public: - wxDataViewToggleRenderer( const wxString &varianttype = wxT("bool"), + static wxString GetDefaultType() { return wxS("bool"); } + + wxDataViewToggleRenderer( const wxString &varianttype = GetDefaultType(), wxDataViewCellMode mode = wxDATAVIEW_CELL_INERT, int align = wxDVR_DEFAULT_ALIGNMENT ); @@ -62,7 +68,9 @@ public: class WXDLLIMPEXP_ADV wxDataViewCustomRenderer: public wxDataViewRenderer { public: - wxDataViewCustomRenderer( const wxString &varianttype = wxT("string"), + static wxString GetDefaultType() { return wxS("string"); } + + wxDataViewCustomRenderer( const wxString &varianttype = GetDefaultType(), wxDataViewCellMode mode = wxDATAVIEW_CELL_INERT, int align = wxDVR_DEFAULT_ALIGNMENT, bool no_init = false ); @@ -97,8 +105,10 @@ public: class WXDLLIMPEXP_ADV wxDataViewProgressRenderer: public wxDataViewCustomRenderer { public: + static wxString GetDefaultType() { return wxS("long"); } + wxDataViewProgressRenderer( const wxString &label = wxEmptyString, - const wxString &varianttype = wxT("long"), + const wxString &varianttype = GetDefaultType(), wxDataViewCellMode mode = wxDATAVIEW_CELL_INERT, int align = wxDVR_DEFAULT_ALIGNMENT ); virtual ~wxDataViewProgressRenderer(); @@ -117,7 +127,9 @@ public: class WXDLLIMPEXP_ADV wxDataViewIconTextRenderer: public wxDataViewCustomRenderer { public: - wxDataViewIconTextRenderer( const wxString &varianttype = wxT("wxDataViewIconText"), + static wxString GetDefaultType() { return wxS("wxDataViewIconText"); } + + wxDataViewIconTextRenderer( const wxString &varianttype = GetDefaultType(), wxDataViewCellMode mode = wxDATAVIEW_CELL_INERT, int align = wxDVR_DEFAULT_ALIGNMENT ); virtual ~wxDataViewIconTextRenderer(); @@ -140,7 +152,9 @@ public: class WXDLLIMPEXP_ADV wxDataViewDateRenderer: public wxDataViewCustomRenderer { public: - wxDataViewDateRenderer( const wxString &varianttype = wxT("datetime"), + static wxString GetDefaultType() { return wxS("datetime"); } + + wxDataViewDateRenderer( const wxString &varianttype = GetDefaultType(), wxDataViewCellMode mode = wxDATAVIEW_CELL_ACTIVATABLE, int align = wxDVR_DEFAULT_ALIGNMENT ); diff --git a/interface/wx/dataview.h b/interface/wx/dataview.h index 1609406ee3..5b1339ee55 100644 --- a/interface/wx/dataview.h +++ b/interface/wx/dataview.h @@ -1904,10 +1904,17 @@ protected: class wxDataViewTextRenderer : public wxDataViewRenderer { public: + /** + Returns the wxVariant type used with this renderer. + + @since 3.1.0 + */ + static wxString GetDefaultType(); + /** The ctor. */ - wxDataViewTextRenderer(const wxString& varianttype = "string", + wxDataViewTextRenderer(const wxString& varianttype = GetDefaultType(), wxDataViewCellMode mode = wxDATAVIEW_CELL_INERT, int align = wxDVR_DEFAULT_ALIGNMENT ); }; @@ -1930,10 +1937,17 @@ public: class wxDataViewIconTextRenderer : public wxDataViewRenderer { public: + /** + Returns the wxVariant type used with this renderer. + + @since 3.1.0 + */ + static wxString GetDefaultType(); + /** The ctor. */ - wxDataViewIconTextRenderer(const wxString& varianttype = "wxDataViewIconText", + wxDataViewIconTextRenderer(const wxString& varianttype = GetDefaultType(), wxDataViewCellMode mode = wxDATAVIEW_CELL_INERT, int align = wxDVR_DEFAULT_ALIGNMENT ); }; @@ -1951,11 +1965,18 @@ public: class wxDataViewProgressRenderer : public wxDataViewRenderer { public: + /** + Returns the wxVariant type used with this renderer. + + @since 3.1.0 + */ + static wxString GetDefaultType(); + /** The ctor. */ wxDataViewProgressRenderer(const wxString& label = wxEmptyString, - const wxString& varianttype = "long", + const wxString& varianttype = GetDefaultType(), wxDataViewCellMode mode = wxDATAVIEW_CELL_INERT, int align = wxDVR_DEFAULT_ALIGNMENT ); }; @@ -1997,10 +2018,17 @@ public: class wxDataViewToggleRenderer : public wxDataViewRenderer { public: + /** + Returns the wxVariant type used with this renderer. + + @since 3.1.0 + */ + static wxString GetDefaultType(); + /** The ctor. */ - wxDataViewToggleRenderer(const wxString& varianttype = "bool", + wxDataViewToggleRenderer(const wxString& varianttype = GetDefaultType(), wxDataViewCellMode mode = wxDATAVIEW_CELL_INERT, int align = wxDVR_DEFAULT_ALIGNMENT); }; @@ -2075,10 +2103,17 @@ public: class wxDataViewDateRenderer : public wxDataViewRenderer { public: + /** + Returns the wxVariant type used with this renderer. + + @since 3.1.0 + */ + static wxString GetDefaultType(); + /** The ctor. */ - wxDataViewDateRenderer(const wxString& varianttype = "datetime", + wxDataViewDateRenderer(const wxString& varianttype = GetDefaultType(), wxDataViewCellMode mode = wxDATAVIEW_CELL_ACTIVATABLE, int align = wxDVR_DEFAULT_ALIGNMENT); }; @@ -2107,10 +2142,17 @@ public: class wxDataViewCustomRenderer : public wxDataViewRenderer { public: + /** + Returns the wxVariant type used with this renderer. + + @since 3.1.0 + */ + static wxString GetDefaultType(); + /** Constructor. */ - wxDataViewCustomRenderer(const wxString& varianttype = "string", + wxDataViewCustomRenderer(const wxString& varianttype = GetDefaultType(), wxDataViewCellMode mode = wxDATAVIEW_CELL_INERT, int align = wxDVR_DEFAULT_ALIGNMENT); @@ -2310,10 +2352,17 @@ protected: class wxDataViewBitmapRenderer : public wxDataViewRenderer { public: + /** + Returns the wxVariant type used with this renderer. + + @since 3.1.0 + */ + static wxString GetDefaultType(); + /** The ctor. */ - wxDataViewBitmapRenderer(const wxString& varianttype = "wxBitmap", + wxDataViewBitmapRenderer(const wxString& varianttype = GetDefaultType(), wxDataViewCellMode mode = wxDATAVIEW_CELL_INERT, int align = wxDVR_DEFAULT_ALIGNMENT); };