<commit_before>#include <sequanto/QtWidgetNode.h>
#include <sequanto/QtWrapper.h>
#include <sequanto/QtUnnamedObjectStore.h>
#include <sequanto/ui.h>
#include <cassert>

using namespace sequanto::automation;

QtWidgetNode::QtWidgetNode( QWidget * _widget )
    : ListNode(QtWrapper::GetObjectName(_widget) ),
      m_widget(_widget)
{
   m_eventFilter = new QtWidgetAutomationEventFilter(this);
   m_widget->installEventFilter( m_eventFilter );
}

void QtWidgetNode::SendChildrenUpdate ()
{
   ListNode * childrenNode = dynamic_cast<ListNode*>(this->FindChild ( SQ_UI_NODE_CHILDREN ) );
   if ( childrenNode != NULL )
   {
      childrenNode->SendUpdate ();
   }
}

bool QtWidgetNode::AddChildWidget ( QWidget * _child )
{
   ListNode * childrenNode = dynamic_cast<ListNode*>( this->FindChild ( SQ_UI_NODE_CHILDREN ) );
   if ( childrenNode != NULL )
   {
      std::string childName ( QtWrapper::GetObjectName(_child) );
      if ( !childName.empty() )
      {
         if ( !childrenNode->HasChild(childName) )
         {
            if ( QtUnnamedObjectStore::IsKnown ( _child ) )
            {
               std::string unnamedObjectName ( QtUnnamedObjectStore::GetName(_child) );
               if ( childrenNode->HasChild(unnamedObjectName) )
               {
                  childrenNode->RemoveChild ( unnamedObjectName );
                  QtUnnamedObjectStore::Deleted ( _child );
               }
            }
            QtWidgetNode * child = new QtWidgetNode ( _child );
            QtWrapper::WrapUi ( child, qobject_cast<QWidget*>(_child) );
            childrenNode->AddChild ( child );
            return true;
         }
      }
   }
   return false;
}

/*
bool QtWidgetNode::RemoveChildWidget ( QWidget * _child )
{
   ListNode * childrenNode = dynamic_cast<ListNode*>( this->FindChild ( SQ_UI_NODE_CHILDREN ) );
   if ( childrenNode != NULL )
   {
      std::string childName ( QtWrapper::GetObjectName(_child) );
      if ( !childrenNode->HasChild(childName) )
      {
         childrenNode->RemoveChild ( childName );
         return true;
      }
   }
   return false;
}
*/

void QtWidgetNode::WidgetDestroyed()
{
   // If m_widget is NULL we are in the process of being destroyed (~QtWidgetNode is in progress).
   if ( m_widget != NULL )
   {
      QtUnnamedObjectStore::Deleted ( m_widget );
      m_widget = NULL;
      ListNode * parent = dynamic_cast<ListNode*>(this->GetParent());<commit_msg>Report error when trying to add a child with the same name as an already existing one.<commit_after>#include <sequanto/QtWidgetNode.h>
#include <sequanto/QtWrapper.h>
#include <sequanto/QtUnnamedObjectStore.h>
#include <sequanto/ui.h>
#include <cassert>

using namespace sequanto::automation;

QtWidgetNode::QtWidgetNode( QWidget * _widget )
    : ListNode(QtWrapper::GetObjectName(_widget) ),
      m_widget(_widget)
{
   m_eventFilter = new QtWidgetAutomationEventFilter(this);
   m_widget->installEventFilter( m_eventFilter );
}

void QtWidgetNode::SendChildrenUpdate ()
{
   ListNode * childrenNode = dynamic_cast<ListNode*>(this->FindChild ( SQ_UI_NODE_CHILDREN ) );
   if ( childrenNode != NULL )
   {
      childrenNode->SendUpdate ();
   }
}

bool QtWidgetNode::AddChildWidget ( QWidget * _child )
{
   ListNode * childrenNode = dynamic_cast<ListNode*>( this->FindChild ( SQ_UI_NODE_CHILDREN ) );
   if ( childrenNode != NULL )
   {
      std::string childName ( QtWrapper::GetObjectName(_child) );
      if ( !childName.empty() )
      {
         if ( !childrenNode->HasChild(childName) )
         {
            if ( QtUnnamedObjectStore::IsKnown ( _child ) )
            {
               std::string unnamedObjectName ( QtUnnamedObjectStore::GetName(_child) );
               if ( childrenNode->HasChild(unnamedObjectName) )
               {
                  childrenNode->RemoveChild ( unnamedObjectName );
                  QtUnnamedObjectStore::Deleted ( _child );
               }
            }
            QtWidgetNode * child = new QtWidgetNode ( _child );
            QtWrapper::WrapUi ( child, qobject_cast<QWidget*>(_child) );
            childrenNode->AddChild ( child );
            return true;
         }
		 else
		 {
			 QtWrapper::Log ( QString("ERROR: Tried to add the child %1 to the widget %2 but it already contains a child with the given name.").arg(childName.c_str()).arg(GetFullName().c_str()) );
		 }
      }
   }
   return false;
}

/*
bool QtWidgetNode::RemoveChildWidget ( QWidget * _child )
{
   ListNode * childrenNode = dynamic_cast<ListNode*>( this->FindChild ( SQ_UI_NODE_CHILDREN ) );
   if ( childrenNode != NULL )
   {
      std::string childName ( QtWrapper::GetObjectName(_child) );
      if ( !childrenNode->HasChild(childName) )
      {
         childrenNode->RemoveChild ( childName );
         return true;
      }
   }
   return false;
}
*/

void QtWidgetNode::WidgetDestroyed()
{
   // If m_widget is NULL we are in the process of being destroyed (~QtWidgetNode is in progress).
   if ( m_widget != NULL )
   {
      QtUnnamedObjectStore::Deleted ( m_widget );
      m_widget = NULL;
      ListNode * parent = dynamic_cast<ListNode*>(this->GetParent());
{'fraction_non_alphanumeric': 0.1157218001168907, 'fraction_numerical': 0.0003896356906292616, 'mean_word_length': 2.8747169811320754, 'pattern_counts': {'":': 0, '<': 23, '<?xml version=': 0, '>': 47, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5604969', 'n_tokens_mistral': 1541, 'n_tokens_neox': 1524, 'n_words': 296}