[gimp] app: add virtual function GimpFilterTool::config_notify()
- From: Michael Natterer <mitch src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gimp] app: add virtual function GimpFilterTool::config_notify()
- Date: Sun, 2 Jul 2017 22:46:30 +0000 (UTC)
commit 00a9659c28ed3b5df8e86c8efb3e9477ea4b0a72
Author: Michael Natterer <mitch gimp org>
Date: Mon Jul 3 00:15:09 2017 +0200
app: add virtual function GimpFilterTool::config_notify()
and call it from GimpFilterTool's "notify" callback. Remove signal
connections from all subblasses and instead implement ::config_notify().
The config object belongs to GimpFilterTool, and only GimpFilterTool
should know when it's created and can be connected to.
app/tools/gimpcurvestool.c | 70 +++++++++++---------------
app/tools/gimpfiltertool.c | 25 +++++++--
app/tools/gimpfiltertool.h | 3 +
app/tools/gimplevelstool.c | 111 +++++++++++++++++++----------------------
app/tools/gimpthresholdtool.c | 35 +++++--------
5 files changed, 119 insertions(+), 125 deletions(-)
---
diff --git a/app/tools/gimpcurvestool.c b/app/tools/gimpcurvestool.c
index 808b01c..e68b0e6 100644
--- a/app/tools/gimpcurvestool.c
+++ b/app/tools/gimpcurvestool.c
@@ -62,8 +62,6 @@
/* local function prototypes */
-static void gimp_curves_tool_constructed (GObject *object);
-
static gboolean gimp_curves_tool_initialize (GimpTool *tool,
GimpDisplay *display,
GError **error);
@@ -93,6 +91,9 @@ static gchar * gimp_curves_tool_get_operation (GimpFilterTool *filter
gchar **export_dialog_title);
static void gimp_curves_tool_dialog (GimpFilterTool *filter_tool);
static void gimp_curves_tool_reset (GimpFilterTool *filter_tool);
+static void gimp_curves_tool_config_notify (GimpFilterTool *filter_tool,
+ GimpConfig *config,
+ const GParamSpec *pspec);
static gboolean gimp_curves_tool_settings_import (GimpFilterTool *filter_tool,
GInputStream *input,
GError **error);
@@ -111,9 +112,6 @@ static void gimp_curves_tool_export_setup (GimpSettingsBox *settin
gboolean export,
GimpCurvesTool *tool);
static void gimp_curves_tool_update_channel (GimpCurvesTool *tool);
-static void gimp_curves_tool_config_notify (GObject *object,
- GParamSpec *pspec,
- GimpCurvesTool *tool);
static void curves_channel_callback (GtkWidget *widget,
GimpCurvesTool *tool);
@@ -161,12 +159,9 @@ gimp_curves_tool_register (GimpToolRegisterCallback callback,
static void
gimp_curves_tool_class_init (GimpCurvesToolClass *klass)
{
- GObjectClass *object_class = G_OBJECT_CLASS (klass);
GimpToolClass *tool_class = GIMP_TOOL_CLASS (klass);
GimpFilterToolClass *filter_tool_class = GIMP_FILTER_TOOL_CLASS (klass);
- object_class->constructed = gimp_curves_tool_constructed;
-
tool_class->initialize = gimp_curves_tool_initialize;
tool_class->button_release = gimp_curves_tool_button_release;
tool_class->key_press = gimp_curves_tool_key_press;
@@ -175,6 +170,7 @@ gimp_curves_tool_class_init (GimpCurvesToolClass *klass)
filter_tool_class->get_operation = gimp_curves_tool_get_operation;
filter_tool_class->dialog = gimp_curves_tool_dialog;
filter_tool_class->reset = gimp_curves_tool_reset;
+ filter_tool_class->config_notify = gimp_curves_tool_config_notify;
filter_tool_class->settings_import = gimp_curves_tool_settings_import;
filter_tool_class->settings_export = gimp_curves_tool_settings_export;
filter_tool_class->color_picked = gimp_curves_tool_color_picked;
@@ -189,16 +185,6 @@ gimp_curves_tool_init (GimpCurvesTool *tool)
tool->picked_color[i] = -1.0;
}
-static void
-gimp_curves_tool_constructed (GObject *object)
-{
- G_OBJECT_CLASS (parent_class)->constructed (object);
-
- g_signal_connect_object (GIMP_FILTER_TOOL (object)->config, "notify",
- G_CALLBACK (gimp_curves_tool_config_notify),
- object, 0);
-}
-
static gboolean
gimp_curves_tool_initialize (GimpTool *tool,
GimpDisplay *display,
@@ -600,6 +586,32 @@ gimp_curves_tool_reset (GimpFilterTool *filter_tool)
}
}
+static void
+gimp_curves_tool_config_notify (GimpFilterTool *filter_tool,
+ GimpConfig *config,
+ const GParamSpec *pspec)
+{
+ GimpCurvesTool *curves_tool = GIMP_CURVES_TOOL (filter_tool);
+ GimpCurvesConfig *curves_config = GIMP_CURVES_CONFIG (config);
+ GimpCurve *curve = curves_config->curve[curves_config->channel];
+
+ GIMP_FILTER_TOOL_CLASS (parent_class)->config_notify (filter_tool,
+ config, pspec);
+
+ if (! curves_tool->xrange)
+ return;
+
+ if (! strcmp (pspec->name, "channel"))
+ {
+ gimp_curves_tool_update_channel (GIMP_CURVES_TOOL (filter_tool));
+ }
+ else if (! strcmp (pspec->name, "curve"))
+ {
+ gimp_int_combo_box_set_active (GIMP_INT_COMBO_BOX (curves_tool->curve_type),
+ curve->curve_type);
+ }
+}
+
static gboolean
gimp_curves_tool_settings_import (GimpFilterTool *filter_tool,
GInputStream *input,
@@ -774,28 +786,6 @@ gimp_curves_tool_update_channel (GimpCurvesTool *tool)
}
static void
-gimp_curves_tool_config_notify (GObject *object,
- GParamSpec *pspec,
- GimpCurvesTool *tool)
-{
- GimpCurvesConfig *config = GIMP_CURVES_CONFIG (object);
- GimpCurve *curve = config->curve[config->channel];
-
- if (! tool->xrange)
- return;
-
- if (! strcmp (pspec->name, "channel"))
- {
- gimp_curves_tool_update_channel (GIMP_CURVES_TOOL (tool));
- }
- else if (! strcmp (pspec->name, "curve"))
- {
- gimp_int_combo_box_set_active (GIMP_INT_COMBO_BOX (tool->curve_type),
- curve->curve_type);
- }
-}
-
-static void
curves_channel_callback (GtkWidget *widget,
GimpCurvesTool *tool)
{
diff --git a/app/tools/gimpfiltertool.c b/app/tools/gimpfiltertool.c
index 456954e..6dd7dd5 100644
--- a/app/tools/gimpfiltertool.c
+++ b/app/tools/gimpfiltertool.c
@@ -137,8 +137,12 @@ static void gimp_filter_tool_color_picked (GimpColorTool *color_too
const GimpRGB *color);
static void gimp_filter_tool_real_reset (GimpFilterTool *filter_tool);
-static void gimp_filter_tool_real_set_config (GimpFilterTool *filter_tool,
+static void gimp_filter_tool_real_set_config(GimpFilterTool *filter_tool,
GimpConfig *config);
+static void gimp_filter_tool_real_config_notify
+ (GimpFilterTool *filter_tool,
+ GimpConfig *config,
+ const GParamSpec *pspec);
static void gimp_filter_tool_halt (GimpFilterTool *filter_tool);
static void gimp_filter_tool_commit (GimpFilterTool *filter_tool);
@@ -202,6 +206,7 @@ gimp_filter_tool_class_init (GimpFilterToolClass *klass)
klass->dialog = NULL;
klass->reset = gimp_filter_tool_real_reset;
klass->set_config = gimp_filter_tool_real_set_config;
+ klass->config_notify = gimp_filter_tool_real_config_notify;
klass->settings_import = gimp_filter_tool_real_settings_import;
klass->settings_export = gimp_filter_tool_real_settings_export;
}
@@ -950,6 +955,17 @@ gimp_filter_tool_real_set_config (GimpFilterTool *filter_tool,
}
static void
+gimp_filter_tool_real_config_notify (GimpFilterTool *filter_tool,
+ GimpConfig *config,
+ const GParamSpec *pspec)
+{
+ GimpFilterOptions *options = GIMP_FILTER_TOOL_GET_OPTIONS (filter_tool);
+
+ if (filter_tool->filter && options->preview)
+ gimp_drawable_filter_apply (filter_tool->filter, NULL);
+}
+
+static void
gimp_filter_tool_halt (GimpFilterTool *filter_tool)
{
GimpTool *tool = GIMP_TOOL (filter_tool);
@@ -1129,10 +1145,9 @@ gimp_filter_tool_config_notify (GObject *object,
const GParamSpec *pspec,
GimpFilterTool *filter_tool)
{
- GimpFilterOptions *options = GIMP_FILTER_TOOL_GET_OPTIONS (filter_tool);
-
- if (filter_tool->filter && options->preview)
- gimp_drawable_filter_apply (filter_tool->filter, NULL);
+ GIMP_FILTER_TOOL_GET_CLASS (filter_tool)->config_notify (filter_tool,
+ GIMP_CONFIG (object),
+ pspec);
}
static void
diff --git a/app/tools/gimpfiltertool.h b/app/tools/gimpfiltertool.h
index d24f1e2..b3671a0 100644
--- a/app/tools/gimpfiltertool.h
+++ b/app/tools/gimpfiltertool.h
@@ -92,6 +92,9 @@ struct _GimpFilterToolClass
void (* reset) (GimpFilterTool *filter_tool);
void (* set_config) (GimpFilterTool *filter_tool,
GimpConfig *config);
+ void (* config_notify) (GimpFilterTool *filter_tool,
+ GimpConfig *config,
+ const GParamSpec *pspec);
gboolean (* settings_import) (GimpFilterTool *filter_tool,
GInputStream *input,
diff --git a/app/tools/gimplevelstool.c b/app/tools/gimplevelstool.c
index 6994465..f1bd3f0 100644
--- a/app/tools/gimplevelstool.c
+++ b/app/tools/gimplevelstool.c
@@ -65,7 +65,6 @@
/* local function prototypes */
-static void gimp_levels_tool_constructed (GObject *object);
static void gimp_levels_tool_finalize (GObject *object);
static gboolean gimp_levels_tool_initialize (GimpTool *tool,
@@ -83,6 +82,9 @@ static gchar * gimp_levels_tool_get_operation (GimpFilterTool *filter_tool
gchar **export_dialog_title);
static void gimp_levels_tool_dialog (GimpFilterTool *filter_tool);
static void gimp_levels_tool_reset (GimpFilterTool *filter_tool);
+static void gimp_levels_tool_config_notify (GimpFilterTool *filter_tool,
+ GimpConfig *config,
+ const GParamSpec *pspec);
static gboolean gimp_levels_tool_settings_import(GimpFilterTool *filter_tool,
GInputStream *input,
GError **error);
@@ -100,9 +102,6 @@ static void gimp_levels_tool_export_setup (GimpSettingsBox *settings_bo
GtkFileChooserDialog *dialog,
gboolean export,
GimpLevelsTool *tool);
-static void gimp_levels_tool_config_notify (GObject *object,
- GParamSpec *pspec,
- GimpLevelsTool *tool);
static void levels_update_input_bar (GimpLevelsTool *tool);
@@ -152,7 +151,6 @@ gimp_levels_tool_class_init (GimpLevelsToolClass *klass)
GimpToolClass *tool_class = GIMP_TOOL_CLASS (klass);
GimpFilterToolClass *filter_tool_class = GIMP_FILTER_TOOL_CLASS (klass);
- object_class->constructed = gimp_levels_tool_constructed;
object_class->finalize = gimp_levels_tool_finalize;
tool_class->initialize = gimp_levels_tool_initialize;
@@ -160,6 +158,7 @@ gimp_levels_tool_class_init (GimpLevelsToolClass *klass)
filter_tool_class->get_operation = gimp_levels_tool_get_operation;
filter_tool_class->dialog = gimp_levels_tool_dialog;
filter_tool_class->reset = gimp_levels_tool_reset;
+ filter_tool_class->config_notify = gimp_levels_tool_config_notify;
filter_tool_class->settings_import = gimp_levels_tool_settings_import;
filter_tool_class->settings_export = gimp_levels_tool_settings_export;
filter_tool_class->color_picked = gimp_levels_tool_color_picked;
@@ -172,16 +171,6 @@ gimp_levels_tool_init (GimpLevelsTool *tool)
}
static void
-gimp_levels_tool_constructed (GObject *object)
-{
- G_OBJECT_CLASS (parent_class)->constructed (object);
-
- g_signal_connect_object (GIMP_FILTER_TOOL (object)->config, "notify",
- G_CALLBACK (gimp_levels_tool_config_notify),
- object, 0);
-}
-
-static void
gimp_levels_tool_finalize (GObject *object)
{
GimpLevelsTool *tool = GIMP_LEVELS_TOOL (object);
@@ -653,6 +642,54 @@ gimp_levels_tool_reset (GimpFilterTool *filter_tool)
NULL);
}
+static void
+gimp_levels_tool_config_notify (GimpFilterTool *filter_tool,
+ GimpConfig *config,
+ const GParamSpec *pspec)
+{
+ GimpLevelsTool *levels_tool = GIMP_LEVELS_TOOL (filter_tool);
+ GimpLevelsConfig *levels_config = GIMP_LEVELS_CONFIG (config);
+
+ GIMP_FILTER_TOOL_CLASS (parent_class)->config_notify (filter_tool,
+ config, pspec);
+
+ if (! levels_tool->low_input)
+ return;
+
+ if (! strcmp (pspec->name, "channel"))
+ {
+ gimp_histogram_view_set_channel (GIMP_HISTOGRAM_VIEW (levels_tool->histogram_view),
+ levels_config->channel);
+ gimp_color_bar_set_channel (GIMP_COLOR_BAR (levels_tool->output_bar),
+ levels_config->channel);
+ gimp_int_combo_box_set_active (GIMP_INT_COMBO_BOX (levels_tool->channel_menu),
+ levels_config->channel);
+ }
+ else if (! strcmp (pspec->name, "gamma") ||
+ ! strcmp (pspec->name, "low-input") ||
+ ! strcmp (pspec->name, "high-input"))
+ {
+ gdouble low = gtk_adjustment_get_value (levels_tool->low_input);
+ gdouble high = gtk_adjustment_get_value (levels_tool->high_input);
+ gdouble delta, mid, tmp, value;
+
+ gtk_adjustment_set_lower (levels_tool->high_input, low);
+ gtk_adjustment_set_lower (levels_tool->gamma_linear, low);
+
+ gtk_adjustment_set_upper (levels_tool->low_input, high);
+ gtk_adjustment_set_upper (levels_tool->gamma_linear, high);
+
+ levels_update_input_bar (levels_tool);
+
+ delta = (high - low) / 2.0;
+ mid = low + delta;
+ tmp = log10 (1.0 / levels_config->gamma[levels_config->channel]);
+ value = mid + delta * tmp;
+
+ gtk_adjustment_set_value (levels_tool->gamma_linear, value);
+ }
+}
+
static gboolean
gimp_levels_tool_settings_import (GimpFilterTool *filter_tool,
GInputStream *input,
@@ -788,50 +825,6 @@ gimp_levels_tool_export_setup (GimpSettingsBox *settings_box,
}
static void
-gimp_levels_tool_config_notify (GObject *object,
- GParamSpec *pspec,
- GimpLevelsTool *tool)
-{
- GimpLevelsConfig *config = GIMP_LEVELS_CONFIG (object);
-
- if (! tool->low_input)
- return;
-
- if (! strcmp (pspec->name, "channel"))
- {
- gimp_histogram_view_set_channel (GIMP_HISTOGRAM_VIEW (tool->histogram_view),
- config->channel);
- gimp_color_bar_set_channel (GIMP_COLOR_BAR (tool->output_bar),
- config->channel);
- gimp_int_combo_box_set_active (GIMP_INT_COMBO_BOX (tool->channel_menu),
- config->channel);
- }
- else if (! strcmp (pspec->name, "gamma") ||
- ! strcmp (pspec->name, "low-input") ||
- ! strcmp (pspec->name, "high-input"))
- {
- gdouble low = gtk_adjustment_get_value (tool->low_input);
- gdouble high = gtk_adjustment_get_value (tool->high_input);
- gdouble delta, mid, tmp, value;
-
- gtk_adjustment_set_lower (tool->high_input, low);
- gtk_adjustment_set_lower (tool->gamma_linear, low);
-
- gtk_adjustment_set_upper (tool->low_input, high);
- gtk_adjustment_set_upper (tool->gamma_linear, high);
-
- levels_update_input_bar (tool);
-
- delta = (high - low) / 2.0;
- mid = low + delta;
- tmp = log10 (1.0 / config->gamma[config->channel]);
- value = mid + delta * tmp;
-
- gtk_adjustment_set_value (tool->gamma_linear, value);
- }
-}
-
-static void
levels_update_input_bar (GimpLevelsTool *tool)
{
GimpFilterTool *filter_tool = GIMP_FILTER_TOOL (tool);
diff --git a/app/tools/gimpthresholdtool.c b/app/tools/gimpthresholdtool.c
index e96460e..982bc55 100644
--- a/app/tools/gimpthresholdtool.c
+++ b/app/tools/gimpthresholdtool.c
@@ -45,7 +45,6 @@
/* local function prototypes */
-static void gimp_threshold_tool_constructed (GObject *object);
static void gimp_threshold_tool_finalize (GObject *object);
static gboolean gimp_threshold_tool_initialize (GimpTool *tool,
@@ -62,10 +61,9 @@ static gchar * gimp_threshold_tool_get_operation (GimpFilterTool *filter
gchar **import_dialog_title,
gchar **export_dialog_title);
static void gimp_threshold_tool_dialog (GimpFilterTool *filter_tool);
-
-static void gimp_threshold_tool_config_notify (GObject *object,
- GParamSpec *pspec,
- GimpThresholdTool *t_tool);
+static void gimp_threshold_tool_config_notify (GimpFilterTool *filter_tool,
+ GimpConfig *config,
+ const GParamSpec *pspec);
static gboolean gimp_threshold_tool_channel_sensitive
(gint value,
@@ -108,13 +106,13 @@ gimp_threshold_tool_class_init (GimpThresholdToolClass *klass)
GimpToolClass *tool_class = GIMP_TOOL_CLASS (klass);
GimpFilterToolClass *filter_tool_class = GIMP_FILTER_TOOL_CLASS (klass);
- object_class->constructed = gimp_threshold_tool_constructed;
object_class->finalize = gimp_threshold_tool_finalize;
tool_class->initialize = gimp_threshold_tool_initialize;
filter_tool_class->get_operation = gimp_threshold_tool_get_operation;
filter_tool_class->dialog = gimp_threshold_tool_dialog;
+ filter_tool_class->config_notify = gimp_threshold_tool_config_notify;
}
static void
@@ -124,16 +122,6 @@ gimp_threshold_tool_init (GimpThresholdTool *t_tool)
}
static void
-gimp_threshold_tool_constructed (GObject *object)
-{
- G_OBJECT_CLASS (parent_class)->constructed (object);
-
- g_signal_connect_object (GIMP_FILTER_TOOL (object)->config, "notify",
- G_CALLBACK (gimp_threshold_tool_config_notify),
- object, 0);
-}
-
-static void
gimp_threshold_tool_finalize (GObject *object)
{
GimpThresholdTool *t_tool = GIMP_THRESHOLD_TOOL (object);
@@ -295,10 +283,15 @@ gimp_threshold_tool_dialog (GimpFilterTool *filter_tool)
}
static void
-gimp_threshold_tool_config_notify (GObject *object,
- GParamSpec *pspec,
- GimpThresholdTool *t_tool)
+gimp_threshold_tool_config_notify (GimpFilterTool *filter_tool,
+ GimpConfig *config,
+ const GParamSpec *pspec)
{
+ GimpThresholdTool *t_tool = GIMP_THRESHOLD_TOOL (filter_tool);
+
+ GIMP_FILTER_TOOL_CLASS (parent_class)->config_notify (filter_tool,
+ config, pspec);
+
if (! t_tool->histogram_box)
return;
@@ -306,7 +299,7 @@ gimp_threshold_tool_config_notify (GObject *object,
{
GimpHistogramChannel channel;
- g_object_get (object,
+ g_object_get (config,
"channel", &channel,
NULL);
@@ -320,7 +313,7 @@ gimp_threshold_tool_config_notify (GObject *object,
gdouble high;
gint n_bins;
- g_object_get (object,
+ g_object_get (config,
"low", &low,
"high", &high,
NULL);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]