GNU Octave  8.1.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-2023 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 
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 
349 
350 #endif
OCTAVE_END_NAMESPACE(octave)
bool is_valid(void) const
QString update_pending_data(const QModelIndex &idx) const
base_ve_model & operator=(const base_ve_model &)=delete
bool index_ok(const QModelIndex &idx, int &row, int &col) const
virtual char quote_char(const QModelIndex &idx) const
int column_width(void) const
virtual octave_value value_at(const QModelIndex &idx) const
QString edit_display_sub(const octave_value &elt, int role) const
virtual void maybe_resize_rows(int)
int display_rows(void) const
virtual QString make_description_text(void) const
octave_idx_type data_columns(void) const
base_ve_model(const QString &expr, const octave_value &val)
octave_idx_type data_rows(void) const
void clear_update_pending(void)
QVariant data(const QModelIndex &idx, int role=Qt::DisplayRole) const
octave_idx_type m_data_cols
base_ve_model(const base_ve_model &)=delete
int display_columns(void) const
virtual void maybe_resize_columns(int)
float_display_format m_display_fmt
virtual bool is_editable(void) const
virtual bool requires_sub_editor(const QModelIndex &idx) const
virtual ~base_ve_model(void)=default
int rowCount(const QModelIndex &=QModelIndex()) const
virtual QVariant header_data(int section, Qt::Orientation orientation, int role) const
bool update_pending(const QModelIndex &idx) const
void set_update_pending(const QModelIndex &idx, const QString &str)
octave_idx_type m_data_rows
void reset(const octave_value &val)
std::string name(void) const
virtual QString subscript_expression(const QModelIndex &idx) const
virtual QVariant edit_display(const QModelIndex &idx, int role) const
int columnCount(const QModelIndex &=QModelIndex()) const
QMap< QModelIndex, QString > m_update_pending
void user_error_signal(const QString &title, const QString &msg) const
bool insertRows(int row, int count, const QModelIndex &parent=QModelIndex())
octave_value value_at(const QModelIndex &idx) const
void init_from_oct(interpreter &interp)
QString subscript_expression(const QModelIndex &idx) const
Qt::ItemFlags flags(const QModelIndex &idx) const
void set_update_pending(const QModelIndex &idx, const QString &str)
bool insertColumns(int column, int count, const QModelIndex &parent=QModelIndex())
bool setData(const QModelIndex &idx, const QVariant &v, int role=Qt::EditRole)
octave_idx_type data_rows(void) const
bool update_pending(const QModelIndex &idx) const
void set_editable_signal(bool)
void evaluation_error(const std::string &expr) const
void data_error(const QString &msg)
QVariant data(const QModelIndex &idx=QModelIndex(), int role=Qt::DisplayRole) const
void data_error_signal(const QString &name) const
int columnCount(const QModelIndex &idx=QModelIndex()) const
variable_editor_model(const QString &expr, const octave_value &val, QObject *parent=nullptr)
void edit_variable_signal(const QString &name, const octave_value &val)
int rowCount(const QModelIndex &idx=QModelIndex()) const
std::string name(void) const
void interpreter_event(const meth_callback &meth)
bool removeRows(int row, int count, const QModelIndex &parent=QModelIndex())
octave_value retrieve_variable(interpreter &, const std::string &name)
variable_editor_model & operator=(const variable_editor_model &)=delete
void interpreter_event(const fcn_callback &fcn)
void eval_expr_event(const QString &expr)
void update_data(const octave_value &val)
void double_click(const QModelIndex &idx)
octave_idx_type data_columns(void) const
QString make_description_text(void) const
bool clear_content(const QModelIndex &idx)
bool removeColumns(int column, int count, const QModelIndex &parent=QModelIndex())
static base_ve_model * create(const QString &expr, const octave_value &val)
QVariant headerData(int section, Qt::Orientation orientation, int role) const
void change_display_size(int old_rows, int old_cols, int new_rows, int new_cols)
void description_changed(const QString &description)
void reset(const octave_value &val)
bool requires_sub_editor(const QModelIndex &idx) const
void user_error(const QString &title, const QString &msg)
QString update_pending_data(const QModelIndex &idx) const
void update_data_signal(const octave_value &val)
variable_editor_model(const variable_editor_model &)=delete
void update_description(const QString &description=QString())
char quote_char(const QModelIndex &idx) const
OCTAVE_BEGIN_NAMESPACE(octave) static octave_value daspk_fcn
std::function< void(void)> fcn_callback
Definition: event-manager.h:43
std::function< void(interpreter &)> meth_callback
Definition: event-manager.h:48