From 0d88b9d892038c2c6d9593c716cdc91e4054db40 Mon Sep 17 00:00:00 2001 From: Esteban Papp <81431996+amznestebanpapp@users.noreply.github.com> Date: Mon, 8 Nov 2021 18:45:13 -0800 Subject: [PATCH] Removes DeepFilterProxyModel from Code/Editor/Plugins/EditorCommon Signed-off-by: Esteban Papp <81431996+amznestebanpapp@users.noreply.github.com> --- .../EditorCommon/DeepFilterProxyModel.cpp | 172 ------------------ .../EditorCommon/DeepFilterProxyModel.h | 48 ----- .../EditorCommon/editorcommon_files.cmake | 2 - 3 files changed, 222 deletions(-) delete mode 100644 Code/Editor/Plugins/EditorCommon/DeepFilterProxyModel.cpp delete mode 100644 Code/Editor/Plugins/EditorCommon/DeepFilterProxyModel.h diff --git a/Code/Editor/Plugins/EditorCommon/DeepFilterProxyModel.cpp b/Code/Editor/Plugins/EditorCommon/DeepFilterProxyModel.cpp deleted file mode 100644 index d4bcabdfbe..0000000000 --- a/Code/Editor/Plugins/EditorCommon/DeepFilterProxyModel.cpp +++ /dev/null @@ -1,172 +0,0 @@ -/* - * Copyright (c) Contributors to the Open 3D Engine Project. - * For complete copyright and license terms please see the LICENSE at the root of this distribution. - * - * SPDX-License-Identifier: Apache-2.0 OR MIT - * - */ - - -#include "DeepFilterProxyModel.h" -#include - -DeepFilterProxyModel::DeepFilterProxyModel(QObject* parent) - : QSortFilterProxyModel(parent) -{ -} - -void DeepFilterProxyModel::setFilterString(const QString& filter) -{ - m_filter = filter; - m_filterParts = m_filter.split(' ', Qt::SkipEmptyParts); - m_acceptCache.clear(); -} - -void DeepFilterProxyModel::invalidate() -{ - QSortFilterProxyModel::invalidate(); - m_acceptCache.clear(); -} - -QVariant DeepFilterProxyModel::data(const QModelIndex& index, int role) const -{ - if (role == Qt::ForegroundRole) - { - QModelIndex sourceIndex = mapToSource(index); - if (matchFilter(sourceIndex.row(), sourceIndex.parent())) - { - return QSortFilterProxyModel::data(index, role); - } - else - { - return QPalette().color(QPalette::Disabled, QPalette::Text); - } - } - else - { - return QSortFilterProxyModel::data(index, role); - } -} - - -void DeepFilterProxyModel::setFilterWildcard(const QString& pattern) -{ - m_acceptCache.clear(); - QSortFilterProxyModel::setFilterWildcard(pattern); -} - -bool DeepFilterProxyModel::matchFilter(int sourceRow, const QModelIndex& sourceParent) const -{ - int columnCount = sourceModel()->columnCount(sourceParent); - for (int i = 0; i < m_filterParts.size(); ++i) - { - bool atLeastOneContains = false; - for (int j = 0; j < columnCount; ++j) - { - QModelIndex index = sourceModel()->index(sourceRow, j, sourceParent); - QVariant data = sourceModel()->data(index, Qt::DisplayRole); - QString str(data.toString()); - if (str.isEmpty()) - { - if (m_filterParts.empty()) - { - atLeastOneContains = true; - } - } - else if (str.contains(m_filterParts[i], Qt::CaseInsensitive)) - { - atLeastOneContains = true; - } - } - if (!atLeastOneContains) - { - return false; - } - } - return true; -} - -bool DeepFilterProxyModel::filterAcceptsRow(int sourceRow, const QModelIndex& sourceParent) const -{ - if (matchFilter(sourceRow, sourceParent)) - { - return true; - } - - if (hasAcceptedChildrenCached(sourceRow, sourceParent)) - { - return true; - } - - return false; -} - -bool DeepFilterProxyModel::hasAcceptedChildrenCached(int sourceRow, const QModelIndex& sourceParent) const -{ - std::pair indexId = std::make_pair(sourceParent, sourceRow); - TAcceptCache::iterator it = m_acceptCache.find(indexId); - if (it == m_acceptCache.end()) - { - bool result = hasAcceptedChildren(sourceRow, sourceParent); - m_acceptCache[indexId] = result; - return result; - } - else - { - return it->second; - } -} - -bool DeepFilterProxyModel::hasAcceptedChildren(int sourceRow, const QModelIndex& sourceParent) const -{ - QModelIndex item = sourceModel()->index(sourceRow, 0, sourceParent); - if (!item.isValid()) - { - return false; - } - - int childCount = item.model()->rowCount(item); - if (childCount == 0) - { - return false; - } - - for (int i = 0; i < childCount; ++i) - { - if (filterAcceptsRow(i, item)) - { - return true; - } - } - - return false; -} - -QModelIndex DeepFilterProxyModel::findFirstMatchingIndex(const QModelIndex& root) -{ - int rowCount = this->rowCount(root); - for (int i = 0; i < rowCount; ++i) - { - QModelIndex index = this->index(i, 0, root); - if (!index.isValid()) - { - continue; - } - QModelIndex sourceIndex = mapToSource(index); - if (!sourceIndex.isValid()) - { - continue; - } - if (matchFilter(sourceIndex.row(), sourceIndex.parent())) - { - return index; - } - - QModelIndex child = findFirstMatchingIndex(index); - if (child.isValid()) - { - return child; - } - } - return QModelIndex(); -} diff --git a/Code/Editor/Plugins/EditorCommon/DeepFilterProxyModel.h b/Code/Editor/Plugins/EditorCommon/DeepFilterProxyModel.h deleted file mode 100644 index c7373ef18c..0000000000 --- a/Code/Editor/Plugins/EditorCommon/DeepFilterProxyModel.h +++ /dev/null @@ -1,48 +0,0 @@ -/* - * Copyright (c) Contributors to the Open 3D Engine Project. - * For complete copyright and license terms please see the LICENSE at the root of this distribution. - * - * SPDX-License-Identifier: Apache-2.0 OR MIT - * - */ - - -#ifndef CRYINCLUDE_EDITORCOMMON_DEEPFILTERPROXYMODEL_H -#define CRYINCLUDE_EDITORCOMMON_DEEPFILTERPROXYMODEL_H -#pragma once - -#include -#include -#include -#include "EditorCommonAPI.h" - -class EDITOR_COMMON_API DeepFilterProxyModel - : public QSortFilterProxyModel -{ -public: - DeepFilterProxyModel(QObject* parent); - - void setFilterString(const QString& filter); - void invalidate(); - - QVariant data(const QModelIndex& index, int role) const override; - - void setFilterWildcard(const QString& pattern); - - bool matchFilter(int source_row, const QModelIndex& source_parent) const; - bool filterAcceptsRow(int source_row, const QModelIndex& source_parent) const override; - bool hasAcceptedChildrenCached(int source_row, const QModelIndex& source_parent) const; - bool hasAcceptedChildren(int source_row, const QModelIndex& source_parent) const; - - QModelIndex findFirstMatchingIndex(const QModelIndex& root); - -private: - QString m_filter; - AZ_PUSH_DISABLE_DLL_EXPORT_MEMBER_WARNING - QStringList m_filterParts; - typedef std::map, bool> TAcceptCache; - mutable TAcceptCache m_acceptCache; - AZ_POP_DISABLE_DLL_EXPORT_MEMBER_WARNING -}; - -#endif // CRYINCLUDE_EDITORCOMMON_DEEPFILTERPROXYMODEL_H diff --git a/Code/Editor/Plugins/EditorCommon/editorcommon_files.cmake b/Code/Editor/Plugins/EditorCommon/editorcommon_files.cmake index 1c6efbdf2c..d07ab71acf 100644 --- a/Code/Editor/Plugins/EditorCommon/editorcommon_files.cmake +++ b/Code/Editor/Plugins/EditorCommon/editorcommon_files.cmake @@ -19,8 +19,6 @@ set(FILES SaveUtilities/AsyncSaveRunner.cpp AxisHelper.cpp DisplayContext.cpp - DeepFilterProxyModel.cpp - DeepFilterProxyModel.h Resource.h DrawingPrimitives/Ruler.cpp DrawingPrimitives/Ruler.h