Renamed HasChildren() to IsContainer(), added GetParent() to wxDataViewModel
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@47589 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
parent
ee5aa9d44f
commit
ed903e4242
@ -104,7 +104,8 @@ public:
|
||||
const wxDataViewItem &item, unsigned int col ) = 0;
|
||||
|
||||
// define hierachy
|
||||
virtual bool HasChildren( const wxDataViewItem &item ) const = 0;
|
||||
virtual wxDataViewItem GetParent( const wxDataViewItem &item ) const = 0;
|
||||
virtual bool IsContainer( const wxDataViewItem &item ) const = 0;
|
||||
virtual wxDataViewItem GetFirstChild( const wxDataViewItem &parent ) const = 0;
|
||||
virtual wxDataViewItem GetNextSibling( const wxDataViewItem &item ) const = 0;
|
||||
|
||||
|
@ -171,7 +171,7 @@ public:
|
||||
|
||||
int Compare( const wxDataViewItem &item1, const wxDataViewItem &item2 )
|
||||
{
|
||||
if (HasChildren(item1) && HasChildren(item2))
|
||||
if (IsContainer(item1) && IsContainer(item2))
|
||||
{
|
||||
wxVariant value1,value2;
|
||||
GetValue( value1, item1, 0 );
|
||||
@ -230,12 +230,29 @@ public:
|
||||
}
|
||||
}
|
||||
|
||||
virtual bool HasChildren( const wxDataViewItem &item ) const
|
||||
virtual wxDataViewItem GetParent( const wxDataViewItem &item ) const
|
||||
{
|
||||
// the invisble root node has no parent
|
||||
if (!item.IsOk())
|
||||
return wxDataViewItem(0);
|
||||
|
||||
MyMusicModelNode *node = (MyMusicModelNode*) item.GetID();
|
||||
if (!node)
|
||||
|
||||
// "MyMusic" also has no parent
|
||||
if (node == m_root)
|
||||
return wxDataViewItem(0);
|
||||
|
||||
return wxDataViewItem( (void*) node->GetParent() );
|
||||
}
|
||||
|
||||
virtual bool IsContainer( const wxDataViewItem &item ) const
|
||||
{
|
||||
// the invisble root node can have children (in
|
||||
// our model always "MyMusic")
|
||||
if (!item.IsOk())
|
||||
return true;
|
||||
|
||||
MyMusicModelNode *node = (MyMusicModelNode*) item.GetID();
|
||||
return node->IsContainer();
|
||||
}
|
||||
|
||||
@ -261,14 +278,19 @@ public:
|
||||
virtual wxDataViewItem GetNextSibling( const wxDataViewItem &item ) const
|
||||
{
|
||||
MyMusicModelNode *node = (MyMusicModelNode*) item.GetID();
|
||||
MyMusicModelNode *parent = node->GetParent();
|
||||
if (!parent)
|
||||
|
||||
// "MyMusic" has no siblings in our model
|
||||
if (node == m_root)
|
||||
return wxDataViewItem(0);
|
||||
|
||||
MyMusicModelNode *parent = node->GetParent();
|
||||
int pos = parent->GetChildren().Index( node );
|
||||
|
||||
// Something went wrong
|
||||
if (pos == wxNOT_FOUND)
|
||||
return wxDataViewItem(0);
|
||||
|
||||
// No more children
|
||||
if (pos == parent->GetChildCount()-1)
|
||||
return wxDataViewItem(0);
|
||||
|
||||
|
@ -148,12 +148,12 @@ void wxDataViewModel::RemoveNotifier( wxDataViewModelNotifier *notifier )
|
||||
int wxDataViewModel::Compare( const wxDataViewItem &item1, const wxDataViewItem &item2 )
|
||||
{
|
||||
// sort branches before leaves
|
||||
bool item1_has_children = HasChildren(item1);
|
||||
bool item2_has_children = HasChildren(item2);
|
||||
bool item1_is_container = IsContainer(item1);
|
||||
bool item2_is_container = IsContainer(item2);
|
||||
|
||||
if (item1_has_children && !item2_has_children)
|
||||
if (item1_is_container && !item2_is_container)
|
||||
return 1;
|
||||
if (item2_has_children && !item1_has_children)
|
||||
if (item2_is_container && !item1_is_container)
|
||||
return -1;
|
||||
|
||||
wxVariant value1,value2;
|
||||
|
@ -2307,7 +2307,7 @@ gboolean wxDataViewCtrlInternal::iter_children( GtkTreeIter *iter, GtkTreeIter *
|
||||
{
|
||||
wxDataViewItem item( (void*) parent->user_data );
|
||||
|
||||
if (!m_wx_model->HasChildren( item ))
|
||||
if (!m_wx_model->IsContainer( item ))
|
||||
return FALSE;
|
||||
|
||||
wxGtkTreeModelNode *parent_node = FindNode( parent );
|
||||
@ -2327,7 +2327,7 @@ gboolean wxDataViewCtrlInternal::iter_children( GtkTreeIter *iter, GtkTreeIter *
|
||||
gboolean wxDataViewCtrlInternal::iter_has_child( GtkTreeIter *iter )
|
||||
{
|
||||
wxDataViewItem item( (void*) iter->user_data );
|
||||
bool res = m_wx_model->HasChildren( item );
|
||||
bool res = m_wx_model->IsContainer( item );
|
||||
|
||||
if (!res)
|
||||
return FALSE;
|
||||
@ -2342,7 +2342,7 @@ gint wxDataViewCtrlInternal::iter_n_children( GtkTreeIter *iter )
|
||||
{
|
||||
wxDataViewItem item( (void*) iter->user_data );
|
||||
|
||||
if (!m_wx_model->HasChildren( item ))
|
||||
if (!m_wx_model->IsContainer( item ))
|
||||
return 0;
|
||||
|
||||
wxGtkTreeModelNode *parent_node = FindNode( iter );
|
||||
@ -2359,7 +2359,7 @@ gboolean wxDataViewCtrlInternal::iter_nth_child( GtkTreeIter *iter, GtkTreeIter
|
||||
if (parent) id = (void*) parent->user_data;
|
||||
wxDataViewItem item( id );
|
||||
|
||||
if (!m_wx_model->HasChildren( item ))
|
||||
if (!m_wx_model->IsContainer( item ))
|
||||
return FALSE;
|
||||
|
||||
wxGtkTreeModelNode *parent_node = FindNode( parent );
|
||||
|
Loading…
Reference in New Issue
Block a user