mirror of
https://github.com/RGBCube/serenity
synced 2025-05-19 09:35:07 +00:00

This is accomplished by putting a GSortingProxyTableModel between the model and the view. It's pretty simplistic but it works for this use case. :^)
38 lines
1,012 B
C++
38 lines
1,012 B
C++
#include "ProcessTableView.h"
|
|
#include "ProcessTableModel.h"
|
|
#include <LibGUI/GSortingProxyTableModel.h>
|
|
#include <stdio.h>
|
|
|
|
ProcessTableView::ProcessTableView(GWidget* parent)
|
|
: GTableView(parent)
|
|
{
|
|
auto process_model = make<ProcessTableModel>();
|
|
m_model = process_model.ptr();
|
|
set_model(make<GSortingProxyTableModel>(move(process_model)));
|
|
GTableView::model()->set_key_column_and_sort_order(ProcessTableModel::Column::CPU, GSortOrder::Descending);
|
|
start_timer(1000);
|
|
model().update();
|
|
}
|
|
|
|
ProcessTableView::~ProcessTableView()
|
|
{
|
|
}
|
|
|
|
void ProcessTableView::timer_event(GTimerEvent&)
|
|
{
|
|
model().update();
|
|
}
|
|
|
|
void ProcessTableView::model_notification(const GModelNotification& notification)
|
|
{
|
|
if (notification.type() == GModelNotification::ModelUpdated) {
|
|
if (on_status_message)
|
|
on_status_message(String::format("%d processes", model().row_count()));
|
|
return;
|
|
}
|
|
}
|
|
|
|
pid_t ProcessTableView::selected_pid() const
|
|
{
|
|
return model().selected_pid();
|
|
}
|