mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 16:17:45 +00:00
LibGUI: Add is_toggled getter for TreeView
This has safer fallbacks than toggle_index, because we want to be able to call it on indices that don't have children.
This commit is contained in:
parent
d813bf77ee
commit
4e8cb0508f
2 changed files with 13 additions and 0 deletions
|
@ -158,6 +158,18 @@ void TreeView::toggle_index(ModelIndex const& index)
|
||||||
update();
|
update();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool TreeView::is_toggled(ModelIndex const& index)
|
||||||
|
{
|
||||||
|
if (model()->row_count(index) == 0) {
|
||||||
|
if (model()->parent_index(index).is_valid())
|
||||||
|
return is_toggled(model()->parent_index(index));
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
auto& metadata = ensure_metadata_for_index(index);
|
||||||
|
return metadata.open;
|
||||||
|
}
|
||||||
|
|
||||||
template<typename Callback>
|
template<typename Callback>
|
||||||
void TreeView::traverse_in_paint_order(Callback callback) const
|
void TreeView::traverse_in_paint_order(Callback callback) const
|
||||||
{
|
{
|
||||||
|
|
|
@ -21,6 +21,7 @@ public:
|
||||||
|
|
||||||
virtual int item_count() const override;
|
virtual int item_count() const override;
|
||||||
virtual void toggle_index(ModelIndex const&) override;
|
virtual void toggle_index(ModelIndex const&) override;
|
||||||
|
bool is_toggled(ModelIndex const& index);
|
||||||
|
|
||||||
void expand_tree(ModelIndex const& root = {});
|
void expand_tree(ModelIndex const& root = {});
|
||||||
void collapse_tree(ModelIndex const& root = {});
|
void collapse_tree(ModelIndex const& root = {});
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue