GNU Octave  4.2.1
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-2017 John W. Eaton
4 Copyright (C) 2013-2016 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 
167 {
168  Q_OBJECT
169 
170 public:
171 
172  explicit MessageDialog (const QString& message, const QString& title,
173  const QString& icon, const QStringList& button,
174  const QString& defbutton,
175  const QStringList& role);
176 
177 private:
178 
179  void closeEvent (QCloseEvent *)
180  {
181  // Reroute the close tab to a button click so there is only a single
182  // route to waking the wait condition.
183  emit buttonClicked (0);
184  }
185 };
186 
187 class ListDialog : public QDialog
188 {
189  Q_OBJECT
190 
191  QItemSelectionModel *selector;
192 
193 public:
194 
195  explicit ListDialog (const QStringList& list, const QString& mode,
196  int width, int height, const QList<int>& initial,
197  const QString& name, const QStringList& prompt,
198  const QString& ok_string, const QString& cancel_string);
199 
200  ~ListDialog (void);
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  void item_double_clicked (const QModelIndex&);
215 
216 private:
217 
218  QAbstractItemModel *model;
219 };
220 
221 class InputDialog : public QDialog
222 {
223  Q_OBJECT
224 
226 
227 public:
228 
229  explicit InputDialog (const QStringList& prompt, const QString& title,
230  const QFloatList& nr, const QFloatList& nc,
231  const QStringList& defaults);
232 
233 signals:
234 
235  void finish_input (const QStringList&, int);
236 
237 public slots:
238 
239  void buttonOk_clicked (void);
240 
241  void buttonCancel_clicked (void);
242 
243  void reject (void);
244 };
245 
246 class FileDialog : public QFileDialog
247 {
248  Q_OBJECT
249 
250 public:
251 
252  explicit FileDialog (const QStringList& filters,
253  const QString& title, const QString& filename,
254  const QString& dirname, const QString& multimode);
255 
256 signals:
257 
258  void finish_input (const QStringList&, const QString&, int);
259 
260 private slots:
261 
262  void rejectSelection (void);
263 
264  void acceptSelection (void);
265 };
266 
267 #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
~ListDialog(void)
Definition: dialog.cc:298
void item_double_clicked(const QModelIndex &)
Definition: dialog.cc:338
~QUIWidgetCreator(void)
Definition: dialog.cc:53
void list_select_finished(const QIntList &selected, int button_pressed)
Definition: dialog.cc:80
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
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:728
void create_listview(const QStringList &, const QString &, int, int, const QIntList &, const QString &, const QStringList &, const QString &, const QString &)
Definition: moc-dialog.cc:136
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:6386
void buttonOk_clicked(void)
Definition: dialog.cc:304
void finish_selection(const QIntList &, int)
Definition: moc-dialog.cc:303
QItemSelectionModel * selector
Definition: dialog.h:191
const QIntList * get_list_index(void)
Definition: dialog.h:91
std::string filename
Definition: urlwrite.cc:340
void create_dialog(const QString &, const QString &, const QString &, const QStringList &, const QString &, const QStringList &)
Definition: moc-dialog.cc:129
OCTAVE_EXPORT octave_value_list return the value of the option it must match the dimension of the state and the relative tolerance must also be a vector of the same length tem it must match the dimension of the state and the absolute tolerance must also be a vector of the same length The local error test applied at each integration step is xample roup calculate Y_a and Y _d item Given calculate Y nd enumerate In either initial values for the given components are input
Definition: DASPK-opts.cc:739
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:197
void rejectSelection(void)
Definition: dialog.cc:490
void filedialog_finished(const QStringList &files, const QString &path, int filterindex)
Definition: dialog.cc:113
void reject(void)
Definition: dialog.cc:435
void message(const char *name, const char *fmt,...)
Definition: error.cc:430
void reject(void)
Definition: dialog.cc:332
OCTAVE_EXPORT octave_value_list any number nd example oindent prints the prompt xample Pick a any number!nd example oindent and waits for the user to enter a value The string entered by the user is evaluated as an so it may be a literal a variable name
Definition: input.cc:871
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:61
void closeEvent(QCloseEvent *)
Definition: dialog.h:179
QIntList * list_index
Definition: dialog.h:158
void buttonCancel_clicked(void)
Definition: dialog.cc:425
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:97
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:413
int dialog_result
Definition: dialog.h:152
QUIWidgetCreator uiwidget_creator
Definition: dialog.cc:45
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:2981
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:130
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:343
void finish_input(const QStringList &, const QString &, int)
Definition: moc-dialog.cc:480
QList< int > QIntList
Definition: dialog.h:38
void acceptSelection(void)
Definition: dialog.cc:496
QString get_dialog_button(void)
Definition: dialog.h:75
QAbstractItemModel * model
Definition: dialog.h:218
QList< QLineEdit * > input_line
Definition: dialog.h:225
QUIWidgetCreator(void)
Definition: dialog.cc:47
void buttonCancel_clicked(void)
Definition: dialog.cc:320
void finish_input(const QStringList &, int)
Definition: moc-dialog.cc:393