Mercurial > octave
changeset 29597:07591becbc40
eliminate more child to parent signal/slot connections
* main-window.cc (create_default_editor): Delete.
* file-editor.h, file-editor.cc (file_editor::update_gui_lexer_signal,
file_editor::execute_command_in_terminal_signal,
file_editor::focus_console_after_command_signal,
file_editor::run_file_signal, file_editor::edit_mfile_request,
file_editor::debug_quit_signal): New signals.
(file_editor::make_file_editor_tab): Instead of connecting signals
from the tab to parent object slots, forward through new file_editor
signals.
* main-window.cc (main_window::main_window): Connect file_editor
signals to main_window slots here.
(file_editor::find_create, file_editor::is_editor_console_tabbed,
file_editor::empty_script): Use parentWidget instead of calling
main_win.
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Mon, 03 May 2021 13:30:29 -0400 |
parents | d2b56b5e9d43 |
children | c7b104ebed4d |
files | libgui/src/m-editor/file-editor.cc libgui/src/m-editor/file-editor.h libgui/src/main-window.cc |
diffstat | 3 files changed, 119 insertions(+), 82 deletions(-) [+] |
line wrap: on
line diff
--- a/libgui/src/m-editor/file-editor.cc Mon May 03 09:24:16 2021 -0400 +++ b/libgui/src/m-editor/file-editor.cc Mon May 03 13:30:29 2021 -0400 @@ -72,6 +72,7 @@ { tab_bar *bar = new tab_bar (this); + // FIXME: Making a connection to a grandparent object seems bad. connect (bar, SIGNAL (close_current_tab_signal (bool)), p->parent (), SLOT (request_close_file (bool))); @@ -273,28 +274,33 @@ if (startup && ! isFloating ()) { // check if editor is really visible or hidden between tabbed widgets - QList<QTabBar *> tab_list = main_win ()->findChildren<QTabBar *>(); - - bool in_tab = false; - int i = 0; - while ((i < tab_list.count ()) && (! in_tab)) + QWidget *parent = parentWidget (); + + if (parent) { - QTabBar *tab = tab_list.at (i); - i++; - - int j = 0; - while ((j < tab->count ()) && (! in_tab)) + QList<QTabBar *> tab_list = parent->findChildren<QTabBar *>(); + + bool in_tab = false; + int i = 0; + while ((i < tab_list.count ()) && (! in_tab)) { - // check all tabs for the editor - if (tab->tabText (j) == windowTitle ()) + QTabBar *tab = tab_list.at (i); + i++; + + int j = 0; + while ((j < tab->count ()) && (! in_tab)) { - // editor is in this tab widget - in_tab = true; - int top = tab->currentIndex (); - if (! (top > -1 && tab->tabText (top) == windowTitle ())) - return; // not current tab -> not visible + // check all tabs for the editor + if (tab->tabText (j) == windowTitle ()) + { + // editor is in this tab widget + in_tab = true; + int top = tab->currentIndex (); + if (! (top > -1 && tab->tabText (top) == windowTitle ())) + return; // not current tab -> not visible + } + j++; } - j++; } } } @@ -867,7 +873,7 @@ if (isFloating ()) m_find_dialog = new find_dialog (m_octave_qobj, this, this); else - m_find_dialog = new find_dialog (m_octave_qobj, this, main_win ()); + m_find_dialog = new find_dialog (m_octave_qobj, this, parentWidget ()); // Add required actions m_find_dialog->addAction (m_find_next_action); @@ -888,8 +894,14 @@ if (! isFloating ()) { // Fix position if editor is docked - xp = xp + main_win ()->x(); - yp = yp + main_win ()->y(); + + QWidget *parent = parentWidget (); + + if (parent) + { + xp = xp + parent->x (); + yp = yp + parent->y (); + } } if (yp < 0) @@ -1828,15 +1840,22 @@ bool file_editor::is_editor_console_tabbed (void) { - main_window *w = static_cast<main_window *>(main_win ()); - QList<QDockWidget *> w_list = w->tabifiedDockWidgets (this); - QDockWidget *console = - static_cast<QDockWidget *> (w->get_dock_widget_list ().at (0)); - - for (int i = 0; i < w_list.count (); i++) + // FIXME: is there a way to do this job that doesn't require casting + // the parent to a main_window object? + + main_window *w = dynamic_cast<main_window *> (parentWidget ()); + + if (w) { - if (w_list.at (i) == console) - return true; + QList<QDockWidget *> w_list = w->tabifiedDockWidgets (this); + QDockWidget *console = + static_cast<QDockWidget *> (w->get_dock_widget_list ().at (0)); + + for (int i = 0; i < w_list.count (); i++) + { + if (w_list.at (i) == console) + return true; + } } return false; @@ -2314,12 +2333,6 @@ SLOT (copy_full_file_path (bool)), this); // signals - connect (this, SIGNAL (request_settings_dialog (const QString&)), - main_win (), SLOT (process_settings_dialog_request (const QString&))); - - connect (this, SIGNAL (request_dbcont_signal (void)), - main_win (), SLOT (debug_continue (void))); - connect (m_mru_file_menu, &QMenu::triggered, this, &file_editor::request_mru_open_file); @@ -2381,19 +2394,9 @@ connect (f->qsci_edit_area (), &octave_qscintilla::status_update, this, &file_editor::edit_status_update); - connect (f->qsci_edit_area (), SIGNAL (show_doc_signal (const QString&)), - main_win (), SLOT (handle_show_doc (const QString&))); - connect (f->qsci_edit_area (), &octave_qscintilla::create_context_menu_signal, this, &file_editor::create_context_menu); - connect (f->qsci_edit_area (), SIGNAL (execute_command_in_terminal_signal (const QString&)), - main_win (), SLOT (execute_command_in_terminal (const QString&))); - - connect (f->qsci_edit_area (), - SIGNAL (focus_console_after_command_signal (void)), - main_win (), SLOT (focus_console_after_command (void))); - connect (f->qsci_edit_area (), &octave_qscintilla::SCN_AUTOCCOMPLETED, this, &file_editor::reset_focus); @@ -2426,18 +2429,9 @@ connect (f, &file_editor_tab::mru_add_file, this, &file_editor::handle_mru_add_file); - connect (f, SIGNAL (run_file_signal (const QFileInfo&)), - main_win (), SLOT (run_file_in_terminal (const QFileInfo&))); - connect (f, &file_editor_tab::request_open_file, this, [=] (const QString& fname, const QString& encoding) { request_open_file (fname, encoding); }); - connect (f, SIGNAL (edit_mfile_request (const QString&, const QString&, - const QString&, int)), - main_win (), SLOT (handle_edit_mfile_request (const QString&, - const QString&, - const QString&, int))); - connect (f, &file_editor_tab::edit_area_changed, this, &file_editor::edit_area_changed); @@ -2451,12 +2445,8 @@ connect (this, &file_editor::fetab_change_request, f, &file_editor_tab::change_editor_state); - connect (this, SIGNAL (fetab_save_file (const QWidget*, const QString&, - bool)), - f, SLOT (save_file (const QWidget*, const QString&, bool))); - - connect (main_win (), SIGNAL (update_gui_lexer_signal (bool)), - f, SLOT (update_lexer_settings (bool))); + connect (this, QOverload<const QWidget*, const QString&, bool>::of (&file_editor::fetab_save_file), + f, QOverload<const QWidget*, const QString&, bool>::of (&file_editor_tab::save_file)); // Signals from the file_editor trivial operations connect (this, &file_editor::fetab_recover_from_exit, @@ -2478,11 +2468,11 @@ connect (this, &file_editor::fetab_context_edit, f, &file_editor_tab::context_edit); - connect (this, SIGNAL (fetab_save_file (const QWidget*)), - f, SLOT (save_file (const QWidget*))); - - connect (this, SIGNAL (fetab_save_file_as (const QWidget*)), - f, SLOT (save_file_as (const QWidget*))); + connect (this, QOverload<const QWidget*>::of (&file_editor::fetab_save_file), + f, QOverload<const QWidget*>::of (&file_editor_tab::save_file)); + + connect (this, &file_editor::fetab_save_file_as, + f, QOverload<const QWidget *>::of (&file_editor_tab::save_file_as)); connect (this, &file_editor::fetab_print_file, f, &file_editor_tab::print_file); @@ -2556,12 +2546,35 @@ connect (this, &file_editor::fetab_delete_debugger_pointer, f, &file_editor_tab::delete_debugger_pointer); - connect (f, SIGNAL (debug_quit_signal (void)), - main_win (), SLOT (debug_quit (void))); - connect (this, &file_editor::fetab_do_breakpoint_marker, f, &file_editor_tab::do_breakpoint_marker); + connect (this, &file_editor::update_gui_lexer_signal, + f, &file_editor_tab::update_lexer_settings); + + // FIXME: What was the intent here? The + // main_window::handle_show_doc slot no longer exists. + // + // connect (f->qsci_edit_area (), SIGNAL (show_doc_signal (const QString&)), + // main_win (), SLOT (handle_show_doc (const QString&))); + + // Convert other signals from the edit area and tab to editor signals. + + connect (f->qsci_edit_area (), &octave_qscintilla::execute_command_in_terminal_signal, + this, &file_editor::execute_command_in_terminal_signal); + + connect (f->qsci_edit_area (), &octave_qscintilla::focus_console_after_command_signal, + this, &file_editor::focus_console_after_command_signal); + + connect (f, &file_editor_tab::run_file_signal, + this, &file_editor::run_file_signal); + + connect (f, &file_editor_tab::edit_mfile_request, + this, &file_editor::edit_mfile_request); + + connect (f, &file_editor_tab::debug_quit_signal, + this, &file_editor::debug_quit_signal); + // Any interpreter_event signal from a file_editor_tab_widget is // handled the same as for the parent main_window object.
--- a/libgui/src/m-editor/file-editor.h Mon May 03 09:24:16 2021 -0400 +++ b/libgui/src/m-editor/file-editor.h Mon May 03 13:30:29 2021 -0400 @@ -177,6 +177,13 @@ void enter_debug_mode_signal (void); void exit_debug_mode_signal (void); + void update_gui_lexer_signal (bool); + void execute_command_in_terminal_signal (const QString&); + void focus_console_after_command_signal (void); + void run_file_signal (const QFileInfo&); + void edit_mfile_request (const QString&, const QString&, const QString&, int); + void debug_quit_signal (void); + public slots: void activate (void);
--- a/libgui/src/main-window.cc Mon May 03 09:24:16 2021 -0400 +++ b/libgui/src/main-window.cc Mon May 03 13:30:29 2021 -0400 @@ -95,19 +95,6 @@ namespace octave { - static file_editor_interface * - create_default_editor (QWidget *p, base_qobject& oct_qobj) - { -#if defined (HAVE_QSCINTILLA) - return new file_editor (p, oct_qobj); -#else - octave_unused_parameter (p); - octave_unused_parameter (oct_qobj); - - return 0; -#endif - } - main_window::main_window (base_qobject& oct_qobj) : QMainWindow (), m_octave_qobj (oct_qobj), m_workspace_model (nullptr), @@ -194,7 +181,37 @@ m_doc_browser_window = new documentation_dock_widget (this, m_octave_qobj); - m_editor_window = create_default_editor (this, m_octave_qobj); +#if defined (HAVE_QSCINTILLA) + file_editor *editor = new file_editor (this, m_octave_qobj); + + connect (editor, &file_editor::request_settings_dialog, + this, QOverload<const QString&>::of (&main_window::process_settings_dialog_request)); + + connect (editor, &file_editor::request_dbcont_signal, + this, &main_window::debug_continue); + + connect (this, &main_window::update_gui_lexer_signal, + editor, &file_editor::update_gui_lexer_signal); + + connect (editor, &file_editor::execute_command_in_terminal_signal, + this, &main_window::execute_command_in_terminal); + + connect (editor, &file_editor::focus_console_after_command_signal, + this, &main_window::focus_console_after_command); + + connect (editor, &file_editor::run_file_signal, + this, &main_window::run_file_in_terminal); + + connect (editor, &file_editor::edit_mfile_request, + this, &main_window::handle_edit_mfile_request); + + connect (editor, &file_editor::debug_quit_signal, + this, &main_window::debug_quit); + + m_editor_window = editor; +#else + m_editor_window = nullptr; +#endif m_variable_editor_window = new variable_editor (this, m_octave_qobj);