mirror of
https://github.com/AxioDL/PrimeWorldEditor.git
synced 2025-12-17 17:05:37 +00:00
CWorldTreeModel: Use built-in filtering facilities
The ability to filter via a string is already built into the proxy model. This also extends the search bar to allow general regular expressions as well out of the box without any additional work.
This commit is contained in:
@@ -56,7 +56,7 @@ void CWorldInfoSidebar::OnActiveProjectChanged(const CGameProject* pProj)
|
||||
mpUI->WorldInfoWidget->setHidden(true);
|
||||
mpUI->AreaInfoWidget->setHidden(true);
|
||||
mpUI->AreaSearchLineEdit->clear();
|
||||
mProxyModel.SetFilterString({});
|
||||
mProxyModel.setFilterRegularExpression(QString());
|
||||
|
||||
mpUI->GameNameLabel->setText(pProj ? TO_QSTRING(pProj->Name()) : QString{});
|
||||
|
||||
@@ -82,7 +82,7 @@ void CWorldInfoSidebar::OnActiveProjectChanged(const CGameProject* pProj)
|
||||
|
||||
void CWorldInfoSidebar::OnAreaFilterStringChanged(const QString& rkFilter)
|
||||
{
|
||||
mProxyModel.SetFilterString(rkFilter);
|
||||
mProxyModel.setFilterRegularExpression(QRegularExpression(rkFilter, QRegularExpression::CaseInsensitiveOption));
|
||||
|
||||
// Expand top-level items that contain matches for the new filter string
|
||||
int NumTopLevel = mModel.rowCount(QModelIndex());
|
||||
|
||||
@@ -362,16 +362,20 @@ bool CWorldTreeProxyModel::lessThan(const QModelIndex& rkSourceLeft, const QMode
|
||||
bool CWorldTreeProxyModel::filterAcceptsRow(int SourceRow, const QModelIndex& rkSourceParent) const
|
||||
{
|
||||
// Always accept worlds
|
||||
if (!rkSourceParent.isValid() || mFilterString.isEmpty())
|
||||
if (!rkSourceParent.isValid())
|
||||
return true;
|
||||
|
||||
const CWorldTreeModel *pModel = qobject_cast<CWorldTreeModel*>(sourceModel());
|
||||
ASSERT(pModel != nullptr);
|
||||
const auto filterExpression = filterRegularExpression();
|
||||
if (filterExpression.pattern().isEmpty())
|
||||
return true;
|
||||
|
||||
for (int iCol = 0; iCol < pModel->columnCount(rkSourceParent); iCol++)
|
||||
const auto* model = qobject_cast<CWorldTreeModel*>(sourceModel());
|
||||
ASSERT(model != nullptr);
|
||||
|
||||
for (int column = 0; column < model->columnCount(rkSourceParent); column++)
|
||||
{
|
||||
const QModelIndex Index = pModel->index(SourceRow, iCol, rkSourceParent);
|
||||
if (pModel->data(Index, Qt::DisplayRole).toString().contains(mFilterString, Qt::CaseInsensitive))
|
||||
const QModelIndex index = model->index(SourceRow, column, rkSourceParent);
|
||||
if (model->data(index, Qt::DisplayRole).toString().contains(filterExpression))
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@@ -51,17 +51,10 @@ public slots:
|
||||
class CWorldTreeProxyModel : public QSortFilterProxyModel
|
||||
{
|
||||
Q_OBJECT
|
||||
QString mFilterString;
|
||||
|
||||
public:
|
||||
bool lessThan(const QModelIndex& rkSourceLeft, const QModelIndex& rkSourceRight) const override;
|
||||
bool filterAcceptsRow(int SourceRow, const QModelIndex& rkSourceParent) const override;
|
||||
|
||||
void SetFilterString(const QString& rkFilter)
|
||||
{
|
||||
mFilterString = rkFilter;
|
||||
invalidate();
|
||||
}
|
||||
};
|
||||
|
||||
#endif // CWORLDTREEMODEL_H
|
||||
|
||||
Reference in New Issue
Block a user