mirror of
https://github.com/AxioDL/PrimeWorldEditor.git
synced 2025-12-17 17:05:37 +00:00
50 lines
1.3 KiB
C++
50 lines
1.3 KiB
C++
#include "CPropertyNameValidator.h"
|
|
#include "UICommon.h"
|
|
#include <Common/Hash/CCRC32.h>
|
|
|
|
CPropertyNameValidator::CPropertyNameValidator(QObject* pParent)
|
|
: QValidator(pParent)
|
|
{}
|
|
|
|
/** Set the property to validate against */
|
|
void CPropertyNameValidator::SetProperty(IProperty* pProp)
|
|
{
|
|
mpProperty = pProp;
|
|
emit changed();
|
|
}
|
|
|
|
/** Set the type name override */
|
|
void CPropertyNameValidator::SetTypeNameOverride(const QString& kNewTypeName)
|
|
{
|
|
mTypeNameOverride = kNewTypeName;
|
|
emit changed();
|
|
}
|
|
|
|
/** Perform validation */
|
|
QValidator::State CPropertyNameValidator::validate(QString& rInput, int&) const
|
|
{
|
|
if (!mpProperty)
|
|
return QValidator::Invalid;
|
|
|
|
const TString TypeName = mTypeNameOverride.isEmpty() ? mpProperty->HashableTypeName() : TO_TSTRING(mTypeNameOverride);
|
|
const auto InputString = rInput.toStdString();
|
|
|
|
CCRC32 Hash;
|
|
Hash.Hash(InputString.c_str());
|
|
Hash.Hash(TypeName.Data());
|
|
uint32 PropertyID = Hash.Digest();
|
|
|
|
if (PropertyID != mpProperty->ID())
|
|
{
|
|
if (mpProperty->Type() == EPropertyType::Int)
|
|
{
|
|
CCRC32 Hash2;
|
|
Hash2.Hash(InputString.c_str());
|
|
Hash2.Hash("choice");
|
|
PropertyID = Hash2.Digest();
|
|
}
|
|
}
|
|
|
|
return PropertyID == mpProperty->ID() ? QValidator::Acceptable : QValidator::Invalid;
|
|
}
|