Mercurial > jwe > qt-gui-with-push-parser
comparison gui-main.cpp @ 7:04867eba6428
function objects and signals/slots for errors and results
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Thu, 23 May 2019 09:27:09 -0400 |
parents | 54edd85237ab |
children | 822a2fe5bb51 |
comparison
equal
deleted
inserted
replaced
6:1b575145197e | 7:04867eba6428 |
---|---|
40 } | 40 } |
41 | 41 |
42 static void redisplay (void) | 42 static void redisplay (void) |
43 { | 43 { |
44 if (calc_interaction_window) | 44 if (calc_interaction_window) |
45 calc_interaction_window->redisplay (); | 45 emit calc_interaction_window->redisplay_signal (); |
46 } | 46 } |
47 | 47 |
48 static void prep_term (int) | 48 static void prep_term (int) |
49 { | 49 { |
50 } | 50 } |
72 for (int i = 1; i < num_matches; i++) | 72 for (int i = 1; i < num_matches; i++) |
73 buf << matches[i] << "\n"; | 73 buf << matches[i] << "\n"; |
74 | 74 |
75 calc_interaction_window->insert_at_end (buf.str ()); | 75 calc_interaction_window->insert_at_end (buf.str ()); |
76 | 76 |
77 calc_interaction_window->redisplay (); | 77 emit calc_interaction_window->redisplay_signal (); |
78 } | 78 } |
79 } | 79 } |
80 | 80 |
81 static void readline_init (void) | 81 static void readline_init (void) |
82 { | 82 { |
106 | 106 |
107 setMinimumSize (QSize (600, 400)); | 107 setMinimumSize (QSize (600, 400)); |
108 | 108 |
109 setDocument (m_buffer); | 109 setDocument (m_buffer); |
110 | 110 |
111 connect (this, SIGNAL (result_available (double)), | 111 connect (m_interpreter, SIGNAL (result_ready (double)), |
112 this, SLOT (handle_result (double))); | 112 this, SLOT (handle_result (double))); |
113 | |
114 connect (m_interpreter, SIGNAL (error_signal (const QString&)), | |
115 this, SLOT (handle_error (const QString&))); | |
113 | 116 |
114 connect (this, SIGNAL (input_char_available (int)), | 117 connect (this, SIGNAL (input_char_available (int)), |
115 this, SLOT (handle_input_char (int))); | 118 this, SLOT (handle_input_char (int))); |
119 | |
120 connect (this, SIGNAL (redisplay_signal (void)), | |
121 this, SLOT (redisplay (void))); | |
116 | 122 |
117 connect (this, SIGNAL (accept_line_signal (const QString&)), | 123 connect (this, SIGNAL (accept_line_signal (const QString&)), |
118 m_interpreter, SLOT (accept_input_line (const QString&))); | 124 m_interpreter, SLOT (accept_input_line (const QString&))); |
119 | 125 |
120 insert_at_end | 126 insert_at_end |
147 | 153 |
148 emit accept_line_signal (QString::fromStdString (line)); | 154 emit accept_line_signal (QString::fromStdString (line)); |
149 } | 155 } |
150 } | 156 } |
151 | 157 |
158 void command_window::insert_at_end (const std::string& text) | |
159 { | |
160 scroll_to_bottom (); | |
161 | |
162 insert_at_cursor (text); | |
163 } | |
164 | |
165 void command_window::handle_error (const QString& msg) | |
166 { | |
167 insert_at_end ("parse error: " + msg.toStdString () + "\n"); | |
168 | |
169 rl_abort (0, 0); | |
170 } | |
171 | |
172 // FIXME: do we really need this extra function? | |
173 void command_window::handle_result (double value) | |
174 { | |
175 insert_result (value); | |
176 } | |
177 | |
152 // Redisplay current command line. | 178 // Redisplay current command line. |
153 | 179 |
154 void command_window::redisplay (void) | 180 void command_window::redisplay (void) |
155 { | 181 { |
156 erase_line (); | 182 erase_line (); |
165 QTextCursor cursor = textCursor (); | 191 QTextCursor cursor = textCursor (); |
166 | 192 |
167 cursor.setPosition (prompt_mark + rl_point, QTextCursor::MoveAnchor); | 193 cursor.setPosition (prompt_mark + rl_point, QTextCursor::MoveAnchor); |
168 | 194 |
169 setTextCursor (cursor); | 195 setTextCursor (cursor); |
170 } | |
171 | |
172 void command_window::insert_at_end (const std::string& text) | |
173 { | |
174 scroll_to_bottom (); | |
175 | |
176 insert_at_cursor (text); | |
177 } | |
178 | |
179 void command_window::emit_error (const std::string& msg) | |
180 { | |
181 insert_at_end ("parse error: " + msg); | |
182 | |
183 rl_abort (0, 0); | |
184 } | |
185 | |
186 void command_window::emit_result (double value) | |
187 { | |
188 emit result_available (value); | |
189 } | |
190 | |
191 // FIXME: do we really need this extra function? | |
192 void command_window::handle_result (double value) | |
193 { | |
194 insert_result (value); | |
195 } | 196 } |
196 | 197 |
197 void command_window::keyPressEvent (QKeyEvent *event) | 198 void command_window::keyPressEvent (QKeyEvent *event) |
198 { | 199 { |
199 if (! event) | 200 if (! event) |
388 int status = app.exec (); | 389 int status = app.exec (); |
389 | 390 |
390 readline_fini (); | 391 readline_fini (); |
391 | 392 |
392 return status; | 393 return status; |
393 } | |
394 | |
395 void emit_error (const std::string& msg) | |
396 { | |
397 calc_interaction_window->emit_error (msg); | |
398 } | |
399 | |
400 void emit_result (double value) | |
401 { | |
402 calc_interaction_window->emit_result (value); | |
403 } | 394 } |
404 } | 395 } |
405 | 396 |
406 // -- Variable: rl_getc_func_t * rl_getc_function | 397 // -- Variable: rl_getc_func_t * rl_getc_function |
407 // If non-zero, Readline will call indirectly through this pointer to | 398 // If non-zero, Readline will call indirectly through this pointer to |