Correct new_order index in RowsReordered().
Only call RowsReordered() if index was not empty
before.
Get some more memory things right.
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@46240 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -188,9 +188,6 @@ public:
|
|||||||
wxDataViewSortedListModelNotifier( wxDataViewSortedListModel *model )
|
wxDataViewSortedListModelNotifier( wxDataViewSortedListModel *model )
|
||||||
{ m_model = model; }
|
{ m_model = model; }
|
||||||
|
|
||||||
~wxDataViewSortedListModelNotifier()
|
|
||||||
{ m_model->DetachChild(); }
|
|
||||||
|
|
||||||
virtual bool RowAppended()
|
virtual bool RowAppended()
|
||||||
{ return m_model->ChildRowAppended(); }
|
{ return m_model->ChildRowAppended(); }
|
||||||
|
|
||||||
@@ -289,17 +286,24 @@ wxDataViewSortedListModel::wxDataViewSortedListModel( wxDataViewListModel *child
|
|||||||
m_notifierOnChild = new wxDataViewSortedListModelNotifier( this );
|
m_notifierOnChild = new wxDataViewSortedListModelNotifier( this );
|
||||||
m_child->AddNotifier( m_notifierOnChild );
|
m_child->AddNotifier( m_notifierOnChild );
|
||||||
|
|
||||||
|
m_child->IncRef();
|
||||||
|
|
||||||
Resort();
|
Resort();
|
||||||
}
|
}
|
||||||
|
|
||||||
wxDataViewSortedListModel::~wxDataViewSortedListModel()
|
wxDataViewSortedListModel::~wxDataViewSortedListModel()
|
||||||
{
|
{
|
||||||
if (m_child)
|
DetachChild();
|
||||||
m_child->RemoveNotifier( m_notifierOnChild );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void wxDataViewSortedListModel::DetachChild()
|
void wxDataViewSortedListModel::DetachChild()
|
||||||
{
|
{
|
||||||
|
if (m_child)
|
||||||
|
{
|
||||||
|
m_child->RemoveNotifier( m_notifierOnChild );
|
||||||
|
m_child->DecRef();
|
||||||
|
}
|
||||||
|
|
||||||
m_child = NULL;
|
m_child = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -318,14 +322,48 @@ void wxDataViewSortedListModel::Resort()
|
|||||||
{
|
{
|
||||||
InitStatics();
|
InitStatics();
|
||||||
|
|
||||||
m_array.Clear();
|
if (!m_child) return;
|
||||||
|
|
||||||
unsigned int n = m_child->GetRowCount();
|
unsigned int n = m_child->GetRowCount();
|
||||||
|
|
||||||
unsigned int i;
|
unsigned int i;
|
||||||
|
if (n != m_array.GetCount())
|
||||||
|
{
|
||||||
|
// probably sorted for the first time -> no reordered
|
||||||
|
// -- just create index and leave
|
||||||
|
m_array.Clear();
|
||||||
|
for (i = 0; i < n; i++)
|
||||||
|
m_array.Add( i );
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
unsigned int *old_array = new unsigned int[ n ];
|
||||||
|
|
||||||
|
for (i = 0; i < n; i++)
|
||||||
|
old_array[i] = m_array[ i ];
|
||||||
|
|
||||||
|
m_array.Clear();
|
||||||
for (i = 0; i < n; i++)
|
for (i = 0; i < n; i++)
|
||||||
m_array.Add( i );
|
m_array.Add( i );
|
||||||
|
|
||||||
// do we need the neworder?
|
unsigned int *order = new unsigned int[ n ];
|
||||||
wxDataViewListModel::RowsReordered( NULL );
|
|
||||||
|
for (i = 0; i < n; i++)
|
||||||
|
{
|
||||||
|
unsigned int new_value = m_array[i];
|
||||||
|
|
||||||
|
unsigned int old_pos;
|
||||||
|
for (old_pos = 0; old_pos < n; old_pos++)
|
||||||
|
if (old_array[old_pos] == new_value)
|
||||||
|
break;
|
||||||
|
order[i] = old_pos;
|
||||||
|
}
|
||||||
|
|
||||||
|
delete [] old_array;
|
||||||
|
|
||||||
|
wxDataViewListModel::RowsReordered( order );
|
||||||
|
|
||||||
|
delete [] order;
|
||||||
}
|
}
|
||||||
|
|
||||||
#if 0
|
#if 0
|
||||||
@@ -559,11 +597,15 @@ bool wxDataViewSortedListModel::ChildCleared()
|
|||||||
|
|
||||||
unsigned int wxDataViewSortedListModel::GetRowCount() const
|
unsigned int wxDataViewSortedListModel::GetRowCount() const
|
||||||
{
|
{
|
||||||
return m_array.GetCount();
|
if (!m_child) return 0;
|
||||||
|
|
||||||
|
return m_child->GetRowCount();
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned int wxDataViewSortedListModel::GetColumnCount() const
|
unsigned int wxDataViewSortedListModel::GetColumnCount() const
|
||||||
{
|
{
|
||||||
|
if (!m_child) return 0;
|
||||||
|
|
||||||
return m_child->GetColumnCount();
|
return m_child->GetColumnCount();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -572,6 +614,8 @@ wxString wxDataViewSortedListModel::GetColumnType( unsigned int col ) const
|
|||||||
return m_child->GetColumnType( col );
|
return m_child->GetColumnType( col );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#include "wx/crt.h"
|
||||||
|
|
||||||
void wxDataViewSortedListModel::GetValue( wxVariant &variant, unsigned int col, unsigned int row ) const
|
void wxDataViewSortedListModel::GetValue( wxVariant &variant, unsigned int col, unsigned int row ) const
|
||||||
{
|
{
|
||||||
unsigned int child_row = m_array[row];
|
unsigned int child_row = m_array[row];
|
||||||
|
|||||||
Reference in New Issue
Block a user