mirror of
https://github.com/RGBCube/serenity
synced 2025-07-17 11:47:37 +00:00
LibGUI: Add convenient helpers for getting the sibling of a ModelIndex
This commit is contained in:
parent
10d9a8db71
commit
0c02dfcad5
2 changed files with 20 additions and 2 deletions
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org>
|
* Copyright (c) 2018-2021, Andreas Kling <kling@serenityos.org>
|
||||||
* All rights reserved.
|
* All rights reserved.
|
||||||
*
|
*
|
||||||
* Redistribution and use in source and binary forms, with or without
|
* Redistribution and use in source and binary forms, with or without
|
||||||
|
@ -39,4 +39,19 @@ Variant ModelIndex::data(ModelRole role) const
|
||||||
return model()->data(*this, role);
|
return model()->data(*this, role);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ModelIndex ModelIndex::sibling(int row, int column) const
|
||||||
|
{
|
||||||
|
if (!is_valid())
|
||||||
|
return {};
|
||||||
|
VERIFY(model());
|
||||||
|
return model()->index(row, column, parent());
|
||||||
|
}
|
||||||
|
|
||||||
|
ModelIndex ModelIndex::sibling_at_column(int column) const
|
||||||
|
{
|
||||||
|
if (!is_valid())
|
||||||
|
return {};
|
||||||
|
return sibling(row(), column);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org>
|
* Copyright (c) 2018-2021, Andreas Kling <kling@serenityos.org>
|
||||||
* All rights reserved.
|
* All rights reserved.
|
||||||
*
|
*
|
||||||
* Redistribution and use in source and binary forms, with or without
|
* Redistribution and use in source and binary forms, with or without
|
||||||
|
@ -61,6 +61,9 @@ public:
|
||||||
|
|
||||||
Variant data(ModelRole = ModelRole::Display) const;
|
Variant data(ModelRole = ModelRole::Display) const;
|
||||||
|
|
||||||
|
ModelIndex sibling(int row, int column) const;
|
||||||
|
ModelIndex sibling_at_column(int column) const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
ModelIndex(const Model& model, int row, int column, void* internal_data)
|
ModelIndex(const Model& model, int row, int column, void* internal_data)
|
||||||
: m_model(&model)
|
: m_model(&model)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue