changeset 27660:30e84a3d58e5

replace preference literals by symbolic constants for workspace view * gui-preferences-ws.h: added all remaining workspace view preferences * resource-manager.cc (storage_class_names, storage_class_default_colors): remove obsolete function from resource_manager * resource-manager.h: remove obsolete functions storage_class_names ans storage_class_default_colors as well as class chars * settings-dialog.cc (read_workspace_colors): use new symbolic constants instead of literals and resource manager static functions; (write_workspace_colors): dito * workspace-model.cc (workspace_model): use new symbolic constants instead of literals and resource manager static functions; (storage_class_default_colors): remove obsolete functions; (storage_class_names): dito (data): use new symbolic constants instead of literals and resource manager static functions; (notice_settings): dito; * workspace-model.h: remove obsolete funtions storage_class_default_colors, storage_class_names * workspace-view.cc (workspace_view): use new symbolic constants instead of literals and resource manager static functions; (notice_settings): dito; (save_settings): dito; (header_contextmenu_requested): dito; (toggle_header): dito * workspace-view.h: removed obsolete class variables
author Torsten Lilge <ttl-octave@mailbox.org>
date Sat, 09 Nov 2019 12:45:07 +0100
parents d4f1abfaf3a5
children 2213e82bb9d3
files libgui/src/gui-preferences-ws.h libgui/src/resource-manager.cc libgui/src/resource-manager.h libgui/src/settings-dialog.cc libgui/src/workspace-model.cc libgui/src/workspace-model.h libgui/src/workspace-view.cc libgui/src/workspace-view.h
diffstat 8 files changed, 97 insertions(+), 145 deletions(-) [+]
line wrap: on
line diff
--- a/libgui/src/gui-preferences-ws.h	Fri Nov 08 10:26:28 2019 -0500
+++ b/libgui/src/gui-preferences-ws.h	Sat Nov 09 12:45:07 2019 +0100
@@ -33,4 +33,54 @@
 const gui_pref
 ws_hide_tool_tips ("workspaceview/hide_tools_tips", QVariant (false));
 
+const gui_pref
+ws_filter_active ("workspaceview/filter_active", QVariant (false));
+
+const gui_pref
+ws_filter_shown ("workspaceview/filter_shown", QVariant (true));
+
+const gui_pref
+ws_column_state ("workspaceview/column_state", QVariant ());
+
+const gui_pref
+ws_sort_column ("workspaceview/sort_by_column", QVariant (0));
+
+const gui_pref
+ws_sort_order ("workspaceview/sort_order", QVariant (Qt::AscendingOrder));
+
+const gui_pref
+ws_mru_list ("workspaceview/mru_list", QVariant ());
+
+const QStringList ws_columns_shown (QStringList ()
+    << QT_TRANSLATE_NOOP ("workspace_view::notice_settings", "Class")
+    << QT_TRANSLATE_NOOP ("workspace_view::notice_settings", "Dimension")
+    << QT_TRANSLATE_NOOP ("workspace_view::notice_settings", "Value")
+    << QT_TRANSLATE_NOOP ("workspace_view::notice_settings", "Attribute"));
+
+const QStringList ws_columns_shown_keys (QStringList ()
+    << "workspaceview/show_class"
+    << "workspaceview/show_dimension"
+    << "workspaceview/show_value"
+    << "workspaceview/show_attribute");
+
+const gui_pref
+ws_max_filter_history ("workspaceview/max_filter_history", QVariant (10));
+
+const int ws_colors_count = 3;
+
+const gui_pref ws_colors[ws_colors_count] =
+{
+  {"terminal/color_a", QVariant (QColor(190,255,255))},
+  {"terminal/color_g", QVariant (QColor(255,255,190))},
+  {"terminal/color_p", QVariant (QColor(255,190,255))}
+};
+
+const QString ws_class_chars ("agp");
+
+const QStringList
+ws_color_names (QStringList ()
+             << QT_TRANSLATE_NOOP ("workspace_model::workspace_model", "argument")
+             << QT_TRANSLATE_NOOP ("workspace_model::workspace_model", "global")
+             << QT_TRANSLATE_NOOP ("workspace_model::workspace_model", "persistant"));
+
 #endif
--- a/libgui/src/resource-manager.cc	Fri Nov 08 10:26:28 2019 -0500
+++ b/libgui/src/resource-manager.cc	Sat Nov 09 12:45:07 2019 +0100
@@ -185,16 +185,6 @@
 
   }
 
