You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
o3de/Code/Tools/SceneAPI/SceneUI/RowWidgets/ManifestNameWidget.cpp

119 lines
4.3 KiB
C++

/*
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
* its licensors.
*
* For complete copyright and license terms please see the LICENSE at the root of this
* distribution (the "License"). All use of this software is governed by the License,
* or, if provided, by the license below or the license accompanying this file. Do not
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*
*/
#include <QStyle>
#include <AzFramework/StringFunc/StringFunc.h>
#include <SceneAPI/SceneCore/Containers/Scene.h>
#include <SceneAPI/SceneCore/Containers/SceneManifest.h>
#include <SceneAPI/SceneCore/DataTypes/DataTypeUtilities.h>
#include <SceneAPI/SceneCore/DataTypes/IManifestObject.h>
#include <SceneAPI/SceneUI/SceneWidgets/ManifestWidget.h>
#include <SceneAPI/SceneUI/RowWidgets/ManifestNameWidget.h>
namespace AZ
{
namespace SceneAPI
{
namespace SceneUI
{
AZ_CLASS_ALLOCATOR_IMPL(ManifestNameWidget, SystemAllocator, 0)
ManifestNameWidget::ManifestNameWidget(QWidget* parent)
: QLineEdit(parent)
, m_filterType(DataTypes::IManifestObject::TYPEINFO_Uuid())
, m_inFailureState(false)
{
connect(this, &QLineEdit::textChanged, this, &ManifestNameWidget::OnTextChanged);
}
void ManifestNameWidget::SetName(const char* name)
{
setText(name);
UpdateStatus(name, false);
}
void ManifestNameWidget::SetName(const AZStd::string& name)
{
setText(name.c_str());
UpdateStatus(name, false);
}
const AZStd::string& ManifestNameWidget::GetName() const
{
return m_name;
}
void ManifestNameWidget::SetFilterType(const Uuid& type)
{
m_filterType = type;
}
void ManifestNameWidget::OnTextChanged(const QString& textValue)
{
m_name = textValue.toStdString().c_str();
UpdateStatus(m_name, true);
emit valueChanged(m_name);
}
void ManifestNameWidget::UpdateStatus(const AZStd::string& newName, bool checkAvailability)
{
AZStd::string error;
bool isValid = AzFramework::StringFunc::Path::IsValid(newName.c_str(), false, false, &error);
if (isValid && checkAvailability)
{
isValid = IsAvailableName(error, newName);
}
if (!isValid && !m_inFailureState)
{
m_originalToolTip = toolTip();
setToolTip(error.c_str());
setProperty("inputValid", "false");
m_inFailureState = true;
style()->unpolish(this);
style()->polish(this);
}
else if (isValid && m_inFailureState)
{
setToolTip(m_originalToolTip);
setProperty("inputValid", "true");
m_inFailureState = false;
style()->unpolish(this);
style()->polish(this);
}
}
bool ManifestNameWidget::IsAvailableName(AZStd::string& error, const AZStd::string& name) const
{
const UI::ManifestWidget* manifestWidget = UI::ManifestWidget::FindRoot(this);
if (!manifestWidget)
{
error = "ManifestNameWidget is not a child of a ManifestWidget. For correct name checking this is required.";
return false;
}
const SceneAPI::Containers::SceneManifest& manifest = manifestWidget->GetScene()->GetManifest();
if (!DataTypes::Utilities::IsNameAvailable(name, manifest, m_filterType))
{
error = "Name is already in use.";
return false;
}
return true;
}
} // SceneUI
} // SceneAPI
} // AZ
#include <RowWidgets/moc_ManifestNameWidget.cpp>