Mercurial > hg > octave-lojdl
changeset 16463:8e2a853cdd7d
derive workspace_view from octave_dock_widget; style fixes
* workspace-view.h, workspace-view.cc (workspace_view): Derive from
octave_dock_widget. Delete functions that we now inherit. Style
fixes.
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Sun, 07 Apr 2013 16:08:15 -0400 |
parents | 8c666c7b0e5d |
children | 328048fd43b8 |
files | libgui/src/workspace-view.cc libgui/src/workspace-view.h |
diffstat | 2 files changed, 62 insertions(+), 89 deletions(-) [+] |
line wrap: on
line diff
--- a/libgui/src/workspace-view.cc +++ b/libgui/src/workspace-view.cc @@ -1,5 +1,6 @@ /* +Copyright (C) 2013 John W. Eaton Copyright (C) 2011-2012 Jacob Dawid This file is part of Octave. @@ -33,19 +34,20 @@ #include <QMenu> workspace_view::workspace_view (QWidget *p) - : QDockWidget (p) + : octave_dock_widget (p) { 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. - view->setAlternatingRowColors (true); // Activate alternating row colors. - view->setAnimated (false); // Deactivate animations because of strange glitches. - view->setTextElideMode (Qt::ElideRight);// Elide text to the right side of the cells. - view->setWordWrap (false); // No wordwrapping in cells. + view = new QTreeView (this); + + view->setHeaderHidden (false); + view->setAlternatingRowColors (true); + view->setAnimated (false); + view->setTextElideMode (Qt::ElideRight); + view->setWordWrap (false); view->setContextMenuPolicy (Qt::CustomContextMenu); // Set an empty widget, so we can assign a layout to it. @@ -65,13 +67,18 @@ // FIXME -- what should happen if settings is 0? - _explicit_collapse.local = settings->value ("workspaceview/local_collapsed", false).toBool (); - _explicit_collapse.global = settings->value ("workspaceview/global_collapsed", false).toBool ();; - _explicit_collapse.persistent = settings->value ("workspaceview/persistent_collapsed", false).toBool ();; + _explicit_collapse.local + = settings->value ("workspaceview/local_collapsed", false).toBool (); + + _explicit_collapse.global + = settings->value ("workspaceview/global_collapsed", false).toBool (); + + _explicit_collapse.persistent + = settings->value ("workspaceview/persistent_collapsed", false).toBool (); // Initialize column order and width of the workspace - view->header ()->restoreState (settings->value("workspaceview/column_state").toByteArray ()); + view->header ()->restoreState (settings->value ("workspaceview/column_state").toByteArray ()); // Connect signals and slots. connect (view, SIGNAL (collapsed (QModelIndex)), @@ -88,30 +95,28 @@ connect (this, SIGNAL (command_requested (const QString&)), p, SLOT (handle_command_double_clicked(const QString&))); - - // topLevelChanged is emitted when floating property changes (floating = true) - connect (this, SIGNAL (topLevelChanged(bool)), this, SLOT(top_level_changed(bool))); - } -workspace_view::~workspace_view () +workspace_view::~workspace_view (void) { QSettings *settings = resource_manager::get_settings (); - settings->setValue("workspaceview/local_collapsed", _explicit_collapse.local); - settings->setValue("workspaceview/global_collapsed", _explicit_collapse.global); - settings->setValue("workspaceview/persistent_collapsed", _explicit_collapse.persistent); - settings->setValue("workspaceview/column_state", view->header ()->saveState ()); + + settings->setValue ("workspaceview/local_collapsed", + _explicit_collapse.local); + + settings->setValue ("workspaceview/global_collapsed", + _explicit_collapse.global); + + settings->setValue ("workspaceview/persistent_collapsed", + _explicit_collapse.persistent); + + settings->setValue("workspaceview/column_state", + view->header ()->saveState ()); + settings->sync (); } void -workspace_view::connect_visibility_changed (void) -{ - connect (this, SIGNAL (visibilityChanged (bool)), - this, SLOT (handle_visibility (bool))); -} - -void workspace_view::model_changed () { QAbstractItemModel *m = view->model (); @@ -136,23 +141,20 @@ QModelIndex global_model_index = m->index (1, 0); QModelIndex persistent_model_index = m->index (2, 0); - if (_explicit_collapse.local) { + if (_explicit_collapse.local) view->collapse (local_model_index); - } else { + else view->expand (local_model_index); - } - if (_explicit_collapse.global) { + if (_explicit_collapse.global) view->collapse (global_model_index); - } else { + else view->expand (global_model_index); - } - if (_explicit_collapse.persistent) { + if (_explicit_collapse.persistent) view->collapse (persistent_model_index); - } else { + else view->expand (persistent_model_index); - } } void @@ -177,8 +179,10 @@ if (item_data[0] == "Local") _explicit_collapse.local = true; + if (item_data[0] == "Global") _explicit_collapse.global = true; + if (item_data[0] == "Persistent") _explicit_collapse.persistent = true; } @@ -205,8 +209,10 @@ if (item_data[0] == "Local") _explicit_collapse.local = false; + if (item_data[0] == "Global") _explicit_collapse.global = false; + if (item_data[0] == "Persistent") _explicit_collapse.persistent = false; } @@ -214,7 +220,8 @@ void workspace_view::item_double_clicked (QModelIndex) { - // TODO: Implement opening a dialog that allows the user to change a variable in the workspace. + // TODO: Implement opening a dialog that allows the user to change a + // variable in the workspace. } void @@ -224,36 +231,6 @@ QDockWidget::closeEvent (e); } -// slot for signal that is emitted when floating property changes -void -workspace_view::top_level_changed (bool floating) -{ - if(floating) - { - setWindowFlags(Qt::Window); // make a window from the widget when floating - 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 (); -} - void workspace_view::contextmenu_requested (const QPoint& pos) { @@ -291,7 +268,7 @@ void workspace_view::handle_contextmenu_plot (void) { - relay_contextmenu_command("figure;\nplot"); + relay_contextmenu_command ("figure;\nplot"); } void
--- a/libgui/src/workspace-view.h +++ b/libgui/src/workspace-view.h @@ -1,5 +1,6 @@ /* +Copyright (C) 2013 John W. Eaton Copyright (C) 2011-2012 Jacob Dawid This file is part of Octave. @@ -20,16 +21,16 @@ */ -#ifndef WORKSPACEVIEW_H -#define WORKSPACEVIEW_H +#if !defined (workspace_view_h) +#define workspace_view_h 1 -#include <QDockWidget> #include <QTreeView> #include <QSemaphore> +#include "octave-dock-widget.h" #include "workspace-model.h" -class workspace_view : public QDockWidget +class workspace_view : public octave_dock_widget { Q_OBJECT @@ -37,9 +38,7 @@ workspace_view (QWidget * parent = 0); - ~workspace_view (); - - void connect_visibility_changed (void); + ~workspace_view (void); public: @@ -47,34 +46,31 @@ public slots: - void model_changed (); - - /** Slot when floating property changes */ - void top_level_changed (bool floating); - - void focus (void); - - void handle_visibility (bool visible); + void model_changed (void); signals: - /** Custom signal that tells if a user has clicke away that dock widget. */ - void active_changed (bool active); + /** signal that user had requested a command on a variable */ void command_requested (const QString& cmd); protected: + void closeEvent (QCloseEvent *event); protected slots: + void collapse_requested (QModelIndex index); void expand_requested (QModelIndex index); void item_double_clicked (QModelIndex index); void contextmenu_requested (const QPoint& pos); + // context menu slots - void handle_contextmenu_disp (); - void handle_contextmenu_plot (); - void handle_contextmenu_stem (); + void handle_contextmenu_disp (void); + void handle_contextmenu_plot (void); + void handle_contextmenu_stem (void); + private: + void relay_contextmenu_command (const QString& cmdname); QTreeView *view; @@ -87,4 +83,4 @@ } _explicit_collapse; }; -#endif // WORKSPACEVIEW_H +#endif