|
@@ -7,14 +7,12 @@
|
|
*/
|
|
*/
|
|
|
|
|
|
#include <AzCore/Asset/AssetTypeInfoBus.h>
|
|
#include <AzCore/Asset/AssetTypeInfoBus.h>
|
|
-
|
|
|
|
#include <AzFramework/StringFunc/StringFunc.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/AssetBrowserBus.h>
|
|
#include <AzToolsFramework/AssetBrowser/EBusFindAssetTypeByName.h>
|
|
#include <AzToolsFramework/AssetBrowser/EBusFindAssetTypeByName.h>
|
|
|
|
+#include <AzToolsFramework/AssetBrowser/Entries/AssetBrowserEntry.h>
|
|
|
|
+#include <AzToolsFramework/AssetBrowser/Entries/ProductAssetBrowserEntry.h>
|
|
|
|
+#include <AzToolsFramework/AssetBrowser/Search/Filter.h>
|
|
|
|
|
|
namespace AzToolsFramework
|
|
namespace AzToolsFramework
|
|
{
|
|
{
|
|
@@ -22,109 +20,76 @@ namespace AzToolsFramework
|
|
{
|
|
{
|
|
namespace
|
|
namespace
|
|
{
|
|
{
|
|
- bool StringMatch(const QString& searched, const QString& text)
|
|
|
|
|
|
+ inline bool StringMatch(const QString& searched, const QString& text)
|
|
{
|
|
{
|
|
return text.contains(searched, Qt::CaseInsensitive);
|
|
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)
|
|
|
|
|
|
+ //! Expand all entries that are either parent or child relationship to the entry and write to result
|
|
|
|
+ void Expand(AZStd::unordered_set<const AssetBrowserEntry*>& result, const AssetBrowserEntry* entry)
|
|
{
|
|
{
|
|
- // 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())
|
|
|
|
|
|
+ entry->VisitUp(
|
|
|
|
+ [&](const auto& currentEntry)
|
|
{
|
|
{
|
|
- 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);
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
|
|
+ result.insert(currentEntry);
|
|
|
|
+ return true;
|
|
|
|
+ });
|
|
|
|
|
|
- //! 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);
|
|
|
|
|
|
+ entry->VisitDown(
|
|
|
|
+ [&](const auto& currentEntry)
|
|
|
|
+ {
|
|
|
|
+ result.reserve(result.size() + currentEntry->GetChildCount() + 1);
|
|
|
|
+ result.insert(currentEntry);
|
|
|
|
+ return true;
|
|
|
|
+ });
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
|
//////////////////////////////////////////////////////////////////////////
|
|
// AssetBrowserEntryFilter
|
|
// AssetBrowserEntryFilter
|
|
//////////////////////////////////////////////////////////////////////////
|
|
//////////////////////////////////////////////////////////////////////////
|
|
- AssetBrowserEntryFilter::AssetBrowserEntryFilter()
|
|
|
|
- : m_direction(None)
|
|
|
|
- {
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
bool AssetBrowserEntryFilter::Match(const AssetBrowserEntry* entry) const
|
|
bool AssetBrowserEntryFilter::Match(const AssetBrowserEntry* entry) const
|
|
{
|
|
{
|
|
- if (MatchInternal(entry))
|
|
|
|
|
|
+ if (m_direction == None)
|
|
{
|
|
{
|
|
- return true;
|
|
|
|
|
|
+ if (MatchInternal(entry))
|
|
|
|
+ {
|
|
|
|
+ return true;
|
|
|
|
+ }
|
|
}
|
|
}
|
|
|
|
|
|
if (m_direction & Up)
|
|
if (m_direction & Up)
|
|
{
|
|
{
|
|
- auto parent = entry->GetParent();
|
|
|
|
- while (parent && parent->GetEntryType() != AssetBrowserEntry::AssetEntryType::Root)
|
|
|
|
- {
|
|
|
|
- if (MatchInternal(parent))
|
|
|
|
|
|
+ bool result = false;
|
|
|
|
+ entry->VisitUp(
|
|
|
|
+ [&result, this](const auto& currentEntry)
|
|
{
|
|
{
|
|
- return true;
|
|
|
|
- }
|
|
|
|
- parent = parent->GetParent();
|
|
|
|
|
|
+ result = result || MatchInternal(currentEntry);
|
|
|
|
+ return !result;
|
|
|
|
+ });
|
|
|
|
+
|
|
|
|
+ if (result)
|
|
|
|
+ {
|
|
|
|
+ return true;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
+
|
|
if (m_direction & Down)
|
|
if (m_direction & Down)
|
|
{
|
|
{
|
|
- AZStd::vector<const AssetBrowserEntry*> children;
|
|
|
|
- entry->GetChildren<AssetBrowserEntry>(children);
|
|
|
|
- for (auto child : children)
|
|
|
|
- {
|
|
|
|
- if (MatchDown(child))
|
|
|
|
|
|
+ bool result = false;
|
|
|
|
+ entry->VisitDown(
|
|
|
|
+ [&](const auto& currentEntry)
|
|
{
|
|
{
|
|
- return true;
|
|
|
|
- }
|
|
|
|
|
|
+ result = result || MatchInternal(currentEntry);
|
|
|
|
+ return !result;
|
|
|
|
+ });
|
|
|
|
+
|
|
|
|
+ if (result)
|
|
|
|
+ {
|
|
|
|
+ return true;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
+
|
|
return false;
|
|
return false;
|
|
}
|
|
}
|
|
|
|
|
|
@@ -133,27 +98,43 @@ namespace AzToolsFramework
|
|
return MatchInternal(entry);
|
|
return MatchInternal(entry);
|
|
}
|
|
}
|
|
|
|
|
|
- void AssetBrowserEntryFilter::Filter(AZStd::vector<const AssetBrowserEntry*>& result, const AssetBrowserEntry* entry) const
|
|
|
|
|
|
+ void AssetBrowserEntryFilter::Filter(AZStd::unordered_set<const AssetBrowserEntry*>& result, const AssetBrowserEntry* entry) const
|
|
{
|
|
{
|
|
- FilterInternal(result, entry);
|
|
|
|
-
|
|
|
|
- if (m_direction & Up)
|
|
|
|
|
|
+ if (m_direction == None)
|
|
{
|
|
{
|
|
- auto parent = entry->GetParent();
|
|
|
|
- while (parent && parent->GetEntryType() != AssetBrowserEntry::AssetEntryType::Root)
|
|
|
|
|
|
+ if (MatchInternal(entry))
|
|
{
|
|
{
|
|
- FilterInternal(result, parent);
|
|
|
|
- parent = parent->GetParent();
|
|
|
|
|
|
+ Expand(result, entry);
|
|
|
|
+ return;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ if (m_direction & Up)
|
|
|
|
+ {
|
|
|
|
+ entry->VisitUp(
|
|
|
|
+ [&result, this](const auto& currentEntry)
|
|
|
|
+ {
|
|
|
|
+ if (MatchInternal(currentEntry))
|
|
|
|
+ {
|
|
|
|
+ Expand(result, currentEntry);
|
|
|
|
+ return false;
|
|
|
|
+ }
|
|
|
|
+ return true;
|
|
|
|
+ });
|
|
|
|
+ }
|
|
|
|
+
|
|
if (m_direction & Down)
|
|
if (m_direction & Down)
|
|
{
|
|
{
|
|
- AZStd::vector<const AssetBrowserEntry*> children;
|
|
|
|
- entry->GetChildren<AssetBrowserEntry>(children);
|
|
|
|
- for (auto child : children)
|
|
|
|
- {
|
|
|
|
- FilterDown(result, child);
|
|
|
|
- }
|
|
|
|
|
|
+ entry->VisitDown(
|
|
|
|
+ [&](const auto& currentEntry)
|
|
|
|
+ {
|
|
|
|
+ if (MatchInternal(currentEntry))
|
|
|
|
+ {
|
|
|
|
+ Expand(result, currentEntry);
|
|
|
|
+ return false;
|
|
|
|
+ }
|
|
|
|
+ return true;
|
|
|
|
+ });
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
@@ -182,51 +163,18 @@ namespace AzToolsFramework
|
|
m_direction = 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::StringFilter()
|
|
|
|
- : m_filterString("") {}
|
|
|
|
|
|
+ AssetBrowserEntryFilter* StringFilter::Clone() const
|
|
|
|
+ {
|
|
|
|
+ auto clone = new StringFilter();
|
|
|
|
+ clone->m_name = m_name;
|
|
|
|
+ clone->m_tag = m_tag;
|
|
|
|
+ clone->m_direction = m_direction;
|
|
|
|
+ clone->m_filterString = m_filterString;
|
|
|
|
+ return clone;
|
|
|
|
+ }
|
|
|
|
|
|
void StringFilter::SetFilterString(const QString& filterString)
|
|
void StringFilter::SetFilterString(const QString& filterString)
|
|
{
|
|
{
|
|
@@ -258,6 +206,15 @@ namespace AzToolsFramework
|
|
{
|
|
{
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ AssetBrowserEntryFilter* CustomFilter::Clone() const
|
|
|
|
+ {
|
|
|
|
+ auto clone = new CustomFilter(m_filterFn);
|
|
|
|
+ clone->m_name = m_name;
|
|
|
|
+ clone->m_tag = m_tag;
|
|
|
|
+ clone->m_direction = m_direction;
|
|
|
|
+ return clone;
|
|
|
|
+ }
|
|
|
|
+
|
|
QString CustomFilter::GetNameInternal() const
|
|
QString CustomFilter::GetNameInternal() const
|
|
{
|
|
{
|
|
return "Custom Filter";
|
|
return "Custom Filter";
|
|
@@ -265,12 +222,22 @@ namespace AzToolsFramework
|
|
|
|
|
|
bool CustomFilter::MatchInternal(const AssetBrowserEntry* entry) const
|
|
bool CustomFilter::MatchInternal(const AssetBrowserEntry* entry) const
|
|
{
|
|
{
|
|
- return m_filterFn && m_filterFn(entry);
|
|
|
|
|
|
+ return !m_filterFn || m_filterFn(entry);
|
|
}
|
|
}
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
|
//////////////////////////////////////////////////////////////////////////
|
|
// RegExpFilter
|
|
// RegExpFilter
|
|
//////////////////////////////////////////////////////////////////////////
|
|
//////////////////////////////////////////////////////////////////////////
|
|
|
|
+ AssetBrowserEntryFilter* RegExpFilter::Clone() const
|
|
|
|
+ {
|
|
|
|
+ auto clone = new RegExpFilter();
|
|
|
|
+ clone->m_name = m_name;
|
|
|
|
+ clone->m_tag = m_tag;
|
|
|
|
+ clone->m_direction = m_direction;
|
|
|
|
+ clone->m_filterPattern = m_filterPattern;
|
|
|
|
+ return clone;
|
|
|
|
+ }
|
|
|
|
+
|
|
void RegExpFilter::SetFilterPattern(const QRegExp& filterPattern)
|
|
void RegExpFilter::SetFilterPattern(const QRegExp& filterPattern)
|
|
{
|
|
{
|
|
m_filterPattern = filterPattern;
|
|
m_filterPattern = filterPattern;
|
|
@@ -291,8 +258,15 @@ namespace AzToolsFramework
|
|
//////////////////////////////////////////////////////////////////////////
|
|
//////////////////////////////////////////////////////////////////////////
|
|
// AssetTypeFilter
|
|
// AssetTypeFilter
|
|
//////////////////////////////////////////////////////////////////////////
|
|
//////////////////////////////////////////////////////////////////////////
|
|
- AssetTypeFilter::AssetTypeFilter()
|
|
|
|
- : m_assetType(AZ::Data::AssetType::CreateNull()) {}
|
|
|
|
|
|
+ AssetBrowserEntryFilter* AssetTypeFilter::Clone() const
|
|
|
|
+ {
|
|
|
|
+ auto clone = new AssetTypeFilter();
|
|
|
|
+ clone->m_name = m_name;
|
|
|
|
+ clone->m_tag = m_tag;
|
|
|
|
+ clone->m_direction = m_direction;
|
|
|
|
+ clone->m_assetType = m_assetType;
|
|
|
|
+ return clone;
|
|
|
|
+ }
|
|
|
|
|
|
void AssetTypeFilter::SetAssetType(AZ::Data::AssetType assetType)
|
|
void AssetTypeFilter::SetAssetType(AZ::Data::AssetType assetType)
|
|
{
|
|
{
|
|
@@ -322,32 +296,36 @@ namespace AzToolsFramework
|
|
bool AssetTypeFilter::MatchInternal(const AssetBrowserEntry* entry) const
|
|
bool AssetTypeFilter::MatchInternal(const AssetBrowserEntry* entry) const
|
|
{
|
|
{
|
|
// this filter only works on products.
|
|
// this filter only works on products.
|
|
- if (entry->GetEntryType() == AssetBrowserEntry::AssetEntryType::Product)
|
|
|
|
|
|
+ const ProductAssetBrowserEntry* product = entry->GetEntryType() == AssetBrowserEntry::AssetEntryType::Product
|
|
|
|
+ ? static_cast<const ProductAssetBrowserEntry*>(entry)
|
|
|
|
+ : nullptr;
|
|
|
|
+ if (!product)
|
|
{
|
|
{
|
|
- if (m_assetType.IsNull())
|
|
|
|
- {
|
|
|
|
- return true;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- if (static_cast<const ProductAssetBrowserEntry*>(entry)->GetAssetType() == m_assetType)
|
|
|
|
- {
|
|
|
|
- return true;
|
|
|
|
- }
|
|
|
|
|
|
+ return false;
|
|
}
|
|
}
|
|
- return false;
|
|
|
|
|
|
+
|
|
|
|
+ return m_assetType.IsNull() || (product && product->GetAssetType() == m_assetType);
|
|
}
|
|
}
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
|
//////////////////////////////////////////////////////////////////////////
|
|
// AssetGroupFilter
|
|
// AssetGroupFilter
|
|
//////////////////////////////////////////////////////////////////////////
|
|
//////////////////////////////////////////////////////////////////////////
|
|
- AssetGroupFilter::AssetGroupFilter()
|
|
|
|
- : m_group("All")
|
|
|
|
|
|
+ AssetBrowserEntryFilter* AssetGroupFilter::Clone() const
|
|
{
|
|
{
|
|
|
|
+ auto clone = new AssetGroupFilter();
|
|
|
|
+ clone->m_name = m_name;
|
|
|
|
+ clone->m_tag = m_tag;
|
|
|
|
+ clone->m_direction = m_direction;
|
|
|
|
+ clone->SetAssetGroup(m_group);
|
|
|
|
+ return clone;
|
|
}
|
|
}
|
|
|
|
|
|
void AssetGroupFilter::SetAssetGroup(const QString& group)
|
|
void AssetGroupFilter::SetAssetGroup(const QString& group)
|
|
{
|
|
{
|
|
m_group = group;
|
|
m_group = group;
|
|
|
|
+ m_groupCrc = AZ::Crc32(group.toUtf8().constData());
|
|
|
|
+ m_groupIsAll = m_group.compare("All", Qt::CaseInsensitive) == 0;
|
|
|
|
+ m_groupIsOther = m_group.compare("Other", Qt::CaseInsensitive) == 0;
|
|
}
|
|
}
|
|
|
|
|
|
const QString& AssetGroupFilter::GetAssetTypeGroup() const
|
|
const QString& AssetGroupFilter::GetAssetTypeGroup() const
|
|
@@ -363,27 +341,15 @@ namespace AzToolsFramework
|
|
bool AssetGroupFilter::MatchInternal(const AssetBrowserEntry* entry) const
|
|
bool AssetGroupFilter::MatchInternal(const AssetBrowserEntry* entry) const
|
|
{
|
|
{
|
|
// this filter only works on products.
|
|
// this filter only works on products.
|
|
- if (entry->GetEntryType() != AssetBrowserEntry::AssetEntryType::Product)
|
|
|
|
|
|
+ const ProductAssetBrowserEntry* product = entry->GetEntryType() == AssetBrowserEntry::AssetEntryType::Product
|
|
|
|
+ ? static_cast<const ProductAssetBrowserEntry*>(entry)
|
|
|
|
+ : nullptr;
|
|
|
|
+ if (!product)
|
|
{
|
|
{
|
|
return false;
|
|
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);
|
|
|
|
|
|
+ return (m_groupIsAll) || (m_groupIsOther && product->GetGroupName().isEmpty()) || (m_groupCrc == product->GetGroupNameCrc());
|
|
}
|
|
}
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
|
//////////////////////////////////////////////////////////////////////////
|
|
@@ -394,6 +360,16 @@ namespace AzToolsFramework
|
|
{
|
|
{
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ AssetBrowserEntryFilter* EntryTypeFilter::Clone() const
|
|
|
|
+ {
|
|
|
|
+ auto clone = new EntryTypeFilter();
|
|
|
|
+ clone->m_name = m_name;
|
|
|
|
+ clone->m_tag = m_tag;
|
|
|
|
+ clone->m_direction = m_direction;
|
|
|
|
+ clone->m_entryType = m_entryType;
|
|
|
|
+ return clone;
|
|
|
|
+ }
|
|
|
|
+
|
|
void EntryTypeFilter::SetEntryType(AssetBrowserEntry::AssetEntryType entryType)
|
|
void EntryTypeFilter::SetEntryType(AssetBrowserEntry::AssetEntryType entryType)
|
|
{
|
|
{
|
|
m_entryType = entryType;
|
|
m_entryType = entryType;
|
|
@@ -419,7 +395,23 @@ namespace AzToolsFramework
|
|
//////////////////////////////////////////////////////////////////////////
|
|
//////////////////////////////////////////////////////////////////////////
|
|
CompositeFilter::CompositeFilter(LogicOperatorType logicOperator)
|
|
CompositeFilter::CompositeFilter(LogicOperatorType logicOperator)
|
|
: m_logicOperator(logicOperator)
|
|
: m_logicOperator(logicOperator)
|
|
- , m_emptyResult(true) {}
|
|
|
|
|
|
+ {
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ AssetBrowserEntryFilter* CompositeFilter::Clone() const
|
|
|
|
+ {
|
|
|
|
+ auto clone = new CompositeFilter();
|
|
|
|
+ clone->m_name = m_name;
|
|
|
|
+ clone->m_tag = m_tag;
|
|
|
|
+ clone->m_direction = m_direction;
|
|
|
|
+ clone->m_logicOperator = m_logicOperator;
|
|
|
|
+ clone->m_emptyResult = m_emptyResult;
|
|
|
|
+ for (const auto& subFilter : m_subFilters)
|
|
|
|
+ {
|
|
|
|
+ clone->AddFilter(FilterConstType(subFilter->Clone()));
|
|
|
|
+ }
|
|
|
|
+ return clone;
|
|
|
|
+ }
|
|
|
|
|
|
void CompositeFilter::AddFilter(FilterConstType filter)
|
|
void CompositeFilter::AddFilter(FilterConstType filter)
|
|
{
|
|
{
|
|
@@ -464,7 +456,7 @@ namespace AzToolsFramework
|
|
|
|
|
|
QString CompositeFilter::GetNameInternal() const
|
|
QString CompositeFilter::GetNameInternal() const
|
|
{
|
|
{
|
|
- QString name = "";
|
|
|
|
|
|
+ QString name;
|
|
for (auto it = m_subFilters.begin(); it != m_subFilters.end(); ++it)
|
|
for (auto it = m_subFilters.begin(); it != m_subFilters.end(); ++it)
|
|
{
|
|
{
|
|
name += (*it)->GetName();
|
|
name += (*it)->GetName();
|
|
@@ -478,7 +470,7 @@ namespace AzToolsFramework
|
|
|
|
|
|
bool CompositeFilter::MatchInternal(const AssetBrowserEntry* entry) const
|
|
bool CompositeFilter::MatchInternal(const AssetBrowserEntry* entry) const
|
|
{
|
|
{
|
|
- if (m_subFilters.count() == 0)
|
|
|
|
|
|
+ if (m_subFilters.empty())
|
|
{
|
|
{
|
|
return m_emptyResult;
|
|
return m_emptyResult;
|
|
}
|
|
}
|
|
@@ -486,124 +478,59 @@ namespace AzToolsFramework
|
|
// AND
|
|
// AND
|
|
if (m_logicOperator == LogicOperatorType::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);
|
|
|
|
|
|
+ return AZStd::all_of(m_subFilters.begin(), m_subFilters.end(), [&entry](const auto& filter) {
|
|
|
|
+ return filter->Match(entry);
|
|
|
|
+ });
|
|
}
|
|
}
|
|
// OR
|
|
// OR
|
|
- else
|
|
|
|
- {
|
|
|
|
- for (auto filter : m_subFilters)
|
|
|
|
- {
|
|
|
|
- AZStd::vector<const AssetBrowserEntry*> set;
|
|
|
|
- filter->Filter(set, entry);
|
|
|
|
- Join(result, set);
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
|
|
+ return AZStd::any_of(m_subFilters.begin(), m_subFilters.end(), [&entry](const auto& filter) {
|
|
|
|
+ return filter->Match(entry);
|
|
|
|
+ });
|
|
}
|
|
}
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
|
//////////////////////////////////////////////////////////////////////////
|
|
// InverseFilter
|
|
// InverseFilter
|
|
//////////////////////////////////////////////////////////////////////////
|
|
//////////////////////////////////////////////////////////////////////////
|
|
- InverseFilter::InverseFilter() {}
|
|
|
|
|
|
+ AssetBrowserEntryFilter* InverseFilter::Clone() const
|
|
|
|
+ {
|
|
|
|
+ auto clone = new InverseFilter();
|
|
|
|
+ clone->m_name = m_name;
|
|
|
|
+ clone->m_tag = m_tag;
|
|
|
|
+ clone->m_direction = m_direction;
|
|
|
|
+ clone->m_filter = FilterConstType(m_filter->Clone());
|
|
|
|
+ return clone;
|
|
|
|
+ }
|
|
|
|
|
|
void InverseFilter::SetFilter(FilterConstType filter)
|
|
void InverseFilter::SetFilter(FilterConstType filter)
|
|
{
|
|
{
|
|
- if (m_filter == filter)
|
|
|
|
|
|
+ if (m_filter != filter)
|
|
{
|
|
{
|
|
- return;
|
|
|
|
|
|
+ m_filter = filter;
|
|
|
|
+ Q_EMIT updatedSignal();
|
|
}
|
|
}
|
|
-
|
|
|
|
- m_filter = filter;
|
|
|
|
- Q_EMIT updatedSignal();
|
|
|
|
}
|
|
}
|
|
|
|
|
|
QString InverseFilter::GetNameInternal() const
|
|
QString InverseFilter::GetNameInternal() const
|
|
{
|
|
{
|
|
- if (m_filter.isNull())
|
|
|
|
- {
|
|
|
|
- QString name = tr("NOT");
|
|
|
|
- }
|
|
|
|
- QString name = tr("NOT (%1)").arg(m_filter->GetName());
|
|
|
|
- return name;
|
|
|
|
|
|
+ return m_filter.isNull() ? tr("NOT") : tr("NOT (%1)").arg(m_filter->GetName());
|
|
}
|
|
}
|
|
|
|
|
|
bool InverseFilter::MatchInternal(const AssetBrowserEntry* entry) const
|
|
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);
|
|
|
|
- }
|
|
|
|
|
|
+ return m_filter && !m_filter->Match(entry);
|
|
}
|
|
}
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
|
//////////////////////////////////////////////////////////////////////////
|
|
// CleanerProductsFilter
|
|
// CleanerProductsFilter
|
|
//////////////////////////////////////////////////////////////////////////
|
|
//////////////////////////////////////////////////////////////////////////
|
|
- CleanerProductsFilter::CleanerProductsFilter() {}
|
|
|
|
|
|
+ AssetBrowserEntryFilter* CleanerProductsFilter::Clone() const
|
|
|
|
+ {
|
|
|
|
+ auto clone = new CleanerProductsFilter();
|
|
|
|
+ clone->m_name = m_name;
|
|
|
|
+ clone->m_tag = m_tag;
|
|
|
|
+ clone->m_direction = m_direction;
|
|
|
|
+ return clone;
|
|
|
|
+ }
|
|
|
|
|
|
QString CleanerProductsFilter::GetNameInternal() const
|
|
QString CleanerProductsFilter::GetNameInternal() const
|
|
{
|
|
{
|
|
@@ -612,39 +539,30 @@ namespace AzToolsFramework
|
|
|
|
|
|
bool CleanerProductsFilter::MatchInternal(const AssetBrowserEntry* entry) const
|
|
bool CleanerProductsFilter::MatchInternal(const AssetBrowserEntry* entry) const
|
|
{
|
|
{
|
|
- auto product = azrtti_cast<const ProductAssetBrowserEntry*>(entry);
|
|
|
|
|
|
+ const ProductAssetBrowserEntry* product = entry->GetEntryType() == AssetBrowserEntry::AssetEntryType::Product
|
|
|
|
+ ? static_cast<const ProductAssetBrowserEntry*>(entry)
|
|
|
|
+ : nullptr;
|
|
if (!product)
|
|
if (!product)
|
|
{
|
|
{
|
|
return true;
|
|
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())
|
|
|
|
|
|
+ auto source = product->GetParent();
|
|
|
|
+ if (!source || source->GetChildCount() != 1)
|
|
{
|
|
{
|
|
return true;
|
|
return true;
|
|
}
|
|
}
|
|
-
|
|
|
|
- return false;
|
|
|
|
- }
|
|
|
|
|
|
|
|
- void CleanerProductsFilter::FilterInternal(AZStd::vector<const AssetBrowserEntry*>& result, const AssetBrowserEntry* entry) const
|
|
|
|
- {
|
|
|
|
- if (MatchInternal(entry))
|
|
|
|
- {
|
|
|
|
- Expand(result, entry);
|
|
|
|
- }
|
|
|
|
|
|
+ bool result = false;
|
|
|
|
+ AZ::AssetTypeInfoBus::Event(
|
|
|
|
+ product->GetAssetType(),
|
|
|
|
+ [&result](AZ::AssetTypeInfoBus::Events* handler)
|
|
|
|
+ {
|
|
|
|
+ const char* assetTypeName = handler->GetAssetTypeDisplayName();
|
|
|
|
+ result = assetTypeName && assetTypeName[0];
|
|
|
|
+ });
|
|
|
|
+ return result;
|
|
}
|
|
}
|
|
-
|
|
|
|
} // namespace AssetBrowser
|
|
} // namespace AssetBrowser
|
|
} // namespace AzToolsFramework
|
|
} // namespace AzToolsFramework
|
|
|
|
|