<commit_before>// For conditions of distribution and use, see copyright notice in license.txt

#include "StableHeaders.h"
#include "DebugOperatorNew.h"

#include "ECAttributeEditor.h"
#include "MultiEditPropertyManager.h"
#include "MultiEditPropertyFactory.h"
#include "LineEditPropertyFactory.h"

#include "IComponent.h"
#include "IAttribute.h"
#include "Transform.h"
#include "AssetReference.h"

// QtPropertyBrowser headers.
#include <qtvariantproperty.h>
#include <qtpropertymanager.h>
#include <qtpropertybrowser.h>
#include <qteditorfactory.h>

#include "LoggingFunctions.h"
DEFINE_POCO_LOGGING_FUNCTIONS("ECAttributeEditor")

#include "MemoryLeakCheck.h"

ECAttributeEditorBase::ECAttributeEditorBase(QtAbstractPropertyBrowser *owner,
                                             ComponentPtr component,
                                             const QString &name,
                                             const QString &type,
                                             QObject *parent):
    QObject(parent),
    owner_(owner),
    name_(name),
    typeName_(type),
    rootProperty_(0),
    factory_(0),
    propertyMgr_(0),
    listenEditorChangedSignal_(false),
    useMultiEditor_(false),
    metaDataFlag_(0)
{
    AddComponent(component);
}

ECAttributeEditorBase::~ECAttributeEditorBase()
{
    UnInitialize();
}

bool ECAttributeEditorBase::ContainsProperty(QtProperty *property) const
{
    QSet<QtProperty *> properties = propertyMgr_->properties();
    QSet<QtProperty *>::const_iterator iter = properties.find(property);
    if(iter != properties.end())
        return true;
    return false;
}

void ECAttributeEditorBase::UpdateEditorUI(IAttribute *attr)
{
    PROFILE(ECAttributeEditor_UpdateEditorUI);
    // If attribute editor is holding only single component, "HasIdenticalAttributes" method should automaticly return true.
    bool identical_attr = HasIdenticalAttributes();
    if (!useMultiEditor_ && !identical_attr)
    {
        useMultiEditor_ = true;
        UnInitialize();
        Initialize();
    }
    else if(useMultiEditor_ && identical_attr)
    {
        useMultiEditor_ = false;
        UnInitialize();
        Initialize();
    }
    else
    {
        if (!propertyMgr_)
            Initialize();
        else
        {
            listenEditorChangedSignal_ = false;
            Update(attr);<commit_msg>ECEditor: Add a feature that attributes check designable from metadata when the attribute has changed. If a attribute is hidden during run time the EC editor (hidden and visible ones) respect the new metadata if the attribute should be shown in the editor.<commit_after>// For conditions of distribution and use, see copyright notice in license.txt

#include "StableHeaders.h"
#include "DebugOperatorNew.h"

#include "ECAttributeEditor.h"
#include "MultiEditPropertyManager.h"
#include "MultiEditPropertyFactory.h"
#include "LineEditPropertyFactory.h"

#include "IComponent.h"
#include "IAttribute.h"
#include "Transform.h"
#include "AssetReference.h"

// QtPropertyBrowser headers.
#include <qtvariantproperty.h>
#include <qtpropertymanager.h>
#include <qtpropertybrowser.h>
#include <qteditorfactory.h>

#include "LoggingFunctions.h"
DEFINE_POCO_LOGGING_FUNCTIONS("ECAttributeEditor")

#include "MemoryLeakCheck.h"

ECAttributeEditorBase::ECAttributeEditorBase(QtAbstractPropertyBrowser *owner,
                                             ComponentPtr component,
                                             const QString &name,
                                             const QString &type,
                                             QObject *parent):
    QObject(parent),
    owner_(owner),
    name_(name),
    typeName_(type),
    rootProperty_(0),
    factory_(0),
    propertyMgr_(0),
    listenEditorChangedSignal_(false),
    useMultiEditor_(false),
    metaDataFlag_(0)
{
    AddComponent(component);
}

ECAttributeEditorBase::~ECAttributeEditorBase()
{
    UnInitialize();
}

bool ECAttributeEditorBase::ContainsProperty(QtProperty *property) const
{
    QSet<QtProperty *> properties = propertyMgr_->properties();
    QSet<QtProperty *>::const_iterator iter = properties.find(property);
    if(iter != properties.end())
        return true;
    return false;
}

void ECAttributeEditorBase::UpdateEditorUI(IAttribute *attr)
{
    PROFILE(ECAttributeEditor_UpdateEditorUI);
    
    // Check if the attributes metadata has changed designable to false
    if (!useMultiEditor_ && !components_.empty())
    {
        ComponentPtr comp = components_[0].lock();
        IAttribute *attribute = FindAttribute(comp);
        if (attribute && attribute->HasMetadata() && !attribute->GetMetadata()->designable)
        {
            // If not uninitialize that attributes ui and return
            UnInitialize();
            return;
        }
    }

    // If attribute editor is holding only single component, "HasIdenticalAttributes" method should automaticly return true.
    bool identical_attr = HasIdenticalAttributes();
    if (!useMultiEditor_ && !identical_attr)
    {
        useMultiEditor_ = true;
        UnInitialize();
        Initialize();
    }
    else if(useMultiEditor_ && identical_attr)
    {
        useMultiEditor_ = false;
        UnInitialize();
        Initialize();
    }
    else
    {
        if (!propertyMgr_)
            Initialize();
        else
        {
            listenEditorChangedSignal_ = false;
            Update(attr);
{'fraction_non_alphanumeric': 0.09547461368653422, 'fraction_numerical': 0.0016556291390728477, 'mean_word_length': 2.905890804597701, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 20, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 16, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6797679', 'n_tokens_mistral': 1400, 'n_tokens_neox': 1462, 'n_words': 338}