mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 08:47:34 +00:00
Profiler: Make the ProfileModel searchable
Note that this only searches the items at the same level as the selected index.
This commit is contained in:
parent
bf0315ff8f
commit
44cc6e1662
2 changed files with 27 additions and 0 deletions
|
@ -145,4 +145,29 @@ GUI::Variant ProfileModel::data(const GUI::ModelIndex& index, GUI::ModelRole rol
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Vector<GUI::ModelIndex> ProfileModel::matches(StringView const& searching, unsigned flags, GUI::ModelIndex const& parent)
|
||||||
|
{
|
||||||
|
RemoveReference<decltype(m_profile.roots())>* nodes { nullptr };
|
||||||
|
|
||||||
|
if (!parent.is_valid())
|
||||||
|
nodes = &m_profile.roots();
|
||||||
|
else
|
||||||
|
nodes = &static_cast<ProfileNode*>(parent.internal_data())->children();
|
||||||
|
|
||||||
|
if (!nodes)
|
||||||
|
return {};
|
||||||
|
|
||||||
|
Vector<GUI::ModelIndex> found_indices;
|
||||||
|
for (auto it = nodes->begin(); !it.is_end(); ++it) {
|
||||||
|
GUI::ModelIndex index = this->index(it.index(), StackFrame, parent);
|
||||||
|
if (!string_matches(data(index, GUI::ModelRole::Display).as_string(), searching, flags))
|
||||||
|
continue;
|
||||||
|
|
||||||
|
found_indices.append(index);
|
||||||
|
if (flags & FirstMatchOnly)
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
return found_indices;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -38,6 +38,8 @@ public:
|
||||||
virtual GUI::ModelIndex parent_index(const GUI::ModelIndex&) const override;
|
virtual GUI::ModelIndex parent_index(const GUI::ModelIndex&) const override;
|
||||||
virtual int tree_column() const override { return Column::StackFrame; }
|
virtual int tree_column() const override { return Column::StackFrame; }
|
||||||
virtual bool is_column_sortable(int) const override { return false; }
|
virtual bool is_column_sortable(int) const override { return false; }
|
||||||
|
virtual bool is_searchable() const override { return true; }
|
||||||
|
virtual Vector<GUI::ModelIndex> matches(StringView const&, unsigned flags, GUI::ModelIndex const&) override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
explicit ProfileModel(Profile&);
|
explicit ProfileModel(Profile&);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue