Mercurial > jwe > qt-gui-with-push-parser
comparison gui-main.cpp @ 1:08df60a01bc1
debug flag, handle input with signal
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Mon, 20 May 2019 13:45:58 -0400 |
parents | dff751fb985c |
children | 52c033864347 |
comparison
equal
deleted
inserted
replaced
0:dff751fb985c | 1:08df60a01bc1 |
---|---|
104 | 104 |
105 setDocument (m_buffer); | 105 setDocument (m_buffer); |
106 | 106 |
107 connect (this, SIGNAL (result_available (double)), | 107 connect (this, SIGNAL (result_available (double)), |
108 this, SLOT (handle_result (double))); | 108 this, SLOT (handle_result (double))); |
109 | |
110 connect (this, SIGNAL (input_char_available (int)), | |
111 this, SLOT (handle_input_char (int))); | |
109 | 112 |
110 insert_at_end | 113 insert_at_end |
111 ("Qt Example Calculator.\n" | 114 ("Qt Example Calculator.\n" |
112 "Available operations: + - * / ^ ()\n" | 115 "Available operations: + - * / ^ ()\n" |
113 "Semicolon terminates statement.\n" | 116 "Semicolon terminates statement.\n" |
119 | 122 |
120 // Accept an input line, parse and possibly execute it. | 123 // Accept an input line, parse and possibly execute it. |
121 | 124 |
122 void command_window::accept (const std::string& line) | 125 void command_window::accept (const std::string& line) |
123 { | 126 { |
127 if (calc::debug_mode) | |
128 std::cerr << "accept: " << line << std::endl; | |
129 | |
124 insert_at_end ("\n"); | 130 insert_at_end ("\n"); |
125 | 131 |
126 if (! line.empty ()) | 132 if (! line.empty ()) |
127 { | 133 { |
128 add_history (line.c_str ()); | 134 add_history (line.c_str ()); |
157 void command_window::insert_at_end (const std::string& text) | 163 void command_window::insert_at_end (const std::string& text) |
158 { | 164 { |
159 scroll_to_bottom (); | 165 scroll_to_bottom (); |
160 | 166 |
161 insert_at_cursor (text); | 167 insert_at_cursor (text); |
168 } | |
169 | |
170 void command_window::emit_error (const std::string& msg) | |
171 { | |
172 insert_at_end ("parse error: " + msg); | |
173 | |
174 rl_abort (0, 0); | |
162 } | 175 } |
163 | 176 |
164 void command_window::emit_result (double value) | 177 void command_window::emit_result (double value) |
165 { | 178 { |
166 emit result_available (value); | 179 emit result_available (value); |
229 } | 242 } |
230 break; | 243 break; |
231 } | 244 } |
232 | 245 |
233 if (key >= 0) | 246 if (key >= 0) |
234 { | 247 emit input_char_available (key); |
235 // FIXME: should this emit a signal instead? | |
236 available_char = key; | |
237 rl_callback_read_char (); | |
238 return; | |
239 } | |
240 } | 248 } |
249 } | |
250 | |
251 | |
252 void command_window::handle_input_char (int key) | |
253 { | |
254 available_char = key; | |
255 rl_callback_read_char (); | |
241 } | 256 } |
242 | 257 |
243 int command_window::do_arrow_key (int arrow_key) | 258 int command_window::do_arrow_key (int arrow_key) |
244 { | 259 { |
245 int retval = 0; | 260 int retval = 0; |
331 } | 346 } |
332 | 347 |
333 void command_window::insert_result (double value) | 348 void command_window::insert_result (double value) |
334 { | 349 { |
335 std::ostringstream buf; | 350 std::ostringstream buf; |
351 | |
336 buf << "ans = " << value << "\n"; | 352 buf << "ans = " << value << "\n"; |
337 | 353 |
338 insert_at_cursor (buf.str ()); | 354 insert_at_cursor (buf.str ()); |
339 | 355 |
340 beg_mark = set_mark (); | 356 beg_mark = set_mark (); |
368 readline_fini (); | 384 readline_fini (); |
369 | 385 |
370 interpreter::parser_fini (); | 386 interpreter::parser_fini (); |
371 | 387 |
372 return status; | 388 return status; |
389 } | |
390 | |
391 void emit_error (const std::string& msg) | |
392 { | |
393 calc_interaction_window->emit_error (msg); | |
373 } | 394 } |
374 | 395 |
375 void emit_result (double value) | 396 void emit_result (double value) |
376 { | 397 { |
377 calc_interaction_window->emit_result (value); | 398 calc_interaction_window->emit_result (value); |