Mantid
Loading...
Searching...
No Matches
FilteredTreeModel.cpp
Go to the documentation of this file.
1// Mantid Repository : https://github.com/mantidproject/mantid
2//
3// Copyright © 2018 ISIS Rutherford Appleton Laboratory UKRI,
4// NScD Oak Ridge National Laboratory, European Spallation Source,
5// Institut Laue - Langevin & CSNS, Institute of High Energy Physics, CAS
6// SPDX - License - Identifier: GPL - 3.0 +
10
11FilteredTreeModel::FilteredTreeModel(RowLocationAdapter rowLocationAdapter, QObject *parent)
12 : QSortFilterProxyModel(parent), m_rowLocation(rowLocationAdapter) {
14}
15
17 m_predicate = nullptr;
18 invalidate();
19}
20
21bool FilteredTreeModel::isReset() const { return m_predicate == nullptr; }
22
23void FilteredTreeModel::setPredicate(std::unique_ptr<RowPredicate> predicate) {
24 m_predicate = std::move(predicate);
25 invalidate();
26}
27
29 return m_rowLocation.atIndex(fromMainModel(index, *sourceModel()));
30}
31
32bool FilteredTreeModel::filterAcceptsRow(int row, const QModelIndex &parent) const {
33 auto index = sourceModel()->index(row, 0, parent);
34 if (index.isValid()) {
35 if (m_predicate == nullptr || (*m_predicate)(rowLocationAt(index))) {
36 return true;
37 } else {
38 int rows = sourceModel()->rowCount(index);
39 for (auto r = 0; r < rows; r++)
40 if (filterAcceptsRow(r, index))
41 return true;
42 return false;
43 }
44 } else {
45 return false;
46 }
47}
48} // namespace MantidQt::MantidWidgets::Batch
std::map< DeltaEMode::Type, std::string > index
Definition: DeltaEMode.cpp:19
RowLocation rowLocationAt(QModelIndex const &index) const
FilteredTreeModel(RowLocationAdapter rowLocation, QObject *parent=nullptr)
void setPredicate(std::unique_ptr< RowPredicate > predicate)
bool filterAcceptsRow(int row, const QModelIndex &parent) const override
RowLocation atIndex(QModelIndexForMainModel const &index) const
QModelIndexForMainModel fromMainModel(QModelIndex const &mainModelIndex, QAbstractItemModel const &model)