<commit_before>#include "MultiProperty.h"

#include "Config.h"
#include "PropertyConnector.h"
#include "Delegates/PropertyDelegateFactory.h"
#include "Delegates/Core/PropertyDelegateBool.h"

#include <QStyleOption>
#include <QKeyEvent>

QtnMultiProperty::QtnMultiProperty(const QMetaObject *propertyMetaObject, QObject *parent)
	: QtnProperty(parent)
	, propertyMetaObject(propertyMetaObject)
	, calculateMultipleValues(true)
	, multipleValues(false)
{

}

QtnMultiProperty::~QtnMultiProperty()
{
	for (auto property : properties)
	{
		QObject::disconnect(property, &QtnProperty::propertyValueAccept,
							this, &QtnMultiProperty::onPropertyValueAccept);
		QObject::disconnect(property, &QtnPropertyBase::propertyWillChange,
							this, &QtnMultiProperty::onPropertyWillChange);
		QObject::disconnect(property, &QtnPropertyBase::propertyDidChange,
							this, &QtnMultiProperty::onPropertyDidChange);
	}
}

void QtnMultiProperty::addProperty(QtnProperty *property, bool own)
{
	Q_ASSERT(nullptr != property);
	Q_ASSERT(nullptr != propertyMetaObject->cast(property));

	if (own)
		property->setParent(this);

	if (properties.end() != std::find(properties.begin(), properties.end(), property))
		return;

	properties.push_back(property);

	QObject::connect(property, &QtnProperty::propertyValueAccept,
					 this, &QtnMultiProperty::onPropertyValueAccept);
	QObject::connect(property, &QtnPropertyBase::propertyWillChange,
					 this, &QtnMultiProperty::onPropertyWillChange);
	QObject::connect(property, &QtnPropertyBase::propertyDidChange,
					 this, &QtnMultiProperty::onPropertyDidChange);
}

void QtnMultiProperty::resetValues()
{
	for (auto property : properties)
	{
		auto connector = property->getConnector();

		if (nullptr != connector)
			connector->resetPropertyValue();
	}

	updateMultipleState(true);
	emit propertyDidChange(QtnPropertyChangeReasonNewValue);
}

bool QtnMultiProperty::hasResettableValues() const
{
	for (auto property : properties)
	{
		auto connector = property->getConnector();

		if (nullptr != connector && connector->isResettablePropertyValue())
			return true;
	}

	return false;
}

void QtnMultiProperty::Register()
{
	qRegisterMetaType<QtnMultiVariant>();

	QtnPropertyDelegateFactory::staticInstance()
		.registerDelegateDefault(&QtnMultiProperty::staticMetaObject
		, &qtnCreateDelegate<QtnMultiPropertyDelegate, QtnMultiProperty>
		, "MultiProperty");
}

QString QtnMultiProperty::getMultiValuePlaceholder()
{
	return tr("(Multiple Values)");
}

QMetaProperty QtnMultiProperty::getMetaProperty() const
{
	Q_ASSERT(!properties.empty());

	auto connector = properties.at(0)->getConnector();
	Q_ASSERT(nullptr != connector);

	return connector->getMetaProperty();

}

bool QtnMultiProperty::hasMultipleValues() const
{
	if (calculateMultipleValues)
	{
		QString dummy;
		toStrImpl(dummy);
	}

	return multipleValues;
}

void QtnMultiProperty::onPropertyValueAccept(QtnPropertyValuePtr valueToAccept, bool *accept)
{
	emit propertyValueAccept(valueToAccept, accept);
}

void QtnMultiProperty::onPropertyWillChange(QtnPropertyChangeReason reason,
											QtnPropertyValuePtr newValue,
											int typeId)
{
	emit propertyWillChange(reason, newValue, typeId);
}

void QtnMultiProperty::onPropertyDidChange(QtnPropertyChangeReason reason)
{
	if (0 != (reason & QtnPropertyChangeReasonStateInherited)
	||	0 != (reason & QtnPropertyChangeReasonValue))
	{
		updateMultipleState(true);
	}

	emit propertyDidChange(reason);
}

bool QtnMultiProperty::loadImpl(QDataStream &stream)
{
	for (auto property : properties)
	{
		QByteArray propertyData;
		stream >> propertyData;
		QDataStream propertyStream(&propertyData, QIODevice::ReadOnly);
		if (!property->load(propertyStream))
			return false;
	}

	return true;
}

