Mercurial > hg > octave-lojdl
changeset 13541:b48ac9ad8de0
Highly improved separation of model and view classes.
author | Jacob Dawid <jacob.dawid@googlemail.com> |
---|---|
date | Tue, 26 Jul 2011 23:04:52 +0200 |
parents | 0dbf8681cd08 |
children | 5b168bbd6044 |
files | gui/src/MainWindow.cpp gui/src/MainWindow.h gui/src/OctaveCallbackThread.cpp gui/src/OctaveCallbackThread.h gui/src/OctaveLink.cpp gui/src/OctaveLink.h gui/src/OctaveMainThread.cpp gui/src/OctaveMainThread.h gui/src/VariablesDockWidget.cpp gui/src/VariablesDockWidget.h |
diffstat | 10 files changed, 52 insertions(+), 56 deletions(-) [+] |
line wrap: on
line diff
--- a/gui/src/MainWindow.cpp +++ b/gui/src/MainWindow.cpp @@ -26,16 +26,14 @@ #include "FileEditorMdiSubWindow.h" #include "ImageViewerMdiSubWindow.h" #include "SettingsDialog.h" -#include "OctaveCallbackThread.h" #include "cmd-edit.h" #define VERSION_STRING "Octave GUI (0.6.0)" -MainWindow::MainWindow (QWidget * parent):QMainWindow (parent), -m_isRunning (true) +MainWindow::MainWindow (QWidget * parent):QMainWindow (parent) { construct (); - establishOctaveLink (); + OctaveLink::instance ()->launchOctave(); } MainWindow::~MainWindow () @@ -151,14 +149,10 @@ void MainWindow::closeEvent (QCloseEvent * closeEvent) { - m_isRunning = false; reportStatusMessage (tr ("Saving data and shutting down.")); writeSettings (); - m_octaveCallbackThread->terminate (); - m_octaveCallbackThread->wait (); - - m_octaveMainThread->terminate (); + OctaveLink::instance ()->terminateOctave(); QMainWindow::closeEvent (closeEvent); } @@ -206,6 +200,8 @@ m_documentationWidget = new BrowserWidget (this); m_ircWidget = new IRCWidget (this); + m_octaveTerminal->openTerminal (); + m_documentationWidgetSubWindow = m_centralMdiArea->addSubWindow (m_documentationWidget, Qt::WindowTitleHint | Qt:: @@ -304,15 +300,3 @@ openWebPage ("http://www.gnu.org/software/octave/doc/interpreter/"); } -void -MainWindow::establishOctaveLink () -{ - m_octaveTerminal->openTerminal (); - - m_octaveMainThread = new OctaveMainThread (this); - m_octaveMainThread->start (); - - m_octaveCallbackThread = new OctaveCallbackThread (this, this); - connect (m_octaveMainThread, SIGNAL(ready()), m_octaveCallbackThread, SLOT(start())); - reportStatusMessage (tr ("Established link to Octave.")); -}
--- a/gui/src/MainWindow.h +++ b/gui/src/MainWindow.h @@ -35,9 +35,6 @@ #include "BrowserWidget.h" #include "IRCWidget.h" -class OctaveCallbackThread; -#include "OctaveMainThread.h" - /** * \class MainWindow * @@ -49,10 +46,6 @@ MainWindow (QWidget * parent = 0); ~MainWindow (); - bool isRunning () - { - return m_isRunning; - } OctaveTerminal *octaveTerminal () { return m_octaveTerminal; @@ -113,11 +106,6 @@ // Toolbars. QStatusBar *m_statusBar; - - // Threads for running octave and managing the data interaction. - OctaveMainThread *m_octaveMainThread; - OctaveCallbackThread *m_octaveCallbackThread; - bool m_isRunning; }; #endif // MAINWINDOW_H
--- a/gui/src/OctaveCallbackThread.cpp +++ b/gui/src/OctaveCallbackThread.cpp @@ -1,25 +1,16 @@ #include "OctaveCallbackThread.h" +#include "MainWindow.h" -OctaveCallbackThread::OctaveCallbackThread (QObject * parent, - MainWindow * mainWindow):QThread (parent), - m_mainWindow (mainWindow) +OctaveCallbackThread::OctaveCallbackThread (QObject * parent):QThread (parent) { } void OctaveCallbackThread::run () { - while (m_mainWindow->isRunning ()) + while (1) { OctaveLink::instance ()->fetchSymbolTable (); - - // Get a full variable list. - QList < SymbolRecord > symbolTable = OctaveLink::instance ()->copyCurrentSymbolTable (); - if (symbolTable.size ()) - { - m_mainWindow->variablesDockWidget ()->setVariablesList (symbolTable); - } - OctaveLink::instance ()->updateHistoryModel (); usleep (500000); }
--- a/gui/src/OctaveCallbackThread.h +++ b/gui/src/OctaveCallbackThread.h @@ -2,18 +2,15 @@ #define OCTAVECALLBACKTHREAD_H #include <QThread> -#include "MainWindow.h" class OctaveCallbackThread:public QThread { Q_OBJECT public: - OctaveCallbackThread (QObject * parent, MainWindow * mainWindow); - + OctaveCallbackThread (QObject * parent); protected: void run (); -private: - MainWindow * m_mainWindow; + }; #endif // OCTAVECALLBACKTHREAD_H
--- a/gui/src/OctaveLink.cpp +++ b/gui/src/OctaveLink.cpp @@ -20,10 +20,7 @@ */ -// Born July 13, 2007. - #include "OctaveLink.h" -#include <QDebug> OctaveLink OctaveLink::m_singleton; @@ -97,6 +94,26 @@ } void +OctaveLink::launchOctave () +{ + m_octaveMainThread = new OctaveMainThread (this); + m_octaveMainThread->start (); + + m_octaveCallbackThread = new OctaveCallbackThread (this); + connect (m_octaveMainThread, SIGNAL(ready()), m_octaveCallbackThread, SLOT(start())); +} + +void +OctaveLink::terminateOctave () +{ + m_octaveCallbackThread->terminate (); + m_octaveCallbackThread->wait (); + + m_octaveMainThread->terminate (); + m_octaveMainThread->wait(); +} + +void OctaveLink::fetchSymbolTable () { m_symbolTableSemaphore->acquire ();
--- a/gui/src/OctaveLink.h +++ b/gui/src/OctaveLink.h @@ -81,6 +81,9 @@ #include <QObject> #include <QStringListModel> +#include "OctaveCallbackThread.h" +#include "OctaveMainThread.h" + typedef symbol_table::symbol_record SymbolRecord; typedef octave_value OctaveValue; @@ -88,7 +91,7 @@ * \class OctaveLink * Manages a link to an octave instance. */ -class OctaveLink:QObject +class OctaveLink:public QObject { Q_OBJECT public: @@ -100,6 +103,9 @@ static QString octaveValueAsQString (OctaveValue octaveValue); + void launchOctave (); + void terminateOctave (); + /** * Returns a copy of the current symbol table buffer. * \return Copy of the current symbol table buffer. @@ -134,6 +140,10 @@ /** History related member variables. */ QStringListModel *m_historyModel; + // Threads for running octave and managing the data interaction. + OctaveMainThread *m_octaveMainThread; + OctaveCallbackThread *m_octaveCallbackThread; + static OctaveLink m_singleton; }; #endif // OCTAVELINK_H
--- a/gui/src/OctaveMainThread.cpp +++ b/gui/src/OctaveMainThread.cpp @@ -1,4 +1,5 @@ #include "OctaveMainThread.h" +#include "OctaveLink.h" OctaveMainThread::OctaveMainThread (QObject * parent):QThread (parent) {
--- a/gui/src/OctaveMainThread.h +++ b/gui/src/OctaveMainThread.h @@ -2,8 +2,6 @@ #define OCTAVEMAINTHREAD_H #include <QThread> -#include "OctaveLink.h" - class OctaveMainThread:public QThread { Q_OBJECT
--- a/gui/src/VariablesDockWidget.cpp +++ b/gui/src/VariablesDockWidget.cpp @@ -26,6 +26,8 @@ { setObjectName ("VariablesDockWidget"); construct (); + + connect (OctaveLink::instance(), SIGNAL (symbolTableChanged()), this, SLOT (fetchSymbolTable())); } void @@ -194,3 +196,10 @@ { } + +void +VariablesDockWidget::fetchSymbolTable () +{ + QList < SymbolRecord > symbolTable = OctaveLink::instance ()->copyCurrentSymbolTable (); + setVariablesList (symbolTable); +}