mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 06:27:45 +00:00
LibGUI: Make GSortingProxyModel update the selection on resort again
After resorting, we now re-map every selected index so it matches the new row mappings. This makes the process table view in SystemMonitor behave normally again :^)
This commit is contained in:
parent
23a2e84873
commit
449ebbddb6
1 changed files with 23 additions and 4 deletions
|
@ -1,4 +1,5 @@
|
||||||
#include <AK/QuickSort.h>
|
#include <AK/QuickSort.h>
|
||||||
|
#include <LibGUI/GAbstractView.h>
|
||||||
#include <LibGUI/GSortingProxyModel.h>
|
#include <LibGUI/GSortingProxyModel.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
@ -73,6 +74,7 @@ void GSortingProxyModel::set_key_column_and_sort_order(int column, GSortOrder so
|
||||||
|
|
||||||
void GSortingProxyModel::resort()
|
void GSortingProxyModel::resort()
|
||||||
{
|
{
|
||||||
|
auto old_row_mappings = m_row_mappings;
|
||||||
int row_count = target().row_count();
|
int row_count = target().row_count();
|
||||||
m_row_mappings.resize(row_count);
|
m_row_mappings.resize(row_count);
|
||||||
for (int i = 0; i < row_count; ++i)
|
for (int i = 0; i < row_count; ++i)
|
||||||
|
@ -87,11 +89,28 @@ void GSortingProxyModel::resort()
|
||||||
if (data1 == data2)
|
if (data1 == data2)
|
||||||
return 0;
|
return 0;
|
||||||
bool is_less_than;
|
bool is_less_than;
|
||||||
if (data1.is_string() && data2.is_string() && !m_sorting_case_sensitive)
|
if (data1.is_string() && data2.is_string() && !m_sorting_case_sensitive)
|
||||||
is_less_than = data1.as_string().to_lowercase() < data2.as_string().to_lowercase();
|
is_less_than = data1.as_string().to_lowercase() < data2.as_string().to_lowercase();
|
||||||
else
|
else
|
||||||
is_less_than = data1 < data2;
|
is_less_than = data1 < data2;
|
||||||
return m_sort_order == GSortOrder::Ascending ? is_less_than : !is_less_than;
|
return m_sort_order == GSortOrder::Ascending ? is_less_than : !is_less_than;
|
||||||
});
|
});
|
||||||
did_update();
|
did_update();
|
||||||
|
for_each_view([&](GAbstractView& view) {
|
||||||
|
auto& selection = view.selection();
|
||||||
|
Vector<GModelIndex> selected_indexes_in_target;
|
||||||
|
selection.for_each_index([&](const GModelIndex& index) {
|
||||||
|
selected_indexes_in_target.append(target().index(old_row_mappings[index.row()], index.column()));
|
||||||
|
});
|
||||||
|
|
||||||
|
selection.clear();
|
||||||
|
for (auto& index : selected_indexes_in_target) {
|
||||||
|
for (int i = 0; i < m_row_mappings.size(); ++i) {
|
||||||
|
if (m_row_mappings[i] == index.row()) {
|
||||||
|
selection.add(this->index(i, index.column()));
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue