From 5e18436a15298a95cda9ecd0123bbf1b70dd312c Mon Sep 17 00:00:00 2001 From: Christian Hergert Date: Thu, 15 Jun 2023 17:08:38 -0700 Subject: [PATCH] libsysprof-gtk: add SysprofMarkChartItem The goal here is to use a map list model to convert to these and then to use the session filter to apply the selection. --- src/libsysprof-gtk/meson.build | 1 + .../sysprof-mark-chart-item-private.h | 39 +++++ src/libsysprof-gtk/sysprof-mark-chart-item.c | 159 ++++++++++++++++++ 3 files changed, 199 insertions(+) create mode 100644 src/libsysprof-gtk/sysprof-mark-chart-item-private.h create mode 100644 src/libsysprof-gtk/sysprof-mark-chart-item.c diff --git a/src/libsysprof-gtk/meson.build b/src/libsysprof-gtk/meson.build index dae0173e..7b5c1163 100644 --- a/src/libsysprof-gtk/meson.build +++ b/src/libsysprof-gtk/meson.build @@ -8,6 +8,7 @@ libsysprof_gtk_public_sources = [ libsysprof_gtk_private_sources = [ 'sysprof-css.c', + 'sysprof-mark-chart-item.c', 'sysprof-mark-chart-row.c', 'sysprof-progress-cell.c', 'sysprof-symbol-label.c', diff --git a/src/libsysprof-gtk/sysprof-mark-chart-item-private.h b/src/libsysprof-gtk/sysprof-mark-chart-item-private.h new file mode 100644 index 00000000..01c5d266 --- /dev/null +++ b/src/libsysprof-gtk/sysprof-mark-chart-item-private.h @@ -0,0 +1,39 @@ +/* sysprof-mark-chart-item-private.h + * + * Copyright 2023 Christian Hergert + * + * 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 . + * + * SPDX-License-Identifier: GPL-3.0-or-later + */ + +#pragma once + +#include + +#include "sysprof-session.h" + +G_BEGIN_DECLS + +#define SYSPROF_TYPE_MARK_CHART_ITEM (sysprof_mark_chart_item_get_type()) + +G_DECLARE_FINAL_TYPE (SysprofMarkChartItem, sysprof_mark_chart_item, SYSPROF, MARK_CHART_ITEM, GObject) + +SysprofMarkChartItem *sysprof_mark_chart_item_new (SysprofSession *session, + SysprofMarkCatalog *catalog); +SysprofMarkCatalog *sysprof_mark_chart_item_get_catalog (SysprofMarkChartItem *self); +SysprofSession *sysprof_mark_chart_item_get_session (SysprofMarkChartItem *self); +GListModel *sysprof_mark_chart_item_get_marks (SysprofMarkChartItem *self); + +G_END_DECLS diff --git a/src/libsysprof-gtk/sysprof-mark-chart-item.c b/src/libsysprof-gtk/sysprof-mark-chart-item.c new file mode 100644 index 00000000..e28b8703 --- /dev/null +++ b/src/libsysprof-gtk/sysprof-mark-chart-item.c @@ -0,0 +1,159 @@ +/* sysprof-mark-chart-item.c + * + * Copyright 2023 Christian Hergert + * + * 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 . + * + * SPDX-License-Identifier: GPL-3.0-or-later + */ + +#include "config.h" + +#include "sysprof-mark-chart-item-private.h" + +struct _SysprofMarkChartItem +{ + GObject parent_instance; + SysprofSession *session; + SysprofMarkCatalog *catalog; + GtkFilterListModel *filtered; +}; + +enum { + PROP_0, + PROP_SESSION, + PROP_CATALOG, + N_PROPS +}; + +G_DEFINE_FINAL_TYPE (SysprofMarkChartItem, sysprof_mark_chart_item, G_TYPE_OBJECT) + +static GParamSpec *properties [N_PROPS]; + +static void +sysprof_mark_chart_item_constructed (GObject *object) +{ + SysprofMarkChartItem *self = (SysprofMarkChartItem *)object; + + self->filtered = gtk_filter_list_model_new (g_object_ref (G_LIST_MODEL (self->catalog)), NULL); + g_object_bind_property (self->session, "filter", self->filtered, "filter", G_BINDING_SYNC_CREATE); + + G_OBJECT_CLASS (sysprof_mark_chart_item_parent_class)->constructed (object); +} + +static void +sysprof_mark_chart_item_dispose (GObject *object) +{ + SysprofMarkChartItem *self = (SysprofMarkChartItem *)object; + + g_clear_object (&self->session); + g_clear_object (&self->catalog); + + G_OBJECT_CLASS (sysprof_mark_chart_item_parent_class)->dispose (object); +} + +static void +sysprof_mark_chart_item_get_property (GObject *object, + guint prop_id, + GValue *value, + GParamSpec *pspec) +{ + SysprofMarkChartItem *self = SYSPROF_MARK_CHART_ITEM (object); + + switch (prop_id) + { + case PROP_CATALOG: + g_value_set_object (value, sysprof_mark_chart_item_get_catalog (self)); + break; + + case PROP_SESSION: + g_value_set_object (value, sysprof_mark_chart_item_get_session (self)); + break; + + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); + } +} + +static void +sysprof_mark_chart_item_set_property (GObject *object, + guint prop_id, + const GValue *value, + GParamSpec *pspec) +{ + SysprofMarkChartItem *self = SYSPROF_MARK_CHART_ITEM (object); + + switch (prop_id) + { + case PROP_CATALOG: + self->catalog = g_value_dup_object (value); + break; + + case PROP_SESSION: + self->session = g_value_dup_object (value); + break; + + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); + } +} + +static void +sysprof_mark_chart_item_class_init (SysprofMarkChartItemClass *klass) +{ + GObjectClass *object_class = G_OBJECT_CLASS (klass); + + object_class->constructed = sysprof_mark_chart_item_constructed; + object_class->dispose = sysprof_mark_chart_item_dispose; + object_class->get_property = sysprof_mark_chart_item_get_property; + object_class->set_property = sysprof_mark_chart_item_set_property; + + properties[PROP_CATALOG] = + g_param_spec_object ("catalog", NULL, NULL, + SYSPROF_TYPE_MARK_CATALOG, + (G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS)); + + properties[PROP_SESSION] = + g_param_spec_object ("session", NULL, NULL, + SYSPROF_TYPE_SESSION, + (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_chart_item_init (SysprofMarkChartItem *self) +{ +} + +SysprofMarkChartItem * +_sysprof_mark_chart_item_new (SysprofSession *session, + SysprofMarkCatalog *catalog) +{ + g_return_val_if_fail (SYSPROF_IS_SESSION (session), NULL); + g_return_val_if_fail (SYSPROF_IS_MARK_CATALOG (catalog), NULL); + + return g_object_new (SYSPROF_TYPE_MARK_CHART_ITEM, + "session", session, + "catalog", catalog, + NULL); +} + +GListModel * +sysprof_mark_chart_item_get_marks (SysprofMarkChartItem *self) +{ + g_return_val_if_fail (SYSPROF_IS_MARK_CHART_ITEM (self), NULL); + + return G_LIST_MODEL (self->filtered); +}