GNU Octave  4.4.1
A high-level interpreted language, primarily intended for numerical computations, mostly compatible with Matlab
dialog.h
Go to the documentation of this file.
1 /*
2 
3 Copyright (C) 2013-2018 John W. Eaton
4 Copyright (C) 2013-2018 Daniel J. Sebald
5 
6 This file is part of Octave.
7 
8 Octave is free software: you can redistribute it and/or modify it
9 under the terms of the GNU General Public License as published by
10 the Free Software Foundation, either version 3 of the License, or
11 (at your option) any later version.
12 
13 Octave is distributed in the hope that it will be useful, but
14 WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
17 
18 You should have received a copy of the GNU General Public License
19 along with Octave; see the file COPYING. If not, see
20 <https://www.gnu.org/licenses/>.
21 
22 */
23 
24 #if ! defined (octave_dialog_h)
25 #define octave_dialog_h 1
26 
27 #include <QMutex>
28 #include <QWaitCondition>
29 #include <QAbstractButton>
30 #include <QList>
31 #include <QItemSelectionModel>
32 #include <QDialog>
33 #include <QMessageBox>
34 #include <QLineEdit>
35 #include <QFileDialog>
36 
37 // Defined for purposes of sending QList<int> as part of signal.
39 
40 // Defined for purposes of sending QList<float> as part of signal.
42 
43 namespace octave
44 {
45  class QUIWidgetCreator : public QObject
46  {
47  Q_OBJECT
48 
49  public:
50 
51  QUIWidgetCreator (void);
52 
53  ~QUIWidgetCreator (void);
54 
55  public:
56 
57  QString rm_amp (const QString& text);
58 
59  void signal_dialog (const QString& message, const QString& title,
60  const QString& icon, const QStringList& button,
61  const QString& defbutton, const QStringList& role)
62  {
63  // Store button text before a window-manager adds accelerators
64  m_button_list = button;
65 
66  // Use the last button in the list as the reject result, i.e., when no
67  // button is pressed such as in the case of the upper right close tab.
68  if (! button.isEmpty ())
69  m_dialog_button = button.last ();
70 
71  QString xicon = icon;
72  if (xicon.isEmpty ())
73  xicon = "none";
74 
75  emit create_dialog (message, title, xicon, button, defbutton, role);
76  };
77 
78  int get_dialog_result (void) { return m_dialog_result; }
79 
80  QString get_dialog_button (void) { return m_dialog_button; }
81 
82  bool signal_listview (const QStringList& list, const QString& mode,
83  int wd, int ht, const QList<int>& initial,
84  const QString& name, const QStringList& prompt,
85  const QString& ok_string,
86  const QString& cancel_string)
87  {
88  if (list.isEmpty ())
89  return false;
90 
91  emit create_listview (list, mode, wd, ht, initial, name,
92  prompt, ok_string, cancel_string);
93 
94  return true;
95  };
96 
97  const QIntList * get_list_index (void) { return m_list_index; }
98 
99  bool signal_inputlayout (const QStringList& prompt, const QString& title,
100  const QFloatList& nr, const QFloatList& nc,
101  const QStringList& defaults)
102  {
103  if (prompt.isEmpty ())
104  return false;
105 
106  emit create_inputlayout (prompt, title, nr, nc, defaults);
107 
108  return true;
109  };
110 
111  const QStringList * get_string_list (void) { return m_string_list; }
112 
113  bool signal_filedialog (const QStringList& filters, const QString& title,
114  const QString& filename, const QString& dirname,
115  const QString& multimode)
116  {
117  emit create_filedialog (filters, title, filename, dirname, multimode);
118  return true;
119  }
120 
121  const QString * get_dialog_path (void) { return m_path_name; }
122 
123  void lock (void) { m_mutex.lock (); }
124  void wait (void) { m_waitcondition.wait (&m_mutex); }
125  void unlock (void) { m_mutex.unlock (); }
126  void wake_all (void) { m_waitcondition.wakeAll (); }
127 
128  signals:
129 
130  void create_dialog (const QString&, const QString&, const QString&,
131  const QStringList&, const QString&, const QStringList&);
132 
133  void create_listview (const QStringList&, const QString&, int, int,
134  const QIntList&, const QString&, const QStringList&,
135  const QString&, const QString&);
136 
137  void create_inputlayout (const QStringList&, const QString&,
138  const QFloatList&, const QFloatList&,
139  const QStringList&);
140 
141  void create_filedialog (const QStringList& filters, const QString& title,
142  const QString& filename, const QString& dirname,
143  const QString& multimode);
144  public slots:
145 
146  void dialog_button_clicked (QAbstractButton *button);
147 
148  void list_select_finished (const QIntList& selected, int button_pressed);
149 
150  void input_finished (const QStringList& input, int button_pressed);
151 
152  void filedialog_finished (const QStringList& files, const QString& path,
153  int filterindex);
154 
155  private:
156 
159 
160  // A copy of the dialogs button texts
161  QStringList m_button_list;
162 
163  // The list could conceivably be big. Not sure how things are
164  // stored internally, so keep off of the stack.
165  QStringList *m_string_list;
167 
168  QString *m_path_name;
169 
170  // GUI objects cannot be accessed in the non-GUI thread. However,
171  // signals can be sent to slots across threads with proper
172  // synchronization. Hence, the use of QWaitCondition.
173  QMutex m_mutex;
174  QWaitCondition m_waitcondition;
175  };
176 
178 
179  class MessageDialog : public QMessageBox
180  {
181  Q_OBJECT
182 
183  public:
184 
185  explicit MessageDialog (const QString& message, const QString& title,
186  const QString& icon, const QStringList& button,
187  const QString& defbutton,
188  const QStringList& role);
189 
190  private:
191 
192  void closeEvent (QCloseEvent *)
193  {
194  // Reroute the close tab to a button click so there is only a single
195  // route to waking the wait condition.
196  emit buttonClicked (nullptr);
197  }
198  };
199 
200  class ListDialog : public QDialog
201  {
202  Q_OBJECT
203 
204  QItemSelectionModel *selector;
205 
206  public:
207 
208  explicit ListDialog (const QStringList& list, const QString& mode,
209  int width, int height, const QList<int>& initial,
210  const QString& name, const QStringList& prompt,
211  const QString& ok_string,
212  const QString& cancel_string);
213 
214  ~ListDialog (void);
215 
216  signals:
217 
218  void finish_selection (const QIntList&, int);
219 
220  public slots:
221 
222  void buttonOk_clicked (void);
223 
224  void buttonCancel_clicked (void);
225 
226  void reject (void);
227 
228  void item_double_clicked (const QModelIndex&);
229 
230  private:
231 
232  QAbstractItemModel *m_model;
233  };
234 
235  class InputDialog : public QDialog
236  {
237  Q_OBJECT
238 
240 
241  public:
242 
243  explicit InputDialog (const QStringList& prompt, const QString& title,
244  const QFloatList& nr, const QFloatList& nc,
245  const QStringList& defaults);
246 
247  signals:
248 
249  void finish_input (const QStringList&, int);
250 
251  public slots:
252 
253  void buttonOk_clicked (void);
254 
255  void buttonCancel_clicked (void);
256 
257  void reject (void);
258  };
259 
260  class FileDialog : public QFileDialog
261  {
262  Q_OBJECT
263 
264  public:
265 
266  explicit FileDialog (const QStringList& filters,
267  const QString& title, const QString& filename,
268  const QString& dirname, const QString& multimode);
269 
270  signals:
271 
272  void finish_input (const QStringList&, const QString&, int);
273 
274  private slots:
275 
276  void acceptSelection (void);
277 
278  void rejectSelection (void);
279  };
280 }
281 
282 #endif
void create_inputlayout(const QStringList &, const QString &, const QFloatList &, const QFloatList &, const QStringList &)
void reject(void)
Definition: dialog.cc:448
QStringList * m_string_list
Definition: dialog.h:165
bool signal_filedialog(const QStringList &filters, const QString &title, const QString &filename, const QString &dirname, const QString &multimode)
Definition: dialog.h:113
void reject(void)
Definition: dialog.cc:347
The value of lines which begin with a space character are not saved in the history list A value of all commands are saved on the history list
Definition: oct-hist.cc:734
void input_finished(const QStringList &input, int button_pressed)
Definition: dialog.cc:110
void list_select_finished(const QIntList &selected, int button_pressed)
Definition: dialog.cc:94
void signal_dialog(const QString &message, const QString &title, const QString &icon, const QStringList &button, const QString &defbutton, const QStringList &role)
Definition: dialog.h:59
void wake_all(void)
Definition: dialog.h:126
Return the CPU time used by your Octave session The first output is the total time spent executing your process and is equal to the sum of second and third which are the number of CPU seconds spent executing in user mode and the number of CPU seconds spent executing in system mode
Definition: data.cc:6348
QList< QLineEdit * > input_line
Definition: dialog.h:239
bool signal_inputlayout(const QStringList &prompt, const QString &title, const QFloatList &nr, const QFloatList &nc, const QStringList &defaults)
Definition: dialog.h:99
QItemSelectionModel * selector
Definition: dialog.h:204
QString * m_path_name
Definition: dialog.h:168
QWaitCondition m_waitcondition
Definition: dialog.h:174
std::string filename
Definition: urlwrite.cc:121
std::string dirname(const std::string &path)
Definition: file-ops.cc:353
QAbstractItemModel * m_model
Definition: dialog.h:232
MessageDialog(const QString &message, const QString &title, const QString &icon, const QStringList &button, const QString &defbutton, const QStringList &role)
Definition: dialog.cc:144
void create_filedialog(const QStringList &filters, const QString &title, const QString &filename, const QString &dirname, const QString &multimode)
void buttonCancel_clicked(void)
Definition: dialog.cc:439
void message(const char *name, const char *fmt,...)
Definition: error.cc:435
void item_double_clicked(const QModelIndex &)
Definition: dialog.cc:352
nd deftypefn *std::string name
Definition: sysdep.cc:647
void finish_input(const QStringList &, int)
void finish_selection(const QIntList &, int)
bool signal_listview(const QStringList &list, const QString &mode, int wd, int ht, const QList< int > &initial, const QString &name, const QStringList &prompt, const QString &ok_string, const QString &cancel_string)
Definition: dialog.h:82
QIntList * m_list_index
Definition: dialog.h:166
void finish_input(const QStringList &, const QString &, int)
int get_dialog_result(void)
Definition: dialog.h:78
void create_listview(const QStringList &, const QString &, int, int, const QIntList &, const QString &, const QStringList &, const QString &, const QString &)
const QStringList * get_string_list(void)
Definition: dialog.h:111
QString get_dialog_button(void)
Definition: dialog.h:80
OCTAVE_EXPORT octave_value_list or cell arrays Arguments are concatenated vertically The returned values are padded with blanks as needed to make each row of the string array have the same length Empty input strings are significant and will concatenated in the output For numerical input
Definition: strfns.cc:81
void acceptSelection(void)
Definition: dialog.cc:508
FileDialog(const QStringList &filters, const QString &title, const QString &filename, const QString &dirname, const QString &multimode)
Definition: dialog.cc:453
void closeEvent(QCloseEvent *)
Definition: dialog.h:192
QStringList m_button_list
Definition: dialog.h:161
void buttonOk_clicked(void)
Definition: dialog.cc:428
ListDialog(const QStringList &list, const QString &mode, int width, int height, const QList< int > &initial, const QString &name, const QStringList &prompt, const QString &ok_string, const QString &cancel_string)
Definition: dialog.cc:214
otherwise an error message is printed The permission mask is a UNIX concept used when creating new objects on a file system such as files
Definition: file-io.cc:3038
QList< float > QFloatList
Definition: dialog.h:41
const QIntList * get_list_index(void)
Definition: dialog.h:97
QString rm_amp(const QString &text)
Definition: dialog.cc:61
QList< int > QIntList
Definition: dialog.h:38
void buttonOk_clicked(void)
Definition: dialog.cc:321
void buttonCancel_clicked(void)
Definition: dialog.cc:336
const QString * get_dialog_path(void)
Definition: dialog.h:121
void dialog_button_clicked(QAbstractButton *button)
Definition: dialog.cc:68
void filedialog_finished(const QStringList &files, const QString &path, int filterindex)
Definition: dialog.cc:126
void create_dialog(const QString &, const QString &, const QString &, const QStringList &, const QString &, const QStringList &)
QUIWidgetCreator uiwidget_creator
Definition: dialog.cc:46
InputDialog(const QStringList &prompt, const QString &title, const QFloatList &nr, const QFloatList &nc, const QStringList &defaults)
Definition: dialog.cc:357
void rejectSelection(void)
Definition: dialog.cc:502