[dia] Remove superfluous (redundant) fields from Property struct



commit c6ab2bf5f9de46e2dbf6aed831f365c3e7d0f5f9
Author: Hans Breuer <hans breuer org>
Date:   Mon Oct 11 00:02:42 2010 +0200

    Remove superfluous (redundant) fields from Property struct
    
    Quite some fields from Property were just mirrored from their
    PropDescription. They could be removed and their access be
    replaced by the extra lookup via Property::descr.

 app/find-and-replace.c           |    6 +++---
 lib/group.c                      |    6 +++---
 lib/prop_attr.c                  |    8 ++++----
 lib/prop_basic.c                 |    7 ++-----
 lib/prop_geomtypes.c             |    8 ++++----
 lib/prop_inttypes.c              |   18 +++++++++---------
 lib/prop_sdarray.c               |    2 +-
 lib/prop_text.c                  |    4 ++--
 lib/propdialogs.c                |    8 ++++----
 lib/properties.h                 |    3 ---
 lib/proplist.c                   |    6 +++---
 plug-ins/python/pydia-property.c |   20 ++++++++++----------
 12 files changed, 45 insertions(+), 51 deletions(-)
---
diff --git a/app/find-and-replace.c b/app/find-and-replace.c
index d260dc4..1185eae 100644
--- a/app/find-and-replace.c
+++ b/app/find-and-replace.c
@@ -156,7 +156,7 @@ _match_prop (DiaObject *obj, const SearchData *sd, const gchar *replacement, Pro
 
   /* TODO: We could probably speed this up by using the type_quark,
    *       but I don't know enough yet to use it safely... */
-  prop_type = prop->type;
+  prop_type = prop->descr->type;
   if (!prop_type)
     return FALSE;
 
@@ -236,11 +236,11 @@ _match_all_props (DiaObject *obj, const SearchData *sd, const gchar *replacement
     gboolean is_match = FALSE;
     const gchar *prop_name;
 
-    if (!prop || !prop->name)
+    if (!prop || !prop->descr->name)
       continue;
 
     /* This extra step seems to be necessary to populate the property data. */
-    prop_name = prop->name;
+    prop_name = prop->descr->name;
     prop->ops->free (prop);
     prop = object_prop_by_name (obj, prop_name);
 
diff --git a/lib/group.c b/lib/group.c
index 4b32994..ca1f5a7 100644
--- a/lib/group.c
+++ b/lib/group.c
@@ -563,7 +563,7 @@ group_prop_event_deliver(Group *group, Property *prop)
 
       /* I'm sorry. I haven't found a working less ugly solution :( */
       plist = obj->ops->describe_props(obj);
-      pdesc = prop_desc_list_find_prop(plist,prop->name);
+      pdesc = prop_desc_list_find_prop(plist,prop->descr->name);
       if (pdesc && pdesc->event_handler) {
         /* deliver */
         PropEventHandler hdl = prop_desc_find_real_handler(pdesc);
@@ -571,13 +571,13 @@ group_prop_event_deliver(Group *group, Property *prop)
           return hdl(obj,prop);
         } else {
           g_warning("dropped group event on prop %s, "
-                    "final handler was NULL",prop->name);
+                    "final handler was NULL",prop->descr->name);
           return FALSE;
         }
       }
     }
   }
-  g_warning("undelivered group property event for prop %s",prop->name); 
+  g_warning("undelivered group property event for prop %s",prop->descr->name); 
   return FALSE;
 }
 
