Mercurial > octave
changeset 24750:82c3ae6145b5
merge away extra head
author | Torsten <mttl@mailbox.org> |
---|---|
date | Tue, 13 Feb 2018 19:36:38 +0100 |
parents | 4aa86466f971 (current diff) 2ae7119e7cdc (diff) |
children | 6e670c58c6f0 |
files | |
diffstat | 3 files changed, 52 insertions(+), 19 deletions(-) [+] |
line wrap: on
line diff
--- a/libgui/src/variable-editor-model.cc Tue Feb 13 19:12:27 2018 +0100 +++ b/libgui/src/variable-editor-model.cc Tue Feb 13 19:36:38 2018 +0100 @@ -154,12 +154,21 @@ } QString -base_ve_model::edit_display_sub (const octave_value& elt) const +base_ve_model::edit_display_sub (const octave_value& elt, int role) const { std::string str; if (cell_is_editable (elt)) - str = elt.edit_display (m_display_fmt, 0, 0); + { + float_display_format fmt; + + if (role == Qt::DisplayRole) + fmt = get_edit_display_format (elt); + else + fmt.set_precision (elt.is_single_type () ? 8 : 16); + + str = elt.edit_display (fmt, 0, 0); + } else { dim_vector dv = elt.dims (); @@ -170,7 +179,7 @@ } QVariant -base_ve_model::edit_display (const QModelIndex& idx) const +base_ve_model::edit_display (const QModelIndex& idx, int role) const { int row; int col; @@ -178,7 +187,14 @@ if (! index_ok (idx, row, col)) return QVariant (); - std::string str = m_value.edit_display (m_display_fmt, row, col); + float_display_format fmt; + if (role == Qt::DisplayRole) + fmt = m_display_fmt; + else + fmt.set_precision (m_value.is_single_type () ? 8 : 16); + + std::string str = m_value.edit_display (fmt, row, col); + return QString::fromStdString (str); } @@ -201,7 +217,8 @@ { case Qt::DisplayRole: case Qt::EditRole: - return edit_display (idx); + return edit_display (idx, role); + return edit_display (idx, role); #if 0 case Qt::StatusTipRole: @@ -325,7 +342,7 @@ numeric_model& operator = (const numeric_model&) = delete; - QVariant edit_display (const QModelIndex& idx) const + QVariant edit_display (const QModelIndex& idx, int role) const { int row; int col; @@ -333,7 +350,14 @@ if (! index_ok (idx, row, col)) return QVariant (); - std::string str = m_value.edit_display (m_display_fmt, row, col); + float_display_format fmt; + if (role == Qt::DisplayRole) + fmt = m_display_fmt; + else + fmt.set_precision (m_value.is_single_type () ? 8 : 16); + + std::string str = m_value.edit_display (fmt, row, col); + return QString::fromStdString (str); } @@ -370,9 +394,12 @@ string_model& operator = (const string_model&) = delete; - QVariant edit_display (const QModelIndex&) const + QVariant edit_display (const QModelIndex&, int) const { - std::string str = m_value.edit_display (m_display_fmt, 0, 0); + // There isn't really a format for strings... + + std::string str = m_value.edit_display (float_display_format (), 0, 0); + return QString::fromStdString (str); } @@ -404,7 +431,7 @@ cell_model& operator = (const cell_model&) = delete; - QVariant edit_display (const QModelIndex& idx) const + QVariant edit_display (const QModelIndex& idx, int role) const { int row; int col; @@ -414,7 +441,7 @@ Cell cval = m_value.cell_value (); - return edit_display_sub (cval(row,col)); + return edit_display_sub (cval(row,col), role); } bool requires_sub_editor (const QModelIndex& idx) const @@ -493,7 +520,7 @@ scalar_struct_model& operator = (const scalar_struct_model&) = delete; - QVariant edit_display (const QModelIndex& idx) const + QVariant edit_display (const QModelIndex& idx, int role) const { int row; int col; @@ -503,7 +530,7 @@ octave_scalar_map m = m_value.scalar_map_value (); - return edit_display_sub (m.contents (row)); + return edit_display_sub (m.contents (row), role); } bool requires_sub_editor (const QModelIndex& idx) const @@ -612,7 +639,7 @@ bool is_editable (void) const { return false; } - QVariant edit_display (const QModelIndex&) const + QVariant edit_display (const QModelIndex&, int) const { if (m_value.is_undefined ()) return QVariant (); @@ -661,7 +688,7 @@ vector_struct_model& operator = (const vector_struct_model&) = delete; - QVariant edit_display (const QModelIndex& idx) const + QVariant edit_display (const QModelIndex& idx, int role) const { int row; int col; @@ -673,7 +700,7 @@ Cell cval = m.contents (col); - return edit_display_sub (cval(row)); + return edit_display_sub (cval(row), role); } bool requires_sub_editor (const QModelIndex& idx) const @@ -782,7 +809,7 @@ struct_model& operator = (const struct_model&) = delete; - QVariant edit_display (const QModelIndex& idx) const + QVariant edit_display (const QModelIndex& idx, int) const { int row; int col;
--- a/libgui/src/variable-editor-model.h Tue Feb 13 19:12:27 2018 +0100 +++ b/libgui/src/variable-editor-model.h Tue Feb 13 19:36:38 2018 +0100 @@ -61,9 +61,9 @@ int columnCount (const QModelIndex& = QModelIndex ()) const; - QString edit_display_sub (const octave_value& elt) const; + QString edit_display_sub (const octave_value& elt, int role) const; - virtual QVariant edit_display (const QModelIndex& idx) const; + virtual QVariant edit_display (const QModelIndex& idx, int role) const; QVariant data (const QModelIndex& idx, int role = Qt::DisplayRole) const;
--- a/libinterp/corefcn/pr-flt-fmt.h Tue Feb 13 19:12:27 2018 +0100 +++ b/libinterp/corefcn/pr-flt-fmt.h Tue Feb 13 19:36:38 2018 +0100 @@ -155,6 +155,12 @@ float_format imag_format (void) const { return m_imag_fmt; } + void set_precision (int prec) + { + m_real_fmt.prec = prec; + m_imag_fmt.prec = prec; + } + private: float_format m_real_fmt;