Mercurial > hg > octave-nkf
changeset 15760:1ac3c906990a
graphics.cc (graphics_object::set (const octave_map& m)): set structure
property/value in the order in which they were originally stored. Add test.
author | Pantxo Diribarne <pantxo.diribarne@gmail.com> |
---|---|
date | Sun, 09 Dec 2012 13:01:53 -0500 |
parents | b0ad083e1958 |
children | 9f3656ada658 |
files | libinterp/interpfcn/graphics.cc |
diffstat | 1 files changed, 32 insertions(+), 7 deletions(-) [+] |
line wrap: on
line diff
--- a/libinterp/interpfcn/graphics.cc +++ b/libinterp/interpfcn/graphics.cc @@ -2045,13 +2045,12 @@ void graphics_object::set (const octave_map& m) { - for (octave_map::const_iterator p = m.begin (); - p != m.end (); p++) - { - caseless_str name = m.key (p); - - octave_value val = octave_value (m.contents (p).elem (m.numel () - 1)); - + for (octave_idx_type p = 0; p < m.nfields (); p++) + { + caseless_str name = m.keys ()[p]; + + octave_value val = octave_value (m.contents (name).elem (m.numel () - 1)); + set_value_or_default (name, val); if (error_state) @@ -2070,6 +2069,32 @@ %! h = plot (1:10, 10:-1:1, 1:10, 1:10); %! set (h, struct ("linewidth", {5, 10})); %! assert (get (h, "linewidth"), {10; 10}); +## test ordering +%!test +%! markchanged = @(h, foobar, name) set (h, "userdata", [get(h,"userdata"); {name}]); +%! figure (1, "visible", "off") +%! clf () +%! h = line (); +%! set (h, "userdata", {}) +%! addlistener (h, "color", {markchanged, "color"}) +%! addlistener (h, "linewidth", {markchanged, "linewidth"}) +%! # "linewidth" first +%! props.linewidth = 2; +%! props.color = "r"; +%! set (h, props); +%! assert (get (h, "userdata"), fieldnames (props)) +%! clear props +%! clf () +%! h = line (); +%! set (h, "userdata", {}) +%! addlistener (h, "color", {markchanged, "color"}) +%! addlistener (h, "linewidth", {markchanged, "linewidth"}) +%! # "color" first +%! props.color = "r"; +%! props.linewidth = 2; +%! set (h, props); +%! assert (get (h, "userdata"), fieldnames (props)) +%! close (1) */ // Set a property to a value or to its (factory) default value.