Mercurial > hg > octave-lyh
changeset 16413:28136851099a
remove _terminal pointer from main_window, it is contained by other Qt object
* main-window.cc, main-window.h (main_window::_terminal):
Delete member variable.
(main_window::get_terminal_view, main_window::get_history_dock_widget,
main_window::get_files_dock_widget, main_window::is_closing):
Delete unused functions.
(main_window::notice_settings): New argument settings.
(main_window::handle_command_double_clicked): Don't sent terminal a
command here.
(main_window::process_settings_dialog_request): New argument, settings.
(main_window::read_settings): New argument, settings.
Produce debug message if settings is nul.
(main_window::write_settings): Produce debug message if settings is nul.
(main_window::construct): Make _terminal a local variable and rename
to terminal. Change all uses.
* QTerminal.cc: New file.
(QTerminal::relay_command): New slot.
* QTerminal.h (QTerminal::notice_settings,
QTerminal::notice_settings): New slots.
* QTerminal: Delete.
* files_dockwidget.cc, files_dockwidget.h
(files_dock_widget::notice_settings): New argument, settings.
* file_editor_tab.cc, file_editor_tab.h (file_editor_tab::notice_settings):
Changed the slot to accept QSettings pointer rather than retrieve from
resource_manager. (file_editor_tabl::file_editor_tab,
file_editor_tab::update_lexer): Check that settings is not null
before using.
* file_editor.cc, file_editor.h (file_editor::notice_settings,
file_editor::fetab_settings_changed): New argument, settings.
(file_editor::update_lexer, file_editor::file_editor_tab): Check that
settings is not null before using.
* qterminal-module.mk (qterminal_libqterminal_la_SOURCES): Add
QTerminal.cc to the list.
author | Daniel J Sebald <daniel.sebald@ieee.org> |
---|---|
date | Wed, 03 Apr 2013 00:10:56 -0400 |
parents | 61989cde13ae |
children | 610e02bf9579 aa81cfa5c359 |
files | libgui/qterminal-module.mk libgui/qterminal/libqterminal/QTerminal libgui/qterminal/libqterminal/QTerminal.cc libgui/qterminal/libqterminal/QTerminal.h libgui/src/files-dockwidget.cc libgui/src/files-dockwidget.h libgui/src/m-editor/file-editor-tab.cc libgui/src/m-editor/file-editor-tab.h libgui/src/m-editor/file-editor.cc libgui/src/m-editor/file-editor.h libgui/src/main-window.cc libgui/src/main-window.h |
diffstat | 12 files changed, 125 insertions(+), 102 deletions(-) [+] |
line wrap: on
line diff
--- a/libgui/qterminal-module.mk +++ b/libgui/qterminal-module.mk @@ -46,7 +46,8 @@ qterminal_libqterminal_la_SOURCES = \ qterminal/libqterminal/win32/QTerminalColors.cpp \ - qterminal/libqterminal/win32/QWinTerminalImpl.cpp + qterminal/libqterminal/win32/QWinTerminalImpl.cpp \ + qterminal/libqterminal/QTerminal.cc qterminal_libqterminal_la_MOC += \ qterminal/libqterminal/win32/moc-QWinTerminalImpl.cc @@ -73,7 +74,8 @@ qterminal/libqterminal/unix/Vt102Emulation.cpp \ qterminal/libqterminal/unix/SelfListener.cpp \ qterminal/libqterminal/unix/TerminalModel.cpp \ - qterminal/libqterminal/unix/TerminalView.cpp + qterminal/libqterminal/unix/TerminalView.cpp \ + qterminal/libqterminal/QTerminal.cc qterminal_libqterminal_la_MOC += \ qterminal/libqterminal/unix/moc-Emulation.cc \
deleted file mode 100644 --- a/libgui/qterminal/libqterminal/QTerminal +++ /dev/null @@ -1,23 +0,0 @@ -/* - -Copyright (C) 2012 Michael Goffioul. -Copyright (C) 2012 Jacob Dawid. - -This file is part of QTerminal. - -Foobar is free software: you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation, either version 3 of the License, or -(at your option) any later version. - -QTerminal is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with Foobar. If not, see <http://www.gnu.org/licenses/>. - -*/ - -#include "QTerminal.h"
new file mode 100644 --- /dev/null +++ b/libgui/qterminal/libqterminal/QTerminal.cc @@ -0,0 +1,52 @@ +/* + +Copyright (C) 2012 Michael Goffioul. +Copyright (C) 2012 Jacob Dawid. + +This file is part of QTerminal. + +Foobar is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +QTerminal is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with Foobar. If not, see <http://www.gnu.org/licenses/>. + +*/ + +#include "QTerminal.h" + +#include <QSettings> + +void +QTerminal::notice_settings (const QSettings *settings) +{ + // QSettings pointer is checked before emitting. + + // Set terminal font: + QFont term_font = QFont(); + term_font.setFamily(settings->value("terminal/fontName","Courier New").toString()); + term_font.setPointSize(settings->value("terminal/fontSize",10).toInt ()); + setTerminalFont (term_font); + + QString cursorType = settings->value ("terminal/cursorType","ibeam").toString (); + bool cursorBlinking = settings->value ("terminal/cursorBlinking",true).toBool (); + if (cursorType == "ibeam") + setCursorType(QTerminalInterface::IBeamCursor, cursorBlinking); + else if (cursorType == "block") + setCursorType(QTerminalInterface::BlockCursor, cursorBlinking); + else if (cursorType == "underline") + setCursorType(QTerminalInterface::UnderlineCursor, cursorBlinking); +} + +void +QTerminal::relay_command (const QString& command) +{ + sendText (command); +}
--- a/libgui/qterminal/libqterminal/QTerminal.h +++ b/libgui/qterminal/libqterminal/QTerminal.h @@ -34,6 +34,10 @@ QTerminal(QWidget *xparent = 0) : QWinTerminalImpl(xparent) { } ~QTerminal() { } + + public slots: + void notice_settings (const QSettings *settings); + void relay_command (const QString& text); }; #else #include "unix/QUnixTerminalImpl.h" @@ -44,6 +48,10 @@ QTerminal(QWidget *xparent = 0) : QUnixTerminalImpl(xparent) { } ~QTerminal() { } + + public slots: + void notice_settings (const QSettings *settings); + void relay_command (const QString& command); }; #endif
--- a/libgui/src/files-dockwidget.cc +++ b/libgui/src/files-dockwidget.cc @@ -182,11 +182,10 @@ } void -files_dock_widget::notice_settings () +files_dock_widget::notice_settings (const QSettings *settings) { - QSettings *settings = resource_manager::get_settings (); + // Qsettings pointer is checked before emitting. - // FIXME -- what should happen if settings is 0? // file names are always shown, other columns can be hidden by settings _file_tree_view->setColumnHidden (0, false); _file_tree_view->setColumnHidden (1, !settings->value ("showFileSize",false).toBool ());
--- a/libgui/src/files-dockwidget.h +++ b/libgui/src/files-dockwidget.h @@ -34,6 +34,7 @@ #include <QVBoxLayout> #include <QAction> #include <QTreeView> +#include <QSettings> #include <QLineEdit> #include "octave-dock-widget.h" @@ -67,7 +68,7 @@ void display_directory (const QString& directory); /** Tells the widget to react on changed settings. */ - void notice_settings (); + void notice_settings (const QSettings *settings); signals: /** Emitted, whenever the user requested to open a file. */
--- a/libgui/src/m-editor/file-editor-tab.cc +++ b/libgui/src/m-editor/file-editor-tab.cc @@ -116,7 +116,9 @@ connect (&_file_system_watcher, SIGNAL (fileChanged (QString)), this, SLOT (file_has_changed (QString))); - notice_settings (); + QSettings *settings = resource_manager::get_settings (); + if (settings) + notice_settings (settings); } file_editor_tab::~file_editor_tab () @@ -242,7 +244,8 @@ } QSettings *settings = resource_manager::get_settings (); - lexer->readSettings (*settings); + if (settings) + lexer->readSettings (*settings); _edit_area->setLexer (lexer); } @@ -1003,14 +1006,12 @@ } void -file_editor_tab::notice_settings () +file_editor_tab::notice_settings (const QSettings *settings) { + // QSettings pointer is checked before emitting. + update_lexer (); QFontMetrics lexer_font_metrics (_edit_area->lexer ()->defaultFont (0)); - QSettings *settings = resource_manager::get_settings (); - - if (settings==NULL) - return; // this shouldn't happen! _edit_area->setCaretLineVisible(settings->value ("editor/highlightCurrentLine",true).toBool ());
--- a/libgui/src/m-editor/file-editor-tab.h +++ b/libgui/src/m-editor/file-editor-tab.h @@ -27,6 +27,7 @@ #include <QWidget> #include <QCloseEvent> #include <QFileSystemWatcher> +#include <QSettings> #include "find-dialog.h" @@ -44,7 +45,7 @@ void handle_margin_clicked (int line, int margin, Qt::KeyboardModifiers state); /** Tells the editor tab to react on changed settings. */ - void notice_settings (); + void notice_settings (const QSettings *settings); /** Will initiate close if associated with the identifier tag. */ void conditional_close (const QWidget* ID); /** Change to a different editor tab by identifier tag. */
--- a/libgui/src/m-editor/file-editor.cc +++ b/libgui/src/m-editor/file-editor.cc @@ -594,10 +594,10 @@ } void -file_editor::notice_settings () +file_editor::notice_settings (const QSettings *settings) { // Relay signal to file editor tabs. - emit fetab_settings_changed (); + emit fetab_settings_changed (settings); } void @@ -874,8 +874,8 @@ parent (), SLOT (handle_command_double_clicked (const QString&))); // Signals from the file_editor non-trivial operations - connect (this, SIGNAL (fetab_settings_changed ()), - f, SLOT (notice_settings ())); + connect (this, SIGNAL (fetab_settings_changed (const QSettings *)), + f, SLOT (notice_settings (const QSettings *))); connect (this, SIGNAL (fetab_close_request (const QWidget*)), f, SLOT (conditional_close (const QWidget*))); connect (this, SIGNAL (fetab_change_request (const QWidget*)),
--- a/libgui/src/m-editor/file-editor.h +++ b/libgui/src/m-editor/file-editor.h @@ -29,6 +29,7 @@ #include <QStatusBar> #include <QCloseEvent> #include <QTabWidget> +#include <QSettings> #include <map> @@ -60,7 +61,7 @@ void handle_quit_debug_mode (); signals: - void fetab_settings_changed (); + void fetab_settings_changed (const QSettings *settings); void fetab_close_request (const QWidget* ID); void fetab_change_request (const QWidget* ID); void fetab_file_name_query (const QWidget* ID); @@ -138,7 +139,7 @@ void handle_edit_file_request (const QString& file); /** Tells the editor to react on changed settings. */ - void notice_settings (); + void notice_settings (const QSettings *settings); private slots: void request_open_file (const QString& fileName, int line = -1,
--- a/libgui/src/main-window.cc +++ b/libgui/src/main-window.cc @@ -161,9 +161,8 @@ } void -main_window::handle_command_double_clicked (const QString& command) +main_window::handle_command_double_clicked (const QString&) { - _terminal->sendText (command); focus_command_window (); } @@ -199,34 +198,18 @@ if (change_settings == QDialog::Accepted) { settingsDialog->write_changed_settings (); - emit settings_changed (); + QSettings *settings = resource_manager::get_settings (); + if (settings) + emit settings_changed (settings); } delete settingsDialog; } void -main_window::notice_settings () +main_window::notice_settings (const QSettings *settings) { - QSettings *settings = resource_manager::get_settings (); - - // FIXME -- what should happen if settings is 0? - - // Set terminal font: - QFont term_font = QFont(); - term_font.setFamily(settings->value("terminal/fontName","Courier New").toString()); - term_font.setPointSize(settings->value("terminal/fontSize",10).toInt ()); - _terminal->setTerminalFont (term_font); - - QString cursorType = settings->value ("terminal/cursorType","ibeam").toString (); - bool cursorBlinking = settings->value ("terminal/cursorBlinking",true).toBool (); - if (cursorType == "ibeam") - _terminal->setCursorType(QTerminalInterface::IBeamCursor, cursorBlinking); - else if (cursorType == "block") - _terminal->setCursorType(QTerminalInterface::BlockCursor, cursorBlinking); - else if (cursorType == "underline") - _terminal->setCursorType(QTerminalInterface::UnderlineCursor, - cursorBlinking); + // QSettings pointer is checked before emitting. // the widget's icons (when floating) QString icon_set = settings->value ("DockWidgets/widget_icon_set","NONE"). @@ -365,9 +348,9 @@ _terminal_dock_widget->activateWindow (); _terminal_dock_widget->raise (); - _terminal->setFocus (); - _terminal->activateWindow (); - _terminal->raise (); + _terminal_dock_widget->widget ()->setFocus (); + _terminal_dock_widget->widget ()->activateWindow (); + _terminal_dock_widget->widget ()->raise (); } void @@ -592,8 +575,11 @@ main_window::read_settings () { QSettings *settings = resource_manager::get_settings (); - - // FIXME -- what should happen if settings is 0? + if (!settings) + { + qDebug("Error: QSettings pointer from resource manager is NULL."); + return; + } restoreState (settings->value ("MainWindow/windowState").toByteArray ()); settings->beginGroup ("DockWidgets"); @@ -621,15 +607,18 @@ { _current_directory_combo_box->addItem (curr_dirs.at (i)); } - emit settings_changed (); + emit settings_changed (settings); } void main_window::write_settings () { QSettings *settings = resource_manager::get_settings (); - - // FIXME -- what should happen if settings is 0? + if (!settings) + { + qDebug("Error: QSettings pointer from resource manager is NULL."); + return; + } settings->setValue ("MainWindow/geometry", saveGeometry ()); settings->beginGroup ("DockWidgets"); @@ -719,10 +708,10 @@ current_directory_up_tool_button->setIcon (QIcon(":/actions/icons/up.png")); // Octave Terminal subwindow. - _terminal = new QTerminal (this); - _terminal->setObjectName ("OctaveTerminal"); - _terminal->setFocusPolicy (Qt::StrongFocus); - _terminal_dock_widget = new terminal_dock_widget (_terminal, this); + QTerminal *terminal = new QTerminal (this); + terminal->setObjectName ("OctaveTerminal"); + terminal->setFocusPolicy (Qt::StrongFocus); + _terminal_dock_widget = new terminal_dock_widget (terminal, this); // Create and set the central widget. QMainWindow takes ownership of // the widget (pointer) so there is no need to delete the object upon @@ -1101,21 +1090,25 @@ connect (reset_windows_action, SIGNAL (triggered ()), this, SLOT (reset_windows ())); #ifdef HAVE_QSCINTILLA - connect (this, SIGNAL (settings_changed ()), - _file_editor, SLOT (notice_settings ())); + connect (this, SIGNAL (settings_changed (const QSettings *)), + _file_editor, SLOT (notice_settings (const QSettings *))); #endif - connect (this, SIGNAL (settings_changed ()), - _files_dock_widget, SLOT (notice_settings ())); - connect (this, SIGNAL (settings_changed ()), - this, SLOT (notice_settings ())); + connect (this, SIGNAL (settings_changed (const QSettings *)), + terminal, SLOT (notice_settings (const QSettings *))); + connect (this, SIGNAL (settings_changed (const QSettings *)), + _files_dock_widget, SLOT (notice_settings (const QSettings *))); + connect (this, SIGNAL (settings_changed (const QSettings *)), + this, SLOT (notice_settings (const QSettings *))); connect (_files_dock_widget, SIGNAL (open_file (QString)), this, SLOT (open_file (QString))); connect (_files_dock_widget, SIGNAL (displayed_directory_changed(QString)), this, SLOT (set_current_working_directory(QString))); connect (_history_dock_widget, SIGNAL (information (QString)), this, SLOT (report_status_message (QString))); - connect (_history_dock_widget, SIGNAL (command_double_clicked (QString)), - this, SLOT (handle_command_double_clicked (QString))); + connect (_history_dock_widget, SIGNAL (command_double_clicked (const QString&)), + this, SLOT (handle_command_double_clicked (const QString&))); + connect (_history_dock_widget, SIGNAL (command_double_clicked (const QString&)), + terminal, SLOT (relay_command (const QString&))); connect (save_workspace_action, SIGNAL (triggered ()), this, SLOT (handle_save_workspace_request ())); connect (load_workspace_action, SIGNAL (triggered ()), @@ -1127,9 +1120,9 @@ connect (current_directory_up_tool_button, SIGNAL (clicked ()), this, SLOT (current_working_directory_up())); connect (copy_action, SIGNAL (triggered()), - _terminal, SLOT (copyClipboard ())); + terminal, SLOT (copyClipboard ())); connect (paste_action, SIGNAL (triggered()), - _terminal, SLOT (pasteClipboard ())); + terminal, SLOT (pasteClipboard ())); connect (_current_directory_combo_box, SIGNAL (activated (QString)), this, SLOT (set_current_working_directory (QString))); connect (_current_directory_line_edit, SIGNAL (returnPressed ()),
--- a/libgui/src/main-window.h +++ b/libgui/src/main-window.h @@ -62,19 +62,8 @@ main_window (QWidget * parent = 0); ~main_window (); - QTerminal *get_terminal_view () { return _terminal; } - history_dock_widget *get_history_dock_widget () - { - return _history_dock_widget; - } - files_dock_widget *get_files_dock_widget () - { - return _files_dock_widget; - } - bool is_closing () { return _closing; } - signals: - void settings_changed (); + void settings_changed (const QSettings *); public slots: void report_status_message (const QString& statusMessage); @@ -92,7 +81,7 @@ void open_agora_page (); void process_settings_dialog_request (); void show_about_octave (); - void notice_settings (); + void notice_settings (const QSettings *settings); void prepare_for_quit (); void reset_windows (); void current_working_directory_has_changed (const QString& directory); @@ -161,7 +150,6 @@ void exit_callback (void); - QTerminal * _terminal; #ifdef HAVE_QSCINTILLA file_editor_interface * _file_editor; #endif