On Wed, 11 Aug 2021 12:49:56 -0700 (PDT) Pedro Bastos das Neves wrote:
PBdN> I'm trying to make a custom dialog where I use a wxDataViewCtrl with
PBdN> a custom model deriving from wxDataviewModel folowing the dataview
PBdN> sample. I have a button for adding nodes dynamically to the dataview.
PBdN> In debug mode, when I do ItemAdded( parent, child ) the code returns the message "assert "parent_node" failed in ItemAdded(): Did you forget a call to ItemAdded()? The parent node is unknown to the wxGtkTreeModel".
PBdN> The dataview starts only with the root node that is added in the
PBdN> model constructor, so it is known to the model. I can't understand
PBdN> why it complains that the parent is unknown to the model.
Have you checked the value of the "parent"? From your explanation it looks
like you expect it to be equal to the root node, but it clearly isn't. And
if it's not the root node, have you called ItemAdded() for the parent
itself first?
PBdN> At the forum they suggested viewing the source code to try to
PBdN> understand the source of the problem,
Yes, this is always a good idea and one of big advantages of using open
source libraries.
PBdN> The source code for this method is:
PBdN> static wxGtkTreeModelNode*
PBdN> wxDataViewCtrlInternal_FindNode( wxDataViewModel * model, wxGtkTreeModelNode *treeNode, const wxDataViewItem &item )
PBdN> {
PBdN> if( model == NULL )
PBdN> return NULL;
PBdN> ItemList list;
PBdN> list.DeleteContents( true );
PBdN> wxDataViewItem it( item );
PBdN> while( it.IsOk() )
PBdN> {
PBdN> wxDataViewItem * pItem = new wxDataViewItem( it );
PBdN> list.Insert( pItem );
PBdN> it = model->GetParent( it );
PBdN> }
PBdN> wxGtkTreeModelNode * node = treeNode;
PBdN> for( ItemList::compatibility_iterator n = list.GetFirst(); n; n = n->GetNext() )
PBdN> {
PBdN> if( node && node->GetNodes().GetCount() != 0 )
PBdN> {
PBdN> int len = node->GetNodes().GetCount();
PBdN> wxGtkTreeModelNodes &nodes = node->GetNodes();
PBdN> int j = 0;
PBdN> for( ; j < len; j ++)
PBdN> {
PBdN> if( nodes[j]->GetItem() == *(n->GetData()))
PBdN> {
PBdN> node = nodes[j];
PBdN> break;
PBdN> }
PBdN> }
PBdN> if( j == len )
PBdN> {
PBdN> return NULL;
PBdN> }
PBdN> }
PBdN> else
PBdN> return NULL;
PBdN> }
PBdN> return node;
PBdN> }
PBdN> This code construct a list with the node passed as parent do
PBdN> ItemAdded and all his parents to compare with the root node children.
PBdN> But, as far is my understanding, the for loop for(
PBdN> ItemList::compatibility_iterator n = list.GetFirst(); n; n =
PBdN> n->GetNext() ) is only executed once and never repeats itself because
PBdN> when j == len in the first iteration the method returns NULL.
It only does this if it doesn't find the parent at this level. For the
search to succeed, it must find all elements of the path to the item.
PBdN> Isn't this a bug? I believe that's because of this behavior that I'm
PBdN> receiving the assert message.
No, or at least I don't see any bug here. If you still think there is a
problem in wxGTK itself, please try reproducing it in the dataview sample
with the minimal modifications and post a patch showing the problem.
Regards,
VZ
--
TT-Solutions: wxWidgets consultancy and technical support
http://www.tt-solutions.com/