rewrite of the filter code to fix [LYN-4156][LYN-4545] (#1640)

* rewrite of the filter code to fix [LYN-4156][LYN-4545]

Signed-off-by: Alex Montgomery <alexmont@amazon.com>

* improved onRowCountChanged() per comments

Signed-off-by: Alex Montgomery <alexmont@amazon.com>
This commit is contained in:
alexmontAmazon
2021-06-29 17:31:27 -07:00
committed by GitHub
parent 9e85caa352
commit 69f2e06134
7 changed files with 217 additions and 161 deletions
@@ -41,18 +41,29 @@ namespace AzToolsFramework
{
}
bool EntityOutlinerSearchTypeSelector::filterItemOut(int unfilteredDataIndex, bool itemMatchesFilter, bool categoryMatchesFilter)
bool EntityOutlinerSearchTypeSelector::filterItemOut(const QModelIndex& sourceIndex, bool filteredByBase)
{
bool unfilteredIndexInvalid = (unfilteredDataIndex >= aznumeric_cast<int>(EntityOutlinerSearchWidget::GlobalSearchCriteria::FirstRealFilter));
return SearchTypeSelector::filterItemOut(unfilteredDataIndex, itemMatchesFilter, categoryMatchesFilter) && unfilteredIndexInvalid;
auto* currItem = m_model->itemFromIndex(sourceIndex);
if (currItem != nullptr)
{
int unfilteredIndex = getUnfilteredDataIndex(currItem);
if (unfilteredIndex >= 0 && unfilteredIndex < aznumeric_cast<int>(EntityOutlinerSearchWidget::GlobalSearchCriteria::FirstRealFilter))
{
// never filter out the categories before FirstRealFilter (unlocked/locked, visible/hidden, etc.)
return false;
}
}
// no special case, return the result of the base filter
return filteredByBase;
}
void EntityOutlinerSearchTypeSelector::initItem(QStandardItem* item, const AzQtComponents::SearchTypeFilter& filter, int unfilteredDataIndex)
{
if (filter.displayName != "--------")
SearchTypeSelector::initItem(item, filter, unfilteredDataIndex);
if (filter.displayName == "--------")
{
item->setCheckable(true);
item->setCheckState(filter.enabled ? Qt::Checked : Qt::Unchecked);
SearchTypeSelector::initItem(item, filter, unfilteredDataIndex);
item->setCheckable(false);
}
if (unfilteredDataIndex < aznumeric_cast<int>(EntityOutlinerSearchWidget::GlobalSearchCriteria::FirstRealFilter))
@@ -44,8 +44,8 @@ namespace AzToolsFramework
EntityOutlinerSearchTypeSelector(QWidget* parent = nullptr);
protected:
// can be used to override the logic when adding items in RepopulateDataModel
bool filterItemOut(int unfilteredDataIndex, bool itemMatchesFilter, bool categoryMatchesFilter) override;
// override the logic of accepting filter categories
bool filterItemOut(const QModelIndex& sourceIndex, bool filteredByBase) override;
void initItem(QStandardItem* item, const AzQtComponents::SearchTypeFilter& filter, int unfilteredDataIndex) override;
int GetNumFixedItems() override;
};