Mercurial > hg > octave-lyh
changeset 14664:664f54233c98 gui
Extracted model code from the WorkspaceView and rearranged it in a new model class.
* WorkspaceModel.cpp/.h (new class): Model class for the workspace.
* WorkspaceView.cpp/.h: Replaced QTreeWidget with QTreeView and removed model code.
* OctaveLink.cpp/.h: Removed symbol table semaphore and methods to access the copy of the symbol table, removed copying the symbol table.
* src.pro: Added new files to Qt project.
author | Jacob Dawid <jacob.dawid@googlemail.com> |
---|---|
date | Sun, 20 May 2012 22:05:49 +0200 |
parents | 6573ba8f094f |
children | 6a6733a55982 |
files | gui/src/WorkspaceModel.cpp gui/src/WorkspaceModel.h gui/src/WorkspaceView.cpp gui/src/WorkspaceView.h gui/src/backend/OctaveLink.cpp gui/src/backend/OctaveLink.h gui/src/src.pro |
diffstat | 7 files changed, 518 insertions(+), 273 deletions(-) [+] |
line wrap: on
line diff
new file mode 100644 --- /dev/null +++ b/gui/src/WorkspaceModel.cpp @@ -0,0 +1,313 @@ +/* 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 "WorkspaceModel.h" +#include <QTreeWidget> + +WorkspaceModel::WorkspaceModel(QObject *parent) + : QAbstractItemModel(parent) +{ + QList<QVariant> rootData; + rootData << tr ("Name") << tr ("Type") << tr ("Value"); + _rootItem = new TreeItem(rootData); +} + +WorkspaceModel::~WorkspaceModel() +{ + delete _rootItem; +} + +QModelIndex +WorkspaceModel::index(int row, int column, const QModelIndex &parent) const +{ + if (!hasIndex(row, column, parent)) + return QModelIndex(); + + TreeItem *parentItem; + + if (!parent.isValid()) + parentItem = _rootItem; + else + parentItem = static_cast<TreeItem*>(parent.internalPointer()); + + TreeItem *childItem = parentItem->child(row); + if (childItem) + return createIndex(row, column, childItem); + else + return QModelIndex(); +} + +QModelIndex +WorkspaceModel::parent(const QModelIndex &index) const +{ + if (!index.isValid()) + return QModelIndex(); + + TreeItem *childItem = static_cast<TreeItem*>(index.internalPointer()); + TreeItem *parentItem = childItem->parent(); + + if (parentItem == _rootItem) + return QModelIndex(); + + return createIndex(parentItem->row(), 0, parentItem); +} + +int +WorkspaceModel::rowCount(const QModelIndex &parent) const +{ + TreeItem *parentItem; + if (parent.column() > 0) + return 0; + + if (!parent.isValid()) + parentItem = _rootItem; + else + parentItem = static_cast<TreeItem*>(parent.internalPointer()); + + return parentItem->childCount(); +} + +int +WorkspaceModel::columnCount(const QModelIndex &parent) const +{ + if (parent.isValid()) + return static_cast<TreeItem*>(parent.internalPointer())->columnCount(); + else + return _rootItem->columnCount(); +} + +void +WorkspaceModel::insertTopLevelItem(int at, TreeItem *treeItem) +{ + _rootItem->insertChildItem(at, treeItem); +} + +TreeItem * +WorkspaceModel::topLevelItem (int at) +{ + return _rootItem->child(at); +} + +Qt::ItemFlags +WorkspaceModel::flags(const QModelIndex &index) const +{ + if (!index.isValid()) + return 0; + + return Qt::ItemIsEnabled | Qt::ItemIsSelectable; +} + +QVariant +WorkspaceModel::headerData(int section, Qt::Orientation orientation, int role) const +{ + if (orientation == Qt::Horizontal && role == Qt::DisplayRole) + return _rootItem->data(section); + + return QVariant(); +} + +QVariant +WorkspaceModel::data(const QModelIndex &index, int role) const +{ + if (!index.isValid()) + return QVariant(); + + if (role != Qt::DisplayRole) + return QVariant(); + + TreeItem *item = static_cast<TreeItem*>(index.internalPointer()); + + return item->data(index.column()); +} + +void +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)); +} + +void +WorkspaceModel::updateFromSymbolTable () +{ + 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; + + for (std::list < symbol_table::symbol_record > ::iterator iterator = allVariables.begin (); + iterator != allVariables.end (); iterator++) + { + // It's true that being global or hidden includes it's can mean it's also locally visible, + // 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 ())); + } + + if (iterator->is_global ()) + { + globalSymbolTable.append (iterator->dup (symbol_table::global_scope ())); + } + + if (iterator->is_persistent ()) + { + persistentSymbolTable.append (iterator->dup (symbol_table::global_scope ())); + } + + if (iterator->is_hidden ()) + { + hiddenSymbolTable.append (iterator->dup (symbol_table::global_scope ())); + } + } + + updateCategory (0, localSymbolTable); + updateCategory (1, globalSymbolTable); + updateCategory (2, persistentSymbolTable); + updateCategory (3, hiddenSymbolTable); +} + +void +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. + TreeItem *treeItem = topLevelItem (topLevelItemIndex); + + // 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) + { + int childCount = treeItem->childCount (); + bool alreadyExists = false; + TreeItem *child; + + // Search for the corresponding item in the tree. If it has been found, child + // will contain the appropriate QTreeWidgetItem* pointing at it. + for (int i = 0; i < childCount; i++) + { + child = treeItem->child (i); + if (child->data (0).toString () == + QString (symbolRecord.name ().c_str ())) + { + alreadyExists = true; + break; + } + } + + // If it already exists, just update it. + if (alreadyExists) + { + updateTreeEntry (child, symbolRecord); + } + else + { + // It does not exist, so create a new one and set the right values. + child = new TreeItem (); + updateTreeEntry (child, symbolRecord); + treeItem->addChild (child); + } + } + + // Check the tree against the list for deleted variables. + for (int i = 0; i < treeItem->childCount (); i++) + { + bool existsInVariableList = false; + TreeItem *child = treeItem->child (i); + foreach (symbol_table::symbol_record symbolRecord, symbolTable) + { + if (QString (symbolRecord.name ().c_str ()) == + child->data (0).toString ()) + { + existsInVariableList = true; + } + } + + if (!existsInVariableList) + { + treeItem->removeChild (child); + delete child; + i--; + } + } +} + +QString +WorkspaceModel::octaveValueAsQString (octave_value octaveValue) +{ + // Convert single qouted string. + if (octaveValue.is_sq_string ()) + { + return QString ("\'%1\'").arg (octaveValue.string_value ().c_str ()); + + // Convert double qouted string. + } + else if (octaveValue.is_dq_string ()) + { + return QString ("\"%1\"").arg (octaveValue.string_value ().c_str ()); + + // Convert real scalar. + } + else if (octaveValue.is_real_scalar ()) + { + return QString ("%1").arg (octaveValue.scalar_value ()); + + // Convert complex scalar. + } + else if (octaveValue.is_complex_scalar ()) + { + return QString ("%1 + %2i").arg (octaveValue.scalar_value ()). + arg (octaveValue.complex_value ().imag ()); + + // Convert range. + } + else if (octaveValue.is_range ()) + { + return QString ("%1 : %2 : %3").arg (octaveValue.range_value (). + base ()).arg (octaveValue. + range_value (). + inc ()). + arg (octaveValue.range_value ().limit ()); + + // Convert real matrix. + } + else if (octaveValue.is_real_matrix ()) + { + return QString ("%1x%2 matrix") + .arg (octaveValue.matrix_value ().rows ()) + .arg (octaveValue.matrix_value ().cols ()); + + // Convert complex matrix. + } + else if (octaveValue.is_complex_matrix ()) + { + return QString ("%1x%2 complex matrix") + .arg (octaveValue.matrix_value ().rows ()) + .arg (octaveValue.matrix_value ().cols ()); + + // If everything else does not fit, we could not recognize the type. + } + else + { + return QString ("<Type not recognized>"); + } +}
new file mode 100644 --- /dev/null +++ b/gui/src/WorkspaceModel.h @@ -0,0 +1,164 @@ +/* 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 WORKSPACEMODEL_H +#define WORKSPACEMODEL_H + +// Octave includes +#undef PACKAGE_BUGREPORT +#undef PACKAGE_NAME +#undef PACKAGE_STRING +#undef PACKAGE_TARNAME +#undef PACKAGE_VERSION +#undef PACKAGE_URL +#include "octave/config.h" +#include "octave/cmd-edit.h" +#include "octave/error.h" +#include "octave/file-io.h" +#include "octave/input.h" +#include "octave/lex.h" +#include "octave/load-path.h" +#include "octave/octave.h" +#include "octave/oct-hist.h" +#include "octave/oct-map.h" +#include "octave/oct-obj.h" +#include "octave/ops.h" +#include "octave/ov.h" +#include "octave/ov-usr-fcn.h" +#include "octave/symtab.h" +#include "octave/pt.h" +#include "octave/pt-eval.h" +#include "octave/config.h" +#include "octave/Range.h" +#include "octave/toplev.h" +#include "octave/procstream.h" +#include "octave/sighandlers.h" +#include "octave/debug.h" +#include "octave/sysdep.h" +#include "octave/ov.h" +#include "octave/unwind-prot.h" +#include "octave/utils.h" +#include "octave/variables.h" + +// Qt includes +#include <QAbstractItemModel> + +class TreeItem +{ +public: + TreeItem(const QList<QVariant> &data, TreeItem *parent = 0) { + _parentItem = parent; + _itemData = data; + } + + TreeItem(QVariant data = QVariant(), TreeItem *parent = 0) { + QList<QVariant> variantList; + variantList << data << QVariant() << QVariant(); + _parentItem = parent; + _itemData = variantList; + } + + ~TreeItem() { + qDeleteAll(_childItems); + } + + void insertChildItem(int at, TreeItem *item) { + item->_parentItem = this; + _childItems.insert(at, item); + } + + void addChild(TreeItem *item) { + item->_parentItem = this; + _childItems.append(item); + } + + void removeChild(TreeItem *item) { + _childItems.removeAll(item); + } + + QVariant data(int column) const + { + return _itemData.value(column); + } + + void setData(int column, QVariant data) + { + _itemData[column] = data; + } + + TreeItem *child(int row) { + return _childItems.value(row); + } + + int childCount() const { + return _childItems.count(); + } + + int columnCount() const + { + return _itemData.count(); + } + + int row() const { + if (_parentItem) + return _parentItem->_childItems.indexOf(const_cast<TreeItem*>(this)); + + return 0; + } + + TreeItem *parent() + { + return _parentItem; + } + +private: + QList<TreeItem*> _childItems; + QList<QVariant> _itemData; + TreeItem *_parentItem; +}; + +class WorkspaceModel : public QAbstractItemModel +{ + Q_OBJECT + +public: + WorkspaceModel(QObject *parent = 0); + ~WorkspaceModel(); + + QVariant data(const QModelIndex &index, int role) const; + Qt::ItemFlags flags(const QModelIndex &index) const; + QVariant headerData(int section, Qt::Orientation orientation, + int role = Qt::DisplayRole) const; + QModelIndex index(int row, int column, + const QModelIndex &parent = QModelIndex()) const; + QModelIndex parent(const QModelIndex &index) const; + int rowCount(const QModelIndex &parent = QModelIndex()) const; + int columnCount(const QModelIndex &parent = QModelIndex()) const; + + void insertTopLevelItem (int at, TreeItem *treeItem); + 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); + +private: + TreeItem *_rootItem; +}; + +#endif // WORKSPACEMODEL_H
--- a/gui/src/WorkspaceView.cpp +++ b/gui/src/WorkspaceView.cpp @@ -26,172 +26,23 @@ setObjectName ("WorkspaceView"); setWindowTitle (tr ("Workspace")); - m_updateSemaphore = new QSemaphore (1); - QStringList headerLabels; - headerLabels << tr ("Name") << tr ("Type") << tr ("Value"); - m_variablesTreeWidget = new QTreeWidget (this); - m_variablesTreeWidget->setHeaderHidden (false); - m_variablesTreeWidget->setHeaderLabels (headerLabels); + m_workspaceTreeView = new QTreeView (this); + m_workspaceTreeView->setHeaderHidden (false); + m_workspaceTreeView->setAlternatingRowColors (true); + m_workspaceTreeView->setAnimated (true); + m_workspaceTreeView->setModel(OctaveLink::instance()->workspaceModel()); setWidget (new QWidget (this)); QVBoxLayout *layout = new QVBoxLayout (); - layout->addWidget (m_variablesTreeWidget); + layout->addWidget (m_workspaceTreeView); layout->setMargin (2); widget ()->setLayout (layout); - QTreeWidgetItem *treeWidgetItem = new QTreeWidgetItem (); - treeWidgetItem->setData (0, 0, QString (tr ("Local"))); - m_variablesTreeWidget->insertTopLevelItem (0, treeWidgetItem); - - treeWidgetItem = new QTreeWidgetItem (); - treeWidgetItem->setData (0, 0, QString (tr ("Global"))); - m_variablesTreeWidget->insertTopLevelItem (1, treeWidgetItem); - - treeWidgetItem = new QTreeWidgetItem (); - treeWidgetItem->setData (0, 0, QString (tr ("Persistent"))); - m_variablesTreeWidget->insertTopLevelItem (2, treeWidgetItem); - - treeWidgetItem = new QTreeWidgetItem (); - treeWidgetItem->setData (0, 0, QString (tr ("Hidden"))); - m_variablesTreeWidget->insertTopLevelItem (3, treeWidgetItem); - - m_variablesTreeWidget->expandAll (); - m_variablesTreeWidget->setAlternatingRowColors (true); - m_variablesTreeWidget->setAnimated (true); - connect (this, SIGNAL (visibilityChanged (bool)), this, SLOT(handleVisibilityChanged (bool))); - connect (OctaveLink::instance(), SIGNAL (updateSymbolTable ()), - this, SLOT (fetchSymbolTable ())); -} -void -WorkspaceView::updateTreeEntry (QTreeWidgetItem * treeItem, SymbolRecord symbolRecord) -{ - treeItem->setData (0, 0, QString (symbolRecord.name ().c_str ())); - treeItem->setData (1, 0, - QString (symbolRecord.varval ().type_name ().c_str ())); - treeItem->setData (2, 0, - OctaveLink::octaveValueAsQString (symbolRecord. - varval ())); -} - -void -WorkspaceView::updateFromSymbolTable (QList < SymbolRecord > symbolTable) -{ - m_updateSemaphore->acquire (); - // Split the symbol table into its different scopes. - QList < SymbolRecord > localSymbolTable; - QList < SymbolRecord > globalSymbolTable; - QList < SymbolRecord > persistentSymbolTable; - QList < SymbolRecord > hiddenSymbolTable; - - foreach (SymbolRecord symbolRecord, symbolTable) - { - // It's true that being global or hidden includes it's can mean it's also locally visible, - // but we want to distinguish that here. - if (symbolRecord.is_local () && !symbolRecord.is_global () - && !symbolRecord.is_hidden ()) - { - localSymbolTable.append (symbolRecord); - } - - if (symbolRecord.is_global ()) - { - globalSymbolTable.append (symbolRecord); - } - - if (symbolRecord.is_persistent ()) - { - persistentSymbolTable.append (symbolRecord); - } - - if (symbolRecord.is_hidden ()) - { - hiddenSymbolTable.append (symbolRecord); - } - } - - updateScope (0, localSymbolTable); - updateScope (1, globalSymbolTable); - updateScope (2, persistentSymbolTable); - updateScope (3, hiddenSymbolTable); - m_updateSemaphore->release (); -} - -void -WorkspaceView::updateScope (int topLevelItemIndex, QList < SymbolRecord > symbolTable) -{ - // This method may be a little bit confusing; variablesList is a complete list of all - // variables that are in the workspace currently. - QTreeWidgetItem *topLevelItem = - m_variablesTreeWidget->topLevelItem (topLevelItemIndex); - - // 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 (SymbolRecord symbolRecord, symbolTable) - { - int childCount = topLevelItem->childCount (); - bool alreadyExists = false; - QTreeWidgetItem *child; - - // Search for the corresponding item in the tree. If it has been found, child - // will contain the appropriate QTreeWidgetItem* pointing at it. - for (int i = 0; i < childCount; i++) - { - child = topLevelItem->child (i); - if (child->data (0, 0).toString () == - QString (symbolRecord.name ().c_str ())) - { - alreadyExists = true; - break; - } - } - - // If it already exists, just update it. - if (alreadyExists) - { - updateTreeEntry (child, symbolRecord); - } - else - { - // It does not exist, so create a new one and set the right values. - child = new QTreeWidgetItem (); - updateTreeEntry (child, symbolRecord); - topLevelItem->addChild (child); - } - } - - // Check the tree against the list for deleted variables. - for (int i = 0; i < topLevelItem->childCount (); i++) - { - bool existsInVariableList = false; - QTreeWidgetItem *child = topLevelItem->child (i); - foreach (SymbolRecord symbolRecord, symbolTable) - { - if (QString (symbolRecord.name ().c_str ()) == - child->data (0, 0).toString ()) - { - existsInVariableList = true; - } - } - - if (!existsInVariableList) - { - topLevelItem->removeChild (child); - delete child; - i--; - } - } -} - -void -WorkspaceView::fetchSymbolTable () -{ - OctaveLink::instance ()->acquireSymbolTable(); - QList < SymbolRecord > symbolTable = OctaveLink::instance ()->symbolTable(); - updateFromSymbolTable (symbolTable); - OctaveLink::instance ()->releaseSymbolTable(); + connect (OctaveLink::instance()->workspaceModel(), SIGNAL(dataChanged(QModelIndex,QModelIndex)), + m_workspaceTreeView, SLOT(expandAll())); } void
--- a/gui/src/WorkspaceView.h +++ b/gui/src/WorkspaceView.h @@ -19,7 +19,7 @@ #define WORKSPACEVIEW_H #include <QDockWidget> -#include <QTreeWidget> +#include <QTreeView> #include <QSemaphore> #include "OctaveLink.h" @@ -30,7 +30,6 @@ WorkspaceView (QWidget * parent = 0); public slots: - void fetchSymbolTable (); void handleVisibilityChanged (bool visible); signals: @@ -41,12 +40,7 @@ void closeEvent (QCloseEvent *event); private: - void updateFromSymbolTable (QList < SymbolRecord > symbolTable); - void updateTreeEntry (QTreeWidgetItem * treeItem, SymbolRecord symbolRecord); - void updateScope (int topLevelItemIndex, QList < SymbolRecord > symbolTable); - - QTreeWidget *m_variablesTreeWidget; - QSemaphore *m_updateSemaphore; + QTreeView *m_workspaceTreeView; }; #endif // WORKSPACEVIEW_H
--- a/gui/src/backend/OctaveLink.cpp +++ b/gui/src/backend/OctaveLink.cpp @@ -21,75 +21,19 @@ OctaveLink::OctaveLink ():QObject () { - m_symbolTableSemaphore = new QSemaphore (1); m_historyModel = new QStringListModel (this); + m_workspaceModel = new WorkspaceModel (this); + + m_workspaceModel->insertTopLevelItem(0, new TreeItem ("Local")); + m_workspaceModel->insertTopLevelItem(1, new TreeItem ("Global")); + m_workspaceModel->insertTopLevelItem(2, new TreeItem ("Persistent")); + m_workspaceModel->insertTopLevelItem(3, new TreeItem ("Hidden")); } OctaveLink::~OctaveLink () { } -QString -OctaveLink::octaveValueAsQString (OctaveValue octaveValue) -{ - // Convert single qouted string. - if (octaveValue.is_sq_string ()) - { - return QString ("\'%1\'").arg (octaveValue.string_value ().c_str ()); - - // Convert double qouted string. - } - else if (octaveValue.is_dq_string ()) - { - return QString ("\"%1\"").arg (octaveValue.string_value ().c_str ()); - - // Convert real scalar. - } - else if (octaveValue.is_real_scalar ()) - { - return QString ("%1").arg (octaveValue.scalar_value ()); - - // Convert complex scalar. - } - else if (octaveValue.is_complex_scalar ()) - { - return QString ("%1 + %2i").arg (octaveValue.scalar_value ()). - arg (octaveValue.complex_value ().imag ()); - - // Convert range. - } - else if (octaveValue.is_range ()) - { - return QString ("%1 : %2 : %3").arg (octaveValue.range_value (). - base ()).arg (octaveValue. - range_value (). - inc ()). - arg (octaveValue.range_value ().limit ()); - - // Convert real matrix. - } - else if (octaveValue.is_real_matrix ()) - { - return QString ("%1x%2 matrix") - .arg (octaveValue.matrix_value ().rows ()) - .arg (octaveValue.matrix_value ().cols ()); - - // Convert complex matrix. - } - else if (octaveValue.is_complex_matrix ()) - { - return QString ("%1x%2 complex matrix") - .arg (octaveValue.matrix_value ().rows ()) - .arg (octaveValue.matrix_value ().cols ()); - - // If everything else does not fit, we could not recognize the type. - } - else - { - return QString ("<Type not recognized>"); - } -} - void OctaveLink::launchOctave () { @@ -98,7 +42,7 @@ m_octaveCallbackThread = new OctaveCallbackThread (this); // Launch the second as soon as the first ist ready. - connect (m_octaveMainThread, SIGNAL(ready()), m_octaveCallbackThread, SLOT(start())); + connect (m_octaveMainThread, SIGNAL (ready ()), m_octaveCallbackThread, SLOT (start ())); // Start the first one. m_octaveMainThread->start (); @@ -107,27 +51,13 @@ void OctaveLink::terminateOctave () { - m_octaveCallbackThread->halt(); + m_octaveCallbackThread->halt (); m_octaveCallbackThread->wait (); m_octaveMainThread->terminate (); //m_octaveMainThread->wait(); } -QList < SymbolRecord > OctaveLink::symbolTable () -{ - m_symbolTableBuffer.clear (); - std::list < SymbolRecord > allVariables = symbol_table::all_variables (); - std::list < SymbolRecord >::iterator iterator; - for (iterator = allVariables.begin (); iterator != allVariables.end (); - iterator++) - { - SymbolRecord s = iterator->dup (symbol_table::global_scope ()); - m_symbolTableBuffer.append (s); - } - return m_symbolTableBuffer; -} - void OctaveLink::triggerUpdateHistoryModel () { @@ -146,8 +76,20 @@ } } +void +OctaveLink::triggerUpdateSymbolTable () +{ + m_workspaceModel->updateFromSymbolTable(); +} + QStringListModel * OctaveLink::historyModel () { return m_historyModel; } + +WorkspaceModel * +OctaveLink::workspaceModel () +{ + return m_workspaceModel; +}
--- a/gui/src/backend/OctaveLink.h +++ b/gui/src/backend/OctaveLink.h @@ -72,12 +72,10 @@ #include <QObject> #include <QStringListModel> +#include "WorkspaceModel.h" #include "OctaveCallbackThread.h" #include "OctaveMainThread.h" -typedef symbol_table::symbol_record SymbolRecord; -typedef octave_value OctaveValue; - /** * \class OctaveLink * Manages a link to an octave instance. @@ -91,43 +89,24 @@ { return &m_singleton; } - static QString - octaveValueAsQString (OctaveValue octaveValue); void launchOctave (); void terminateOctave (); - void acquireSymbolTable () { m_symbolTableSemaphore->acquire (); } - void releaseSymbolTable () { m_symbolTableSemaphore->release (); } - - /** - * For performance reasons this is not thread safe. Before you use this, - * acquire a lock with acquireSymbolTable and releaseSymbolTable. - */ - QList < SymbolRecord > symbolTable (); - - /** - * Returns a copy of the current symbol table buffer. - * \return Copy of the current symbol table buffer. - */ - QList < SymbolRecord > copyCurrentSymbolTable (); + QStringListModel *historyModel (); + WorkspaceModel *workspaceModel (); void triggerUpdateHistoryModel (); - QStringListModel *historyModel (); - void triggerUpdateSymbolTable() { emit updateSymbolTable(); } - -signals: - void updateSymbolTable (); + void triggerUpdateSymbolTable (); private: OctaveLink (); ~OctaveLink (); - /** Variable related member variables. */ - QSemaphore * m_symbolTableSemaphore; - QList < SymbolRecord > m_symbolTableBuffer; + //QSemaphore * m_symbolTableSemaphore; + //QList < symbol_table::symbol_record > m_symbolTableBuffer; - /** History related member variables. */ QStringListModel *m_historyModel; + WorkspaceModel *m_workspaceModel; // Threads for running octave and managing the data interaction. OctaveMainThread *m_octaveMainThread;
--- a/gui/src/src.pro +++ b/gui/src/src.pro @@ -88,7 +88,8 @@ backend/OctaveMainThread.cpp \ backend/ReadlineAdapter.cpp \ WelcomeWizard.cpp \ - FileEditor.cpp + FileEditor.cpp \ + WorkspaceModel.cpp HEADERS += \ lexer/lexeroctavegui.h \ @@ -104,7 +105,8 @@ backend/OctaveMainThread.h \ backend/ReadlineAdapter.h \ WelcomeWizard.h \ - FileEditor.h + FileEditor.h \ + WorkspaceModel.h FORMS += \ SettingsDialog.ui \