change wxDataViewModel::Compare() to including column and sortorder
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@48176 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -151,17 +151,14 @@ public:
|
|||||||
void RemoveNotifier( wxDataViewModelNotifier *notifier );
|
void RemoveNotifier( wxDataViewModelNotifier *notifier );
|
||||||
|
|
||||||
// default compare function
|
// default compare function
|
||||||
virtual int Compare( const wxDataViewItem &item1, const wxDataViewItem &item2 );
|
virtual int Compare( const wxDataViewItem &item1, const wxDataViewItem &item2,
|
||||||
|
unsigned int column, bool ascending );
|
||||||
void SetSortingColumn( unsigned int col ) { m_sortingColumn = col; }
|
|
||||||
unsigned int GetSortingColumn() { return m_sortingColumn; }
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
// the user should not delete this class directly: he should use DecRef() instead!
|
// the user should not delete this class directly: he should use DecRef() instead!
|
||||||
virtual ~wxDataViewModel() { }
|
virtual ~wxDataViewModel() { }
|
||||||
|
|
||||||
wxDataViewModelNotifiers m_notifiers;
|
wxDataViewModelNotifiers m_notifiers;
|
||||||
unsigned int m_sortingColumn;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
// ---------------------------------------------------------
|
// ---------------------------------------------------------
|
||||||
@@ -199,7 +196,8 @@ public:
|
|||||||
|
|
||||||
// compare based on index
|
// compare based on index
|
||||||
|
|
||||||
virtual int Compare( const wxDataViewItem &item1, const wxDataViewItem &item2 );
|
virtual int Compare( const wxDataViewItem &item1, const wxDataViewItem &item2,
|
||||||
|
unsigned int column, bool ascending );
|
||||||
|
|
||||||
// implement base methods
|
// implement base methods
|
||||||
|
|
||||||
|
@@ -170,7 +170,8 @@ public:
|
|||||||
|
|
||||||
// override sorting to always sort branches ascendingly
|
// override sorting to always sort branches ascendingly
|
||||||
|
|
||||||
int Compare( const wxDataViewItem &item1, const wxDataViewItem &item2 )
|
int Compare( const wxDataViewItem &item1, const wxDataViewItem &item2,
|
||||||
|
unsigned int column, bool ascending )
|
||||||
{
|
{
|
||||||
if (IsContainer(item1) && IsContainer(item2))
|
if (IsContainer(item1) && IsContainer(item2))
|
||||||
{
|
{
|
||||||
@@ -190,7 +191,7 @@ public:
|
|||||||
return litem1-litem2;
|
return litem1-litem2;
|
||||||
}
|
}
|
||||||
|
|
||||||
return wxDataViewModel::Compare( item1, item2 );
|
return wxDataViewModel::Compare( item1, item2, column, ascending );
|
||||||
}
|
}
|
||||||
|
|
||||||
// implementation of base class virtuals to define model
|
// implementation of base class virtuals to define model
|
||||||
|
@@ -42,7 +42,6 @@ WX_DEFINE_LIST(wxDataViewModelNotifiers);
|
|||||||
wxDataViewModel::wxDataViewModel()
|
wxDataViewModel::wxDataViewModel()
|
||||||
{
|
{
|
||||||
m_notifiers.DeleteContents( true );
|
m_notifiers.DeleteContents( true );
|
||||||
m_sortingColumn = 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool wxDataViewModel::ItemAdded( const wxDataViewItem &parent, const wxDataViewItem &item )
|
bool wxDataViewModel::ItemAdded( const wxDataViewItem &parent, const wxDataViewItem &item )
|
||||||
@@ -141,7 +140,8 @@ void wxDataViewModel::RemoveNotifier( wxDataViewModelNotifier *notifier )
|
|||||||
m_notifiers.DeleteObject( notifier );
|
m_notifiers.DeleteObject( notifier );
|
||||||
}
|
}
|
||||||
|
|
||||||
int wxDataViewModel::Compare( const wxDataViewItem &item1, const wxDataViewItem &item2 )
|
int wxDataViewModel::Compare( const wxDataViewItem &item1, const wxDataViewItem &item2,
|
||||||
|
unsigned int column, bool ascending )
|
||||||
{
|
{
|
||||||
// sort branches before leaves
|
// sort branches before leaves
|
||||||
bool item1_is_container = IsContainer(item1);
|
bool item1_is_container = IsContainer(item1);
|
||||||
@@ -153,8 +153,15 @@ int wxDataViewModel::Compare( const wxDataViewItem &item1, const wxDataViewItem
|
|||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
wxVariant value1,value2;
|
wxVariant value1,value2;
|
||||||
GetValue( value1, item1, m_sortingColumn );
|
GetValue( value1, item1, column );
|
||||||
GetValue( value2, item2, m_sortingColumn );
|
GetValue( value2, item2, column );
|
||||||
|
|
||||||
|
if (!ascending)
|
||||||
|
{
|
||||||
|
wxVariant temp = value1;
|
||||||
|
value1 = value2;
|
||||||
|
value2 = temp;
|
||||||
|
}
|
||||||
|
|
||||||
if (value1.GetType() == wxT("string"))
|
if (value1.GetType() == wxT("string"))
|
||||||
{
|
{
|
||||||
@@ -189,6 +196,9 @@ int wxDataViewModel::Compare( const wxDataViewItem &item1, const wxDataViewItem
|
|||||||
unsigned long litem1 = (unsigned long) item1.GetID();
|
unsigned long litem1 = (unsigned long) item1.GetID();
|
||||||
unsigned long litem2 = (unsigned long) item2.GetID();
|
unsigned long litem2 = (unsigned long) item2.GetID();
|
||||||
|
|
||||||
|
if (!ascending)
|
||||||
|
return litem2-litem2;
|
||||||
|
|
||||||
return litem1-litem2;
|
return litem1-litem2;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -261,9 +271,13 @@ wxDataViewItem wxDataViewIndexListModel::GetItem( unsigned int row ) const
|
|||||||
return wxDataViewItem( m_hash[row] );
|
return wxDataViewItem( m_hash[row] );
|
||||||
}
|
}
|
||||||
|
|
||||||
int wxDataViewIndexListModel::Compare( const wxDataViewItem &item1, const wxDataViewItem &item2 )
|
int wxDataViewIndexListModel::Compare( const wxDataViewItem &item1, const wxDataViewItem &item2,
|
||||||
|
unsigned int column, bool ascending )
|
||||||
{
|
{
|
||||||
|
if (ascending)
|
||||||
return GetRow(item1) - GetRow(item2);
|
return GetRow(item1) - GetRow(item2);
|
||||||
|
|
||||||
|
return GetRow(item2) - GetRow(item1);
|
||||||
}
|
}
|
||||||
|
|
||||||
void wxDataViewIndexListModel::GetValue( wxVariant &variant,
|
void wxDataViewIndexListModel::GetValue( wxVariant &variant,
|
||||||
|
@@ -90,6 +90,9 @@ public:
|
|||||||
void SetSortOrder( GtkSortType sort_order ) { m_sort_order = sort_order; }
|
void SetSortOrder( GtkSortType sort_order ) { m_sort_order = sort_order; }
|
||||||
GtkSortType GetSortOrder() { return m_sort_order; }
|
GtkSortType GetSortOrder() { return m_sort_order; }
|
||||||
|
|
||||||
|
void SetSortColumn( unsigned int column ) { m_sort_column = column; }
|
||||||
|
unsigned int GetSortColumn() { return m_sort_column; }
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void InitTree();
|
void InitTree();
|
||||||
wxGtkTreeModelNode *FindNode( const wxDataViewItem &item );
|
wxGtkTreeModelNode *FindNode( const wxDataViewItem &item );
|
||||||
@@ -104,6 +107,7 @@ private:
|
|||||||
GtkWxTreeModel *m_gtk_model;
|
GtkWxTreeModel *m_gtk_model;
|
||||||
wxDataViewCtrl *m_owner;
|
wxDataViewCtrl *m_owner;
|
||||||
GtkSortType m_sort_order;
|
GtkSortType m_sort_order;
|
||||||
|
unsigned int m_sort_column;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
@@ -208,9 +212,9 @@ private:
|
|||||||
|
|
||||||
int LINKAGEMODE wxGtkTreeModelNodeCmp( void* id1, void* id2 )
|
int LINKAGEMODE wxGtkTreeModelNodeCmp( void* id1, void* id2 )
|
||||||
{
|
{
|
||||||
int ret = g_internal->GetDataViewModel()->Compare( id1, id2 );
|
int ret = g_internal->GetDataViewModel()->Compare( id1, id2,
|
||||||
if (g_internal->GetSortOrder() == GTK_SORT_DESCENDING)
|
g_internal->GetSortColumn(), (g_internal->GetSortOrder() == GTK_SORT_ASCENDING) );
|
||||||
return -ret;
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -599,7 +603,7 @@ gboolean wxgtk_tree_model_get_sort_column_id (GtkTreeSortable *sortabl
|
|||||||
g_return_val_if_fail (GTK_IS_WX_TREE_MODEL (sortable), FALSE);
|
g_return_val_if_fail (GTK_IS_WX_TREE_MODEL (sortable), FALSE);
|
||||||
|
|
||||||
if (sort_column_id)
|
if (sort_column_id)
|
||||||
*sort_column_id = tree_model->internal->GetDataViewModel()->GetSortingColumn();
|
*sort_column_id = tree_model->internal->GetSortColumn();
|
||||||
|
|
||||||
if (order)
|
if (order)
|
||||||
*order = tree_model->internal->GetSortOrder();
|
*order = tree_model->internal->GetSortOrder();
|
||||||
@@ -614,11 +618,11 @@ void wxgtk_tree_model_set_sort_column_id (GtkTreeSortable *sortable,
|
|||||||
GtkWxTreeModel *tree_model = (GtkWxTreeModel *) sortable;
|
GtkWxTreeModel *tree_model = (GtkWxTreeModel *) sortable;
|
||||||
g_return_if_fail (GTK_IS_WX_TREE_MODEL (sortable) );
|
g_return_if_fail (GTK_IS_WX_TREE_MODEL (sortable) );
|
||||||
|
|
||||||
if ((sort_column_id == (gint) tree_model->internal->GetDataViewModel()->GetSortingColumn()) &&
|
if ((sort_column_id == (gint) tree_model->internal->GetSortColumn()) &&
|
||||||
(order == tree_model->internal->GetSortOrder()))
|
(order == tree_model->internal->GetSortOrder()))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
tree_model->internal->GetDataViewModel()->SetSortingColumn( sort_column_id );
|
tree_model->internal->SetSortColumn( sort_column_id );
|
||||||
|
|
||||||
tree_model->internal->SetSortOrder( order );
|
tree_model->internal->SetSortOrder( order );
|
||||||
|
|
||||||
@@ -2239,6 +2243,7 @@ wxDataViewCtrlInternal::wxDataViewCtrlInternal( wxDataViewCtrl *owner,
|
|||||||
m_gtk_model = gtk_model;
|
m_gtk_model = gtk_model;
|
||||||
m_root = NULL;
|
m_root = NULL;
|
||||||
m_sort_order = GTK_SORT_ASCENDING;
|
m_sort_order = GTK_SORT_ASCENDING;
|
||||||
|
m_sort_column = 0;
|
||||||
InitTree();
|
InitTree();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user