Mercurial > octave
changeset 24657:dd19b0b9a9a1
allow empty strings to be edited (bug #51848)
* variable-editor-model.cc (get_rows_and_columns,
variable_editor_model::impl, variable_editor_model::type_is_editable):
Also allow empty strings.
* ov-base.h (octave_base_value::is_zero_by_zero): New function.
* ov-str-mat.cc (octave_char_matrix_str::edit_display):
Allow empty strings.
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Tue, 30 Jan 2018 22:50:09 -0500 |
parents | cd79f32fba85 |
children | e014e08f939f |
files | libgui/src/variable-editor-model.cc libinterp/octave-value/ov-base.h libinterp/octave-value/ov-str-mat.cc |
diffstat | 3 files changed, 36 insertions(+), 19 deletions(-) [+] |
line wrap: on
line diff
--- a/libgui/src/variable-editor-model.cc Wed Jan 31 01:38:53 2018 +0100 +++ b/libgui/src/variable-editor-model.cc Tue Jan 30 22:50:09 2018 -0500 @@ -83,8 +83,19 @@ static void get_rows_and_columns (const octave_value& val, int& rows, int& cols) { - rows = val.rows (); - cols = (val.is_string () ? 1 : val.columns ()); + if (val.is_string ()) + { + // VAL will either be "" or a char array with a single row. + // Either way, edit it as a single string. + + rows = 1; + cols = 1; + } + else + { + rows = val.rows (); + cols = val.columns (); + } } struct variable_editor_model::impl @@ -105,7 +116,7 @@ octave_value ov = cval(r,c); if ((ov.numel () == 1 && (ov.isnumeric () || ov.islogical ())) - || (ov.rows () == 1 && ov.is_string ())) + || (ov.is_string () && (ov.rows () == 1 || ov.isempty ()))) { m_data = QString::fromStdString (ov.edit_display (r, c)); @@ -183,7 +194,7 @@ octave_value ov = cval(r,c); - if (ov.rows () == 1) + if (ov.rows () == 1 || ov.is_zero_by_zero ()) return get_quote_char (ov); } @@ -832,7 +843,7 @@ { if (((val.isnumeric () || val.islogical () || val.iscell ()) && val.ndims () == 2) - || (val.is_string () && val.rows () == 1)) + || (val.is_string () && (val.rows () == 1 || val.is_zero_by_zero ()))) return true; if (display_error)
--- a/libinterp/octave-value/ov-base.h Wed Jan 31 01:38:53 2018 +0100 +++ b/libinterp/octave-value/ov-base.h Tue Jan 30 22:50:09 2018 -0500 @@ -357,6 +357,8 @@ bool isempty (void) const { return (dims ().any_zero ()); } + bool is_zero_by_zero (void) const { return dims().zero_by_zero (); } + virtual bool iscell (void) const { return false; } virtual bool iscellstr (void) const { return false; }
--- a/libinterp/octave-value/ov-str-mat.cc Wed Jan 31 01:38:53 2018 +0100 +++ b/libinterp/octave-value/ov-str-mat.cc Tue Jan 30 22:50:09 2018 -0500 @@ -278,24 +278,28 @@ } std::string -octave_char_matrix_str::edit_display (octave_idx_type i, octave_idx_type) const +octave_char_matrix_str::edit_display (octave_idx_type i, + octave_idx_type) const { - if (matrix.rows () == 1 && i == 0) + if (i == 0) { - std::string retval = string_value (); - - if (! is_sq_string ()) - retval = undo_string_escapes (retval); + if (rows () == 1) + { + std::string retval = string_value (); - return retval; + if (! is_sq_string ()) + retval = undo_string_escapes (retval); + + return retval; + } + else if (is_zero_by_zero ()) + return ""; } - else - { - std::string tname = type_name (); - dim_vector dv = matrix.dims (); - std::string dimstr = dv.str (); - return "[" + dimstr + " " + tname + "]"; - } + + std::string tname = type_name (); + dim_vector dv = matrix.dims (); + std::string dimstr = dv.str (); + return "[" + dimstr + " " + tname + "]"; } bool