Initial commit

This commit is contained in:
alexpete
2021-03-05 11:26:34 -08:00
commit a10351f38d
27091 changed files with 5521199 additions and 0 deletions
@@ -0,0 +1,616 @@
/*
* 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 <AzCore/Asset/AssetTypeInfoBus.h>
#include <AzFramework/StringFunc/StringFunc.h>
#include <AzToolsFramework/AssetBrowser/Search/Filter.h>
#include <AzToolsFramework/AssetBrowser/Entries/AssetBrowserEntry.h>
#include <AzToolsFramework/AssetBrowser/Entries/ProductAssetBrowserEntry.h>
#include <AzToolsFramework/AssetBrowser/AssetBrowserBus.h>
#include <AzToolsFramework/AssetBrowser/EBusFindAssetTypeByName.h>
namespace AzToolsFramework
{
namespace AssetBrowser
{
namespace
{
bool StringMatch(const QString& searched, const QString& text)
{
return text.contains(searched, Qt::CaseInsensitive);
}
//! Intersect operation between two sets which then overwrites result
void Intersect(AZStd::vector<const AssetBrowserEntry*>& result, AZStd::vector<const AssetBrowserEntry*>& set)
{
// inefficient, but sets are tiny so probably not worth the optimization effort
AZStd::vector<const AssetBrowserEntry*> intersection;
for (auto entry : result)
{
if (AZStd::find(set.begin(), set.end(), entry) != set.end())
{
intersection.push_back(entry);
}
}
result = intersection;
}
//! Insert an entry if it doesn't already exist
void Join(AZStd::vector<const AssetBrowserEntry*>& result, const AssetBrowserEntry* entry)
{
if (AZStd::find(result.begin(), result.end(), entry) == result.end())
{
result.push_back(entry);
}
}
//! Join operation between two sets which then overwrites result
void Join(AZStd::vector<const AssetBrowserEntry*>& result, AZStd::vector<const AssetBrowserEntry*>& set)
{
AZStd::vector<const AssetBrowserEntry*> unionResult;
for (auto entry : set)
{
Join(result, entry);
}
}
//! Expand all children recursively and write to result
void ExpandDown(AZStd::vector<const AssetBrowserEntry*>& result, const AssetBrowserEntry* entry)
{
Join(result, entry);
AZStd::vector<const AssetBrowserEntry*> children;
entry->GetChildren<AssetBrowserEntry>(children);
for (auto child : children)
{
ExpandDown(result, child);
}
}
//! Expand all entries that are either parent or child relationship to the entry and write to result
void Expand(AZStd::vector<const AssetBrowserEntry*>& result, const AssetBrowserEntry* entry)
{
auto parent = entry->GetParent();
while (parent && parent->GetEntryType() != AssetBrowserEntry::AssetEntryType::Root)
{
Join(result, parent);
parent = parent->GetParent();
}
ExpandDown(result, entry);
}
}
//////////////////////////////////////////////////////////////////////////
// AssetBrowserEntryFilter
//////////////////////////////////////////////////////////////////////////
AssetBrowserEntryFilter::AssetBrowserEntryFilter()
: m_direction(None)
{
}
bool AssetBrowserEntryFilter::Match(const AssetBrowserEntry* entry) const
{
if (MatchInternal(entry))
{
return true;
}
if (m_direction & Up)
{
auto parent = entry->GetParent();
while (parent && parent->GetEntryType() != AssetBrowserEntry::AssetEntryType::Root)
{
if (MatchInternal(parent))
{
return true;
}
parent = parent->GetParent();
}
}
if (m_direction & Down)
{
AZStd::vector<const AssetBrowserEntry*> children;
entry->GetChildren<AssetBrowserEntry>(children);
for (auto child : children)
{
if (MatchDown(child))
{
return true;
}
}
}
return false;
}
void AssetBrowserEntryFilter::Filter(AZStd::vector<const AssetBrowserEntry*>& result, const AssetBrowserEntry* entry) const
{
FilterInternal(result, entry);
if (m_direction & Up)
{
auto parent = entry->GetParent();
while (parent && parent->GetEntryType() != AssetBrowserEntry::AssetEntryType::Root)
{
FilterInternal(result, parent);
parent = parent->GetParent();
}
}
if (m_direction & Down)
{
AZStd::vector<const AssetBrowserEntry*> children;
entry->GetChildren<AssetBrowserEntry>(children);
for (auto child : children)
{
FilterDown(result, child);
}
}
}
QString AssetBrowserEntryFilter::GetName() const
{
return m_name.isEmpty() ? GetNameInternal() : m_name;
}
void AssetBrowserEntryFilter::SetName(const QString& name)
{
m_name = name;
}
const QString& AssetBrowserEntryFilter::GetTag() const
{
return m_tag;
}
void AssetBrowserEntryFilter::SetTag(const QString& tag)
{
m_tag = tag;
}
void AssetBrowserEntryFilter::SetFilterPropagation(int direction)
{
m_direction = direction;
}
void AssetBrowserEntryFilter::FilterInternal(AZStd::vector<const AssetBrowserEntry*>& result, const AssetBrowserEntry* entry) const
{
if (MatchInternal(entry))
{
Join(result, entry);
}
}
bool AssetBrowserEntryFilter::MatchDown(const AssetBrowserEntry* entry) const
{
if (MatchInternal(entry))
{
return true;
}
AZStd::vector<const AssetBrowserEntry*> children;
entry->GetChildren<AssetBrowserEntry>(children);
for (auto child : children)
{
if (MatchDown(child))
{
return true;
}
}
return false;
}
void AssetBrowserEntryFilter::FilterDown(AZStd::vector<const AssetBrowserEntry*>& result, const AssetBrowserEntry* entry) const
{
if (MatchInternal(entry))
{
Join(result, entry);
}
AZStd::vector<const AssetBrowserEntry*> children;
entry->GetChildren<AssetBrowserEntry>(children);
for (auto child : children)
{
FilterDown(result, child);
}
}
//////////////////////////////////////////////////////////////////////////
// StringFilter
//////////////////////////////////////////////////////////////////////////
StringFilter::StringFilter()
: m_filterString("") {}
void StringFilter::SetFilterString(const QString& filterString)
{
m_filterString = filterString;
Q_EMIT updatedSignal();
}
QString StringFilter::GetNameInternal() const
{
return m_filterString;
}
bool StringFilter::MatchInternal(const AssetBrowserEntry* entry) const
{
// no filter string matches any asset
if (m_filterString.isEmpty())
{
return true;
}
// entry's name matches search pattern
if (StringMatch(m_filterString, entry->GetDisplayName()))
{
return true;
}
return false;
}
//////////////////////////////////////////////////////////////////////////
// AssetTypeFilter
//////////////////////////////////////////////////////////////////////////
AssetTypeFilter::AssetTypeFilter()
: m_assetType(AZ::Data::AssetType::CreateNull()) {}
void AssetTypeFilter::SetAssetType(AZ::Data::AssetType assetType)
{
m_assetType = assetType;
Q_EMIT updatedSignal();
}
void AssetTypeFilter::SetAssetType(const char* assetTypeName)
{
EBusFindAssetTypeByName result(assetTypeName);
AZ::AssetTypeInfoBus::BroadcastResult(result, &AZ::AssetTypeInfo::GetAssetType);
SetAssetType(result.GetAssetType());
}
AZ::Data::AssetType AssetTypeFilter::GetAssetType() const
{
return m_assetType;
}
QString AssetTypeFilter::GetNameInternal() const
{
QString name;
AZ::AssetTypeInfoBus::EventResult(name, m_assetType, &AZ::AssetTypeInfo::GetAssetTypeDisplayName);
return name;
}
bool AssetTypeFilter::MatchInternal(const AssetBrowserEntry* entry) const
{
// this filter only works on products.
if (entry->GetEntryType() == AssetBrowserEntry::AssetEntryType::Product)
{
if (m_assetType.IsNull())
{
return true;
}
if (static_cast<const ProductAssetBrowserEntry*>(entry)->GetAssetType() == m_assetType)
{
return true;
}
}
return false;
}
//////////////////////////////////////////////////////////////////////////
// AssetGroupFilter
//////////////////////////////////////////////////////////////////////////
AssetGroupFilter::AssetGroupFilter()
: m_group("All")
{
}
void AssetGroupFilter::SetAssetGroup(const QString& group)
{
m_group = group;
}
const QString& AssetGroupFilter::GetAssetTypeGroup() const
{
return m_group;
}
QString AssetGroupFilter::GetNameInternal() const
{
return m_group;
}
bool AssetGroupFilter::MatchInternal(const AssetBrowserEntry* entry) const
{
// this filter only works on products.
if (entry->GetEntryType() != AssetBrowserEntry::AssetEntryType::Product)
{
return false;
}
if (m_group.compare("All", Qt::CaseInsensitive) == 0)
{
return true;
}
auto product = static_cast<const ProductAssetBrowserEntry*>(entry);
QString group;
AZ::AssetTypeInfoBus::EventResult(group, product->GetAssetType(), &AZ::AssetTypeInfo::GetGroup);
if (m_group.compare("Other", Qt::CaseInsensitive) == 0 && group.isEmpty())
{
return true;
}
return (m_group.compare(group, Qt::CaseInsensitive) == 0);
}
//////////////////////////////////////////////////////////////////////////
// EntryTypeFilter
//////////////////////////////////////////////////////////////////////////
EntryTypeFilter::EntryTypeFilter()
: m_entryType(AssetBrowserEntry::AssetEntryType::Product) {}
void EntryTypeFilter::SetEntryType(AssetBrowserEntry::AssetEntryType entryType)
{
m_entryType = entryType;
}
AssetBrowserEntry::AssetEntryType EntryTypeFilter::GetEntryType() const
{
return m_entryType;
}
QString EntryTypeFilter::GetNameInternal() const
{
return AssetBrowserEntry::AssetEntryTypeToString(m_entryType);
}
bool EntryTypeFilter::MatchInternal(const AssetBrowserEntry* entry) const
{
return entry->GetEntryType() == m_entryType;
}
//////////////////////////////////////////////////////////////////////////
// CompositeFilter
//////////////////////////////////////////////////////////////////////////
CompositeFilter::CompositeFilter(LogicOperatorType logicOperator)
: m_logicOperator(logicOperator)
, m_emptyResult(true) {}
void CompositeFilter::AddFilter(FilterConstType filter)
{
connect(filter.data(), &AssetBrowserEntryFilter::updatedSignal, this, &AssetBrowserEntryFilter::updatedSignal, Qt::UniqueConnection);
m_subFilters.append(filter);
Q_EMIT updatedSignal();
}
void CompositeFilter::RemoveFilter(FilterConstType filter)
{
if (m_subFilters.removeAll(filter))
{
Q_EMIT updatedSignal();
}
}
void CompositeFilter::RemoveAllFilters()
{
m_subFilters.clear();
Q_EMIT updatedSignal();
}
void CompositeFilter::SetLogicOperator(LogicOperatorType logicOperator)
{
m_logicOperator = logicOperator;
Q_EMIT updatedSignal();
}
const QList<FilterConstType>& CompositeFilter::GetSubFilters() const
{
return m_subFilters;
}
void CompositeFilter::SetEmptyResult(bool result)
{
if (m_emptyResult != result)
{
m_emptyResult = result;
Q_EMIT updatedSignal();
}
}
QString CompositeFilter::GetNameInternal() const
{
QString name = "";
for (auto it = m_subFilters.begin(); it != m_subFilters.end(); ++it)
{
name += (*it)->GetName();
if (AZStd::next(it) != m_subFilters.end())
{
name += ", ";
}
}
return name;
}
bool CompositeFilter::MatchInternal(const AssetBrowserEntry* entry) const
{
if (m_subFilters.count() == 0)
{
return m_emptyResult;
}
// AND
if (m_logicOperator == LogicOperatorType::AND)
{
for (auto filter : m_subFilters)
{
if (!filter->Match(entry))
{
return false;
}
}
return true;
}
// OR
for (auto filter : m_subFilters)
{
if (filter->Match(entry))
{
return true;
}
}
return false;
}
void CompositeFilter::FilterInternal(AZStd::vector<const AssetBrowserEntry*>& result, const AssetBrowserEntry* entry) const
{
// if no subfilters are present in this composite filter then all relating entries would match
if (m_subFilters.isEmpty())
{
// only if match on empty filter is success
if (m_emptyResult)
{
Expand(result, entry);
}
return;
}
// AND
if (m_logicOperator == LogicOperatorType::AND)
{
AZStd::vector<const AssetBrowserEntry*> andResult;
bool firstResult = true;
for (auto filter : m_subFilters)
{
if (firstResult)
{
firstResult = false;
filter->Filter(andResult, entry);
}
else
{
AZStd::vector<const AssetBrowserEntry*> set;
filter->Filter(set, entry);
Intersect(andResult, set);
}
if (andResult.empty())
{
break;
}
}
Join(result, andResult);
}
// OR
else
{
for (auto filter : m_subFilters)
{
AZStd::vector<const AssetBrowserEntry*> set;
filter->Filter(set, entry);
Join(result, set);
}
}
}
//////////////////////////////////////////////////////////////////////////
// InverseFilter
//////////////////////////////////////////////////////////////////////////
InverseFilter::InverseFilter() {}
void InverseFilter::SetFilter(FilterConstType filter)
{
if (m_filter == filter)
{
return;
}
m_filter = filter;
Q_EMIT updatedSignal();
}
QString InverseFilter::GetNameInternal() const
{
if (m_filter.isNull())
{
QString name = tr("NOT");
}
QString name = tr("NOT (%1)").arg(m_filter->GetName());
return name;
}
bool InverseFilter::MatchInternal(const AssetBrowserEntry* entry) const
{
if (m_filter.isNull())
{
return false;
}
return !m_filter->Match(entry);
}
void InverseFilter::FilterInternal(AZStd::vector<const AssetBrowserEntry*>& result, const AssetBrowserEntry* entry) const
{
if (MatchInternal(entry))
{
Expand(result, entry);
}
}
//////////////////////////////////////////////////////////////////////////
// CleanerProductsFilter
//////////////////////////////////////////////////////////////////////////
CleanerProductsFilter::CleanerProductsFilter() {}
QString CleanerProductsFilter::GetNameInternal() const
{
return QString();
}
bool CleanerProductsFilter::MatchInternal(const AssetBrowserEntry* entry) const
{
auto product = azrtti_cast<const ProductAssetBrowserEntry*>(entry);
if (!product)
{
return true;
}
auto source = product->GetParent();
if (!source)
{
return true;
}
if (source->GetChildCount() != 1)
{
return true;
}
AZStd::string assetTypeName;
AZ::AssetTypeInfoBus::EventResult(assetTypeName, product->GetAssetType(), &AZ::AssetTypeInfo::GetAssetTypeDisplayName);
if (!assetTypeName.empty())
{
return true;
}
return false;
}
void CleanerProductsFilter::FilterInternal(AZStd::vector<const AssetBrowserEntry*>& result, const AssetBrowserEntry* entry) const
{
if (MatchInternal(entry))
{
Expand(result, entry);
}
}
} // namespace AssetBrowser
} // namespace AzToolsFramework
#include "AssetBrowser/Search/moc_Filter.cpp"
@@ -0,0 +1,323 @@
/*
* 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.
*
*/
#pragma once
#if !defined(Q_MOC_RUN)
#include <AzToolsFramework/AssetBrowser/Entries/AssetBrowserEntry.h>
#include <QObject>
#include <QString>
#include <QSharedPointer>
#include <QString>
#include <AzCore/Asset/AssetTypeInfoBus.h>
#include <AzCore/std/containers/vector.h>
#include <AzCore/std/algorithm.h>
#endif
namespace AzToolsFramework
{
namespace AssetBrowser
{
class AssetBrowserEntryFilter;
typedef QSharedPointer<const AssetBrowserEntryFilter> FilterConstType;
//////////////////////////////////////////////////////////////////////////
// AssetBrowserEntryFilter
//////////////////////////////////////////////////////////////////////////
//! Filters are used to fascilitate searching asset browser for specific asset
//! They are also used for enforcing selection constraints for asset picking
class AssetBrowserEntryFilter
: public QObject
{
Q_OBJECT
public:
//! Propagate direction allows match satisfaction based on entry parents and/or children
/*
if PropagateDirection = Down, and entry does not satisfy filter, evaluation will propagate recursively to its children
until at least one child satisfies the filter, then the original entry would match
if PropagateDirection = Up, and entry does not satisfy filter, evaluation will propagate recursively upwards to its parents
until first parent matches the filter, then the original entry would match
if PropagateDirection = None, only entry itself is considered by the filter
*/
enum PropagateDirection : int
{
None = 0x00,
Up = 0x01,
Down = 0x02
};
AssetBrowserEntryFilter();
virtual ~AssetBrowserEntryFilter() = default;
//! Check if entry matches filter
bool Match(const AssetBrowserEntry* entry) const;
//! Retrieve all matching entries that are either entry itself or its parents or children
void Filter(AZStd::vector<const AssetBrowserEntry*>& result, const AssetBrowserEntry* entry) const;
//! Filter name is used to uniquely identify the filter
QString GetName() const;
void SetName(const QString& name);
//! Tags are used for identifying filter groups
const QString& GetTag() const;
void SetTag(const QString& tag);
void SetFilterPropagation(int direction);
Q_SIGNALS:
//! Emitted every time a filter is updated, in case of composite filter, the signal is propagated to the top level filter so only one listener needs to connected
void updatedSignal() const;
protected:
//! Internal name auto generated based on filter type and data
virtual QString GetNameInternal() const = 0;
//! Internal matching logic overrided by every filter type
virtual bool MatchInternal(const AssetBrowserEntry* entry) const = 0;
//! Internal filtering logic overrided by every filter type
virtual void FilterInternal(AZStd::vector<const AssetBrowserEntry*>& result, const AssetBrowserEntry* entry) const;
private:
QString m_name;
QString m_tag;
int m_direction;
bool MatchDown(const AssetBrowserEntry* entry) const;
void FilterDown(AZStd::vector<const AssetBrowserEntry*>& result, const AssetBrowserEntry* entry) const;
};
//////////////////////////////////////////////////////////////////////////
// StringFilter
//////////////////////////////////////////////////////////////////////////
//! StringFilter filters assets based on their name
class StringFilter
: public AssetBrowserEntryFilter
{
Q_OBJECT
public:
StringFilter();
~StringFilter() override = default;
void SetFilterString(const QString& filterString);
protected:
QString GetNameInternal() const override;
bool MatchInternal(const AssetBrowserEntry* entry) const override;
private:
QString m_filterString;
};
//////////////////////////////////////////////////////////////////////////
// AssetTypeFilter
//////////////////////////////////////////////////////////////////////////
//! AssetTypeFilter filters products based on their asset id
class AssetTypeFilter
: public AssetBrowserEntryFilter
{
Q_OBJECT
public:
AssetTypeFilter();
~AssetTypeFilter() override = default;
void SetAssetType(AZ::Data::AssetType assetType);
void SetAssetType(const char* assetTypeName);
AZ::Data::AssetType GetAssetType() const;
protected:
QString GetNameInternal() const override;
bool MatchInternal(const AssetBrowserEntry* entry) const override;
private:
AZ::Data::AssetType m_assetType;
};
//////////////////////////////////////////////////////////////////////////
// AssetGroupFilter
//////////////////////////////////////////////////////////////////////////
//! AssetGroupFilter filters products based on their asset group
class AssetGroupFilter
: public AssetBrowserEntryFilter
{
Q_OBJECT
public:
AssetGroupFilter();
~AssetGroupFilter() override = default;
void SetAssetGroup(const QString& group);
const QString& GetAssetTypeGroup() const;
protected:
QString GetNameInternal() const override;
bool MatchInternal(const AssetBrowserEntry* entry) const override;
private:
QString m_group;
};
//////////////////////////////////////////////////////////////////////////
// EntryTypeFilter
//////////////////////////////////////////////////////////////////////////
class EntryTypeFilter
: public AssetBrowserEntryFilter
{
Q_OBJECT
public:
EntryTypeFilter();
~EntryTypeFilter() override = default;
void SetEntryType(AssetBrowserEntry::AssetEntryType entryType);
AssetBrowserEntry::AssetEntryType GetEntryType() const;
protected:
QString GetNameInternal() const override;
bool MatchInternal(const AssetBrowserEntry* entry) const override;
private:
AssetBrowserEntry::AssetEntryType m_entryType;
};
//////////////////////////////////////////////////////////////////////////
// CompositeFilter
//////////////////////////////////////////////////////////////////////////
//! CompositeFilter performs an AND/OR operation between multiple subfilters
/*
If more complex logic operations required, CompositeFilters can be nested
with different logic operator types
*/
class CompositeFilter
: public AssetBrowserEntryFilter
{
Q_OBJECT
public:
enum class LogicOperatorType
{
OR,
AND
};
explicit CompositeFilter(LogicOperatorType logicOperator);
~CompositeFilter() override = default;
void AddFilter(FilterConstType filter);
void RemoveFilter(FilterConstType filter);
void RemoveAllFilters();
void SetLogicOperator(LogicOperatorType logicOperator);
const QList<FilterConstType>& GetSubFilters() const;
//! Return value if there are no subfilters present
void SetEmptyResult(bool result);
protected:
QString GetNameInternal() const override;
bool MatchInternal(const AssetBrowserEntry* entry) const override;
void FilterInternal(AZStd::vector<const AssetBrowserEntry*>& result, const AssetBrowserEntry* entry) const override;
private:
QList<FilterConstType> m_subFilters;
LogicOperatorType m_logicOperator;
bool m_emptyResult;
};
//////////////////////////////////////////////////////////////////////////
// InverseFilter
//////////////////////////////////////////////////////////////////////////
//! Inverse filter negates result of its child filter
class InverseFilter
: public AssetBrowserEntryFilter
{
Q_OBJECT
public:
InverseFilter();
~InverseFilter() override = default;
void SetFilter(FilterConstType filter);
protected:
QString GetNameInternal() const override;
bool MatchInternal(const AssetBrowserEntry* entry) const override;
void FilterInternal(AZStd::vector<const AssetBrowserEntry*>& result, const AssetBrowserEntry* entry) const override;
private:
FilterConstType m_filter;
};
//////////////////////////////////////////////////////////////////////////
// CleanerProductsFilter
//////////////////////////////////////////////////////////////////////////
//! Filters out products that shouldn't be shown
class CleanerProductsFilter
: public AssetBrowserEntryFilter
{
Q_OBJECT
public:
CleanerProductsFilter();
~CleanerProductsFilter() override = default;
protected:
QString GetNameInternal() const override;
bool MatchInternal(const AssetBrowserEntry* entry) const override;
void FilterInternal(AZStd::vector<const AssetBrowserEntry*>& result, const AssetBrowserEntry* entry) const override;
private:
FilterConstType m_filter;
};
template<class T>
struct EBusAggregateUniqueResults
{
AZStd::vector<T> values;
void operator=(const T& rhs)
{
if (AZStd::find(values.begin(), values.end(), rhs) == values.end())
{
values.push_back(rhs);
}
}
};
struct EBusAggregateAssetTypesIfBelongsToGroup
{
EBusAggregateAssetTypesIfBelongsToGroup(const QString& group)
: m_group(group)
{
}
EBusAggregateAssetTypesIfBelongsToGroup(const EBusAggregateAssetTypesIfBelongsToGroup&) = delete;
EBusAggregateAssetTypesIfBelongsToGroup& operator=(const EBusAggregateAssetTypesIfBelongsToGroup&) = delete;
AZStd::vector<AZ::Data::AssetType> values;
void operator=(const AZ::Data::AssetType& assetType)
{
if (BelongsToGroup(assetType))
{
values.push_back(assetType);
}
}
private:
const QString& m_group;
bool BelongsToGroup(const AZ::Data::AssetType& assetType)
{
QString group;
AZ::AssetTypeInfoBus::EventResult(group, assetType, &AZ::AssetTypeInfo::GetGroup);
return !group.compare(m_group, Qt::CaseInsensitive);
}
};
} // namespace AssetBrowser
} // namespace AzToolsFramework
Q_DECLARE_METATYPE(AzToolsFramework::AssetBrowser::FilterConstType)
@@ -0,0 +1,42 @@
/*
* 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 <AzQtComponents/Components/ExtendedLabel.h>
AZ_PUSH_DISABLE_WARNING(4251, "-Wunknown-warning-option") // 4251: class 'QFlags<Qt::AlignmentFlag>' needs to have dll-interface to be used by clients of class 'QLayoutItem'
#include <AssetBrowser/Search/ui_FilterByWidget.h>
AZ_POP_DISABLE_WARNING
#include <AzToolsFramework/AssetBrowser/Search/FilterByWidget.h>
namespace AzToolsFramework
{
namespace AssetBrowser
{
FilterByWidget::FilterByWidget(QWidget* parent)
: QWidget(parent)
, m_ui(new Ui::FilterByWidgetClass)
{
m_ui->setupUi(this);
connect(m_ui->m_clearFiltersButton, &AzQtComponents::ExtendedLabel::clicked, this, &FilterByWidget::ClearSignal);
// hide clear button as filters are reset at the startup
ToggleClearButton(false);
}
FilterByWidget::~FilterByWidget() = default;
void FilterByWidget::ToggleClearButton(bool visible) const
{
m_ui->m_clearFiltersButton->setVisible(visible);
}
} // namespace AssetBrowser
} // namespace AzToolsFramework
#include "AssetBrowser/Search/moc_FilterByWidget.cpp"
@@ -0,0 +1,48 @@
/*
* 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.
*
*/
#pragma once
/*********************************************************************************************
* FilterByWidget has been deprecated, use AzQtComponents::FilteredSearchWidget instead.
*********************************************************************************************/
#if !defined(Q_MOC_RUN)
#include <QWidget>
#include <QScopedPointer>
#endif
namespace Ui
{
class FilterByWidgetClass;
}
namespace AzToolsFramework
{
namespace AssetBrowser
{
class FilterByWidget
: public QWidget
{
Q_OBJECT
public:
explicit FilterByWidget(QWidget* parent = nullptr);
~FilterByWidget() override;
void ToggleClearButton(bool visible) const;
Q_SIGNALS:
void ClearSignal();
private:
QScopedPointer<Ui::FilterByWidgetClass> m_ui;
};
} // namespace AssetBrowser
} // namespace AzToolsFramework
@@ -0,0 +1,93 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>FilterByWidgetClass</class>
<widget class="QWidget" name="FilterByWidgetClass">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>150</width>
<height>25</height>
</rect>
</property>
<property name="sizePolicy">
<sizepolicy hsizetype="Minimum" vsizetype="Minimum">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>150</width>
<height>25</height>
</size>
</property>
<property name="windowTitle">
<string>Form</string>
</property>
<layout class="QHBoxLayout" name="horizontalLayout">
<property name="spacing">
<number>0</number>
</property>
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
<item>
<widget class="QLabel" name="m_filterByLabel">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="styleSheet">
<string notr="true">color: white;</string>
</property>
<property name="text">
<string>Filter by:</string>
</property>
<property name="wordWrap">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>59</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="AzQtComponents::ExtendedLabel" name="m_clearFiltersButton">
<property name="text">
<string>Reset</string>
</property>
</widget>
</item>
</layout>
</widget>
<customwidgets>
<customwidget>
<class>AzQtComponents::ExtendedLabel</class>
<extends>QLabel</extends>
<header>AzQtComponents/Components/ExtendedLabel.h</header>
</customwidget>
</customwidgets>
<connections/>
</ui>
@@ -0,0 +1,157 @@
/*
* 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 <AzCore/Asset/AssetTypeInfoBus.h>
#include <AzCore/std/containers/vector.h>
#include <AzToolsFramework/AssetBrowser/Search/SearchAssetTypeSelectorWidget.h>
#include <AzToolsFramework/AssetBrowser/Search/Filter.h>
#include <AzToolsFramework/AssetBrowser/Search/FilterByWidget.h>
AZ_PUSH_DISABLE_WARNING(4251, "-Wunknown-warning-option") // 4251: 'QLayoutItem::align': class 'QFlags<Qt::AlignmentFlag>' needs to have dll-interface to be used by clients of class 'QLayoutItem'
#include <AssetBrowser/Search/ui_SearchAssetTypeSelectorWidget.h>
AZ_POP_DISABLE_WARNING
#include <QPushButton>
#include <QMenu>
#include <QCheckBox>
#include <QWidgetAction>
#include <algorithm>
namespace AzToolsFramework
{
namespace AssetBrowser
{
SearchAssetTypeSelectorWidget::SearchAssetTypeSelectorWidget(QWidget* parent)
: QWidget(parent)
, m_ui(new Ui::SearchAssetTypeSelectorWidgetClass())
, m_filter(QSharedPointer<CompositeFilter>(new CompositeFilter(CompositeFilter::LogicOperatorType::OR)))
, m_locked(false)
{
m_ui->setupUi(this);
QMenu* menu = new QMenu(this);
AddAllAction(menu);
menu->addSeparator();
EBusAggregateUniqueResults<QString> results;
AZ::AssetTypeInfoBus::BroadcastResult(results, &AZ::AssetTypeInfo::GetGroup);
std::sort(results.values.begin(), results.values.end(),
[](const QString& a, const QString& b) { return QString::compare(a, b, Qt::CaseInsensitive) < 0; });
for (QString& group : results.values)
{
// Group "Other" should be in the end of the list, and "Hidden" should not be on the list at all
if (group == "Other" || group == "Hidden")
{
continue;
}
AddAssetTypeGroup(menu, group);
}
AddAssetTypeGroup(menu, "Other");
menu->setLayoutDirection(Qt::LeftToRight);
menu->setStyleSheet("border: none; background-color: #333333;");
m_ui->m_showSelectionButton->setMenu(menu);
m_filter->SetTag("AssetTypes");
m_filter->SetFilterPropagation(AssetBrowserEntryFilter::PropagateDirection::Down);
}
SearchAssetTypeSelectorWidget::~SearchAssetTypeSelectorWidget()
{
}
void SearchAssetTypeSelectorWidget::UpdateFilterByWidget() const
{
for (auto assetTypeCheckbox : m_assetTypeCheckboxes)
{
if (assetTypeCheckbox->isChecked())
{
m_filterByWidget->ToggleClearButton(true);
return;
}
}
m_filterByWidget->ToggleClearButton(false);
}
void SearchAssetTypeSelectorWidget::ClearAll() const
{
// check all other asset types
for (auto assetTypeCheckbox : m_assetTypeCheckboxes)
{
if (assetTypeCheckbox->isChecked())
{
assetTypeCheckbox->setChecked(false);
}
}
m_filter->RemoveAllFilters();
m_filter->SetEmptyResult(true);
UpdateFilterByWidget();
}
FilterConstType SearchAssetTypeSelectorWidget::GetFilter() const
{
return m_filter;
}
bool SearchAssetTypeSelectorWidget::IsLocked() const
{
return m_locked;
}
void SearchAssetTypeSelectorWidget::AddAssetTypeGroup(QMenu* menu, const QString& group)
{
EBusAggregateAssetTypesIfBelongsToGroup results(group);
AZ::AssetTypeInfoBus::BroadcastResult(results, &AZ::AssetTypeInfo::GetAssetType);
if (!results.values.empty())
{
QCheckBox* checkbox = new QCheckBox(group, menu);
QWidgetAction* action = new QWidgetAction(menu);
action->setDefaultWidget(checkbox);
menu->addAction(action);
m_assetTypeCheckboxes.push_back(checkbox);
AssetGroupFilter* groupFilter = new AssetGroupFilter();
groupFilter->SetAssetGroup(group);
m_actionFiltersMapping[checkbox] = FilterConstType(groupFilter);
connect(checkbox, &QCheckBox::clicked, this,
[=](bool checked)
{
if (checked)
{
m_filter->AddFilter(m_actionFiltersMapping[checkbox]);
}
else
{
m_filter->RemoveFilter(m_actionFiltersMapping[checkbox]);
}
UpdateFilterByWidget();
});
}
}
void SearchAssetTypeSelectorWidget::AddAllAction(QMenu* menu)
{
m_filterByWidget = new FilterByWidget(menu);
auto action = new QWidgetAction(menu);
action->setDefaultWidget(m_filterByWidget);
menu->addAction(action);
connect(m_filterByWidget, &FilterByWidget::ClearSignal, this, &SearchAssetTypeSelectorWidget::ClearAll);
}
} // namespace AssetBrowser
} // namespace AzToolsFramework
#include "AssetBrowser/Search/moc_SearchAssetTypeSelectorWidget.cpp"
@@ -0,0 +1,80 @@
/*
* 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.
*
*/
#pragma once
/*********************************************************************************************
* SearchAssetTypeSelectorWidget has been deprecated, use AzQtComponents::FilteredSearchWidget instead.
*********************************************************************************************/
#if !defined(Q_MOC_RUN)
#include <AzToolsFramework/AssetBrowser/Search/Filter.h>
#include <AzCore/Memory/SystemAllocator.h>
#include <AzCore/std/smart_ptr/shared_ptr.h>
#include <AzCore/Asset/AssetCommon.h>
#include <AzCore/std/containers/unordered_map.h>
#include <AzCore/std/containers/vector.h>
AZ_PUSH_DISABLE_WARNING(4251 4800, "-Wunknown-warning-option") // 4251: 'QBrush::d': class 'QScopedPointer<QBrushData,QBrushDataPointerDeleter>' needs to have dll-interface to be used by clients of class 'QBrush'
// 4800: 'uint': forcing value to bool 'true' or 'false' (performance warning)
#include <QScopedPointer>
#include <QSharedPointer>
#include <QWidgetAction>
#include <QCheckBox>
#include <QString>
AZ_POP_DISABLE_WARNING
#endif
class QMenu;
class QAction;
namespace Ui
{
class SearchAssetTypeSelectorWidgetClass;
}
namespace AzToolsFramework
{
namespace AssetBrowser
{
class FilterByWidget;
class SearchAssetTypeSelectorWidget
: public QWidget
{
Q_OBJECT
public:
AZ_CLASS_ALLOCATOR(SearchAssetTypeSelectorWidget, AZ::SystemAllocator, 0);
explicit SearchAssetTypeSelectorWidget(QWidget* parent = nullptr);
~SearchAssetTypeSelectorWidget() override;
void UpdateFilterByWidget() const;
FilterConstType GetFilter() const;
bool IsLocked() const;
public Q_SIGNAL:
void ClearAll() const;
private:
QScopedPointer<Ui::SearchAssetTypeSelectorWidgetClass> m_ui;
QSharedPointer<CompositeFilter> m_filter;
FilterByWidget* m_filterByWidget;
AZStd::vector<QCheckBox*> m_assetTypeCheckboxes;
AZStd::unordered_map<QCheckBox*, FilterConstType> m_actionFiltersMapping;
bool m_locked;
void AddAssetTypeGroup(QMenu* menu, const QString& group);
void AddAllAction(QMenu* menu);
};
} // namespace AssetBrowser
} // namespace AzToolsFramework
@@ -0,0 +1,103 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>SearchAssetTypeSelectorWidgetClass</class>
<widget class="QWidget" name="SearchAssetTypeSelectorWidgetClass">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>94</width>
<height>25</height>
</rect>
</property>
<property name="sizePolicy">
<sizepolicy hsizetype="Minimum" vsizetype="Minimum">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>32</width>
<height>25</height>
</size>
</property>
<property name="windowTitle">
<string>Form</string>
</property>
<layout class="QHBoxLayout" name="horizontalLayout">
<property name="spacing">
<number>0</number>
</property>
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
<item>
<widget class="QPushButton" name="m_showSelectionButton">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>32</width>
<height>25</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>32</width>
<height>25</height>
</size>
</property>
<property name="statusTip">
<string/>
</property>
<property name="layoutDirection">
<enum>Qt::RightToLeft</enum>
</property>
<property name="styleSheet">
<string notr="true">QPushButton::menu-indicator { image: none; }</string>
</property>
<property name="text">
<string/>
</property>
<property name="icon">
<iconset resource="../../../../AzQtComponents/AzQtComponents/Components/resources.qrc">
<normaloff>:/stylesheet/img/filter.svg</normaloff>:/stylesheet/img/filter.svg</iconset>
</property>
<property name="iconSize">
<size>
<width>25</width>
<height>21</height>
</size>
</property>
<property name="autoDefault">
<bool>false</bool>
</property>
<property name="default">
<bool>false</bool>
</property>
<property name="flat">
<bool>true</bool>
</property>
</widget>
</item>
</layout>
</widget>
<resources>
<include location="../../../../AzQtComponents/AzQtComponents/Components/resources.qrc"/>
</resources>
<connections/>
</ui>
@@ -0,0 +1,71 @@
/*
* 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 "SearchParametersWidget.h"
AZ_PUSH_DISABLE_WARNING(4251, "-Wunknown-warning-option") // 4251: 'QLayoutItem::align': class 'QFlags<Qt::AlignmentFlag>' needs to have dll-interface to be used by clients of class 'QLayoutItem'
#include "AssetBrowser/Search/ui_SearchParametersWidget.h"
AZ_POP_DISABLE_WARNING
#include <AzQtComponents/Components/ExtendedLabel.h>
namespace AzToolsFramework
{
namespace AssetBrowser
{
SearchParametersWidget::SearchParametersWidget(QWidget* parent)
: QWidget(parent)
, m_ui(new Ui::SearchParametersWidgetClass())
, m_allowClear(true)
{
m_ui->setupUi(this);
hide();
connect(m_ui->m_clearFiltersButton, &AzQtComponents::ExtendedLabel::clicked, this, &SearchParametersWidget::ClearAllSignal);
}
SearchParametersWidget::~SearchParametersWidget() = default;
void SearchParametersWidget::FilterUpdatedSlot()
{
QString filterName = m_filter->GetName();
if (!filterName.isEmpty())
{
show();
m_ui->m_filtersLabel->setText("<b>Filtered by:</b> " + filterName);
if (m_allowClear)
{
m_ui->m_clearFiltersButton->show();
}
else
{
m_ui->m_clearFiltersButton->hide();
}
}
else
{
hide();
}
}
void SearchParametersWidget::SetFilter(FilterConstType filter)
{
m_filter = filter;
connect(m_filter.data(), &AssetBrowserEntryFilter::updatedSignal, this, &SearchParametersWidget::FilterUpdatedSlot);
}
void SearchParametersWidget::SetAllowClear(bool allowClear)
{
m_allowClear = allowClear;
}
} // namespace AssetBrowser
} // namespace AzToolsFramework
#include "AssetBrowser/Search/moc_SearchParametersWidget.cpp"
@@ -0,0 +1,65 @@
/*
* 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.
*
*/
#pragma once
/*********************************************************************************************
* SearchParametersWidget has been deprecated, use AzQtComponents::FilteredSearchWidget instead.
*********************************************************************************************/
#if !defined(Q_MOC_RUN)
#include <AzToolsFramework/AssetBrowser/Search/Filter.h>
#include <AzCore/Memory/SystemAllocator.h>
AZ_PUSH_DISABLE_WARNING(4251 4800, "-Wunknown-warning-option") // 4251: 'QBrush::d': class 'QScopedPointer<QBrushData,QBrushDataPointerDeleter>' needs to have dll-interface to be used by clients of class 'QBrush'
// 4800: 'uint': forcing value to bool 'true' or 'false' (performance warning)
#include <QWidget>
#include <QScopedPointer>
AZ_POP_DISABLE_WARNING
#endif
namespace Ui
{
class SearchParametersWidgetClass;
}
namespace AzToolsFramework
{
namespace AssetBrowser
{
class SearchParametersWidget
: public QWidget
{
Q_OBJECT
public:
AZ_CLASS_ALLOCATOR(SearchParametersWidget, AZ::SystemAllocator, 0);
explicit SearchParametersWidget(QWidget* parent = nullptr);
~SearchParametersWidget();
void SetFilter(FilterConstType filter);
void SetAllowClear(bool allowClear);
Q_SIGNALS:
void ClearAllSignal();
private:
QScopedPointer<Ui::SearchParametersWidgetClass> m_ui;
FilterConstType m_filter;
bool m_allowClear;
private Q_SLOTS:
void FilterUpdatedSlot();
};
} // namespace AssetBrowser
} // namespace AzToolsFramework
@@ -0,0 +1,96 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>SearchParametersWidgetClass</class>
<widget class="QWidget" name="SearchParametersWidgetClass">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>96</width>
<height>28</height>
</rect>
</property>
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Minimum">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>0</width>
<height>0</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>16777215</width>
<height>16777215</height>
</size>
</property>
<property name="windowTitle">
<string>Form</string>
</property>
<layout class="QHBoxLayout" name="horizontalLayout">
<property name="leftMargin">
<number>6</number>
</property>
<property name="topMargin">
<number>6</number>
</property>
<property name="rightMargin">
<number>6</number>
</property>
<property name="bottomMargin">
<number>6</number>
</property>
<item>
<widget class="QLabel" name="m_filtersLabel">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="font">
<font>
<pointsize>10</pointsize>
</font>
</property>
<property name="styleSheet">
<string notr="true">color: white;</string>
</property>
<property name="text">
<string>Filtered by: None</string>
</property>
<property name="wordWrap">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<widget class="AzQtComponents::ExtendedLabel" name="m_clearFiltersButton">
<property name="font">
<font>
<pointsize>10</pointsize>
<weight>75</weight>
<bold>true</bold>
<kerning>true</kerning>
</font>
</property>
<property name="text">
<string>Clear</string>
</property>
</widget>
</item>
</layout>
</widget>
<customwidgets>
<customwidget>
<class>AzQtComponents::ExtendedLabel</class>
<extends>QLabel</extends>
<header>AzQtComponents/Components/ExtendedLabel.h</header>
</customwidget>
</customwidgets>
<connections/>
</ui>
@@ -0,0 +1,176 @@
/*
* 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 <AzToolsFramework/AssetBrowser/Search/SearchWidget.h>
#include <AzCore/Asset/AssetTypeInfoBus.h>
#include <AzCore/std/containers/vector.h>
AZ_PUSH_DISABLE_WARNING(4251, "-Wunknown-warning-option") // 'QTextFormat::d': class 'QSharedDataPointer<QTextFormatPrivate>' needs to have dll-interface to be used by clients of class 'QTextFormat'
#include <QLineEdit>
#include <QToolButton>
AZ_POP_DISABLE_WARNING
namespace AzToolsFramework
{
namespace AssetBrowser
{
namespace
{
AzQtComponents::SearchTypeFilterList buildTypesFilterList()
{
AzQtComponents::SearchTypeFilterList filters;
EBusAggregateUniqueResults<QString> groups;
AZ::AssetTypeInfoBus::BroadcastResult(groups, &AZ::AssetTypeInfo::GetGroup);
// Group "Other" should be in the end of the list, and "Hidden" should not be on the list at all
for (const QString& group : groups.values)
{
if (group != "Hidden")
{
EBusAggregateAssetTypesIfBelongsToGroup types(group);
AZ::AssetTypeInfoBus::BroadcastResult(types, &AZ::AssetTypeInfo::GetAssetType);
if (!types.values.empty())
{
AssetGroupFilter* groupFilter = new AssetGroupFilter();
groupFilter->SetAssetGroup(group);
AzQtComponents::SearchTypeFilter stFilter;
stFilter.displayName = group;
stFilter.metadata = QVariant::fromValue(FilterConstType(groupFilter));
filters.push_back(stFilter);
}
}
}
std::sort(filters.begin(), filters.end(),
[](const AzQtComponents::SearchTypeFilter& a, const AzQtComponents::SearchTypeFilter& b)
{
const int categoryResult = QString::compare(a.category, b.category, Qt::CaseInsensitive);
if (categoryResult != 0)
{
return categoryResult < 0;
}
else if (a.displayName == QStringLiteral("Other"))
{
return false;
}
else if (b.displayName == QStringLiteral("Other"))
{
return true;
}
return QString::compare(a.displayName, b.displayName, Qt::CaseInsensitive) < 0;
});
return filters;
}
}
SearchWidget::SearchWidget(QWidget* parent)
: AzQtComponents::FilteredSearchWidget(parent)
, m_filter(new CompositeFilter(CompositeFilter::LogicOperatorType::AND))
, m_stringFilter(new CompositeFilter(CompositeFilter::LogicOperatorType::AND))
, m_typesFilter(new CompositeFilter(CompositeFilter::LogicOperatorType::OR))
{
m_filter->SetFilterPropagation(AssetBrowserEntryFilter::PropagateDirection::Down);
m_stringFilter->SetFilterPropagation(AssetBrowserEntryFilter::PropagateDirection::Up);
m_stringFilter->SetTag("String");
m_typesFilter->SetFilterPropagation(AssetBrowserEntryFilter::PropagateDirection::Down);
m_typesFilter->SetTag("AssetTypes");
connect(this, &AzQtComponents::FilteredSearchWidget::TextFilterChanged, this,
[this](const QString& text)
{
if (!filterLineEdit()->isHidden())
{
m_stringFilter->RemoveAllFilters();
auto stringList = text.split(' ', Qt::SkipEmptyParts);
for (auto& str : stringList)
{
auto stringFilter = new StringFilter();
stringFilter->SetFilterString(str);
m_stringFilter->AddFilter(FilterConstType(stringFilter));
}
}
});
connect(this, &AzQtComponents::FilteredSearchWidget::TypeFilterChanged, this,
[this](const AzQtComponents::SearchTypeFilterList& filters)
{
if (!filterTypePushButton()->isHidden())
{
m_typesFilter->RemoveAllFilters();
if (filters.isEmpty())
{
m_typesFilter->SetEmptyResult(true);
}
else
{
for (auto it = filters.constBegin(), end = filters.constEnd(); it != end; ++it)
{
m_typesFilter->AddFilter((*it).metadata.value<FilterConstType>());
}
}
}
});
}
void SearchWidget::Setup(bool stringFilter, bool assetTypeFilter)
{
ClearTextFilter();
ClearTypeFilter();
m_filter->RemoveAllFilters();
SetTextFilterVisible(stringFilter);
SetTypeFilterVisible(assetTypeFilter);
if (stringFilter)
{
m_filter->AddFilter(m_stringFilter);
}
// do not show assets in Hidden group
auto hiddenGroupFilter = new AssetGroupFilter();
hiddenGroupFilter->SetAssetGroup("Hidden");
auto inverseFilter = new InverseFilter();
inverseFilter->SetFilter(FilterConstType(hiddenGroupFilter));
m_filter->AddFilter(FilterConstType(inverseFilter));
// hide irrelevant
auto cleanerProductsFilter = new CleanerProductsFilter();
m_filter->AddFilter(FilterConstType(cleanerProductsFilter));
if (assetTypeFilter)
{
m_filter->AddFilter(FilterConstType(m_typesFilter));
SetTypeFilters(buildTypesFilterList());
}
}
QSharedPointer<CompositeFilter> SearchWidget::GetFilter() const
{
return m_filter;
}
} // namespace AssetBrowser
} // namespace AzToolsFramework
#include "AssetBrowser/Search/moc_SearchWidget.cpp"
@@ -0,0 +1,51 @@
/*
* 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.
*
*/
#pragma once
#if !defined(Q_MOC_RUN)
#include <AzCore/PlatformDef.h>
AZ_PUSH_DISABLE_WARNING(4127, "-Wunknown-warning-option") // conditional expression is constant
#include <AzToolsFramework/AssetBrowser/Search/Filter.h>
AZ_POP_DISABLE_WARNING
AZ_PUSH_DISABLE_WARNING(4244 4251, "-Wunknown-warning-option")
#include <AzQtComponents/Components/FilteredSearchWidget.h>
#include <QSharedPointer>
AZ_POP_DISABLE_WARNING
#endif
namespace AzToolsFramework
{
namespace AssetBrowser
{
class SearchWidget
: public AzQtComponents::FilteredSearchWidget
{
Q_OBJECT
public:
explicit SearchWidget(QWidget* parent = nullptr);
void Setup(bool stringFilter, bool assetTypeFilter);
QSharedPointer<CompositeFilter> GetFilter() const;
QString GetFilterString() const { return textFilter(); }
void ClearStringFilter() { ClearTextFilter(); }
private:
QSharedPointer<CompositeFilter> m_filter;
QSharedPointer<CompositeFilter> m_stringFilter;
QSharedPointer<CompositeFilter> m_typesFilter;
};
} // namespace AssetBrowser
} // namespace AzToolsFramework
@@ -0,0 +1,125 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>SearchWidgetClass</class>
<widget class="QWidget" name="SearchWidgetClass">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>304</width>
<height>27</height>
</rect>
</property>
<property name="windowTitle">
<string>Form</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<property name="spacing">
<number>0</number>
</property>
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
<item>
<layout class="QHBoxLayout" name="m_horizontalLayout">
<property name="spacing">
<number>0</number>
</property>
<item>
<widget class="QLineEdit" name="m_textSearch">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>0</width>
<height>25</height>
</size>
</property>
<property name="styleSheet">
<string notr="true">selection-background-color: rgb(233, 99, 0);
background: #6e7071;
background-image: url(:/stylesheet/img/search.svg);
background-repeat: no-repeat;
background-position: left;
padding: 2 2 2 24;
color: rgb(255, 255, 255);</string>
</property>
<property name="inputMask">
<string/>
</property>
<property name="text">
<string/>
</property>
<property name="frame">
<bool>false</bool>
</property>
<property name="placeholderText">
<string>Search...</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="m_buttonClearFilter">
<property name="sizePolicy">
<sizepolicy hsizetype="Minimum" vsizetype="Minimum">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="maximumSize">
<size>
<width>16777215</width>
<height>25</height>
</size>
</property>
<property name="text">
<string/>
</property>
<property name="flat">
<bool>false</bool>
</property>
</widget>
</item>
<item>
<widget class="AzToolsFramework::AssetBrowser::SearchAssetTypeSelectorWidget" name="m_assetTypeSelector" native="true">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>32</width>
<height>25</height>
</size>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</widget>
<customwidgets>
<customwidget>
<class>AzToolsFramework::AssetBrowser::SearchAssetTypeSelectorWidget</class>
<extends>QWidget</extends>
<header>AzToolsFramework/AssetBrowser/Search/SearchAssetTypeSelectorWidget.h</header>
<container>1</container>
</customwidget>
</customwidgets>
<connections/>
</ui>
@@ -0,0 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:1b39515aba246a0c4d7426d7ae1f25890b5bf3890567f1f9a3191d06bc67734a
size 17376
@@ -0,0 +1,15 @@
<?xml version="1.0" encoding="UTF-8"?>
<svg width="12px" height="13px" viewBox="0 0 12 13" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
<!-- Generator: Sketch 57.1 (83088) - https://sketch.com -->
<title>Icons / System / Window Controls / Close</title>
<desc>Created with Sketch.</desc>
<g id="Symbols" stroke="none" stroke-width="1" fill="none" fill-rule="evenodd">
<g id="Tab-/-Selected-hover" transform="translate(-142.000000, -8.000000)" fill="#FFFFFF">
<g id="tab">
<g id="Icons-/-System-/-Window-Controls-/-Close" transform="translate(140.000000, 6.500000)">
<path d="M13.0769231,2 L14,2.92307692 L8.923,8 L14,13.0769231 L13.0769231,14 L8,8.923 L2.92307692,14 L2,13.0769231 L7.076,8 L2,2.92307692 L2.92307692,2 L8,7.076 L13.0769231,2 Z" id="close"></path>
</g>
</g>
</g>
</g>
</svg>

