<commit_before>/******************************************************************************
 * This file is part of the Gluon Development Platform
 * Copyright (c) 2009 <NAME> <<EMAIL>>
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 * 
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 * 
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
 */
#include "gluonobject.h"
#include "gluonobjectprivate.h"
#include "debughelper.h"
#include "gluonvarianttypes.h"

#include <QtCore/QVariant>
#include <QtCore/QPointF>
#include <QtGui/QColor>
#include <QtGui/QVector3D>
#include <QtCore/QDebug>
#include <QtCore/QMetaClassInfo>
#include <QSizeF>

REGISTER_OBJECTTYPE(GluonCore, GluonObject)

using namespace GluonCore;

static int qlist_qurl_typeID = qRegisterMetaType< QList<QUrl> >();

GluonObject::GluonObject(QObject * parent)
        : QObject(parent)
{
    d = new GluonObjectPrivate();

    // Get a nice name first time the object is created...
    QString theClassName(metaObject()->className());
    if (theClassName.contains(':'))
        setName(theClassName.right(theClassName.length() - theClassName.lastIndexOf(':') - 1));
    else
        setName(theClassName);
}

GluonObject::GluonObject(const QString& name, QObject* parent)
        : QObject(parent)
{
    d = new GluonObjectPrivate();
    setName(name);
}

GluonObject::GluonObject(const GluonCore::GluonObject& rt)
{
    d = new GluonObjectPrivate(*rt.d);
}

GluonObject::~GluonObject()
{
}

void
GluonObject::debug(const QString& debugText) const
{
    DEBUG_BLOCK
    DEBUG_TEXT(debugText);
    emit showDebug(QString("%1: %2").arg(fullyQualifiedName()).arg(debugText));
}

GluonObject*
GluonObject::clone() const
{
    const QMetaObject* metaObj = metaObject();
    if(!metaObj)
        debug(QString("Failed to get the meta object for object %1").arg(fullyQualifiedName()));

    // Find my parent...
    GluonObject* parentObject = qobject_cast<GluonObject*>(parent());
    if(!parentObject)
        return 0;

    return clone(parentObject);
}

GluonObject*
GluonObject::clone(GluonObject* parentObject) const
{
    const QMetaObject* metaObj = metaObject();
    if(!metaObj)
        debug(QString("Failed to get the meta object for object %1").arg(fullyQualifiedName()));

    GluonObject* newObject = GluonObjectFactory::instance()->instantiateObjectByName(metaObj->className());
    parentObject->addChild(newObject);

    // Clone all the children
    foreach(QObject* child, children())
    {
        GluonObject* childObject = qobject_cast<GluonObject*>(child);
        if(childObject)
        {
            childObject->clone(newObject);
        }
    }

    // Copy over the values from pre-defined properties
    int count = metaObj->propertyCount();
    for (int i = 0; i < count; ++i)
    {
        QMetaProperty metaproperty = metaObj->property(i);
        newObject->setProperty(metaproperty.name(), metaproperty.read(this));
    }

    // Copy values from dynamic properties
    QList<QByteArray> propertyNames = dynamicPropertyNames();
    foreach(const QByteArray &propName, propertyNames)
    {
        newObject->setProperty(propName, property(propName));
    }

    #warning Clones with properties pointing to children should point to new children rather than the old children

    // In case any object is doing something clever with its children, make sure it's allowed to do that on cloning as well
    newObject->postCloneSanitize();
    return newObject;
}

