Mercurial > hg > octave-nkf
changeset 14698:79c9a6d06590 gui
Wrote SymbolInformation struct and refactored code that updates the symbol table.
* OctaveGUI: Commented out activateWindow call.
* WorkspaceModel: Complete rewrite of symbol table update code.
* OctaveLink: Added code for updating the symbol table.
* MainWindow: Added dummy central widget to meet Qt specifications.
* src.pro: Added includepath to be able to compile with standalone Qt SDK.
author | Jacob Dawid <jacob.dawid@googlemail.com> |
---|---|
date | Tue, 29 May 2012 14:29:05 +0200 |
parents | 55f88d2236b6 |
children | 0bab96aeb995 |
files | gui/src/MainWindow.cpp gui/src/OctaveGUI.cpp gui/src/WorkspaceModel.cpp gui/src/WorkspaceModel.h gui/src/backend/OctaveLink.cpp gui/src/backend/OctaveLink.h gui/src/backend/SymbolInformation.h gui/src/editor/lexeroctavegui.h gui/src/src.pro |
diffstat | 9 files changed, 213 insertions(+), 193 deletions(-) [+] |
line wrap: on
line diff
--- a/gui/src/MainWindow.cpp +++ b/gui/src/MainWindow.cpp @@ -172,7 +172,6 @@ MainWindow::closeEvent (QCloseEvent * closeEvent) { reportStatusMessage (tr ("Saving data and shutting down.")); - writeSettings (); m_closing = true; // inform editor window that whole application is closed OctaveLink::instance ()->terminateOctave (); @@ -228,13 +227,12 @@ m_terminal->setObjectName ("OctaveTerminal"); m_terminalDockWidget = new TerminalDockWidget (m_terminal, this); - /* QWidget *dummyWidget = new QWidget (); - dummyWidget->setObjectName ("DummyWidget"); - dummyWidget->setFixedSize (100, 100); + dummyWidget->setObjectName ("CentralDummyWidget"); + dummyWidget->resize (10, 10); dummyWidget->setSizePolicy (QSizePolicy::Minimum, QSizePolicy::Minimum); - setCentralWidget (dummyWidget);*/ - //dummyWidget->hide (); + dummyWidget->hide (); + setCentralWidget (dummyWidget); m_fileEditor = new FileEditor (m_terminal, this); @@ -365,7 +363,7 @@ addDockWidget (Qt::LeftDockWidgetArea, m_workspaceView); addDockWidget (Qt::LeftDockWidgetArea, m_historyDockWidget); addDockWidget (Qt::RightDockWidgetArea, m_filesDockWidget); - addDockWidget (Qt::BottomDockWidgetArea, m_fileEditor); + addDockWidget (Qt::RightDockWidgetArea, m_fileEditor); addDockWidget (Qt::BottomDockWidgetArea, m_terminalDockWidget); setStatusBar (m_statusBar);
--- a/gui/src/OctaveGUI.cpp +++ b/gui/src/OctaveGUI.cpp @@ -83,7 +83,7 @@ MainWindow w; w.show (); - w.activateWindow(); + //w.activateWindow(); return application.exec (); } }
--- a/gui/src/WorkspaceModel.cpp +++ b/gui/src/WorkspaceModel.cpp @@ -18,6 +18,7 @@ #include "WorkspaceModel.h" #include <QTreeWidget> #include <QTime> +#include "OctaveLink.h" WorkspaceModel::WorkspaceModel(QObject *parent) : QAbstractItemModel(parent) @@ -25,7 +26,6 @@ QList<QVariant> rootData; rootData << tr ("Name") << tr ("Type") << tr ("Value"); _rootItem = new TreeItem(rootData); - _cachedSymbolTableSemaphore = new QSemaphore (1); } WorkspaceModel::~WorkspaceModel() @@ -138,147 +138,35 @@ void -WorkspaceModel::cacheSymbolTable () -{ - std::list < symbol_table::symbol_record > symbolTable = symbol_table::all_variables (); - - _cachedSymbolTableSemaphore->acquire (1); - _cachedSymbolTable.clear(); - for (std::list < symbol_table::symbol_record > ::iterator iterator = symbolTable.begin (); - iterator != symbolTable.end (); iterator++) - { - _cachedSymbolTable.push_back((*iterator).dup(symbol_table::global_scope())); - } - _cachedSymbolTableSemaphore->release (1); -} - -void WorkspaceModel::updateFromSymbolTable () { - // 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; + topLevelItem (0)->deleteChildItems (); + topLevelItem (1)->deleteChildItems (); + topLevelItem (2)->deleteChildItems (); + topLevelItem (3)->deleteChildItems (); + + OctaveLink::instance ()-> acquireSymbolInformation(); + const QList <SymbolInformation>& symbolInformation = OctaveLink::instance() ->symbolInformation (); - _cachedSymbolTableSemaphore->acquire (1); - for (std::list < symbol_table::symbol_record > ::iterator iterator = _cachedSymbolTable.begin (); - iterator != _cachedSymbolTable.end (); iterator++) + foreach (const SymbolInformation& s, symbolInformation) { - // 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 ()) + TreeItem *child = new TreeItem (); + + child->setData (0, s._symbol); + child->setData (1, s._type); + child->setData (2, s._value); + + switch (s._scope) { - localSymbolTable.append (&(*iterator)); - } - - if (iterator->is_global ()) - { - globalSymbolTable.append (&(*iterator)); - } - - if (iterator->is_persistent ()) - { - persistentSymbolTable.append (&(*iterator)); - } - - if (iterator->is_hidden ()) - { - hiddenSymbolTable.append (&(*iterator)); + case SymbolInformation::Local: topLevelItem (0)->addChild (child); break; + case SymbolInformation::Global: topLevelItem (1)->addChild (child); break; + case SymbolInformation::Persistent: topLevelItem (2)->addChild (child); break; + case SymbolInformation::Hidden: topLevelItem (3)->addChild (child); break; } } - updateCategory (0, localSymbolTable); - updateCategory (1, globalSymbolTable); - updateCategory (2, persistentSymbolTable); - updateCategory (3, hiddenSymbolTable); - _cachedSymbolTableSemaphore->release (1); + OctaveLink::instance ()-> releaseSymbolInformation(); + reset(); emit expandRequest(); } - -void -WorkspaceModel::updateCategory (int topLevelItemIndex, const QList < symbol_table::symbol_record* > &symbolTable) -{ - TreeItem *treeItem = topLevelItem (topLevelItemIndex); - - QModelIndex mi = index(treeItem->row(), 0); - treeItem->deleteChildItems(); - - int symbolTableSize = symbolTable.size (); - for(int j = 0; j < symbolTableSize; j++) - { - TreeItem *child = new TreeItem (); - updateTreeEntry (child, symbolTable[j]); - treeItem->addChild (child); - } -} - -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 ())); -} - -QString -WorkspaceModel::octaveValueAsQString (const 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") - .arg (octaveValue.rows ()) - .arg (octaveValue.columns ()); - - // Convert complex matrix. - } - else if (octaveValue.is_complex_matrix ()) - { - return QString ("%1x%2") - .arg (octaveValue.rows ()) - .arg (octaveValue.columns ()); - - // If everything else does not fit, we could not recognize the type. - } - else - { - return QString ("<Type not recognized>"); - } -}
--- a/gui/src/WorkspaceModel.h +++ b/gui/src/WorkspaceModel.h @@ -18,42 +18,6 @@ #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> #include <QVector> @@ -159,12 +123,6 @@ void insertTopLevelItem (int at, TreeItem *treeItem); TreeItem *topLevelItem (int at); - - void cacheSymbolTable (); - void updateTreeEntry (TreeItem * treeItem, symbol_table::symbol_record *symbolRecord); - void updateCategory (int topLevelItemIndex, const QList < symbol_table::symbol_record *> &symbolTable); - QString octaveValueAsQString (const octave_value &octaveValue); - public slots: void updateFromSymbolTable (); @@ -172,8 +130,7 @@ void expandRequest(); private: - QSemaphore *_cachedSymbolTableSemaphore; - std::list < symbol_table::symbol_record > _cachedSymbolTable; + TreeItem *_rootItem; };
--- a/gui/src/backend/OctaveLink.cpp +++ b/gui/src/backend/OctaveLink.cpp @@ -23,7 +23,7 @@ int octave_readline_hook () { OctaveLink::instance ()->triggerUpdateHistoryModel (); - OctaveLink::instance ()->triggerCacheSymbolTable (); + OctaveLink::instance ()->buildSymbolInformation (); QDir::setCurrent (load_path::get_command_line_path ().c_str ()); return 0; } @@ -50,6 +50,8 @@ _updateWorkspaceModelTimer.setSingleShot (false); connect(&_updateWorkspaceModelTimer, SIGNAL (timeout ()), m_workspaceModel, SLOT (updateFromSymbolTable ())); + + _symbolInformationSemaphore = new QSemaphore (1); } OctaveLink::~OctaveLink () @@ -94,9 +96,38 @@ } void -OctaveLink::triggerCacheSymbolTable () +OctaveLink::acquireSymbolInformation () +{ + _symbolInformationSemaphore->acquire (1); +} + +void +OctaveLink::releaseSymbolInformation () +{ + _symbolInformationSemaphore->release (1); +} + +void +OctaveLink::buildSymbolInformation () { - m_workspaceModel->cacheSymbolTable(); + std::list < symbol_table::symbol_record > symbolTable = symbol_table::all_variables (); + + acquireSymbolInformation (); + _symbolInformation.clear (); + for (std::list < symbol_table::symbol_record > ::iterator iterator = symbolTable.begin (); + iterator != symbolTable.end (); iterator++) + { + SymbolInformation symbolInformation; + symbolInformation.fromSymbolRecord (*iterator); + _symbolInformation.push_back (symbolInformation); + } + releaseSymbolInformation (); +} + +const QList <SymbolInformation>& +OctaveLink::symbolInformation () const +{ + return _symbolInformation; } QStringListModel *
--- a/gui/src/backend/OctaveLink.h +++ b/gui/src/backend/OctaveLink.h @@ -75,6 +75,7 @@ #include "WorkspaceModel.h" #include "OctaveMainThread.h" +#include "SymbolInformation.h" /** * \class OctaveLink @@ -96,7 +97,11 @@ WorkspaceModel *workspaceModel (); void triggerUpdateHistoryModel (); - void triggerCacheSymbolTable (); + + void acquireSymbolInformation (); + void releaseSymbolInformation (); + void buildSymbolInformation (); + const QList <SymbolInformation>& symbolInformation () const; private: OctaveLink (); @@ -109,6 +114,9 @@ OctaveMainThread *m_octaveMainThread; QTimer _updateWorkspaceModelTimer; + QSemaphore *_symbolInformationSemaphore; + QList <SymbolInformation> _symbolInformation; + static OctaveLink m_singleton; }; #endif // OCTAVELINK_H
new file mode 100644 --- /dev/null +++ b/gui/src/backend/SymbolInformation.h @@ -0,0 +1,138 @@ +/* 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 SYMBOLINFORMATION_H +#define SYMBOLINFORMATION_H + +#include <QString> +#include <QHash> + +// 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" + +typedef struct SymbolInformation +{ + enum Scope + { + Local = 0, + Global = 1, + Persistent = 2, + Hidden = 3 + }; + + QString _symbol; + QString _type; + QString _value; + Scope _scope; + + int + hash () const + { + return qHash (_symbol) + qHash (_type) + qHash (_value) + (int)_scope; + } + + bool + equals (const SymbolInformation& other) const + { + if (hash () == other.hash ()) + { + return _symbol == other._symbol + && _type == other._type + && _value == other._value + && _scope == other._scope; + } + } + + bool + fromSymbolRecord (const symbol_table::symbol_record& symbolRecord) + { + if (symbolRecord.is_local () && !symbolRecord.is_global () && !symbolRecord.is_hidden ()) + _scope = Local; + else if (symbolRecord.is_global ()) + _scope = Global; + else if (symbolRecord.is_persistent ()) + _scope = Persistent; + else if (symbolRecord.is_hidden ()) + _scope = Hidden; + + _symbol = QString (symbolRecord.name ().c_str ()); + _type = QString (symbolRecord.varval ().type_name ().c_str ()); + octave_value octaveValue = symbolRecord.varval (); + + // For every type, convert to a human readable string. + if (octaveValue.is_sq_string ()) + _value = QString ("\'%1\'").arg (octaveValue.string_value ().c_str ()); + else if (octaveValue.is_dq_string ()) + _value = QString ("\"%1\"").arg (octaveValue.string_value ().c_str ()); + else if (octaveValue.is_real_scalar ()) + _value = QString ("%1").arg (octaveValue.scalar_value ()); + else if (octaveValue.is_complex_scalar ()) + _value = QString ("%1 + %2i").arg (octaveValue.scalar_value ()) + .arg (octaveValue.complex_value ().imag ()); + else if (octaveValue.is_range ()) + _value = QString ("%1 : %2 : %3").arg (octaveValue.range_value ().base ()) + .arg (octaveValue.range_value ().inc ()) + .arg (octaveValue.range_value ().limit ()); + else if (octaveValue.is_real_matrix ()) + _value = QString ("%1x%2").arg (octaveValue.rows ()) + .arg (octaveValue.columns ()); + else if (octaveValue.is_complex_matrix ()) + _value = QString ("%1x%2").arg (octaveValue.rows ()) + .arg (octaveValue.columns ()); + else + _value = QString ("<Type not recognized>"); + + return true; + } +} SymbolInformation; + + + +#endif // SYMBOLINFORMATION_H
--- a/gui/src/editor/lexeroctavegui.h +++ b/gui/src/editor/lexeroctavegui.h @@ -20,7 +20,6 @@ #include "ResourceManager.h" #include <QObject> - #include <Qsci/qsciglobal.h> #include <Qsci/qscilexer.h>
--- a/gui/src/src.pro +++ b/gui/src/src.pro @@ -40,7 +40,7 @@ } # Includepaths and libraries to link against: -INCLUDEPATH += . backend editor ../qterminal/libqterminal \ +INCLUDEPATH += . backend editor ../qterminal/libqterminal /usr/include/qt4 \ $$system(mkoctfile -p INCFLAGS) INCFLAGS += $$system(mkoctfile -p INCFLAGS) mac { @@ -105,7 +105,8 @@ WorkspaceModel.h \ editor/FileEditorInterface.h \ editor/FileEditorTab.h \ - TerminalDockWidget.h + TerminalDockWidget.h \ + backend/SymbolInformation.h FORMS += \ SettingsDialog.ui \