changeset 24748:2ae7119e7cdc

display more precision when editing values in variable editor Double clicking a cell in the variable editor to enter edit mode now displays more digits of precision for floating point numerical values than the default display. * pr-flt-fmt.h (float_display_format::set_precision): New function. * variable-editor-model.h, variable-editor-model.cc (base_ve_model::edit_display_sub): New arg, role. Set format for the given element rather than using the overall format of the object containing this sub element. If role is Qt::EditRole, set display precision directly. (base_ve_model::edit_display): New arg, role. If role is Qt::EditRole, set display precision directly. (base_ve_model::data): Pass role to edit_display. (numeric_model::edit_display, string_model::edit_display, cell_model::edit_display, scalar_struct_model::edit_display, display_only_model::edit_display, vector_struct_model::edit_display, struct_model::edit_display): New arg, role.
author John W. Eaton <jwe@octave.org>
date Tue, 13 Feb 2018 13:24:16 -0500
parents 6114be517240
children 82c3ae6145b5
files libgui/src/variable-editor-model.cc libgui/src/variable-editor-model.h libinterp/corefcn/pr-flt-fmt.h
diffstat 3 files changed, 52 insertions(+), 19 deletions(-) [+]
line wrap: on
line diff
--- a/libgui/src/variable-editor-model.cc	Tue Feb 13 13:09:45 2018 -0500
+++ b/libgui/src/variable-editor-model.cc	Tue Feb 13 13:24:16 2018 -0500
@@ -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 13:09:45 2018 -0500
+++ b/libgui/src/variable-editor-model.h	Tue Feb 13 13:24:16 2018 -0500
@@ -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 13:09:45 2018 -0500
+++ b/libinterp/corefcn/pr-flt-fmt.h	Tue Feb 13 13:24:16 2018 -0500
@@ -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;