void
GluonObject::sanitize()
{
    DEBUG_BLOCK
//    DEBUG_TEXT(QString("Sanitizing the object %1 with %2 children").arg(this->fullyQualifiedName()).arg(this->children().count()));

    const QObjectList &children = this->children();
    foreach(QObject * child, children)
    {<commit_msg>Fix krazy issues for "cpp" test<commit_after>/******************************************************************************
 * This file is part of the Gluon Development Platform
 * Copyright (c) 2009 <NAME> <<EMAIL>>
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 * 
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 * 
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
 */
#include "gluonobject.h"
#include "gluonobjectprivate.h"
#include "debughelper.h"
#include "gluonvarianttypes.h"

#include <QtCore/QVariant>
#include <QtCore/QPointF>
#include <QtGui/QColor>
#include <QtGui/QVector3D>
#include <QtCore/QDebug>
#include <QtCore/QMetaClassInfo>
#include <QSizeF>

REGISTER_OBJECTTYPE(GluonCore, GluonObject)

using namespace GluonCore;

static int qlist_qurl_typeID = qRegisterMetaType< QList<QUrl> >();

GluonObject::GluonObject(QObject * parent)
        : QObject(parent)
{
    d = new GluonObjectPrivate();

    // Get a nice name first time the object is created...
    QString theClassName(metaObject()->className());
    if (theClassName.contains(':'))
        setName(theClassName.right(theClassName.length() - theClassName.lastIndexOf(':') - 1));
    else
        setName(theClassName);
}

GluonObject::GluonObject(const QString& name, QObject* parent)
        : QObject(parent)
{
    d = new GluonObjectPrivate();
    setName(name);
}

GluonObject::GluonObject(const GluonCore::GluonObject& rt)
{
    d = new GluonObjectPrivate(*rt.d);
}

GluonObject::~GluonObject()
{
}

void
GluonObject::debug(const QString& debugText) const
{
    DEBUG_BLOCK
    DEBUG_TEXT(debugText);
    emit showDebug(QString("%1: %2").arg(fullyQualifiedName()).arg(debugText));
}

GluonObject*
GluonObject::clone() const
{
    const QMetaObject* metaObj = metaObject();
    if(!metaObj)
        debug(QString("Failed to get the meta object for object %1").arg(fullyQualifiedName()));

    // Find my parent...
    GluonObject* parentObject = qobject_cast<GluonObject*>(parent());
    if(!parentObject)
        return 0;

    return clone(parentObject);
}

GluonObject*
GluonObject::clone(GluonObject* parentObject) const
{
    const QMetaObject* metaObj = metaObject();
    if(!metaObj)
        debug(QString("Failed to get the meta object for object %1").arg(fullyQualifiedName()));

    GluonObject* newObject = GluonObjectFactory::instance()->instantiateObjectByName(metaObj->className());
    parentObject->addChild(newObject);

    // Clone all the children
    foreach(QObject* child, children())
    {
        GluonObject* childObject = qobject_cast<GluonObject*>(child);
        if(childObject)
        {
            childObject->clone(newObject);
        }
    }

    // Copy over the values from pre-defined properties
    int count = metaObj->propertyCount();
    for (int i = 0; i < count; ++i)
    {
        QMetaProperty metaproperty = metaObj->property(i);
        newObject->setProperty(metaproperty.name(), metaproperty.read(this));
    }

    // Copy values from dynamic properties
    QList<QByteArray> propertyNames = dynamicPropertyNames();
    foreach(const QByteArray &propName, propertyNames)
    {
        newObject->setProperty(propName, property(propName));
    }

    #ifdef __GNUC__
    #warning Clones with properties pointing to children should point to new children rather than the old children
    #endif

    // In case any object is doing something clever with its children, make sure it's allowed to do that on cloning as well
    newObject->postCloneSanitize();
    return newObject;
}

void
GluonObject::sanitize()
{
    DEBUG_BLOCK
//    DEBUG_TEXT(QString("Sanitizing the object %1 with %2 children").arg(this->fullyQualifiedName()).arg(this->children().count()));

    const QObjectList &children = this->children();
    foreach(QObject * child, children)
    {
{'fraction_non_alphanumeric': 0.1265619626275364, 'fraction_numerical': 0.006190530780694715, 'mean_word_length': 4.063261752756819, 'pattern_counts': {'":': 0, '<': 35, '<?xml version=': 0, '>': 59, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2807227', 'n_tokens_mistral': 2614, 'n_tokens_neox': 2493, 'n_words': 752}