From 74fe973bba96bbc36abe8fda44ae23bebcd7a4cc Mon Sep 17 00:00:00 2001 From: Robert Roebling Date: Fri, 31 Aug 2007 09:44:59 +0000 Subject: [PATCH] Added wxDataViewModel::GetChildren() (removed GetSibling() and GetFirstChild()) git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@48508 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- docs/latex/wx/dataviewmodel.tex | 14 ++++------ include/wx/dataview.h | 6 ++--- samples/dataview/dataview.cpp | 48 +++++++++++++-------------------- src/common/datavcmn.cpp | 27 +++++-------------- src/gtk/dataview.cpp | 10 ++++--- 5 files changed, 37 insertions(+), 68 deletions(-) diff --git a/docs/latex/wx/dataviewmodel.tex b/docs/latex/wx/dataviewmodel.tex index 662f99c131..69cab3a75f 100644 --- a/docs/latex/wx/dataviewmodel.tex +++ b/docs/latex/wx/dataviewmodel.tex @@ -8,6 +8,7 @@ pure virtual functions in order to define a complete data model. In detail, you need to override \helpref{IsContainer}{wxdataviewmodeliscontainer}, \helpref{GetParent}{wxdataviewmodelgetparent}, +\helpref{GetChildren}{wxdataviewmodelgetchildren}, \helpref{GetColumnCount}{wxdataviewmodelgetcolumncount}, \helpref{GetColumnType}{wxdataviewmodelgetcolumntype} and \helpref{GetValue}{wxdataviewmodelgetvalue} in order to @@ -125,17 +126,12 @@ Override this to indicate what type of data is stored in the column specified by {\it col}. This should return a string indicating the type of data as reported by \helpref{wxVariant}{wxvariant}. -\membersection{wxDataViewModel::GetFirstChild}\label{wxdataviewmodelgetfirstchild} +\membersection{wxDataViewModel::GetChildren}\label{wxdataviewmodelgetfirstchild} -\constfunc{wxDataViewItem}{GetFirstChild}{\param{const wxDataViewItem\& }{parent}} +\constfunc{unsigned int}{GetChildren}{\param{const wxDataViewItem\& }{item}, \param{wxDataViewItemArray\& }{children} } -To be removed. - -\membersection{wxDataViewModel::GetNextSibling}\label{wxdataviewmodelgetnextsibling} - -\constfunc{wxDataViewItem}{GetNextSibling}{\param{const wxDataViewItem\& }{item}} - -To be removed. +Override this so the control can query the child items of +an item. Returns the number of items. \membersection{wxDataViewModel::GetParent}\label{wxdataviewmodelgetparent} diff --git a/include/wx/dataview.h b/include/wx/dataview.h index 17544e7d53..4f8540fc4c 100644 --- a/include/wx/dataview.h +++ b/include/wx/dataview.h @@ -138,8 +138,7 @@ public: // define hierachy 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; + virtual unsigned int GetChildren( const wxDataViewItem &item, wxDataViewItemArray &children ) const = 0; // delegated notifiers virtual bool ItemAdded( const wxDataViewItem &parent, const wxDataViewItem &item ); @@ -210,8 +209,7 @@ public: const wxDataViewItem &item, unsigned int col ); virtual wxDataViewItem GetParent( const wxDataViewItem &item ) const; virtual bool IsContainer( const wxDataViewItem &item ) const; - virtual wxDataViewItem GetFirstChild( const wxDataViewItem &parent ) const; - virtual wxDataViewItem GetNextSibling( const wxDataViewItem &item ) const; + virtual unsigned int GetChildren( const wxDataViewItem &item, wxDataViewItemArray &children ) const; private: wxDataViewItemArray m_hash; diff --git a/samples/dataview/dataview.cpp b/samples/dataview/dataview.cpp index 8b1e24f85f..adb6e6f49e 100644 --- a/samples/dataview/dataview.cpp +++ b/samples/dataview/dataview.cpp @@ -333,48 +333,36 @@ public: return node->IsContainer(); } - virtual wxDataViewItem GetFirstChild( const wxDataViewItem &parent ) const + virtual unsigned int GetChildren( const wxDataViewItem &parent, wxDataViewItemArray &array ) const { MyMusicModelNode *node = (MyMusicModelNode*) parent.GetID(); if (!node) - return wxDataViewItem( (void*) m_root ); + { + array.Add( wxDataViewItem( (void*) m_root ) ); + return 1; + } - if (node->GetChildCount() == 0) - return wxDataViewItem( 0 ); - if (node == m_classical) { MyMusicModel *model = (MyMusicModel*)(const MyMusicModel*) this; model->m_classicalMusicIsKnownToControl = true; } - MyMusicModelNode *first_child = node->GetChildren().Item( 0 ); - return wxDataViewItem( (void*) first_child ); + if (node->GetChildCount() == 0) + { + return 0; + } + + unsigned int count = node->GetChildren().GetCount(); + unsigned int pos; + for (pos = 0; pos < count; pos++) + { + MyMusicModelNode *child = node->GetChildren().Item( pos ); + array.Add( wxDataViewItem( (void*) child ) ); + } + return count; } - virtual wxDataViewItem GetNextSibling( const wxDataViewItem &item ) const - { - MyMusicModelNode *node = (MyMusicModelNode*) item.GetID(); - - // "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); - - node = parent->GetChildren().Item( pos+1 ); - return wxDataViewItem( (void*) node ); - } - private: MyMusicModelNode* m_root; MyMusicModelNode* m_pop; diff --git a/src/common/datavcmn.cpp b/src/common/datavcmn.cpp index c8fc22960d..9a21003099 100644 --- a/src/common/datavcmn.cpp +++ b/src/common/datavcmn.cpp @@ -307,29 +307,14 @@ bool wxDataViewIndexListModel::IsContainer( const wxDataViewItem &item ) const return false; } -wxDataViewItem wxDataViewIndexListModel::GetFirstChild( const wxDataViewItem &parent ) const +unsigned int wxDataViewIndexListModel::GetChildren( const wxDataViewItem &item, wxDataViewItemArray &children ) const { - if (!parent.IsOk()) - { - if (m_hash.GetCount() == 0) - return wxDataViewItem(0); - - return wxDataViewItem( m_hash[0]); - } - - return wxDataViewItem(0); -} + if (item.IsOk()) + return 0; -wxDataViewItem wxDataViewIndexListModel::GetNextSibling( const wxDataViewItem &item ) const -{ - if (!item.IsOk()) - return wxDataViewItem(0); - - int pos = m_hash.Index( item.GetID() ); - if ((pos == wxNOT_FOUND) || (pos == (int) (m_hash.GetCount()-1))) - return wxDataViewItem(0); - - return wxDataViewItem( m_hash[pos+1] ); + children = m_hash; + + return m_hash.GetCount(); } //----------------------------------------------------------------------------- diff --git a/src/gtk/dataview.cpp b/src/gtk/dataview.cpp index ef2990497a..9b7df0db61 100644 --- a/src/gtk/dataview.cpp +++ b/src/gtk/dataview.cpp @@ -2380,17 +2380,19 @@ void wxDataViewCtrlInternal::BuildBranch( wxGtkTreeModelNode *node ) { if (node->GetChildCount() == 0) { - wxDataViewItem child = m_wx_model->GetFirstChild( node->GetItem() ); - while (child.IsOk()) + wxDataViewItemArray children; + unsigned int count = m_wx_model->GetChildren( node->GetItem(), children ); + unsigned int pos; + for (pos = 0; pos < count; pos++) { + wxDataViewItem child = children[pos]; + if (m_wx_model->IsContainer( child )) node->AddNode( new wxGtkTreeModelNode( node, child, this ) ); else node->AddLeave( child.GetID() ); // Don't send any events here - - child = m_wx_model->GetNextSibling( child ); } } } -- 2.45.2