diff --git a/include/wx/dvrenderers.h b/include/wx/dvrenderers.h index 4de42f3b14..f1b3fc1c04 100644 --- a/include/wx/dvrenderers.h +++ b/include/wx/dvrenderers.h @@ -155,6 +155,15 @@ public: wxString GetVariantType() const { return m_variantType; } + // Check if the given variant type is compatible with the type expected by + // this renderer: by default, just compare it with GetVariantType(), but + // can be overridden to accept other types that can be converted to the + // type needed by the renderer. + virtual bool IsCompatibleVariantType(const wxString& variantType) const + { + return variantType == GetVariantType(); + } + // Prepare for rendering the value of the corresponding item in the given // column taken from the provided non-null model. // @@ -163,8 +172,9 @@ public: // it and should probably be removed in the future. // // Return true if this cell is non-empty or false otherwise (and also if - // the model returned a value of the wrong, i.e. different from our - // GetVariantType(), type, in which case a debug error is also logged). + // the model returned a value of the wrong type, i.e. such that our + // IsCompatibleVariantType() returned false for it, in which case a debug + // error is also logged). bool PrepareForItem(const wxDataViewModel *model, const wxDataViewItem& item, unsigned column); diff --git a/interface/wx/dataview.h b/interface/wx/dataview.h index fa26279b2c..563a6ad1b4 100644 --- a/interface/wx/dataview.h +++ b/interface/wx/dataview.h @@ -2064,6 +2064,19 @@ public: */ wxString GetVariantType() const; + /** + Check if the given variant type is compatible with the type expected by + this renderer. + + The base class implementation just compares @a variantType with the + value returned by GetVariantType(), but this function can be overridden + to accept other types that can be converted to the type needed by the + renderer. + + @since 3.1.7 + */ + virtual bool IsCompatibleVariantType(const wxString& variantType) const; + /** Sets the alignment of the renderer's content. The default value of @c wxDVR_DEFAULT_ALIGNMENT indicates that the content diff --git a/src/common/datavcmn.cpp b/src/common/datavcmn.cpp index db60a89eda..10ce375710 100644 --- a/src/common/datavcmn.cpp +++ b/src/common/datavcmn.cpp @@ -861,7 +861,7 @@ wxDataViewRendererBase::CheckedGetValue(const wxDataViewModel* model, // We always allow the cell to be null, regardless of the renderer type. if ( !value.IsNull() ) { - if ( value.GetType() != GetVariantType() ) + if ( !IsCompatibleVariantType(value.GetType()) ) { // If you're seeing this message, this indicates that either your // renderer is using the wrong type, or your model returns values