diff --git a/lib/prop_attr.c b/lib/prop_attr.c
index 14e91ac..b407486 100644
--- a/lib/prop_attr.c
+++ b/lib/prop_attr.c
@@ -206,12 +206,12 @@ arrowprop_load(ArrowProperty *prop, AttributeNode attr, DataNode data)
   prop->arrow_data.width = DEFAULT_ARROW_SIZE;
   if (prop->arrow_data.type != ARROW_NONE) {
     ObjectNode obj_node = attr->parent;
-    gchar *str = g_strconcat(prop->common.name, "_length", NULL);
+    gchar *str = g_strconcat(prop->common.descr->name, "_length", NULL);
     if ((attr = object_find_attribute(obj_node, str)) &&
         (data = attribute_first_data(attr)))
       prop->arrow_data.length = data_real(data);
     g_free(str);
-    str = g_strconcat(prop->common.name, "_width", NULL);
+    str = g_strconcat(prop->common.descr->name, "_width", NULL);
     if ((attr = object_find_attribute(obj_node, str)) &&
         (data = attribute_first_data(attr)))
       prop->arrow_data.width = data_real(data);
@@ -225,11 +225,11 @@ arrowprop_save(ArrowProperty *prop, AttributeNode attr)
   data_add_enum(attr, prop->arrow_data.type);
   if (prop->arrow_data.type != ARROW_NONE) {
     ObjectNode obj_node = attr->parent;
-    gchar *str = g_strconcat(prop->common.name, "_length", NULL);
+    gchar *str = g_strconcat(prop->common.descr->name, "_length", NULL);
     attr = new_attribute(obj_node, str);
     g_free(str);
     data_add_real(attr, prop->arrow_data.length);
-    str = g_strconcat(prop->common.name, "_width", NULL);
+    str = g_strconcat(prop->common.descr->name, "_width", NULL);
     attr = new_attribute(obj_node, str);
     g_free(str);
     data_add_real(attr, prop->arrow_data.width);
diff --git a/lib/prop_basic.c b/lib/prop_basic.c
index 4d320aa..0f01530 100644
--- a/lib/prop_basic.c
+++ b/lib/prop_basic.c
@@ -199,21 +199,18 @@ void initialize_property(Property *prop, const PropDescription *pdesc,
                          PropDescToPropPredicate reason)
 {
   prop->reason = reason;
-  prop->name = pdesc->name;
   prop->name_quark = pdesc->quark;
   if (!prop->name_quark) {
-    prop->name_quark = g_quark_from_string(prop->name);
+    prop->name_quark = g_quark_from_string(prop->descr->name);
     g_error("%s: late quark construction for property %s",
-            G_STRFUNC,prop->name);
+            G_STRFUNC,prop->descr->name);
   }
-  prop->type = pdesc->type;
   prop->type_quark = pdesc->type_quark;
   prop->ops = &commonprop_ops;
   prop->real_ops = pdesc->ops;
   /* if late quark construction, we'll have NULL here */
   prop->descr = pdesc;
   prop->reason = reason;
-  prop->extra_data = pdesc->extra_data;
   /* prop->self remains 0 until we get a widget from this. */
   prop->event_handler = pdesc->event_handler;
 
diff --git a/lib/prop_geomtypes.c b/lib/prop_geomtypes.c
index 1a8162b..407a693 100644
--- a/lib/prop_geomtypes.c
+++ b/lib/prop_geomtypes.c
@@ -82,8 +82,8 @@ static void
 realprop_reset_widget(RealProperty *prop, WIDGET *widget)
 {
   GtkAdjustment *adj;
-  if (prop->common.extra_data) {
-    PropNumData *numdata = prop->common.extra_data;
+  if (prop->common.descr->extra_data) {
+    PropNumData *numdata = prop->common.descr->extra_data;
     adj = GTK_ADJUSTMENT(gtk_adjustment_new(prop->real_data,
                                             numdata->min, numdata->max,
                                             numdata->step, 
@@ -316,7 +316,7 @@ fontsizeprop_set_from_widget(FontsizeProperty *prop, WIDGET *widget)
 static void 
 fontsizeprop_load(FontsizeProperty *prop, AttributeNode attr, DataNode data)
 {
-  PropNumData *numdata = prop->common.extra_data;
+  PropNumData *numdata = prop->common.descr->extra_data;
   real value = data_real(data);
 
   if (numdata) {
@@ -345,7 +345,7 @@ static void
 fontsizeprop_set_from_offset(FontsizeProperty *prop,
                          void *base, guint offset, guint offset2)
 {
-  PropNumData *numdata = prop->common.extra_data;
+  PropNumData *numdata = prop->common.descr->extra_data;
   real value = prop->fontsize_data;
 
   if (numdata) {
diff --git a/lib/prop_inttypes.c b/lib/prop_inttypes.c
index 856a0f7..5416df2 100644
--- a/lib/prop_inttypes.c
+++ b/lib/prop_inttypes.c
@@ -94,7 +94,7 @@ charprop_load(CharProperty *prop, AttributeNode attr, DataNode data)
     g_free(str);
   } else {
     g_warning("Could not read character data for attribute %s", 
-              prop->common.name);
+              prop->common.descr->name);
   }
 }
 
@@ -292,8 +292,8 @@ static void
 intprop_reset_widget(IntProperty *prop, WIDGET *widget)
 {
   GtkAdjustment *adj;
-  if (prop->common.extra_data) {
-    PropNumData *numdata = prop->common.extra_data;
+  if (prop->common.descr->extra_data) {
+    PropNumData *numdata = prop->common.descr->extra_data;
     adj = GTK_ADJUSTMENT(gtk_adjustment_new(prop->int_data,
                                             numdata->min, numdata->max,
                                             numdata->step, 10.0 * numdata->step, 0));
@@ -486,8 +486,8 @@ enumprop_get_widget(EnumProperty *prop, PropDialog *dialog)
 { 
   GtkWidget *ret;
 
-  if (prop->common.extra_data) {
-    PropEnumData *enumdata = prop->common.extra_data;
+  if (prop->common.descr->extra_data) {
+    PropEnumData *enumdata = prop->common.descr->extra_data;
     guint i;
 
     ret = gtk_combo_box_new_text ();
@@ -503,8 +503,8 @@ enumprop_get_widget(EnumProperty *prop, PropDialog *dialog)
 static void 
 enumprop_reset_widget(EnumProperty *prop, WIDGET *widget)
 {
-  if (prop->common.extra_data) {
-    PropEnumData *enumdata = prop->common.extra_data;
+  if (prop->common.descr->extra_data) {
+    PropEnumData *enumdata = prop->common.descr->extra_data;
     guint i, pos = 0;
 
     for (i = 0; enumdata[i].name != NULL; i++) {
@@ -526,7 +526,7 @@ enumprop_set_from_widget(EnumProperty *prop, WIDGET *widget)
 {
   if (GTK_IS_COMBO_BOX (widget)) {
     guint pos = gtk_combo_box_get_active (GTK_COMBO_BOX (widget));
-    PropEnumData *enumdata = prop->common.extra_data;
+    PropEnumData *enumdata = prop->common.descr->extra_data;
     
     g_return_if_fail (enumdata != NULL);
     
@@ -544,7 +544,7 @@ enumprop_load(EnumProperty *prop, AttributeNode attr, DataNode data)
     prop->enum_data = data_enum(data);
   else if (DATATYPE_INT == dt) {
     gboolean cast_ok = FALSE;
-    PropEnumData *enumdata = prop->common.extra_data;
+    PropEnumData *enumdata = prop->common.descr->extra_data;
     guint i, v = data_int(data);
     for (i = 0; enumdata[i].name != NULL; ++i) {
       if (v == enumdata[i].enumv) {
diff --git a/lib/prop_sdarray.c b/lib/prop_sdarray.c
index 9ac924a..9189c6f 100644
--- a/lib/prop_sdarray.c
+++ b/lib/prop_sdarray.c
@@ -100,7 +100,7 @@ arrayprop_load(ArrayProperty *prop, AttributeNode attr, DataNode data)
     GPtrArray *record = prop_list_from_descs(extra->record,
                                              prop->common.reason);
     if (!prop_list_load(record,composite, &err)) {
-      g_warning ("%s:%s", prop->common.name, err->message);
+      g_warning ("%s:%s", prop->common.descr->name, err->message);
       g_error_free (err);
       err = NULL;
     }
diff --git a/lib/prop_text.c b/lib/prop_text.c
index 4540c7a..0542a28 100644
--- a/lib/prop_text.c
+++ b/lib/prop_text.c
@@ -157,8 +157,8 @@ static GtkWidget *
 fileprop_get_widget(StringProperty *prop, PropDialog *dialog) 
 { 
   GtkWidget *ret = dia_file_selector_new();
-  if (prop->common.extra_data)
-    dia_file_selector_set_extensions (DIAFILESELECTOR(ret), prop->common.extra_data);
+  if (prop->common.descr->extra_data)
+    dia_file_selector_set_extensions (DIAFILESELECTOR(ret), prop->common.descr->extra_data);
   prophandler_connect(&prop->common, G_OBJECT(ret), "value-changed");
   return ret;
 }
diff --git a/lib/propdialogs.c b/lib/propdialogs.c
index 18dcf1b..9215af3 100644
--- a/lib/propdialogs.c
+++ b/lib/propdialogs.c
@@ -185,7 +185,7 @@ property_signal_handler(GtkObject *obj,
 	return;
 
     /* g_message("Received a signal for object %s from property %s",
-       obj->type->name,prop->name); */
+       obj->type->name,prop->descr->name); */
 
     /* obj is a scratch object ; we can do what we want with it. */
     prop_get_data_from_widgets(dialog);
@@ -214,7 +214,7 @@ prophandler_connect(const Property *prop,
 {
   if (0==strcmp(signal,"FIXME")) {
     g_warning("signal type unknown for this kind of property (name is %s), \n"
-              "handler ignored.",prop->name);
+              "handler ignored.",prop->descr->name);
     return;
   } 
 
@@ -332,7 +332,7 @@ _prop_list_extend_for_meta (GPtrArray *props)
   Property *p = g_ptr_array_index(props,0);
   GPtrArray *pex = prop_list_from_descs(extras,pdtpp_is_visible);
 
-  if (strcmp (p->type, PROP_TYPE_NOTEBOOK_BEGIN) != 0) {
+  if (strcmp (p->descr->type, PROP_TYPE_NOTEBOOK_BEGIN) != 0) {
     int i, olen = props->len;
     /* wrap everything into a first notebook page */
     g_ptr_array_set_size (props, olen + 2);
@@ -343,7 +343,7 @@ _prop_list_extend_for_meta (GPtrArray *props)
     g_ptr_array_index (props, 1) = g_ptr_array_index (pex, 1);
   } else {
     p = g_ptr_array_index (props, props->len - 1);
-    g_assert (strcmp (p->type, PROP_TYPE_NOTEBOOK_END) == 0);
+    g_assert (strcmp (p->descr->type, PROP_TYPE_NOTEBOOK_END) == 0);
     /* drop the end, we'll add it again below */
     g_ptr_array_set_size (props, props->len - 1);
   }
diff --git a/lib/properties.h b/lib/properties.h
index 6f55e0c..4d8d97a 100644
--- a/lib/properties.h
+++ b/lib/properties.h
@@ -282,12 +282,9 @@ struct  _PropDescSArrayExtra {
 /* The Property itself */
 /* ******************* */ 
 struct _Property {
-  const gchar *name;
   GQuark name_quark; 
-  PropertyType type;
   GQuark type_quark;
   const PropDescription *descr;
-  gpointer extra_data;
   PropEventData self;
   PropEventHandler event_handler;
   PropDescToPropPredicate reason; /* why has this property been created from
diff --git a/lib/proplist.c b/lib/proplist.c
index d048218..8bbe577 100644
--- a/lib/proplist.c
+++ b/lib/proplist.c
@@ -150,7 +150,7 @@ prop_list_load(GPtrArray *props, DataNode data, GError **err)
 
   for (i = 0; i < props->len; i++) {
     Property *prop = g_ptr_array_index(props,i);
-    AttributeNode attr = object_find_attribute(data, prop->name);
+    AttributeNode attr = object_find_attribute(data, prop->descr->name);
     DataNode data = attr ? attribute_first_data(attr) : NULL;
     if ((!attr || !data) && prop->descr->flags & PROP_FLAG_OPTIONAL) {
       prop->experience |= PXP_NOTSET;
@@ -161,7 +161,7 @@ prop_list_load(GPtrArray *props, DataNode data, GError **err)
 	*err = g_error_new (DIA_ERROR,
                             DIA_ERROR_FORMAT,
 			    _("No attribute '%s' (%p) or no data (%p) in this attribute"),
-			    prop->name,attr,data);
+			    prop->descr->name,attr,data);
       prop->experience |= PXP_NOTSET;
       ret = FALSE;
       continue;
@@ -177,7 +177,7 @@ prop_list_save(GPtrArray *props, DataNode data)
   int i;
   for (i = 0; i < props->len; i++) {
     Property *prop = g_ptr_array_index(props,i);
-    AttributeNode attr = new_attribute(data,prop->name);
+    AttributeNode attr = new_attribute(data,prop->descr->name);
     prop->ops->save(prop,attr);
   }
 }
diff --git a/plug-ins/python/pydia-property.c b/plug-ins/python/pydia-property.c
index d1fd7fd..ef723e6 100644
--- a/plug-ins/python/pydia-property.c
+++ b/plug-ins/python/pydia-property.c
@@ -658,7 +658,7 @@ PyDia_set_Array (Property *prop, PyObject *val)
 	setters[i] = (PyDiaPropSetFunc)prop_type_map[j].propset;
     }
     if (!setters[i]) {
-      g_debug("No setter for '%s'", ex->type);
+      g_debug("No setter for '%s'", ex->descr->type);
       g_free(setters);
       return -1;
     }
@@ -697,7 +697,7 @@ PyDia_set_Array (Property *prop, PyObject *val)
             /* use just the defaults, setters don't need to handle this */
 	  } else {
 	    g_debug ("Failed to set '%s::%s' from '%s'", 
-	      p->common.name, inner->name, v->ob_type->tp_name);
+	      p->common.descr->name, inner->descr->name, v->ob_type->tp_name);
 	    inner->ops->free(inner);
 	    ret = -1;
 	    break;
@@ -772,9 +772,9 @@ PyDiaProperty_GetAttr(PyDiaProperty *self, gchar *attr)
   if (!strcmp(attr, "__members__"))
     return Py_BuildValue("[ssss]", "name", "type", "value", "visible");
   else if (!strcmp(attr, "name"))
-    return PyString_FromString(self->property->name);
+    return PyString_FromString(self->property->descr->name);
   else if (!strcmp(attr, "type"))
-    return PyString_FromString(self->property->type);
+    return PyString_FromString(self->property->descr->type);
   else if (!strcmp(attr, "visible"))
     return PyInt_FromLong(0 != (self->property->descr->flags & PROP_FLAG_VISIBLE));
   else if (!strcmp(attr, "value")) {
@@ -785,7 +785,7 @@ PyDiaProperty_GetAttr(PyDiaProperty *self, gchar *attr)
       if (prop_type_map[i].quark == self->property->type_quark)
         return prop_type_map[i].propget(self->property);
     if (0 == (PROP_FLAG_WIDGET_ONLY & self->property->descr->flags))
-      g_debug ("No handler for type '%s'", self->property->type);
+      g_debug ("No handler for type '%s'", self->property->descr->type);
 
     Py_INCREF(Py_None);
     return Py_None;
@@ -810,7 +810,7 @@ int PyDiaProperty_ApplyToObject (DiaObject   *object,
     /* must be a Property object ? Or PyDiaRect etc ? */
     Property* inprop = ((PyDiaProperty*)val)->property;
 
-    if (0 == strcmp (prop->type, inprop->type)) {
+    if (0 == strcmp (prop->descr->type, inprop->descr->type)) {
       GPtrArray *plist;
       /* apply it */
       prop->ops->free (prop); /* release this one */
@@ -822,7 +822,7 @@ int PyDiaProperty_ApplyToObject (DiaObject   *object,
       return 0;
     } else {
       g_debug("PyDiaProperty_ApplyToObject : no property conversion %s -> %s",
-	             inprop->type, prop->type);
+	             inprop->descr->type, prop->descr->type);
     }
   } else {
     int i;
@@ -838,7 +838,7 @@ int PyDiaProperty_ApplyToObject (DiaObject   *object,
     }
     if (ret != 0)
       g_debug("PyDiaProperty_ApplyToObject : no conversion %s -> %s",
-	             key, prop->type);
+	             key, prop->descr->type);
   }
 
   if (0 == ret) {
@@ -862,8 +862,8 @@ PyDiaProperty_Str(PyDiaProperty *self)
 
   s = g_strdup_printf("<DiaProperty at %p, \"%s\", %s>",
                       self,
-                      self->property->name,
-                      self->property->type);
+                      self->property->descr->name,
+                      self->property->descr->type);
 
   py_s = PyString_FromString(s);
   g_free (s);



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]