Fix not resorting generic wxDVC when model sort order changes

We can't skip resorting wxDataViewCtrl contents when the sort order is
defined by the model class, as it can change at any moment, so restrict
this optimization to the cases when we're sorting by the value of some
column.

Closes https://github.com/wxWidgets/wxWidgets/pull/2153
This commit is contained in:
Jorge Moraleda
2020-12-25 13:10:33 -08:00
committed by Vadim Zeitlin
parent 87d94819a1
commit ce4d95eac0

View File

@@ -110,6 +110,8 @@ public:
bool IsNone() const { return m_column == SortColumn_None; }
bool UsesColumn() const { return m_column >= 0; }
int GetColumn() const { return m_column; }
bool IsAscending() const { return m_ascending; }
@@ -1888,9 +1890,10 @@ void wxDataViewTreeNode::Resort(wxDataViewMainWindow* window)
{
wxDataViewTreeNodes& nodes = m_branchData->children;
// Only sort the children if they aren't already sorted by the wanted
// criteria.
if ( m_branchData->sortOrder != sortOrder )
// When sorting by column value, we can skip resorting entirely if the
// same sort order was used previously. However we can't do this when
// using model-specific sort order, which can change at any time.
if ( m_branchData->sortOrder != sortOrder || !sortOrder.UsesColumn() )
{
std::sort(m_branchData->children.begin(),
m_branchData->children.end(),