GNU Octave  6.2.0
A high-level interpreted language, primarily intended for numerical computations, mostly compatible with Matlab
variable-editor-model.h
Go to the documentation of this file.
1 ////////////////////////////////////////////////////////////////////////
2 //
3 // Copyright (C) 2013-2021 The Octave Project Developers
4 //
5 // See the file COPYRIGHT.md in the top-level directory of this
6 // distribution or <https://octave.org/copyright/>.
7 //
8 // This file is part of Octave.
9 //
10 // Octave is free software: you can redistribute it and/or modify it
11 // under the terms of the GNU General Public License as published by
12 // the Free Software Foundation, either version 3 of the License, or
13 // (at your option) any later version.
14 //
15 // Octave is distributed in the hope that it will be useful, but
16 // WITHOUT ANY WARRANTY; without even the implied warranty of
17 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 // GNU General Public License for more details.
19 //
20 // You should have received a copy of the GNU General Public License
21 // along with Octave; see the file COPYING. If not, see
22 // <https://www.gnu.org/licenses/>.
23 //
24 ////////////////////////////////////////////////////////////////////////
25 
26 #if ! defined (octave_variable_editor_model_h)
27 #define octave_variable_editor_model_h 1
28 
29 #include <QAbstractTableModel>
30 #include <QMap>
31 #include <QString>
32 
33 #include "qt-interpreter-events.h"
34 
35 #include "ov.h"
36 #include "pr-flt-fmt.h"
37 
38 namespace octave
39 {
40  class interpreter;
41 
43  {
44  public:
45 
46  base_ve_model (const QString &expr, const octave_value& val);
47 
48  virtual ~base_ve_model (void) = default;
49 
50  // No copying!
51 
52  base_ve_model (const base_ve_model&) = delete;
53 
55 
56  virtual void maybe_resize_rows (int) { }
57 
58  virtual void maybe_resize_columns (int) { }
59 
60  std::string name (void) const;
61 
62  bool index_ok (const QModelIndex& idx, int& row, int& col) const;
63 
64  virtual bool is_editable (void) const { return true; }
65 
66  virtual octave_value value_at (const QModelIndex& idx) const;
67 
68  int column_width (void) const;
69 
70  int rowCount (const QModelIndex& = QModelIndex ()) const;
71 
72  int columnCount (const QModelIndex& = QModelIndex ()) const;
73 
74  QString edit_display_sub (const octave_value& elt, int role) const;
75 
76  virtual QVariant edit_display (const QModelIndex& idx, int role) const;
77 
78  QVariant data (const QModelIndex& idx, int role = Qt::DisplayRole) const;
79 
80  virtual bool requires_sub_editor (const QModelIndex& idx) const;
81 
82  void set_update_pending (const QModelIndex& idx, const QString& str);
83 
84  bool update_pending (const QModelIndex& idx) const;
85 
86  QString update_pending_data (const QModelIndex& idx) const;
87 
88  void clear_update_pending (void);
89 
90  virtual char quote_char (const QModelIndex& idx) const;
91 
92  virtual QVariant
93  header_data (int section, Qt::Orientation orientation, int role) const;
94 
95  // Return a subscript expression as a string that can be used to
96  // access a sub-element of a data structure. For example "{1,3}"
97  // for cell array element {1,3} or "(2,4)" for array element (2,4).
98 
99  virtual QString subscript_expression (const QModelIndex& idx) const;
100 
101  bool is_valid (void) const { return m_valid; }
102 
103  octave_idx_type data_rows (void) const { return m_data_rows; }
104 
105  octave_idx_type data_columns (void) const { return m_data_cols; }
106 
107  int display_rows (void) const { return m_display_rows; }
108 
109  int display_columns (void) const { return m_display_cols; }
110 
111  virtual QString make_description_text (void) const;
112 
113  void reset (const octave_value& val);
114 
115  protected:
116 
117  std::string m_name;
118 
120 
123 
124  // Qt table widget limits the size to int.
127 
129 
130  bool m_valid;
131 
133  };
134 
136  {
137  Q_OBJECT
138 
139  private:
140 
141  static base_ve_model * create (const QString &expr, const octave_value& val);
142 
143  public:
144 
145  variable_editor_model (const QString &expr, const octave_value& val,
146  QObject *parent = nullptr);
147 
149  {
150  delete rep;
151  }
152 
153  // No copying!
154 
156 
158 
159  std::string name (void) const
160  {
161  return rep->name ();
162  }
163 
164  bool is_editable (void) const
165  {
166  return rep->is_editable ();
167  }
168 
169  octave_value value_at (const QModelIndex& idx) const
170  {
171  return rep->value_at (idx);
172  }
173 
174  int column_width (void) const
175  {
176  return rep->column_width ();
177  }
178 
179  int rowCount (const QModelIndex& idx = QModelIndex ()) const
180  {
181  return rep->rowCount (idx);
182  }
183 
184  int columnCount (const QModelIndex& idx = QModelIndex ()) const
185  {
186  return rep->columnCount (idx);
187  }
188 
189  QVariant data (const QModelIndex& idx = QModelIndex (),
190  int role = Qt::DisplayRole) const
191  {
192  return rep->data (idx, role);
193  }
194 
195  bool setData (const QModelIndex& idx, const QVariant& v,
196  int role = Qt::EditRole);
197 
198  bool clear_content (const QModelIndex& idx);
199 
200  Qt::ItemFlags flags (const QModelIndex& idx) const;
201 
202  bool insertRows (int row, int count,
203  const QModelIndex& parent = QModelIndex());
204 
205  bool removeRows (int row, int count,
206  const QModelIndex& parent = QModelIndex());
207 
208  bool insertColumns (int column, int count,
209  const QModelIndex& parent = QModelIndex());
210 
211  bool removeColumns (int column, int count,
212  const QModelIndex& parent = QModelIndex());
213 
214  // Is cell at idx complex enough to require a sub editor?
215 
216  bool requires_sub_editor (const QModelIndex& idx) const
217  {
218  return rep->requires_sub_editor (idx);
219  }
220 
221  void set_update_pending (const QModelIndex& idx, const QString& str)
222  {
223  rep->set_update_pending (idx, str);
224  }
225 
226  bool update_pending (const QModelIndex& idx) const
227  {
228  return rep->update_pending (idx);
229  }
230 
231  QString update_pending_data (const QModelIndex& idx) const
232  {
233  return rep->update_pending_data (idx);
234  }
235 
237  {
239  }
240 
241  char quote_char (const QModelIndex& idx) const
242  {
243  return rep->quote_char (idx);
244  }
245 
246  QVariant
247  headerData (int section, Qt::Orientation orientation, int role) const
248  {
249  return rep->header_data (section, orientation, role);
250  }
251 
252  // Return a subscript expression as a string that can be used to
253  // access a sub-element of a data structure. For example "{1,3}"
254  // for cell array element {1,3} or "(2,4)" for array element (2,4).
255 
256  QString subscript_expression (const QModelIndex& idx) const
257  {
258  return rep->subscript_expression (idx);
259  }
260 
261  int display_rows (void) const
262  {
263  return rep->display_rows ();
264  }
265 
267  {
268  return rep->data_rows ();
269  }
270 
271  int display_columns (void) const
272  {
273  return rep->display_columns ();
274  }
275 
277  {
278  return rep->data_columns ();
279  }
280 
281  void maybe_resize_rows (int rows);
282 
283  void maybe_resize_columns (int cols);
284 
285  signals:
286 
287  void update_data_signal (const octave_value& val);
288 
289  void data_error_signal (const QString& name) const;
290 
291  void user_error_signal (const QString& title, const QString& msg) const;
292 
293  void set_editable_signal (bool);
294 
295  void description_changed (const QString& description);
296 
297  void edit_variable_signal (const QString& name, const octave_value& val);
298 
299  void interpreter_event (const fcn_callback& fcn);
300  void interpreter_event (const meth_callback& meth);
301 
302  public slots:
303 
304  void update_data (const octave_value& val);
305 
306  void update_data_cache (void);
307 
308  void double_click (const QModelIndex& idx);
309 
310  private slots:
311 
312  void data_error (const QString& msg);
313 
314  void user_error (const QString& title, const QString& msg);
315 
316  private:
317 
319 
320  void init_from_oct (interpreter& interp);
321 
322  void eval_expr_event (const QString& expr);
323 
324  octave_value retrieve_variable (interpreter&, const std::string& name);
325 
326  bool is_valid (void) const
327  {
328  return rep->is_valid ();
329  }
330 
331  void change_display_size (int old_rows, int old_cols,
332  int new_rows, int new_cols);
333 
334  QString make_description_text (void) const
335  {
336  return rep->make_description_text ();
337  }
338 
339  void reset (const octave_value& val);
340 
341  void invalidate (void);
342 
343  void update_description (const QString& description = QString ());
344 
345  void evaluation_error (const std::string& expr) const;
346  };
347 }
348 
349 #endif
QString update_pending_data(const QModelIndex &idx) const
float_display_format m_display_fmt
virtual bool requires_sub_editor(const QModelIndex &idx) const
octave_idx_type data_columns(void) const
QVariant data(const QModelIndex &idx, int role=Qt::DisplayRole) const
virtual void maybe_resize_rows(int)
virtual QString make_description_text(void) const
int rowCount(const QModelIndex &=QModelIndex()) const
base_ve_model(const base_ve_model &)=delete
virtual bool is_editable(void) const
virtual char quote_char(const QModelIndex &idx) const
void set_update_pending(const QModelIndex &idx, const QString &str)
bool index_ok(const QModelIndex &idx, int &row, int &col) const
octave_idx_type data_rows(void) const
void reset(const octave_value &val)
virtual QVariant edit_display(const QModelIndex &idx, int role) const
base_ve_model & operator=(const base_ve_model &)=delete
std::string name(void) const
virtual octave_value value_at(const QModelIndex &idx) const
virtual ~base_ve_model(void)=default
virtual QVariant header_data(int section, Qt::Orientation orientation, int role) const
bool update_pending(const QModelIndex &idx) const
int columnCount(const QModelIndex &=QModelIndex()) const
virtual QString subscript_expression(const QModelIndex &idx) const
QMap< QModelIndex, QString > m_update_pending
virtual void maybe_resize_columns(int)
base_ve_model(const QString &expr, const octave_value &val)
QString edit_display_sub(const octave_value &elt, int role) const
Qt::ItemFlags flags(const QModelIndex &idx) const
bool insertRows(int row, int count, const QModelIndex &parent=QModelIndex())
void description_changed(const QString &description)
void data_error(const QString &msg)
void init_from_oct(interpreter &interp)
octave_value value_at(const QModelIndex &idx) const
void update_description(const QString &description=QString())
QVariant data(const QModelIndex &idx=QModelIndex(), int role=Qt::DisplayRole) const
void data_error_signal(const QString &name) const
octave_value retrieve_variable(interpreter &, const std::string &name)
QString update_pending_data(const QModelIndex &idx) const
void interpreter_event(const meth_callback &meth)
void set_update_pending(const QModelIndex &idx, const QString &str)
variable_editor_model(const QString &expr, const octave_value &val, QObject *parent=nullptr)
bool requires_sub_editor(const QModelIndex &idx) const
void user_error(const QString &title, const QString &msg)
void interpreter_event(const fcn_callback &fcn)
bool removeColumns(int column, int count, const QModelIndex &parent=QModelIndex())
bool insertColumns(int column, int count, const QModelIndex &parent=QModelIndex())
void update_data_signal(const octave_value &val)
void user_error_signal(const QString &title, const QString &msg) const
static base_ve_model * create(const QString &expr, const octave_value &val)
int columnCount(const QModelIndex &idx=QModelIndex()) const
void reset(const octave_value &val)
void change_display_size(int old_rows, int old_cols, int new_rows, int new_cols)
void double_click(const QModelIndex &idx)
void edit_variable_signal(const QString &name, const octave_value &val)
int rowCount(const QModelIndex &idx=QModelIndex()) const
QString subscript_expression(const QModelIndex &idx) const
void eval_expr_event(const QString &expr)
void evaluation_error(const std::string &expr) const
variable_editor_model(const variable_editor_model &)=delete
bool clear_content(const QModelIndex &idx)
variable_editor_model & operator=(const variable_editor_model &)=delete
QVariant headerData(int section, Qt::Orientation orientation, int role) const
QString make_description_text(void) const
void update_data(const octave_value &val)
char quote_char(const QModelIndex &idx) const
octave_idx_type data_rows(void) const
bool update_pending(const QModelIndex &idx) const
bool setData(const QModelIndex &idx, const QVariant &v, int role=Qt::EditRole)
octave_idx_type data_columns(void) const
bool removeRows(int row, int count, const QModelIndex &parent=QModelIndex())
std::function< void(octave::interpreter &)> meth_callback
Definition: event-manager.h:47
std::function< void(void)> fcn_callback
Definition: event-manager.h:46