From 1afec5c02563ef53e0be49c6a24e75755dea773d Mon Sep 17 00:00:00 2001 From: Dan Nechita Date: Wed, 15 Jul 2020 14:23:06 +0300 Subject: [PATCH] oscplot: Add option to enable/disable all channels at once This can be handy when there are many channels. Signed-off-by: Dan Nechita --- glade/oscplot.glade | 61 +++++++++++++++++++++++++++++++++++---------- oscplot.c | 41 ++++++++++++++++++++++++++++++ 2 files changed, 89 insertions(+), 13 deletions(-) diff --git a/glade/oscplot.glade b/glade/oscplot.glade index 739143636..17895deae 100644 --- a/glade/oscplot.glade +++ b/glade/oscplot.glade @@ -784,25 +784,60 @@ True False - + True False + 3 - + True False - 0.10000000149011612 - <b>Plot Channels</b> - True + + + True + False + 0.10000000149011612 + <b>Plot Channels</b> + True + + + False + True + 0 + + + + + True + False + + + + + + + + + True + True + 1 + + + + + Enable All + 90 + True + True + True + + + False + True + 2 + + - - False - True - 0 - - - - diff --git a/oscplot.c b/oscplot.c index ac625f5b1..f2be7aa5e 100644 --- a/oscplot.c +++ b/oscplot.c @@ -6697,6 +6697,44 @@ static bool set_channel_state_in_tree_model(GtkTreeModel *model, GtkTreeIter* ch return false; } +static void set_channel_state_via_iter(GtkTreeModel *model, + GtkTreeIter *iter, void *user_data) +{ + gboolean enable_state = *(gboolean *)user_data; + set_channel_state_in_tree_model(model, iter, enable_state); +} + +static void enable_all_button_toggled_cb(GtkToggleButton *btn, OscPlot *plot) +{ + OscPlotPrivate *priv = plot->priv; + gboolean toggled = gtk_toggle_button_get_active(btn); + + if (toggled) { + gtk_button_set_label(GTK_BUTTON(btn), "Disable All"); + } else { + gtk_button_set_label(GTK_BUTTON(btn), "Enable All"); + } + + // Enable/disable by going through all channels of each device + GtkTreeView *treeview = GTK_TREE_VIEW(priv->channel_list_view); + GtkTreeModel *model; + GtkTreeIter iter; + gboolean next_iter; + gchar *dev_name; + + model = gtk_tree_view_get_model(treeview); + next_iter = gtk_tree_model_get_iter_first(model, &iter); + while (next_iter) { + gtk_tree_model_get(model, &iter, + ELEMENT_NAME, &dev_name, -1); + foreach_channel_iter_of_device(treeview, dev_name, + *set_channel_state_via_iter, &toggled); + g_free(dev_name); + next_iter = gtk_tree_model_iter_next(model, &iter); + } + check_valid_setup(plot); +} + static void create_plot(OscPlot *plot) { OscPlotPrivate *priv = plot->priv; @@ -7011,6 +7049,9 @@ static void create_plot(OscPlot *plot) g_signal_connect(key_fullscale, "clicked", G_CALLBACK(math_chooser_fullscale_key_pressed_cb), plot); + g_builder_connect_signal(builder, "togglebutton_enable_all", "toggled", + G_CALLBACK(enable_all_button_toggled_cb), plot); + /* Create Bindings */ g_object_bind_property_full(priv->capture_button, "active", priv->capture_button, "stock-id", 0, capture_button_icon_transform, NULL, plot, NULL);