1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 15:48:12 +00:00

SystemMonitor: Enable sorting by column in the process memory map view

This commit is contained in:
Andreas Kling 2019-12-02 17:43:34 +01:00
parent 7970b594d5
commit b9f58a0e2e
2 changed files with 8 additions and 3 deletions

View file

@ -2,6 +2,7 @@
#include <LibCore/CTimer.h>
#include <LibGUI/GBoxLayout.h>
#include <LibGUI/GJsonArrayModel.h>
#include <LibGUI/GSortingProxyModel.h>
#include <LibGUI/GTableView.h>
ProcessMemoryMapWidget::ProcessMemoryMapWidget(GWidget* parent)
@ -30,7 +31,9 @@ ProcessMemoryMapWidget::ProcessMemoryMapWidget(GWidget* parent)
return builder.to_string();
});
pid_vm_fields.empend("name", "Name", TextAlignment::CenterLeft);
m_table_view->set_model(GJsonArrayModel::create({}, move(pid_vm_fields)));
m_json_model = GJsonArrayModel::create({}, move(pid_vm_fields));
m_table_view->set_model(GSortingProxyModel::create(*m_json_model));
m_table_view->model()->set_key_column_and_sort_order(0, GSortOrder::Ascending);
m_timer = CTimer::construct(1000, [this] { refresh(); }, this);
}
@ -43,11 +46,11 @@ void ProcessMemoryMapWidget::set_pid(pid_t pid)
if (m_pid == pid)
return;
m_pid = pid;
static_cast<GJsonArrayModel*>(m_table_view->model())->set_json_path(String::format("/proc/%d/vm", pid));
m_json_model->set_json_path(String::format("/proc/%d/vm", pid));
}
void ProcessMemoryMapWidget::refresh()
{
if (m_pid != -1)
m_table_view->model()->update();
m_json_model->update();
}

View file

@ -3,6 +3,7 @@
#include <LibGUI/GWidget.h>
class CTimer;
class GJsonArrayModel;
class GTableView;
class ProcessMemoryMapWidget final : public GWidget {
@ -16,6 +17,7 @@ public:
private:
explicit ProcessMemoryMapWidget(GWidget* parent);
RefPtr<GTableView> m_table_view;
RefPtr<GJsonArrayModel> m_json_model;
pid_t m_pid { -1 };
RefPtr<CTimer> m_timer;
};