Fix wxTreeListCtrl items comparison when using checkboxes

Override DoCompareValues() to handle values of "wxDataViewCheckIconText"
type which is not handled by wxDataViewModel::Compare() itself.

This ensures that the items with checkboxes are sorted by their (text)
contents instead of by the order of their addresses in memory as was
done for them, as for any unknown values type, previously.
This commit is contained in:
Fabian Cenedese
2017-09-25 14:45:51 +02:00
committed by Vadim Zeitlin
parent 10e7725246
commit 812224488f

View File

@@ -387,6 +387,10 @@ public:
unsigned col,
bool ascending) const wxOVERRIDE;
protected:
virtual int DoCompareValues(const wxVariant& value1,
const wxVariant& value2) const wxOVERRIDE;
private:
// The control we're associated with.
wxTreeListCtrl* const m_treelist;
@@ -1007,6 +1011,22 @@ wxTreeListModel::Compare(const wxDataViewItem& item1,
return result;
}
int wxTreeListModel::DoCompareValues(const wxVariant& value1,
const wxVariant& value2) const
{
if ( value1.GetType() == wxS("wxDataViewCheckIconText") )
{
wxDataViewCheckIconText iconText1, iconText2;
iconText1 << value1;
iconText2 << value2;
return iconText1.GetText().Cmp(iconText2.GetText());
}
return wxDataViewModel::DoCompareValues(value1, value2);
}
// ============================================================================
// wxTreeListCtrl implementation
// ============================================================================