mirror of
https://github.com/RGBCube/serenity
synced 2025-06-01 11:58:13 +00:00
LibGUI: Rename GTableModel => GModel.
This commit is contained in:
parent
9d4b4c2689
commit
994cf10b3e
23 changed files with 105 additions and 105 deletions
|
@ -1,31 +1,31 @@
|
|||
#include <LibGUI/GTableModel.h>
|
||||
#include <LibGUI/GModel.h>
|
||||
#include <LibGUI/GTableView.h>
|
||||
|
||||
GTableModel::GTableModel()
|
||||
GModel::GModel()
|
||||
{
|
||||
}
|
||||
|
||||
GTableModel::~GTableModel()
|
||||
GModel::~GModel()
|
||||
{
|
||||
}
|
||||
|
||||
void GTableModel::register_view(Badge<GTableView>, GTableView& view)
|
||||
void GModel::register_view(Badge<GTableView>, GTableView& view)
|
||||
{
|
||||
m_views.set(&view);
|
||||
}
|
||||
|
||||
void GTableModel::unregister_view(Badge<GTableView>, GTableView& view)
|
||||
void GModel::unregister_view(Badge<GTableView>, GTableView& view)
|
||||
{
|
||||
m_views.remove(&view);
|
||||
}
|
||||
|
||||
void GTableModel::for_each_view(Function<void(GTableView&)> callback)
|
||||
void GModel::for_each_view(Function<void(GTableView&)> callback)
|
||||
{
|
||||
for (auto* view : m_views)
|
||||
callback(*view);
|
||||
}
|
||||
|
||||
void GTableModel::did_update()
|
||||
void GModel::did_update()
|
||||
{
|
||||
if (on_model_update)
|
||||
on_model_update(*this);
|
||||
|
@ -34,7 +34,7 @@ void GTableModel::did_update()
|
|||
});
|
||||
}
|
||||
|
||||
void GTableModel::set_selected_index(const GModelIndex& index)
|
||||
void GModel::set_selected_index(const GModelIndex& index)
|
||||
{
|
||||
if (m_selected_index == index)
|
||||
return;
|
|
@ -34,7 +34,7 @@ private:
|
|||
GModelIndex m_index;
|
||||
};
|
||||
|
||||
class GTableModel : public Retainable<GTableModel> {
|
||||
class GModel : public Retainable<GModel> {
|
||||
public:
|
||||
struct ColumnMetadata {
|
||||
int preferred_width { 0 };
|
||||
|
@ -44,7 +44,7 @@ public:
|
|||
|
||||
enum class Role { Display, Sort, Custom, ForegroundColor, BackgroundColor };
|
||||
|
||||
virtual ~GTableModel();
|
||||
virtual ~GModel();
|
||||
|
||||
virtual int row_count() const = 0;
|
||||
virtual int column_count() const = 0;
|
||||
|
@ -73,11 +73,11 @@ public:
|
|||
void register_view(Badge<GTableView>, GTableView&);
|
||||
void unregister_view(Badge<GTableView>, GTableView&);
|
||||
|
||||
Function<void(GTableModel&)> on_model_update;
|
||||
Function<void(GModel&)> on_model_update;
|
||||
Function<void(const GModelIndex&)> on_selection_changed;
|
||||
|
||||
protected:
|
||||
GTableModel();
|
||||
GModel();
|
||||
|
||||
void for_each_view(Function<void(GTableView&)>);
|
||||
void did_update();
|
|
@ -1,32 +1,32 @@
|
|||
#include <LibGUI/GSortingProxyTableModel.h>
|
||||
#include <LibGUI/GSortingProxyModel.h>
|
||||
#include <AK/QuickSort.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
|
||||
GSortingProxyTableModel::GSortingProxyTableModel(Retained<GTableModel>&& target)
|
||||
GSortingProxyModel::GSortingProxyModel(Retained<GModel>&& target)
|
||||
: m_target(move(target))
|
||||
, m_key_column(-1)
|
||||
{
|
||||
m_target->on_model_update = [this] (GTableModel&) {
|
||||
m_target->on_model_update = [this] (GModel&) {
|
||||
resort();
|
||||
};
|
||||
}
|
||||
|
||||
GSortingProxyTableModel::~GSortingProxyTableModel()
|
||||
GSortingProxyModel::~GSortingProxyModel()
|
||||
{
|
||||
}
|
||||
|
||||
int GSortingProxyTableModel::row_count() const
|
||||
int GSortingProxyModel::row_count() const
|
||||
{
|
||||
return target().row_count();
|
||||
}
|
||||
|
||||
int GSortingProxyTableModel::column_count() const
|
||||
int GSortingProxyModel::column_count() const
|
||||
{
|
||||
return target().column_count();
|
||||
}
|
||||
|
||||
GModelIndex GSortingProxyTableModel::map_to_target(const GModelIndex& index) const
|
||||
GModelIndex GSortingProxyModel::map_to_target(const GModelIndex& index) const
|
||||
{
|
||||
if (!index.is_valid())
|
||||
return { };
|
||||
|
@ -35,37 +35,37 @@ GModelIndex GSortingProxyTableModel::map_to_target(const GModelIndex& index) con
|
|||
return { m_row_mappings[index.row()], index.column() };
|
||||
}
|
||||
|
||||
String GSortingProxyTableModel::row_name(int index) const
|
||||
String GSortingProxyModel::row_name(int index) const
|
||||
{
|
||||
return target().row_name(index);
|
||||
}
|
||||
|
||||
String GSortingProxyTableModel::column_name(int index) const
|
||||
String GSortingProxyModel::column_name(int index) const
|
||||
{
|
||||
return target().column_name(index);
|
||||
}
|
||||
|
||||
GTableModel::ColumnMetadata GSortingProxyTableModel::column_metadata(int index) const
|
||||
GModel::ColumnMetadata GSortingProxyModel::column_metadata(int index) const
|
||||
{
|
||||
return target().column_metadata(index);
|
||||
}
|
||||
|
||||
GVariant GSortingProxyTableModel::data(const GModelIndex& index, Role role) const
|
||||
GVariant GSortingProxyModel::data(const GModelIndex& index, Role role) const
|
||||
{
|
||||
return target().data(map_to_target(index), role);
|
||||
}
|
||||
|
||||
void GSortingProxyTableModel::activate(const GModelIndex& index)
|
||||
void GSortingProxyModel::activate(const GModelIndex& index)
|
||||
{
|
||||
target().activate(map_to_target(index));
|
||||
}
|
||||
|
||||
void GSortingProxyTableModel::update()
|
||||
void GSortingProxyModel::update()
|
||||
{
|
||||
target().update();
|
||||
}
|
||||
|
||||
void GSortingProxyTableModel::set_key_column_and_sort_order(int column, GSortOrder sort_order)
|
||||
void GSortingProxyModel::set_key_column_and_sort_order(int column, GSortOrder sort_order)
|
||||
{
|
||||
if (column == m_key_column && sort_order == m_sort_order)
|
||||
return;
|
||||
|
@ -76,7 +76,7 @@ void GSortingProxyTableModel::set_key_column_and_sort_order(int column, GSortOrd
|
|||
resort();
|
||||
}
|
||||
|
||||
void GSortingProxyTableModel::resort()
|
||||
void GSortingProxyModel::resort()
|
||||
{
|
||||
int previously_selected_target_row = map_to_target(selected_index()).row();
|
||||
int row_count = target().row_count();
|
||||
|
@ -86,8 +86,8 @@ void GSortingProxyTableModel::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 }, GTableModel::Role::Sort);
|
||||
auto data2 = target().data({ row2, m_key_column }, GTableModel::Role::Sort);
|
||||
auto data1 = target().data({ row1, m_key_column }, GModel::Role::Sort);
|
||||
auto data2 = target().data({ row2, m_key_column }, GModel::Role::Sort);
|
||||
if (data1 == data2)
|
||||
return 0;
|
||||
bool is_less_than = data1 < data2;
|
|
@ -1,11 +1,11 @@
|
|||
#pragma once
|
||||
|
||||
#include <LibGUI/GTableModel.h>
|
||||
#include <LibGUI/GModel.h>
|
||||
|
||||
class GSortingProxyTableModel final : public GTableModel {
|
||||
class GSortingProxyModel final : public GModel {
|
||||
public:
|
||||
static Retained<GSortingProxyTableModel> create(Retained<GTableModel>&& model) { return adopt(*new GSortingProxyTableModel(move(model))); }
|
||||
virtual ~GSortingProxyTableModel() override;
|
||||
static Retained<GSortingProxyModel> create(Retained<GModel>&& model) { return adopt(*new GSortingProxyModel(move(model))); }
|
||||
virtual ~GSortingProxyModel() override;
|
||||
|
||||
virtual int row_count() const override;
|
||||
virtual int column_count() const override;
|
||||
|
@ -23,14 +23,14 @@ public:
|
|||
GModelIndex map_to_target(const GModelIndex&) const;
|
||||
|
||||
private:
|
||||
explicit GSortingProxyTableModel(Retained<GTableModel>&&);
|
||||
explicit GSortingProxyModel(Retained<GModel>&&);
|
||||
|
||||
GTableModel& target() { return *m_target; }
|
||||
const GTableModel& target() const { return *m_target; }
|
||||
GModel& target() { return *m_target; }
|
||||
const GModel& target() const { return *m_target; }
|
||||
|
||||
void resort();
|
||||
|
||||
Retained<GTableModel> m_target;
|
||||
Retained<GModel> m_target;
|
||||
Vector<int> m_row_mappings;
|
||||
int m_key_column { -1 };
|
||||
GSortOrder m_sort_order { GSortOrder::Ascending };
|
|
@ -1,5 +1,5 @@
|
|||
#include <LibGUI/GTableView.h>
|
||||
#include <LibGUI/GTableModel.h>
|
||||
#include <LibGUI/GModel.h>
|
||||
#include <LibGUI/GScrollBar.h>
|
||||
#include <SharedGraphics/Painter.h>
|
||||
#include <Kernel/KeyCode.h>
|
||||
|
@ -13,7 +13,7 @@ GTableView::~GTableView()
|
|||
{
|
||||
}
|
||||
|
||||
void GTableView::set_model(RetainPtr<GTableModel>&& model)
|
||||
void GTableView::set_model(RetainPtr<GModel>&& model)
|
||||
{
|
||||
if (model.ptr() == m_model.ptr())
|
||||
return;
|
||||
|
@ -162,7 +162,7 @@ void GTableView::paint_event(GPaintEvent& event)
|
|||
if (is_selected_row)
|
||||
text_color = Color::White;
|
||||
else
|
||||
text_color = m_model->data(cell_index, GTableModel::Role::ForegroundColor).to_color(Color::Black);
|
||||
text_color = m_model->data(cell_index, GModel::Role::ForegroundColor).to_color(Color::Black);
|
||||
painter.draw_text(cell_rect, data.to_string(), font, column_metadata.text_alignment, text_color);
|
||||
}
|
||||
x_offset += column_width + horizontal_padding() * 2;
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
#pragma once
|
||||
|
||||
#include <LibGUI/GTableModel.h>
|
||||
#include <LibGUI/GModel.h>
|
||||
#include <LibGUI/GScrollableWidget.h>
|
||||
#include <AK/Function.h>
|
||||
#include <AK/HashMap.h>
|
||||
|
@ -16,9 +16,9 @@ public:
|
|||
int header_height() const { return m_headers_visible ? 16 : 0; }
|
||||
int item_height() const { return 16; }
|
||||
|
||||
void set_model(RetainPtr<GTableModel>&&);
|
||||
GTableModel* model() { return m_model.ptr(); }
|
||||
const GTableModel* model() const { return m_model.ptr(); }
|
||||
void set_model(RetainPtr<GModel>&&);
|
||||
GModel* model() { return m_model.ptr(); }
|
||||
const GModel* model() const { return m_model.ptr(); }
|
||||
|
||||
bool headers_visible() const { return m_headers_visible; }
|
||||
void set_headers_visible(bool headers_visible) { m_headers_visible = headers_visible; }
|
||||
|
@ -53,7 +53,7 @@ private:
|
|||
void update_content_size();
|
||||
|
||||
Vector<bool> m_column_visibility;
|
||||
RetainPtr<GTableModel> m_model;
|
||||
RetainPtr<GModel> m_model;
|
||||
int m_horizontal_padding { 5 };
|
||||
bool m_headers_visible { true };
|
||||
bool m_alternating_row_colors { true };
|
||||
|
|
|
@ -32,12 +32,12 @@ LIBGUI_OBJS = \
|
|||
GFontDatabase.o \
|
||||
GToolBar.o \
|
||||
GTableView.o \
|
||||
GTableModel.o \
|
||||
GModel.o \
|
||||
GVariant.o \
|
||||
GShortcut.o \
|
||||
GTextEditor.o \
|
||||
GClipboard.o \
|
||||
GSortingProxyTableModel.o \
|
||||
GSortingProxyModel.o \
|
||||
GStackWidget.o \
|
||||
GEvent.o \
|
||||
GScrollableWidget.o \
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue