diff libgui/src/variable-editor.h @ 24697:21d6d80ed427

refactor variable editor model internal representation (bug #53054) * variable-editor-model.h, variable-editor-model.cc: Rewrite to use pointer to base class instead of opaque pointer to implementation. This change will allow simpler classes to manage editing of each type of data we can edit (numeric array, string, cell, scalar struct, vector struct, 2-d struct array). * variable-editor.h, variable-editor.cc: Use stacked widget to allow switching between a table-based edit view (for variables that may be edited) and a text-edit based view (for variables that we can't edit).
author John W. Eaton <jwe@octave.org>
date Tue, 06 Feb 2018 06:20:08 -0500
parents 9b4edcc62936
children 28211444585e
line wrap: on
line diff
--- a/libgui/src/variable-editor.h	Mon Feb 05 14:44:39 2018 -0600
+++ b/libgui/src/variable-editor.h	Tue Feb 06 06:20:08 2018 -0500
@@ -33,12 +33,53 @@
 
 class octave_value;
 
+class QModelIndex;
+class QStackedWidget;
 class QTabWidget;
+class QTableView;
+class QTextEdit;
 class QToolBar;
-class QMainWindow;
-class QTableView;
-class QModelIndex;
+
+class variable_editor_model;
+
+class var_editor_tab : public QWidget
+{
+  Q_OBJECT
+
+public:
+
+  var_editor_tab (QStackedWidget *widget_stack, QWidget *p = nullptr)
+    : QWidget (p), m_widget_stack (widget_stack)
+  { }
+
+  ~var_editor_tab (void) = default;
+
+  QTableView * get_edit_view (void) const;
+  QTextEdit * get_disp_view (void) const;
+
+  void set_edit_view (QTableView *);
+  void set_disp_view (QTextEdit *);
 
+  void set_model (variable_editor_model *model)
+  {
+    m_model = model;
+  }
+
+  bool has_focus (void) const;
+
+public slots:
+
+  void set_editable (bool);
+
+private:
+
+  variable_editor_model *m_model;
+
+  QStackedWidget *m_widget_stack;
+
+  int m_edit_view_idx;
+  int m_disp_view_idx;
+};
 
 // Subclassed QTabWidget for using custom tabbar
 
@@ -53,6 +94,11 @@
   ~var_editor_tab_widget (void) = default;
 
   QTabBar * tabBar (void) const;
+
+  bool current_tab_has_focus (void) const;
+
+  QTextEdit *get_disp_view (void) const;
+  QTableView *get_edit_view (void) const;
 };
 
 
@@ -76,6 +122,12 @@
 
   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);
@@ -140,6 +192,8 @@
 
   void command_requested (const QString& cmd);
 
+  void refresh_signal (void);
+
 private:
 
   QAction * add_action (QMenu *menu, const QIcon& icon, const QString& text,
@@ -151,7 +205,7 @@
 
   QToolBar *m_tool_bar;
 
-  QTabWidget *m_tab_widget;
+  var_editor_tab_widget *m_tab_widget;
 
   int m_default_width;