diff libgui/src/variable-editor.h @ 24812:ed9ba20d6ed3

Make the variable editor multi-panel via a QMainWindow layout (bug #53046) * main-window.h: Remove <QMdiArea> and <QMdiSubWindow> from header list. * octave-dock-widget.h (label_dock_widget): Added. New intermediate class that contains the features related only to the thin header for dock/undock and close. Namely m_icon_size, m_title_widget, m_dock_button, m_close_button, m_dock_action and m_close_action and member function set_title(). (octave_dock_widget): Removed some elements for label_dock_widget class and inherit that object. * octave-dock-widget.cc (label_dock_widget::label_dock_widget): Constructor of new class selecting a few initialization from octave_dock_widget related to thin header and no settings code and no connections at this level. Set the style sheet of the m_dock_button and m_close_button to transparent. (label_dock_widget::set_title): Moved from octave_dock_widget without modification. (octave_dock_widget::octave_dock_widget): Select code moved to label_dock_widget constructor. (octave_dock_widget::set_title): Moved to label_dock_widget class. * variable-editor-model.h: (variable_editor_model::edit_variable_signal): New signal for a model to launch a new variable_dock_widget if a sub-element needs it. (variable_editor_model::update_data): Changed from private to public. (variable_editor_model::update_data_cache): Ditto. (variable_editor_model::double_click): Moved here from variable_editor to make more modular. * variable-editor-model.cc (variable_editor_model::setData): Change the test on input variable for QString to be anything that can be converted to a QString, e.g., numbers. (variable_editor_model::update_data): Remove obsolete emitted signal maybe_resize_columns_signal(). (variable_editor_model::double_click): Moved from variable_editor. Remove the indirect reference to table then model. * variable-editor.h (var_editor_tab): Remove. A tab widget is no longer used. (variable_dock_widget): Added. A new class inherting label_dock_widget that is merely a container, holding the stack of editable (QTableView) and non-editable (QTextEdit) of variable views. (variable_dock_widget::variable_focused_signal): Added. New signal to let variable_editor know an object or its proxy has come into focus. (variable_dock_widget::handle_focus_change): Added. Slot to connect to QApplication::focusChanged(). (variable_dock_widget::closeEvent): Added. Override any intermediate class and go back to the base QDockWidget behavior. (variable_dock_widget::change_floating): Simple private routine changing the toggling the float state. (variable_dock_widget::change_existence): Simple private routine calling base routine close(). (variable_dock_widget::toplevel_change): Added. Private slot to respond to dock/undock signal. Changes the icon, restores focus, and also makes the first floated display magnified for fast viewing. (variable_editor_stack::variable_editor_stack): New class that holds and manages a variable_editor_model, variable_editor_view (QTableView) and a display view (QTextEdit). (variable_editor_stack::edit_view): Inline function that returns pointer to a variable_editor_view. (variable_editor_stack::disp_view): Inline function that returns pointer to a QTableView. (variable_editor_stack::set_editable): Moved here from var_editor_tab class. Set the view according to whether the variable can be put into table form. (variable_editor_stack::levelUp (void); Moved here from variable_editor class, where it was called up(). Open one higher level of octave value, e.g., cell array, structure. (variable_editor_stack::save (void): Moved here from variable_editor class. General save of variable not related to how it is viewed. (variable_editor_stack::make_disp_view): Moved here from variable_editor class. Only a few small configurations with no model input. (Done later.) (variable_edit_view::variable_edit_view): Added. New class derived from QTableView that holds the majority of functionality moved from the variable_editor class related to table copy, paste, etc. In the constructor is about half of what used to be in variable_editor::make_edit_view(). (variable_edit_view::setModel): Added. Override of the virtual function holding about half of what used to be in variable_editor::make_edit_view(). (variable_edit_view::command_signal): Added. Signal to connect to the variable_editor's mechanism for sending Octave command back to core. (variable_editor_view::range_selected): New method that provides a list of range values for the table used for constructing commands elsewhere. (variable_editor_view::selected_to_octave): Moved from variable_editor class and simplify by calling range_selected(). (variable_editor_view::selected_command_requested): Added. Like function command_requested(), but chooses just the selected data in the table. (variable_editor_view::delete_selected): Moved from variable_editor. Removes a level of indirection, but otherwise pretty much the same. (variable_editor_view::clearContent): Ditto. (variable_editor_view::cutClipboard): Ditto. (variable_editor_view::copyClipboard): Ditto. (variable_editor_view::pasteClipboard): Ditto. (variable_editor_view::pasteTableClipboard): Ditto. (variable_editor_view::handle_horizontal_scroll_action): Ditto. (variable_editor_view::handle_vertical_scroll_action): Ditto. (variable_editor_view::createContextMenu): Ditto. (variable_editor_view::createColumnMenu): Ditto. (variable_editor_view::createRowMenu): Ditto. (variable_editor_view::): Ditto. (variable_editor_view::): Ditto. (variable_editor_view::): Ditto. (variable_editor_view::): Ditto. (variable_editor_view::add_edit_actions): The similar portions of the various context menus that can be reused. (HoverToolButton): Very short class derived from QToolButton whose added feature is to capture the focused variable_dock_widget when the mouse is hovered over the button. (ReturnFocusToolButton): Similarly short class inherting HoverToolButton that adds the feature of restoring the focus before activating its associated action. (ReturnFocusMenu): Analogous to ReturnFocusToolButton, but based on QMenu. This is placed on a HoverToolButton. (variable_editor): Added QStrings m_current_focus_vname and m_hovered_focus_vname to keep track of variable that most recently focused. Removed m_close_action, m_close_others_action and m_close_all_action QActions since tab widget no longer used. Same for m_tab_widget, m_tab_bar. Change QWidget pointer m_container to QMainWindow pointer m_main. (variable_editor::has_focus): Removed. Using a proxy obviates this function. (variable_editor::edit_variable): Change from private to public. (variable_editor::variable_destroyed): New slot. Connect to variable_dock_widget to keep track of when to check if toolbar still valid. (variable_editor::variable_focused): New slot. Connect to variable_dock_widget() to keep track of most recent focused variable window. (variable_editor::record_hovered_focus_variable): New slot. Connect to variable_dock_widget toolbar's ReturnFocusToolButton and ReturnFocusMenu for when mouse cursor hovers. (variable_editor::restore_hovered_focus_variable): New slot. Connect to variable_dock_widget toolbar's ReturnFocusToolButton and ReturnFocusMenu for prior to acting in order to return to active window/focus when hovered. (variable_editor::request_close_tab): Removed. No longer needed. (variable_editor::request_close_other_tabs): Ditto. (variable_editor::request_close_all_tabs): Ditto. (variable_editor::close_tab): Ditto. (variable_editor::contextmenu_requested): Ditto. (variable_editor::columnmenu_requested): Ditto. (variable_editor::rowmenu_requested): Ditto. (variable_editor::double_click): Moved to variable_editor_model class. (variable_editor::up): Renamed levelUp and moved to variable_editor_view class. (variable_editor::clearContent): Moved to variable_dock_view class. (variable_editor::transposeContent): Ditto. (variable_editor::delete_selected): Ditto. (variable_editor::relay_command): Renamed to relay_selected_command() for clarity. (variable_editor::clear_content_signal): Added. New signal to broadcast to the variable_dock_widgets' associated slot. (variable_editor::copy_clipboard_signal): Ditto. (variable_editor::paste_clipboard_signal): Ditto. (variable_editor::paste_table_clipboard_signal): Ditto. (variable_editor::context_menu_signal): Ditto. (variable_editor::column_menu_signal): Ditto. (variable_editor::row_menu_signal): Ditto. (variable_editor::save_signal): Ditto. (variable_editor::delete_selected_signal): Ditto. (variable_editor::selected_command_signal): Ditto. (variable_editor::enable_actions): Removed. Too short of function otherwise. (variable_editor::octave_to_coords): Removed, no longer needed. (variable_editor::real_var_name): Removed, no more KDE problem in tab names because tab widget no longer used. Names stored in most QObject's objectName. (variable_editor::selected_to_octave): Moved to variable_editor_view class. (variable_editor::add_tool_bar_button): Convenience function for repetitive tool bar button construction. * variable-editor.cc: Add <QMdiArea> and <QScreen> to list of headers. Remove <QStackedWidget> from list. (make_plot_mapper): Added. Reusable, list-based convenience function. Adds a plot title that also uses the %1 argument. (variable_dock_widget::variable_dock_widget): Added. Constructor that sets a couple attributes and connects the header dock actions inherited from label_dock_widget to appropriate slots. (variable_dock_widget::handle_focus_change): Added. Connected to QApplication's focusChanged() to set/clear the blue background of the name label and keep track of most recent focused variable_dock_widget. (variable_dock_widget::change_floating): Added. New slot one line long. (variable_dock_widget::change_existence): Added. New slot that calls close() which is configurable by Qt::WA_DeleteOnClose parameter. For now, "close" means "hide". (variable_dock_widget::toplevel_change): Added. Changes the dock/undock icon, but also its tooltip. Also changes the focus to the new window. First time enlarged is very big to simulate "maximize", i.e., better temporary view of this variable. (variable_editor_stack::set_editable): Moved from var_editor_tab object and made more generic so that it can be put in any container. Ensure that the container has the active widget as its focus proxy. (variable_editor_view::closeEvent, etc.): See variable-editor.h for list of functions that are moved from variable_editor, often using findChild() or findChildren() for convenience rather than m_widget_stack or m_table_widget. (variable_editor::variable_editor): Call initializer QMainWindow() and QToolBar() similar to what it was once like. Also initialize m_current_focus_vname and m_hovered_focus_vname to "". Add toolbar to m_main. Use an MDI area for central widget of m_main. Remove all tab bar layout. Set the window's options to QMainWindow::AllowNestedDocks and QMainWindow::VerticalTabs. (variable_editor::edit_variable): Use findChild() to look for variable_dock_widget of requested name. If so, bring into focus and return. If continue, create new variable_dock_widget "page" and place in m_main. Set page's objectName to the variable name. Connect signals/slots to "page" for controlling the blue background of variable name. Remove extra layer of QVBoxLayout container, now replaced by creation of a variable_editor_stack object. Set stack widget's objectName to variable name. Get edit_view from variable_editor_stack's edit_view() method. Set edit_view's objectName to variable name. Make myriad connections to edit_view and variable_editor. Create a variable_edit_model and pass that on to variable_editor_view via setModel(). Make all the various connections amongst these objects. Supply a title to the label_dock_widget and set the text of that title to the variable's name. Use findChildren to enable the toolbar on the first variable, similar to the way it was previous. After creating variable_dock_widget, set its allowed areas to Qt::LeftDockWidgetArea and Qt::RightDockWidgetArea then place it in the main window's left dock area. (variable_editor::make_disp_view): Moved to variable_editor_stack class. (variable_editor::make_edit_view): Absorbed in variable_editor_view constructor and setModel() methods. (variable_editor::has_focus): Removed. Not needed, setting focus proxy appears to obviate this. (variable_editor::notice_settings): Took out shortcut_manager shortcuts because these tab actions no longer needed. Also, these shortcuts can possibly be handled via the QAction shortcut key. (variable_editor::add_tool_bar_button): Added. Mimic the m_tool_bar->addAction() construct used in construct_tool_bar(). (variable_editor::construct_tool_bar): Utilize make_plot_mapper(). Utilize add_tool_bar_button() to place ReturnFocusToolButton objects in the QToolbar. Give an example of adding a short-cut key to the Save QAction. Use a HoverToolButton with a ReturnFocusMenu object similar to existing construction. At the end, utilize findChildren() to loop through all the objects needing connections to slots rather than program individually.
author Daniel J Sebald <daniel.sebald@ieee.org>
date Mon, 19 Feb 2018 20:13:15 -0600
parents ed2d9ef336a7
children 0f6a261ab144
line wrap: on
line diff
--- a/libgui/src/variable-editor.h	Thu Mar 01 11:18:44 2018 -0500
+++ b/libgui/src/variable-editor.h	Mon Feb 19 20:13:15 2018 -0600
@@ -27,6 +27,8 @@
 
 #include <QHeaderView>
 #include <QSettings>
+#include <QStackedWidget>
+#include <QTableView>
 
 #include "octave-dock-widget.h"
 #include "tab-bar.h"
@@ -34,92 +36,197 @@
 class octave_value;
 
 class QModelIndex;
-class QStackedWidget;
-class QTabWidget;
-class QTableView;
 class QTextEdit;
 class QToolBar;
 
 class variable_editor_model;
+class variable_editor_view;
 
-class var_editor_tab : public QWidget
+// The individual variable subwindow class
+
+class variable_dock_widget : public label_dock_widget
+{
+  Q_OBJECT
+
+public:
+
+  variable_dock_widget (QWidget *p = nullptr);
+
+signals:
+
+  void variable_focused_signal (const QString& name);
+
+protected:
+
+  virtual void closeEvent (QCloseEvent *e);
+
+public slots:
+
+  void handle_focus_change (QWidget *old, QWidget *now);
+
+private slots:
+
+  void change_floating (bool);
+
+  void change_existence (bool);
+
+  void toplevel_change (bool);
+
+protected:
+
+  bool m_initial_float;
+};
+
+class variable_editor_stack : public QStackedWidget
+{
+  Q_OBJECT
+
+public:
+
+  variable_editor_stack (QWidget *p = nullptr);
+
+  variable_editor_view *edit_view (void) {return m_edit_view;};
+
+  QTextEdit *disp_view (void) {return m_disp_view;};
+
+signals:
+
+  void command_signal (const QString& cmd);
+
+  void edit_variable_signal (const QString& name, const octave_value& val);
+
+public slots:
+
+  void set_editable (bool editable);
+
+  void levelUp (void);
+
+  void save (void);
+
+private:
+
+  QTextEdit *make_disp_view (QWidget *parent);
+
+  variable_editor_view *m_edit_view;
+
+  QTextEdit *m_disp_view;
+};
+
+
+class variable_editor_view : public QTableView
 {
   Q_OBJECT
 
 public:
 
-  var_editor_tab (QStackedWidget *widget_stack, QWidget *p = nullptr)
-    : QWidget (p), m_model (nullptr), m_widget_stack (widget_stack),
-      m_edit_view_idx (-1), m_disp_view_idx (-1)
-  { }
+  variable_editor_view (QWidget *p = nullptr);
 
-  ~var_editor_tab (void) = default;
-
-  // No copying!
-
-  var_editor_tab (const var_editor_tab&) = delete;
-
-  var_editor_tab& operator = (const var_editor_tab&) = delete;
+  void setModel (QAbstractItemModel *model);
 
-  QTableView * get_edit_view (void) const;
-  QTextEdit * get_disp_view (void) const;
-
-  void set_edit_view (QTableView *);
-  void set_disp_view (QTextEdit *);
+signals:
 
-  void set_model (variable_editor_model *model)
-  {
-    m_model = model;
-  }
+  void command_signal (const QString& cmd);
 
-  bool has_focus (void) const;
-
-  void keyPressEvent (QKeyEvent *event);
+  void add_edit_actions_signal (QMenu *menu, const QString& qualifier_string);
 
 public slots:
 
-  void set_editable (bool);
+  void createVariable (void);
+
+  void transposeContent (void);
+
+  QList<int> range_selected (void);
+
+  void delete_selected (void);
+
+  void clearContent (void);
+
+  void cutClipboard (void);
+
+  void copyClipboard (void);
+
+  void pasteClipboard (void);
+
+  void pasteTableClipboard (void);
 
   void handle_horizontal_scroll_action (int action);
 
   void handle_vertical_scroll_action (int action);
 
+  void createContextMenu (const QPoint& pt);
+
+  void createColumnMenu (const QPoint& pt);
+
+  void createRowMenu (const QPoint& pt);
+
+  // Convert selection to an Octave expression.
+  QString selected_to_octave (void);
+
+  void selected_command_requested (const QString& cmd);
+
 private:
 
-  variable_editor_model *m_model;
+  void add_edit_actions (QMenu *menu, const QString& qualifier_string);
 
-  QStackedWidget *m_widget_stack;
-
-  int m_edit_view_idx;
-  int m_disp_view_idx;
+  variable_editor_model *m_var_model;
 };
 
-// Subclassed QTabWidget for using custom tabbar
+// Gadgets to keep track and restore what variable window
+// was in focus just prior to selecting something on the
+// menu bar
 
-class var_editor_tab_widget : public QTabWidget
+class HoverToolButton : public QToolButton
 {
   Q_OBJECT
 
 public:
 
-  var_editor_tab_widget (QWidget *p);
-
-  ~var_editor_tab_widget (void) = default;
+  HoverToolButton (QWidget *parent = nullptr);
 
-  // No copying!
+signals:
 
-  var_editor_tab_widget (const var_editor_tab_widget&) = delete;
+  void hovered_signal (void);
 
-  var_editor_tab_widget& operator = (const var_editor_tab_widget&) = delete;
-
-  tab_bar * get_tab_bar (void) const;
+  void popup_shown_signal (void);
 
-  bool current_tab_has_focus (void) const;
+protected:
 
-  QTextEdit *get_disp_view (void) const;
-  QTableView *get_edit_view (void) const;
+  bool eventFilter (QObject *obj, QEvent *ev);
 };
 
+class ReturnFocusToolButton : public HoverToolButton
+{
+  Q_OBJECT
+
+public:
+
+  ReturnFocusToolButton (QWidget *parent = nullptr);
+
+signals:
+
+  void about_to_activate (void);
+
+protected:
+
+  bool eventFilter (QObject *obj, QEvent *ev);
+};
+
+class ReturnFocusMenu : public QMenu
+{
+  Q_OBJECT
+
+public:
+
+  ReturnFocusMenu (QWidget *parent = nullptr);
+
+signals:
+
+  void about_to_activate (void);
+
+protected:
+
+  bool eventFilter (QObject *obj, QEvent *ev);
+};
 
 // The variable editor class
 
@@ -139,50 +246,34 @@
 
   variable_editor& operator = (const variable_editor&) = delete;
 
-  void edit_variable (const QString& name, const octave_value& val);
-
-  QTableView *make_edit_view (var_editor_tab *page,
-                              variable_editor_model *model);
-
-  QTextEdit *make_disp_view (var_editor_tab *page,
-                             variable_editor_model *model);
-
   void refresh (void);
 
-  bool has_focus (void);
-
   static QList<QColor> default_colors (void);
 
   static QStringList color_names (void);
 
 public slots:
 
-  void callUpdate (const QModelIndex&,const QModelIndex&);
+  void callUpdate (const QModelIndex&, const QModelIndex&);
 
   void notice_settings (const QSettings *);
 
-protected slots:
+  void edit_variable (const QString& name, const octave_value& val);
+
+  void variable_destroyed (QObject *obj);
+
+  void variable_focused (const QString& name);
 
-  void request_close_tab (bool);
-  void request_close_other_tabs (bool);
-  void request_close_all_tabs (bool);
+  void record_hovered_focus_variable (void);
+
+  void restore_hovered_focus_variable (void);
+
+protected slots:
 
   void closeEvent (QCloseEvent *);
 
-  void closeTab (int idx);
-
-  void contextmenu_requested (const QPoint& pt);
-
-  void columnmenu_requested (const QPoint& pt);
-
-  void rowmenu_requested (const QPoint& pt);
-
-  void double_click (const QModelIndex& idx);
-
   void save (void);
 
-  void clearContent (void);
-
   void cutClipboard (void);
 
   void copyClipboard (void);
@@ -191,17 +282,11 @@
 
   void pasteTableClipboard (void);
 
-  void createVariable (void);
-
-  void transposeContent (void);
-
-  void up (void);
-
-  void delete_selected (void);
+  void levelUp (void);
 
   // Send command to Octave interpreter.
   // %1 in CMD is replaced with the value of selected_to_octave.
-  void relay_command (const QString& cmd);
+  void relay_selected_command (const QString& cmd);
 
 signals:
 
@@ -209,25 +294,35 @@
 
   void finished (void);
 
-  void command_requested (const QString& cmd);
+  void command_signal (const QString& cmd);
 
   void refresh_signal (void);
 
+  void clear_content_signal (void);
+
+  void copy_clipboard_signal (void);
+
+  void paste_clipboard_signal (void);
+
+  void paste_table_clipboard_signal (void);
+
+  void level_up_signal (void);
+
+  void save_signal (void);
+
+  void delete_selected_signal (void);
+
+  void selected_command_signal (const QString& cmd);
+
 private:
 
   QAction * add_action (QMenu *menu, const QIcon& icon, const QString& text,
                         const char *member);
 
-  void enable_actions (void);
-
-  QWidget *m_container;
+  QMainWindow *m_main;
 
   QToolBar *m_tool_bar;
 
-  var_editor_tab_widget *m_tab_widget;
-
-  tab_bar *m_tab_bar;
-
   int m_default_width;
 
   int m_default_height;
@@ -248,21 +343,16 @@
 
   QList<QColor> m_table_colors;
 
-  QAction *m_close_action;
-  QAction *m_close_others_action;
-  QAction *m_close_all_action;
-
-  QList<int> octave_to_coords (QString&);
-
-  // Get the real variable name from the tab text
-  QString real_var_name (int index);
-
-  // Convert selection to an Octave expression.
-  QString selected_to_octave (void);
-
   void update_colors (void);
 
+  QAction *add_tool_bar_button (const QIcon &icon, const QString &text,
+                                const QObject *receiver, const char *member);
+
   void construct_tool_bar (void);
+
+  QString m_current_focus_vname;
+
+  QString m_hovered_focus_vname;
 };
 
 #endif