# HG changeset patch # User Jacob Dawid # Date 1337677224 -7200 # Node ID 7605e7136b5022046b60b096febe912cb91c34c6 # Parent 6a6733a5598298f3017b95ee7e630d9a372db39b Discarded initFileEditor, instead put that in the constructor. Speedup for updating the symbol table by lowering complexity from n² to n. Fixed problem with hangup on quit. * FileEditor: Removed initFileEditor, put that code into the constructor. * WorkspaceModel: Simplified updating the symbol table. * OctaveLink: Add quit_allowed = true to prevent hangup on quit. diff --git a/gui/src/FileEditor.cpp b/gui/src/FileEditor.cpp --- a/gui/src/FileEditor.cpp +++ b/gui/src/FileEditor.cpp @@ -25,10 +25,14 @@ #include #include -FileEditor::FileEditor (QWidget * parent) - : QWidget (parent) +FileEditor::FileEditor (QTerminal *terminalView, LexerOctaveGui *lexer, MainWindow *mainWindow) + : QWidget () { construct (); + m_editor->setLexer (lexer); + m_terminalView = terminalView; // for sending commands to octave + m_mainWindow = mainWindow; // get the MainWindow for chekcing state at subwindow close + show (); } FileEditor::~FileEditor () @@ -208,7 +212,7 @@ if (!file.open (QFile::WriteOnly)) { QMessageBox::warning (this, tr ("File Editor"), - tr ("Cannot write file %1:\n%2."). + tr ("Cannot write file %1:\n%2."). arg (saveFileName).arg (file.errorString ())); return; } @@ -342,18 +346,6 @@ m_editor->setCursorPosition(prevline,0); } -// function for setting the already existing lexer from MainWindow -void -FileEditor::initEditor (QTerminal* terminalView, - LexerOctaveGui* lexer, - MainWindow* mainWindow) -{ - m_editor->setLexer(lexer); - m_terminalView = terminalView; // for sending commands to octave - // TODO: make a global commandOctave function? - m_mainWindow = mainWindow; // get the MainWindow for chekcing state at subwindow close -} - void FileEditor::setModified (bool modified) { @@ -483,7 +475,7 @@ m_toolBar->addSeparator(); m_toolBar->addAction (runAction); - // menu bar + // menu bar QMenu *fileMenu = new QMenu(tr("&File"),m_menuBar); fileMenu->addAction(newAction); fileMenu->addAction(openAction); @@ -544,5 +536,4 @@ m_fileName = ""; newWindowTitle (false); setWindowIcon(QIcon::fromTheme("accessories-text-editor",style->standardIcon (QStyle::SP_FileIcon))); - show (); } diff --git a/gui/src/FileEditor.h b/gui/src/FileEditor.h --- a/gui/src/FileEditor.h +++ b/gui/src/FileEditor.h @@ -44,12 +44,9 @@ Q_OBJECT public: - FileEditor (QWidget * parent = 0); + FileEditor (QTerminal *terminalView, LexerOctaveGui *lexer, MainWindow *mainWindow); ~FileEditor (); void loadFile (QString fileName); - void initEditor (QTerminal *terminalView, - LexerOctaveGui *lexer, - MainWindow *mainWindow); public slots: diff --git a/gui/src/MainWindow.cpp b/gui/src/MainWindow.cpp --- a/gui/src/MainWindow.cpp +++ b/gui/src/MainWindow.cpp @@ -53,9 +53,8 @@ void MainWindow::newEditorWindow (QString fileName) { - FileEditor *fileEditor = new FileEditor (); + FileEditor *fileEditor = new FileEditor (m_terminalView, m_lexer, this); fileEditor->setAttribute (Qt::WA_DeleteOnClose); - fileEditor->initEditor(m_terminalView, m_lexer, this); // init necessary informations for editor if (fileName.isEmpty ()) fileEditor->newFile (); diff --git a/gui/src/WorkspaceModel.cpp b/gui/src/WorkspaceModel.cpp --- a/gui/src/WorkspaceModel.cpp +++ b/gui/src/WorkspaceModel.cpp @@ -17,6 +17,7 @@ #include "WorkspaceModel.h" #include +#include WorkspaceModel::WorkspaceModel(QObject *parent) : QAbstractItemModel(parent) @@ -146,7 +147,6 @@ 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; @@ -184,71 +184,22 @@ updateCategory (2, persistentSymbolTable); updateCategory (3, hiddenSymbolTable); reset(); + emit expandRequest(); } void -WorkspaceModel::updateCategory (int topLevelItemIndex, QList < symbol_table::symbol_record* > symbolTable) +WorkspaceModel::updateCategory (int topLevelItemIndex, const 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; - } - } + treeItem->deleteChildItems(); - // 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++) + int symbolTableSize = symbolTable.size (); + for(int j = 0; j < symbolTableSize; j++) { - 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--; - } + TreeItem *child = new TreeItem (); + updateTreeEntry (child, symbolTable[j]); + treeItem->addChild (child); } } diff --git a/gui/src/WorkspaceModel.h b/gui/src/WorkspaceModel.h --- a/gui/src/WorkspaceModel.h +++ b/gui/src/WorkspaceModel.h @@ -56,6 +56,7 @@ // Qt includes #include +#include class TreeItem { @@ -73,7 +74,7 @@ } ~TreeItem() { - qDeleteAll(_childItems); + qDeleteAll(_childItems); } void insertChildItem(int at, TreeItem *item) { @@ -86,6 +87,11 @@ _childItems.append(item); } + void deleteChildItems() { + qDeleteAll(_childItems); + _childItems.clear(); + } + void removeChild(TreeItem *item) { _childItems.removeAll(item); } @@ -154,7 +160,7 @@ void updateFromSymbolTable (); void updateTreeEntry (TreeItem * treeItem, symbol_table::symbol_record *symbolRecord); - void updateCategory (int topLevelItemIndex, QList < symbol_table::symbol_record *> symbolTable); + void updateCategory (int topLevelItemIndex, const QList < symbol_table::symbol_record *> &symbolTable); QString octaveValueAsQString (const octave_value &octaveValue); signals: diff --git a/gui/src/backend/OctaveLink.cpp b/gui/src/backend/OctaveLink.cpp --- a/gui/src/backend/OctaveLink.cpp +++ b/gui/src/backend/OctaveLink.cpp @@ -56,6 +56,7 @@ OctaveLink::terminateOctave () { m_octaveMainThread->terminate (); + quit_allowed = true; m_octaveMainThread->wait(); }