details-page: Use a GtkColumnView instead of a GtkTreeView

Remove the use of the now deprecated GtkTreeView and allow the colums to be sorted.
This commit is contained in:
Corentin Noël
2022-11-24 12:46:51 +01:00
parent d49c50f42b
commit 8967b2db33
5 changed files with 459 additions and 101 deletions

View File

@ -43,6 +43,7 @@ libsysprof_ui_private_sources = [
'sysprof-log-model.c',
'sysprof-logs-aid.c',
'sysprof-logs-page.c',
'sysprof-mark-detail.c',
'sysprof-marks-aid.c',
'sysprof-marks-model.c',
'sysprof-marks-page.c',

View File

@ -25,28 +25,30 @@
#include <glib/gi18n.h>
#include <string.h>
#include "sysprof-mark-detail.h"
#include "sysprof-details-page.h"
#include "sysprof-ui-private.h"
struct _SysprofDetailsPage
{
GtkWidget parent_instance;
GtkWidget parent_instance ;
/* Template Objects */
GtkListStore *marks_store;
GtkTreeView *marks_view;
GtkLabel *counters;
GtkLabel *duration;
GtkLabel *filename;
GtkLabel *allocations;
GtkLabel *forks;
GtkLabel *marks;
GtkLabel *processes;
GtkLabel *samples;
GtkLabel *start_time;
GtkLabel *cpu_label;
guint next_row;
GListStore *marks_store;
GtkSortListModel *mark_sort_model;
GtkLabel *counters;
GtkLabel *duration;
GtkLabel *filename;
GtkLabel *allocations;
GtkLabel *forks;
GtkLabel *marks;
GtkLabel *processes;
GtkLabel *samples;
GtkLabel *start_time;
GtkLabel *cpu_label;
guint next_row;
};
G_DEFINE_TYPE (SysprofDetailsPage, sysprof_details_page, GTK_TYPE_WIDGET)
@ -74,6 +76,13 @@ _g_date_time_new_from_iso8601 (const gchar *str,
}
#endif
char *
format_time (GObject *unused,
gint64 time)
{
return time ? _sysprof_format_duration (time) : g_strdup("");
}
static void
sysprof_details_page_dispose (GObject *object)
{
@ -94,6 +103,7 @@ sysprof_details_page_class_init (SysprofDetailsPageClass *klass)
object_class->dispose = sysprof_details_page_dispose;
g_type_ensure (SYSPROF_TYPE_MARK_DETAIL);
gtk_widget_class_set_template_from_resource (widget_class, "/org/gnome/sysprof/ui/sysprof-details-page.ui");
gtk_widget_class_set_layout_manager_type (widget_class, GTK_TYPE_BIN_LAYOUT);
gtk_widget_class_bind_template_child (widget_class, SysprofDetailsPage, allocations);
@ -104,10 +114,11 @@ sysprof_details_page_class_init (SysprofDetailsPageClass *klass)
gtk_widget_class_bind_template_child (widget_class, SysprofDetailsPage, forks);
gtk_widget_class_bind_template_child (widget_class, SysprofDetailsPage, marks);
gtk_widget_class_bind_template_child (widget_class, SysprofDetailsPage, marks_store);
gtk_widget_class_bind_template_child (widget_class, SysprofDetailsPage, marks_view);
gtk_widget_class_bind_template_child (widget_class, SysprofDetailsPage, mark_sort_model);
gtk_widget_class_bind_template_child (widget_class, SysprofDetailsPage, processes);
gtk_widget_class_bind_template_child (widget_class, SysprofDetailsPage, samples);
gtk_widget_class_bind_template_child (widget_class, SysprofDetailsPage, start_time);
gtk_widget_class_bind_template_callback (widget_class, format_time);
}
static void
@ -115,9 +126,6 @@ sysprof_details_page_init (SysprofDetailsPage *self)
{
gtk_widget_init_template (GTK_WIDGET (self));
gtk_tree_selection_set_mode (gtk_tree_view_get_selection (self->marks_view),
GTK_SELECTION_MULTIPLE);
self->next_row = 8;
}
@ -273,18 +281,23 @@ sysprof_details_page_add_mark (SysprofDetailsPage *self,
gint64 avg,
gint64 hits)
{
GtkTreeIter iter;
SysprofMarkDetail *detail;
g_return_if_fail (SYSPROF_IS_DETAILS_PAGE (self));
gtk_list_store_append (self->marks_store, &iter);
detail = sysprof_mark_detail_new (mark, min, max, avg, hits);
g_list_store_append (self->marks_store, detail);
/*gtk_list_store_append (self->marks_store, &iter);
gtk_list_store_set (self->marks_store, &iter,
0, mark,
1, min ? _sysprof_format_duration (min) : "—",
2, max ? _sysprof_format_duration (max) : "—",
3, avg ? _sysprof_format_duration (avg) : "—",
4, hits,
-1);
5, detail,
-1);*/
g_object_unref (detail);
}
void

View File

@ -163,79 +163,183 @@
<object class="AdwPreferencesGroup">
<property name="title" translatable="yes">Statistics</property>
<child>
<object class="GtkFrame">
<object class="GtkColumnView" id="marks_view">
<property name="width-request">500</property>
<property name="height-request">100</property>
<property name="model">
<object class="GtkNoSelection">
<property name="model">mark_sort_model</property>
</object>
</property>
<style>
<class name="data-table"/>
<class name="card"/>
</style>
<child>
<object class="GtkTreeView" id="marks_view">
<property name="model">marks_store</property>
<property name="width-request">500</property>
<property name="height-request">100</property>
<property name="enable-grid-lines">both</property>
<child>
<object class="GtkTreeViewColumn">
<property name="expand">true</property>
<property name="title" translatable="yes">Mark</property>
<child>
<object class="GtkCellRendererText">
<property name="xalign">0.0</property>
</object>
<attributes>
<attribute name="text">0</attribute>
</attributes>
</child>
<object class="GtkColumnViewColumn">
<property name="title" translatable="yes">Mark</property>
<property name="expand">true</property>
<property name="sorter">
<object class="GtkStringSorter">
<property name="expression">
<lookup name="label" type="SysprofMarkDetail"/>
</property>
</object>
</child>
<child>
<object class="GtkTreeViewColumn">
<property name="title" translatable="yes">Hits</property>
<child>
<object class="GtkCellRendererText">
<property name="xalign">0.0</property>
</object>
<attributes>
<attribute name="text">4</attribute>
</attributes>
</child>
</property>
<property name="factory">
<object class="GtkBuilderListItemFactory">
<property name="bytes"><![CDATA[
<?xml version="1.0" encoding="UTF-8"?>
<interface>
<template class="GtkListItem">
<property name="child">
<object class="GtkLabel">
<property name="xalign">0</property>
<property name="ellipsize">end</property>
<binding name="label">
<lookup name="label" type="SysprofMarkDetail">
<lookup name="item">GtkListItem</lookup>
</lookup>
</binding>
</object>
</property>
</template>
</interface>
]]></property>
</object>
</child>
<child>
<object class="GtkTreeViewColumn">
<property name="title" translatable="yes">Min</property>
<child>
<object class="GtkCellRendererText">
<property name="xalign">0.0</property>
</object>
<attributes>
<attribute name="text">1</attribute>
</attributes>
</child>
</property>
</object>
</child>
<child>
<object class="GtkColumnViewColumn">
<property name="title" translatable="yes">Hits</property>
<property name="sorter">
<object class="GtkNumericSorter">
<property name="expression">
<lookup name="hits" type="SysprofMarkDetail"/>
</property>
</object>
</child>
<child>
<object class="GtkTreeViewColumn">
<property name="title" translatable="yes">Max</property>
<child>
<object class="GtkCellRendererText">
<property name="xalign">0.0</property>
</object>
<attributes>
<attribute name="text">2</attribute>
</attributes>
</child>
</property>
<property name="factory">
<object class="GtkBuilderListItemFactory">
<property name="bytes"><![CDATA[
<?xml version="1.0" encoding="UTF-8"?>
<interface>
<template class="GtkListItem">
<property name="child">
<object class="GtkLabel">
<property name="xalign">0</property>
<binding name="label">
<lookup name="hits" type="SysprofMarkDetail">
<lookup name="item">GtkListItem</lookup>
</lookup>
</binding>
</object>
</property>
</template>
</interface>
]]></property>
</object>
</child>
<child>
<object class="GtkTreeViewColumn">
<property name="title" translatable="yes">Avg</property>
<child>
<object class="GtkCellRendererText">
<property name="xalign">0.0</property>
</object>
<attributes>
<attribute name="text">3</attribute>
</attributes>
</child>
</property>
</object>
</child>
<child>
<object class="GtkColumnViewColumn">
<property name="title" translatable="yes">Min</property>
<property name="sorter">
<object class="GtkNumericSorter">
<property name="expression">
<lookup name="min" type="SysprofMarkDetail"/>
</property>
</object>
</child>
</property>
<property name="factory">
<object class="GtkBuilderListItemFactory">
<property name="bytes"><![CDATA[
<?xml version="1.0" encoding="UTF-8"?>
<interface>
<template class="GtkListItem">
<property name="child">
<object class="GtkLabel">
<property name="xalign">0</property>
<binding name="label">
<closure type="gchararray" function="format_time">
<lookup name='min' type='SysprofMarkDetail'><lookup name='item'>GtkListItem</lookup></lookup>
</closure>
</binding>
</object>
</property>
</template>
</interface>
]]></property>
</object>
</property>
</object>
</child>
<child>
<object class="GtkColumnViewColumn">
<property name="title" translatable="yes">Max</property>
<property name="sorter">
<object class="GtkNumericSorter">
<property name="expression">
<lookup name="max" type="SysprofMarkDetail"/>
</property>
</object>
</property>
<property name="factory">
<object class="GtkBuilderListItemFactory">
<property name="bytes"><![CDATA[
<?xml version="1.0" encoding="UTF-8"?>
<interface>
<template class="GtkListItem">
<property name="child">
<object class="GtkLabel">
<property name="xalign">0</property>
<binding name="label">
<closure type="gchararray" function="format_time">
<lookup name='max' type='SysprofMarkDetail'><lookup name='item'>GtkListItem</lookup></lookup>
</closure>
</binding>
</object>
</property>
</template>
</interface>
]]></property>
</object>
</property>
</object>
</child>
<child>
<object class="GtkColumnViewColumn">
<property name="title" translatable="yes">Avg</property>
<property name="sorter">
<object class="GtkNumericSorter">
<property name="expression">
<lookup name="average" type="SysprofMarkDetail"/>
</property>
</object>
</property>
<property name="factory">
<object class="GtkBuilderListItemFactory">
<property name="bytes"><![CDATA[
<?xml version="1.0" encoding="UTF-8"?>
<interface>
<template class="GtkListItem">
<property name="child">
<object class="GtkLabel">
<property name="xalign">0</property>
<binding name="label">
<closure type="gchararray" function="format_time">
<lookup name='average' type='SysprofMarkDetail'><lookup name='item'>GtkListItem</lookup></lookup>
</closure>
</binding>
</object>
</property>
</template>
</interface>
]]></property>
</object>
</property>
</object>
</child>
</object>
@ -245,18 +349,13 @@
</object>
</child>
</template>
<object class="GtkListStore" id="marks_store">
<columns>
<!-- column-name Mark -->
<column type="gchararray"/>
<!-- column-name Min -->
<column type="gchararray"/>
<!-- column-name Max -->
<column type="gchararray"/>
<!-- column-name Avg -->
<column type="gchararray"/>
<!-- column-name Hits -->
<column type="gint64"/>
</columns>
<object class="GtkSortListModel" id="mark_sort_model">
<property name="model">marks_store</property>
<property name="incremental">true</property>
<binding name="sorter">
<lookup name="sorter">marks_view</lookup>
</binding>
</object>
<object class="GListStore" id="marks_store">
</object>
</interface>

View File

@ -0,0 +1,208 @@
/* sysprof-mark-detail.c
*
* Copyright 2022 Corentin Noël <corentin.noel@collabora.com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* SPDX-License-Identifier: GPL-3.0-or-later
*/
#define G_LOG_DOMAIN "sysprof-mark-detail"
#include "config.h"
#include <glib/gi18n.h>
#include "sysprof-mark-detail.h"
struct _SysprofMarkDetail
{
GObject parent_instance;
gchar *label;
gint64 min;
gint64 max;
gint64 average;
gint64 hits;
};
G_DEFINE_TYPE (SysprofMarkDetail, sysprof_mark_detail, G_TYPE_OBJECT)
enum {
PROP_0,
PROP_LABEL,
PROP_MIN,
PROP_MAX,
PROP_AVERAGE,
PROP_HITS,
N_PROPS
};
static GParamSpec *properties [N_PROPS];
/**
* sysprof_mark_detail_new:
*
* Create a new #SysprofMarkDetail.
*
* Returns: (transfer full): a newly created #SysprofMarkDetail
*/
SysprofMarkDetail *
sysprof_mark_detail_new (const gchar *mark,
gint64 min,
gint64 max,
gint64 avg,
gint64 hits)
{
return g_object_new (SYSPROF_TYPE_MARK_DETAIL,
"label", mark,
"min", min,
"max", max,
"average", avg,
"hits", hits,
NULL);
}
static void
sysprof_mark_detail_finalize (GObject *object)
{
SysprofMarkDetail *self = (SysprofMarkDetail *)object;
g_clear_pointer (&self->label, g_free);
G_OBJECT_CLASS (sysprof_mark_detail_parent_class)->finalize (object);
}
static void
sysprof_mark_detail_get_property (GObject *object,
guint prop_id,
GValue *value,
GParamSpec *pspec)
{
SysprofMarkDetail *self = SYSPROF_MARK_DETAIL(object);
switch (prop_id)
{
case PROP_LABEL:
g_value_set_string (value, self->label);
break;
case PROP_MIN:
g_value_set_int64 (value, self->min);
break;
case PROP_MAX:
g_value_set_int64 (value, self->max);
break;
case PROP_AVERAGE:
g_value_set_int64 (value, self->average);
break;
case PROP_HITS:
g_value_set_int64 (value, self->hits);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
}
}
static void
sysprof_mark_detail_set_property (GObject *object,
guint prop_id,
const GValue *value,
GParamSpec *pspec)
{
SysprofMarkDetail *self = SYSPROF_MARK_DETAIL(object);
switch (prop_id)
{
case PROP_LABEL:
g_assert(self->label == NULL);
self->label = g_value_dup_string (value);
break;
case PROP_MIN:
self->min = g_value_get_int64 (value);
break;
case PROP_MAX:
self->max = g_value_get_int64 (value);
break;
case PROP_AVERAGE:
self->average = g_value_get_int64 (value);
break;
case PROP_HITS:
self->hits = g_value_get_int64 (value);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
}
}
static void
sysprof_mark_detail_class_init (SysprofMarkDetailClass *klass)
{
GObjectClass *object_class = G_OBJECT_CLASS (klass);
object_class->finalize = sysprof_mark_detail_finalize;
object_class->get_property = sysprof_mark_detail_get_property;
object_class->set_property = sysprof_mark_detail_set_property;
properties [PROP_LABEL] =
g_param_spec_string ("label",
"Label",
"The label of the mark",
NULL,
(G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS));
properties [PROP_MIN] =
g_param_spec_int64 ("min",
"Min",
"The minimal timespan",
0, G_MAXINT64, 0,
(G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS));
properties [PROP_MAX] =
g_param_spec_int64 ("max",
"max",
"The maximal timespan",
0, G_MAXINT64, 0,
(G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS));
properties [PROP_AVERAGE] =
g_param_spec_int64 ("average",
"Average",
"The average timespan",
0, G_MAXINT64, 0,
(G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS));
properties [PROP_HITS] =
g_param_spec_int64 ("hits",
"Hits",
"The number of hits",
0, G_MAXINT64, 0,
(G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS));
g_object_class_install_properties (object_class, N_PROPS, properties);
}
static void
sysprof_mark_detail_init (SysprofMarkDetail *self)
{
}

View File

@ -0,0 +1,37 @@
/* sysprof-mark-detail.h
*
* Copyright 2022 Corentin Noël <corentin.noel@collabora.com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* SPDX-License-Identifier: GPL-3.0-or-later
*/
#pragma once
#include <gio/gio.h>
G_BEGIN_DECLS
#define SYSPROF_TYPE_MARK_DETAIL (sysprof_mark_detail_get_type())
G_DECLARE_FINAL_TYPE (SysprofMarkDetail, sysprof_mark_detail, SYSPROF, MARK_DETAIL, GObject)
SysprofMarkDetail *sysprof_mark_detail_new (const gchar *mark,
gint64 min,
gint64 max,
gint64 avg,
gint64 hits);
G_END_DECLS