LibGUI: Store correct address in TreeViewModel's ModelIndices

After `8a48246` m_nodes[row] amd m_child_nodes[row] return a
NonnullRefPtr<Node>, so we were putting the wrong address
into the ModelIndex's data.
This commit is contained in:
Tim Ledbetter 2023-03-16 00:14:25 +00:00 committed by Jelle Raaijmakers
parent 49b07cda12
commit 2fe4be40af
Notes: sideshowbarker 2024-07-17 22:41:14 +09:00

View file

@ -13,12 +13,12 @@ ModelIndex TreeViewModel::index(int row, int column, ModelIndex const& parent) c
if (!parent.is_valid()) {
if (static_cast<size_t>(row) >= m_nodes.size())
return {};
return create_index(row, column, &m_nodes[row]);
return create_index(row, column, m_nodes[row].ptr());
}
auto const& parent_node = *static_cast<Node const*>(parent.internal_data());
if (static_cast<size_t>(row) >= parent_node.child_nodes().size())
return {};
auto const* child = &parent_node.child_nodes()[row];
auto const* child = parent_node.child_nodes()[row].ptr();
return create_index(row, column, child);
}
@ -32,7 +32,7 @@ ModelIndex TreeViewModel::parent_index(ModelIndex const& index) const
return {};
if (parent_node->parent_node() == nullptr) {
for (size_t row = 0; row < m_nodes.size(); row++)
if (m_nodes[row] == parent_node)
if (m_nodes[row].ptr() == parent_node)
return create_index(static_cast<int>(row), 0, parent_node);
VERIFY_NOT_REACHED();
}