changeset 19700:e7df12f37f71

Freset: avoid multiple reseting of properties (bug #43960) * graphics.in.h (base_graphics_object::get_defaults_list): new method * graphics.in.h (base_graphics_object::build_user_defaults_map): declare new method * graphics.in.h (graphics_object::get_defaults_list): new method * graphics.in.h (graphics_object::build_user_defaults_map): new method * graphics.in.h (root_figure::get_defaults_list, figure::get_defaults_list, axes::get_defaults_list, uitoolbar::get_defaults_list): new methods * graphics.cc (base_graphics_object::build_user_defaults_map): build a list of all local and ancestor defaults. * graphics.cc (xreset_default_properties): use build_user_defaults_map method to replace factory defaults by those defined in user defaults map * graphics.cc (base_graphics_object::reset_default_properties, root_figure::reset_default_properties, figure::reset_default_properties): remove override_default.
author Pantxo Diribarne <pantxo.diribarne@gmail.com>
date Sat, 07 Feb 2015 15:41:48 +0100
parents 409d82472aee
children 4b1a43786489
files libinterp/corefcn/graphics.cc libinterp/corefcn/graphics.in.h
diffstat 2 files changed, 80 insertions(+), 13 deletions(-) [+]
line wrap: on
line diff
--- a/libinterp/corefcn/graphics.cc	Fri Feb 06 23:15:14 2015 -0500
+++ b/libinterp/corefcn/graphics.cc	Sat Feb 07 15:41:48 2015 +0100
@@ -2787,8 +2787,19 @@
 {
   graphics_object obj = gh_manager::get_object (gh);
 
+  // Replace factory defaults by user defined ones
+  std::string go_name = obj.get_properties ().graphics_object_name ();
   property_list::pval_map_type pval;
-
+  obj.build_user_defaults_map (pval, go_name);
+
+  for (property_list::pval_map_const_iterator p = pval.begin ();
+       p != pval.end (); p++)
+    {
+      factory_pval[p->first] = p->second;
+    }
+
+
+  // Reset defaults
   for (property_list::pval_map_const_iterator it = factory_pval.begin ();
        it != factory_pval.end (); it++)
     {
@@ -3160,6 +3171,32 @@
     }
 }
 
+void 
+base_graphics_object::build_user_defaults_map (property_list::pval_map_type &def, const std::string go_name) const
+{
+  property_list local_defaults = get_defaults_list ();
+  property_list::plist_map_const_iterator p = 
+    local_defaults.find (go_name);
+  
+  if (p != local_defaults.end ())
+    {
+      property_list::pval_map_type pval = p->second;
+      for (property_list::pval_map_const_iterator q = pval.begin ();
+           q != pval.end (); q++)
+        {
+          std::string pname = q->first;
+          if (def.find (pname) == def.end ())
+            def[pname] = q->second;
+        }
+    }
+
+  graphics_object parent_obj = gh_manager::get_object (get_parent ());
+
+  if (parent_obj)
+    parent_obj.build_user_defaults_map (def, go_name);
+
+}
+
 void
 base_graphics_object::reset_default_properties (void)
   {
@@ -3170,8 +3207,6 @@
           .find (type ())->second;
 
         xreset_default_properties (get_handle (), factory_pval);
-
-        override_defaults (*this);
       }
   }
 
@@ -4568,14 +4603,8 @@
   plist.erase ("paperunits");
   plist.erase ("paperposition");
   plist.erase ("windowstyle");
+
   xreset_default_properties (get_handle (), plist);
-
-  // FIXME: the following short sleep is needed in order
-  //        to avoid a crash when using qt toolkit
-  Fsleep (octave_value (0.001));
-
-  // override with parents' defaults
-  override_defaults (*this);
 }
 
 // ---------------------------------------------------------------------
@@ -8968,9 +8997,6 @@
 
   xreset_default_properties (get_handle (),
                              xproperties.factory_defaults ());
-
-  // override with parents' defaults
-  override_defaults (*this);
 }
 
 // ---------------------------------------------------------------------
--- a/libinterp/corefcn/graphics.in.h	Fri Feb 06 23:15:14 2015 -0500
+++ b/libinterp/corefcn/graphics.in.h	Sat Feb 07 15:41:48 2015 +0100
@@ -2704,6 +2704,9 @@
     else
       error ("base_graphics_object::override_defaults: invalid graphics object");
   }
+  
+  void build_user_defaults_map (property_list::pval_map_type &def,
+                                const std::string go_name) const;
 
   virtual void set_from_list (property_list& plist)
   {
@@ -2757,6 +2760,13 @@
     error ("base_graphics_object::get_defaults: invalid graphics object");
     return octave_value ();
   }
+  
+  virtual property_list get_defaults_list (void) const
+  {
+    if (! valid_object ())
+      error ("base_graphics_object::get_defaults_list: invalid graphics object");
+    return property_list ();
+  }
 
   virtual octave_value get_factory_defaults (void) const
   {
@@ -2983,6 +2993,12 @@
     rep->override_defaults (obj);
   }
 
+  void build_user_defaults_map (property_list::pval_map_type &def,
+                                const std::string go_name) const
+  {
+    rep->build_user_defaults_map (def, go_name);
+  }
+
   void set_from_list (property_list& plist) { rep->set_from_list (plist); }
 
   void set (const caseless_str& name, const octave_value& val)
@@ -3034,6 +3050,11 @@
 
   octave_value get_defaults (void) const { return rep->get_defaults (); }
 
+  property_list get_defaults_list (void) const
+  {
+    return rep->get_defaults_list ();
+  }
+
   octave_value get_factory_defaults (void) const
   {
     return rep->get_factory_defaults ();
@@ -3288,6 +3309,11 @@
     return default_properties.as_struct ("default");
   }
 
+  property_list get_defaults_list (void) const
+  {
+    return default_properties;
+  }
+
   octave_value get_factory_defaults (void) const
   {
     return factory_properties.as_struct ("factory");
@@ -3544,6 +3570,11 @@
     return default_properties.as_struct ("default");
   }
 
+  property_list get_defaults_list (void) const
+  {
+    return default_properties;
+  }
+
   base_properties& get_properties (void) { return xproperties; }
 
   const base_properties& get_properties (void) const { return xproperties; }
@@ -4283,6 +4314,11 @@
     return default_properties.as_struct ("default");
   }
 
+  property_list get_defaults_list (void) const
+  {
+    return default_properties;
+  }
+
   base_properties& get_properties (void) { return xproperties; }
 
   const base_properties& get_properties (void) const { return xproperties; }
@@ -5595,6 +5631,11 @@
     return default_properties.as_struct ("default");
   }
 
+  property_list get_defaults_list (void) const
+  {
+    return default_properties;
+  }
+
   base_properties& get_properties (void) { return xproperties; }
 
   const base_properties& get_properties (void) const { return xproperties; }