mirror of
https://github.com/RGBCube/serenity
synced 2025-07-24 20:37:34 +00:00
LibGUI: Let GTableModel handle the selection instead of doing it virtually.
It's silly to force every subclass models to deal with selection.
This commit is contained in:
parent
9c21874d33
commit
e1d0a3f226
3 changed files with 6 additions and 22 deletions
|
@ -75,21 +75,6 @@ GTableModel::ColumnMetadata ProcessTableModel::column_metadata(int column) const
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
GModelIndex ProcessTableModel::selected_index() const
|
|
||||||
{
|
|
||||||
return { m_selected_row, 0 };
|
|
||||||
}
|
|
||||||
|
|
||||||
void ProcessTableModel::set_selected_index(GModelIndex index)
|
|
||||||
{
|
|
||||||
if (!index.is_valid()) {
|
|
||||||
m_selected_row = -1;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (index.row() >= 0 && index.row() < m_pids.size())
|
|
||||||
m_selected_row = index.row();
|
|
||||||
}
|
|
||||||
|
|
||||||
static String pretty_byte_size(size_t size)
|
static String pretty_byte_size(size_t size)
|
||||||
{
|
{
|
||||||
return String::format("%uK", size / 1024);
|
return String::format("%uK", size / 1024);
|
||||||
|
@ -207,7 +192,7 @@ void ProcessTableModel::update()
|
||||||
|
|
||||||
pid_t ProcessTableModel::selected_pid() const
|
pid_t ProcessTableModel::selected_pid() const
|
||||||
{
|
{
|
||||||
if (m_selected_row == -1)
|
if (!selected_index().is_valid())
|
||||||
return -1;
|
return -1;
|
||||||
return m_pids[m_selected_row];
|
return m_pids[selected_index().row()];
|
||||||
}
|
}
|
||||||
|
|
|
@ -15,8 +15,6 @@ public:
|
||||||
virtual int column_count() const override;
|
virtual int column_count() const override;
|
||||||
virtual String column_name(int column) const override;
|
virtual String column_name(int column) const override;
|
||||||
virtual ColumnMetadata column_metadata(int column) const override;
|
virtual ColumnMetadata column_metadata(int column) const override;
|
||||||
virtual GModelIndex selected_index() const override;
|
|
||||||
virtual void set_selected_index(GModelIndex) override;
|
|
||||||
virtual GVariant data(int row, int column) const override;
|
virtual GVariant data(int row, int column) const override;
|
||||||
virtual void update() override;
|
virtual void update() override;
|
||||||
|
|
||||||
|
@ -43,7 +41,6 @@ private:
|
||||||
HashMap<uid_t, String> m_usernames;
|
HashMap<uid_t, String> m_usernames;
|
||||||
HashMap<pid_t, OwnPtr<Process>> m_processes;
|
HashMap<pid_t, OwnPtr<Process>> m_processes;
|
||||||
Vector<pid_t> m_pids;
|
Vector<pid_t> m_pids;
|
||||||
int m_selected_row { -1 };
|
|
||||||
RetainPtr<GraphicsBitmap> m_generic_process_icon;
|
RetainPtr<GraphicsBitmap> m_generic_process_icon;
|
||||||
RetainPtr<GraphicsBitmap> m_high_priority_icon;
|
RetainPtr<GraphicsBitmap> m_high_priority_icon;
|
||||||
RetainPtr<GraphicsBitmap> m_low_priority_icon;
|
RetainPtr<GraphicsBitmap> m_low_priority_icon;
|
||||||
|
|
|
@ -46,8 +46,6 @@ public:
|
||||||
virtual String column_name(int) const { return { }; }
|
virtual String column_name(int) const { return { }; }
|
||||||
virtual ColumnMetadata column_metadata(int) const { return { }; }
|
virtual ColumnMetadata column_metadata(int) const { return { }; }
|
||||||
virtual GVariant data(int row, int column) const = 0;
|
virtual GVariant data(int row, int column) const = 0;
|
||||||
virtual void set_selected_index(GModelIndex) { }
|
|
||||||
virtual GModelIndex selected_index() const { return GModelIndex(); }
|
|
||||||
virtual void update() = 0;
|
virtual void update() = 0;
|
||||||
|
|
||||||
bool is_valid(GModelIndex index) const
|
bool is_valid(GModelIndex index) const
|
||||||
|
@ -55,6 +53,9 @@ public:
|
||||||
return index.row() >= 0 && index.row() < row_count() && index.column() >= 0 && index.column() < column_count();
|
return index.row() >= 0 && index.row() < row_count() && index.column() >= 0 && index.column() < column_count();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void set_selected_index(const GModelIndex& index) { m_selected_index = index; }
|
||||||
|
GModelIndex selected_index() const { return m_selected_index; }
|
||||||
|
|
||||||
void register_view(Badge<GTableView>, GTableView&);
|
void register_view(Badge<GTableView>, GTableView&);
|
||||||
void unregister_view(Badge<GTableView>, GTableView&);
|
void unregister_view(Badge<GTableView>, GTableView&);
|
||||||
|
|
||||||
|
@ -66,4 +67,5 @@ protected:
|
||||||
|
|
||||||
private:
|
private:
|
||||||
HashTable<GTableView*> m_views;
|
HashTable<GTableView*> m_views;
|
||||||
|
GModelIndex m_selected_index;
|
||||||
};
|
};
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue