Mercurial > octave
changeset 31821:6bf833d96cbe
Allow querying of only one graphic object at a time with set().
This behavior is Matlab-compatible and Octave wasn't even implementing
the old behavior over multiple graphics handles correctly anyways.
* graphics.cc (Fset): Document that querying graphics properties
can only specify one graphics handle. Add input validation
for code to query graphics properties to check for a single handle.
Simplify code by removing for loop over graphics handles which is
no longer possible.
author | Rik <rik@octave.org> |
---|---|
date | Sat, 11 Feb 2023 09:57:47 -0800 |
parents | 3648ff642964 |
children | 3e4e74ad8fd7 |
files | libinterp/corefcn/graphics.cc |
diffstat | 1 files changed, 48 insertions(+), 48 deletions(-) [+] |
line wrap: on
line diff
--- a/libinterp/corefcn/graphics.cc Fri Feb 10 07:27:38 2023 -0500 +++ b/libinterp/corefcn/graphics.cc Sat Feb 11 09:57:47 2023 -0800 @@ -12156,7 +12156,10 @@ property. If no output variable is used then the list is formatted and printed to the screen. -For example, +When querying properties only a single graphics handle @var{h} for a single +graphics object is permitted. + +Example Query @example @group @@ -12189,64 +12192,61 @@ // Process requests for default value(s) if (nargin == 1) { - // Loop over graphics objects - for (octave_idx_type n = 0; n < hcv.numel (); n++) - { - graphics_object go = gh_mgr.get_object (hcv(n)); - - if (! go) - error ("set: invalid handle (= %g)", hcv(n)); - - if (nargout > 0) - retval = go.values_as_struct (); - else - { - std::string s = go.values_as_string (); - - octave_stdout << s; - } + if (hcv.numel () > 1) + error ("set: H must be a single graphics handle when querying properties"); + + graphics_object go = gh_mgr.get_object (hcv(0)); + if (! go) + error ("set: invalid handle (= %g)", hcv(0)); + + if (nargout > 0) + retval = go.values_as_struct (); + else + { + std::string s = go.values_as_string (); + + octave_stdout << s; } return retval; } else if (nargin == 2 && args(1).is_string ()) { + if (hcv.numel () > 1) + error ("set: H must be a single graphics handle when querying properties"); + std::string property = args(1).string_value (); std::transform (property.begin (), property.end (), property.begin (), tolower); - // Loop over graphics objects - for (octave_idx_type n = 0; n < hcv.numel (); n++) - { - graphics_object go = gh_mgr.get_object (hcv(n)); - - if (! go) - error ("set: invalid handle (= %g)", hcv(n)); - - octave_map pmap = go.values_as_struct (); - - if (go.has_readonly_property (property)) - { - if (nargout > 0) - retval = Matrix (); - else - octave_stdout << "set: " << property << " is read-only" - << std::endl; - } - else if (pmap.isfield (property)) - { - if (nargout != 0) - retval = pmap.getfield (property)(0); - else - { - std::string s = go.value_as_string (property); - - octave_stdout << s; - } - } + graphics_object go = gh_mgr.get_object (hcv(0)); + + if (! go) + error ("set: invalid handle (= %g)", hcv(0)); + + octave_map pmap = go.values_as_struct (); + + if (go.has_readonly_property (property)) + { + if (nargout > 0) + retval = Matrix (); else - error (R"(set: unknown property "%s")", property.c_str ()); - } + octave_stdout << "set: " << property << " is read-only" + << std::endl; + } + else if (pmap.isfield (property)) + { + if (nargout != 0) + retval = pmap.getfield (property)(0); + else + { + std::string s = go.value_as_string (property); + + octave_stdout << s; + } + } + else + error (R"(set: unknown property "%s")", property.c_str ()); return retval; }