Mercurial > octave
comparison libgui/src/main-window.cc @ 15607:c9c79d4a0a00
Delete dynamic objects in the main_window destructor for proper cleanup. (bug #37234)
* main-window.h (main_window : public QMainWindow): Remove member variables that aren't utilized.
* main-window.cc (main_window::~main_window): Delete all the objects created by the construct process that remain the ownership of the main_window. Ownership of some other objects are handed off elsewhere.
author | Daniel J Sebald <daniel.sebald@ieee.org> |
---|---|
date | Sat, 13 Oct 2012 23:36:37 -0500 |
parents | 8be22193532b |
children | 1cc10ce368ea |
comparison
equal
deleted
inserted
replaced
15606:fb9dffe5fbfb | 15607:c9c79d4a0a00 |
---|---|
59 octave_link::launch_octave (); | 59 octave_link::launch_octave (); |
60 } | 60 } |
61 | 61 |
62 main_window::~main_window () | 62 main_window::~main_window () |
63 { | 63 { |
64 // Clean up all dynamically created objects to ensure they are | |
65 // deleted before this main_window is. Otherwise, some will be | |
66 // attached to a non-existent parent. | |
67 | |
68 if (_octave_qt_event_listener) | |
69 delete _octave_qt_event_listener; | |
70 | |
71 if (_file_editor) | |
72 delete _file_editor; | |
73 | |
74 if (_terminal_dock_widget) | |
75 delete _terminal_dock_widget; | |
76 | |
77 if (_terminal) | |
78 delete _terminal; | |
79 | |
80 if (_status_bar) | |
81 delete _status_bar; | |
82 | |
83 if (_documentation_dock_widget) | |
84 delete _documentation_dock_widget; | |
85 | |
86 if (_files_dock_widget) | |
87 delete _files_dock_widget; | |
88 | |
89 if (_history_dock_widget) | |
90 delete _history_dock_widget; | |
91 | |
92 if (_workspace_view) | |
93 delete _workspace_view; | |
64 } | 94 } |
65 | 95 |
66 void | 96 void |
67 main_window::new_file () | 97 main_window::new_file () |
68 { | 98 { |
483 _current_directory_combo_box->setEditable (true); | 513 _current_directory_combo_box->setEditable (true); |
484 _current_directory_combo_box->setInsertPolicy (QComboBox::InsertAtTop); | 514 _current_directory_combo_box->setInsertPolicy (QComboBox::InsertAtTop); |
485 _current_directory_combo_box->setMaxVisibleItems (16); | 515 _current_directory_combo_box->setMaxVisibleItems (16); |
486 _current_directory_combo_box->setMaxCount (16); | 516 _current_directory_combo_box->setMaxCount (16); |
487 | 517 |
488 _current_directory_tool_button = new QToolButton (this); | 518 QToolButton *current_directory_tool_button = new QToolButton (this); |
489 _current_directory_tool_button->setIcon (QIcon(":/actions/icons/search.png")); | 519 current_directory_tool_button->setIcon (QIcon(":/actions/icons/search.png")); |
490 | 520 |
491 _current_directory_up_tool_button = new QToolButton (this); | 521 QToolButton *current_directory_up_tool_button = new QToolButton (this); |
492 _current_directory_up_tool_button->setIcon (QIcon(":/actions/icons/up.png")); | 522 current_directory_up_tool_button->setIcon (QIcon(":/actions/icons/up.png")); |
493 | 523 |
494 // Octave Terminal subwindow. | 524 // Octave Terminal subwindow. |
495 _terminal = new QTerminal (this); | 525 _terminal = new QTerminal (this); |
496 _terminal->setObjectName ("OctaveTerminal"); | 526 _terminal->setObjectName ("OctaveTerminal"); |
497 _terminal->setFocusPolicy (Qt::StrongFocus); | 527 _terminal->setFocusPolicy (Qt::StrongFocus); |
498 _terminal_dock_widget = new terminal_dock_widget (_terminal, this); | 528 _terminal_dock_widget = new terminal_dock_widget (_terminal, this); |
499 | 529 |
530 // Create and set the central widget. QMainWindow takes ownership of | |
531 // the widget (pointer) so there is no need to delete the object upon | |
532 // destroying this main_window. | |
500 QWidget *dummyWidget = new QWidget (); | 533 QWidget *dummyWidget = new QWidget (); |
501 dummyWidget->setObjectName ("CentralDummyWidget"); | 534 dummyWidget->setObjectName ("CentralDummyWidget"); |
502 dummyWidget->resize (10, 10); | 535 dummyWidget->resize (10, 10); |
503 dummyWidget->setSizePolicy (QSizePolicy::Minimum, QSizePolicy::Minimum); | 536 dummyWidget->setSizePolicy (QSizePolicy::Minimum, QSizePolicy::Minimum); |
504 dummyWidget->hide (); | 537 dummyWidget->hide (); |
751 main_tool_bar->addAction (copy_action); | 784 main_tool_bar->addAction (copy_action); |
752 main_tool_bar->addAction (paste_action); | 785 main_tool_bar->addAction (paste_action); |
753 main_tool_bar->addAction (undo_action); | 786 main_tool_bar->addAction (undo_action); |
754 main_tool_bar->addAction (redo_action); | 787 main_tool_bar->addAction (redo_action); |
755 main_tool_bar->addSeparator (); | 788 main_tool_bar->addSeparator (); |
789 // addWidget takes ownership of the objects so there is no | |
790 // need to delete these upon destroying this main_window. | |
756 main_tool_bar->addWidget (new QLabel (tr ("Current Directory:"))); | 791 main_tool_bar->addWidget (new QLabel (tr ("Current Directory:"))); |
757 main_tool_bar->addWidget (_current_directory_combo_box); | 792 main_tool_bar->addWidget (_current_directory_combo_box); |
758 main_tool_bar->addWidget (_current_directory_tool_button); | 793 main_tool_bar->addWidget (current_directory_tool_button); |
759 main_tool_bar->addWidget (_current_directory_up_tool_button); | 794 main_tool_bar->addWidget (current_directory_up_tool_button); |
760 | 795 |
761 connect (qApp, SIGNAL (aboutToQuit ()), | 796 connect (qApp, SIGNAL (aboutToQuit ()), |
762 this, SLOT (prepare_for_quit ())); | 797 this, SLOT (prepare_for_quit ())); |
763 connect (preferences_action, SIGNAL (triggered ()), | 798 connect (preferences_action, SIGNAL (triggered ()), |
764 this, SLOT (process_settings_dialog_request ())); | 799 this, SLOT (process_settings_dialog_request ())); |
834 this, SLOT (handle_save_workspace_request ())); | 869 this, SLOT (handle_save_workspace_request ())); |
835 connect (load_workspace_action, SIGNAL (triggered ()), | 870 connect (load_workspace_action, SIGNAL (triggered ()), |
836 this, SLOT (handle_load_workspace_request ())); | 871 this, SLOT (handle_load_workspace_request ())); |
837 connect (clear_workspace_action, SIGNAL (triggered ()), | 872 connect (clear_workspace_action, SIGNAL (triggered ()), |
838 this, SLOT (handle_clear_workspace_request ())); | 873 this, SLOT (handle_clear_workspace_request ())); |
839 connect (_current_directory_tool_button, SIGNAL (clicked ()), | 874 connect (current_directory_tool_button, SIGNAL (clicked ()), |
840 this, SLOT (change_current_working_directory ())); | 875 this, SLOT (change_current_working_directory ())); |
841 connect (_current_directory_up_tool_button, SIGNAL (clicked ()), | 876 connect (current_directory_up_tool_button, SIGNAL (clicked ()), |
842 this, SLOT (current_working_directory_up())); | 877 this, SLOT (current_working_directory_up())); |
843 connect (copy_action, SIGNAL (triggered()), | 878 connect (copy_action, SIGNAL (triggered()), |
844 _terminal, SLOT (copyClipboard ())); | 879 _terminal, SLOT (copyClipboard ())); |
845 connect (paste_action, SIGNAL (triggered()), | 880 connect (paste_action, SIGNAL (triggered()), |
846 _terminal, SLOT (pasteClipboard ())); | 881 _terminal, SLOT (pasteClipboard ())); |