bool QtnMultiProperty::saveImpl(QDataStream &stream) const
{
	for (auto property : properties)
	{
		QByteArray propertyData;<commit_msg>MultiProperty state update fix<commit_after>#include "MultiProperty.h"

#include "Config.h"
#include "PropertyConnector.h"
#include "Delegates/PropertyDelegateFactory.h"
#include "Delegates/Core/PropertyDelegateBool.h"

#include <QStyleOption>
#include <QKeyEvent>

QtnMultiProperty::QtnMultiProperty(const QMetaObject *propertyMetaObject, QObject *parent)
	: QtnProperty(parent)
	, propertyMetaObject(propertyMetaObject)
	, calculateMultipleValues(true)
	, multipleValues(false)
{

}

QtnMultiProperty::~QtnMultiProperty()
{
	for (auto property : properties)
	{
		QObject::disconnect(property, &QtnProperty::propertyValueAccept,
							this, &QtnMultiProperty::onPropertyValueAccept);
		QObject::disconnect(property, &QtnPropertyBase::propertyWillChange,
							this, &QtnMultiProperty::onPropertyWillChange);
		QObject::disconnect(property, &QtnPropertyBase::propertyDidChange,
							this, &QtnMultiProperty::onPropertyDidChange);
	}
}

void QtnMultiProperty::addProperty(QtnProperty *property, bool own)
{
	Q_ASSERT(nullptr != property);
	Q_ASSERT(nullptr != propertyMetaObject->cast(property));

	if (own)
		property->setParent(this);

	if (properties.end() != std::find(properties.begin(), properties.end(), property))
		return;

	properties.push_back(property);

	QObject::connect(property, &QtnProperty::propertyValueAccept,
					 this, &QtnMultiProperty::onPropertyValueAccept);
	QObject::connect(property, &QtnPropertyBase::propertyWillChange,
					 this, &QtnMultiProperty::onPropertyWillChange);
	QObject::connect(property, &QtnPropertyBase::propertyDidChange,
					 this, &QtnMultiProperty::onPropertyDidChange);
}

void QtnMultiProperty::resetValues()
{
	for (auto property : properties)
	{
		auto connector = property->getConnector();

		if (nullptr != connector)
			connector->resetPropertyValue();
	}

	updateMultipleState(true);
	emit propertyDidChange(QtnPropertyChangeReasonNewValue);
}

bool QtnMultiProperty::hasResettableValues() const
{
	for (auto property : properties)
	{
		auto connector = property->getConnector();

		if (nullptr != connector && connector->isResettablePropertyValue())
			return true;
	}

	return false;
}

void QtnMultiProperty::Register()
{
	qRegisterMetaType<QtnMultiVariant>();

	QtnPropertyDelegateFactory::staticInstance()
		.registerDelegateDefault(&QtnMultiProperty::staticMetaObject
		, &qtnCreateDelegate<QtnMultiPropertyDelegate, QtnMultiProperty>
		, "MultiProperty");
}

QString QtnMultiProperty::getMultiValuePlaceholder()
{
	return tr("(Multiple Values)");
}

QMetaProperty QtnMultiProperty::getMetaProperty() const
{
	Q_ASSERT(!properties.empty());

	auto connector = properties.at(0)->getConnector();
	Q_ASSERT(nullptr != connector);

	return connector->getMetaProperty();

}

bool QtnMultiProperty::hasMultipleValues() const
{
	if (calculateMultipleValues)
	{
		QString dummy;
		toStrImpl(dummy);
	}

	return multipleValues;
}

void QtnMultiProperty::onPropertyValueAccept(QtnPropertyValuePtr valueToAccept, bool *accept)
{
	emit propertyValueAccept(valueToAccept, accept);
}

void QtnMultiProperty::onPropertyWillChange(QtnPropertyChangeReason reason,
											QtnPropertyValuePtr newValue,
											int typeId)
{
	emit propertyWillChange(reason, newValue, typeId);
}

void QtnMultiProperty::onPropertyDidChange(QtnPropertyChangeReason reason)
{
	if (0 != (reason & (QtnPropertyChangeReasonState | QtnPropertyChangeReasonValue)))
	{
		updateMultipleState(true);
	}

	emit propertyDidChange(reason);
}

bool QtnMultiProperty::loadImpl(QDataStream &stream)
{
	for (auto property : properties)
	{
		QByteArray propertyData;
		stream >> propertyData;
		QDataStream propertyStream(&propertyData, QIODevice::ReadOnly);
		if (!property->load(propertyStream))
			return false;
	}

	return true;
}

bool QtnMultiProperty::saveImpl(QDataStream &stream) const
{
	for (auto property : properties)
	{
		QByteArray propertyData;
{'fraction_non_alphanumeric': 0.11502830674215131, 'fraction_numerical': 0.0006433350488934637, 'mean_word_length': 7.088449531737774, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 33, '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': '2858712', 'n_tokens_mistral': 2528, 'n_tokens_neox': 2350, 'n_words': 402}