Fix overloading of "source" and "target" terminology in GBinding

GBindingTransformFunc called its arguments "source_value" and
"target_value", but in the transform_from function of a bidirectional
binding, "source_value" comes from the target object, and
"target_value" comes from the source object, which quickly gets
confusing if you need to use g_binding_get_source(), etc, in the
function.

Of course developers can call their transform function arguments
whatever they want, but many will copy from the headers/docs to start
out, so use less confusing names here ("from_value" and "to_value").

Also, fix the documentation to describe the bidirectional case
correctly.

https://bugzilla.gnome.org/show_bug.cgi?id=709440
This commit is contained in:
Dan Winship
2013-10-04 12:58:48 -04:00
parent be7f40185f
commit 8e17040c15
3 changed files with 44 additions and 41 deletions

View File

@@ -237,44 +237,44 @@ binding_target_init (BindingTarget *self)
static gboolean
celsius_to_fahrenheit (GBinding *binding,
const GValue *source_value,
GValue *target_value,
const GValue *from_value,
GValue *to_value,
gpointer user_data G_GNUC_UNUSED)
{
gdouble celsius, fahrenheit;
g_assert (G_VALUE_HOLDS (source_value, G_TYPE_DOUBLE));
g_assert (G_VALUE_HOLDS (target_value, G_TYPE_DOUBLE));
g_assert (G_VALUE_HOLDS (from_value, G_TYPE_DOUBLE));
g_assert (G_VALUE_HOLDS (to_value, G_TYPE_DOUBLE));
celsius = g_value_get_double (source_value);
celsius = g_value_get_double (from_value);
fahrenheit = (9 * celsius / 5) + 32.0;
if (g_test_verbose ())
g_print ("Converting %.2fC to %.2fF\n", celsius, fahrenheit);
g_value_set_double (target_value, fahrenheit);
g_value_set_double (to_value, fahrenheit);
return TRUE;
}
static gboolean
fahrenheit_to_celsius (GBinding *binding,
const GValue *source_value,
GValue *target_value,
const GValue *from_value,
GValue *to_value,
gpointer user_data G_GNUC_UNUSED)
{
gdouble celsius, fahrenheit;
g_assert (G_VALUE_HOLDS (source_value, G_TYPE_DOUBLE));
g_assert (G_VALUE_HOLDS (target_value, G_TYPE_DOUBLE));
g_assert (G_VALUE_HOLDS (from_value, G_TYPE_DOUBLE));
g_assert (G_VALUE_HOLDS (to_value, G_TYPE_DOUBLE));
fahrenheit = g_value_get_double (source_value);
fahrenheit = g_value_get_double (from_value);
celsius = 5 * (fahrenheit - 32.0) / 9;
if (g_test_verbose ())
g_print ("Converting %.2fF to %.2fC\n", fahrenheit, celsius);
g_value_set_double (target_value, celsius);
g_value_set_double (to_value, celsius);
return TRUE;
}