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