GNU Octave  4.0.0
A high-level interpreted language, primarily intended for numerical computations, mostly compatible with Matlab
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
dialog.h
Go to the documentation of this file.
1 /*
2 
3 Copyright (C) 2013-2015 John W. Eaton
4 Copyright (C) 2013-2015 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 the
10 Free Software Foundation; either version 3 of the License, or (at your
11 option) any later version.
12 
13 Octave is distributed in the hope that it will be useful, but WITHOUT
14 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
15 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
16 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 <http://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 
44 class QUIWidgetCreator : public QObject
45 {
46  Q_OBJECT
47 
48 public:
49 
50  QUIWidgetCreator (void);
51 
52  ~QUIWidgetCreator (void);
53 
54 public:
55 
56  void signal_dialog (const QString& message, const QString& title,
57  const QString& icon, const QStringList& button,
58  const QString& defbutton, const QStringList& role)
59  {
60 
61  // Use the last button in the list as the reject result, i.e., when no
62  // button is pressed such as in the case of the upper right close tab.
63  if (!button.isEmpty ())
64  dialog_button = button.last ();
65 
66  QString xicon = icon;
67  if (xicon.isEmpty ())
68  xicon = "none";
69 
70  emit create_dialog (message, title, xicon, button, defbutton, role);
71  };
72 
73  int get_dialog_result (void) { return dialog_result; }
74 
75  QString get_dialog_button (void) { return dialog_button; }
76 
77  bool signal_listview (const QStringList& list, const QString& mode,
78  int wd, int ht, const QList<int>& initial,
79  const QString& name, const QStringList& prompt,
80  const QString& ok_string, const QString& cancel_string)
81  {
82  if (list.isEmpty ())
83  return false;
84 
85  emit create_listview (list, mode, wd, ht, initial, name,
86  prompt, ok_string, cancel_string);
87 
88  return true;
89  };
90 
91  const QIntList *get_list_index (void) { return list_index; }
92 
93  bool signal_inputlayout (const QStringList& prompt, const QString& title,
94  const QFloatList& nr, const QFloatList& nc,
95  const QStringList& defaults)
96  {
97  if (prompt.isEmpty ())
98  return false;
99 
100  emit create_inputlayout (prompt, title, nr, nc, defaults);
101 
102  return true;
103  };
104 
105  const QStringList *get_string_list (void) { return string_list; }
106 
107  bool signal_filedialog (const QStringList& filters, const QString& title,
108  const QString& filename, const QString& dirname,
109  const QString &multimode)
110  {
111  emit create_filedialog (filters, title, filename, dirname, multimode);
112  return true;
113  }
114 
115  const QString *get_dialog_path (void) { return path_name; }
116 
117  // GUI objects cannot be accessed in the non-GUI thread. However,
118  // signals can be sent to slots across threads with proper
119  // synchronization. Hence, the use of QWaitCondition.
120  QMutex mutex;
121  QWaitCondition waitcondition;
122 
123 signals:
124 
125  void create_dialog (const QString&, const QString&, const QString&,
126  const QStringList&, const QString&, const QStringList&);
127 
128  void create_listview (const QStringList&, const QString&, int, int,
129  const QIntList&, const QString&, const QStringList&,
130  const QString&, const QString&);
131 
132  void create_inputlayout (const QStringList&, const QString&,
133  const QFloatList&, const QFloatList&,
134  const QStringList&);
135 
136  void create_filedialog (const QStringList& filters, const QString& title,
137  const QString& filename, const QString& dirname,
138  const QString& multimode);
139 public slots:
140 
141  void dialog_button_clicked (QAbstractButton *button);
142 
143  void list_select_finished (const QIntList& selected, int button_pressed);
144 
145  void input_finished (const QStringList& input, int button_pressed);
146 
147  void filedialog_finished (const QStringList& files, const QString& path,
148  int filterindex);
149 
150 private:
151 
153  QString dialog_button;
154 
155  // The list could conceivably be big. Not sure how things are
156  // stored internally, so keep off of the stack.
157  QStringList *string_list;
159 
160  QString *path_name;
161 
162 };
163 
165 
166 
168 {
169  Q_OBJECT
170 
171 public:
172 
173  explicit MessageDialog (const QString& message, const QString& title,
174  const QString& icon, const QStringList& button,
175  const QString& defbutton,
176  const QStringList& role);
177 
178 private:
179 
180  void closeEvent (QCloseEvent *)
181  {
182  // Reroute the close tab to a button click so there is only a single
183  // route to waking the wait condition.
184  emit buttonClicked (0);
185  }
186 };
187 
188 
189 class ListDialog : public QDialog
190 {
191  Q_OBJECT
192 
193  QItemSelectionModel *selector;
194 
195 public:
196 
197  explicit ListDialog (const QStringList& list, const QString& mode,
198  int width, int height, const QList<int>& initial,
199  const QString& name, const QStringList& prompt,
200  const QString& ok_string, const QString& cancel_string);
201 
202 signals:
203 
204  void finish_selection (const QIntList&, int);
205 
206 public slots:
207 
208  void buttonOk_clicked (void);
209 
210  void buttonCancel_clicked (void);
211 
212  void reject (void);
213 };
214 
215 
216 class InputDialog : public QDialog
217 {
218  Q_OBJECT
219 
221 
222 public:
223 
224  explicit InputDialog (const QStringList& prompt, const QString& title,
225  const QFloatList& nr, const QFloatList& nc,
226  const QStringList& defaults);
227 
228 signals:
229 
230  void finish_input (const QStringList&, int);
231 
232 public slots:
233 
234  void buttonOk_clicked (void);
235 
236  void buttonCancel_clicked (void);
237 
238  void reject (void);
239 };
240 
241 class FileDialog : public QFileDialog
242 {
243  Q_OBJECT
244 
245 public:
246 
247  explicit FileDialog (const QStringList& filters,
248  const QString& title, const QString& filename,
249  const QString& dirname, const QString& multimode);
250 
251 signals:
252 
253  void finish_input (const QStringList&, const QString&, int);
254 
255 private slots:
256 
257  void rejectSelection (void);
258 
259  void acceptSelection (void);
260 };
261 
262 #endif
void signal_dialog(const QString &message, const QString &title, const QString &icon, const QStringList &button, const QString &defbutton, const QStringList &role)
Definition: dialog.h:56
~QUIWidgetCreator(void)
Definition: dialog.cc:54
void list_select_finished(const QIntList &selected, int button_pressed)
Definition: dialog.cc:83
bool signal_filedialog(const QStringList &filters, const QString &title, const QString &filename, const QString &dirname, const QString &multimode)
Definition: dialog.h:107
int get_dialog_result(void)
Definition: dialog.h:73
void create_inputlayout(const QStringList &, const QString &, const QFloatList &, const QFloatList &, const QStringList &)
Definition: moc-dialog.cc:143
void create_listview(const QStringList &, const QString &, int, int, const QIntList &, const QString &, const QStringList &, const QString &, const QString &)
Definition: moc-dialog.cc:136
void buttonOk_clicked(void)
Definition: dialog.cc:305
void finish_selection(const QIntList &, int)
Definition: moc-dialog.cc:301
QItemSelectionModel * selector
Definition: dialog.h:193
const QIntList * get_list_index(void)
Definition: dialog.h:91
void create_dialog(const QString &, const QString &, const QString &, const QStringList &, const QString &, const QStringList &)
Definition: moc-dialog.cc:129
FileDialog(const QStringList &filters, const QString &title, const QString &filename, const QString &dirname, const QString &multimode)
Definition: dialog.cc:440
QMutex mutex
Definition: dialog.h:120
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:203
void rejectSelection(void)
Definition: dialog.cc:490
void filedialog_finished(const QStringList &files, const QString &path, int filterindex)
Definition: dialog.cc:117
void reject(void)
Definition: dialog.cc:435
void message(const char *name, const char *fmt,...)
Definition: error.cc:380
void reject(void)
Definition: dialog.cc:335
QString dialog_button
Definition: dialog.h:153
const QStringList * get_string_list(void)
Definition: dialog.h:105
QString * path_name
Definition: dialog.h:160
void dialog_button_clicked(QAbstractButton *button)
Definition: dialog.cc:63
void closeEvent(QCloseEvent *)
Definition: dialog.h:180
QIntList * list_index
Definition: dialog.h:158
void buttonCancel_clicked(void)
Definition: dialog.cc:424
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:77
void input_finished(const QStringList &input, int button_pressed)
Definition: dialog.cc:101
QWaitCondition waitcondition
Definition: dialog.h:121
void create_filedialog(const QStringList &filters, const QString &title, const QString &filename, const QString &dirname, const QString &multimode)
Definition: moc-dialog.cc:150
QStringList * string_list
Definition: dialog.h:157
void buttonOk_clicked(void)
Definition: dialog.cc:412
int dialog_result
Definition: dialog.h:152
QUIWidgetCreator uiwidget_creator
Definition: dialog.cc:44
QList< float > QFloatList
Definition: dialog.h:41
bool signal_inputlayout(const QStringList &prompt, const QString &title, const QFloatList &nr, const QFloatList &nc, const QStringList &defaults)
Definition: dialog.h:93
MessageDialog(const QString &message, const QString &title, const QString &icon, const QStringList &button, const QString &defbutton, const QStringList &role)
Definition: dialog.cc:136
const QString * get_dialog_path(void)
Definition: dialog.h:115
InputDialog(const QStringList &prompt, const QString &title, const QFloatList &nr, const QFloatList &nc, const QStringList &defaults)
Definition: dialog.cc:341
void finish_input(const QStringList &, const QString &, int)
Definition: moc-dialog.cc:478
static int input(yyscan_t yyscanner)
QList< int > QIntList
Definition: dialog.h:38
void acceptSelection(void)
Definition: dialog.cc:496
QString get_dialog_button(void)
Definition: dialog.h:75
QList< QLineEdit * > input_line
Definition: dialog.h:220
QUIWidgetCreator(void)
Definition: dialog.cc:47
void buttonCancel_clicked(void)
Definition: dialog.cc:322
void finish_input(const QStringList &, int)
Definition: moc-dialog.cc:391