changeset 16641:64f9a3e301d3

don't store default values in resource manager class * QTerminal.h, QTerminal.cc (QTerminal::default_colors, QTerminal::color_names): New functions. (QTerminal::notice_settings): Call default_colors. * workspace-model.h, workspace-model.cc (workspace_model::storage_class_default_colors, workspace_model::storage_class_names): New functions. * resource-manager.cc (resource_manager::storage_class_names, resource_manager::storage_class_default_colors): Get values from workspace_model. (resource_manager::terminal_color_names, resource_manager::terminal_default_colors): Get values from QTerminal.
author John W. Eaton <jwe@octave.org>
date Sun, 12 May 2013 16:17:48 -0400
parents 0ee7b4d1b940
children e3a0ca9c8836
files libgui/qterminal/libqterminal/QTerminal.cc libgui/qterminal/libqterminal/QTerminal.h libgui/src/resource-manager.cc libgui/src/workspace-model.cc libgui/src/workspace-model.h
diffstat 5 files changed, 92 insertions(+), 32 deletions(-) [+]
line wrap: on
line diff
--- a/libgui/qterminal/libqterminal/QTerminal.cc	Sun May 12 15:33:05 2013 -0400
+++ b/libgui/qterminal/libqterminal/QTerminal.cc	Sun May 12 16:17:48 2013 -0400
@@ -38,6 +38,38 @@
 #endif
 }
 
+QList<QColor>
+QTerminal::default_colors (void)
+{
+  static QList<QColor> colors;
+
+  if (colors.isEmpty ())
+    {
+      colors << QColor(0,0,0)
+             << QColor(255,255,255)
+             << QColor(192,192,192)
+             << QColor(128,128,128);
+    }
+
+  return colors;
+}
+
+QStringList
+QTerminal::color_names (void)
+{
+  static QStringList names;
+
+  if (names.isEmpty ())
+    {
+      names << QObject::tr ("foreground")
+            << QObject::tr ("background")
+            << QObject::tr ("selection")
+            << QObject::tr ("cursor");
+    }
+
+  return names;
+}
+
 void
 QTerminal::notice_settings (const QSettings *settings)
 {
@@ -68,29 +100,22 @@
   bool cursorUseForegroundColor
     = settings->value ("terminal/cursorUseForegroundColor", true).toBool ();
 
-  // FIXME -- we shouldn't duplicate this information here and in the
-  // resource manager.
-  QList<QColor> default_colors;
-
-  default_colors << QColor(0,0,0)
-                 << QColor(255,255,255)
-                 << QColor(192,192,192)
-                 << QColor(128,128,128);
+  QList<QColor> colors = default_colors ();
 
   setForegroundColor
     (settings->value ("terminal/color_f",
-                      QVariant (default_colors.at (0))).value<QColor> ());
+                      QVariant (colors.at (0))).value<QColor> ());
 
   setBackgroundColor
     (settings->value ("terminal/color_b",
-                      QVariant (default_colors.at (1))).value<QColor> ());
+                      QVariant (colors.at (1))).value<QColor> ());
 
   setSelectionColor
     (settings->value ("terminal/color_s",
-                      QVariant (default_colors.at (2))).value<QColor> ());
+                      QVariant (colors.at (2))).value<QColor> ());
 
   setCursorColor
     (cursorUseForegroundColor,
      settings->value ("terminal/color_c",
-                      QVariant (default_colors.at (3))).value<QColor> ());
+                      QVariant (colors.at (3))).value<QColor> ());
 }
--- a/libgui/qterminal/libqterminal/QTerminal.h	Sun May 12 15:33:05 2013 -0400
+++ b/libgui/qterminal/libqterminal/QTerminal.h	Sun May 12 16:17:48 2013 -0400
@@ -26,7 +26,9 @@
 #include <QSettings>
 #include <QtGlobal>
 #include <QWidget>
+#include <QStringList>
 #include <QColor>
+#include <QList>
 #include <QMenu>
 
 class QTerminal : public QWidget
@@ -37,6 +39,10 @@
 
   static QTerminal *create (QWidget *xparent = 0);
 