After

Width:  |  Height:  |  Size: 948 B

@@ -0,0 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:95801d5824584df03e9076295b2dc4609839fc5cd42a5ec5157d1b1e6d49c369
size 15655
@@ -0,0 +1,3 @@
<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24">
<polygon fill="#E9E9E9" fill-rule="evenodd" points="10 19 10 11.5 4 4 4 2 20 2 20 4 14 11.5 14 19 12 22 10 22"/>
</svg>

After

Width:  |  Height:  |  Size: 206 B

@@ -0,0 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:65b0a95d652f993f88f51f9270be5b48c9e496422fda03ba675202255ddde46e
size 15251
@@ -0,0 +1,7 @@
<RCC>
<qresource prefix="/AssetBrowser/Resources">
<file>search.svg</file>
<file>close.svg</file>
<file>filter.svg</file>
</qresource>
</RCC>
@@ -0,0 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<svg width="24px" height="24px" viewBox="0 0 24 24" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
<!-- Generator: Sketch 50.2 (55047) - http://www.bohemiancoding.com/sketch -->
<title>Search</title>
<desc>Created with Sketch.</desc>
<defs></defs>
<g id="Search" stroke="none" stroke-width="1" fill="none" fill-rule="evenodd">
<rect id="Icon-Background" x="0" y="0" width="24" height="24"></rect>
<path d="M20.9694824,19.6604004 L16.3757324,15.0666504 C17.4069824,13.7541504 17.9694824,12.1604004 17.9694824,10.4729004 C17.9694824,6.34790039 14.5944824,2.97290039 10.4694824,2.97290039 C6.34448242,2.97290039 2.96948242,6.34790039 2.96948242,10.4729004 C2.96948242,14.5979004 6.34448242,17.9729004 10.4694824,17.9729004 C12.1569824,17.9729004 13.7507324,17.4104004 15.0632324,16.3791504 L19.6569824,20.9729004 L20.9694824,19.6604004 Z M10.4694824,16.0979004 C7.37573242,16.0979004 4.84448242,13.5666504 4.84448242,10.4729004 C4.84448242,7.37915039 7.37573242,4.84790039 10.4694824,4.84790039 C13.5632324,4.84790039 16.0944824,7.37915039 16.0944824,10.4729004 C16.0944824,13.5666504 13.5632324,16.0979004 10.4694824,16.0979004 Z" id="Shape" fill="#E9E9E9" fill-rule="nonzero"></path>
</g>
</svg>

After

Width:  |  Height:  |  Size: 1.3 KiB