changeset 16447:e3b33a7530bc

improve encapsulation of history window object * history-dockwidget.h, history-dockwidget.cc (history_dock_widget::history_dock_widget): Set status tip here. Connect history_dock_widget::information signal to main_window::report_status_message. Connect history_dock_widget::command_double_clicked signal to main_window::handle_command_double_clicked. (history_dock_widget::connect_visibility_changed, history_dock_widget::focus, history_dock_widget::handle_visibility): New functions. * main-window.h, main-window.cc (main_window::history_window): Rename from _history_dock_widget. Don't use a pointer. Change all uses. (main_window::main_window): Initialize it here. (main_window::~main_window): Don't delete _history_dock_widget. (main_window::focus_history_window_signal): New signal. (main_window::focus_history_window): Rename from main_window::focus_command_history. Emit focus_history_window_signal instead of performing actions here. (main_window::handle_command_history_visible): Delete. (main_window::connect_visibility_changed): Call history_window.connect_visibility_changed instead of performing actions here. (main_window::construct): Don't create _history_dock_widget. Adapt signal/slot connections for new history_window object.
author John W. Eaton <jwe@octave.org>
date Sat, 06 Apr 2013 16:46:14 -0400
parents 4b3a4bf8569b
children 47fe533ec85b
files libgui/src/history-dockwidget.cc libgui/src/history-dockwidget.h libgui/src/main-window.cc libgui/src/main-window.h
diffstat 4 files changed, 64 insertions(+), 43 deletions(-) [+]
line wrap: on
line diff
--- a/libgui/src/history-dockwidget.cc	Sat Apr 06 16:14:32 2013 -0400
+++ b/libgui/src/history-dockwidget.cc	Sat Apr 06 16:46:14 2013 -0400
@@ -34,16 +34,30 @@
 #include "cmd-hist.h"
 
 #include "history-dockwidget.h"
-#include "octave-link.h"
 
-history_dock_widget::history_dock_widget (QWidget * p)
+history_dock_widget::history_dock_widget (QWidget *p)
   : octave_dock_widget (p)
 {
   setObjectName ("HistoryDockWidget");
+  setStatusTip (tr ("Browse and search the command history."));
+
+  connect (this, SIGNAL (information (QString)),
+           p, SLOT (report_status_message (QString)));
+
+  connect (this, SIGNAL (command_double_clicked (const QString&)),
+           p, SLOT (handle_command_double_clicked (const QString&)));
+
   construct ();
 }
 
 void
+history_dock_widget::connect_visibility_changed (void)
+{
+  connect (this, SIGNAL (visibilityChanged (bool)),
+           this, SLOT (handle_visibility (bool)));
+}
+
+void
 history_dock_widget::construct ()
 {
   _history_model = new QStringListModel ();
@@ -141,3 +155,21 @@
   _history_model->setStringList (QStringList ());
 }
 
+void
+history_dock_widget::focus (void)
+{
+  if (! isVisible ())
+    setVisible (true);
+
+  setFocus ();
+  activateWindow ();
+  raise ();
+}
+
+void
+history_dock_widget::handle_visibility (bool visible)
+{
+  if (visible && ! isFloating ())
+    focus ();
+}
+
--- a/libgui/src/history-dockwidget.h	Sat Apr 06 16:14:32 2013 -0400
+++ b/libgui/src/history-dockwidget.h	Sat Apr 06 16:46:14 2013 -0400
@@ -32,27 +32,38 @@
 class history_dock_widget : public octave_dock_widget
 {
   Q_OBJECT
-  public:
+
+public:
+
   history_dock_widget (QWidget *parent = 0);
 
+  void connect_visibility_changed (void);
+
 public slots:
+
   void set_history (const QStringList& hist);
   void append_history (const QString& hist_entry);
   void clear_history (void);
 
+  void focus (void);
+  void handle_visibility (bool);
+
 signals:
+
   void information (const QString& message);
 
   /** Emitted, whenever the user double-clicked a command in the history. */
   void command_double_clicked (const QString& command);
 
 private slots:
+
   void handle_double_click (QModelIndex modelIndex);
   void handle_contextmenu_copy(bool flag);
   void handle_contextmenu_evaluate(bool flag);
   void ctxMenu(const QPoint &pos);
 
 private:
+
   void construct ();
   QListView *_history_list_view;
   QLineEdit *_filter_line_edit;
--- a/libgui/src/main-window.cc	Sat Apr 06 16:14:32 2013 -0400
+++ b/libgui/src/main-window.cc	Sat Apr 06 16:46:14 2013 -0400
@@ -1,5 +1,6 @@
 /*
 
+Copyright (C) 2013 John W. Eaton
 Copyright (C) 2011-2012 Jacob Dawid
 
 This file is part of Octave.
@@ -55,7 +56,7 @@
 #include "oct-env.h"
 
 main_window::main_window (QWidget *p)
-  : QMainWindow (p), command_window (this)
+  : QMainWindow (p), command_window (this), history_window (this)
 {
   // We have to set up all our windows, before we finally launch octave.
   construct ();
@@ -87,9 +88,6 @@
   if (_files_dock_widget)
     delete _files_dock_widget;
 
-  if (_history_dock_widget)
-    delete _history_dock_widget;
-
   delete _workspace_model;
   delete _workspace_view;
 }
@@ -351,16 +349,9 @@
 }
 
 void
-main_window::focus_command_history ()
+main_window::focus_history_window (void)
 {
-  if (!_history_dock_widget->isVisible ())
-    {
-      _history_dock_widget->setVisible (true);
-    }
-
-  _history_dock_widget->setFocus ();
-  _history_dock_widget->activateWindow ();
-  _history_dock_widget->raise ();
+  emit focus_history_window_signal ();
 }
 
 void
@@ -413,14 +404,6 @@
 }
 
 void
-main_window::handle_command_history_visible (bool visible)
-{
-  // if changed to visible and widget is not floating
-  if (visible && !_history_dock_widget->isFloating ())
-    focus_command_history ();
-}
-
-void
 main_window::handle_current_directory_visible (bool visible)
 {
   // if changed to visible and widget is not floating
@@ -617,11 +600,10 @@
 main_window::connect_visibility_changed ()
 {
   command_window.connect_visibility_changed ();
+  history_window.connect_visibility_changed ();
 
   connect (_workspace_view,       SIGNAL (visibilityChanged (bool)),
            this,                  SLOT (handle_workspace_visible (bool)));
-  connect (_history_dock_widget,  SIGNAL (visibilityChanged (bool)),
-           this,                  SLOT (handle_command_history_visible (bool)));
   connect (_files_dock_widget,    SIGNAL (visibilityChanged (bool)),
            this,                  SLOT (handle_current_directory_visible (bool)));
 #ifdef HAVE_QSCINTILLA
@@ -652,8 +634,6 @@
   connect (_workspace_model, SIGNAL (model_changed ()),
            _workspace_view, SLOT (model_changed ()));
 
-  _history_dock_widget      = new history_dock_widget (this);
-  _history_dock_widget->setStatusTip (tr ("Browse and search the command history."));
   _files_dock_widget        = new files_dock_widget (this);
   _files_dock_widget->setStatusTip (tr ("Browse your files."));
   _documentation_dock_widget= new documentation_dock_widget (this);
@@ -1017,8 +997,8 @@
   connect (_workspace_view,             SIGNAL (active_changed (bool)),
            show_workspace_action,       SLOT   (setChecked (bool)));
   connect (show_history_action,         SIGNAL (toggled (bool)),
-           _history_dock_widget,        SLOT   (setVisible (bool)));
-  connect (_history_dock_widget,        SIGNAL (active_changed (bool)),
+           &history_window,             SLOT   (setVisible (bool)));
+  connect (&history_window,             SIGNAL (active_changed (bool)),
            show_history_action,         SLOT   (setChecked (bool)));
   connect (show_file_browser_action,    SIGNAL (toggled (bool)),
            _files_dock_widget,          SLOT   (setVisible (bool)));
@@ -1070,10 +1050,6 @@
            this,                        SLOT   (open_file (QString)));
   connect (_files_dock_widget,          SIGNAL (displayed_directory_changed(QString)),
            this,                        SLOT   (set_current_working_directory(QString)));
-  connect (_history_dock_widget,        SIGNAL (information (QString)),
-           this,                        SLOT   (report_status_message (QString)));
-  connect (_history_dock_widget,        SIGNAL (command_double_clicked (const QString&)),
-           this,                        SLOT   (handle_command_double_clicked (const QString&)));
   connect (this,                        SIGNAL (relay_command_signal (const QString&)),
            &command_window,             SLOT   (relay_command (const QString&)));
   connect (save_workspace_action,       SIGNAL (triggered ()),
@@ -1119,7 +1095,7 @@
 #endif
   addDockWidget (Qt::LeftDockWidgetArea, _files_dock_widget);
   addDockWidget (Qt::LeftDockWidgetArea, _workspace_view);
-  addDockWidget (Qt::LeftDockWidgetArea, _history_dock_widget);
+  addDockWidget (Qt::LeftDockWidgetArea, &history_window);
 
   int win_x = QApplication::desktop()->width();
   int win_y = QApplication::desktop()->height();
@@ -1147,15 +1123,15 @@
 
   connect (_octave_qt_link,
            SIGNAL (set_history_signal (const QStringList&)),
-           _history_dock_widget, SLOT (set_history (const QStringList&)));
+           &history_window, SLOT (set_history (const QStringList&)));
 
   connect (_octave_qt_link,
            SIGNAL (append_history_signal (const QString&)),
-           _history_dock_widget, SLOT (append_history (const QString&)));
+           &history_window, SLOT (append_history (const QString&)));
 
   connect (_octave_qt_link,
            SIGNAL (clear_history_signal (void)),
-           _history_dock_widget, SLOT (clear_history (void)));
+           &history_window, SLOT (clear_history (void)));
 
   connect (_octave_qt_link, SIGNAL (enter_debugger_signal ()),
            this, SLOT (handle_enter_debugger ()));
--- a/libgui/src/main-window.h	Sat Apr 06 16:14:32 2013 -0400
+++ b/libgui/src/main-window.h	Sat Apr 06 16:46:14 2013 -0400
@@ -1,5 +1,6 @@
 /*
 
+Copyright (C) 2013 John W. Eaton
 Copyright (C) 2011-2012 Jacob Dawid
 
 This file is part of Octave.
@@ -20,8 +21,8 @@
 
 */
 
-#ifndef MAINWINDOW_H
-#define MAINWINDOW_H
+#if !defined (main_window_h)
+#define main_window_h 1
 
 // Qt includes
 #include <QtGui/QMainWindow>
@@ -72,6 +73,7 @@
   void settings_changed (const QSettings *);
   void relay_command_signal (const QString&);
   void focus_command_window_signal (void);
+  void focus_history_window_signal (void);
 
 public slots:
   void report_status_message (const QString& statusMessage);
@@ -102,12 +104,11 @@
   void handle_command_double_clicked (const QString& command);
 
   void focus_command_window (void);
-  void focus_command_history ();
+  void focus_history_window (void);
   void focus_current_directory ();
   void focus_workspace ();
   void focus_editor ();
   void focus_documentation ();
-  void handle_command_history_visible (bool);
   void handle_current_directory_visible (bool);
   void handle_workspace_visible (bool);
   void handle_editor_visible (bool);
@@ -156,6 +157,8 @@
 
   terminal_dock_widget command_window;
 
+  history_dock_widget history_window;
+
 #ifdef HAVE_QSCINTILLA
   file_editor_interface *   _file_editor;
 #endif
@@ -172,7 +175,6 @@
 
   // Dock widgets.
   workspace_view *          _workspace_view;
-  history_dock_widget *     _history_dock_widget;
   files_dock_widget *       _files_dock_widget;
   documentation_dock_widget*_documentation_dock_widget;