+  static QList<QColor> default_colors (void);
+
+  static QStringList color_names (void);
+
   virtual ~QTerminal (void) { }
 
   virtual void setTerminalFont(const QFont& font) = 0;
--- a/libgui/src/resource-manager.cc	Sun May 12 15:33:05 2013 -0400
+++ b/libgui/src/resource-manager.cc	Sun May 12 16:17:48 2013 -0400
@@ -33,11 +33,14 @@
 
 #include "error.h"
 #include "file-ops.h"
+#include "help.h"
 #include "oct-env.h"
 #include "singleton-cleanup.h"
 
 #include "defaults.h"
 
+#include "QTerminal.h"
+#include "workspace-model.h"
 #include "resource-manager.h"
 
 resource_manager *resource_manager::instance = 0;
@@ -198,41 +201,25 @@
 QStringList 
 resource_manager::storage_class_names (void)
 {
-  return QStringList () << QObject::tr ("automatic")
-                        << QObject::tr ("function")
-                        << QObject::tr ("global")
-                        << QObject::tr ("hidden")
-                        << QObject::tr ("inherited")
-                        << QObject::tr ("persistent");
+  return workspace_model::storage_class_names ();
 }
 
 QList<QColor>
 resource_manager::storage_class_default_colors (void)
 {
-  return QList<QColor> () << QColor(190,255,255)
-                          << QColor(220,255,220)
-                          << QColor(220,220,255)
-                          << QColor(255,255,190)
-                          << QColor(255,220,220)
-                          << QColor(255,190,255);
+  return workspace_model::storage_class_default_colors ();
 }
 
 QStringList 
 resource_manager::terminal_color_names (void)
 {
-  return QStringList () << QObject::tr ("foreground")
-                        << QObject::tr ("background")
-                        << QObject::tr ("selection")
-                        << QObject::tr ("cursor");
+  return QTerminal::color_names ();
 }
 
 QList<QColor>
 resource_manager::terminal_default_colors (void)
 {
-  return QList<QColor> () << QColor(0,0,0)
-                          << QColor(255,255,255)
-                          << QColor(192,192,192)
-                          << QColor(128,128,128);
+  return QTerminal::default_colors ();
 }
 
 const char*
--- a/libgui/src/workspace-model.cc	Sun May 12 15:33:05 2013 -0400
+++ b/libgui/src/workspace-model.cc	Sun May 12 16:17:48 2013 -0400
@@ -46,6 +46,43 @@
 
 }
 
+QList<QColor>
+workspace_model::storage_class_default_colors (void)
+{
+  QList<QColor> colors;
+
+  if (colors.isEmpty ())
+    {
+      colors << QColor (190,255,255)
+             << QColor (220,255,220)
+             << QColor (220,220,255)
+             << QColor (255,255,190)
+             << QColor (255,220,220)
+             << QColor (255,190,255);
+    }
+
+  return colors;
+}
+
+
+QStringList
+workspace_model::storage_class_names (void)
+{
+  QStringList names;
+
+  if (names.isEmpty ())
+    {
+      names << QObject::tr ("automatic")
+            << QObject::tr ("function")
+            << QObject::tr ("global")
+            << QObject::tr ("hidden")
+            << QObject::tr ("inherited")
+            << QObject::tr ("persistent");
+    }
+
+  return names;
+}
+
 int
 workspace_model::rowCount (const QModelIndex&) const
 {
--- a/libgui/src/workspace-model.h	Sun May 12 15:33:05 2013 -0400
+++ b/libgui/src/workspace-model.h	Sun May 12 16:17:48 2013 -0400
@@ -29,6 +29,7 @@
 #include <QSemaphore>
 #include <QStringList>
 #include <QChar>
+#include <QList>
 #include <QColor>
 #include <QSettings>
 
@@ -43,6 +44,10 @@
 
   ~workspace_model (void) { }
 
+  static QList<QColor> storage_class_default_colors (void);
+
+  static QStringList storage_class_names (void);
+
   QVariant data (const QModelIndex& index, int role) const;
 
   bool setData (const QModelIndex& index, const QVariant& value,