Beispiel #1
0
/**
 * gwy_graph_label_set_model:
 * @label: A graph label.
 * @gmodel: New graph model.
 *
 * Sets new model of a graph label.
 **/
void
gwy_graph_label_set_model(GwyGraphLabel *label,
                          GwyGraphModel *gmodel)
{
    g_return_if_fail(GWY_IS_GRAPH_LABEL(label));
    g_return_if_fail(!gmodel || GWY_IS_GRAPH_MODEL(gmodel));

    if (label->graph_model == gmodel)
        return;

    gwy_signal_handler_disconnect(label->graph_model, label->model_notify_id);
    gwy_signal_handler_disconnect(label->graph_model, label->curve_notify_id);

    if (gmodel)
        g_object_ref(gmodel);
    gwy_object_unref(label->graph_model);
    label->graph_model = gmodel;

    if (gmodel) {
        label->model_notify_id
            = g_signal_connect_swapped(gmodel, "notify",
                                       G_CALLBACK(gwy_graph_label_model_notify),
                                       label);
        label->curve_notify_id
            = g_signal_connect_swapped(gmodel, "curve-notify",
                                       G_CALLBACK(gwy_graph_label_curve_notify),
                                       label);
    }

    gwy_graph_label_refresh_all(label);
    gwy_graph_label_refresh_visible(label);
}
Beispiel #2
0
static gboolean
filter_target_graphs(GwyContainer *data, gint id, gpointer user_data)
{
    GrainCrossControls *controls = (GrainCrossControls*)user_data;
    GwyGraphModel *gmodel, *targetgmodel;
    GQuark quark = gwy_app_get_graph_key_for_id(id);

    gmodel = gwy_graph_get_model(GWY_GRAPH(controls->graph));
    g_return_val_if_fail(GWY_IS_GRAPH_MODEL(gmodel), FALSE);
    return (gwy_container_gis_object(data, quark, (GObject**)&targetgmodel)
            && gwy_graph_model_units_are_compatible(gmodel, targetgmodel));
}
Beispiel #3
0
/**
 * gwy_graph_data_new:
 * @gmodel: A graph_data model.  It can be %NULL.
 *
 * Creates graph_data widget based on information in graph model.
 *
 * The #GtkTreeModel and the columns follow the graph model and must not be
 * changed manually.
 *
 * Returns: A new graph_data widget.
 **/
GtkWidget*
gwy_graph_data_new(GwyGraphModel *gmodel)
{
    GwyGraphData *graph_data;

    graph_data = g_object_new(GWY_TYPE_GRAPH_DATA, NULL);
    g_return_val_if_fail(!gmodel || GWY_IS_GRAPH_MODEL(gmodel),
                         (GtkWidget*)graph_data);

    if (gmodel)
       gwy_graph_data_set_model(graph_data, gmodel);

    return (GtkWidget*)graph_data;
}
static void
add_object_id(gpointer hkey,
              gpointer hvalue,
              gpointer user_data)
{
    GValue *value = (GValue*)hvalue;
    FileInfoData *filedata = (FileInfoData*)user_data;
    const gchar *strkey;
    gchar *end;
    gint id;

    strkey = g_quark_to_string(GPOINTER_TO_UINT(hkey));
    if (!strkey || strkey[0] != '/' || !G_VALUE_HOLDS_OBJECT(value))
        return;

    if ((id = strtol(strkey + 1, &end, 10)) >= 0
            && gwy_strequal(end, "/data")
            && GWY_IS_DATA_FIELD(g_value_get_object(value))) {
        filedata->nchannels++;
        filedata->channels = g_slist_prepend(filedata->channels,
                                             GINT_TO_POINTER(id));
        return;
    }

    if (g_str_has_prefix(strkey, "/0/graph/graph/")
            && (id = strtol(strkey + 15, &end, 10)) >= 0
            && !*end
            && GWY_IS_GRAPH_MODEL(g_value_get_object(value))) {
        filedata->ngraphs++;
        filedata->graphs = g_slist_prepend(filedata->graphs,
                                           GINT_TO_POINTER(id));
        return;
    }

    if (g_str_has_prefix(strkey, "/sps/")
            && (id = strtol(strkey + 5, &end, 10)) >= 0
            && !*end
            && GWY_IS_SPECTRA(g_value_get_object(value))) {
        filedata->nspectra++;
        filedata->spectra = g_slist_prepend(filedata->spectra,
                                            GINT_TO_POINTER(id));
        return;
    }
}
Beispiel #5
0
/**
 * gwy_app_data_id_verify_graph:
 * @id: Numerical identifiers of a graph in data managed by the data browser.
 *
 * Checks if numerical graph identifiers correspond to an existing graph.
 *
 * If either the data contained referenced in @id or the graph model does not
 * exist the structure is cleared to %GWY_APP_DATA_ID_NONE and the function
 * returns %FALSE.  If it represents an existing graph it is kept intact and
 * the function return %TRUE.
 *
 * Returns: Whether @id refers to an existing graph now.
 *
 * Since: 2.41
 **/
