mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 08:57:47 +00:00
LibGUI: Move GUI::Model::Role to GUI::ModelRole
This is preparation for using ModelRole in the ModelIndex API.
This commit is contained in:
parent
f6d7204689
commit
a1e381a0f8
66 changed files with 201 additions and 167 deletions
|
@ -146,10 +146,10 @@ String AddEventDialog::MonthListModel::column_name(int column) const
|
|||
}
|
||||
}
|
||||
|
||||
GUI::Variant AddEventDialog::MonthListModel::data(const GUI::ModelIndex& index, Role role) const
|
||||
GUI::Variant AddEventDialog::MonthListModel::data(const GUI::ModelIndex& index, GUI::ModelRole role) const
|
||||
{
|
||||
auto& month = Calendar::name_of_month(index.row() + 1);
|
||||
if (role == Role::Display) {
|
||||
if (role == GUI::ModelRole::Display) {
|
||||
switch (index.column()) {
|
||||
case Column::Month:
|
||||
return month;
|
||||
|
|
|
@ -58,7 +58,7 @@ private:
|
|||
virtual int row_count(const GUI::ModelIndex& = GUI::ModelIndex()) const override;
|
||||
virtual int column_count(const GUI::ModelIndex& = GUI::ModelIndex()) const override { return Column::__Count; }
|
||||
virtual String column_name(int) const override;
|
||||
virtual GUI::Variant data(const GUI::ModelIndex&, Role = Role::Display) const override;
|
||||
virtual GUI::Variant data(const GUI::ModelIndex&, GUI::ModelRole) const override;
|
||||
virtual void update() override;
|
||||
|
||||
private:
|
||||
|
|
|
@ -52,11 +52,11 @@ public:
|
|||
return "Data";
|
||||
}
|
||||
|
||||
virtual GUI::Variant data(const GUI::ModelIndex& index, Role role = Role::Display) const override
|
||||
virtual GUI::Variant data(const GUI::ModelIndex& index, GUI::ModelRole role) const override
|
||||
{
|
||||
if (role == Role::TextAlignment)
|
||||
if (role == GUI::ModelRole::TextAlignment)
|
||||
return Gfx::TextAlignment::CenterLeft;
|
||||
if (role == Role::Display)
|
||||
if (role == GUI::ModelRole::Display)
|
||||
return m_data.at(index.row());
|
||||
|
||||
return {};
|
||||
|
|
|
@ -438,7 +438,7 @@ int run_in_windowed_mode(RefPtr<Core::ConfigFile> config, String initial_locatio
|
|||
view.selection().for_each_index([&](const GUI::ModelIndex& index) {
|
||||
auto parent_index = model.parent_index(index);
|
||||
auto name_index = model.index(index.row(), GUI::FileSystemModel::Column::Name, parent_index);
|
||||
auto path = model.data(name_index, GUI::Model::Role::Custom).to_string();
|
||||
auto path = model.data(name_index, GUI::ModelRole::Custom).to_string();
|
||||
paths.append(path);
|
||||
});
|
||||
return paths;
|
||||
|
|
|
@ -155,17 +155,17 @@ int ManualModel::column_count(const GUI::ModelIndex&) const
|
|||
return 1;
|
||||
}
|
||||
|
||||
GUI::Variant ManualModel::data(const GUI::ModelIndex& index, Role role) const
|
||||
GUI::Variant ManualModel::data(const GUI::ModelIndex& index, GUI::ModelRole role) const
|
||||
{
|
||||
auto* node = static_cast<const ManualNode*>(index.internal_data());
|
||||
switch (role) {
|
||||
case Role::Search:
|
||||
case GUI::ModelRole::Search:
|
||||
if (!node->is_page())
|
||||
return {};
|
||||
return String(page_view(page_path(index)).value());
|
||||
case Role::Display:
|
||||
case GUI::ModelRole::Display:
|
||||
return node->name();
|
||||
case Role::Icon:
|
||||
case GUI::ModelRole::Icon:
|
||||
if (node->is_page())
|
||||
return m_page_icon;
|
||||
if (node->is_open())
|
||||
|
|
|
@ -50,7 +50,7 @@ public:
|
|||
void update_section_node_on_toggle(const GUI::ModelIndex&, const bool);
|
||||
virtual int row_count(const GUI::ModelIndex& = GUI::ModelIndex()) const override;
|
||||
virtual int column_count(const GUI::ModelIndex& = GUI::ModelIndex()) const override;
|
||||
virtual GUI::Variant data(const GUI::ModelIndex&, Role = Role::Display) const override;
|
||||
virtual GUI::Variant data(const GUI::ModelIndex&, GUI::ModelRole) const override;
|
||||
virtual TriState data_matches(const GUI::ModelIndex&, GUI::Variant) const override;
|
||||
virtual void update() override;
|
||||
virtual GUI::ModelIndex parent_index(const GUI::ModelIndex&) const override;
|
||||
|
|
|
@ -57,11 +57,11 @@ String IRCChannelMemberListModel::column_name(int column) const
|
|||
ASSERT_NOT_REACHED();
|
||||
}
|
||||
|
||||
GUI::Variant IRCChannelMemberListModel::data(const GUI::ModelIndex& index, Role role) const
|
||||
GUI::Variant IRCChannelMemberListModel::data(const GUI::ModelIndex& index, GUI::ModelRole role) const
|
||||
{
|
||||
if (role == Role::TextAlignment)
|
||||
if (role == GUI::ModelRole::TextAlignment)
|
||||
return Gfx::TextAlignment::CenterLeft;
|
||||
if (role == Role::Display) {
|
||||
if (role == GUI::ModelRole::Display) {
|
||||
switch (index.column()) {
|
||||
case Column::Name:
|
||||
return m_channel.member_at(index.row());
|
||||
|
@ -77,5 +77,5 @@ void IRCChannelMemberListModel::update()
|
|||
|
||||
String IRCChannelMemberListModel::nick_at(const GUI::ModelIndex& index) const
|
||||
{
|
||||
return data(index, IRCChannelMemberListModel::Role::Display).to_string();
|
||||
return data(index, GUI::ModelRole::Display).to_string();
|
||||
}
|
||||
|
|
|
@ -42,7 +42,7 @@ public:
|
|||
virtual int row_count(const GUI::ModelIndex&) const override;
|
||||
virtual int column_count(const GUI::ModelIndex&) const override;
|
||||
virtual String column_name(int column) const override;
|
||||
virtual GUI::Variant data(const GUI::ModelIndex&, Role = Role::Display) const override;
|
||||
virtual GUI::Variant data(const GUI::ModelIndex&, GUI::ModelRole) const override;
|
||||
virtual void update() override;
|
||||
virtual String nick_at(const GUI::ModelIndex& index) const;
|
||||
|
||||
|
|
|
@ -56,11 +56,11 @@ String IRCWindowListModel::column_name(int column) const
|
|||
ASSERT_NOT_REACHED();
|
||||
}
|
||||
|
||||
GUI::Variant IRCWindowListModel::data(const GUI::ModelIndex& index, Role role) const
|
||||
GUI::Variant IRCWindowListModel::data(const GUI::ModelIndex& index, GUI::ModelRole role) const
|
||||
{
|
||||
if (role == Role::TextAlignment)
|
||||
if (role == GUI::ModelRole::TextAlignment)
|
||||
return Gfx::TextAlignment::CenterLeft;
|
||||
if (role == Role::Display) {
|
||||
if (role == GUI::ModelRole::Display) {
|
||||
switch (index.column()) {
|
||||
case Column::Name: {
|
||||
auto& window = m_client.window_at(index.row());
|
||||
|
@ -70,7 +70,7 @@ GUI::Variant IRCWindowListModel::data(const GUI::ModelIndex& index, Role role) c
|
|||
}
|
||||
}
|
||||
}
|
||||
if (role == Role::ForegroundColor) {
|
||||
if (role == GUI::ModelRole::ForegroundColor) {
|
||||
switch (index.column()) {
|
||||
case Column::Name: {
|
||||
auto& window = m_client.window_at(index.row());
|
||||
|
|
|
@ -44,7 +44,7 @@ public:
|
|||
virtual int row_count(const GUI::ModelIndex&) const override;
|
||||
virtual int column_count(const GUI::ModelIndex&) const override;
|
||||
virtual String column_name(int column) const override;
|
||||
virtual GUI::Variant data(const GUI::ModelIndex&, Role = Role::Display) const override;
|
||||
virtual GUI::Variant data(const GUI::ModelIndex&, GUI::ModelRole) const override;
|
||||
virtual void update() override;
|
||||
|
||||
private:
|
||||
|
|
|
@ -48,12 +48,12 @@ public:
|
|||
return 1;
|
||||
}
|
||||
|
||||
virtual GUI::Variant data(const GUI::ModelIndex& index, Role role = Role::Display) const override
|
||||
virtual GUI::Variant data(const GUI::ModelIndex& index, GUI::ModelRole role) const override
|
||||
{
|
||||
ASSERT(index.is_valid());
|
||||
ASSERT(index.column() == 0);
|
||||
|
||||
if (role == Role::Display)
|
||||
if (role == GUI::ModelRole::Display)
|
||||
return m_file_names.at(index.row());
|
||||
|
||||
return {};
|
||||
|
|
|
@ -73,11 +73,11 @@ String DevicesModel::column_name(int column) const
|
|||
}
|
||||
}
|
||||
|
||||
GUI::Variant DevicesModel::data(const GUI::ModelIndex& index, Role role) const
|
||||
GUI::Variant DevicesModel::data(const GUI::ModelIndex& index, GUI::ModelRole role) const
|
||||
{
|
||||
ASSERT(is_valid(index));
|
||||
|
||||
if (role == Role::TextAlignment) {
|
||||
if (role == GUI::ModelRole::TextAlignment) {
|
||||
switch (index.column()) {
|
||||
case Column::Device:
|
||||
return Gfx::TextAlignment::CenterLeft;
|
||||
|
@ -93,7 +93,7 @@ GUI::Variant DevicesModel::data(const GUI::ModelIndex& index, Role role) const
|
|||
return {};
|
||||
}
|
||||
|
||||
if (role == Role::Display) {
|
||||
if (role == GUI::ModelRole::Display) {
|
||||
const DeviceInfo& device = m_devices[index.row()];
|
||||
switch (index.column()) {
|
||||
case Column::Device:
|
||||
|
|
|
@ -47,7 +47,7 @@ public:
|
|||
virtual int row_count(const GUI::ModelIndex&) const override;
|
||||
virtual int column_count(const GUI::ModelIndex&) const override;
|
||||
virtual String column_name(int column) const override;
|
||||
virtual GUI::Variant data(const GUI::ModelIndex&, Role = Role::Display) const override;
|
||||
virtual GUI::Variant data(const GUI::ModelIndex&, GUI::ModelRole) const override;
|
||||
virtual void update() override;
|
||||
|
||||
private:
|
||||
|
|
|
@ -40,7 +40,7 @@ public:
|
|||
virtual void paint(GUI::Painter& painter, const Gfx::IntRect& a_rect, const Gfx::Palette&, const GUI::Model& model, const GUI::ModelIndex& index) override
|
||||
{
|
||||
auto rect = a_rect.shrunken(2, 2);
|
||||
auto pagemap = model.data(index, GUI::Model::Role::Custom).to_string();
|
||||
auto pagemap = model.data(index, GUI::ModelRole::Custom).to_string();
|
||||
|
||||
float scale_factor = (float)pagemap.length() / (float)rect.width();
|
||||
|
||||
|
|
|
@ -156,11 +156,11 @@ static String pretty_byte_size(size_t size)
|
|||
return String::format("%uK", size / 1024);
|
||||
}
|
||||
|
||||
GUI::Variant ProcessModel::data(const GUI::ModelIndex& index, Role role) const
|
||||
GUI::Variant ProcessModel::data(const GUI::ModelIndex& index, GUI::ModelRole role) const
|
||||
{
|
||||
ASSERT(is_valid(index));
|
||||
|
||||
if (role == Role::TextAlignment) {
|
||||
if (role == GUI::ModelRole::TextAlignment) {
|
||||
switch (index.column()) {
|
||||
case Column::Icon:
|
||||
case Column::Name:
|
||||
|
@ -203,7 +203,7 @@ GUI::Variant ProcessModel::data(const GUI::ModelIndex& index, Role role) const
|
|||
auto it = m_threads.find(m_pids[index.row()]);
|
||||
auto& thread = *(*it).value;
|
||||
|
||||
if (role == Role::Sort) {
|
||||
if (role == GUI::ModelRole::Sort) {
|
||||
switch (index.column()) {
|
||||
case Column::Icon:
|
||||
return 0;
|
||||
|
@ -272,7 +272,7 @@ GUI::Variant ProcessModel::data(const GUI::ModelIndex& index, Role role) const
|
|||
return {};
|
||||
}
|
||||
|
||||
if (role == Role::Display) {
|
||||
if (role == GUI::ModelRole::Display) {
|
||||
switch (index.column()) {
|
||||
case Column::Icon:
|
||||
if (thread.current_state.icon_id != -1) {
|
||||
|
|
|
@ -89,7 +89,7 @@ public:
|
|||
virtual int row_count(const GUI::ModelIndex&) const override;
|
||||
virtual int column_count(const GUI::ModelIndex&) const override;
|
||||
virtual String column_name(int column) const override;
|
||||
virtual GUI::Variant data(const GUI::ModelIndex&, Role = Role::Display) const override;
|
||||
virtual GUI::Variant data(const GUI::ModelIndex&, GUI::ModelRole) const override;
|
||||
virtual void update() override;
|
||||
|
||||
struct CpuInfo {
|
||||
|
|
|
@ -193,7 +193,7 @@ int main(int argc, char** argv)
|
|||
if (process_table_view.selection().is_empty())
|
||||
return -1;
|
||||
auto pid_index = process_table_view.model()->index(process_table_view.selection().first().row(), column);
|
||||
return process_table_view.model()->data(pid_index, GUI::Model::Role::Display).to_i32();
|
||||
return process_table_view.model()->data(pid_index, GUI::ModelRole::Display).to_i32();
|
||||
};
|
||||
|
||||
auto kill_action = GUI::Action::create("Kill process", { Mod_Ctrl, Key_K }, Gfx::Bitmap::load_from_file("/res/icons/kill16.png"), [&](const GUI::Action&) {
|
||||
|
@ -340,9 +340,9 @@ public:
|
|||
virtual void paint(GUI::Painter& painter, const Gfx::IntRect& a_rect, const Palette& palette, const GUI::Model& model, const GUI::ModelIndex& index) override
|
||||
{
|
||||
auto rect = a_rect.shrunken(2, 2);
|
||||
auto percentage = model.data(index, GUI::Model::Role::Custom).to_i32();
|
||||
auto percentage = model.data(index, GUI::ModelRole::Custom).to_i32();
|
||||
|
||||
auto data = model.data(index, GUI::Model::Role::Display);
|
||||
auto data = model.data(index, GUI::ModelRole::Display);
|
||||
String text;
|
||||
if (data.is_string())
|
||||
text = data.as_string();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue