mirror of
https://github.com/RGBCube/serenity
synced 2025-07-24 22:17:42 +00:00
ProfileViewer: Use the new multi-column tree model support in GTreeView
Put the sample count into a separate column. This is so neat :^)
This commit is contained in:
parent
0ac74d3778
commit
5cd4fb4db2
3 changed files with 44 additions and 5 deletions
|
@ -63,17 +63,43 @@ int ProfileModel::row_count(const GModelIndex& index) const
|
||||||
|
|
||||||
int ProfileModel::column_count(const GModelIndex&) const
|
int ProfileModel::column_count(const GModelIndex&) const
|
||||||
{
|
{
|
||||||
return 1;
|
return Column::__Count;
|
||||||
|
}
|
||||||
|
|
||||||
|
String ProfileModel::column_name(int column) const
|
||||||
|
{
|
||||||
|
switch (column) {
|
||||||
|
case Column::SampleCount:
|
||||||
|
return "# Samples";
|
||||||
|
case Column::StackFrame:
|
||||||
|
return "Stack Frame";
|
||||||
|
default:
|
||||||
|
ASSERT_NOT_REACHED();
|
||||||
|
return {};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
GModel::ColumnMetadata ProfileModel::column_metadata(int column) const
|
||||||
|
{
|
||||||
|
if (column == Column::SampleCount)
|
||||||
|
return ColumnMetadata { 0, TextAlignment::CenterRight };
|
||||||
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
GVariant ProfileModel::data(const GModelIndex& index, Role role) const
|
GVariant ProfileModel::data(const GModelIndex& index, Role role) const
|
||||||
{
|
{
|
||||||
auto* node = static_cast<ProfileNode*>(index.internal_data());
|
auto* node = static_cast<ProfileNode*>(index.internal_data());
|
||||||
if (role == Role::Icon) {
|
if (role == Role::Icon) {
|
||||||
return m_frame_icon;
|
if (index.column() == Column::StackFrame)
|
||||||
|
return m_frame_icon;
|
||||||
|
return {};
|
||||||
}
|
}
|
||||||
if (role == Role::Display) {
|
if (role == Role::Display) {
|
||||||
return String::format("%s (%u)", node->symbol().characters(), node->sample_count());
|
if (index.column() == Column::SampleCount)
|
||||||
|
return node->sample_count();
|
||||||
|
if (index.column() == Column::StackFrame)
|
||||||
|
return node->symbol();
|
||||||
|
return {};
|
||||||
}
|
}
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,14 +11,23 @@ public:
|
||||||
return adopt(*new ProfileModel(profile));
|
return adopt(*new ProfileModel(profile));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
enum Column {
|
||||||
|
SampleCount,
|
||||||
|
StackFrame,
|
||||||
|
__Count
|
||||||
|
};
|
||||||
|
|
||||||
virtual ~ProfileModel() override;
|
virtual ~ProfileModel() override;
|
||||||
|
|
||||||
virtual int row_count(const GModelIndex& = GModelIndex()) const override;
|
virtual int row_count(const GModelIndex& = GModelIndex()) const override;
|
||||||
virtual int column_count(const GModelIndex& = GModelIndex()) const override;
|
virtual int column_count(const GModelIndex& = GModelIndex()) const override;
|
||||||
|
virtual String column_name(int) const override;
|
||||||
|
virtual ColumnMetadata column_metadata(int) const override;
|
||||||
virtual GVariant data(const GModelIndex&, Role = Role::Display) const override;
|
virtual GVariant data(const GModelIndex&, Role = Role::Display) const override;
|
||||||
virtual GModelIndex index(int row, int column, const GModelIndex& parent = GModelIndex()) const override;
|
virtual GModelIndex index(int row, int column, const GModelIndex& parent = GModelIndex()) const override;
|
||||||
virtual GModelIndex parent_index(const GModelIndex&) const override;
|
virtual GModelIndex parent_index(const GModelIndex&) const override;
|
||||||
virtual void update() override;
|
virtual void update() override;
|
||||||
|
virtual int tree_column() const override { return Column::StackFrame; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
explicit ProfileModel(Profile&);
|
explicit ProfileModel(Profile&);
|
||||||
|
|
|
@ -11,9 +11,11 @@ int main(int argc, char** argv)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
auto profile = Profile::load_from_file(argv[1]);
|
const char* path = argv[1];
|
||||||
|
|
||||||
|
auto profile = Profile::load_from_file(path);
|
||||||
if (!profile) {
|
if (!profile) {
|
||||||
fprintf(stderr, "Unable to load profile '%s'\n", argv[1]);
|
fprintf(stderr, "Unable to load profile '%s'\n", path);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -24,6 +26,8 @@ int main(int argc, char** argv)
|
||||||
window->set_rect(100, 100, 800, 600);
|
window->set_rect(100, 100, 800, 600);
|
||||||
|
|
||||||
auto tree_view = GTreeView::construct(nullptr);
|
auto tree_view = GTreeView::construct(nullptr);
|
||||||
|
tree_view->set_headers_visible(true);
|
||||||
|
tree_view->set_size_columns_to_fit_content(true);
|
||||||
tree_view->set_model(profile->model());
|
tree_view->set_model(profile->model());
|
||||||
|
|
||||||
window->set_main_widget(tree_view);
|
window->set_main_widget(tree_view);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue