mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 05:08:13 +00:00
LibGUI: Minor tidying.
This commit is contained in:
parent
46caa2663b
commit
7d2c962836
2 changed files with 5 additions and 8 deletions
|
@ -86,10 +86,8 @@ void GSortingProxyTableModel::resort()
|
||||||
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)
|
||||||
m_row_mappings[i] = i;
|
m_row_mappings[i] = i;
|
||||||
|
|
||||||
if (m_key_column == -1)
|
if (m_key_column == -1)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
struct Context {
|
struct Context {
|
||||||
GTableModel* target;
|
GTableModel* target;
|
||||||
int key_column;
|
int key_column;
|
||||||
|
@ -97,11 +95,9 @@ void GSortingProxyTableModel::resort()
|
||||||
};
|
};
|
||||||
Context context { m_target.ptr(), m_key_column, m_sort_order };
|
Context context { m_target.ptr(), m_key_column, m_sort_order };
|
||||||
qsort_r(m_row_mappings.data(), m_row_mappings.size(), sizeof(int), [] (const void* a, const void* b, void* ctx) -> int {
|
qsort_r(m_row_mappings.data(), m_row_mappings.size(), sizeof(int), [] (const void* a, const void* b, void* ctx) -> int {
|
||||||
int row1 = *(const int*)(a);
|
|
||||||
int row2 = *(const int*)(b);
|
|
||||||
auto& context = *(Context*)(ctx);
|
auto& context = *(Context*)(ctx);
|
||||||
GModelIndex index1 { row1, context.key_column };
|
GModelIndex index1 { *(const int*)(a), context.key_column };
|
||||||
GModelIndex index2 { row2, context.key_column };
|
GModelIndex index2 { *(const int*)(b), context.key_column };
|
||||||
auto data1 = context.target->data(index1, GTableModel::Role::Sort);
|
auto data1 = context.target->data(index1, GTableModel::Role::Sort);
|
||||||
auto data2 = context.target->data(index2, GTableModel::Role::Sort);
|
auto data2 = context.target->data(index2, GTableModel::Role::Sort);
|
||||||
if (data1 == data2)
|
if (data1 == data2)
|
||||||
|
|
|
@ -103,14 +103,15 @@ Rect GTableView::header_rect(int column_index) const
|
||||||
void GTableView::mousedown_event(GMouseEvent& event)
|
void GTableView::mousedown_event(GMouseEvent& event)
|
||||||
{
|
{
|
||||||
if (event.y() < header_height()) {
|
if (event.y() < header_height()) {
|
||||||
// FIXME: Do something when clicking on a header.
|
|
||||||
auto adjusted_position = event.position().translated(m_horizontal_scrollbar->value(), 0);
|
auto adjusted_position = event.position().translated(m_horizontal_scrollbar->value(), 0);
|
||||||
for (int i = 0; i < m_model->column_count(); ++i) {
|
for (int i = 0; i < m_model->column_count(); ++i) {
|
||||||
auto header_rect = this->header_rect(i);
|
auto header_rect = this->header_rect(i);
|
||||||
if (header_rect.contains(adjusted_position)) {
|
if (header_rect.contains(adjusted_position)) {
|
||||||
auto new_sort_order = GSortOrder::Ascending;
|
auto new_sort_order = GSortOrder::Ascending;
|
||||||
if (m_model->key_column() == i)
|
if (m_model->key_column() == i)
|
||||||
new_sort_order = m_model->sort_order() == GSortOrder::Ascending ? GSortOrder::Descending : GSortOrder::Ascending;
|
new_sort_order = m_model->sort_order() == GSortOrder::Ascending
|
||||||
|
? GSortOrder::Descending
|
||||||
|
: GSortOrder::Ascending;
|
||||||
m_model->set_key_column_and_sort_order(i, new_sort_order);
|
m_model->set_key_column_and_sort_order(i, new_sort_order);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue