changeset 14668:6a6733a55982 gui

Removed unused classes and added octave loop hook. * OctaveGUI.cpp: Removed header for command line parsing and command line parser. * WorkspaceModel: Optimized updated the model from the symbol table by passing pointers instead of copying. * OctaveLink: Removed polling thread. * src.pro: Removed deleted files. * OctaveCallbackThread: Not used anymore, hence removed. * CommandLineParser: Not used anymore, hence removed. * ReadlineAdapter: Not used anymore, hence removed.
author Jacob Dawid <jacob.dawid@googlemail.com>
date Tue, 22 May 2012 09:13:46 +0200
parents 664f54233c98
children 7605e7136b50
files gui/src/CommandLineParser.cpp gui/src/CommandLineParser.h gui/src/OctaveGUI.cpp gui/src/WorkspaceModel.cpp gui/src/WorkspaceModel.h gui/src/WorkspaceView.cpp gui/src/backend/OctaveCallbackThread.cpp gui/src/backend/OctaveCallbackThread.h gui/src/backend/OctaveLink.cpp gui/src/backend/OctaveLink.h gui/src/backend/ReadlineAdapter.cpp gui/src/backend/ReadlineAdapter.h gui/src/src.pro
diffstat 13 files changed, 38 insertions(+), 293 deletions(-) [+]
line wrap: on
line diff
--- a/gui/src/CommandLineParser.cpp	Sun May 20 22:05:49 2012 +0200
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,47 +0,0 @@
-/* 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 <http://www.gnu.org/licenses/>.
- */
-
-#include "CommandLineParser.h"
-
-CommandLineParser::CommandLineParser ()
-{
-}
-
-void
-CommandLineParser::registerOption (CommandLineOption commandLineOption)
-{
-  if (m_registeredCommandLineOptions.contains(commandLineOption))
-    m_registeredCommandLineOptions.append(commandLineOption);
-}
-
-void
-CommandLineParser::registerOption (QString longOption, QString shortOption, QString description, bool withArgument)
-{
-  CommandLineOption commandLineOption;
-  commandLineOption.longOption = longOption;
-  commandLineOption.shortOption = shortOption;
-  commandLineOption.description = description;
-  commandLineOption.withArgument = withArgument;
-  registerOption (commandLineOption);
-}
-
-void
-CommandLineParser::parse (int argc, char** argv)
-{
-  Q_UNUSED(argc);
-  Q_UNUSED(argv);
-}
--- a/gui/src/CommandLineParser.h	Sun May 20 22:05:49 2012 +0200
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,50 +0,0 @@
-/* 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 <http://www.gnu.org/licenses/>.
- */
-
-#ifndef COMMANDLINEPARSER_H
-#define COMMANDLINEPARSER_H
-
-#include <QList>
-#include <QString>
-
-class CommandLineParser
-{
-public:
-  struct CommandLineOption
-  {
-    QString longOption;
-    QString shortOption;
-    QString description;
-    bool withArgument;
-
-    bool operator== (CommandLineOption other)
-    {
-        return longOption == other.longOption
-            || shortOption == other.shortOption;
-    }
-  };
-
-  CommandLineParser ();
-  void registerOption (CommandLineOption commandLineOption);
-  void registerOption (QString longOption, QString shortOption, QString description, bool withArgument);
-  void parse (int argc, char** argv);
-
-private:
-  QList<CommandLineOption> m_registeredCommandLineOptions;
-};
-
-#endif // COMMANDLINEPARSER_H
--- a/gui/src/OctaveGUI.cpp	Sun May 20 22:05:49 2012 +0200
+++ b/gui/src/OctaveGUI.cpp	Tue May 22 09:13:46 2012 +0200
@@ -18,7 +18,6 @@
 #include <QtGui/QApplication>
 #include <QTranslator>
 #include <QSettings>
-#include "CommandLineParser.h"
 #include "WelcomeWizard.h"
 #include "ResourceManager.h"
 #include "MainWindow.h"
@@ -71,10 +70,6 @@
         }
       else
         {
-          CommandLineParser commandLineParser;
-          commandLineParser.registerOption ("--config", "-c", "Tells OctaveGUI to use that configuration file.", true);
-          commandLineParser.parse (argc, argv);
-
           QSettings *settings = ResourceManager::instance ()->settings ();
           QString language = settings->value ("language").toString ();
 
--- a/gui/src/WorkspaceModel.cpp	Sun May 20 22:05:49 2012 +0200
+++ b/gui/src/WorkspaceModel.cpp	Tue May 22 09:13:46 2012 +0200
@@ -135,12 +135,11 @@
 }
 
 void
-WorkspaceModel::updateTreeEntry (TreeItem * treeItem, symbol_table::symbol_record symbolRecord)
+WorkspaceModel::updateTreeEntry (TreeItem * treeItem, symbol_table::symbol_record *symbolRecord)
 {
-  treeItem->setData (0, QString (symbolRecord.name ().c_str ()));
-  treeItem->setData (1, QString (symbolRecord.varval ().type_name ().c_str ()));
-  treeItem->setData (2, octaveValueAsQString (symbolRecord.varval ()));
-  emit dataChanged(index(treeItem->row(), 0), index(treeItem->row(), 2));
+  treeItem->setData (0, QString (symbolRecord->name ().c_str ()));
+  treeItem->setData (1, QString (symbolRecord->varval ().type_name ().c_str ()));
+  treeItem->setData (2, octaveValueAsQString (symbolRecord->varval ()));
 }
 
 void
@@ -149,10 +148,10 @@
   std::list < symbol_table::symbol_record > allVariables = symbol_table::all_variables ();
 
   // Split the symbol table into its different categories.
-  QList < symbol_table::symbol_record > localSymbolTable;
-  QList < symbol_table::symbol_record > globalSymbolTable;
-  QList < symbol_table::symbol_record > persistentSymbolTable;
-  QList < symbol_table::symbol_record > hiddenSymbolTable;
+  QList < symbol_table::symbol_record* > localSymbolTable;
+  QList < symbol_table::symbol_record* > globalSymbolTable;
+  QList < symbol_table::symbol_record* > persistentSymbolTable;
+  QList < symbol_table::symbol_record* > hiddenSymbolTable;
 
   for (std::list < symbol_table::symbol_record > ::iterator iterator = allVariables.begin ();
        iterator != allVariables.end (); iterator++)
@@ -161,22 +160,22 @@
       // but we want to distinguish that here.
       if (iterator->is_local () && !iterator->is_global () && !iterator->is_hidden ())
         {
-          localSymbolTable.append (iterator->dup (symbol_table::global_scope ()));
+          localSymbolTable.append (&(*iterator));
         }
 
       if (iterator->is_global ())
         {
-          globalSymbolTable.append (iterator->dup (symbol_table::global_scope ()));
+          globalSymbolTable.append (&(*iterator));
         }
 
       if (iterator->is_persistent ())
         {
-          persistentSymbolTable.append (iterator->dup (symbol_table::global_scope ()));
+          persistentSymbolTable.append (&(*iterator));
         }
 
       if (iterator->is_hidden ())
         {
-          hiddenSymbolTable.append (iterator->dup (symbol_table::global_scope ()));
+          hiddenSymbolTable.append (&(*iterator));
         }
     }
 
@@ -184,10 +183,12 @@
   updateCategory (1, globalSymbolTable);
   updateCategory (2, persistentSymbolTable);
   updateCategory (3, hiddenSymbolTable);
+  reset();
+  emit expandRequest();
 }
 
 void