gboolean
gwy_app_data_id_verify_graph(GwyAppDataId *id)
{
    GwyContainer *container;
    GObject *object;
    GQuark quark;

    g_return_val_if_fail(id, FALSE);

    container = gwy_app_data_browser_get(id->datano);
    if (!container)
        return clear_data_id(id);

    quark = gwy_app_get_graph_key_for_id(id->id);
    if (!gwy_container_gis_object(container, quark, &object))
        return clear_data_id(id);

    return GWY_IS_GRAPH_MODEL(object);
}
Beispiel #6
0
/**
 * gwy_graph_data_set_model:
 * @graph_data: A graph data widget.
 * @gmodel: New graph_data model.
 *
 * Changes the graph model a graph data table displays.
 **/
void
gwy_graph_data_set_model(GwyGraphData *graph_data,
                         GwyGraphModel *gmodel)
{
    g_return_if_fail(GWY_IS_GRAPH_DATA(graph_data));
    g_return_if_fail(!gmodel || GWY_IS_GRAPH_MODEL(gmodel));

    gwy_signal_handler_disconnect(graph_data->graph_model,
                                  graph_data->notify_id);
    gwy_object_unref(graph_data->graph_model);
    gwy_debug("setting model to: %p", gmodel);
    graph_data->graph_model = gmodel;
    if (gmodel) {
        g_object_ref(gmodel);
        graph_data->notify_id
            = g_signal_connect_swapped(gmodel, "notify",
                                       G_CALLBACK(gwy_graph_data_model_notify),
                                       graph_data);
    }
    gwy_graph_data_update_ncurves(graph_data);
}
Beispiel #7
0
/**
 * gwy_app_add_graph_or_curves:
 * @gmodel: A graph model with curves to add.
 * @data: Data container where the graph would be added.
 * @target_graph: Graph where curves would be added.
 * @colorstep: Curve block size as in gwy_graph_model_append_curves().
 *
 * Puts the curves of a graph to another graph if possible, or adds the graph
 * as new.
 *
 * If the units of @gmodel are compatible with the units of the graph
 * identified by @target_graph the curves are copied to the target graph with
 * gwy_graph_model_append_curves().
 *
 * In all other cases, including when @target_graph does not refer to any
 * existing graph, the graph model is added to @data as a new graph.
 *
 * Either way, the caller usually need to release its own reference afterwards.
 *
 * This function is useful particularly in modules that create graphs and can
 * be run non-interactively.
 *
 * Returns: The numerical identifier of the newly-created graph of one was
 *          created.  Value -1 is returned if curves were added to
 *          @target_graph.
 *
 * Since: 2.41
 **/
gint
gwy_app_add_graph_or_curves(GwyGraphModel *gmodel,
                            GwyContainer *data,
                            const GwyAppDataId *target_graph,
                            gint colorstep)
{
    GwyAppDataId tgtgraph = *target_graph;

    if (gwy_app_data_id_verify_graph(&tgtgraph)) {
        GQuark quark = gwy_app_get_graph_key_for_id(tgtgraph.id);
        GwyContainer *data2 = gwy_app_data_browser_get(tgtgraph.datano);
        GwyGraphModel *target_gmodel = gwy_container_get_object(data2, quark);

        g_return_val_if_fail(GWY_IS_GRAPH_MODEL(target_gmodel), -1);
        if (gwy_graph_model_units_are_compatible(gmodel, target_gmodel)) {
            gwy_graph_model_append_curves(target_gmodel, gmodel, colorstep);
            return -1;
        }
    }
    g_return_val_if_fail(GWY_IS_CONTAINER(data), FALSE);
    return gwy_app_data_browser_add_graph_model(gmodel, data, TRUE);
}