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:
@@ -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);
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user