Adding custom title to PropertyAssetCtrl

This commit is contained in:
mnaumov
2021-04-22 16:56:56 -07:00
parent 1fa5728655
commit 09a0676b9c
9 changed files with 75 additions and 12 deletions
@@ -15,6 +15,8 @@
#include "PropertyAssetCtrl.hxx"
#include "PropertyQTConstants.h"
#include "PropertyRowWidget.hxx"
#include "ReflectedPropertyEditor.hxx"
AZ_PUSH_DISABLE_WARNING(4244 4251, "-Wunknown-warning-option")
#include <QtWidgets/QHBoxLayout>
@@ -674,6 +676,28 @@ namespace AzToolsFramework
AzQtComponents::BrowseEdit::removeDropTargetStyle(m_browseEdit);
}
AssetSelectionModel PropertyAssetCtrl::GetAssetSelectionModel()
{
auto selectionModel = AssetSelectionModel::AssetTypeSelection(GetCurrentAssetType());
QString title;
auto propertyRowWidget = FindFirstParent<PropertyRowWidget>(parent());
if (propertyRowWidget)
{
if (!propertyRowWidget->label().isEmpty())
{
title = propertyRowWidget->label();
}
auto reflectedPropertyEditor = FindFirstParent<ReflectedPropertyEditor>(propertyRowWidget->parent());
if (reflectedPropertyEditor && !reflectedPropertyEditor->GetTitle().isEmpty())
{
title = QString("%1 %2").arg(reflectedPropertyEditor->GetTitle()).arg(title);
}
}
selectionModel.SetTitle(title);
return selectionModel;
}
void PropertyAssetCtrl::UpdateTabOrder()
{
setTabOrder(m_browseEdit, m_editButton);
@@ -89,7 +89,7 @@ namespace AzToolsFramework
void dragLeaveEvent(QDragLeaveEvent* event) override;
void dropEvent(QDropEvent* event) override;
virtual AssetSelectionModel GetAssetSelectionModel() { return AssetSelectionModel::AssetTypeSelection(GetCurrentAssetType()); }
virtual AssetSelectionModel GetAssetSelectionModel();
signals:
void OnAssetIDChanged(AZ::Data::AssetId newAssetID);
@@ -177,6 +177,9 @@ namespace AzToolsFramework
void HandleFieldClear();
AZStd::string AddDefaultSuffix(const AZStd::string& filename);
template <class Widget_Type>
Widget_Type* FindFirstParent(QObject* pParent) const;
//////////////////////////////////////////////////////////////////////////
// AssetSystemBus
@@ -233,6 +236,22 @@ namespace AzToolsFramework
void UpdateThumbnail();
};
template<class Widget_Type>
Widget_Type* PropertyAssetCtrl::FindFirstParent(QObject* pParent) const
{
Widget_Type* widget = nullptr;
while (pParent)
{
widget = qobject_cast<Widget_Type*>(pParent);
if (widget)
{
break;
}
pParent = pParent->parent();
}
return widget;
}
class AssetPropertyHandlerDefault
: QObject
, public PropertyHandler<AZ::Data::Asset<AZ::Data::AssetData>, PropertyAssetCtrl>
@@ -387,17 +387,17 @@ namespace AzToolsFramework
QString PropertyRowWidget::label() const
{
return m_nameLabel->text();
return m_title;
}
void PropertyRowWidget::SetNameLabel(const char* text)
{
QString label{ text };
m_nameLabel->setText(label);
m_nameLabel->setVisible(!label.isEmpty());
m_title = text;
m_nameLabel->setText(m_title);
m_nameLabel->setVisible(!m_title.isEmpty());
// setting the stretches to 0 in case of an empty label really hides the label (i.e. even the reserved space)
m_mainLayout->setStretch(0, label.isEmpty() ? 0 : LabelColumnStretch);
m_mainLayout->setStretch(1, label.isEmpty() ? 0 : ValueColumnStretch);
m_mainLayout->setStretch(0, m_title.isEmpty() ? 0 : LabelColumnStretch);
m_mainLayout->setStretch(1, m_title.isEmpty() ? 0 : ValueColumnStretch);
m_identifier = AZ::Crc32(text);
}
@@ -175,6 +175,8 @@ namespace AzToolsFramework
QLabel* m_defaultLabel; // if there is no handler, we use a m_defaultLabel label
InstanceDataNode* m_sourceNode;
QString m_title;
QString m_groupTitle;
QString m_currentFilterString;
struct ChangeNotification
@@ -2248,6 +2248,16 @@ namespace AzToolsFramework
m_impl->m_visibilityCallback = callback;
}
void ReflectedPropertyEditor::SetTitle(const QString& title)
{
m_title = title;
}
const QString& ReflectedPropertyEditor::GetTitle() const
{
return m_title;
}
QWidget* ReflectedPropertyEditor::GetContainerWidget()
{
return m_impl->m_containerWidget;
@@ -156,6 +156,9 @@ namespace AzToolsFramework
using VisibilityCallback = AZStd::function<void(InstanceDataNode* node, NodeDisplayVisibility& visibility, bool& checkChildVisibility)>;
void SetVisibilityCallback(VisibilityCallback callback);
void SetTitle(const QString& title);
const QString& GetTitle() const;
signals:
void OnExpansionContractionDone();
private:
@@ -163,6 +166,7 @@ namespace AzToolsFramework
std::unique_ptr<Impl> m_impl;
AZStd::string m_currentFilterString;
QString m_title;
virtual void paintEvent(QPaintEvent* event) override;
int m_updateDepth = 0;