LibGUI: Rename GTableModel => GModel.

This commit is contained in:
Andreas Kling 2019-03-23 01:42:49 +01:00
parent 9d4b4c2689
commit 994cf10b3e
23 changed files with 105 additions and 105 deletions

View file

@ -1,4 +1,4 @@
#include "DirectoryTableModel.h"
#include "DirectoryModel.h"
#include <dirent.h>
#include <stdio.h>
#include <unistd.h>
@ -7,7 +7,7 @@
#include <AK/FileSystemPath.h>
#include <AK/StringBuilder.h>
DirectoryTableModel::DirectoryTableModel()
DirectoryModel::DirectoryModel()
{
m_directory_icon = GraphicsBitmap::load_from_file("/res/icons/folder16.png");
m_file_icon = GraphicsBitmap::load_from_file("/res/icons/file16.png");
@ -27,21 +27,21 @@ DirectoryTableModel::DirectoryTableModel()
endgrent();
}
DirectoryTableModel::~DirectoryTableModel()
DirectoryModel::~DirectoryModel()
{
}
int DirectoryTableModel::row_count() const
int DirectoryModel::row_count() const
{
return m_directories.size() + m_files.size();
}
int DirectoryTableModel::column_count() const
int DirectoryModel::column_count() const
{
return Column::__Count;
}
String DirectoryTableModel::column_name(int column) const
String DirectoryModel::column_name(int column) const
{
switch (column) {
case Column::Icon: return "";
@ -55,7 +55,7 @@ String DirectoryTableModel::column_name(int column) const
ASSERT_NOT_REACHED();
}
GTableModel::ColumnMetadata DirectoryTableModel::column_metadata(int column) const
GModel::ColumnMetadata DirectoryModel::column_metadata(int column) const
{
switch (column) {
case Column::Icon: return { 16, TextAlignment::Center };
@ -69,7 +69,7 @@ GTableModel::ColumnMetadata DirectoryTableModel::column_metadata(int column) con
ASSERT_NOT_REACHED();
}
const GraphicsBitmap& DirectoryTableModel::icon_for(const Entry& entry) const
const GraphicsBitmap& DirectoryModel::icon_for(const Entry& entry) const
{
if (S_ISDIR(entry.mode))
return *m_directory_icon;
@ -122,7 +122,7 @@ static String permission_string(mode_t mode)
return builder.to_string();
}
String DirectoryTableModel::name_for_uid(uid_t uid) const
String DirectoryModel::name_for_uid(uid_t uid) const
{
auto it = m_user_names.find(uid);
if (it == m_user_names.end())
@ -130,7 +130,7 @@ String DirectoryTableModel::name_for_uid(uid_t uid) const
return (*it).value;
}
String DirectoryTableModel::name_for_gid(uid_t gid) const
String DirectoryModel::name_for_gid(uid_t gid) const
{
auto it = m_user_names.find(gid);
if (it == m_user_names.end())
@ -138,7 +138,7 @@ String DirectoryTableModel::name_for_gid(uid_t gid) const
return (*it).value;
}
GVariant DirectoryTableModel::data(const GModelIndex& index, Role role) const
GVariant DirectoryModel::data(const GModelIndex& index, Role role) const
{
ASSERT(is_valid(index));
auto& entry = this->entry(index.row());
@ -168,7 +168,7 @@ GVariant DirectoryTableModel::data(const GModelIndex& index, Role role) const
return { };
}
void DirectoryTableModel::update()
void DirectoryModel::update()
{
DIR* dirp = opendir(m_path.characters());
if (!dirp) {
@ -204,7 +204,7 @@ void DirectoryTableModel::update()
did_update();
}
void DirectoryTableModel::open(const String& a_path)
void DirectoryModel::open(const String& a_path)
{
FileSystemPath canonical_path(a_path);
auto path = canonical_path.string();
@ -219,7 +219,7 @@ void DirectoryTableModel::open(const String& a_path)
set_selected_index({ 0, 0 });
}
void DirectoryTableModel::activate(const GModelIndex& index)
void DirectoryModel::activate(const GModelIndex& index)
{
if (!index.is_valid())
return;

View file

@ -1,13 +1,13 @@
#pragma once
#include <LibGUI/GTableModel.h>
#include <LibGUI/GModel.h>
#include <AK/HashMap.h>
#include <sys/stat.h>
class DirectoryTableModel final : public GTableModel {
class DirectoryModel final : public GModel {
public:
static Retained<DirectoryTableModel> create() { return adopt(*new DirectoryTableModel); }
virtual ~DirectoryTableModel() override;
static Retained<DirectoryModel> create() { return adopt(*new DirectoryModel); }
virtual ~DirectoryModel() override;
enum Column {
Icon = 0,
@ -33,7 +33,7 @@ public:
size_t bytes_in_files() const { return m_bytes_in_files; }
private:
DirectoryTableModel();
DirectoryModel();
String name_for_uid(uid_t) const;
String name_for_gid(gid_t) const;

View file

@ -1,12 +1,12 @@
#include "DirectoryTableView.h"
#include <LibGUI/GSortingProxyTableModel.h>
#include <LibGUI/GSortingProxyModel.h>
DirectoryTableView::DirectoryTableView(GWidget* parent)
: GTableView(parent)
, m_model(DirectoryTableModel::create())
, m_model(DirectoryModel::create())
{
set_model(GSortingProxyTableModel::create(m_model.copy_ref()));
GTableView::model()->set_key_column_and_sort_order(DirectoryTableModel::Column::Name, GSortOrder::Ascending);
set_model(GSortingProxyModel::create(m_model.copy_ref()));
GTableView::model()->set_key_column_and_sort_order(DirectoryModel::Column::Name, GSortOrder::Ascending);
}
DirectoryTableView::~DirectoryTableView()

View file

@ -2,7 +2,7 @@
#include <LibGUI/GTableView.h>
#include <sys/stat.h>
#include "DirectoryTableModel.h"
#include "DirectoryModel.h"
class DirectoryTableView final : public GTableView {
public:
@ -21,10 +21,10 @@ public:
private:
virtual void model_notification(const GModelNotification&) override;
DirectoryTableModel& model() { return *m_model; }
const DirectoryTableModel& model() const { return *m_model; }
DirectoryModel& model() { return *m_model; }
const DirectoryModel& model() const { return *m_model; }
void set_status_message(const String&);
Retained<DirectoryTableModel> m_model;
Retained<DirectoryModel> m_model;
};

View file

@ -1,5 +1,5 @@
OBJS = \
DirectoryTableModel.o \
DirectoryModel.o \
DirectoryTableView.o \
main.o

View file

@ -31,7 +31,7 @@ String IRCChannelMemberListModel::column_name(int column) const
ASSERT_NOT_REACHED();
}
GTableModel::ColumnMetadata IRCChannelMemberListModel::column_metadata(int column) const
GModel::ColumnMetadata IRCChannelMemberListModel::column_metadata(int column) const
{
switch (column) {
case Column::Name: return { 70, TextAlignment::CenterLeft };

View file

@ -1,11 +1,11 @@
#pragma once
#include <LibGUI/GTableModel.h>
#include <LibGUI/GModel.h>
#include <AK/Function.h>
class IRCChannel;
class IRCChannelMemberListModel final : public GTableModel {
class IRCChannelMemberListModel final : public GModel {
public:
enum Column { Name };
static Retained<IRCChannelMemberListModel> create(IRCChannel& channel) { return adopt(*new IRCChannelMemberListModel(channel)); }

View file

@ -33,7 +33,7 @@ String IRCLogBufferModel::column_name(int column) const
ASSERT_NOT_REACHED();
}
GTableModel::ColumnMetadata IRCLogBufferModel::column_metadata(int column) const
GModel::ColumnMetadata IRCLogBufferModel::column_metadata(int column) const
{
switch (column) {
case Column::Timestamp: return { 60, TextAlignment::CenterLeft };

View file

@ -1,10 +1,10 @@
#pragma once
#include <LibGUI/GTableModel.h>
#include <LibGUI/GModel.h>
class IRCLogBuffer;
class IRCLogBufferModel final : public GTableModel {
class IRCLogBufferModel final : public GModel {
public:
enum Column {
Timestamp = 0,

View file

@ -33,7 +33,7 @@ String IRCWindowListModel::column_name(int column) const
ASSERT_NOT_REACHED();
}
GTableModel::ColumnMetadata IRCWindowListModel::column_metadata(int column) const
GModel::ColumnMetadata IRCWindowListModel::column_metadata(int column) const
{
switch (column) {
case Column::Name: return { 70, TextAlignment::CenterLeft };

View file

@ -1,12 +1,12 @@
#pragma once
#include <LibGUI/GTableModel.h>
#include <LibGUI/GModel.h>
#include <AK/Function.h>
class IRCClient;
class IRCWindow;
class IRCWindowListModel final : public GTableModel {
class IRCWindowListModel final : public GModel {
public:
enum Column {
Name,

View file

@ -1,5 +1,5 @@
OBJS = \
ProcessTableModel.o \
ProcessModel.o \
ProcessTableView.o \
MemoryStatsWidget.o \
main.o

View file

@ -1,10 +1,10 @@
#include "ProcessTableModel.h"
#include "ProcessModel.h"
#include <LibGUI/GFile.h>
#include <fcntl.h>
#include <stdio.h>
#include <pwd.h>
ProcessTableModel::ProcessTableModel()
ProcessModel::ProcessModel()
{
setpwent();
while (auto* passwd = getpwent())
@ -17,21 +17,21 @@ ProcessTableModel::ProcessTableModel()
m_normal_priority_icon = GraphicsBitmap::load_from_file("/res/icons/normalpriority16.png");
}
ProcessTableModel::~ProcessTableModel()
ProcessModel::~ProcessModel()
{
}
int ProcessTableModel::row_count() const
int ProcessModel::row_count() const
{
return m_processes.size();
}
int ProcessTableModel::column_count() const
int ProcessModel::column_count() const
{
return Column::__Count;
}
String ProcessTableModel::column_name(int column) const
String ProcessModel::column_name(int column) const
{
switch (column) {
case Column::Icon: return "";
@ -47,7 +47,7 @@ String ProcessTableModel::column_name(int column) const
}
}
GTableModel::ColumnMetadata ProcessTableModel::column_metadata(int column) const
GModel::ColumnMetadata ProcessModel::column_metadata(int column) const
{
switch (column) {
case Column::Icon: return { 16, TextAlignment::CenterLeft };
@ -68,7 +68,7 @@ static String pretty_byte_size(size_t size)
return String::format("%uK", size / 1024);
}
GVariant ProcessTableModel::data(const GModelIndex& index, Role role) const
GVariant ProcessModel::data(const GModelIndex& index, Role role) const
{
ASSERT(is_valid(index));
@ -123,7 +123,7 @@ GVariant ProcessTableModel::data(const GModelIndex& index, Role role) const
return { };
}
void ProcessTableModel::update()
void ProcessModel::update()
{
GFile file("/proc/all");
if (!file.open(GIODevice::ReadOnly)) {

View file

@ -3,10 +3,10 @@
#include <AK/AKString.h>
#include <AK/HashMap.h>
#include <AK/Vector.h>
#include <LibGUI/GTableModel.h>
#include <LibGUI/GModel.h>
#include <unistd.h>
class ProcessTableModel final : public GTableModel {
class ProcessModel final : public GModel {
public:
enum Column {
Icon = 0,
@ -21,8 +21,8 @@ public:
__Count
};
static Retained<ProcessTableModel> create() { return adopt(*new ProcessTableModel); }
virtual ~ProcessTableModel() override;
static Retained<ProcessModel> create() { return adopt(*new ProcessModel); }
virtual ~ProcessModel() override;
virtual int row_count() const override;
virtual int column_count() const override;
@ -32,7 +32,7 @@ public:
virtual void update() override;
private:
ProcessTableModel();
ProcessModel();
struct ProcessState {
pid_t pid;

View file

@ -1,13 +1,13 @@
#include "ProcessTableView.h"
#include "ProcessTableModel.h"
#include <LibGUI/GSortingProxyTableModel.h>
#include "ProcessModel.h"
#include <LibGUI/GSortingProxyModel.h>
#include <stdio.h>
ProcessTableView::ProcessTableView(GWidget* parent)
: GTableView(parent)
{
set_model(GSortingProxyTableModel::create(ProcessTableModel::create()));
model()->set_key_column_and_sort_order(ProcessTableModel::Column::CPU, GSortOrder::Descending);
set_model(GSortingProxyModel::create(ProcessModel::create()));
model()->set_key_column_and_sort_order(ProcessModel::Column::CPU, GSortOrder::Descending);
start_timer(1000);
model()->update();
}
@ -33,5 +33,5 @@ pid_t ProcessTableView::selected_pid() const
{
if (!model()->selected_index().is_valid())
return -1;
return model()->data({ model()->selected_index().row(), ProcessTableModel::Column::PID }, GTableModel::Role::Sort).as_int();
return model()->data({ model()->selected_index().row(), ProcessModel::Column::PID }, GModel::Role::Sort).as_int();
}

View file

@ -4,7 +4,7 @@
#include <AK/Function.h>
#include <unistd.h>
class ProcessTableModel;
class ProcessModel;
class ProcessTableView final : public GTableView {
public:

View file

@ -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;

View file

@ -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();

View file

@ -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;

View file

@ -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 };

View file

@ -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;

View file

@ -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 };

View file

@ -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 \