summaryrefslogtreecommitdiff
path: root/Userland/Libraries/LibGUI/ModelIndex.cpp
diff options
context:
space:
mode:
authorJelle Raaijmakers <jelle@gmta.nl>2021-05-31 23:47:01 +0200
committerAndreas Kling <kling@serenityos.org>2021-06-01 08:22:51 +0200
commit7a4445a1fe4a53746444d8c128a08ffbf8404493 (patch)
tree565f883710691092722dde9a2df7a6c9780d07a3 /Userland/Libraries/LibGUI/ModelIndex.cpp
parent67a5e9f0184eac51a7451f540845e49dfdc0b34a (diff)
downloadserenity-7a4445a1fe4a53746444d8c128a08ffbf8404493.zip
LibGUI/TreeView: Select parent on collapse
When collapsing a tree that contains the current selection, the parent node becomes selected instead.
Diffstat (limited to 'Userland/Libraries/LibGUI/ModelIndex.cpp')
-rw-r--r--Userland/Libraries/LibGUI/ModelIndex.cpp11
1 files changed, 11 insertions, 0 deletions
diff --git a/Userland/Libraries/LibGUI/ModelIndex.cpp b/Userland/Libraries/LibGUI/ModelIndex.cpp
index ac7108bd41..e095764d4d 100644
--- a/Userland/Libraries/LibGUI/ModelIndex.cpp
+++ b/Userland/Libraries/LibGUI/ModelIndex.cpp
@@ -19,6 +19,17 @@ Variant ModelIndex::data(ModelRole role) const
return model()->data(*this, role);
}
+bool ModelIndex::is_parent_of(const ModelIndex& child) const
+{
+ auto current_index = child.parent();
+ while (current_index.is_valid()) {
+ if (current_index == *this)
+ return true;
+ current_index = current_index.parent();
+ }
+ return false;
+}
+
ModelIndex ModelIndex::sibling(int row, int column) const
{
if (!is_valid())