diff 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
line wrap: on
line diff
--- a/gui-main.cpp	Thu May 23 07:41:18 2019 -0400
+++ b/gui-main.cpp	Thu May 23 09:27:09 2019 -0400
@@ -42,7 +42,7 @@
   static void redisplay (void)
   {
     if (calc_interaction_window)
-      calc_interaction_window->redisplay ();
+      emit calc_interaction_window->redisplay_signal ();
   }
 
   static void prep_term (int)
@@ -74,7 +74,7 @@
 
         calc_interaction_window->insert_at_end (buf.str ());
 
-        calc_interaction_window->redisplay ();
+        emit calc_interaction_window->redisplay_signal ();
       }
   }
 
@@ -108,12 +108,18 @@
 
     setDocument (m_buffer);
 
-    connect (this, SIGNAL (result_available (double)),
+    connect (m_interpreter, SIGNAL (result_ready (double)),
              this, SLOT (handle_result (double)));
 
+    connect (m_interpreter, SIGNAL (error_signal (const QString&)),
+             this, SLOT (handle_error (const QString&)));
+
     connect (this, SIGNAL (input_char_available (int)),
              this, SLOT (handle_input_char (int)));
 
+    connect (this, SIGNAL (redisplay_signal (void)),
+             this, SLOT (redisplay (void)));
+
     connect (this, SIGNAL (accept_line_signal (const QString&)),
              m_interpreter, SLOT (accept_input_line (const QString&)));
 
@@ -149,6 +155,26 @@
       }
   }
 
+  void command_window::insert_at_end (const std::string& text)
+  {
+    scroll_to_bottom ();
+
+    insert_at_cursor (text);
+  }
+
+  void command_window::handle_error (const QString& msg)
+  {
+    insert_at_end ("parse error: " + msg.toStdString () + "\n");
+
+    rl_abort (0, 0);
+  }
+
+  // FIXME: do we really need this extra function?
+  void command_window::handle_result (double value)
+  {
+    insert_result (value);
+  }
+
   // Redisplay current command line.
 
   void command_window::redisplay (void)
@@ -169,31 +195,6 @@
     setTextCursor (cursor);
   }
 
-  void command_window::insert_at_end (const std::string& text)
-  {
-    scroll_to_bottom ();
-
-    insert_at_cursor (text);
-  }
-
-  void command_window::emit_error (const std::string& msg)
-  {
-    insert_at_end ("parse error: " + msg);
-
-    rl_abort (0, 0);
-  }
-
-  void command_window::emit_result (double value)
-  {
-    emit result_available (value);
-  }
-
-  // FIXME: do we really need this extra function?
-  void command_window::handle_result (double value)
-  {
-    insert_result (value);
-  }
-
   void command_window::keyPressEvent (QKeyEvent *event)
   {
     if (! event)
@@ -391,16 +392,6 @@
 
     return status;
   }
-
-  void emit_error (const std::string& msg)
-  {
-    calc_interaction_window->emit_error (msg);
-  }
-
-  void emit_result (double value)
-  {
-    calc_interaction_window->emit_result (value);
-  }
 }
 
 // -- Variable: rl_getc_func_t * rl_getc_function