Mercurial > hg > octave-lyh
changeset 16459:cbc39a3d0c42
improve encapsulation of workspace window object
* workspace-view.h, workspace-view.cc
(workspace_view::handle_visibility_changed): Delete.
(workspace_view::workspace_view): Set status tip.
Don't connect workspace_view::visibilityChanged signal to
workspace_view::handle_visibility_changed.
(workspace_view::connect_visibility_changed, workspace_view::focus,
workspace_view::handle_visibility): New functions.
* main-window.h, main-window.cc (main_window::workspace_window):
Rename from _workspace_view. Change all uses.
(main_window::main_window): Initialize it.
(main_window::focus_workspace, main_window::handle_workspace_visible):
Delete.
(main_window::connect_visibility_changed):
Call workspace_window->connect_visibility_changed.
(main_window::construct): Don't create _workspace_view.
Connect workspace_action::triggered directly to workspace_window::focus.
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Sun, 07 Apr 2013 11:52:09 -0400 |
parents | a3513fc13cdb |
children | 4d4e7c6f839d |
files | libgui/src/main-window.cc libgui/src/main-window.h libgui/src/workspace-view.cc libgui/src/workspace-view.h |
diffstat | 4 files changed, 48 insertions(+), 53 deletions(-) [+] |
line wrap: on
line diff
--- a/libgui/src/main-window.cc +++ b/libgui/src/main-window.cc @@ -73,7 +73,8 @@ history_window (new history_dock_widget (this)), file_browser_window (new files_dock_widget (this)), doc_browser_window (new documentation_dock_widget (this)), - editor_window (create_default_editor (this)) + editor_window (create_default_editor (this)), + workspace_window (new workspace_view (this)) { // We have to set up all our windows, before we finally launch octave. construct (); @@ -88,6 +89,7 @@ delete file_browser_window; delete doc_browser_window; delete editor_window; + delete workspace_window; // Clean up all dynamically created objects to ensure they are // deleted before this main_window is. Otherwise, some will be @@ -98,8 +100,6 @@ octave_link::connect_link (0); delete _octave_qt_link; - - delete _workspace_view; } void @@ -278,7 +278,7 @@ void main_window::update_workspace (void) { - _workspace_view->model_changed (); + workspace_window->model_changed (); } void @@ -353,28 +353,6 @@ } void -main_window::focus_workspace (void) -{ - if (!_workspace_view->isVisible ()) - { - _workspace_view->setVisible (true); - } - - _workspace_view->setFocus (); - _workspace_view->activateWindow (); - _workspace_view->raise (); -} - - -void -main_window::handle_workspace_visible (bool visible) -{ - // if changed to visible and widget is not floating - if (visible && !_workspace_view->isFloating ()) - focus_workspace (); -} - -void main_window::handle_enter_debugger (void) { setWindowTitle ("Octave (Debugging)"); @@ -543,9 +521,7 @@ #ifdef HAVE_QSCINTILLA editor_window->connect_visibility_changed (); #endif - - connect (_workspace_view, SIGNAL (visibilityChanged (bool)), - this, SLOT (handle_workspace_visible (bool))); + workspace_window->connect_visibility_changed (); } @@ -556,14 +532,10 @@ _closing = false; // flag for editor files when closed setWindowIcon (QIcon (":/actions/icons/logo.png")); - // Setup dockable widgets and the status bar. - _workspace_view = new workspace_view (this); - - _workspace_view->setModel (_workspace_model); - _workspace_view->setStatusTip (tr ("View the variables in the active workspace.")); + workspace_window->setModel (_workspace_model); connect (_workspace_model, SIGNAL (model_changed ()), - _workspace_view, SLOT (model_changed ())); + workspace_window, SLOT (model_changed ())); // Create and set the central widget. QMainWindow takes ownership of // the widget (pointer) so there is no need to delete the object upon @@ -602,7 +574,7 @@ #endif addDockWidget (Qt::LeftDockWidgetArea, file_browser_window); - addDockWidget (Qt::LeftDockWidgetArea, _workspace_view); + addDockWidget (Qt::LeftDockWidgetArea, workspace_window); addDockWidget (Qt::LeftDockWidgetArea, history_window); int win_x = QApplication::desktop()->width(); @@ -1033,9 +1005,9 @@ show_command_window_action, SLOT (setChecked (bool))); connect (show_workspace_action, SIGNAL (toggled (bool)), - _workspace_view, SLOT (setVisible (bool))); + workspace_window, SLOT (setVisible (bool))); - connect (_workspace_view, SIGNAL (active_changed (bool)), + connect (workspace_window, SIGNAL (active_changed (bool)), show_workspace_action, SLOT (setChecked (bool))); connect (show_history_action, SIGNAL (toggled (bool)), @@ -1068,7 +1040,7 @@ command_window, SLOT (focus ())); connect (workspace_action, SIGNAL (triggered ()), - this, SLOT (focus_workspace ())); + workspace_window, SLOT (focus ())); connect (history_action, SIGNAL (triggered ()), history_window, SLOT (focus ()));
--- a/libgui/src/main-window.h +++ b/libgui/src/main-window.h @@ -104,9 +104,6 @@ void handle_command_double_clicked (const QString& command); - void focus_workspace (void); - void handle_workspace_visible (bool); - void handle_enter_debugger (void); void handle_exit_debugger (void); void debug_continue (void); @@ -184,6 +181,7 @@ files_dock_widget *file_browser_window; documentation_dock_widget *doc_browser_window; file_editor_interface *editor_window; + workspace_view *workspace_window; QMenu *_debug_menu; @@ -202,9 +200,6 @@ QAction *_undo_action; QAction *_redo_action; - // Dock widgets. - workspace_view *_workspace_view; - // Toolbars. QComboBox *_current_directory_combo_box; static const int current_directory_width = 300;
--- a/libgui/src/workspace-view.cc +++ b/libgui/src/workspace-view.cc @@ -37,6 +37,7 @@ setObjectName ("WorkspaceView"); setWindowIcon (QIcon(":/actions/icons/logo.png")); setWindowTitle (tr ("Workspace")); + setStatusTip (tr ("View the variables in the active workspace.")); view = new QTreeView (this); // Create a new tree view. view->setHeaderHidden (false); // Do not show header columns. @@ -71,11 +72,9 @@ view->header ()->restoreState (settings->value("workspaceview/column_state").toByteArray ()); // Connect signals and slots. - connect (this, SIGNAL (visibilityChanged (bool)), - this, SLOT(handle_visibility_changed (bool))); - connect (view, SIGNAL (collapsed (QModelIndex)), this, SLOT (collapse_requested (QModelIndex))); + connect (view, SIGNAL (expanded (QModelIndex)), this, SLOT (expand_requested (QModelIndex))); @@ -98,10 +97,10 @@ } void -workspace_view::handle_visibility_changed (bool visible) +workspace_view::connect_visibility_changed (void) { - if (visible) - emit active_changed (true); + connect (this, SIGNAL (visibilityChanged (bool)), + this, SLOT (handle_visibility (bool))); } void @@ -227,3 +226,22 @@ show(); // make it visible again since setWindowFlags hides it } } + +void +workspace_view::focus (void) +{ + if (! isVisible ()) + setVisible (true); + + setFocus (); + activateWindow (); + raise (); +} + +void +workspace_view::handle_visibility (bool visible) +{ + // if changed to visible and widget is not floating + if (visible && ! isFloating ()) + focus (); +}
--- a/libgui/src/workspace-view.h +++ b/libgui/src/workspace-view.h @@ -32,20 +32,30 @@ class workspace_view : public QDockWidget { Q_OBJECT - public: + +public: + workspace_view (QWidget * parent = 0); + ~workspace_view (); + void connect_visibility_changed (void); + public: void setModel (workspace_model *model) { view->setModel (model); } public slots: - void handle_visibility_changed (bool visible); + void model_changed (); + /** Slot when floating property changes */ void top_level_changed (bool floating); + void focus (void); + + void handle_visibility (bool visible); + signals: /** Custom signal that tells if a user has clicke away that dock widget. */ void active_changed (bool active);