changeset 33508:1d0365c531a1

workspace view column width only stored by header state (bug #65030) * gui-preferences-ws.h: remove obsolete settings keys * workspace-view.cc (workspace_view::workspace_view): initialize new class variable, do not restore header state here; (workspace_view::notice_settings): save current header state if it is not the first run where the header would be the default one, do not read column visibility from settings file, restore header state after other settings are updated; (workspace_view::header_contextmenu_requested): get column visibility from QTableView, not from settings; (workspace_view::toggle_header): toggle current visibility, which is determined from QTableView, not from settings; * workspace-view.h: new class variable m_first
author Torsten Lilge <ttl-octave@mailbox.org>
date Thu, 02 May 2024 06:44:38 +0200
parents c8a91da569ac
children d3effbb99fa3
files libgui/src/gui-preferences-ws.h libgui/src/workspace-view.cc libgui/src/workspace-view.h
diffstat 3 files changed, 23 insertions(+), 31 deletions(-) [+]
line wrap: on
line diff
--- a/libgui/src/gui-preferences-ws.h	Wed May 01 22:14:17 2024 -0400
+++ b/libgui/src/gui-preferences-ws.h	Thu May 02 06:44:38 2024 +0200
@@ -54,14 +54,6 @@
   QT_TRANSLATE_NOOP ("octave::workspace_view", "Attribute")
 };
 
-const QStringList ws_columns_shown_keys =
-{
-  "workspaceview/show_class",
-  "workspaceview/show_dimension",
-  "workspaceview/show_value",
-  "workspaceview/show_attribute"
-};
-
 extern gui_pref ws_max_filter_history;
 
 extern gui_pref ws_color_mode;
--- a/libgui/src/workspace-view.cc	Wed May 01 22:14:17 2024 -0400
+++ b/libgui/src/workspace-view.cc	Thu May 02 06:44:38 2024 +0200
@@ -53,7 +53,8 @@
     m_view (new QTableView (this)),
     m_filter_checkbox (new QCheckBox ()),
     m_filter (new QComboBox (this)),
-    m_filter_widget (new QWidget (this))
+    m_filter_widget (new QWidget (this)),
+    m_first (true)
 {
   set_title (tr ("Workspace"));
   setStatusTip (tr ("View the variables in the active workspace."));
@@ -149,13 +150,6 @@
 
   if (! p)
     make_window ();
-
-  // Initialize column order and width of the workspace. From this post,
-  // https://www.qtcentre.org/threads/26675-QTableView-saving-restoring-columns-widths
-  // this might fail if done directly in the constructor. This effect shows
-  // up in the GUI since Qt 6.6.x. As a solution, the following timer ensures
-  // that the header is restored when the event loop is idle.
-  QTimer::singleShot (0, this, SLOT(restore_header_state ()));
 }
 
 void
@@ -194,10 +188,17 @@
 {
   gui_settings settings;
 
-  m_model->notice_settings (); // update colors of model first
+  if (m_first)
+    m_first = false;
+  else
+    {
+      // Save current state in case some settings are messing up the state
+      settings.setValue (ws_column_state.settings_key (),
+                         m_view->horizontalHeader ()->saveState ());
+      settings.sync ();
+    }
 
-  for (int i = 0; i < ws_columns_shown.length (); i++)
-    m_view->setColumnHidden (i + 1, ! settings.value (ws_columns_shown_keys.at (i), true).toBool ());
+  m_model->notice_settings (); // update colors of model first
 
   QString tool_tip;
 
@@ -219,6 +220,14 @@
     }
 
   setToolTip (tool_tip);
+
+  // Initialize column order, visibility and width of the file browser. From this post,
+  // https://www.qtcentre.org/threads/26675-QTableView-saving-restoring-columns-widths
+  // this might fail if done directly after other actions. This effect shows
+  // up in the GUI since Qt 6.6.x. As a solution, the following timer ensures
+  // that the header is restored when the event loop is idle.
+
+  QTimer::singleShot (0, this, SLOT(restore_header_state ()));
 }
 
 void
@@ -311,7 +320,7 @@
                           &sig_mapper, SLOT (map ()));
       sig_mapper.setMapping (action, i);
       action->setCheckable (true);
-      action->setChecked (settings.value (ws_columns_shown_keys.at (i), true).toBool ());
+      action->setChecked (! m_view->isColumnHidden (i+1));
     }
 
 #if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
@@ -328,17 +337,7 @@
 void
 workspace_view::toggle_header (int col)
 {
-  gui_settings settings;
-
-  QString key = ws_columns_shown_keys.at (col);
-  bool shown = settings.value (key, true).toBool ();
-
-  m_view->setColumnHidden (col + 1, shown);
-
-  settings.setValue (key, ! shown);
-  settings.sync ();
-
-  octave_dock_widget::save_settings ();
+  m_view->setColumnHidden (col + 1, ! m_view->isColumnHidden (col + 1));
 }
 
 void
--- a/libgui/src/workspace-view.h	Wed May 01 22:14:17 2024 -0400
+++ b/libgui/src/workspace-view.h	Thu May 02 06:44:38 2024 +0200
@@ -126,6 +126,7 @@
   QComboBox *m_filter;
   QWidget *m_filter_widget;
   bool m_filter_shown;
+  bool m_first;
 };
 
 OCTAVE_END_NAMESPACE(octave)