From 15b8afdcb8732a17679c08a9c23ebe1c0226eaf6 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Wed, 21 Sep 2011 15:07:49 +0000 Subject: [PATCH] Reset previous sort column in generic wxDataViewColumn::SetSortOrder(). The sort indicator on the column previously used for sorting was only reset when the user clicked on the column header (by wxDataViewHeaderWindow code that explicitly called wxDataViewCtrl::SetSortingColumnIndex()) but not when wxDataViewCtrl::SetSortOrder() was called directly. Fix this and take care of updating everything in SetSortOrder() itself. This makes the code simpler and also means that calling SetSortOrder() from the program now works as expected (it resulted in having sort indicators in two columns at once before). git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@69175 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- include/wx/generic/dataview.h | 7 +------ src/generic/datavgen.cpp | 33 ++++++++++++++++++++++++--------- 2 files changed, 25 insertions(+), 15 deletions(-) diff --git a/include/wx/generic/dataview.h b/include/wx/generic/dataview.h index 0fac7af910..ed3d11eb69 100644 --- a/include/wx/generic/dataview.h +++ b/include/wx/generic/dataview.h @@ -72,12 +72,7 @@ public: virtual void UnsetAsSortKey() { m_sort = false; UpdateDisplay(); } - virtual void SetSortOrder(bool ascending) - { - m_sort = true; - m_sortAscending = ascending; - UpdateDisplay(); - } + virtual void SetSortOrder(bool ascending); virtual bool IsSortOrderAscending() const { return m_sortAscending; } diff --git a/src/generic/datavgen.cpp b/src/generic/datavgen.cpp index f5fcf0d5e3..7faab77e67 100644 --- a/src/generic/datavgen.cpp +++ b/src/generic/datavgen.cpp @@ -146,6 +146,30 @@ void wxDataViewColumn::UpdateDisplay() } } +void wxDataViewColumn::SetSortOrder(bool ascending) +{ + if ( !m_owner ) + return; + + // First unset the old sort column if any. + int oldSortKey = m_owner->GetSortingColumnIndex(); + if ( oldSortKey != wxNOT_FOUND ) + { + m_owner->GetColumn(oldSortKey)->UnsetAsSortKey(); + } + + // Now set this one as the new sort column. + const int idx = m_owner->GetColumnIndex(this); + m_owner->SetSortingColumnIndex(idx); + + m_sort = true; + m_sortAscending = ascending; + + // Call this directly instead of using UpdateDisplay() as we already have + // the column index, no need to look it up again. + m_owner->OnColumnChange(idx); +} + //----------------------------------------------------------------------------- // wxDataViewHeaderWindow //----------------------------------------------------------------------------- @@ -221,15 +245,6 @@ private: } else // not using this column for sorting yet { - // first unset the old sort column if any - int oldSortKey = owner->GetSortingColumnIndex(); - if ( oldSortKey != wxNOT_FOUND ) - { - owner->GetColumn(oldSortKey)->UnsetAsSortKey(); - owner->OnColumnChange(oldSortKey); - } - - owner->SetSortingColumnIndex(idx); col->SetSortOrder(true); } -- 2.47.2