# HG changeset patch # User John W. Eaton # Date 1344697332 14400 # Node ID 9e62d5a3a45e547df73b79fc27c11e1f4f4c1eab # Parent d8a10cae1dcdf6a2aecab4ac50a079fcb45a4961 partial cleanup of include files in gui sources * symbol-information.cc, octave-adapter/octave-event.cc: New files. * documentation-dockwidget.h, history-dockwidget.cc, m-editor/file-editor.h, octave-event.cc, octave-event.h, octave-link.cc, octave-link.h, octave-main-thread.cc, octave-gui.cc, symbol-information.cc, symbol-information.h, workspace-model.cc: Avoid including unnecssary header files. diff --git a/gui/src/Makefile.am b/gui/src/Makefile.am --- a/gui/src/Makefile.am +++ b/gui/src/Makefile.am @@ -48,6 +48,7 @@ octave-qt-event-listener.cc \ resource-manager.cc \ settings-dialog.cc \ + symbol-information.cc \ terminal-dockwidget.cc \ welcome-wizard.cc \ workspace-model.cc \ @@ -56,6 +57,7 @@ m-editor/file-editor-tab.cc \ m-editor/find-dialog.cc \ m-editor/lexer-octave-gui.cc \ + octave-adapter/octave-event.cc \ octave-adapter/octave-link.cc \ octave-adapter/octave-main-thread.cc \ qtinfo/parser.cc \ diff --git a/gui/src/documentation-dockwidget.h b/gui/src/documentation-dockwidget.h --- a/gui/src/documentation-dockwidget.h +++ b/gui/src/documentation-dockwidget.h @@ -18,6 +18,7 @@ #ifndef DOCUMENTATIONDOCKWIDGET_H #define DOCUMENTATIONDOCKWIDGET_H +#include #include #include "webinfo.h" diff --git a/gui/src/history-dockwidget.cc b/gui/src/history-dockwidget.cc --- a/gui/src/history-dockwidget.cc +++ b/gui/src/history-dockwidget.cc @@ -15,8 +15,15 @@ * along with this program. If not, see . */ +#ifdef HAVE_CONFIG_H +#include +#endif + +#include + +#include "cmd-hist.h" + #include "history-dockwidget.h" -#include history_dock_widget::history_dock_widget (QWidget * parent) : QDockWidget (parent), octave_event_observer () diff --git a/gui/src/m-editor/file-editor.h b/gui/src/m-editor/file-editor.h --- a/gui/src/m-editor/file-editor.h +++ b/gui/src/m-editor/file-editor.h @@ -18,10 +18,6 @@ #ifndef FILEEDITORMDISUBWINDOW_H #define FILEEDITORMDISUBWINDOW_H -#include "main-window.h" -#include "file-editor-interface.h" -#include "file-editor-tab.h" - #include #include #include @@ -29,6 +25,10 @@ #include #include +#include "main-window.h" +#include "file-editor-interface.h" +#include "file-editor-tab.h" + const char UNNAMED_FILE[] = ""; const char SAVE_FILE_FILTER[] = "Octave Files (*.m);;All Files (*.*)"; enum editor_markers diff --git a/gui/src/octave-adapter/octave-event.cc b/gui/src/octave-adapter/octave-event.cc new file mode 100644 --- /dev/null +++ b/gui/src/octave-adapter/octave-event.cc @@ -0,0 +1,170 @@ +/* OctaveGUI - A graphical user interface for Octave + * Copyright (C) 2011 John P. Swensen, Jacob Dawid (jacob.dawid@googlemail.com) + * + * This program 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. + * + * This program 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 this program. If not, see . + */ + +#ifdef HAVE_CONFIG_H +#include +#endif + +#include + +#include "cmd-hist.h" +#include "oct-env.h" + +#include "debug.h" +#include "oct-obj.h" +#include "parse.h" +#include "symtab.h" +#include "toplev.h" + +#include "octave-event.h" + +#include + +void +octave_event::call_octave_function (std::string name) +{ + call_octave_function (name, octave_value_list ()); +} + +void +octave_event::call_octave_function (std::string name, + const octave_value_list& args, + int nargout) +{ + try + { + feval (name, args, nargout); + } catch (...) { } // Ignore exceptions. Crashes without that. +} + +void +octave_event::finish_readline_event () const +{ + rl_line_buffer[0] = '\0'; + rl_point = rl_end = 0; + rl_done = 1; + //rl_forced_update_display (); +} + +bool +octave_clear_history_event::perform () +{ + int i; + while ((i = command_history::length ()) > 0) { + command_history::remove (i - 1); + } + return true; +} + +bool +octave_debug_step_into_event::perform () +{ + octave_value_list args; + args.append (octave_value ("in")); + call_octave_function ("dbstep", args); + finish_readline_event (); + return true; +} + +bool +octave_debug_step_out_event::perform () +{ + octave_value_list args; + args.append (octave_value ("out")); + call_octave_function ("dbstep", args); + finish_readline_event (); + return true; +} + + +bool +octave_exit_event::perform () +{ + clean_up_and_exit (0); + return true; +} + +bool +octave_run_file_event::perform () +{ + octave_value_list args; + args.append (octave_value (_file)); + call_octave_function ("run", args); + finish_readline_event (); + return true; +} + +bool +octave_change_directory_event::perform () +{ + return octave_env::chdir (_directory); +} + +bool +octave_load_workspace_event::perform () +{ + octave_value_list args; + args.append (octave_value (_file)); + call_octave_function ("load", args); + return true; +} + +bool +octave_save_workspace_event::perform () +{ + octave_value_list args; + args.append (octave_value (_file)); + call_octave_function ("save", args); + return true; +} + +bool +octave_add_breakpoint_event::perform () +{ + bp_table::intmap intmap; + intmap[0] = _line + 1; + + std::string previous_directory = octave_env::get_current_directory (); + octave_env::chdir (_path); + intmap = bp_table::add_breakpoint (_function_name, intmap); + octave_env::chdir (previous_directory); + return intmap.size () > 0; +} + +bool +octave_remove_breakpoint_event::perform () +{ + bp_table::intmap intmap; + intmap[0] = _line; + + std::string previous_directory = octave_env::get_current_directory (); + octave_env::chdir (_path); + bp_table::remove_breakpoint (_function_name, intmap); + octave_env::chdir (previous_directory); + return true; // TODO: Check result. +} + +bool +octave_remove_all_breakpoints_event::perform () +{ + bp_table::intmap intmap; + std::string previous_directory = octave_env::get_current_directory (); + octave_env::chdir (_path); + intmap = bp_table::remove_all_breakpoints_in_file (_function_name, true); + octave_env::chdir (previous_directory); + return intmap.size() > 0; +} diff --git a/gui/src/octave-adapter/octave-event.h b/gui/src/octave-adapter/octave-event.h --- a/gui/src/octave-adapter/octave-event.h +++ b/gui/src/octave-adapter/octave-event.h @@ -19,17 +19,10 @@ #define OCTAVEEVENT_H #include + +class octave_value_list; + #include "octave-event-observer.h" -#include "config.h" -#include "symtab.h" -#include "oct-env.h" -#include "pt-eval.h" -#include "toplev.h" -#include "parse.h" -#include "debug.h" -#include "cmd-hist.h" - -#include /** * \class octave_event @@ -74,23 +67,13 @@ { _octave_event_observer.event_reject (this); } protected: + void call_octave_function (std::string name); + void call_octave_function (std::string name, - const octave_value_list& args = octave_value_list (), - int nargout = 0) - { - try - { - feval (name, args, nargout); - } catch (...) { } // Ignore exceptions. Crashes without that. - } + const octave_value_list& args, + int nargout = 0); - void finish_readline_event () const - { - rl_line_buffer[0] = '\0'; - rl_point = rl_end = 0; - rl_done = 1; - //rl_forced_update_display (); - } + void finish_readline_event () const; private: octave_event_observer& _octave_event_observer; @@ -129,8 +112,7 @@ : octave_event (o) { } - bool perform () - { clean_up_and_exit (0); return true; } + bool perform (); }; /** Implements an octave run file event. */ @@ -143,14 +125,7 @@ : octave_event (o) { _file = file; } - bool perform () - { - octave_value_list args; - args.append (octave_value (_file)); - call_octave_function ("run", args); - finish_readline_event (); - return true; - } + bool perform (); private: std::string _file; @@ -166,8 +141,7 @@ : octave_event (o) { _directory = directory; } - bool perform () - { return octave_env::chdir (_directory); } + bool perform (); private: std::string _directory; @@ -199,13 +173,7 @@ : octave_event (o) { _file = file; } - bool perform () - { - octave_value_list args; - args.append (octave_value (_file)); - call_octave_function ("load", args); - return true; - } + bool perform (); private: std::string _file; @@ -221,13 +189,7 @@ : octave_event (o) { _file = file; } - bool perform () - { - octave_value_list args; - args.append (octave_value (_file)); - call_octave_function ("save", args); - return true; - } + bool perform (); private: std::string _file; @@ -241,14 +203,7 @@ : octave_event (o) { } - bool perform () - { - int i; - while ((i = command_history::length ()) > 0) { - command_history::remove (i - 1); - } - return true; - } + bool perform (); }; class octave_add_breakpoint_event : public octave_event @@ -265,17 +220,7 @@ _line = line; } - bool perform () - { - bp_table::intmap intmap; - intmap[0] = _line + 1; - - std::string previous_directory = octave_env::get_current_directory (); - octave_env::chdir (_path); - intmap = bp_table::add_breakpoint (_function_name, intmap); - octave_env::chdir (previous_directory); - return intmap.size () > 0; - } + bool perform (); std::string get_path () { @@ -312,17 +257,7 @@ _line = line; } - bool perform () - { - bp_table::intmap intmap; - intmap[0] = _line; - - std::string previous_directory = octave_env::get_current_directory (); - octave_env::chdir (_path); - bp_table::remove_breakpoint (_function_name, intmap); - octave_env::chdir (previous_directory); - return true; // TODO: Check result. - } + bool perform (); std::string get_path () { @@ -357,15 +292,7 @@ _function_name = function_name; } - bool perform () - { - bp_table::intmap intmap; - std::string previous_directory = octave_env::get_current_directory (); - octave_env::chdir (_path); - intmap = bp_table::remove_all_breakpoints_in_file (_function_name, true); - octave_env::chdir (previous_directory); - return intmap.size() > 0; - } + bool perform (); std::string get_path () { @@ -389,14 +316,7 @@ octave_debug_step_into_event (octave_event_observer& o) : octave_event (o) { } - bool perform () - { - octave_value_list args; - args.append (octave_value ("in")); - call_octave_function ("dbstep", args); - finish_readline_event (); - return true; - } + bool perform (); }; class octave_debug_step_over_event : public octave_event @@ -421,14 +341,7 @@ octave_debug_step_out_event (octave_event_observer& o) : octave_event (o) { } - bool perform () - { - octave_value_list args; - args.append (octave_value ("out")); - call_octave_function ("dbstep", args); - finish_readline_event (); - return true; - } + bool perform (); }; class octave_debug_continue_event : public octave_event diff --git a/gui/src/octave-adapter/octave-link.cc b/gui/src/octave-adapter/octave-link.cc --- a/gui/src/octave-adapter/octave-link.cc +++ b/gui/src/octave-adapter/octave-link.cc @@ -15,8 +15,17 @@ * along with this program. If not, see . */ +#ifdef HAVE_CONFIG_H +#include +#endif + +#include "cmd-edit.h" +#include "oct-env.h" +#include "oct-mutex.h" +#include "symtab.h" +#include "toplev.h" + #include "octave-link.h" -#include "load-path.h" int octave_readline_hook () { diff --git a/gui/src/octave-adapter/octave-link.h b/gui/src/octave-adapter/octave-link.h --- a/gui/src/octave-adapter/octave-link.h +++ b/gui/src/octave-adapter/octave-link.h @@ -18,51 +18,10 @@ #ifndef OCTAVELINK_H #define OCTAVELINK_H -// Octave includes -#undef PACKAGE_BUGREPORT -#undef PACKAGE_NAME -#undef PACKAGE_STRING -#undef PACKAGE_TARNAME -#undef PACKAGE_VERSION -#undef PACKAGE_URL -#include "config.h" -#include "cmd-edit.h" -#include "error.h" -#include "file-io.h" -#include "input.h" -#include "lex.h" -#include "load-path.h" -#include "octave.h" -#include "oct-hist.h" -#include "oct-map.h" -#include "oct-obj.h" -#include "ops.h" -#include "ov.h" -#include "ov-usr-fcn.h" -#include "symtab.h" -#include "pt.h" -#include "pt-eval.h" -#include "config.h" -#include "Range.h" -#include "toplev.h" -#include "procstream.h" -#include "sighandlers.h" -#include "debug.h" -#include "sysdep.h" -#include "ov.h" -#include "unwind-prot.h" -#include "utils.h" -#include "variables.h" -#include "oct-mutex.h" -#include "profiler.h" +#include +#include -// Standard includes -#include -#include -#include -#include -#include -#include +class octave_mutex; #include "octave-main-thread.h" #include "octave-event.h" diff --git a/gui/src/octave-adapter/octave-main-thread.cc b/gui/src/octave-adapter/octave-main-thread.cc --- a/gui/src/octave-adapter/octave-main-thread.cc +++ b/gui/src/octave-adapter/octave-main-thread.cc @@ -15,9 +15,16 @@ * along with this program. If not, see . */ +#ifdef HAVE_CONFIG_H +#include +#endif + +#include + +#include "octave.h" + #include "octave-main-thread.h" #include "octave-link.h" -#include octave_main_thread::octave_main_thread () : QThread () { diff --git a/gui/src/octave-gui.cc b/gui/src/octave-gui.cc --- a/gui/src/octave-gui.cc +++ b/gui/src/octave-gui.cc @@ -15,9 +15,18 @@ * along with this program. If not, see . */ +#ifdef HAVE_CONFIG_H +#include +#endif + #include #include #include + +#include + +#include + #include "welcome-wizard.h" #include "resource-manager.h" #include "main-window.h" diff --git a/gui/src/symbol-information.cc b/gui/src/symbol-information.cc new file mode 100644 --- /dev/null +++ b/gui/src/symbol-information.cc @@ -0,0 +1,100 @@ +/* OctaveGUI - A graphical user interface for Octave + * Copyright (C) 2011 Jacob Dawid (jacob.dawid@googlemail.com) + * + * This program 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. + * + * This program 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 this program. If not, see . + */ + +#ifdef HAVE_CONFIG_H +#include +#endif + +#include + +#include "ov.h" +#include "symtab.h" + +#include "symbol-information.h" + +bool +symbol_information::from_symbol_record + (const symbol_table::symbol_record& symbol_record) +{ + if (symbol_record.is_local () && !symbol_record.is_global () && !symbol_record.is_hidden ()) + _scope = local; + else if (symbol_record.is_global ()) + _scope = global; + else if (symbol_record.is_persistent ()) + _scope = persistent; + else if (symbol_record.is_hidden ()) + _scope = hidden; + + _symbol = QString (symbol_record.name ().c_str ()); + _type = QString (symbol_record.varval ().type_name ().c_str ()); + octave_value ov = symbol_record.varval (); + + // In case we have really large matrices or strings, cut them down + // for performance reasons. + QString short_value_string; + bool use_short_value_string = false; + if (ov.is_matrix_type () || ov.is_cell ()) + { + if (ov.rows () * ov.columns () > 10) + { + use_short_value_string = true; + short_value_string + = QString ("%1x%2 items").arg (ov.rows ()).arg (ov.columns ()); + } + } + else if (ov.is_string ()) + { + if (ov.string_value ().length () > 40) + { + use_short_value_string = true; + short_value_string + = QString::fromStdString (ov.string_value ().substr (0, 40)); + } + } + + if (use_short_value_string) + { + _value = short_value_string; + } + else + { + std::stringstream buffer; + ov.print (buffer, true); + _value = QString::fromStdString (buffer.str ()); + } + _value.replace("\n", " "); + + if (ov.is_string ()) + _dimension = QString ("%1").arg (ov.string_value ().length ()); + else if (ov.is_range ()) + _dimension = QString ("%1 : %2 : %3").arg (ov.range_value ().base ()) + .arg (ov.range_value ().inc ()) + .arg (ov.range_value ().limit ()); + else if (ov.is_matrix_type () || ov.is_cell ()) + _dimension = QString ("%1x%2").arg (ov.rows ()) + .arg (ov.columns ()); + else if (ov.is_function_handle ()) + // See code for func2str for a possible solution + _dimension = QString ("func handle"); + else if (ov.is_inline_function ()) + // See code for formula for a possible solution + _dimension = QString ("inline func"); + else + _dimension = "1"; + + return true; +} diff --git a/gui/src/symbol-information.h b/gui/src/symbol-information.h --- a/gui/src/symbol-information.h +++ b/gui/src/symbol-information.h @@ -18,46 +18,18 @@ #ifndef SYMBOLINFORMATION_H #define SYMBOLINFORMATION_H +// FIXME -- we should not be including config.h in header files. + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + #include #include #include -// Octave includes -#undef PACKAGE_BUGREPORT -#undef PACKAGE_NAME -#undef PACKAGE_STRING -#undef PACKAGE_TARNAME -#undef PACKAGE_VERSION -#undef PACKAGE_URL -#include "config.h" -#include "cmd-edit.h" -#include "error.h" -#include "file-io.h" -#include "input.h" -#include "lex.h" -#include "load-path.h" -#include "octave.h" -#include "oct-hist.h" -#include "oct-map.h" -#include "oct-obj.h" -#include "ops.h" -#include "ov.h" -#include "ov-usr-fcn.h" #include "symtab.h" -#include "pt.h" -#include "pt-eval.h" -#include "config.h" -#include "Range.h" -#include "toplev.h" -#include "procstream.h" -#include "sighandlers.h" -#include "debug.h" -#include "sysdep.h" -#include "ov.h" -#include "unwind-prot.h" -#include "utils.h" -#include "variables.h" /** * \struct symbol_information @@ -68,7 +40,7 @@ * about a symbol-table entry that will be used in the model for the * graphical user interface. */ -typedef struct symbol_information +struct symbol_information { enum Scope { @@ -108,76 +80,7 @@ /** Extracts meta information from a given symbol record. */ bool - from_symbol_record (const symbol_table::symbol_record& symbol_record) - { - if (symbol_record.is_local () && !symbol_record.is_global () && !symbol_record.is_hidden ()) - _scope = local; - else if (symbol_record.is_global ()) - _scope = global; - else if (symbol_record.is_persistent ()) - _scope = persistent; - else if (symbol_record.is_hidden ()) - _scope = hidden; - - _symbol = QString (symbol_record.name ().c_str ()); - _type = QString (symbol_record.varval ().type_name ().c_str ()); - octave_value ov = symbol_record.varval (); - - // In case we have really large matrices or strings, cut them down - // for performance reasons. - QString short_value_string; - bool use_short_value_string = false; - if (ov.is_matrix_type () || ov.is_cell ()) - { - if (ov.rows () * ov.columns () > 10) - { - use_short_value_string = true; - short_value_string - = QString ("%1x%2 items").arg (ov.rows ()).arg (ov.columns ()); - } - } - else if (ov.is_string ()) - { - if (ov.string_value ().length () > 40) - { - use_short_value_string = true; - short_value_string - = QString::fromStdString (ov.string_value ().substr (0, 40)); - } - } - - if (use_short_value_string) - { - _value = short_value_string; - } - else - { - std::stringstream buffer; - ov.print (buffer, true); - _value = QString::fromStdString (buffer.str ()); - } - _value.replace("\n", " "); - - if (ov.is_string ()) - _dimension = QString ("%1").arg (ov.string_value ().length ()); - else if (ov.is_range ()) - _dimension = QString ("%1 : %2 : %3").arg (ov.range_value ().base ()) - .arg (ov.range_value ().inc ()) - .arg (ov.range_value ().limit ()); - else if (ov.is_matrix_type () || ov.is_cell ()) - _dimension = QString ("%1x%2").arg (ov.rows ()) - .arg (ov.columns ()); - else if (ov.is_function_handle ()) - // See code for func2str for a possible solution - _dimension = QString ("func handle"); - else if (ov.is_inline_function ()) - // See code for formula for a possible solution - _dimension = QString ("inline func"); - else - _dimension = "1"; - - return true; - } -} symbol_information; + from_symbol_record (const symbol_table::symbol_record& symbol_record); +}; #endif // SYMBOLINFORMATION_H diff --git a/gui/src/workspace-model.cc b/gui/src/workspace-model.cc --- a/gui/src/workspace-model.cc +++ b/gui/src/workspace-model.cc @@ -15,9 +15,18 @@ * along with this program. If not, see . */ -#include "workspace-model.h" +#ifdef HAVE_CONFIG_H +#include +#endif + #include #include + +#include + +#include + +#include "workspace-model.h" #include "octave-link.h" workspace_model::workspace_model(QObject *parent)