Mercurial > hg > octave-lojdl
changeset 14721:ec76264adca9 gui
Removed last bits of Qt from octave_link.
* main-window: Made subclass from octave_event_observer.
* octave-event-listener: Added new listener method to interface.
* octave-link: Removed last bits of Qt.
* octave-qt-event-listener: Implemented new listener method.
author | Jacob Dawid <jacob.dawid@googlemail.com> |
---|---|
date | Mon, 04 Jun 2012 22:03:18 +0200 |
parents | cecc7da96e2a |
children | 7784625acf66 |
files | gui/src/main-window.cc gui/src/main-window.h gui/src/octave-adapter/octave-event-listener.h gui/src/octave-adapter/octave-link.cc gui/src/octave-adapter/octave-link.h gui/src/octave-qt-event-listener.cc gui/src/octave-qt-event-listener.h |
diffstat | 7 files changed, 51 insertions(+), 29 deletions(-) [+] |
line wrap: on
line diff
--- a/gui/src/main-window.cc +++ b/gui/src/main-window.cc @@ -30,7 +30,8 @@ #include "file-editor.h" #include "settings-dialog.h" -main_window::main_window (QWidget * parent):QMainWindow (parent) +main_window::main_window (QWidget * parent) + : QMainWindow (parent), octave_event_observer () { // We have to set up all our windows, before we finally launch octave. construct (); @@ -50,6 +51,18 @@ } void +main_window::event_accepted (octave_event *e) +{ + delete e; +} + +void +main_window::event_reject (octave_event *e) +{ + delete e; +} + +void main_window::new_file () { _file_editor->request_new_file (); @@ -177,14 +190,17 @@ if (!selectedDirectory.isEmpty ()) { octave_link::instance () - ->request_working_directory_change (selectedDirectory.toStdString ()); + ->post_event (new octave_change_directory_event (*this, + selectedDirectory.toStdString ())); } } void main_window::change_current_working_directory (QString directory) { - octave_link::instance ()->request_working_directory_change (directory.toStdString ()); + octave_link::instance () + ->post_event (new octave_change_directory_event (*this, + directory.toStdString ())); } void @@ -223,7 +239,7 @@ main_window::closeEvent (QCloseEvent * closeEvent) { closeEvent->ignore (); - octave_link::instance ()->request_octave_exit (); + octave_link::instance ()->post_event (new octave_exit_event (*this)); } void
--- a/gui/src/main-window.h +++ b/gui/src/main-window.h @@ -45,18 +45,23 @@ #include "files-dockwidget.h" #include "terminal-dockwidget.h" #include "octave-qt-event-listener.h" +#include "octave-event-observer.h" /** * \class MainWindow * * Represents the main window. */ -class main_window:public QMainWindow +class main_window + : public QMainWindow, public octave_event_observer { Q_OBJECT public: main_window (QWidget * parent = 0); ~main_window (); + void event_accepted (octave_event *e); + void event_reject (octave_event *e); + 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; }
--- a/gui/src/octave-adapter/octave-event-listener.h +++ b/gui/src/octave-adapter/octave-event-listener.h @@ -27,6 +27,7 @@ virtual ~octave_event_listener () { } virtual void current_directory_has_changed (std::string directory) = 0; + virtual void about_to_exit () = 0; }; #endif // OCTAVEEVENTLISTENER_H
--- a/gui/src/octave-adapter/octave-link.cc +++ b/gui/src/octave-adapter/octave-link.cc @@ -17,8 +17,6 @@ #include "octave-link.h" #include "load-path.h" -#include <QDir> -#include <QApplication> int octave_readline_hook () { @@ -29,15 +27,15 @@ void octave_exit_hook (int status) { - Q_UNUSED (status); - qApp->quit (); + (void) status; + octave_link::instance ()->about_to_exit (); } octave_link octave_link::_singleton; octave_link::octave_link () { - _event_queue_semaphore = new QSemaphore (1); + _event_queue_mutex = new octave_mutex (); _last_working_directory = ""; } @@ -77,7 +75,7 @@ void octave_link::process_events () { - _event_queue_semaphore->acquire (); + _event_queue_mutex->lock (); while (_event_queue.size () > 0) { octave_event * e = _event_queue.front (); @@ -87,7 +85,7 @@ else e->reject (); } - _event_queue_semaphore->release (); + _event_queue_mutex->unlock (); } void @@ -95,9 +93,9 @@ { if (e) { - _event_queue_semaphore->acquire (); + _event_queue_mutex->lock (); _event_queue.push (e); - _event_queue_semaphore->release (); + _event_queue_mutex->unlock (); } } @@ -110,9 +108,8 @@ { delete e; } void -octave_link::request_working_directory_change (std::string directory) -{ post_event (new octave_change_directory_event (*this, directory)); } - -void -octave_link::request_octave_exit () -{ post_event (new octave_exit_event (*this)); } +octave_link::about_to_exit () +{ + if (_octave_event_listener) + _octave_event_listener->about_to_exit (); +}
--- a/gui/src/octave-adapter/octave-link.h +++ b/gui/src/octave-adapter/octave-link.h @@ -53,6 +53,7 @@ #include "octave/unwind-prot.h" #include "octave/utils.h" #include "octave/variables.h" +#include "oct-mutex.h" // Standard includes #include <iostream> @@ -61,9 +62,6 @@ #include <readline/readline.h> #include <queue> -// Qt includes -#include <QSemaphore> - #include "workspace-model.h" #include "octave-main-thread.h" #include "octave-event.h" @@ -83,8 +81,7 @@ { public: /** Provides a way to access the unique octave_link object. */ - static octave_link * - instance () { return &_singleton; } + static octave_link * instance () { return &_singleton; } /** Starts octave. */ void launch_octave (); @@ -96,9 +93,7 @@ void event_accepted (octave_event *e); void event_reject (octave_event *e); - void request_working_directory_change (std::string directory); - void request_octave_exit (); - + void about_to_exit (); private: /** Singleton. */ octave_link (); @@ -110,7 +105,7 @@ octave_main_thread *_octave_main_thread; /** Semaphore to lock access to the event queue. */ - QSemaphore *_event_queue_semaphore; + octave_mutex *_event_queue_mutex; /** Buffer for queueing events until they will be processed. */ std::queue <octave_event *> _event_queue;
--- a/gui/src/octave-qt-event-listener.cc +++ b/gui/src/octave-qt-event-listener.cc @@ -16,6 +16,7 @@ */ #include "octave-qt-event-listener.h" +#include <QApplication> octave_qt_event_listener::octave_qt_event_listener (QObject *parent) : QObject (parent), octave_event_listener () @@ -25,3 +26,9 @@ void octave_qt_event_listener::current_directory_has_changed (std::string directory) { emit current_directory_changed (QString::fromStdString (directory)); } + +void +octave_qt_event_listener::about_to_exit () +{ + qApp->quit (); +}