-WorkspaceModel::updateCategory (int topLevelItemIndex, QList < symbol_table::symbol_record > symbolTable)
+WorkspaceModel::updateCategory (int topLevelItemIndex, QList < symbol_table::symbol_record* > symbolTable)
 {
   // This method may be a little bit confusing; variablesList is a complete list of all
   // variables that are in the workspace currently.
@@ -195,7 +196,7 @@
 
   // First we check, if any variables that exist in the model tree have to be updated
   // or created. So we walk the variablesList check against the tree.
-  foreach (symbol_table::symbol_record symbolRecord, symbolTable)
+  foreach (symbol_table::symbol_record *symbolRecord, symbolTable)
     {
       int childCount = treeItem->childCount ();
       bool alreadyExists = false;
@@ -207,7 +208,7 @@
         {
           child = treeItem->child (i);
           if (child->data (0).toString () ==
-              QString (symbolRecord.name ().c_str ()))
+              QString (symbolRecord->name ().c_str ()))
             {
               alreadyExists = true;
               break;
@@ -233,9 +234,9 @@
     {
       bool existsInVariableList = false;
       TreeItem *child = treeItem->child (i);
-      foreach (symbol_table::symbol_record symbolRecord, symbolTable)
+      foreach (symbol_table::symbol_record *symbolRecord, symbolTable)
         {
-          if (QString (symbolRecord.name ().c_str ()) ==
+          if (QString (symbolRecord->name ().c_str ()) ==
               child->data (0).toString ())
             {
               existsInVariableList = true;
@@ -252,7 +253,7 @@
 }
 
 QString
-WorkspaceModel::octaveValueAsQString (octave_value octaveValue)
+WorkspaceModel::octaveValueAsQString (const octave_value& octaveValue)
 {
   // Convert single qouted string.
   if (octaveValue.is_sq_string ())
--- a/gui/src/WorkspaceModel.h	Sun May 20 22:05:49 2012 +0200
+++ b/gui/src/WorkspaceModel.h	Tue May 22 09:13:46 2012 +0200
@@ -92,7 +92,7 @@
 
   QVariant data(int column) const
   {
-    return _itemData.value(column);
+    return _itemData[column];
   }
 
   void setData(int column, QVariant data)
@@ -101,7 +101,7 @@
   }
 
   TreeItem *child(int row) {
-    return _childItems.value(row);
+    return _childItems[row];
   }
 
   int childCount() const {
@@ -153,9 +153,12 @@
   TreeItem *topLevelItem (int at);
 
   void updateFromSymbolTable ();
-  void updateTreeEntry (TreeItem * treeItem, symbol_table::symbol_record symbolRecord);
-  void updateCategory (int topLevelItemIndex, QList < symbol_table::symbol_record > symbolTable);
-  QString octaveValueAsQString (octave_value octaveValue);
+  void updateTreeEntry (TreeItem * treeItem, symbol_table::symbol_record *symbolRecord);
+  void updateCategory (int topLevelItemIndex, QList < symbol_table::symbol_record *> symbolTable);
+  QString octaveValueAsQString (const octave_value &octaveValue);
+
+signals:
+  void expandRequest();
 
 private:
   TreeItem *_rootItem;
--- a/gui/src/WorkspaceView.cpp	Sun May 20 22:05:49 2012 +0200
+++ b/gui/src/WorkspaceView.cpp	Tue May 22 09:13:46 2012 +0200
@@ -41,7 +41,7 @@
   connect (this, SIGNAL (visibilityChanged (bool)),
            this, SLOT(handleVisibilityChanged (bool)));
 
-  connect (OctaveLink::instance()->workspaceModel(), SIGNAL(dataChanged(QModelIndex,QModelIndex)),
+  connect (OctaveLink::instance()->workspaceModel(), SIGNAL(expandRequest()),
            m_workspaceTreeView, SLOT(expandAll()));
 }
 
--- a/gui/src/backend/OctaveCallbackThread.cpp	Sun May 20 22:05:49 2012 +0200
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,50 +0,0 @@
-/* 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 <http://www.gnu.org/licenses/>.
- */
-
-#include "OctaveCallbackThread.h"
-#include "MainWindow.h"
-
-OctaveCallbackThread::OctaveCallbackThread (QObject * parent)
-  : QThread (parent)
-{
-  m_runningSemaphore = new QSemaphore(1);
-  m_running = true;
-}
-
-void
-OctaveCallbackThread::halt ()
-{
-  m_runningSemaphore->acquire ();
-  m_running = false;
-  m_runningSemaphore->release ();
-}
-
-void
-OctaveCallbackThread::run ()
-{
-  bool running = true;
-  while (running)
-    {
-      OctaveLink::instance ()->triggerUpdateSymbolTable ();
-      OctaveLink::instance ()->triggerUpdateHistoryModel ();
-      usleep (1000000);
-
-      m_runningSemaphore->acquire ();
-      running = m_running;
-      m_runningSemaphore->release ();
-    }
-}
--- a/gui/src/backend/OctaveCallbackThread.h	Sun May 20 22:05:49 2012 +0200
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,37 +0,0 @@
-/* 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 <http://www.gnu.org/licenses/>.
- */
-
-#ifndef OCTAVECALLBACKTHREAD_H
-#define OCTAVECALLBACKTHREAD_H
-
-#include <QThread>
-#include <QSemaphore>
-
-class OctaveCallbackThread:public QThread
-{
-  Q_OBJECT
-public:
-  void halt();
-  OctaveCallbackThread (QObject * parent);
-protected:
-  void run ();
-private:
-  QSemaphore *m_runningSemaphore;
-  bool m_running;
-};
-
-#endif // OCTAVECALLBACKTHREAD_H
--- a/gui/src/backend/OctaveLink.cpp	Sun May 20 22:05:49 2012 +0200
+++ b/gui/src/backend/OctaveLink.cpp	Tue May 22 09:13:46 2012 +0200
@@ -17,6 +17,13 @@
 
 #include "OctaveLink.h"
 
+void octave_loop_hook_impl()
+{
+  OctaveLink::instance()->triggerUpdateHistoryModel();
+  OctaveLink::instance()->triggerUpdateSymbolTable();
+}
+
+
 OctaveLink OctaveLink::m_singleton;
 
 OctaveLink::OctaveLink ():QObject ()
@@ -39,10 +46,7 @@
 {
   // Create both threads.
   m_octaveMainThread = new OctaveMainThread (this);
-  m_octaveCallbackThread = new OctaveCallbackThread (this);
-
-  // Launch the second as soon as the first ist ready.
-  connect (m_octaveMainThread, SIGNAL (ready ()), m_octaveCallbackThread, SLOT (start ()));
+  octave_loop_hook = octave_loop_hook_impl;
 
   // Start the first one.
   m_octaveMainThread->start ();
@@ -51,11 +55,8 @@
 void
 OctaveLink::terminateOctave ()
 {
-  m_octaveCallbackThread->halt ();
-  m_octaveCallbackThread->wait ();
-
   m_octaveMainThread->terminate ();
-  //m_octaveMainThread->wait();
+  m_octaveMainThread->wait();
 }
 
 void
--- a/gui/src/backend/OctaveLink.h	Sun May 20 22:05:49 2012 +0200
+++ b/gui/src/backend/OctaveLink.h	Tue May 22 09:13:46 2012 +0200
@@ -73,7 +73,6 @@
 #include <QStringListModel>
 
 #include "WorkspaceModel.h"
-#include "OctaveCallbackThread.h"
 #include "OctaveMainThread.h"
 
 /**
@@ -102,15 +101,11 @@
   OctaveLink ();
   ~OctaveLink ();
 
-  //QSemaphore * m_symbolTableSemaphore;
-  //QList < symbol_table::symbol_record > m_symbolTableBuffer;
-
   QStringListModel *m_historyModel;
   WorkspaceModel *m_workspaceModel;
 
   // Threads for running octave and managing the data interaction.
   OctaveMainThread *m_octaveMainThread;
-  OctaveCallbackThread *m_octaveCallbackThread;
 
   static OctaveLink m_singleton;
 };
--- a/gui/src/backend/ReadlineAdapter.cpp	Sun May 20 22:05:49 2012 +0200
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,23 +0,0 @@
-/* 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 <http://www.gnu.org/licenses/>.
- */
-
-#include "ReadlineAdapter.h"
-
-ReadlineAdapter::ReadlineAdapter (QObject *parent) :
-  QObject (parent), command_editor ()
-{
-}
--- a/gui/src/backend/ReadlineAdapter.h	Sun May 20 22:05:49 2012 +0200
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,37 +0,0 @@
-/* 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 <http://www.gnu.org/licenses/>.
- */
-
-#ifndef READLINEADAPTER_H
-#define READLINEADAPTER_H
-
-#include "octave/config.h"
-#include "octave/cmd-edit.h"
-#include <QObject>
-
-class ReadlineAdapter : public QObject, public command_editor
-{
-  Q_OBJECT
-public:
-  explicit ReadlineAdapter (QObject *parent = 0);
-
-signals:
-
-public slots:
-
-};
-
-#endif // READLINEADAPTER_H
--- a/gui/src/src.pro	Sun May 20 22:05:49 2012 +0200
+++ b/gui/src/src.pro	Tue May 22 09:13:46 2012 +0200
@@ -82,11 +82,8 @@
     SettingsDialog.cpp \
     OctaveGUI.cpp \
     ResourceManager.cpp \
-    CommandLineParser.cpp \
-    backend/OctaveCallbackThread.cpp \
     backend/OctaveLink.cpp \
     backend/OctaveMainThread.cpp \
-    backend/ReadlineAdapter.cpp \
     WelcomeWizard.cpp \
     FileEditor.cpp \
     WorkspaceModel.cpp
@@ -99,11 +96,8 @@
     FilesDockWidget.h \
     SettingsDialog.h \
     ResourceManager.h \
-    CommandLineParser.h \
-    backend/OctaveCallbackThread.h \
     backend/OctaveLink.h \
     backend/OctaveMainThread.h \
-    backend/ReadlineAdapter.h \
     WelcomeWizard.h \
     FileEditor.h \
     WorkspaceModel.h