changeset 24648:1f1ac73910ab

respect sorting in variable editor (bug #51843) * workspace-view.h, workspace-view.cc (workspace_view::handle_contextmenu_edit): Use get_var_name to access variable name through sort model proxy pointer instead of accessing through m_model pointer. (workspace_view::get_var_name): Pass arg by const reference instead of value.
author John W. Eaton <jwe@octave.org>
date Mon, 29 Jan 2018 08:51:47 -0500
parents 41a87a2a8d38
children 456b486ae5e6
files libgui/src/workspace-view.cc libgui/src/workspace-view.h
diffstat 2 files changed, 13 insertions(+), 9 deletions(-) [+]
line wrap: on
line diff
--- a/libgui/src/workspace-view.cc	Sun Jan 28 10:05:45 2018 +0100
+++ b/libgui/src/workspace-view.cc	Mon Jan 29 08:51:47 2018 -0500
@@ -458,11 +458,7 @@
 
   if (index.isValid ())
     {
-      index = index.sibling (index.row (), 0);
-
-      QMap<int, QVariant> item_data = m_model->itemData (index);
-
-      QString var_name = item_data[0].toString ();
+      QString var_name = get_var_name (index);
 
       octave::symbol_scope scope = m_model->scope ();
 
@@ -541,11 +537,15 @@
 }
 
 QString
-workspace_view::get_var_name (QModelIndex index)
+workspace_view::get_var_name (const QModelIndex& index)
 {
-  index = index.sibling (index.row (), 0);
+  // We are using a sort model proxy so m_model won't provide the
+  // correct ordering.
+
   QAbstractItemModel *m = m_view->model ();
-  QMap<int, QVariant> item_data = m->itemData (index);
+
+  QMap<int, QVariant> item_data
+    = m->itemData (index.sibling (index.row (), 0));
 
   return item_data[0].toString ();
 }
--- a/libgui/src/workspace-view.h	Sun Jan 28 10:05:45 2018 +0100
+++ b/libgui/src/workspace-view.h	Mon Jan 29 08:51:47 2018 -0500
@@ -99,10 +99,14 @@
 
   void relay_contextmenu_command (const QString& cmdname);
 
-  QString get_var_name (QModelIndex index);
+  QString get_var_name (const QModelIndex& index);
 
   QTableView *m_view;
   int m_view_previous_row_count;
+
+  // We are using a sort model proxy so m_model won't provide the
+  // correct ordering.  It is still OK to use this pointer to access
+  // other info attached to the model, for example the scope or colors.
   workspace_model *m_model;
 
   QSortFilterProxyModel m_filter_model;