mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-04-26 22:38:51 +00:00
LibGUI: Expand GModelIndex a bit, adding internal data and model pointers.
This will be useful for implementing more complicated models.
This commit is contained in:
parent
12ec55ee74
commit
d02238af48
Notes:
sideshowbarker
2024-07-19 14:54:19 +09:00
Author: https://github.com/awesomekling
Commit: d02238af48
10 changed files with 94 additions and 34 deletions
|
@ -32,7 +32,7 @@ GModelIndex GSortingProxyModel::map_to_target(const GModelIndex& index) const
|
|||
return { };
|
||||
if (index.row() >= row_count() || index.column() >= column_count())
|
||||
return { };
|
||||
return { m_row_mappings[index.row()], index.column() };
|
||||
return target().index(m_row_mappings[index.row()], index.column());
|
||||
}
|
||||
|
||||
String GSortingProxyModel::row_name(int index) const
|
||||
|
@ -86,8 +86,8 @@ void GSortingProxyModel::resort()
|
|||
if (m_key_column == -1)
|
||||
return;
|
||||
quick_sort(m_row_mappings.begin(), m_row_mappings.end(), [&] (auto row1, auto row2) -> bool {
|
||||
auto data1 = target().data({ row1, m_key_column }, GModel::Role::Sort);
|
||||
auto data2 = target().data({ row2, m_key_column }, GModel::Role::Sort);
|
||||
auto data1 = target().data(target().index(row1, m_key_column), GModel::Role::Sort);
|
||||
auto data2 = target().data(target().index(row2, m_key_column), GModel::Role::Sort);
|
||||
if (data1 == data2)
|
||||
return 0;
|
||||
bool is_less_than = data1 < data2;
|
||||
|
@ -97,7 +97,7 @@ void GSortingProxyModel::resort()
|
|||
// Preserve selection.
|
||||
for (int i = 0; i < row_count; ++i) {
|
||||
if (m_row_mappings[i] == previously_selected_target_row) {
|
||||
set_selected_index({ i, 0 });
|
||||
set_selected_index(index(i, 0));
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue