GNU Octave  6.2.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-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_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 
45 namespace octave
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 
173  class MessageDialog : public QMessageBox
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  private:
185 
186  void closeEvent (QCloseEvent *)
187  {
188  // Reroute the close tab to a button click so there is only a single
189  // route to waking the wait condition.
190  emit buttonClicked (nullptr);
191  }
192  };
193 
194  class ListDialog : public QDialog
195  {
196  Q_OBJECT
197 
198  QItemSelectionModel *selector;
199 
200  public:
201 
202  ListDialog (base_qobject& oct_qobj, const QStringList& list,
203  const QString& mode, int width, int height,
204  const QList<int>& initial, const QString& name,
205  const QStringList& prompt, const QString& ok_string,
206  const QString& cancel_string);
207 
208  ~ListDialog (void);
209 
210  signals:
211 
212  void finish_selection (const QIntList&, int);
213 
214  public slots:
215 
216  void buttonOk_clicked (void);
217 
218  void buttonCancel_clicked (void);
219 
220  void reject (void);
221 
222  void item_double_clicked (const QModelIndex&);
223 
224  private:
225 
226  QAbstractItemModel *m_model;
227  };
228 
229  class InputDialog : public QDialog
230  {
231  Q_OBJECT
232 
234 
235  public:
236 
237  InputDialog (base_qobject& oct_qobj, const QStringList& prompt,
238  const QString& title, const QFloatList& nr,
239  const QFloatList& nc, const QStringList& defaults);
240 
241  signals:
242 
243  void finish_input (const QStringList&, int);
244 
245  public slots:
246 
247  void buttonOk_clicked (void);
248 
249  void buttonCancel_clicked (void);
250 
251  void reject (void);
252  };
253 
254  class FileDialog : public QFileDialog
255  {
256  Q_OBJECT
257 
258  public:
259 
260  FileDialog (base_qobject& oct_qobj, const QStringList& filters,
261  const QString& title, const QString& filename,
262  const QString& dirname, const QString& multimode);
263 
264  signals:
265 
266  void finish_input (const QStringList&, const QString&, int);
267 
268  private slots:
269 
270  void acceptSelection (void);
271 
272  void rejectSelection (void);
273  };
274 }
275 
276 #endif
FileDialog(base_qobject &oct_qobj, const QStringList &filters, const QString &title, const QString &filename, const QString &dirname, const QString &multimode)
Definition: dialog.cc:656
void acceptSelection(void)
Definition: dialog.cc:713
void finish_input(const QStringList &, const QString &, int)
void rejectSelection(void)
Definition: dialog.cc:707
InputDialog(base_qobject &oct_qobj, const QStringList &prompt, const QString &title, const QFloatList &nr, const QFloatList &nc, const QStringList &defaults)
Definition: dialog.cc:562
QList< QLineEdit * > input_line
Definition: dialog.h:233
void reject(void)
Definition: dialog.cc:651
void buttonOk_clicked(void)
Definition: dialog.cc:629
void finish_input(const QStringList &, int)
void buttonCancel_clicked(void)
Definition: dialog.cc:641
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:421
QAbstractItemModel * m_model
Definition: dialog.h:226
void buttonCancel_clicked(void)
Definition: dialog.cc:540
void buttonOk_clicked(void)
Definition: dialog.cc:524
void item_double_clicked(const QModelIndex &)
Definition: dialog.cc:557
void finish_selection(const QIntList &, int)
void reject(void)
Definition: dialog.cc:552
QItemSelectionModel * selector
Definition: dialog.h:198
void closeEvent(QCloseEvent *)
Definition: dialog.h:186
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:349
int get_dialog_result(void)
Definition: dialog.h:67
void handle_create_filedialog(const QStringList &filters, const QString &title, const QString &filename, const QString &dirname, const QString &multimode)
Definition: dialog.cc:316
QStringList get_string_list(void) const
Definition: dialog.h:86
QStringList input_dialog(const QStringList &prompt, const QString &title, const QFloatList &nr, const QFloatList &nc, const QStringList &defaults)
Definition: dialog.cc:160
void dialog_button_clicked(QAbstractButton *button)
Definition: dialog.cc:221
QString rm_amp(const QString &text)
Definition: dialog.cc:95
void handle_create_inputlayout(const QStringList &, const QString &, const QFloatList &, const QFloatList &, const QStringList &)
Definition: dialog.cc:288
void create_inputlayout(const QStringList &, const QString &, const QFloatList &, const QFloatList &, const QStringList &)
void create_listview(const QStringList &, const QString &, int, int, const QIntList &, const QString &, const QStringList &, const QString &, const QString &)
QString get_dialog_path(void) const
Definition: dialog.h:92
void input_finished(const QStringList &input, int button_pressed)
Definition: dialog.cc:304
QStringList file_dialog(const QStringList &filters, const QString &title, const QString &filename, const QString &dirname, const QString &multimode)
Definition: dialog.cc:180
void wake_all(void)
Definition: dialog.h:97
QString get_dialog_button(void)
Definition: dialog.h:69
QStringList m_button_list
Definition: dialog.h:157
void unlock(void)
Definition: dialog.h:96
QWaitCondition m_waitcondition
Definition: dialog.h:170
base_qobject & m_octave_qobj
Definition: dialog.h:151
void create_filedialog(const QStringList &filters, const QString &title, const QString &filename, const QString &dirname, const QString &multimode)
QUIWidgetCreator(base_qobject &oct_qobj)
Definition: dialog.cc:50
QString message_dialog(const QString &message, const QString &title, const QString &icon, const QStringList &button, const QString &defbutton, const QStringList &role)
Definition: dialog.cc:102
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:203
void list_select_finished(const QIntList &selected, int button_pressed)
Definition: dialog.cc:273
void create_dialog(const QString &, const QString &, const QString &, const QStringList &, const QString &, const QStringList &)
QStringList m_string_list
Definition: dialog.h:161
~QUIWidgetCreator(void)=default
void filedialog_finished(const QStringList &files, const QString &path, int filterindex)
Definition: dialog.cc:335
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:135
QIntList get_list_index(void) const
Definition: dialog.h:80
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:253
Base class for Octave interfaces that use Qt.
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:936
QString path
QString name
std::string dirname(const std::string &path)
Definition: file-ops.cc:363
static int input(yyscan_t yyscanner)