-  QStringList resource_manager::storage_class_names (void)
-  {
-    return workspace_model::storage_class_names ();
-  }
-
-  QList<QColor> resource_manager::storage_class_default_colors (void)
-  {
-    return workspace_model::storage_class_default_colors ();
-  }
-
   QList<QColor> resource_manager::varedit_default_colors(void)
   {
     return variable_editor::default_colors ();
--- a/libgui/src/resource-manager.h	Fri Nov 08 10:26:28 2019 -0500
+++ b/libgui/src/resource-manager.h	Sat Nov 09 12:45:07 2019 +0100
@@ -56,12 +56,6 @@
     void config_translators (QTranslator *qt_tr, QTranslator *qsci_tr,
                              QTranslator *gui_tr);
 
-    QString storage_class_chars (void) { return "agp"; }
-
-    QStringList storage_class_names (void);
-
-    QList<QColor> storage_class_default_colors (void);
-
     QString varedit_color_chars (void) {return "fbsha"; }
 
     QStringList varedit_color_names (void);
--- a/libgui/src/settings-dialog.cc	Fri Nov 08 10:26:28 2019 -0500
+++ b/libgui/src/settings-dialog.cc	Sat Nov 09 12:45:07 2019 +0100
@@ -1056,16 +1056,9 @@
   void settings_dialog::read_workspace_colors (gui_settings *settings)
   {
     // Construct the grid with all color related settings
-    resource_manager& rmgr = m_octave_qobj.get_resource_manager ();
-    QList<QColor> default_colors
-      = rmgr.storage_class_default_colors ();
-    QStringList class_names = rmgr.storage_class_names ();
-    QString class_chars = rmgr.storage_class_chars ();
-    int nr_of_classes = class_chars.length ();
-
     QGridLayout *style_grid = new QGridLayout ();
-    QVector<QLabel*> description (nr_of_classes);
-    QVector<color_picker*> color (nr_of_classes);
+    QVector<QLabel*> description (ws_colors_count);
+    QVector<color_picker*> color (ws_colors_count);
 
     int column = 0;
     int row = 0;
@@ -1080,17 +1073,17 @@
     m_ws_hide_tool_tips->setChecked
       (settings->value (ws_hide_tool_tips.key, ws_hide_tool_tips.def).toBool ());
 
-    for (int i = 0; i < nr_of_classes; i++)
+    for (int i = 0; i < ws_colors_count; i++)
       {
-        description[i] = new QLabel ("    " + class_names.at (i));
+        description[i] = new QLabel ("    " + ws_color_names.at (i));
         description[i]->setAlignment (Qt::AlignRight);
         connect (m_ws_enable_colors, SIGNAL (toggled (bool)),
                  description[i], SLOT(setEnabled (bool)));
 
-        QVariant default_var = default_colors.at (i);
-        QColor setting_color = settings->value ("workspaceview/color_" + class_chars.mid (i, 1), default_var).value<QColor> ();
+        QColor setting_color = settings->value (ws_colors[i].key,
+                                                ws_colors[i].def).value<QColor> ();
         color[i] = new color_picker (setting_color);
-        color[i]->setObjectName ("color_" + class_chars.mid (i, 1));
+        color[i]->setObjectName (ws_colors[i].key);
         color[i]->setMinimumSize (30, 10);
         connect (m_ws_enable_colors, SIGNAL (toggled (bool)),
                  color[i], SLOT(setEnabled (bool)));
@@ -1120,15 +1113,13 @@
     settings->setValue (ws_enable_colors.key, m_ws_enable_colors->isChecked ());
     settings->setValue (ws_hide_tool_tips.key, m_ws_hide_tool_tips->isChecked ());
 
-    resource_manager& rmgr = m_octave_qobj.get_resource_manager ();
-    QString class_chars = rmgr.storage_class_chars ();
     color_picker *color;
 
-    for (int i = 0; i < class_chars.length (); i++)
+    for (int i = 0; i < ws_colors_count; i++)
       {
-        color = workspace_colors_box->findChild <color_picker *> ("color_" + class_chars.mid (i, 1));
+        color = workspace_colors_box->findChild <color_picker *> (ws_colors[i].key);
         if (color)
-          settings->setValue ("workspaceview/color_" + class_chars.mid (i, 1), color->color ());
+          settings->setValue (ws_colors[i].key, color->color ());
       }
     settings->sync ();
   }
--- a/libgui/src/workspace-model.cc	Fri Nov 08 10:26:28 2019 -0500
+++ b/libgui/src/workspace-model.cc	Sat Nov 09 12:45:07 2019 +0100
@@ -52,43 +52,11 @@
     // classes in the workspace view. The structure is
     // m_storage_class_colors(1,2,...,colors):        background colors
     // m_storage_class_colors(colors+1,...,2*colors): foreground colors
-    resource_manager& rmgr = m_octave_qobj.get_resource_manager ();
-    int colors = rmgr.storage_class_chars ().length ();
-    for (int i = 0; i < 2*colors; i++)
+    for (unsigned int i = 0; i < 2*ws_colors_count; i++)
       m_storage_class_colors.append (QColor (Qt::white));
 
   }
 
-  QList<QColor>
-  workspace_model::storage_class_default_colors (void)
-  {
-    QList<QColor> colors;
-
-    if (colors.isEmpty ())
-      {
-        colors << QColor (190, 255, 255)
-               << QColor (255, 255, 190)
-               << QColor (255, 190, 255);
-      }
-
-    return colors;
-  }
-
-  QStringList
-  workspace_model::storage_class_names (void)
-  {
-    QStringList names;
-
-    if (names.isEmpty ())
-      {
-        names << QObject::tr ("argument")
-              << QObject::tr ("global")
-              << QObject::tr ("persistent");
-      }
-
-    return names;
-  }
-
   int
   workspace_model::rowCount (const QModelIndex&) const
   {
@@ -137,16 +105,14 @@
         if ((role == Qt::BackgroundColorRole || role == Qt::ForegroundRole)
             && m_enable_colors)
           {
-            resource_manager& rmgr = m_octave_qobj.get_resource_manager ();
-            QString class_chars = rmgr.storage_class_chars ();
             int actual_class
-              = class_chars.indexOf (m_scopes[idx.row ()].toLatin1 ());
+              = ws_class_chars.indexOf (m_scopes[idx.row ()].toLatin1 ());
             if (actual_class >= 0)
               {
                 // Valid class: Get backgorund (normal indexes) or foreground
                 // color (indexes with offset)
                 if (role == Qt::ForegroundRole)
-                  actual_class += class_chars.length ();
+                  actual_class += ws_colors_count;
 
                 return QVariant (m_storage_class_colors.at (actual_class));
               }
@@ -184,20 +150,11 @@
                 {
                   QString sclass;
 
-                  resource_manager& rmgr
-                    = m_octave_qobj.get_resource_manager ();
-
-                  QString class_chars = rmgr.storage_class_chars ();
-
                   int actual_class
-                    = class_chars.indexOf (m_scopes[idx.row ()].toLatin1 ());
+                    = ws_class_chars.indexOf (m_scopes[idx.row ()].toLatin1 ());
 
                   if (actual_class >= 0)
-                    {
-                      QStringList class_names = rmgr.storage_class_names ();
-
-                      sclass = class_names.at (actual_class);
-                    }
+                    sclass = ws_color_names.at (actual_class);
 
                   if (m_complex_flags[idx.row ()])
                     {
@@ -239,26 +196,19 @@
   void
   workspace_model::notice_settings (const gui_settings *settings)
   {
-    resource_manager& rmgr = m_octave_qobj.get_resource_manager ();
-    QList<QColor> default_colors =
-      rmgr.storage_class_default_colors ();
-    QString class_chars = rmgr.storage_class_chars ();
-
     m_enable_colors =
         settings->value (ws_enable_colors.key, ws_enable_colors.def).toBool ();
 
-    for (int i = 0; i < class_chars.length (); i++)
+    for (int i = 0; i < ws_colors_count; i++)
       {
-        QVariant default_var = default_colors.at (i);
-        QColor setting_color = settings->value ("workspaceview/color_"
-                                                + class_chars.mid (i,1),
-                                                default_var).value<QColor> ();
+        QColor setting_color = settings->value (ws_colors[i].key,
+                                                ws_colors[i].def).value<QColor> ();
 
         QPalette p (setting_color);
         m_storage_class_colors.replace (i,setting_color);
 
         QColor fg_color = p.color (QPalette::WindowText);
-        m_storage_class_colors.replace (i + class_chars.length (), fg_color);
+        m_storage_class_colors.replace (i + ws_colors_count, fg_color);
 
       }
   }
--- a/libgui/src/workspace-model.h	Fri Nov 08 10:26:28 2019 -0500
+++ b/libgui/src/workspace-model.h	Sat Nov 09 12:45:07 2019 +0100
@@ -54,10 +54,6 @@
 
     ~workspace_model (void) = default;
 
-    static QList<QColor> storage_class_default_colors (void);
-
-    static QStringList storage_class_names (void);
-
     int rowCount (const QModelIndex& parent = QModelIndex ()) const;
 
     int columnCount (const QModelIndex& parent = QModelIndex ()) const;
--- a/libgui/src/workspace-view.cc	Fri Nov 08 10:26:28 2019 -0500
+++ b/libgui/src/workspace-view.cc	Sat Nov 09 12:45:07 2019 +0100
@@ -62,7 +62,7 @@
 
     m_filter->setToolTip (tr ("Enter text to filter the workspace"));
     m_filter->setEditable (true);
-    m_filter->setMaxCount (MaxFilterHistory);
+    m_filter->setMaxCount (ws_max_filter_history.def.toInt ());
     m_filter->setInsertPolicy (QComboBox::NoInsert);
     m_filter->setSizeAdjustPolicy (QComboBox::AdjustToMinimumContentsLengthWithIcon);
     QSizePolicy sizePol (QSizePolicy::Expanding, QSizePolicy::Preferred);
@@ -101,7 +101,8 @@
 
     if (settings)
       {
-        m_filter_shown = settings->value ("workspaceview/filter_shown",true).toBool ();
+        m_filter_shown = settings->value (ws_filter_shown.key,
+                                          ws_filter_shown.def).toBool ();
         m_filter_widget->setVisible (m_filter_shown);
 
         ws_layout->setMargin (2);
@@ -115,7 +116,7 @@
         m_view->setSortingEnabled (true);
         // Initialize column order and width of the workspace
         m_view->horizontalHeader ()->restoreState
-          (settings->value ("workspaceview/column_state").toByteArray ());
+          (settings->value (ws_column_state.key).toByteArray ());
 
         // Set header properties for sorting
 #if defined (HAVE_QHEADERVIEW_SETSECTIONSCLICKABLE)
@@ -128,9 +129,9 @@
 #else
         m_view->horizontalHeader ()->setMovable (true);
 #endif
-        m_view->horizontalHeader ()->setSortIndicator (settings->value ("workspaceview/sort_by_column",0).toInt (),
-                                                       static_cast<Qt::SortOrder>
-                                                       (settings->value ("workspaceview/sort_order", Qt::AscendingOrder).toUInt ()));
+        m_view->horizontalHeader ()->setSortIndicator (
+            settings->value (ws_sort_column.key, ws_sort_column.def).toInt (),
+            static_cast<Qt::SortOrder> (settings->value (ws_sort_order.key, ws_sort_order.def).toUInt ()));
         m_view->horizontalHeader ()->setSortIndicatorShown (true);
 
         m_view->horizontalHeader ()->setContextMenuPolicy (Qt::CustomContextMenu);
@@ -139,10 +140,10 @@
                  this, SLOT (header_contextmenu_requested (const QPoint &)));
 
         // Init state of the filter
-        m_filter->addItems (settings->value ("workspaceview/mru_list").toStringList ());
+        m_filter->addItems (settings->value (ws_mru_list.key).toStringList ());
 
         bool filter_state =
-          settings->value ("workspaceview/filter_active", false).toBool ();
+          settings->value (ws_filter_active.key, ws_filter_active.def).toBool ();
         m_filter_checkbox->setChecked (filter_state);
         filter_activate (filter_state);
       }
@@ -180,8 +181,9 @@
     // set the sorting after a model was set, it would be ignored otherwise
     resource_manager& rmgr = m_octave_qobj.get_resource_manager ();
     gui_settings *settings = rmgr.get_settings ();
-    m_view->sortByColumn (settings->value ("workspaceview/sort_by_column",0).toInt (),
-                          static_cast<Qt::SortOrder> (settings->value ("workspaceview/sort_order", Qt::AscendingOrder).toUInt ()));
+    m_view->sortByColumn (
+      settings->value (ws_sort_column.key ,ws_sort_column.def).toInt (),
+      static_cast<Qt::SortOrder> (settings->value (ws_sort_order.key, ws_sort_column.def).toUInt ()));
 
     m_model = model;
   }
@@ -189,12 +191,10 @@
   void
   workspace_view::notice_settings (const gui_settings *settings)
   {
-    int i;
-
     m_model->notice_settings (settings); // update colors of model first
 
-    for (i = 0; i < m_columns_shown_keys.size (); i++)
-      m_view->setColumnHidden (i + 1, ! settings->value (m_columns_shown_keys.at (i),true).toBool ());
+    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 ());
 
     QString tool_tip;
 
@@ -203,31 +203,18 @@
       {
         tool_tip  = QString (tr ("View the variables in the active workspace.<br>"));
         tool_tip += QString (tr ("Colors for variable attributes:"));
-        resource_manager& rmgr = m_octave_qobj.get_resource_manager ();
-        int colors = rmgr.storage_class_chars ().length ();
-        for (i = 0; i < colors; i++)
+
+        for (int i = 0; i < ws_colors_count; i++)
           {
             tool_tip +=
               QString (R"(<div style="background-color:%1;color:%2">%3</div>)")
               .arg (m_model->storage_class_color (i).name ())
-              .arg (m_model->storage_class_color (i + colors).name ())
-              .arg (rmgr.storage_class_names ().at (i));
+              .arg (m_model->storage_class_color (i + ws_colors_count).name ())
+              .arg (ws_color_names.at (i));
           }
       }
 
     setToolTip (tool_tip);
-
-    m_columns_shown = QStringList ();
-    m_columns_shown.append (tr ("Class"));
-    m_columns_shown.append (tr ("Dimension"));
-    m_columns_shown.append (tr ("Value"));
-    m_columns_shown.append (tr ("Attribute"));
-
-    m_columns_shown_keys = QStringList ();
-    m_columns_shown_keys.append ("workspaceview/show_class");
-    m_columns_shown_keys.append ("workspaceview/show_dimension");
-    m_columns_shown_keys.append ("workspaceview/show_value");
-    m_columns_shown_keys.append ("workspaceview/show_attribute");
   }
 
   void
@@ -239,22 +226,21 @@
     if (! settings)
       return;
 
-    settings->setValue ("workspaceview/column_state",
+    settings->setValue (ws_column_state.key,
                         m_view->horizontalHeader ()->saveState ());
 
     int sort_column = m_view->horizontalHeader ()->sortIndicatorSection ();
     Qt::SortOrder sort_order = m_view->horizontalHeader ()->sortIndicatorOrder ();
-    settings->setValue ("workspaceview/sort_by_column", sort_column);
-    settings->setValue ("workspaceview/sort_order", sort_order);
+    settings->setValue (ws_sort_column.key, sort_column);
+    settings->setValue (ws_sort_order.key, sort_order);
 
-    settings->setValue ("workspaceview/filter_active",
-                        m_filter_checkbox->isChecked ());
-    settings->setValue ("workspaceview/filter_shown", m_filter_shown);
+    settings->setValue (ws_filter_active.key, m_filter_checkbox->isChecked ());
+    settings->setValue (ws_filter_shown.key, m_filter_shown);
 
     QStringList mru;
     for (int i = 0; i < m_filter->count (); i++)
       mru.append (m_filter->itemText (i));
-    settings->setValue ("workspaceview/mru_list", mru);
+    settings->setValue (ws_mru_list.key, mru);
 
     settings->sync ();
 
@@ -302,13 +288,13 @@
     resource_manager& rmgr = m_octave_qobj.get_resource_manager ();
     gui_settings *settings = rmgr.get_settings ();
 
-    for (int i = 0; i < m_columns_shown.size (); i++)
+    for (int i = 0; i < ws_columns_shown.length (); i++)
       {
-        QAction *action = menu.addAction (m_columns_shown.at (i),
+        QAction *action = menu.addAction (ws_columns_shown.at (i),
                                           &sig_mapper, SLOT (map ()));
         sig_mapper.setMapping (action, i);
         action->setCheckable (true);
-        action->setChecked (settings->value (m_columns_shown_keys.at (i),true).toBool ());
+        action->setChecked (settings->value (ws_columns_shown_keys.at (i),true).toBool ());
       }
 
     connect (&sig_mapper, SIGNAL (mapped (int)),
@@ -323,7 +309,7 @@
     resource_manager& rmgr = m_octave_qobj.get_resource_manager ();
     gui_settings *settings = rmgr.get_settings ();
 
-    QString key = m_columns_shown_keys.at (col);
+    QString key = ws_columns_shown_keys.at (col);
     bool shown = settings->value (key,true).toBool ();
 
     m_view->setColumnHidden (col + 1, shown);
--- a/libgui/src/workspace-view.h	Fri Nov 08 10:26:28 2019 -0500
+++ b/libgui/src/workspace-view.h	Sat Nov 09 12:45:07 2019 +0100
@@ -119,11 +119,6 @@
     QComboBox *m_filter;
     QWidget *m_filter_widget;
     bool m_filter_shown;
-
-    enum { MaxFilterHistory = 10 };
-
-    QStringList m_columns_shown;
-    QStringList m_columns_shown_keys;
   };
 }