GNU Octave  8.1.0
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-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_dialog_h)
27 #define octave_dialog_h 1
28 
29 #include <QAbstractButton>
30 #include <QDialog>
31 #include <QFileDialog>
32 #include <QItemSelectionModel>
33 #include <QLineEdit>
34 #include <QList>
35 #include <QMessageBox>
36 #include <QMutex>
37 #include <QWaitCondition>
38 
39 // Defined for purposes of sending QList<int> as part of signal.
41 
42 // Defined for purposes of sending QList<float> as part of signal.
44 
46 
47 class base_qobject;
48 
49 class QUIWidgetCreator : public QObject
50 {
51  Q_OBJECT
52 
53 public:
54 
55  QUIWidgetCreator (base_qobject& oct_qobj);
56 
57  ~QUIWidgetCreator (void) = default;
58 
59 public:
60 
61  QString rm_amp (const QString& text);
62 
63  QString message_dialog (const QString& message, const QString& title,
64  const QString& icon, const QStringList& button,
65  const QString& defbutton, const QStringList& role);
66 
67  int get_dialog_result (void) { return m_dialog_result; }
68 
69  QString get_dialog_button (void) { return m_dialog_button; }
70 
71  QPair<QIntList, int> list_dialog (const QStringList& list,
72  const QString& mode,
73  int wd, int ht,
74  const QList<int>& initial,
75  const QString& name,
76  const QStringList& prompt,
77  const QString& ok_string,
78  const QString& cancel_string);
79 
80  QIntList get_list_index (void) const { return m_list_index; }
81 
82  QStringList input_dialog (const QStringList& prompt, const QString& title,
83  const QFloatList& nr, const QFloatList& nc,
84  const QStringList& defaults);
85 
86  QStringList get_string_list (void) const { return m_string_list; }
87 
88  QStringList file_dialog (const QStringList& filters, const QString& title,
89  const QString& filename, const QString& dirname,
90  const QString& multimode);
91 
92  QString get_dialog_path (void) const { return m_path_name; }
93 
94  void lock (void) { m_mutex.lock (); }
95  void wait (void) { m_waitcondition.wait (&m_mutex); }
96  void unlock (void) { m_mutex.unlock (); }
97  void wake_all (void) { m_waitcondition.wakeAll (); }
98 
99 signals:
100 
101  void create_dialog (const QString&, const QString&, const QString&,
102  const QStringList&, const QString&, const QStringList&);
103 
104  void create_listview (const QStringList&, const QString&, int, int,
105  const QIntList&, const QString&, const QStringList&,
106  const QString&, const QString&);
107 
108  void create_inputlayout (const QStringList&, const QString&,
109  const QFloatList&, const QFloatList&,
110  const QStringList&);
111 
112  void create_filedialog (const QStringList& filters, const QString& title,
113  const QString& filename, const QString& dirname,
114  const QString& multimode);
115 public slots:
116 
117  void handle_create_dialog (const QString& message, const QString& title,
118  const QString& icon, const QStringList& button,
119  const QString& defbutton,
120  const QStringList& role);
121 
122  void dialog_button_clicked (QAbstractButton *button);
123 
124  void handle_create_listview (const QStringList& list, const QString& mode,
125  int width, int height,
126  const QIntList& initial,
127  const QString& name,
128  const QStringList& prompt,
129  const QString& ok_string,
130  const QString& cancel_string);
131 
132  void list_select_finished (const QIntList& selected, int button_pressed);
133 
134  void handle_create_inputlayout (const QStringList&, const QString&,
135  const QFloatList&, const QFloatList&,
136  const QStringList&);
137 
138  void input_finished (const QStringList& input, int button_pressed);
139 
140  void handle_create_filedialog (const QStringList& filters,
141  const QString& title,
142  const QString& filename,
143  const QString& dirname,
144  const QString& multimode);
145 
146  void filedialog_finished (const QStringList& files, const QString& path,
147  int filterindex);
148 
149 private:
150 
152 
155 
156  // A copy of the dialogs button texts
157  QStringList m_button_list;
158 
159  // The list could conceivably be big. Not sure how things are
160  // stored internally, so keep off of the stack.
161  QStringList m_string_list;
163 
164  QString m_path_name;
165 
166  // GUI objects cannot be accessed in the non-GUI thread. However,
167  // signals can be sent to slots across threads with proper
168  // synchronization. Hence, the use of QWaitCondition.
169  QMutex m_mutex;
170  QWaitCondition m_waitcondition;
171 };
172 
174 {
175  Q_OBJECT
176 
177 public:
178 
179  MessageDialog (base_qobject& oct_qobj, const QString& message,
180  const QString& title, const QString& icon,
181  const QStringList& button, const QString& defbutton,
182  const QStringList& role);
183 
184  ~MessageDialog (void) = default;
185 
186 private:
187 
188  void closeEvent (QCloseEvent *)
189  {
190  // Reroute the close tab to a button click so there is only a single
191  // route to waking the wait condition.
192  emit buttonClicked (nullptr);
193  }
194 };
195 
196 class ListDialog : public QDialog
197 {
198  Q_OBJECT
199 
200  QItemSelectionModel *selector;
201 
202 public:
203 
204  ListDialog (base_qobject& oct_qobj, const QStringList& list,
205  const QString& mode, int width, int height,
206  const QList<int>& initial, const QString& name,
207  const QStringList& prompt, const QString& ok_string,
208  const QString& cancel_string);
209 
210  ~ListDialog (void) = default;
211 
212 signals:
213 
214  void finish_selection (const QIntList&, int);
215 
216 public slots:
217 
218  void buttonOk_clicked (void);
219 
220  void buttonCancel_clicked (void);
221 
222  void reject (void);
223 
224  void item_double_clicked (const QModelIndex&);
225 
226 private:
227 
228  QAbstractItemModel *m_model;
229 };
230 
231 class InputDialog : public QDialog
232 {
233  Q_OBJECT
234 
236 
237 public:
238 
239  InputDialog (base_qobject& oct_qobj, const QStringList& prompt,
240  const QString& title, const QFloatList& nr,
241  const QFloatList& nc, const QStringList& defaults);
242 
243  ~InputDialog (void) = default;
244 
245 signals:
246 
247  void finish_input (const QStringList&, int);
248 
249 public slots:
250 
251  void buttonOk_clicked (void);
252 
253  void buttonCancel_clicked (void);
254 
255  void reject (void);
256 };
257 
258 class FileDialog : public QFileDialog
259 {
260  Q_OBJECT
261 
262 public:
263 
264  FileDialog (base_qobject& oct_qobj, const QStringList& filters,
265  const QString& title, const QString& filename,
266  const QString& dirname, const QString& multimode);
267 
268  ~FileDialog (void) = default;
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 
282 
283 #endif
OCTAVE_END_NAMESPACE(octave)
void acceptSelection(void)
Definition: dialog.cc:678
void rejectSelection(void)
Definition: dialog.cc:672
~FileDialog(void)=default
FileDialog(base_qobject &oct_qobj, const QStringList &filters, const QString &title, const QString &filename, const QString &dirname, const QString &multimode)
Definition: dialog.cc:621
void finish_input(const QStringList &, const QString &, int)
~InputDialog(void)=default
InputDialog(base_qobject &oct_qobj, const QStringList &prompt, const QString &title, const QFloatList &nr, const QFloatList &nc, const QStringList &defaults)
Definition: dialog.cc:527
void buttonCancel_clicked(void)
Definition: dialog.cc:606
void finish_input(const QStringList &, int)
void buttonOk_clicked(void)
Definition: dialog.cc:594
void reject(void)
Definition: dialog.cc:616
QList< QLineEdit * > input_line
Definition: dialog.h:235
void buttonCancel_clicked(void)
Definition: dialog.cc:505
QAbstractItemModel * m_model
Definition: dialog.h:228
QItemSelectionModel * selector
Definition: dialog.h:200
void finish_selection(const QIntList &, int)
void buttonOk_clicked(void)
Definition: dialog.cc:489
ListDialog(base_qobject &oct_qobj, 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:391
void item_double_clicked(const QModelIndex &)
Definition: dialog.cc:522
~ListDialog(void)=default
void reject(void)
Definition: dialog.cc:517
MessageDialog(base_qobject &oct_qobj, const QString &message, const QString &title, const QString &icon, const QStringList &button, const QString &defbutton, const QStringList &role)
Definition: dialog.cc:319
void closeEvent(QCloseEvent *)
Definition: dialog.h:188
~MessageDialog(void)=default
base_qobject & m_octave_qobj
Definition: dialog.h:151
QString rm_amp(const QString &text)
Definition: dialog.cc:67
void handle_create_inputlayout(const QStringList &, const QString &, const QFloatList &, const QFloatList &, const QStringList &)
Definition: dialog.cc:260
QMutex m_mutex
Definition: dialog.h:169
void lock(void)
Definition: dialog.h:94
void handle_create_listview(const QStringList &list, const QString &mode, int width, int height, const QIntList &initial, const QString &name, const QStringList &prompt, const QString &ok_string, const QString &cancel_string)
Definition: dialog.cc:225
void handle_create_dialog(const QString &message, const QString &title, const QString &icon, const QStringList &button, const QString &defbutton, const QStringList &role)
Definition: dialog.cc:175
void unlock(void)
Definition: dialog.h:96
QString m_path_name
Definition: dialog.h:164
QString message_dialog(const QString &message, const QString &title, const QString &icon, const QStringList &button, const QString &defbutton, const QStringList &role)
Definition: dialog.cc:74
void input_finished(const QStringList &input, int button_pressed)
Definition: dialog.cc:276
void wait(void)
Definition: dialog.h:95
QPair< QIntList, int > list_dialog(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.cc:107
int get_dialog_result(void)
Definition: dialog.h:67
QStringList m_string_list
Definition: dialog.h:161
void dialog_button_clicked(QAbstractButton *button)
Definition: dialog.cc:193
void handle_create_filedialog(const QStringList &filters, const QString &title, const QString &filename, const QString &dirname, const QString &multimode)
Definition: dialog.cc:288
QStringList input_dialog(const QStringList &prompt, const QString &title, const QFloatList &nr, const QFloatList &nc, const QStringList &defaults)
Definition: dialog.cc:132
QStringList file_dialog(const QStringList &filters, const QString &title, const QString &filename, const QString &dirname, const QString &multimode)
Definition: dialog.cc:152
QStringList get_string_list(void) const
Definition: dialog.h:86
void create_dialog(const QString &, const QString &, const QString &, const QStringList &, const QString &, const QStringList &)
~QUIWidgetCreator(void)=default
void create_filedialog(const QStringList &filters, const QString &title, const QString &filename, const QString &dirname, const QString &multimode)
void list_select_finished(const QIntList &selected, int button_pressed)
Definition: dialog.cc:245
QString get_dialog_path(void) const
Definition: dialog.h:92
QIntList m_list_index
Definition: dialog.h:162
int m_dialog_result
Definition: dialog.h:153
QString get_dialog_button(void)
Definition: dialog.h:69
QUIWidgetCreator(base_qobject &oct_qobj)
Definition: dialog.cc:50
QIntList get_list_index(void) const
Definition: dialog.h:80
void filedialog_finished(const QStringList &files, const QString &path, int filterindex)
Definition: dialog.cc:305
QString m_dialog_button
Definition: dialog.h:154
void wake_all(void)
Definition: dialog.h:97
void create_inputlayout(const QStringList &, const QString &, const QFloatList &, const QFloatList &, const QStringList &)
QStringList m_button_list
Definition: dialog.h:157
QWaitCondition m_waitcondition
Definition: dialog.h:170
void create_listview(const QStringList &, const QString &, int, int, const QIntList &, const QString &, const QStringList &, const QString &, const QString &)
Base class for Octave interfaces that use Qt.
OCTAVE_BEGIN_NAMESPACE(octave) static octave_value daspk_fcn
QList< float > QFloatList
Definition: dialog.h:43
QList< int > QIntList
Definition: dialog.h:40
void message(const char *name, const char *fmt,...)
Definition: error.cc:947
std::string dirname(const std::string &path)
Definition: file-ops.cc:360
static int input(yyscan_t yyscanner)