Serenity Operating System
1/*
2 * Copyright (c) 2018-2021, Andreas Kling <kling@serenityos.org>
3 *
4 * SPDX-License-Identifier: BSD-2-Clause
5 */
6
7#include <AK/DeprecatedString.h>
8#include <LibGUI/Model.h>
9#include <LibGUI/Variant.h>
10
11namespace GUI {
12
13Variant ModelIndex::data(ModelRole role) const
14{
15 if (!is_valid())
16 return {};
17
18 VERIFY(model());
19 return model()->data(*this, role);
20}
21
22bool ModelIndex::is_parent_of(ModelIndex const& child) const
23{
24 auto current_index = child.parent();
25 while (current_index.is_valid()) {
26 if (current_index == *this)
27 return true;
28 current_index = current_index.parent();
29 }
30 return false;
31}
32
33ModelIndex ModelIndex::sibling(int row, int column) const
34{
35 if (!is_valid())
36 return {};
37 VERIFY(model());
38 return model()->index(row, column, parent());
39}
40
41ModelIndex ModelIndex::sibling_at_column(int column) const
42{
43 if (!is_valid())
44 return {};
45 return sibling(row(), column);
46}
47
48}