# HG changeset patch # User Torsten Lilge # Date 1601231176 -7200 # Node ID 82ccc4e69ba3acb9e53d17ded01ef0f4c8f55e3f # Parent ac5461b59b9337f7c2eca4549be77db381cdb9e0 show value in editor when hovering over variable in debug mode (bug #56990) * file-editor.cc (handle_enter_debug_mode): emit signal for the editor tabs; (handle_exit_debug_mode): emit signal for the editor tabs; (make_file_editor_tab): connect new signals to new related slots in octave_qscintilla; * file-editor.h: new signals for enterin/exiting debug mode; enter/exit debug mode handler moved into public slots * octave-qscintilla.cc (octave_qscintilla): initialization of new class variables, get pointers of workspace model symbol names and values; (event): reimplemented ecent handler for catching tool tip events when in debug mode, testing word under mouse cursor and display the value in a tool tip if the aord is a current variable; (handle_enter_debug_mode): set flag for debug mode, set font of tool tip to the lexers default font; (handle_exit_debug_mode): reset debug flag, reset tool tip font * octave-qscintilla.h: new public slots for entering and exiting debug mode, reimplemented event, class variables for storing debug mode, the pointers of symbol names and values from the workspace model, and the tool tip font * main-window.cc (handle_enter_debugger): do not call realted editor method; (handle_exit_debugger): do not call related editor method; (construct): directly connet qt-link signal with the editor slots instead; * workspace-model.h: provide pointer to symbol list instead of const list, new method providing the pointer to a list with symbol values diff -r ac5461b59b93 -r 82ccc4e69ba3 libgui/src/m-editor/file-editor.cc --- a/libgui/src/m-editor/file-editor.cc Sun Sep 27 12:29:11 2020 -0400 +++ b/libgui/src/m-editor/file-editor.cc Sun Sep 27 20:26:16 2020 +0200 @@ -191,6 +191,8 @@ m_run_action->setShortcut (QKeySequence ()); // prevent ambiguous shortcuts m_run_action->setToolTip (tr ("Continue")); // update tool tip + + emit enter_debug_mode_signal (); } void file_editor::handle_exit_debug_mode (void) @@ -198,6 +200,8 @@ shortcut_manager& scmgr = m_octave_qobj.get_shortcut_manager (); scmgr.set_shortcut (m_run_action, sc_edit_run_run_file); m_run_action->setToolTip (tr ("Save File and Run")); // update tool tip + + emit exit_debug_mode_signal (); } void file_editor::check_actions (void) @@ -2370,6 +2374,13 @@ connect (f->qsci_edit_area (), SIGNAL (SCN_AUTOCCANCELLED (void)), this, SLOT (handle_autoc_cancelled (void))); + // signals from the qscintilla edit area + connect (this, SIGNAL (enter_debug_mode_signal (void)), + f->qsci_edit_area (), SLOT (handle_enter_debug_mode (void))); + + connect (this, SIGNAL (exit_debug_mode_signal (void)), + f->qsci_edit_area (), SLOT (handle_exit_debug_mode (void))); + // Signals from the file editor_tab connect (f, SIGNAL (autoc_closed (void)), this, SLOT (reset_focus (void))); diff -r ac5461b59b93 -r 82ccc4e69ba3 libgui/src/m-editor/file-editor.h --- a/libgui/src/m-editor/file-editor.h Sun Sep 27 12:29:11 2020 -0400 +++ b/libgui/src/m-editor/file-editor.h Sun Sep 27 20:26:16 2020 +0200 @@ -112,9 +112,6 @@ SELECTALL_ACTION }; - void handle_enter_debug_mode (void); - void handle_exit_debug_mode (void); - void check_actions (void); void empty_script (bool startup, bool visible); void restore_session (gui_settings *settings); @@ -175,6 +172,9 @@ void editor_tabs_changed_signal (bool); void request_dbcont_signal (void); + void enter_debug_mode_signal (void); + void exit_debug_mode_signal (void); + public slots: void activate (void); @@ -183,6 +183,9 @@ bool check_closing (void); void handle_tab_ready_to_close (void); + void handle_enter_debug_mode (void); + void handle_exit_debug_mode (void); + void request_new_file (const QString& commands); void request_close_file (bool); void request_close_all_files (bool); diff -r ac5461b59b93 -r 82ccc4e69ba3 libgui/src/m-editor/octave-qscintilla.cc --- a/libgui/src/m-editor/octave-qscintilla.cc Sun Sep 27 12:29:11 2020 -0400 +++ b/libgui/src/m-editor/octave-qscintilla.cc Sun Sep 27 20:26:16 2020 +0200 @@ -110,9 +110,12 @@ } octave_qscintilla::octave_qscintilla (QWidget *p, base_qobject& oct_qobj) - : QsciScintilla (p), m_octave_qobj (oct_qobj), m_word_at_cursor (), - m_selection (), m_selection_replacement (), m_selection_line (-1), - m_selection_col (-1), m_indicator_id (1) + : QsciScintilla (p), m_octave_qobj (oct_qobj), m_debug_mode (false), + m_symbol_names (m_octave_qobj.get_workspace_model ()->get_symbol_names ()), + m_symbol_values (m_octave_qobj.get_workspace_model ()->get_symbol_values ()), + m_word_at_cursor (), m_selection (), m_selection_replacement (), + m_selection_line (-1), m_selection_col (-1), m_indicator_id (1), + m_tooltip_font (QToolTip::font ()) { connect (this, SIGNAL (textChanged (void)), this, SLOT (text_changed (void))); @@ -1118,6 +1121,30 @@ setCursorPosition (line, col); } + bool octave_qscintilla::event (QEvent *e) + { + if (m_debug_mode && e->type() == QEvent::ToolTip) + { + QHelpEvent *help_e = static_cast(e); + QString variable = wordAtPoint (help_e->pos()); + int symbol_idx = m_symbol_names->indexOf (variable); + if (symbol_idx > -1) + { + QToolTip::showText (help_e->globalPos(), variable + + " = " + m_symbol_values->at (symbol_idx)); + } + else + { + QToolTip::hideText(); + e->ignore(); + } + + return true; + } + + return QWidget::event(e); + } + void octave_qscintilla::keyPressEvent (QKeyEvent *key_event) { if (m_selection.isEmpty ()) @@ -1273,6 +1300,24 @@ e->ignore(); } } + + void octave_qscintilla::handle_enter_debug_mode (void) + { + // Set tool tip font to the lexers default font + m_tooltip_font = QToolTip::font (); // Save current font + QToolTip::setFont (lexer ()->defaultFont ()); + + m_debug_mode = true; + } + + void octave_qscintilla::handle_exit_debug_mode (void) + { + m_debug_mode = false; + + // Reset tool tip font + QToolTip::setFont (m_tooltip_font); + } + } #endif diff -r ac5461b59b93 -r 82ccc4e69ba3 libgui/src/m-editor/octave-qscintilla.h --- a/libgui/src/m-editor/octave-qscintilla.h Sun Sep 27 12:29:11 2020 -0400 +++ b/libgui/src/m-editor/octave-qscintilla.h Sun Sep 27 20:26:16 2020 +0200 @@ -98,6 +98,11 @@ void ctx_menu_run_finished_signal (bool, int, QTemporaryFile*, QTemporaryFile*); void focus_console_after_command_signal (void); + public slots: + + void handle_enter_debug_mode (void); + void handle_exit_debug_mode (void); + private slots: void ctx_menu_run_finished (bool, int, QTemporaryFile*, QTemporaryFile*); @@ -121,6 +126,8 @@ void show_replace_action_tooltip (void); + bool event (QEvent *e); + void keyPressEvent (QKeyEvent *e); void dragEnterEvent (QDragEnterEvent *e); @@ -132,6 +139,10 @@ base_qobject& m_octave_qobj; + bool m_debug_mode; + QStringList *m_symbol_names; + QStringList *m_symbol_values; + QString m_word_at_cursor; QString m_selection; @@ -139,6 +150,8 @@ int m_selection_line; int m_selection_col; int m_indicator_id; + + QFont m_tooltip_font; }; } diff -r ac5461b59b93 -r 82ccc4e69ba3 libgui/src/main-window.cc --- a/libgui/src/main-window.cc Sun Sep 27 12:29:11 2020 -0400 +++ b/libgui/src/main-window.cc Sun Sep 27 20:26:16 2020 +0200 @@ -1137,10 +1137,6 @@ m_debug_step_over->setEnabled (true); m_debug_step_out->setEnabled (true); m_debug_quit->setEnabled (true); - -#if defined (HAVE_QSCINTILLA) - m_editor_window->handle_enter_debug_mode (); -#endif } void main_window::handle_exit_debugger (void) @@ -1152,10 +1148,6 @@ m_debug_step_over->setEnabled (m_editor_has_tabs); m_debug_step_out->setEnabled (false); m_debug_quit->setEnabled (false); - -#if defined (HAVE_QSCINTILLA) - m_editor_window->handle_exit_debug_mode (); -#endif } void main_window::debug_continue (void) @@ -2146,6 +2138,13 @@ // Signals for removing/renaming files/dirs in the terminal window connect (qt_link, SIGNAL (file_renamed_signal (bool)), m_editor_window, SLOT (handle_file_renamed (bool))); + + // Signals for entering/exiting debug mode + connect (qt_link, SIGNAL (enter_debugger_signal (void)), + m_editor_window, SLOT (handle_enter_debug_mode (void))); + + connect (qt_link, SIGNAL (exit_debugger_signal (void)), + m_editor_window, SLOT (handle_exit_debug_mode (void))); #endif // Signals for removing/renaming files/dirs in the temrinal window diff -r ac5461b59b93 -r 82ccc4e69ba3 libgui/src/workspace-model.h --- a/libgui/src/workspace-model.h Sun Sep 27 12:29:11 2020 -0400 +++ b/libgui/src/workspace-model.h Sun Sep 27 20:26:16 2020 +0200 @@ -75,7 +75,8 @@ symbol_info_list get_symbol_info (void) const { return m_syminfo_list; } - QStringList get_symbol_names (void) const { return m_symbols; } + QStringList *get_symbol_names (void) { return &m_symbols; } + QStringList *get_symbol_values (void) { return &m_values; } signals: