mirror of
https://github.com/varun-r-mallya/sysprof.git
synced 2026-02-12 16:10:54 +00:00
libsysprof-gtk: make chart row use :model property
This will allow us to make a map model and then bind from that after filtering based on selection.
This commit is contained in:
@ -22,16 +22,14 @@
|
|||||||
|
|
||||||
#include <gtk/gtk.h>
|
#include <gtk/gtk.h>
|
||||||
|
|
||||||
#include <sysprof-analyze.h>
|
|
||||||
|
|
||||||
G_BEGIN_DECLS
|
G_BEGIN_DECLS
|
||||||
|
|
||||||
#define SYSPROF_TYPE_MARK_CHART_ROW (sysprof_mark_chart_row_get_type())
|
#define SYSPROF_TYPE_MARK_CHART_ROW (sysprof_mark_chart_row_get_type())
|
||||||
|
|
||||||
G_DECLARE_FINAL_TYPE (SysprofMarkChartRow, sysprof_mark_chart_row, SYSPROF, MARK_CHART_ROW, GtkWidget)
|
G_DECLARE_FINAL_TYPE (SysprofMarkChartRow, sysprof_mark_chart_row, SYSPROF, MARK_CHART_ROW, GtkWidget)
|
||||||
|
|
||||||
SysprofMarkCatalog *sysprof_mark_chart_row_get_catalog (SysprofMarkChartRow *self);
|
GListModel *sysprof_mark_chart_row_get_model (SysprofMarkChartRow *self);
|
||||||
void sysprof_mark_chart_row_set_catalog (SysprofMarkChartRow *self,
|
void sysprof_mark_chart_row_set_model (SysprofMarkChartRow *self,
|
||||||
SysprofMarkCatalog *catalog);
|
GListModel *model);
|
||||||
|
|
||||||
G_END_DECLS
|
G_END_DECLS
|
||||||
|
|||||||
@ -20,17 +20,19 @@
|
|||||||
|
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
|
|
||||||
|
#include <sysprof-analyze.h>
|
||||||
|
|
||||||
#include "sysprof-mark-chart-row-private.h"
|
#include "sysprof-mark-chart-row-private.h"
|
||||||
|
|
||||||
struct _SysprofMarkChartRow
|
struct _SysprofMarkChartRow
|
||||||
{
|
{
|
||||||
GtkWidget parent_instance;
|
GtkWidget parent_instance;
|
||||||
SysprofMarkCatalog *catalog;
|
GListModel *model;
|
||||||
};
|
};
|
||||||
|
|
||||||
enum {
|
enum {
|
||||||
PROP_0,
|
PROP_0,
|
||||||
PROP_CATALOG,
|
PROP_MODEL,
|
||||||
N_PROPS
|
N_PROPS
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -55,13 +57,13 @@ sysprof_mark_chart_row_snapshot (GtkWidget *widget,
|
|||||||
g_assert (SYSPROF_IS_MARK_CHART_ROW (self));
|
g_assert (SYSPROF_IS_MARK_CHART_ROW (self));
|
||||||
g_assert (GTK_IS_SNAPSHOT (snapshot));
|
g_assert (GTK_IS_SNAPSHOT (snapshot));
|
||||||
|
|
||||||
if (self->catalog == NULL)
|
if (self->model == NULL)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
width = gtk_widget_get_width (widget);
|
width = gtk_widget_get_width (widget);
|
||||||
height = gtk_widget_get_height (widget);
|
height = gtk_widget_get_height (widget);
|
||||||
|
|
||||||
model = G_LIST_MODEL (self->catalog);
|
model = G_LIST_MODEL (self->model);
|
||||||
n_items = g_list_model_get_n_items (model);
|
n_items = g_list_model_get_n_items (model);
|
||||||
|
|
||||||
layout = gtk_widget_create_pango_layout (widget, NULL);
|
layout = gtk_widget_create_pango_layout (widget, NULL);
|
||||||
@ -113,7 +115,7 @@ sysprof_mark_chart_row_dispose (GObject *object)
|
|||||||
{
|
{
|
||||||
SysprofMarkChartRow *self = (SysprofMarkChartRow *)object;
|
SysprofMarkChartRow *self = (SysprofMarkChartRow *)object;
|
||||||
|
|
||||||
g_clear_object (&self->catalog);
|
g_clear_object (&self->model);
|
||||||
|
|
||||||
G_OBJECT_CLASS (sysprof_mark_chart_row_parent_class)->dispose (object);
|
G_OBJECT_CLASS (sysprof_mark_chart_row_parent_class)->dispose (object);
|
||||||
}
|
}
|
||||||
@ -128,8 +130,8 @@ sysprof_mark_chart_row_get_property (GObject *object,
|
|||||||
|
|
||||||
switch (prop_id)
|
switch (prop_id)
|
||||||
{
|
{
|
||||||
case PROP_CATALOG:
|
case PROP_MODEL:
|
||||||
g_value_set_object (value, sysprof_mark_chart_row_get_catalog (self));
|
g_value_set_object (value, sysprof_mark_chart_row_get_model (self));
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
@ -147,8 +149,8 @@ sysprof_mark_chart_row_set_property (GObject *object,
|
|||||||
|
|
||||||
switch (prop_id)
|
switch (prop_id)
|
||||||
{
|
{
|
||||||
case PROP_CATALOG:
|
case PROP_MODEL:
|
||||||
sysprof_mark_chart_row_set_catalog (self, g_value_get_object (value));
|
sysprof_mark_chart_row_set_model (self, g_value_get_object (value));
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
@ -168,9 +170,9 @@ sysprof_mark_chart_row_class_init (SysprofMarkChartRowClass *klass)
|
|||||||
|
|
||||||
widget_class->snapshot = sysprof_mark_chart_row_snapshot;
|
widget_class->snapshot = sysprof_mark_chart_row_snapshot;
|
||||||
|
|
||||||
properties [PROP_CATALOG] =
|
properties [PROP_MODEL] =
|
||||||
g_param_spec_object ("catalog", NULL, NULL,
|
g_param_spec_object ("model", NULL, NULL,
|
||||||
SYSPROF_TYPE_MARK_CATALOG,
|
G_TYPE_LIST_MODEL,
|
||||||
(G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
|
(G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
|
||||||
|
|
||||||
g_object_class_install_properties (object_class, N_PROPS, properties);
|
g_object_class_install_properties (object_class, N_PROPS, properties);
|
||||||
@ -181,24 +183,39 @@ sysprof_mark_chart_row_init (SysprofMarkChartRow *self)
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
SysprofMarkCatalog *
|
GListModel *
|
||||||
sysprof_mark_chart_row_get_catalog (SysprofMarkChartRow *self)
|
sysprof_mark_chart_row_get_model (SysprofMarkChartRow *self)
|
||||||
{
|
{
|
||||||
g_return_val_if_fail (SYSPROF_IS_MARK_CHART_ROW (self), NULL);
|
g_return_val_if_fail (SYSPROF_IS_MARK_CHART_ROW (self), NULL);
|
||||||
|
|
||||||
return self->catalog;
|
return self->model;
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
sysprof_mark_chart_row_set_catalog (SysprofMarkChartRow *self,
|
sysprof_mark_chart_row_set_model (SysprofMarkChartRow *self,
|
||||||
SysprofMarkCatalog *catalog)
|
GListModel *model)
|
||||||
{
|
{
|
||||||
g_return_if_fail (SYSPROF_IS_MARK_CHART_ROW (self));
|
g_return_if_fail (SYSPROF_IS_MARK_CHART_ROW (self));
|
||||||
g_return_if_fail (!catalog || SYSPROF_IS_MARK_CATALOG (catalog));
|
g_return_if_fail (!model || G_IS_LIST_MODEL (model));
|
||||||
|
|
||||||
if (g_set_object (&self->catalog, catalog))
|
if (self->model == model)
|
||||||
{
|
return;
|
||||||
g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_CATALOG]);
|
|
||||||
gtk_widget_queue_draw (GTK_WIDGET (self));
|
if (self->model)
|
||||||
}
|
g_signal_handlers_disconnect_by_func (self->model,
|
||||||
|
G_CALLBACK (gtk_widget_queue_allocate),
|
||||||
|
self);
|
||||||
|
|
||||||
|
g_set_object (&self->model, model);
|
||||||
|
|
||||||
|
if (model)
|
||||||
|
g_signal_connect_object (model,
|
||||||
|
"items-changed",
|
||||||
|
G_CALLBACK (gtk_widget_queue_allocate),
|
||||||
|
self,
|
||||||
|
G_CONNECT_SWAPPED);
|
||||||
|
|
||||||
|
g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_MODEL]);
|
||||||
|
|
||||||
|
gtk_widget_queue_allocate (GTK_WIDGET (self));
|
||||||
}
|
}
|
||||||
|
|||||||
@ -58,7 +58,7 @@
|
|||||||
<child>
|
<child>
|
||||||
<object class="SysprofMarkChartRow">
|
<object class="SysprofMarkChartRow">
|
||||||
<property name="hexpand">true</property>
|
<property name="hexpand">true</property>
|
||||||
<binding name="catalog">
|
<binding name="model">
|
||||||
<lookup name="item">GtkListItem</lookup>
|
<lookup name="item">GtkListItem</lookup>
|
||||||
</binding>
|
</binding>
|
||||||
</object>
|
</object>
|
||||||
|
|||||||
Reference in New Issue
Block a user