Allow relaxing the check for variant type in wxDataViewRenderer

Instead of checking for the exact variant type match, call the new
IsCompatibleVariantType() virtual function, which still does the same
check by default, but can be overridden to allow other types as well if
they're accepted by the renderer.

This will be soon used to allow accepting both wxBitmap (which must
still be accepted for compatibility) and wxBitmapBundle (which is the
simplest way to support high DPI) in wxDataViewBitmapRenderer at once.
This commit is contained in:
Vadim Zeitlin
2022-05-08 18:32:46 +01:00
parent eb361a182a
commit 23e815bcf6
3 changed files with 26 additions and 3 deletions

View File

@@ -155,6 +155,15 @@ public:
wxString GetVariantType() const { return m_variantType; } 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 // Prepare for rendering the value of the corresponding item in the given
// column taken from the provided non-null model. // column taken from the provided non-null model.
// //
@@ -163,8 +172,9 @@ public:
// it and should probably be removed in the future. // it and should probably be removed in the future.
// //
// Return true if this cell is non-empty or false otherwise (and also if // 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 // the model returned a value of the wrong type, i.e. such that our
// GetVariantType(), type, in which case a debug error is also logged). // IsCompatibleVariantType() returned false for it, in which case a debug
// error is also logged).
bool PrepareForItem(const wxDataViewModel *model, bool PrepareForItem(const wxDataViewModel *model,
const wxDataViewItem& item, const wxDataViewItem& item,
unsigned column); unsigned column);

View File

@@ -2064,6 +2064,19 @@ public:
*/ */
wxString GetVariantType() const; 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. Sets the alignment of the renderer's content.
The default value of @c wxDVR_DEFAULT_ALIGNMENT indicates that the content The default value of @c wxDVR_DEFAULT_ALIGNMENT indicates that the content

View File

@@ -861,7 +861,7 @@ wxDataViewRendererBase::CheckedGetValue(const wxDataViewModel* model,
// We always allow the cell to be null, regardless of the renderer type. // We always allow the cell to be null, regardless of the renderer type.
if ( !value.IsNull() ) if ( !value.IsNull() )
{ {
if ( value.GetType() != GetVariantType() ) if ( !IsCompatibleVariantType(value.GetType()) )
{ {
// If you're seeing this message, this indicates that either your // If you're seeing this message, this indicates that either your
// renderer is using the wrong type, or your model returns values // renderer is using the wrong type, or your model returns values